Skip to content

Commit 61baf6d

Browse files
Clean up gossip batching/frequency (#1253)
1 parent 845aaa4 commit 61baf6d

File tree

3 files changed

+8
-20
lines changed

3 files changed

+8
-20
lines changed

plugin/evm/block_builder.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,6 @@ import (
1717
)
1818

1919
const (
20-
// waitBlockTime is the amount of time to wait for BuildBlock to be
21-
// called by the engine before deciding whether or not to gossip the
22-
// transaction that triggered the PendingTxs message to the engine.
23-
//
24-
// This is done to reduce contention in the network when there is no
25-
// preferred producer. If we did not wait here, we may gossip a new
26-
// transaction to a peer while building a block that will conflict with
27-
// whatever the peer makes.
28-
waitBlockTime = 100 * time.Millisecond
29-
3020
// Minimum amount of time to wait after building a block before attempting to build a block
3121
// a second time without changing the contents of the mempool.
3222
minBlockBuildingRetryDelay = 500 * time.Millisecond
@@ -168,9 +158,6 @@ func (b *blockBuilder) awaitSubmittedTxs() {
168158
b.signalTxsReady()
169159

170160
if b.gossiper != nil && len(ethTxsEvent.Txs) > 0 {
171-
// Give time for this node to build a block before attempting to
172-
// gossip
173-
time.Sleep(waitBlockTime)
174161
// [GossipEthTxs] will block unless [gossiper.ethTxsToGossipChan] (an
175162
// unbuffered channel) is listened on
176163
if err := b.gossiper.GossipEthTxs(ethTxsEvent.Txs); err != nil {
@@ -186,9 +173,6 @@ func (b *blockBuilder) awaitSubmittedTxs() {
186173

187174
newTxs := b.mempool.GetNewTxs()
188175
if b.gossiper != nil && len(newTxs) > 0 {
189-
// Give time for this node to build a block before attempting to
190-
// gossip
191-
time.Sleep(waitBlockTime)
192176
if err := b.gossiper.GossipAtomicTxs(newTxs); err != nil {
193177
log.Warn(
194178
"failed to gossip new atomic transactions",

plugin/evm/gossiper.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ const (
3636
// [ethTxsGossipInterval] is how often we attempt to gossip newly seen
3737
// transactions to other nodes.
3838
ethTxsGossipInterval = 500 * time.Millisecond
39+
40+
// [minGossipBatchInterval] is the minimum amount of time that must pass
41+
// before our last gossip to peers.
42+
minGossipBatchInterval = 50 * time.Millisecond
3943
)
4044

4145
// Gossiper handles outgoing gossip of transactions
@@ -326,7 +330,7 @@ func (n *pushGossiper) sendEthTxs(txs []*types.Transaction) error {
326330
}
327331

328332
func (n *pushGossiper) gossipEthTxs(force bool) (int, error) {
329-
if (!force && time.Since(n.lastGossiped) < ethTxsGossipInterval) || len(n.ethTxsToGossip) == 0 {
333+
if (!force && time.Since(n.lastGossiped) < minGossipBatchInterval) || len(n.ethTxsToGossip) == 0 {
330334
return 0, nil
331335
}
332336
n.lastGossiped = time.Now()

plugin/evm/gossiper_atomic_gossiping_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestMempoolAtmTxsIssueTxAndGossiping(t *testing.T) {
5858

5959
// Optimistically gossip raw tx
6060
assert.NoError(vm.issueTx(tx, true /*=local*/))
61-
time.Sleep(waitBlockTime * 3)
61+
time.Sleep(500 * time.Millisecond)
6262
gossipedLock.Lock()
6363
assert.Equal(1, gossiped)
6464
gossipedLock.Unlock()
@@ -119,7 +119,7 @@ func TestMempoolAtmTxsAppGossipHandling(t *testing.T) {
119119

120120
// show that no txID is requested
121121
assert.NoError(vm.AppGossip(context.Background(), nodeID, msgBytes))
122-
time.Sleep(waitBlockTime * 3)
122+
time.Sleep(500 * time.Millisecond)
123123

124124
assert.False(txRequested, "tx should not have been requested")
125125
txGossipedLock.Lock()
@@ -218,7 +218,7 @@ func TestMempoolAtmTxsAppGossipHandlingDiscardedTx(t *testing.T) {
218218
assert.NoError(err)
219219

220220
assert.NoError(vm.AppGossip(context.Background(), nodeID, msgBytes))
221-
time.Sleep(waitBlockTime * 3)
221+
time.Sleep(500 * time.Millisecond)
222222
assert.False(txRequested, "tx shouldn't be requested")
223223
txGossipedLock.Lock()
224224
assert.Equal(1, txGossiped, "conflicting tx should have been gossiped")

0 commit comments

Comments
 (0)