Skip to content

Commit

Permalink
rename config for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic committed Jun 25, 2024
1 parent dfb21bb commit 6a47743
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (
// config/toml.go
// NOTE: libs/cli must know to look in the config dir!
var (
DefaultMaxPercentPeersInSameRegion = float64(0.9) // Target 90% of peers in the same region
DefaultPercentPeersInSameRegion = float64(0.9) // Target 90% of peers in the same region
DefaultRegionQueriesPerPeerQueryPeriod = 20 // Query 20 peers per peer query period (30s), used to prevent hitting rate limit on free API

DefaultTendermintDir = ".cometbft"
Expand Down Expand Up @@ -636,7 +636,7 @@ type P2PConfig struct { //nolint: maligned

// Configs for connecting to peers in the same region
RegionAware bool `mapstructure:"region_aware"`
MaxPercentPeersInSameRegion float64 `mapstructure:"max_percent_peers_in_same_region"`
PercentPeersInSameRegion float64 `mapstructure:"percent_peers_in_same_region"`
RegionQueriesPerPeerQueryPeriod int `mapstructure:"region_queries_per_peer_query_period"`
}

Expand All @@ -663,7 +663,7 @@ func DefaultP2PConfig() *P2PConfig {
TestFuzz: false,
TestFuzzConfig: DefaultFuzzConnConfig(),
RegionAware: false,
MaxPercentPeersInSameRegion: DefaultMaxPercentPeersInSameRegion,
PercentPeersInSameRegion: DefaultPercentPeersInSameRegion,
RegionQueriesPerPeerQueryPeriod: DefaultRegionQueriesPerPeerQueryPeriod,
}
}
Expand Down
10 changes: 5 additions & 5 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,14 @@ allow_duplicate_ip = {{ .P2P.AllowDuplicateIP }}
handshake_timeout = "{{ .P2P.HandshakeTimeout }}"
dial_timeout = "{{ .P2P.DialTimeout }}"
# If region_aware is set to true, the defined max_percent_peers_in_same_region
# is the percent of both inbound and outbound that must be from the same region as this node.
# If region_aware is set to true, the defined percent_peers_in_same_region of the max_num_inbound_peers and
# max_num_outbound_peers must be from the same region as this node.
# The percent can be at max 0.9 (90%), as we hardcode this max to allow cross-geo connectivity.
# E.g. if max_num_inbound_peers and max_num_inbound_peers are both set to 10, and max_percent_peers_in_same_region
# E.g. if max_num_inbound_peers and max_num_inbound_peers are both set to 10, and percent_peers_in_same_region
# is set to 0.9 (90%), then 9 peers must be from the same region as this node, and 1 peer must be from a different region.
region_aware = {{ .P2P.RegionAware }}
max_percent_peers_in_same_region = {{ .P2P.MaxPercentPeersInSameRegion }}
# The amount of times we can query a region for a peer in a given period.
percent_peers_in_same_region = {{ .P2P.PercentPeersInSameRegion }}
# The amount of times we can query a region for a peer in a given ensurePeers period.
# E.g. The current peer query period is hard coded to 30 seconds. If our API rate limits us to 40 queries per minute,
# then we can set this value to 20, preventing us from hitting the rate limit.
region_queries_per_peer_query_period = {{ .P2P.RegionQueriesPerPeerQueryPeriod }}
Expand Down
2 changes: 1 addition & 1 deletion p2p/pex/pex_reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ func (r *Reactor) ensurePeers(regionAware bool) {
swConfig := r.Switch.GetConfig()

currentOutboundInOtherRegion := r.Switch.CurrentNumOutboundPeersInOtherRegion
maxOutboundPeersInOtherRegion := swConfig.MaxNumOutboundPeers - int(swConfig.MaxPercentPeersInSameRegion*float64(swConfig.MaxNumOutboundPeers))
maxOutboundPeersInOtherRegion := swConfig.MaxNumOutboundPeers - int(swConfig.PercentPeersInSameRegion*float64(swConfig.MaxNumOutboundPeers))

numToDialInOtherRegion := maxOutboundPeersInOtherRegion - currentOutboundInOtherRegion
numToDialInSameRegion := numToDial - numToDialInOtherRegion
Expand Down
10 changes: 5 additions & 5 deletions p2p/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ func NewSwitch(
}
sw.MyRegion = myRegion

// Make sure that the MaxPercentPeersInSameRegion does not exceed some hard coded value.
// Make sure that the PercentPeersInSameRegion does not exceed some hard coded value.
// If it does, replace it with the max
if cfg.MaxPercentPeersInSameRegion > 0.9 {
cfg.MaxPercentPeersInSameRegion = config.DefaultMaxPercentPeersInSameRegion
if cfg.PercentPeersInSameRegion > 0.9 {
cfg.PercentPeersInSameRegion = config.DefaultPercentPeersInSameRegion
}
}

Expand Down Expand Up @@ -800,8 +800,8 @@ func (sw *Switch) acceptRoutine() {
isSameRegion := region == sw.MyRegion

// Calculate the maximum allowed peers for both same region and other regions
maxOutboundPeersInSameRegion := int(sw.config.MaxPercentPeersInSameRegion * float64(sw.config.MaxNumOutboundPeers))
maxInboundPeersInSameRegion := int(sw.config.MaxPercentPeersInSameRegion * float64(sw.config.MaxNumInboundPeers))
maxOutboundPeersInSameRegion := int(sw.config.PercentPeersInSameRegion * float64(sw.config.MaxNumOutboundPeers))
maxInboundPeersInSameRegion := int(sw.config.PercentPeersInSameRegion * float64(sw.config.MaxNumInboundPeers))
maxOutboundPeersInOtherRegion := sw.config.MaxNumOutboundPeers - maxOutboundPeersInSameRegion
maxInboundPeersInOtherRegion := sw.config.MaxNumInboundPeers - maxInboundPeersInSameRegion

Expand Down

0 comments on commit 6a47743

Please sign in to comment.