Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove more int64 usage #2369

Merged
merged 2 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions beacon_chain/attestation_pool.nim
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,19 @@ 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:
# 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)) ..
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we introduce some saturated math type?

As is, this needs a comment explaining why we complexify things, the bounds are quite tricky here:

  • inclusive end, which lead to off by 1
  • need to think about unsigned underflow
  • need to start at 1 and so need to filter out 0 from the range

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8825b9a

There's already toGaugeValue() and clamp(); what would this saturated type add? Most of the remaining items in #2366 need non-saturating arithmetic, to the extent they're issues at all (e.g., I only included the genesis time one for completion).

newBlockSlot:
let maybeSlotData = getAttestationsForSlot(pool, i.Slot)
if maybeSlotData.isSome:
insert(attestations, maybeSlotData.get.attestations)
Expand Down
3 changes: 1 addition & 2 deletions beacon_chain/validators/validator_duties.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down