go-ethereum/core/txpool
Daniel Liu 1dd09427ed
core/txpool: fix global MinGasPrice override and single test failure, fix #1881 (#1880)
Since commit 845d3d49e (July 2023), MinGasPrice validation (250000000 wei /
0.25 Gwei) has been enforced for all non-special transactions in validateTx().
Later, commit 141cb75c (Dec 2025) refactored this validation logic into the
standalone ValidateTransactionWithState() function for code reusability.

However, the transaction pool test suite was never updated to comply with the
MinGasPrice requirement and continued using extremely low gas prices (1-6 wei),
causing test failures when run independently.

The root cause of this issue was that testQueueTimeLimiting() set the global
variable 'common.MinGasPrice = big.NewInt(0)' without restoring it. This global
variable modification created severe testing problems:

1. Intermittent, non-deterministic failures: The same test would randomly pass
   or fail without any code changes, depending on whether testQueueTimeLimiting
   had executed and set MinGasPrice=0 before other tests checked it

2. Race conditions in concurrent execution: Since tests use t.Parallel(), multiple
   tests could simultaneously access the shared global MinGasPrice variable,
   creating unpredictable timing-dependent behavior

3. Test order dependency: When running 'make test', if testQueueTimeLimiting
   executed early and set MinGasPrice=0, other tests with low gas prices would
   pass. Running the same tests individually or in a different order would fail
   with 'under min gas price' errors

4. Global state pollution: The MinGasPrice modification affected ALL concurrently
   running tests in the suite, violating test isolation principles and making
   debugging extremely difficult

5. Masked real validation issues: The global override hid the fact that test
   transactions violated MinGasPrice requirements that would be enforced in
   production, reducing test effectiveness

6. No cleanup mechanism: The changed value was never restored, permanently
   affecting subsequent tests and creating cascading failures

This intermittent behavior made CI/CD pipelines unreliable - tests could pass
locally but fail in CI, or pass on retry without changes, wasting developer time
investigating 'phantom' failures.

This commit systematically updates all affected test cases to use gas prices
that satisfy the MinGasPrice requirement:

- Replace transaction() helper calls with pricedTransaction() using gas prices
  >= 250000000 wei (MinGasPrice)
- Update dynamicFeeTx() calls to use gasFeeCap and gasTipCap >= 250000000 wei
- Scale account balances proportionally to cover the higher transaction costs
- Maintain test logic and relative price relationships between transactions

Tests fixed (36 total):
- TestStateChangeDuringReset
- TestInvalidTransactions
- TestChainFork
- TestDoubleNonce
- TestMissingNonce
- TestNonceRecovery
- TestPostponing
- TestGapFilling
- TestQueueAccountLimiting
- TestQueueGlobalLimiting
- TestQueueGlobalLimitingNoLocals
- TestQueueTimeLimiting
- TestQueueTimeLimitingNoLocals
- TestPendingLimiting
- TestPendingGlobalLimiting
- TestAllowedTxSize
- TestCapClearsFromAll
- TestPendingMinimumAllowance
- TestRepricing
- TestRepricingDynamicFee
- TestRepricingKeepsLocals
- TestPoolUnderpricing
- TestPoolStableUnderpricing
- TestUnderpricingDynamicFee
- TestDualHeapEviction
- TestDeduplication
- TestReplacement
- TestReplacementDynamicFee
- TestJournaling
- TestJournalingNoLocals
- TestStatusCheck
- TestDropping
- TestQueue
- TestQueue2
- TestNegativeValue
- TestSlotCount

All tests now pass consistently when run with: go test ./core/txpool -count=1
2025-12-22 12:01:21 +05:30
..
journal.go all: fix typos, close XFN-23 (#1725) 2025-11-14 20:02:34 +05:30
lending_pool.go all: change chain head markers from block to header #26777 (#1846) 2025-12-16 07:36:51 +04:00
lending_pool_test.go all: fix whitespace error of golangci-lint, remove extra empty lines (#1676) 2025-11-17 11:16:09 +05:30
lending_tx_journal.go all: fix typos, close XFN-23 (#1725) 2025-11-14 20:02:34 +05:30
lending_tx_list.go core/txpool: remove a redundant heap.Init #28910 (#1706) 2025-12-07 15:47:20 +05:30
list.go core/txpool: disallow future churn by remote txs #26907 (#1860) 2025-12-16 11:05:39 +04:00
list_test.go core/txpool: remove a redundant heap.Init #28910 (#1706) 2025-12-07 15:47:20 +05:30
noncer.go all: refactor txpool into it's own package in prep for 4844 (#26038) 2024-11-01 11:36:53 +08:00
order_pool.go all: change chain head markers from block to header #26777 (#1846) 2025-12-16 07:36:51 +04:00
order_tx_journal.go all: fix typos, close XFN-23 (#1725) 2025-11-14 20:02:34 +05:30
order_tx_list.go core/txpool: remove a redundant heap.Init #28910 (#1706) 2025-12-07 15:47:20 +05:30
txpool.go all: implement eip-7702 set code tx #30078 (#1759) 2025-12-19 14:09:45 +04:00
txpool2_test.go core/txpool: disallow future churn by remote txs #26907 (#1860) 2025-12-16 11:05:39 +04:00
txpool_test.go core/txpool: fix global MinGasPrice override and single test failure, fix #1881 (#1880) 2025-12-22 12:01:21 +05:30