1717package txpool
1818
1919import (
20- "context"
2120 "errors"
2221 "fmt"
2322 "math/big"
@@ -77,32 +76,22 @@ type TxPool struct {
7776 term chan struct {} // Termination channel to detect a closed pool
7877
7978 sync chan chan error // Testing / simulator channel to block until internal reset is done
80-
81- ingressFilters []IngressFilter // List of filters to apply to incoming transactions
82-
83- filterCtx context.Context // Filters may use external resources
84- filterCancel context.CancelFunc // Filter calls are cancelled on shutdown
8579}
8680
8781// New creates a new transaction pool to gather, sort and filter inbound
8882// transactions from the network.
89- func New (gasTip uint64 , chain BlockChain , subpools []SubPool , poolFilters []IngressFilter ) (* TxPool , error ) {
83+ func New (gasTip uint64 , chain BlockChain , subpools []SubPool , ingressFilters []IngressFilter ) (* TxPool , error ) {
9084 // Retrieve the current head so that all subpools and this main coordinator
9185 // pool will have the same starting state, even if the chain moves forward
9286 // during initialization.
9387 head := chain .CurrentBlock ()
9488
95- filterCtx , filterCancel := context .WithCancel (context .Background ())
96-
9789 pool := & TxPool {
98- subpools : subpools ,
99- reservations : make (map [common.Address ]SubPool ),
100- quit : make (chan chan error ),
101- term : make (chan struct {}),
102- sync : make (chan chan error ),
103- ingressFilters : poolFilters ,
104- filterCtx : filterCtx ,
105- filterCancel : filterCancel ,
90+ subpools : subpools ,
91+ reservations : make (map [common.Address ]SubPool ),
92+ quit : make (chan chan error ),
93+ term : make (chan struct {}),
94+ sync : make (chan chan error ),
10695 }
10796 for i , subpool := range subpools {
10897 if err := subpool .Init (gasTip , head , pool .reserver (i , subpool )); err != nil {
@@ -111,6 +100,8 @@ func New(gasTip uint64, chain BlockChain, subpools []SubPool, poolFilters []Ingr
111100 }
112101 return nil , err
113102 }
103+ // Set the ingress filters for the subpool
104+ subpool .SetIngressFilters (ingressFilters )
114105 }
115106 go pool .loop (head , chain )
116107 return pool , nil
@@ -166,8 +157,6 @@ func (p *TxPool) reserver(id int, subpool SubPool) AddressReserver {
166157func (p * TxPool ) Close () error {
167158 var errs []error
168159
169- p .filterCancel () // Cancel filter work, these in-flight txs will be not be allowed through before shutdown
170-
171160 // Terminate the reset loop and wait for it to finish
172161 errc := make (chan error )
173162 p .quit <- errc
@@ -350,23 +339,11 @@ func (p *TxPool) Add(txs []*types.Transaction, sync bool) []error {
350339 // so we can piece back the returned errors into the original order.
351340 txsets := make ([][]* types.Transaction , len (p .subpools ))
352341 splits := make ([]int , len (txs ))
353- filtered_out := make ([]bool , len (txs ))
354342
355343 for i , tx := range txs {
356344 // Mark this transaction belonging to no-subpool
357345 splits [i ] = - 1
358346
359- // Filter the transaction through the ingress filters
360- for _ , f := range p .ingressFilters {
361- if ! f .FilterTx (p .filterCtx , tx ) {
362- filtered_out [i ] = true
363- }
364- }
365- // if the transaction is filtered out, don't add it to any subpool
366- if filtered_out [i ] {
367- continue
368- }
369-
370347 // Try to find a subpool that accepts the transaction
371348 for j , subpool := range p .subpools {
372349 if subpool .Filter (tx ) {
@@ -384,11 +361,6 @@ func (p *TxPool) Add(txs []*types.Transaction, sync bool) []error {
384361 }
385362 errs := make ([]error , len (txs ))
386363 for i , split := range splits {
387- // If the transaction was filtered out, mark it as such
388- if filtered_out [i ] {
389- errs [i ] = core .ErrTxFilteredOut
390- continue
391- }
392364 // If the transaction was rejected by all subpools, mark it unsupported
393365 if split == - 1 {
394366 errs [i ] = fmt .Errorf ("%w: received type %d" , core .ErrTxTypeNotSupported , txs [i ].Type ())
0 commit comments