From 7b45710f5b99fb290fb7bce6412fa4d442b9daa0 Mon Sep 17 00:00:00 2001 From: Dustin Brody Date: Tue, 2 Mar 2021 07:24:18 +0100 Subject: [PATCH 1/2] remove more int64 usage --- beacon_chain/attestation_pool.nim | 7 ++++--- beacon_chain/validators/validator_duties.nim | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/beacon_chain/attestation_pool.nim b/beacon_chain/attestation_pool.nim index eed280a12f..819a75435f 100644 --- a/beacon_chain/attestation_pool.nim +++ b/beacon_chain/attestation_pool.nim @@ -351,13 +351,14 @@ proc getAttestationsForBlock*(pool: var AttestationPool, cache: var StateCache): seq[Attestation] = ## Retrieve attestations that may be added to a new block at the slot of the ## given state - let newBlockSlot = state.slot + let newBlockSlot = state.slot.uint64 var attestations: seq[AttestationEntry] pool.updateAttestationsCache(state) - for i in max(1, newBlockSlot.int64 - ATTESTATION_LOOKBACK.int64) .. - newBlockSlot.int64: + for i in max( + 1'u64, newBlockSlot - min(newBlockSlot, ATTESTATION_LOOKBACK)) .. + newBlockSlot: let maybeSlotData = getAttestationsForSlot(pool, i.Slot) if maybeSlotData.isSome: insert(attestations, maybeSlotData.get.attestations) diff --git a/beacon_chain/validators/validator_duties.nim b/beacon_chain/validators/validator_duties.nim index be340acc82..6816bee404 100644 --- a/beacon_chain/validators/validator_duties.nim +++ b/beacon_chain/validators/validator_duties.nim @@ -583,8 +583,7 @@ proc updateValidatorMetrics*(node: BeaconNode) = if i < 64: attached_validator_balance.set( - min(balance, int64.high.uint64).int64, - labelValues = [shortLog(v.pubkey)]) + balance.toGaugeValue, labelValues = [shortLog(v.pubkey)]) else: inc i total += balance From 8825b9ad09bbb67ba782bd0988e85c9b89570b8c Mon Sep 17 00:00:00 2001 From: Dustin Brody Date: Tue, 2 Mar 2021 12:31:00 +0100 Subject: [PATCH 2/2] explain loop bounds --- beacon_chain/attestation_pool.nim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/beacon_chain/attestation_pool.nim b/beacon_chain/attestation_pool.nim index 819a75435f..dfe4ad9fa7 100644 --- a/beacon_chain/attestation_pool.nim +++ b/beacon_chain/attestation_pool.nim @@ -356,6 +356,11 @@ proc getAttestationsForBlock*(pool: var AttestationPool, pool.updateAttestationsCache(state) + # Consider attestations from the current slot and ranging back up to + # ATTESTATION_LOOKBACK slots, excluding the special genesis slot. As + # unsigned subtraction (mostly avoided in this codebase, partly as a + # consequence) will otherwise wrap through zero, clamp value which's + # subtracted so that slots through ATTESTATION_LOOKBACK don't do so. for i in max( 1'u64, newBlockSlot - min(newBlockSlot, ATTESTATION_LOOKBACK)) .. newBlockSlot: