Skip to content

Commit c99659b

Browse files
authored
Larger tx announce queue for trusted peers (#1781)
* Larger tx announce queue for trusted peers Allows the node to allocate more buffer (x10) for txn announcements for trusted and static peers. Larger queue reduces the possibility a transaction might get dropped by the node when there is a surge of txns in the network. * Add specific comment
1 parent 1606594 commit c99659b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

eth/protocols/eth/broadcast.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ func (p *Peer) announceTransactions() {
142142
fail = make(chan error, 1) // Channel used to receive network error
143143
failed bool // Flag whether a send failed, discard everything onward
144144
)
145+
146+
queueLimit := maxQueuedTxAnns
147+
if p.IsTrusted() || p.IsStatic() {
148+
queueLimit = maxQueuedTxAnnsTrusted
149+
}
150+
145151
for {
146152
// If there's no in-flight announce running, check if a new one is needed
147153
if done == nil && len(queue) > 0 {
@@ -197,9 +203,9 @@ func (p *Peer) announceTransactions() {
197203
}
198204
// New batch of transactions to be broadcast, queue them (with cap)
199205
queue = append(queue, hashes...)
200-
if len(queue) > maxQueuedTxAnns {
206+
if len(queue) > queueLimit {
201207
// Fancy copy and resize to ensure buffer doesn't grow indefinitely
202-
queue = queue[:copy(queue, queue[len(queue)-maxQueuedTxAnns:])]
208+
queue = queue[:copy(queue, queue[len(queue)-queueLimit:])]
203209
}
204210

205211
case <-done:

eth/protocols/eth/peer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ const (
4545
// before dropping older announcements.
4646
maxQueuedTxAnns = 4096
4747

48+
// maxQueuedTxAnnsTrusted is the maximum number of transaction announcements to queue up before dropping older announcements for trusted and static peers. Specific to Bor.
49+
maxQueuedTxAnnsTrusted = 40960
50+
4851
// maxQueuedBlocks is the maximum number of block propagations to queue up before
4952
// dropping broadcasts. There's not much point in queueing stale blocks, so a few
5053
// that might cover uncles should be enough.

0 commit comments

Comments
 (0)