17
17
package txpool
18
18
19
19
import (
20
- "context"
21
20
"errors"
22
21
"fmt"
23
22
"math/big"
@@ -77,32 +76,22 @@ type TxPool struct {
77
76
term chan struct {} // Termination channel to detect a closed pool
78
77
79
78
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
85
79
}
86
80
87
81
// New creates a new transaction pool to gather, sort and filter inbound
88
82
// 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 ) {
90
84
// Retrieve the current head so that all subpools and this main coordinator
91
85
// pool will have the same starting state, even if the chain moves forward
92
86
// during initialization.
93
87
head := chain .CurrentBlock ()
94
88
95
- filterCtx , filterCancel := context .WithCancel (context .Background ())
96
-
97
89
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 ),
106
95
}
107
96
for i , subpool := range subpools {
108
97
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
111
100
}
112
101
return nil , err
113
102
}
103
+ // Set the ingress filters for the subpool
104
+ subpool .SetIngressFilters (ingressFilters )
114
105
}
115
106
go pool .loop (head , chain )
116
107
return pool , nil
@@ -166,8 +157,6 @@ func (p *TxPool) reserver(id int, subpool SubPool) AddressReserver {
166
157
func (p * TxPool ) Close () error {
167
158
var errs []error
168
159
169
- p .filterCancel () // Cancel filter work, these in-flight txs will be not be allowed through before shutdown
170
-
171
160
// Terminate the reset loop and wait for it to finish
172
161
errc := make (chan error )
173
162
p .quit <- errc
@@ -350,23 +339,11 @@ func (p *TxPool) Add(txs []*types.Transaction, sync bool) []error {
350
339
// so we can piece back the returned errors into the original order.
351
340
txsets := make ([][]* types.Transaction , len (p .subpools ))
352
341
splits := make ([]int , len (txs ))
353
- filtered_out := make ([]bool , len (txs ))
354
342
355
343
for i , tx := range txs {
356
344
// Mark this transaction belonging to no-subpool
357
345
splits [i ] = - 1
358
346
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
-
370
347
// Try to find a subpool that accepts the transaction
371
348
for j , subpool := range p .subpools {
372
349
if subpool .Filter (tx ) {
@@ -384,11 +361,6 @@ func (p *TxPool) Add(txs []*types.Transaction, sync bool) []error {
384
361
}
385
362
errs := make ([]error , len (txs ))
386
363
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
- }
392
364
// If the transaction was rejected by all subpools, mark it unsupported
393
365
if split == - 1 {
394
366
errs [i ] = fmt .Errorf ("%w: received type %d" , core .ErrTxTypeNotSupported , txs [i ].Type ())
0 commit comments