29
29
ErrTxRecentlyCommitted = errors .New ("tx was recently committed" )
30
30
)
31
31
32
+ // InclusionDelay is the amount of time a transaction must be in the mempool
33
+ // before it is included in the block.
34
+ const InclusionDelay = time .Second
35
+
32
36
// TxPoolOption sets an optional parameter on the TxPool.
33
37
type TxPoolOption func (* TxPool )
34
38
@@ -452,9 +456,16 @@ func (txmp *TxPool) allEntriesSorted() []*wrappedTx {
452
456
// constraints, the result will also be empty.
453
457
func (txmp * TxPool ) ReapMaxBytesMaxGas (maxBytes , maxGas int64 ) types.Txs {
454
458
var totalGas , totalBytes int64
459
+ currentTime := time .Now ()
455
460
456
461
var keep []types.Tx //nolint:prealloc
457
462
for _ , w := range txmp .allEntriesSorted () {
463
+ // skip transactions that have been in the mempool for less than the inclusion delay
464
+ // This gives time for the transaction to be broadcast to all peers
465
+ if currentTime .Sub (w .timestamp ) < InclusionDelay {
466
+ break
467
+ }
468
+
458
469
// N.B. When computing byte size, we need to include the overhead for
459
470
// encoding as protobuf to send to the application. This actually overestimates it
460
471
// as we add the proto overhead to each transaction
@@ -479,8 +490,11 @@ func (txmp *TxPool) ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs {
479
490
// does not have that many transactions available.
480
491
func (txmp * TxPool ) ReapMaxTxs (max int ) types.Txs {
481
492
var keep []types.Tx //nolint:prealloc
482
-
493
+ currentTime := time . Now ()
483
494
for _ , w := range txmp .allEntriesSorted () {
495
+ if currentTime .Sub (w .timestamp ) < InclusionDelay {
496
+ break
497
+ }
484
498
if max >= 0 && len (keep ) >= max {
485
499
break
486
500
}
0 commit comments