@@ -37,6 +37,7 @@ type ConnsOptions struct {
3737 ShouldBroadcastBlocks bool
3838 ShouldBroadcastBlockHashes bool
3939 BroadcastWorkers int
40+ TxBatchTimeout time.Duration
4041}
4142
4243// Conns manages a collection of active peer connections for transaction broadcasting.
@@ -72,6 +73,9 @@ type Conns struct {
7273
7374 // txBroadcastCh is a buffered channel for async transaction broadcast
7475 txBroadcastCh chan types.Transactions
76+
77+ // txBatchTimeout is the timeout for batching transactions before broadcast
78+ txBatchTimeout time.Duration
7579}
7680
7781// NewConns creates a new connection manager with a blocks cache.
@@ -82,6 +86,11 @@ func NewConns(opts ConnsOptions) *Conns {
8286 oldest := & ds.Locked [* types.Header ]{}
8387 oldest .Set (opts .Head .Block .Header ())
8488
89+ txBatchTimeout := opts .TxBatchTimeout
90+ if txBatchTimeout <= 0 {
91+ txBatchTimeout = 500 * time .Millisecond
92+ }
93+
8594 c := & Conns {
8695 conns : make (map [string ]* conn ),
8796 blocks : ds.NewLRU [common.Hash , BlockCache ](opts .BlocksCache ),
@@ -95,6 +104,7 @@ func NewConns(opts ConnsOptions) *Conns {
95104 shouldBroadcastBlocks : opts .ShouldBroadcastBlocks ,
96105 shouldBroadcastBlockHashes : opts .ShouldBroadcastBlockHashes ,
97106 txBroadcastCh : make (chan types.Transactions , 100000 ),
107+ txBatchTimeout : txBatchTimeout ,
98108 }
99109
100110 workers := opts .BroadcastWorkers
@@ -311,7 +321,7 @@ func (c *Conns) pullTxBatch() (types.Transactions, []common.Hash) {
311321 }
312322
313323 // Drain more until max size or timeout
314- timer := time .NewTimer (100 * time . Millisecond )
324+ timer := time .NewTimer (c . txBatchTimeout )
315325 defer timer .Stop ()
316326
317327 for batchSize < maxTxPacketSize {
0 commit comments