Skip to content

Commit

Permalink
core/txpool/tracker: address review concerns (pkg name + unused)
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman committed Nov 4, 2024
1 parent 8885467 commit 165f71b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://www.gnu.org/licenses/>.

package tracking
package tracker

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

// Package legacypool implements the normal EVM execution transaction pool.
package tracking
package tracker

import (
"sync"
Expand Down Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)
Expand Down
13 changes: 5 additions & 8 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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"
Expand Down Expand Up @@ -70,7 +70,7 @@ type Ethereum struct {
// core protocol objects
config *ethconfig.Config
txPool *txpool.TxPool
localTxTracker *tracking.TxTracker
localTxTracker *tracker.TxTracker
blockchain *core.BlockChain

handler *handler
Expand Down Expand Up @@ -238,10 +238,7 @@ 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,
eth.localTxTracker = tracker.New(config.TxPool.Journal,
config.TxPool.Rejournal,
eth.blockchain.Config(), eth.txPool)
stack.RegisterLifecycle(eth.localTxTracker)
Expand Down Expand Up @@ -340,8 +337,8 @@ 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) Tracker() *tracker.TxTracker { return s.localTxTracker }

func (s *Ethereum) AccountManager() *accounts.Manager { return s.accountManager }
func (s *Ethereum) BlockChain() *core.BlockChain { return s.blockchain }
Expand Down

0 comments on commit 165f71b

Please sign in to comment.