From 82c9789a9a64dc9ca5c726c866b9ab22f543f514 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Mon, 4 Nov 2024 09:27:52 +0100 Subject: [PATCH] core/txpool/tracker: address review concerns (pkg name + unused) --- core/txpool/blobpool/blobpool.go | 7 ----- core/txpool/legacypool/legacypool_test.go | 28 ------------------- core/txpool/{tracking => tracker}/journal.go | 2 +- .../{tracking => tracker}/tx_tracker.go | 21 +++----------- eth/backend.go | 20 ++++++------- 5 files changed, 15 insertions(+), 63 deletions(-) rename core/txpool/{tracking => tracker}/journal.go (99%) rename core/txpool/{tracking => tracker}/tx_tracker.go (89%) diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index dafc385998..da38461702 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -1693,13 +1693,6 @@ func (p *BlobPool) ContentFrom(addr common.Address) ([]*types.Transaction, []*ty return []*types.Transaction{}, []*types.Transaction{} } -// Locals retrieves the accounts currently considered local by the pool. -// -// There is no notion of local accounts in the blob pool. -func (p *BlobPool) Locals() []common.Address { - return []common.Address{} -} - // Status returns the known status (unknown/pending/queued) of a transaction // identified by their hashes. func (p *BlobPool) Status(hash common.Hash) txpool.TxStatus { diff --git a/core/txpool/legacypool/legacypool_test.go b/core/txpool/legacypool/legacypool_test.go index 7f37317d50..b8152e0b39 100644 --- a/core/txpool/legacypool/legacypool_test.go +++ b/core/txpool/legacypool/legacypool_test.go @@ -2245,34 +2245,6 @@ func benchmarkBatchInsert(b *testing.B, size int) { } } -func BenchmarkInsertRemoteWithAllLocals(b *testing.B) { - // Allocate keys for testing - key, _ := crypto.GenerateKey() - account := crypto.PubkeyToAddress(key.PublicKey) - - remoteKey, _ := crypto.GenerateKey() - remoteAddr := crypto.PubkeyToAddress(remoteKey.PublicKey) - - remotes := make([]*types.Transaction, 1000) - for i := 0; i < len(remotes); i++ { - remotes[i] = pricedTransaction(uint64(i), 100000, big.NewInt(2), remoteKey) // Higher gasprice - } - // Benchmark importing the transactions into the queue - b.ResetTimer() - for i := 0; i < b.N; i++ { - b.StopTimer() - pool, _ := setupPool() - testAddBalance(pool, account, big.NewInt(100000000)) - b.StartTimer() - // Assign a high enough balance for testing - testAddBalance(pool, remoteAddr, big.NewInt(100000000)) - for i := 0; i < len(remotes); i++ { - pool.addRemotes([]*types.Transaction{remotes[i]}) - } - pool.Close() - } -} - // Benchmarks the speed of batch transaction insertion in case of multiple accounts. func BenchmarkMultiAccountBatchInsert(b *testing.B) { // Generate a batch of transactions to enqueue into the pool diff --git a/core/txpool/tracking/journal.go b/core/txpool/tracker/journal.go similarity index 99% rename from core/txpool/tracking/journal.go rename to core/txpool/tracker/journal.go index ba40b885b9..a008648379 100644 --- a/core/txpool/tracking/journal.go +++ b/core/txpool/tracker/journal.go @@ -14,7 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . -package tracking +package tracker import ( "errors" diff --git a/core/txpool/tracking/tx_tracker.go b/core/txpool/tracker/tx_tracker.go similarity index 89% rename from core/txpool/tracking/tx_tracker.go rename to core/txpool/tracker/tx_tracker.go index cfe75a658e..34a06c4f1b 100644 --- a/core/txpool/tracking/tx_tracker.go +++ b/core/txpool/tracker/tx_tracker.go @@ -15,7 +15,7 @@ // along with the go-ethereum library. If not, see . // Package legacypool implements the normal EVM execution transaction pool. -package tracking +package tracker import ( "sync" @@ -48,19 +48,18 @@ type TxTracker struct { signer types.Signer shutdownCh chan struct{} - triggerCh chan struct{} mu sync.Mutex wg sync.WaitGroup } -func NewTxTracker(journalPath string, journalTime time.Duration, chainConfig *params.ChainConfig, next *txpool.TxPool) *TxTracker { +// New creates a new TxTracker +func New(journalPath string, journalTime time.Duration, chainConfig *params.ChainConfig, next *txpool.TxPool) *TxTracker { signer := types.LatestSigner(chainConfig) pool := &TxTracker{ all: make(map[common.Hash]*types.Transaction), byAddr: make(map[common.Address]*legacypool.SortedMap), signer: signer, shutdownCh: make(chan struct{}), - triggerCh: make(chan struct{}), pool: next, } if journalPath != "" { @@ -148,7 +147,7 @@ func (tracker *TxTracker) Start() error { return nil } -// Start implements node.Lifecycle interface +// Stop implements node.Lifecycle interface // Stop terminates all goroutines belonging to the service, blocking until they // are all terminated. func (tracker *TxTracker) Stop() error { @@ -157,13 +156,6 @@ func (tracker *TxTracker) Stop() error { return nil } -// TriggerRecheck triggers a recheck, whereby the tracker potentially resubmits -// transactions to the tx pool. This method is mainly useful for test purposes, -// in order to speed up the process. -func (tracker *TxTracker) TriggerRecheck() { - tracker.triggerCh <- struct{}{} -} - func (tracker *TxTracker) loop() { defer tracker.wg.Done() if tracker.journal != nil { @@ -180,11 +172,6 @@ func (tracker *TxTracker) loop() { select { case <-tracker.shutdownCh: return - case <-tracker.triggerCh: - resubmits, _ := tracker.recheck(false) - if len(resubmits) > 0 { - tracker.pool.Add(resubmits, false) - } case <-t.C: checkJournal := tracker.journal != nil && time.Since(lastJournal) > tracker.rejournal resubmits, rejournal := tracker.recheck(checkJournal) diff --git a/eth/backend.go b/eth/backend.go index b20ba9dd4d..8c75f4d040 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -23,6 +23,7 @@ import ( "math/big" "runtime" "sync" + "time" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/common" @@ -35,7 +36,7 @@ import ( "github.com/ethereum/go-ethereum/core/txpool" "github.com/ethereum/go-ethereum/core/txpool/blobpool" "github.com/ethereum/go-ethereum/core/txpool/legacypool" - "github.com/ethereum/go-ethereum/core/txpool/tracking" + "github.com/ethereum/go-ethereum/core/txpool/tracker" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/eth/downloader" @@ -70,7 +71,7 @@ type Ethereum struct { // core protocol objects config *ethconfig.Config txPool *txpool.TxPool - localTxTracker *tracking.TxTracker + localTxTracker *tracker.TxTracker blockchain *core.BlockChain handler *handler @@ -238,12 +239,12 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { eth.txPool, err = txpool.New(config.TxPool.PriceLimit, eth.blockchain, []txpool.SubPool{legacyPool, blobPool}) if !config.TxPool.NoLocals { - // TODO! - // We also need to handle config.Locals, the accounts that are - // to be treated as locals, regardless of how they arrive to geth. - eth.localTxTracker = tracking.NewTxTracker(config.TxPool.Journal, - config.TxPool.Rejournal, - eth.blockchain.Config(), eth.txPool) + rejournal := config.TxPool.Rejournal + if rejournal < time.Second { + log.Warn("Sanitizing invalid txpool journal time", "provided", rejournal, "updated", time.Second) + rejournal = time.Second + } + eth.localTxTracker = tracker.New(config.TxPool.Journal, rejournal, eth.blockchain.Config(), eth.txPool) stack.RegisterLifecycle(eth.localTxTracker) } @@ -340,8 +341,7 @@ func (s *Ethereum) ResetWithGenesisBlock(gb *types.Block) { s.blockchain.ResetWithGenesisBlock(gb) } -func (s *Ethereum) Miner() *miner.Miner { return s.miner } -func (s *Ethereum) Tracker() *tracking.TxTracker { return s.localTxTracker } +func (s *Ethereum) Miner() *miner.Miner { return s.miner } func (s *Ethereum) AccountManager() *accounts.Manager { return s.accountManager } func (s *Ethereum) BlockChain() *core.BlockChain { return s.blockchain }