Skip to content

Commit 14a1e96

Browse files
authored
core/txpool/legacypool: respect nolocals-setting (#28435)
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.pricelimit setting.
1 parent a737482 commit 14a1e96

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

core/txpool/legacypool/legacypool.go

+3
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,9 @@ func (pool *LegacyPool) addRemoteSync(tx *types.Transaction) error {
959959
// If sync is set, the method will block until all internal maintenance related
960960
// to the add is finished. Only use this during tests for determinism!
961961
func (pool *LegacyPool) Add(txs []*types.Transaction, local, sync bool) []error {
962+
// Do not treat as local if local transactions have been disabled
963+
local = local && !pool.config.NoLocals
964+
962965
// Filter out known ones without obtaining the pool lock or recovering signatures
963966
var (
964967
errs = make([]error, len(txs))

core/txpool/legacypool/legacypool_test.go

+44
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,50 @@ func TestRepricing(t *testing.T) {
14921492
}
14931493
}
14941494

1495+
func TestMinGasPriceEnforced(t *testing.T) {
1496+
t.Parallel()
1497+
1498+
// Create the pool to test the pricing enforcement with
1499+
statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
1500+
blockchain := newTestBlockChain(eip1559Config, 10000000, statedb, new(event.Feed))
1501+
1502+
txPoolConfig := DefaultConfig
1503+
txPoolConfig.NoLocals = true
1504+
pool := New(txPoolConfig, blockchain)
1505+
pool.Init(new(big.Int).SetUint64(txPoolConfig.PriceLimit), blockchain.CurrentBlock(), makeAddressReserver())
1506+
defer pool.Close()
1507+
1508+
key, _ := crypto.GenerateKey()
1509+
testAddBalance(pool, crypto.PubkeyToAddress(key.PublicKey), big.NewInt(1000000))
1510+
1511+
tx := pricedTransaction(0, 100000, big.NewInt(2), key)
1512+
pool.SetGasTip(big.NewInt(tx.GasPrice().Int64() + 1))
1513+
1514+
if err := pool.addLocal(tx); !errors.Is(err, txpool.ErrUnderpriced) {
1515+
t.Fatalf("Min tip not enforced")
1516+
}
1517+
1518+
if err := pool.Add([]*types.Transaction{tx}, true, false)[0]; !errors.Is(err, txpool.ErrUnderpriced) {
1519+
t.Fatalf("Min tip not enforced")
1520+
}
1521+
1522+
tx = dynamicFeeTx(0, 100000, big.NewInt(3), big.NewInt(2), key)
1523+
pool.SetGasTip(big.NewInt(tx.GasTipCap().Int64() + 1))
1524+
1525+
if err := pool.addLocal(tx); !errors.Is(err, txpool.ErrUnderpriced) {
1526+
t.Fatalf("Min tip not enforced")
1527+
}
1528+
1529+
if err := pool.Add([]*types.Transaction{tx}, true, false)[0]; !errors.Is(err, txpool.ErrUnderpriced) {
1530+
t.Fatalf("Min tip not enforced")
1531+
}
1532+
// Make sure the tx is accepted if locals are enabled
1533+
pool.config.NoLocals = false
1534+
if err := pool.Add([]*types.Transaction{tx}, true, false)[0]; err != nil {
1535+
t.Fatalf("Min tip enforced with locals enabled, error: %v", err)
1536+
}
1537+
}
1538+
14951539
// Tests that setting the transaction pool gas price to a higher value correctly
14961540
// discards everything cheaper (legacy & dynamic fee) than that and moves any
14971541
// gapped transactions back from the pending pool to the queue.

0 commit comments

Comments
 (0)