Skip to content

Commit

Permalink
update to rate
Browse files Browse the repository at this point in the history
  • Loading branch information
arnetheduck committed Oct 24, 2022
1 parent f9d06f0 commit a77ee75
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions beacon_chain/networking/eth2_network.nim
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ const
maxGlobalQuota = 2 * maxRequestQuota
## Roughly, this means we allow 2 peers to sync from us at a time
fullReplenishTime = 5.seconds
replenishRate = (maxRequestQuota / fullReplenishTime.nanoseconds.float)

template awaitQuota*(peerParam: Peer, costParam: float) =
let
Expand All @@ -435,6 +434,7 @@ template awaitQuota*(networkParam: Eth2Node, costParam: float) =
await network.quota.consume(cost.int)

func allowedOpsPerSecondCost*(n: int): float =
const replenishRate = (maxRequestQuota / fullReplenishTime.nanoseconds.float)
(replenishRate * 1000000000'f / n.float)

const
Expand Down Expand Up @@ -1727,7 +1727,7 @@ proc new(T: type Eth2Node,
rng: rng,
connectTimeout: connectTimeout,
seenThreshold: seenThreshold,
quota: TokenBucket.new(maxGlobalQuota, int(replenishRate / 1000))
quota: TokenBucket.new(maxGlobalQuota, fullReplenishTime)
)

newSeq node.protocolStates, allProtocols.len
Expand Down Expand Up @@ -1847,7 +1847,7 @@ proc init(T: type Peer, network: Eth2Node, peerId: PeerId): Peer =
lastReqTime: now(chronos.Moment),
lastMetadataTime: now(chronos.Moment),
protocolStates: newSeq[RootRef](len(allProtocols)),
quota: TokenBucket.new(maxRequestQuota.int, int(replenishRate / 1000))
quota: TokenBucket.new(maxRequestQuota.int, fullReplenishTime)
)
for i in 0 ..< len(allProtocols):
let proto = allProtocols[i]
Expand Down
2 changes: 1 addition & 1 deletion vendor/nim-chronos

0 comments on commit a77ee75

Please sign in to comment.