core/txpool/tracker: address review concerns (pkg name + unused)

pull/30559/head
Martin Holst Swende 3 weeks ago
parent 888546725e
commit 82c9789a9a
No known key found for this signature in database
GPG Key ID: 683B438C05A5DDF0
  1. 7
      core/txpool/blobpool/blobpool.go
  2. 28
      core/txpool/legacypool/legacypool_test.go
  3. 2
      core/txpool/tracker/journal.go
  4. 21
      core/txpool/tracker/tx_tracker.go
  5. 20
      eth/backend.go

@ -1693,13 +1693,6 @@ func (p *BlobPool) ContentFrom(addr common.Address) ([]*types.Transaction, []*ty
return []*types.Transaction{}, []*types.Transaction{} 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 // Status returns the known status (unknown/pending/queued) of a transaction
// identified by their hashes. // identified by their hashes.
func (p *BlobPool) Status(hash common.Hash) txpool.TxStatus { func (p *BlobPool) Status(hash common.Hash) txpool.TxStatus {

@ -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. // Benchmarks the speed of batch transaction insertion in case of multiple accounts.
func BenchmarkMultiAccountBatchInsert(b *testing.B) { func BenchmarkMultiAccountBatchInsert(b *testing.B) {
// Generate a batch of transactions to enqueue into the pool // Generate a batch of transactions to enqueue into the pool

@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License // 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/>. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package tracking package tracker
import ( import (
"errors" "errors"

@ -15,7 +15,7 @@
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Package legacypool implements the normal EVM execution transaction pool. // Package legacypool implements the normal EVM execution transaction pool.
package tracking package tracker
import ( import (
"sync" "sync"
@ -48,19 +48,18 @@ type TxTracker struct {
signer types.Signer signer types.Signer
shutdownCh chan struct{} shutdownCh chan struct{}
triggerCh chan struct{}
mu sync.Mutex mu sync.Mutex
wg sync.WaitGroup 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) signer := types.LatestSigner(chainConfig)
pool := &TxTracker{ pool := &TxTracker{
all: make(map[common.Hash]*types.Transaction), all: make(map[common.Hash]*types.Transaction),
byAddr: make(map[common.Address]*legacypool.SortedMap), byAddr: make(map[common.Address]*legacypool.SortedMap),
signer: signer, signer: signer,
shutdownCh: make(chan struct{}), shutdownCh: make(chan struct{}),
triggerCh: make(chan struct{}),
pool: next, pool: next,
} }
if journalPath != "" { if journalPath != "" {
@ -148,7 +147,7 @@ func (tracker *TxTracker) Start() error {
return nil return nil
} }
// Start implements node.Lifecycle interface // Stop implements node.Lifecycle interface
// Stop terminates all goroutines belonging to the service, blocking until they // Stop terminates all goroutines belonging to the service, blocking until they
// are all terminated. // are all terminated.
func (tracker *TxTracker) Stop() error { func (tracker *TxTracker) Stop() error {
@ -157,13 +156,6 @@ func (tracker *TxTracker) Stop() error {
return nil 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() { func (tracker *TxTracker) loop() {
defer tracker.wg.Done() defer tracker.wg.Done()
if tracker.journal != nil { if tracker.journal != nil {
@ -180,11 +172,6 @@ func (tracker *TxTracker) loop() {
select { select {
case <-tracker.shutdownCh: case <-tracker.shutdownCh:
return return
case <-tracker.triggerCh:
resubmits, _ := tracker.recheck(false)
if len(resubmits) > 0 {
tracker.pool.Add(resubmits, false)
}
case <-t.C: case <-t.C:
checkJournal := tracker.journal != nil && time.Since(lastJournal) > tracker.rejournal checkJournal := tracker.journal != nil && time.Since(lastJournal) > tracker.rejournal
resubmits, rejournal := tracker.recheck(checkJournal) resubmits, rejournal := tracker.recheck(checkJournal)

@ -23,6 +23,7 @@ import (
"math/big" "math/big"
"runtime" "runtime"
"sync" "sync"
"time"
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common" "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"
"github.com/ethereum/go-ethereum/core/txpool/blobpool" "github.com/ethereum/go-ethereum/core/txpool/blobpool"
"github.com/ethereum/go-ethereum/core/txpool/legacypool" "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/types"
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/eth/downloader"
@ -70,7 +71,7 @@ type Ethereum struct {
// core protocol objects // core protocol objects
config *ethconfig.Config config *ethconfig.Config
txPool *txpool.TxPool txPool *txpool.TxPool
localTxTracker *tracking.TxTracker localTxTracker *tracker.TxTracker
blockchain *core.BlockChain blockchain *core.BlockChain
handler *handler 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}) eth.txPool, err = txpool.New(config.TxPool.PriceLimit, eth.blockchain, []txpool.SubPool{legacyPool, blobPool})
if !config.TxPool.NoLocals { if !config.TxPool.NoLocals {
// TODO! rejournal := config.TxPool.Rejournal
// We also need to handle config.Locals, the accounts that are if rejournal < time.Second {
// to be treated as locals, regardless of how they arrive to geth. log.Warn("Sanitizing invalid txpool journal time", "provided", rejournal, "updated", time.Second)
eth.localTxTracker = tracking.NewTxTracker(config.TxPool.Journal, rejournal = time.Second
config.TxPool.Rejournal, }
eth.blockchain.Config(), eth.txPool) eth.localTxTracker = tracker.New(config.TxPool.Journal, rejournal, eth.blockchain.Config(), eth.txPool)
stack.RegisterLifecycle(eth.localTxTracker) stack.RegisterLifecycle(eth.localTxTracker)
} }
@ -340,8 +341,7 @@ func (s *Ethereum) ResetWithGenesisBlock(gb *types.Block) {
s.blockchain.ResetWithGenesisBlock(gb) s.blockchain.ResetWithGenesisBlock(gb)
} }
func (s *Ethereum) Miner() *miner.Miner { return s.miner } func (s *Ethereum) Miner() *miner.Miner { return s.miner }
func (s *Ethereum) Tracker() *tracking.TxTracker { return s.localTxTracker }
func (s *Ethereum) AccountManager() *accounts.Manager { return s.accountManager } func (s *Ethereum) AccountManager() *accounts.Manager { return s.accountManager }
func (s *Ethereum) BlockChain() *core.BlockChain { return s.blockchain } func (s *Ethereum) BlockChain() *core.BlockChain { return s.blockchain }

Loading…
Cancel
Save