From 6d9ea162abb2f76e6ce0080456838543bcafe262 Mon Sep 17 00:00:00 2001 From: Alex Sharov <AskAlexSharov@gmail.com> Date: Wed, 16 Feb 2022 11:24:51 +0700 Subject: [PATCH] =?UTF-8?q?rpc=20daemon=20embed=C2=A0(step=203)=20(#3519)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/rpcdaemon/cli/config.go | 3 +-- cmd/rpcdaemon/filters/filters.go | 27 ++++++++++++++------------- eth/backend.go | 16 +++++++++------- go.mod | 2 +- go.sum | 4 ++-- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/cmd/rpcdaemon/cli/config.go b/cmd/rpcdaemon/cli/config.go index a09f68202c..eb4ce32acc 100644 --- a/cmd/rpcdaemon/cli/config.go +++ b/cmd/rpcdaemon/cli/config.go @@ -250,8 +250,7 @@ func EmbeddedServices(ctx context.Context, erigonDB kv.RoDB, stateCacheCfg kvcac kvRPC := remotedbserver.NewKvServer(ctx, erigonDB) stateDiffClient := direct.NewStateDiffClientDirect(kvRPC) _ = stateDiffClient - //TODO: enable next line - //subscribeToStateChangesLoop(ctx, stateDiffClient, stateCache) + subscribeToStateChangesLoop(ctx, stateDiffClient, stateCache) directClient := direct.NewEthBackendClientDirect(ethBackendServer) diff --git a/cmd/rpcdaemon/filters/filters.go b/cmd/rpcdaemon/filters/filters.go index d753daffbc..fa80611861 100644 --- a/cmd/rpcdaemon/filters/filters.go +++ b/cmd/rpcdaemon/filters/filters.go @@ -13,6 +13,7 @@ import ( "github.com/ledgerwatch/erigon-lib/gointerfaces/remote" "github.com/ledgerwatch/erigon-lib/gointerfaces/txpool" + txpool2 "github.com/ledgerwatch/erigon-lib/txpool" "github.com/ledgerwatch/erigon/cmd/rpcdaemon/services" "github.com/ledgerwatch/erigon/core/types" "github.com/ledgerwatch/erigon/rlp" @@ -69,16 +70,16 @@ func New(ctx context.Context, ethBackend services.ApiBackend, txPool txpool.Txpo default: } if s, ok := status.FromError(err); ok && s.Code() == codes.Canceled { - time.Sleep(time.Second) + time.Sleep(3 * time.Second) continue } if errors.Is(err, io.EOF) || errors.Is(err, context.Canceled) { - time.Sleep(time.Second) + time.Sleep(3 * time.Second) continue } log.Warn("rpc filters: error subscribing to events", "err", err) - time.Sleep(time.Second) + time.Sleep(3 * time.Second) } } }() @@ -98,15 +99,15 @@ func New(ctx context.Context, ethBackend services.ApiBackend, txPool txpool.Txpo default: } if s, ok := status.FromError(err); ok && s.Code() == codes.Canceled { - time.Sleep(time.Second) + time.Sleep(3 * time.Second) continue } - if errors.Is(err, io.EOF) || errors.Is(err, context.Canceled) { - time.Sleep(time.Second) + if errors.Is(err, io.EOF) || errors.Is(err, context.Canceled) || errors.Is(err, txpool2.ErrPoolDisabled) { + time.Sleep(3 * time.Second) continue } log.Warn("rpc filters: error subscribing to pending transactions", "err", err) - time.Sleep(time.Second) + time.Sleep(3 * time.Second) } } }() @@ -125,15 +126,15 @@ func New(ctx context.Context, ethBackend services.ApiBackend, txPool txpool.Txpo default: } if s, ok := status.FromError(err); ok && s.Code() == codes.Canceled { - time.Sleep(time.Second) + time.Sleep(3 * time.Second) continue } if errors.Is(err, io.EOF) || errors.Is(err, context.Canceled) { - time.Sleep(time.Second) + time.Sleep(3 * time.Second) continue } log.Warn("rpc filters: error subscribing to pending blocks", "err", err) - time.Sleep(time.Second) + time.Sleep(3 * time.Second) } } }() @@ -151,15 +152,15 @@ func New(ctx context.Context, ethBackend services.ApiBackend, txPool txpool.Txpo default: } if s, ok := status.FromError(err); ok && s.Code() == codes.Canceled { - time.Sleep(time.Second) + time.Sleep(3 * time.Second) continue } if errors.Is(err, io.EOF) || errors.Is(err, context.Canceled) { - time.Sleep(time.Second) + time.Sleep(3 * time.Second) continue } log.Warn("rpc filters: error subscribing to pending logs", "err", err) - time.Sleep(time.Second) + time.Sleep(3 * time.Second) } } }() diff --git a/eth/backend.go b/eth/backend.go index b987832c91..db4d6e7108 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -523,10 +523,13 @@ func New(stack *node.Node, config *ethconfig.Config, txpoolCfg txpool2.Config, l gpoParams.Default = config.Miner.GasPrice } //eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, gpoParams) - /* // start HTTP API - httpRpcCfg := cli.Flags{} // TODO: add rpcdaemon cli flags to Erigon and fill this struct (or break it to smaller config objects) + httpRpcCfg := cli.Flags{ + HttpListenAddress: "0.0.0.0", + HttpPort: 8545, + API: []string{"eth", "net", "web3", "txpool", "debug"}, + } // TODO: add rpcdaemon cli flags to Erigon and fill this struct (or break it to smaller config objects) ethRpcClient, txPoolRpcClient, miningRpcClient, starkNetRpcClient, stateCache, ff, err := cli.EmbeddedServices( ctx, chainKv, httpRpcCfg.StateCache, blockReader, ethBackendRPC, @@ -543,11 +546,10 @@ func New(stack *node.Node, config *ethconfig.Config, txpoolCfg txpool2.Config, l } apiList := commands.APIList(chainKv, borDb, ethRpcClient, txPoolRpcClient, miningRpcClient, starkNetRpcClient, ff, stateCache, blockReader, httpRpcCfg, nil) go func() { - _ = apiList - //if err := cli.StartRpcServer(ctx, httpRpcCfg, apiList); err != nil { - // log.Error(err.Error()) - // return - //} + if err := cli.StartRpcServer(ctx, httpRpcCfg, apiList); err != nil { + log.Error(err.Error()) + return + } }() */ diff --git a/go.mod b/go.mod index e64528b18a..cf63209ced 100644 --- a/go.mod +++ b/go.mod @@ -40,7 +40,7 @@ require ( github.com/json-iterator/go v1.1.12 github.com/julienschmidt/httprouter v1.3.0 github.com/kevinburke/go-bindata v3.21.0+incompatible - github.com/ledgerwatch/erigon-lib v0.0.0-20220213185636-136385995894 + github.com/ledgerwatch/erigon-lib v0.0.0-20220216032013-ccbe5cbcd37b github.com/ledgerwatch/log/v3 v3.4.0 github.com/ledgerwatch/secp256k1 v1.0.0 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect diff --git a/go.sum b/go.sum index e5ba9019cf..d139420c54 100644 --- a/go.sum +++ b/go.sum @@ -632,8 +632,8 @@ github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3P github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= -github.com/ledgerwatch/erigon-lib v0.0.0-20220213185636-136385995894 h1:YLRLN/rmjQ3fLMtgna1iVqAQbZVIz+G07G3jXHc+lpU= -github.com/ledgerwatch/erigon-lib v0.0.0-20220213185636-136385995894/go.mod h1:phuzMr8tLvqjo5cQVA9jj8odAso6eLyS4LFmUJrDFGw= +github.com/ledgerwatch/erigon-lib v0.0.0-20220216032013-ccbe5cbcd37b h1:kmvty/I8TLDFTvjWPRIYqwRle5mzg9n3LUrM7bqZkko= +github.com/ledgerwatch/erigon-lib v0.0.0-20220216032013-ccbe5cbcd37b/go.mod h1:phuzMr8tLvqjo5cQVA9jj8odAso6eLyS4LFmUJrDFGw= github.com/ledgerwatch/log/v3 v3.4.0 h1:SEIOcv5a2zkG3PmoT5jeTU9m/0nEUv0BJS5bzsjwKCI= github.com/ledgerwatch/log/v3 v3.4.0/go.mod h1:VXcz6Ssn6XEeU92dCMc39/g1F0OYAjw1Mt+dGP5DjXY= github.com/ledgerwatch/secp256k1 v1.0.0 h1:Usvz87YoTG0uePIV8woOof5cQnLXGYa162rFf3YnwaQ= -- GitLab