Unverified Commit 950d5643 authored by Péter Szilágyi's avatar Péter Szilágyi Committed by GitHub

core/txpool: make transaction validation reusable across packages (pools) (#27429)

* core/txpool: abstraction prep work for secondary pools (blob pool)

* core/txpool: leave subpool concepts to a followup pr

* les: fix tests using hard coded errors

* core/txpool: use bitmaps instead of maps for tx type filtering
parent 4cf708d3
...@@ -419,7 +419,7 @@ func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend, isCon ...@@ -419,7 +419,7 @@ func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend, isCon
} }
// Set the gas price to the limits from the CLI and start mining // Set the gas price to the limits from the CLI and start mining
gasprice := flags.GlobalBig(ctx, utils.MinerGasPriceFlag.Name) gasprice := flags.GlobalBig(ctx, utils.MinerGasPriceFlag.Name)
ethBackend.TxPool().SetGasPrice(gasprice) ethBackend.TxPool().SetGasTip(gasprice)
if err := ethBackend.StartMining(); err != nil { if err := ethBackend.StartMining(); err != nil {
utils.Fatalf("Failed to start mining: %v", err) utils.Fatalf("Failed to start mining: %v", err)
} }
......
This diff is collapsed.
...@@ -83,7 +83,7 @@ func TestTransactionFutureAttack(t *testing.T) { ...@@ -83,7 +83,7 @@ func TestTransactionFutureAttack(t *testing.T) {
config := testTxPoolConfig config := testTxPoolConfig
config.GlobalQueue = 100 config.GlobalQueue = 100
config.GlobalSlots = 100 config.GlobalSlots = 100
pool := NewTxPool(config, eip1559Config, blockchain) pool := New(config, eip1559Config, blockchain)
defer pool.Stop() defer pool.Stop()
fillPool(t, pool) fillPool(t, pool)
pending, _ := pool.Stats() pending, _ := pool.Stats()
...@@ -116,7 +116,7 @@ func TestTransactionFuture1559(t *testing.T) { ...@@ -116,7 +116,7 @@ func TestTransactionFuture1559(t *testing.T) {
// Create the pool to test the pricing enforcement with // Create the pool to test the pricing enforcement with
statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewMemoryDatabase()), nil) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
blockchain := newTestBlockChain(1000000, statedb, new(event.Feed)) blockchain := newTestBlockChain(1000000, statedb, new(event.Feed))
pool := NewTxPool(testTxPoolConfig, eip1559Config, blockchain) pool := New(testTxPoolConfig, eip1559Config, blockchain)
defer pool.Stop() defer pool.Stop()
// Create a number of test accounts, fund them and make transactions // Create a number of test accounts, fund them and make transactions
...@@ -148,7 +148,7 @@ func TestTransactionZAttack(t *testing.T) { ...@@ -148,7 +148,7 @@ func TestTransactionZAttack(t *testing.T) {
// Create the pool to test the pricing enforcement with // Create the pool to test the pricing enforcement with
statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewMemoryDatabase()), nil) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
blockchain := newTestBlockChain(1000000, statedb, new(event.Feed)) blockchain := newTestBlockChain(1000000, statedb, new(event.Feed))
pool := NewTxPool(testTxPoolConfig, eip1559Config, blockchain) pool := New(testTxPoolConfig, eip1559Config, blockchain)
defer pool.Stop() defer pool.Stop()
// Create a number of test accounts, fund them and make transactions // Create a number of test accounts, fund them and make transactions
fillPool(t, pool) fillPool(t, pool)
...@@ -218,7 +218,7 @@ func BenchmarkFutureAttack(b *testing.B) { ...@@ -218,7 +218,7 @@ func BenchmarkFutureAttack(b *testing.B) {
config := testTxPoolConfig config := testTxPoolConfig
config.GlobalQueue = 100 config.GlobalQueue = 100
config.GlobalSlots = 100 config.GlobalSlots = 100
pool := NewTxPool(config, eip1559Config, blockchain) pool := New(config, eip1559Config, blockchain)
defer pool.Stop() defer pool.Stop()
fillPool(b, pool) fillPool(b, pool)
......
This diff is collapsed.
This diff is collapsed.
...@@ -63,7 +63,7 @@ func (api *MinerAPI) SetGasPrice(gasPrice hexutil.Big) bool { ...@@ -63,7 +63,7 @@ func (api *MinerAPI) SetGasPrice(gasPrice hexutil.Big) bool {
api.e.gasPrice = (*big.Int)(&gasPrice) api.e.gasPrice = (*big.Int)(&gasPrice)
api.e.lock.Unlock() api.e.lock.Unlock()
api.e.txPool.SetGasPrice((*big.Int)(&gasPrice)) api.e.txPool.SetGasTip((*big.Int)(&gasPrice))
return true return true
} }
......
...@@ -206,7 +206,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { ...@@ -206,7 +206,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
if config.TxPool.Journal != "" { if config.TxPool.Journal != "" {
config.TxPool.Journal = stack.ResolvePath(config.TxPool.Journal) config.TxPool.Journal = stack.ResolvePath(config.TxPool.Journal)
} }
eth.txPool = txpool.NewTxPool(config.TxPool, eth.blockchain.Config(), eth.blockchain) eth.txPool = txpool.New(config.TxPool, eth.blockchain.Config(), eth.blockchain)
// Permit the downloader to use the trie cache allowance during fast sync // Permit the downloader to use the trie cache allowance during fast sync
cacheLimit := cacheConfig.TrieCleanLimit + cacheConfig.TrieDirtyLimit + cacheConfig.SnapshotLimit cacheLimit := cacheConfig.TrieCleanLimit + cacheConfig.TrieDirtyLimit + cacheConfig.SnapshotLimit
...@@ -399,7 +399,7 @@ func (s *Ethereum) StartMining() error { ...@@ -399,7 +399,7 @@ func (s *Ethereum) StartMining() error {
s.lock.RLock() s.lock.RLock()
price := s.gasPrice price := s.gasPrice
s.lock.RUnlock() s.lock.RUnlock()
s.txPool.SetGasPrice(price) s.txPool.SetGasTip(price)
// Configure the local mining address // Configure the local mining address
eb, err := s.Etherbase() eb, err := s.Etherbase()
......
...@@ -119,7 +119,7 @@ func newTestBackendWithGenerator(blocks int, shanghai bool, generator func(int, ...@@ -119,7 +119,7 @@ func newTestBackendWithGenerator(blocks int, shanghai bool, generator func(int,
return &testBackend{ return &testBackend{
db: db, db: db,
chain: chain, chain: chain,
txpool: txpool.NewTxPool(txconfig, params.TestChainConfig, chain), txpool: txpool.New(txconfig, params.TestChainConfig, chain),
} }
} }
......
...@@ -611,6 +611,8 @@ func testTransactionStatus(t *testing.T, protocol int) { ...@@ -611,6 +611,8 @@ func testTransactionStatus(t *testing.T, protocol int) {
var reqID uint64 var reqID uint64
test := func(tx *types.Transaction, send bool, expStatus light.TxStatus) { test := func(tx *types.Transaction, send bool, expStatus light.TxStatus) {
t.Helper()
reqID++ reqID++
if send { if send {
sendRequest(rawPeer.app, SendTxV2Msg, reqID, types.Transactions{tx}) sendRequest(rawPeer.app, SendTxV2Msg, reqID, types.Transactions{tx})
...@@ -618,14 +620,14 @@ func testTransactionStatus(t *testing.T, protocol int) { ...@@ -618,14 +620,14 @@ func testTransactionStatus(t *testing.T, protocol int) {
sendRequest(rawPeer.app, GetTxStatusMsg, reqID, []common.Hash{tx.Hash()}) sendRequest(rawPeer.app, GetTxStatusMsg, reqID, []common.Hash{tx.Hash()})
} }
if err := expectResponse(rawPeer.app, TxStatusMsg, reqID, testBufLimit, []light.TxStatus{expStatus}); err != nil { if err := expectResponse(rawPeer.app, TxStatusMsg, reqID, testBufLimit, []light.TxStatus{expStatus}); err != nil {
t.Errorf("transaction status mismatch") t.Errorf("transaction status mismatch: %v", err)
} }
} }
signer := types.HomesteadSigner{} signer := types.HomesteadSigner{}
// test error status by sending an underpriced transaction // test error status by sending an underpriced transaction
tx0, _ := types.SignTx(types.NewTransaction(0, userAddr1, big.NewInt(10000), params.TxGas, nil, nil), signer, bankKey) tx0, _ := types.SignTx(types.NewTransaction(0, userAddr1, big.NewInt(10000), params.TxGas, nil, nil), signer, bankKey)
test(tx0, true, light.TxStatus{Status: txpool.TxStatusUnknown, Error: txpool.ErrUnderpriced.Error()}) test(tx0, true, light.TxStatus{Status: txpool.TxStatusUnknown, Error: "transaction underpriced: tip needed 1, tip permitted 0"})
tx1, _ := types.SignTx(types.NewTransaction(0, userAddr1, big.NewInt(10000), params.TxGas, big.NewInt(100000000000), nil), signer, bankKey) tx1, _ := types.SignTx(types.NewTransaction(0, userAddr1, big.NewInt(10000), params.TxGas, big.NewInt(100000000000), nil), signer, bankKey)
test(tx1, false, light.TxStatus{Status: txpool.TxStatusUnknown}) // query before sending, should be unknown test(tx1, false, light.TxStatus{Status: txpool.TxStatusUnknown}) // query before sending, should be unknown
......
...@@ -234,7 +234,7 @@ func newTestServerHandler(blocks int, indexers []*core.ChainIndexer, db ethdb.Da ...@@ -234,7 +234,7 @@ func newTestServerHandler(blocks int, indexers []*core.ChainIndexer, db ethdb.Da
txpoolConfig := txpool.DefaultConfig txpoolConfig := txpool.DefaultConfig
txpoolConfig.Journal = "" txpoolConfig.Journal = ""
txpool := txpool.NewTxPool(txpoolConfig, gspec.Config, simulation.Blockchain()) txpool := txpool.New(txpoolConfig, gspec.Config, simulation.Blockchain())
server := &LesServer{ server := &LesServer{
lesCommons: lesCommons{ lesCommons: lesCommons{
......
...@@ -267,7 +267,7 @@ func createMiner(t *testing.T) (*Miner, *event.TypeMux, func(skipMiner bool)) { ...@@ -267,7 +267,7 @@ func createMiner(t *testing.T) (*Miner, *event.TypeMux, func(skipMiner bool)) {
statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(chainDB), nil) statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(chainDB), nil)
blockchain := &testBlockChain{statedb, 10000000, new(event.Feed)} blockchain := &testBlockChain{statedb, 10000000, new(event.Feed)}
pool := txpool.NewTxPool(testTxPoolConfig, chainConfig, blockchain) pool := txpool.New(testTxPoolConfig, chainConfig, blockchain)
backend := NewMockBackend(bc, pool) backend := NewMockBackend(bc, pool)
// Create event Mux // Create event Mux
mux := new(event.TypeMux) mux := new(event.TypeMux)
......
...@@ -135,7 +135,7 @@ func newTestWorkerBackend(t *testing.T, chainConfig *params.ChainConfig, engine ...@@ -135,7 +135,7 @@ func newTestWorkerBackend(t *testing.T, chainConfig *params.ChainConfig, engine
return &testWorkerBackend{ return &testWorkerBackend{
db: db, db: db,
chain: chain, chain: chain,
txPool: txpool.NewTxPool(testTxPoolConfig, chainConfig, chain), txPool: txpool.New(testTxPoolConfig, chainConfig, chain),
genesis: gspec, genesis: gspec,
} }
} }
......
...@@ -138,7 +138,7 @@ func newFuzzer(input []byte) *fuzzer { ...@@ -138,7 +138,7 @@ func newFuzzer(input []byte) *fuzzer {
chtKeys: chtKeys, chtKeys: chtKeys,
bloomKeys: bloomKeys, bloomKeys: bloomKeys,
nonce: uint64(len(txHashes)), nonce: uint64(len(txHashes)),
pool: txpool.NewTxPool(txpool.DefaultConfig, params.TestChainConfig, chain), pool: txpool.New(txpool.DefaultConfig, params.TestChainConfig, chain),
input: bytes.NewReader(input), input: bytes.NewReader(input),
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment