Skip to content

Commit

Permalink
core/txpool/legacypool: respect nolocals-setting (#28435) (#640)
Browse files Browse the repository at this point in the history
commit ethereum/go-ethereum@14a1e96.

This change adds a check to ensure that transactions added to the legacy pool
are not treated as 'locals' if the global locals-management has been disabled.

This change makes the pool enforce the --txpool.nolocals setting.

Co-authored-by: jp-imx <[email protected]>
  • Loading branch information
minh-bq and jp-imx authored Dec 5, 2024
1 parent 824d4a8 commit 50d831d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
3 changes: 3 additions & 0 deletions core/txpool/legacypool/legacypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,9 @@ func (pool *LegacyPool) AddRemote(tx *types.Transaction) error {

// Add attempts to queue a batch of transactions if they are valid.
func (pool *LegacyPool) Add(txs []*types.Transaction, local, sync bool) []error {
// Do not treat as local if local transactions have been disabled
local = local && !pool.config.NoLocals

// Filter out known ones without obtaining the pool lock or recovering signatures
var (
errs = make([]error, len(txs))
Expand Down
45 changes: 45 additions & 0 deletions core/txpool/legacypool/legacypool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,51 @@ func TestRepricing(t *testing.T) {
}
}

func TestMinGasPriceEnforced(t *testing.T) {
t.Parallel()

// Create the pool to test the pricing enforcement with
statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
// blockchain := newTestBlockChain(eip1559Config, 10000000, statedb, new(event.Feed))
blockchain := &testBlockChain{1000000, statedb, new(event.Feed), 0}

txPoolConfig := DefaultConfig
txPoolConfig.NoLocals = true
pool := New(txPoolConfig, params.TestChainConfig, blockchain)
pool.Init(txPoolConfig.PriceLimit, blockchain.CurrentBlock().Header(), func(addr common.Address, reserve bool) error { return nil })
defer pool.Close()

key, _ := crypto.GenerateKey()
testAddBalance(pool, crypto.PubkeyToAddress(key.PublicKey), big.NewInt(1000000))

tx := pricedTransaction(0, 100000, big.NewInt(2), key)
pool.SetGasTip(big.NewInt(tx.GasPrice().Int64() + 1))

if err := pool.AddLocal(tx); !errors.Is(err, txpool.ErrUnderpriced) {
t.Fatalf("Min tip not enforced")
}

if err := pool.Add([]*types.Transaction{tx}, true, false)[0]; !errors.Is(err, txpool.ErrUnderpriced) {
t.Fatalf("Min tip not enforced")
}

tx = dynamicFeeTx(0, 100000, big.NewInt(3), big.NewInt(2), key)
pool.SetGasTip(big.NewInt(tx.GasTipCap().Int64() + 1))

if err := pool.AddLocal(tx); !errors.Is(err, txpool.ErrUnderpriced) {
t.Fatalf("Min tip not enforced")
}

if err := pool.Add([]*types.Transaction{tx}, true, false)[0]; !errors.Is(err, txpool.ErrUnderpriced) {
t.Fatalf("Min tip not enforced")
}
// Make sure the tx is accepted if locals are enabled
pool.config.NoLocals = false
if err := pool.Add([]*types.Transaction{tx}, true, false)[0]; err != nil {
t.Fatalf("Min tip enforced with locals enabled, error: %v", err)
}
}

// Tests that setting the transaction pool gas price to a higher value correctly
// discards everything cheaper (legacy & dynamic fee) than that and moves any
// gapped transactions back from the pending pool to the queue.
Expand Down
2 changes: 1 addition & 1 deletion tests/testdata

0 comments on commit 50d831d

Please sign in to comment.