Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit 3148809

Browse files
author
Darioush Jalali
authored
fix panic if config duration is set to 0 (#765)
1 parent 9e729ab commit 3148809

File tree

3 files changed

+55
-21
lines changed

3 files changed

+55
-21
lines changed

plugin/evm/gossip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func newTxGossipHandler[T gossip.Gossipable](
4949
maxMessageSize int,
5050
throttlingPeriod time.Duration,
5151
throttlingLimit int,
52-
validators *p2p.Validators,
52+
validators p2p.ValidatorSet,
5353
) txGossipHandler {
5454
// push gossip messages can be handled from any peer
5555
handler := gossip.NewHandler(

plugin/evm/validators.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
4+
package evm
5+
6+
import (
7+
"context"
8+
9+
"github.com/ava-labs/avalanchego/ids"
10+
"github.com/ava-labs/avalanchego/utils/set"
11+
)
12+
13+
type validatorSet struct {
14+
set set.Set[ids.NodeID]
15+
}
16+
17+
func (v *validatorSet) Has(ctx context.Context, nodeID ids.NodeID) bool {
18+
return v.set.Contains(nodeID)
19+
}

plugin/evm/vm.go

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,11 @@ func (vm *VM) initBlockBuilding() error {
11201120
vm.builder = vm.NewBlockBuilder(vm.toEngine)
11211121
vm.builder.awaitSubmittedTxs()
11221122

1123+
var p2pValidators p2p.ValidatorSet = &validatorSet{}
1124+
if vm.config.PullGossipFrequency.Duration > 0 {
1125+
p2pValidators = vm.p2pValidators
1126+
}
1127+
11231128
if vm.ethTxGossipHandler == nil {
11241129
vm.ethTxGossipHandler = newTxGossipHandler[*GossipEthTx](
11251130
vm.ctx.Log,
@@ -1129,7 +1134,7 @@ func (vm *VM) initBlockBuilding() error {
11291134
txGossipTargetMessageSize,
11301135
txGossipThrottlingPeriod,
11311136
txGossipThrottlingLimit,
1132-
vm.p2pValidators,
1137+
p2pValidators,
11331138
)
11341139
}
11351140

@@ -1146,7 +1151,7 @@ func (vm *VM) initBlockBuilding() error {
11461151
txGossipTargetMessageSize,
11471152
txGossipThrottlingPeriod,
11481153
txGossipThrottlingLimit,
1149-
vm.p2pValidators,
1154+
p2pValidators,
11501155
)
11511156
}
11521157

@@ -1171,15 +1176,20 @@ func (vm *VM) initBlockBuilding() error {
11711176
}
11721177
}
11731178

1174-
vm.shutdownWg.Add(2)
1175-
go func() {
1176-
gossip.Every(ctx, vm.ctx.Log, ethTxPushGossiper, vm.config.PushGossipFrequency.Duration)
1177-
vm.shutdownWg.Done()
1178-
}()
1179-
go func() {
1180-
gossip.Every(ctx, vm.ctx.Log, vm.ethTxPullGossiper, vm.config.PullGossipFrequency.Duration)
1181-
vm.shutdownWg.Done()
1182-
}()
1179+
if vm.config.PushGossipFrequency.Duration > 0 {
1180+
vm.shutdownWg.Add(1)
1181+
go func() {
1182+
gossip.Every(ctx, vm.ctx.Log, ethTxPushGossiper, vm.config.PushGossipFrequency.Duration)
1183+
vm.shutdownWg.Done()
1184+
}()
1185+
}
1186+
if vm.config.PullGossipFrequency.Duration > 0 {
1187+
vm.shutdownWg.Add(1)
1188+
go func() {
1189+
gossip.Every(ctx, vm.ctx.Log, vm.ethTxPullGossiper, vm.config.PullGossipFrequency.Duration)
1190+
vm.shutdownWg.Done()
1191+
}()
1192+
}
11831193

11841194
if vm.atomicTxPullGossiper == nil {
11851195
atomicTxPullGossiper := gossip.NewPullGossiper[*atomic.GossipAtomicTx](
@@ -1198,15 +1208,20 @@ func (vm *VM) initBlockBuilding() error {
11981208
}
11991209
}
12001210

1201-
vm.shutdownWg.Add(2)
1202-
go func() {
1203-
gossip.Every(ctx, vm.ctx.Log, vm.atomicTxPushGossiper, vm.config.PushGossipFrequency.Duration)
1204-
vm.shutdownWg.Done()
1205-
}()
1206-
go func() {
1207-
gossip.Every(ctx, vm.ctx.Log, vm.atomicTxPullGossiper, vm.config.PullGossipFrequency.Duration)
1208-
vm.shutdownWg.Done()
1209-
}()
1211+
if vm.config.PushGossipFrequency.Duration > 0 {
1212+
vm.shutdownWg.Add(1)
1213+
go func() {
1214+
gossip.Every(ctx, vm.ctx.Log, vm.atomicTxPushGossiper, vm.config.PushGossipFrequency.Duration)
1215+
vm.shutdownWg.Done()
1216+
}()
1217+
}
1218+
if vm.config.PullGossipFrequency.Duration > 0 {
1219+
vm.shutdownWg.Add(1)
1220+
go func() {
1221+
gossip.Every(ctx, vm.ctx.Log, vm.atomicTxPullGossiper, vm.config.PullGossipFrequency.Duration)
1222+
vm.shutdownWg.Done()
1223+
}()
1224+
}
12101225

12111226
return nil
12121227
}

0 commit comments

Comments
 (0)