From ec14cba6113f1779d270be7a443bdc7438d17474 Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Wed, 15 Sep 2021 09:09:19 +0700 Subject: [PATCH] Remote Pool: add mining rpc, test pending txs stream (#2685) --- cmd/rpcdaemon/filters/filters.go | 6 +++--- cmd/txpool/main.go | 10 ++++++---- eth/backend.go | 6 +++++- go.mod | 2 +- go.sum | 4 ++-- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/cmd/rpcdaemon/filters/filters.go b/cmd/rpcdaemon/filters/filters.go index 27f8bdd7f..9010de680 100644 --- a/cmd/rpcdaemon/filters/filters.go +++ b/cmd/rpcdaemon/filters/filters.go @@ -384,12 +384,12 @@ func (ff *Filters) OnNewTx(reply *txpool.OnAddReply) { defer ff.mu.RUnlock() txs := make([]types.Transaction, len(reply.RplTxs)) - for i, rplTx := range reply.RplTxs { + for i, rlpTx := range reply.RplTxs { var decodeErr error - txs[i], decodeErr = types.UnmarshalTransactionFromBinary(rplTx) + txs[i], decodeErr = types.UnmarshalTransactionFromBinary(rlpTx) if decodeErr != nil { // ignoring what we can't unmarshal - log.Warn("OnNewTx rpc filters, unprocessable payload", "err", decodeErr) + log.Warn("OnNewTx rpc filters, unprocessable payload", "err", decodeErr, "data", fmt.Sprintf("%x", rlpTx)) break } } diff --git a/cmd/txpool/main.go b/cmd/txpool/main.go index df05a1531..00db394b2 100644 --- a/cmd/txpool/main.go +++ b/cmd/txpool/main.go @@ -15,8 +15,10 @@ import ( "github.com/ledgerwatch/erigon-lib/kv/remotedb" "github.com/ledgerwatch/erigon-lib/txpool" "github.com/ledgerwatch/erigon-lib/txpool/txpooluitl" + "github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcdaemontest" "github.com/ledgerwatch/erigon/cmd/utils" "github.com/ledgerwatch/erigon/common/paths" + "github.com/ledgerwatch/erigon/ethdb/privateapi" "github.com/ledgerwatch/erigon/ethdb/remotedbserver" "github.com/ledgerwatch/erigon/internal/debug" "github.com/ledgerwatch/log/v3" @@ -93,8 +95,8 @@ var rootCmd = &cobra.Command{ cfg := txpool.DefaultConfig cfg.DBDir = path.Join(datadir, "txpool") - cfg.LogEvery = 5 * time.Minute - cfg.CommitEvery = 5 * time.Minute + cfg.LogEvery = 30 * time.Second + cfg.CommitEvery = 30 * time.Second cacheConfig := kvcache.DefaultCoherentCacheConfig cacheConfig.MetricsLabel = "txpool" @@ -114,10 +116,10 @@ var rootCmd = &cobra.Command{ if casted, ok := backend.engine.(*ethash.Ethash); ok { ethashApi = casted.APIs(nil)[1].Service.(*ethash.API) } - miningGrpcServer := privateapi.NewMiningServer(cmd.Context(), &rpcdaemontest.IsMiningMock{}, ethashApi) */ + miningGrpcServer := privateapi.NewMiningServer(cmd.Context(), &rpcdaemontest.IsMiningMock{}, nil) - grpcServer, err := txpool.StartGrpc(txpoolGrpcServer, nil, txpoolApiAddr, nil) + grpcServer, err := txpool.StartGrpc(txpoolGrpcServer, miningGrpcServer, txpoolApiAddr, nil) if err != nil { return err } diff --git a/eth/backend.go b/eth/backend.go index 4cf0b06a0..da878b872 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -33,7 +33,9 @@ import ( libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon-lib/direct" "github.com/ledgerwatch/erigon-lib/etl" + "github.com/ledgerwatch/erigon-lib/gointerfaces" "github.com/ledgerwatch/erigon-lib/gointerfaces/grpcutil" + "github.com/ledgerwatch/erigon-lib/gointerfaces/remote" "github.com/ledgerwatch/erigon-lib/gointerfaces/sentry" txpool_proto "github.com/ledgerwatch/erigon-lib/gointerfaces/txpool" "github.com/ledgerwatch/erigon-lib/kv" @@ -649,7 +651,9 @@ func (s *Ethereum) StartMining(ctx context.Context, db kv.RwDB, mining *stagedsy if hh.BaseFee != nil { baseFee = hh.BaseFee.Uint64() } - return s.txPool2.OnNewBlock(context.Background(), nil, txpool2.TxSlots{}, txpool2.TxSlots{}, baseFee, hh.Number.Uint64(), hh.Hash()) + return s.txPool2.OnNewBlock(context.Background(), &remote.StateChange{ + BlockHeight: hh.Number.Uint64(), BlockHash: gointerfaces.ConvertHashToH256(hh.Hash()), + }, txpool2.TxSlots{}, txpool2.TxSlots{}, baseFee) }); err != nil { return err } diff --git a/go.mod b/go.mod index 79844db9b..0b7d61717 100644 --- a/go.mod +++ b/go.mod @@ -38,7 +38,7 @@ require ( github.com/julienschmidt/httprouter v1.3.0 github.com/kevinburke/go-bindata v3.21.0+incompatible github.com/kylelemons/godebug v1.1.0 // indirect - github.com/ledgerwatch/erigon-lib v0.0.0-20210913065323-1b66a410bef3 + github.com/ledgerwatch/erigon-lib v0.0.0-20210914145433-c35be2a22677 github.com/ledgerwatch/log/v3 v3.3.0 github.com/ledgerwatch/secp256k1 v0.0.0-20210626115225-cd5cd00ed72d github.com/logrusorgru/aurora/v3 v3.0.0 diff --git a/go.sum b/go.sum index fca6bbfa1..4d11ec290 100644 --- a/go.sum +++ b/go.sum @@ -493,8 +493,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= 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-20210913065323-1b66a410bef3 h1:LEE17DjFV3+2pRin3snY9mOXiNCJnaUXLU4HWuzu5RY= -github.com/ledgerwatch/erigon-lib v0.0.0-20210913065323-1b66a410bef3/go.mod h1:GiYMKOrTi4T2feH10Fvu8QTbvLm/GOckYzUmuk9WU8s= +github.com/ledgerwatch/erigon-lib v0.0.0-20210914145433-c35be2a22677 h1:6b4eTdKUqxVXjlXp9HENcWh3f/WZ1hJ8V3ZTaTkCOWI= +github.com/ledgerwatch/erigon-lib v0.0.0-20210914145433-c35be2a22677/go.mod h1:GiYMKOrTi4T2feH10Fvu8QTbvLm/GOckYzUmuk9WU8s= github.com/ledgerwatch/log/v3 v3.3.0 h1:k8N/3NQLILr8CKCMyza261vLFKU7VA+nMNNb0wVyQSc= github.com/ledgerwatch/log/v3 v3.3.0/go.mod h1:J58eOHHrIYHxl7LKkRsb/0YibKwtLfauUryl5SLRGm0= github.com/ledgerwatch/secp256k1 v0.0.0-20210626115225-cd5cd00ed72d h1:/IKMrJdfRsoYNc36PXqP4xMH3vhW/8IQyBKGQbKZUno=