Skip to content

Commit

Permalink
fix panic if config duration is set to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
darioush committed Jan 24, 2025
1 parent a087e40 commit 77147ce
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 21 deletions.
2 changes: 1 addition & 1 deletion plugin/evm/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func newTxGossipHandler[T gossip.Gossipable](
maxMessageSize int,
throttlingPeriod time.Duration,
throttlingLimit int,
validators *p2p.Validators,
validators p2p.ValidatorSet,
) txGossipHandler {
// push gossip messages can be handled from any peer
handler := gossip.NewHandler(
Expand Down
19 changes: 19 additions & 0 deletions plugin/evm/validators.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package evm

import (
"context"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/set"
)

type validatorSet struct {
set set.Set[ids.NodeID]
}

func (v *validatorSet) Has(ctx context.Context, nodeID ids.NodeID) bool {
return v.set.Contains(nodeID)
}
55 changes: 35 additions & 20 deletions plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,11 @@ func (vm *VM) initBlockBuilding() error {
vm.builder = vm.NewBlockBuilder(vm.toEngine)
vm.builder.awaitSubmittedTxs()

var p2pValidators p2p.ValidatorSet = &validatorSet{}
if vm.config.PullGossipFrequency.Duration > 0 {
p2pValidators = vm.p2pValidators
}

if vm.ethTxGossipHandler == nil {
vm.ethTxGossipHandler = newTxGossipHandler[*GossipEthTx](
vm.ctx.Log,
Expand All @@ -1129,7 +1134,7 @@ func (vm *VM) initBlockBuilding() error {
txGossipTargetMessageSize,
txGossipThrottlingPeriod,
txGossipThrottlingLimit,
vm.p2pValidators,
p2pValidators,
)
}

Expand All @@ -1146,7 +1151,7 @@ func (vm *VM) initBlockBuilding() error {
txGossipTargetMessageSize,
txGossipThrottlingPeriod,
txGossipThrottlingLimit,
vm.p2pValidators,
p2pValidators,
)
}

Expand All @@ -1171,15 +1176,20 @@ func (vm *VM) initBlockBuilding() error {
}
}

vm.shutdownWg.Add(2)
go func() {
gossip.Every(ctx, vm.ctx.Log, ethTxPushGossiper, vm.config.PushGossipFrequency.Duration)
vm.shutdownWg.Done()
}()
go func() {
gossip.Every(ctx, vm.ctx.Log, vm.ethTxPullGossiper, vm.config.PullGossipFrequency.Duration)
vm.shutdownWg.Done()
}()
if vm.config.PushGossipFrequency.Duration > 0 {
vm.shutdownWg.Add(1)
go func() {
gossip.Every(ctx, vm.ctx.Log, ethTxPushGossiper, vm.config.PushGossipFrequency.Duration)
vm.shutdownWg.Done()
}()
}
if vm.config.PullGossipFrequency.Duration > 0 {
vm.shutdownWg.Add(1)
go func() {
gossip.Every(ctx, vm.ctx.Log, vm.ethTxPullGossiper, vm.config.PullGossipFrequency.Duration)
vm.shutdownWg.Done()
}()
}

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

vm.shutdownWg.Add(2)
go func() {
gossip.Every(ctx, vm.ctx.Log, vm.atomicTxPushGossiper, vm.config.PushGossipFrequency.Duration)
vm.shutdownWg.Done()
}()
go func() {
gossip.Every(ctx, vm.ctx.Log, vm.atomicTxPullGossiper, vm.config.PullGossipFrequency.Duration)
vm.shutdownWg.Done()
}()
if vm.config.PushGossipFrequency.Duration > 0 {
vm.shutdownWg.Add(1)
go func() {
gossip.Every(ctx, vm.ctx.Log, vm.atomicTxPushGossiper, vm.config.PushGossipFrequency.Duration)
vm.shutdownWg.Done()
}()
}
if vm.config.PullGossipFrequency.Duration > 0 {
vm.shutdownWg.Add(1)
go func() {
gossip.Every(ctx, vm.ctx.Log, vm.atomicTxPullGossiper, vm.config.PullGossipFrequency.Duration)
vm.shutdownWg.Done()
}()
}

return nil
}
Expand Down

0 comments on commit 77147ce

Please sign in to comment.