Skip to content
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
2 changes: 1 addition & 1 deletion beacon_chain/conf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ type
name: "discv5" .}: bool

dumpEnabled* {.
desc: "Write SSZ dumps of blocks, attestations and states to data dir"
desc: "Write SSZ dumps of blocks and states to data dir"
defaultValue: false
name: "dump" .}: bool

Expand Down
44 changes: 29 additions & 15 deletions beacon_chain/consensus_object_pools/attestation_pool.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# beacon_chain
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Copyright (c) 2018-2025 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
Expand Down Expand Up @@ -66,6 +66,10 @@ type
## voted on different states - this map keeps track of each vote keyed by
## getAttestationCandidateKey()

CandidateIdxType {.pure.} = enum
phase0Idx
electraIdx

AttestationPool* = object
## The attestation pool keeps track of all attestations that potentially
## could be added to a block during block production.
Expand Down Expand Up @@ -198,11 +202,12 @@ proc addForkChoiceVotes(
# hopefully the fork choice will heal itself over time.
error "Couldn't add attestation to fork choice, bug?", err = v.error()

func candidateIdx(pool: AttestationPool, slot: Slot,
isElectra: bool = false): Opt[int] =
func candidateIdx(
pool: AttestationPool, slot: Slot, candidateIdxType: CandidateIdxType):
Opt[int] =
static: doAssert pool.phase0Candidates.len == pool.electraCandidates.len

let poolLength = if isElectra:
let poolLength = if candidateIdxtype == CandidateIdxType.electraIdx:
pool.electraCandidates.lenu64 else: pool.phase0Candidates.lenu64

if slot >= pool.startingSlot and
Expand Down Expand Up @@ -450,7 +455,14 @@ proc addAttestation*(

updateCurrent(pool, wallTime.slotOrZero)

let candidateIdx = pool.candidateIdx(attestation.data.slot)
when kind(typeof(attestation)) == ConsensusFork.Electra:
let candidateIdx = pool.candidateIdx(
attestation.data.slot, CandidateIdxType.electraIdx)
elif kind(typeof(attestation)) == ConsensusFork.Phase0:
let candidateIdx = pool.candidateIdx(
attestation.data.slot, CandidateIdxType.phase0Idx)
else:
static: doAssert false
if candidateIdx.isNone:
debug "Skipping old attestation for block production",
startingSlot = pool.startingSlot
Expand Down Expand Up @@ -540,7 +552,7 @@ func covers*(
## the existing aggregates, making it redundant
## the `var` attestation pool is needed to use `withValue`, else Table becomes
## unusably inefficient
let candidateIdx = pool.candidateIdx(data.slot)
let candidateIdx = pool.candidateIdx(data.slot, CandidateIdxType.phase0Idx)
if candidateIdx.isNone:
return false

Expand All @@ -558,7 +570,7 @@ func covers*(
## the existing aggregates, making it redundant
## the `var` attestation pool is needed to use `withValue`, else Table becomes
## unusably inefficient
let candidateIdx = pool.candidateIdx(data.slot)
let candidateIdx = pool.candidateIdx(data.slot, CandidateIdxType.electraIdx)
if candidateIdx.isNone:
return false

Expand Down Expand Up @@ -593,7 +605,8 @@ iterator attestations*(
committee_index: Opt[CommitteeIndex]): phase0.Attestation =
let candidateIndices =
if slot.isSome():
let candidateIdx = pool.candidateIdx(slot.get())
let candidateIdx = pool.candidateIdx(
slot.get(), CandidateIdxType.phase0Idx)
if candidateIdx.isSome():
candidateIdx.get() .. candidateIdx.get()
else:
Expand Down Expand Up @@ -622,7 +635,8 @@ iterator electraAttestations*(
committee_index: Opt[CommitteeIndex]): electra.Attestation =
let candidateIndices =
if slot.isSome():
let candidateIdx = pool.candidateIdx(slot.get(), true)
let candidateIdx = pool.candidateIdx(
slot.get(), CandidateIdxType.electraIdx)
if candidateIdx.isSome():
candidateIdx.get() .. candidateIdx.get()
else:
Expand Down Expand Up @@ -795,7 +809,7 @@ proc getAttestationsForBlock*(pool: var AttestationPool,

let
slot = Slot(maxAttestationSlot - i)
candidateIdx = pool.candidateIdx(slot)
candidateIdx = pool.candidateIdx(slot, CandidateIdxType.phase0Idx)

if candidateIdx.isNone():
# Passed the collection horizon - shouldn't happen because it's based on
Expand Down Expand Up @@ -931,7 +945,7 @@ proc getElectraAttestationsForBlock*(

let
slot = Slot(maxAttestationSlot - i)
candidateIdx = pool.candidateIdx(slot)
candidateIdx = pool.candidateIdx(slot, CandidateIdxType.electraIdx)

if candidateIdx.isNone():
# Passed the collection horizon - shouldn't happen because it's based on
Expand Down Expand Up @@ -1096,7 +1110,7 @@ func getElectraAggregatedAttestation*(
Opt[electra.Attestation] =

let
candidateIdx = pool.candidateIdx(slot)
candidateIdx = pool.candidateIdx(slot, CandidateIdxType.electraIdx)
if candidateIdx.isNone:
return Opt.none(electra.Attestation)

Expand Down Expand Up @@ -1124,7 +1138,7 @@ func getElectraAggregatedAttestation*(
# be used here, because otherwise they wouldn't have the same value. It thus
# leaves the cross-committee aggregation for getElectraAttestationsForBlock,
# which does do this.
let candidateIdx = pool.candidateIdx(slot)
let candidateIdx = pool.candidateIdx(slot, CandidateIdxType.electraIdx)
if candidateIdx.isNone:
return Opt.none(electra.Attestation)

Expand All @@ -1147,7 +1161,7 @@ func getPhase0AggregatedAttestation*(
pool: var AttestationPool, slot: Slot, attestation_data_root: Eth2Digest):
Opt[phase0.Attestation] =
let
candidateIdx = pool.candidateIdx(slot)
candidateIdx = pool.candidateIdx(slot, CandidateIdxType.phase0Idx)
if candidateIdx.isNone:
return Opt.none(phase0.Attestation)

Expand All @@ -1168,7 +1182,7 @@ func getPhase0AggregatedAttestation*(
## Select the attestation that has the most votes going for it in the given
## slot/index
## https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/phase0/validator.md#construct-aggregate
let candidateIdx = pool.candidateIdx(slot)
let candidateIdx = pool.candidateIdx(slot, CandidateIdxType.phase0Idx)
if candidateIdx.isNone:
return Opt.none(phase0.Attestation)

Expand Down
6 changes: 3 additions & 3 deletions beacon_chain/sync/sync_queue.nim
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ iterator blocks(
proc push*[T](sq: SyncQueue[T], sr: SyncRequest[T]) =
## Push failed request back to queue.
let pos = sq.find(sr).valueOr:
debug "Request is no more relevant", request = sr
debug "Request is not relevant anymore", request = sr
return
sq.del(pos)

Expand Down Expand Up @@ -768,7 +768,7 @@ proc push*[T](

template findPosition(sq, sr: untyped): SyncPosition =
sq.find(sr).valueOr:
debug "Request is no more relevant",
debug "Request is not relevant anymore",
request = sr, sync_ident = sq.ident, topics = "syncman"
# Request is not in queue anymore, probably reset happened.
return
Expand All @@ -790,7 +790,7 @@ proc push*[T](
let res = await sq.waitForChanges()
if res:
# SyncQueue reset happen
debug "Request is no more relevant, reset happen",
debug "Request is not relevant anymore, reset has happened",
request = sr,
sync_ident = sq.ident,
topics = "syncman"
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/validator_client/block_service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ proc addOrReplaceProposers*(vc: ValidatorClientRef, epoch: Epoch,

for task in epochDuties.duties:
if task notin duties:
# Task is no more relevant, so cancel it.
# Task is not relevant anymore, so cancel it.
debug "Cancelling running proposal duty tasks",
slot = task.duty.slot,
pubkey = shortLog(task.duty.pubkey)
Expand Down
2 changes: 1 addition & 1 deletion docs/the_nimbus_book/src/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ The following options are available:
keys of the validators what to sign and when) and load the validators in the
beacon node itself [=true].
--discv5 Enable Discovery v5 [=true].
--dump Write SSZ dumps of blocks, attestations and states to data dir [=false].
--dump Write SSZ dumps of blocks and states to data dir [=false].
--direct-peer The list of privileged, secure and known peers to connect and maintain the
connection to. This requires a not random netkey-file. In the multiaddress
format like: /ip4/<address>/tcp/<port>/p2p/<peerId-public-key>, or enr format
Expand Down
Loading