Skip to content

Commit

Permalink
change peer count after setupEventHandling
Browse files Browse the repository at this point in the history
  • Loading branch information
nkryuchkov committed Dec 9, 2024
1 parent 1fb160d commit c1ed6e5
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions cli/operator/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,35 +164,6 @@ var StartNodeCmd = &cobra.Command{
nodeStorage, operatorData := setupOperatorStorage(logger, db, operatorPrivKey, operatorPrivKeyText)
operatorDataStore := operatordatastore.New(operatorData)

// Increase MaxPeers if the operator is subscribed to many subnets.
// TODO: use OperatorCommittees when it's fixed.
const (
baseMaxPeers = 60
maxPeersLimit = 150
peersPerSubnet = 3
)
start := time.Now()
myValidators := nodeStorage.ValidatorStore().OperatorValidators(operatorData.ID)
mySubnets := make(records.Subnets, networkcommons.SubnetsCount)
myActiveSubnets := 0
for _, v := range myValidators {
subnet := networkcommons.CommitteeSubnet(v.CommitteeID())
if mySubnets[subnet] == 0 {
mySubnets[subnet] = 1
myActiveSubnets++
}
}
idealMaxPeers := min(baseMaxPeers+peersPerSubnet*myActiveSubnets, maxPeersLimit)
if cfg.P2pNetworkConfig.MaxPeers < idealMaxPeers {
logger.Warn("increasing MaxPeers to match the operator's subscribed subnets",
zap.Int("old_max_peers", cfg.P2pNetworkConfig.MaxPeers),
zap.Int("new_max_peers", idealMaxPeers),
zap.Int("subscribed_subnets", myActiveSubnets),
zap.Duration("took", time.Since(start)),
)
cfg.P2pNetworkConfig.MaxPeers = idealMaxPeers
}

usingLocalEvents := len(cfg.LocalEventsPath) != 0

if err := validateConfig(nodeStorage, networkConfig.NetworkName(), usingLocalEvents); err != nil {
Expand Down Expand Up @@ -367,6 +338,35 @@ var StartNodeCmd = &cobra.Command{
nodeProber.AddNode("event syncer", eventSyncer)
}

// Increase MaxPeers if the operator is subscribed to many subnets.
// TODO: use OperatorCommittees when it's fixed.
const (
baseMaxPeers = 60
maxPeersLimit = 150
peersPerSubnet = 3
)
start := time.Now()
myValidators := nodeStorage.ValidatorStore().OperatorValidators(operatorData.ID)
mySubnets := make(records.Subnets, networkcommons.SubnetsCount)
myActiveSubnets := 0
for _, v := range myValidators {
subnet := networkcommons.CommitteeSubnet(v.CommitteeID())
if mySubnets[subnet] == 0 {
mySubnets[subnet] = 1
myActiveSubnets++
}
}
idealMaxPeers := min(baseMaxPeers+peersPerSubnet*myActiveSubnets, maxPeersLimit)
if cfg.P2pNetworkConfig.MaxPeers < idealMaxPeers {
logger.Warn("increasing MaxPeers to match the operator's subscribed subnets",
zap.Int("old_max_peers", cfg.P2pNetworkConfig.MaxPeers),
zap.Int("new_max_peers", idealMaxPeers),
zap.Int("subscribed_subnets", myActiveSubnets),
zap.Duration("took", time.Since(start)),
)
cfg.P2pNetworkConfig.MaxPeers = idealMaxPeers
}

cfg.P2pNetworkConfig.GetValidatorStats = func() (uint64, uint64, uint64, error) {
return validatorCtrl.GetValidatorStats()
}
Expand Down

0 comments on commit c1ed6e5

Please sign in to comment.