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

explicitly refer to phase0.{Attestation,TrustedAttestation} rather than sans module name #6214

Merged
merged 1 commit into from
Apr 17, 2024
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/beacon_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type
EventBus* = object
headQueue*: AsyncEventQueue[HeadChangeInfoObject]
blocksQueue*: AsyncEventQueue[EventBeaconBlockObject]
attestQueue*: AsyncEventQueue[Attestation]
attestQueue*: AsyncEventQueue[phase0.Attestation]
exitQueue*: AsyncEventQueue[SignedVoluntaryExit]
blsToExecQueue*: AsyncEventQueue[SignedBLSToExecutionChange]
propSlashQueue*: AsyncEventQueue[ProposerSlashing]
Expand Down
44 changes: 23 additions & 21 deletions beacon_chain/consensus_object_pools/attestation_pool.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const
## that potentially could be added to a newly created block

type
OnAttestationCallback = proc(data: Attestation) {.gcsafe, raises: [].}
OnAttestationCallback = proc(data: phase0.Attestation) {.gcsafe, raises: [].}

Validation = object
## Validations collect a set of signatures for a distict attestation - in
Expand Down Expand Up @@ -222,8 +222,9 @@ func oneIndex(bits: CommitteeValidatorsBits): Opt[int] =
return Opt.none(int)
res

func toAttestation(entry: AttestationEntry, validation: Validation): Attestation =
Attestation(
func toAttestation(entry: AttestationEntry, validation: Validation):
phase0.Attestation =
phase0.Attestation(
aggregation_bits: validation.aggregation_bits,
data: entry.data,
signature: validation.aggregate_signature.finish().toValidatorSig()
Expand Down Expand Up @@ -293,7 +294,7 @@ func covers(entry: AttestationEntry, bits: CommitteeValidatorsBits): bool =
false

proc addAttestation(entry: var AttestationEntry,
attestation: Attestation,
attestation: phase0.Attestation,
signature: CookedSig): bool =
logScope:
attestation = shortLog(attestation)
Expand Down Expand Up @@ -335,7 +336,7 @@ proc addAttestation(entry: var AttestationEntry,
true

proc addAttestation*(pool: var AttestationPool,
attestation: Attestation,
attestation: phase0.Attestation,
attesting_indices: openArray[ValidatorIndex],
signature: CookedSig,
wallTime: BeaconTime) =
Expand Down Expand Up @@ -419,8 +420,9 @@ proc addForkChoice*(pool: var AttestationPool,
error "Couldn't add block to fork choice, bug?",
blck = shortLog(blck), err = state.error

iterator attestations*(pool: AttestationPool, slot: Opt[Slot],
committee_index: Opt[CommitteeIndex]): Attestation =
iterator attestations*(
pool: AttestationPool, slot: Opt[Slot],
committee_index: Opt[CommitteeIndex]): phase0.Attestation =
let candidateIndices =
if slot.isSome():
let candidateIdx = pool.candidateIdx(slot.get())
Expand All @@ -434,7 +436,7 @@ iterator attestations*(pool: AttestationPool, slot: Opt[Slot],
for candidateIndex in candidateIndices:
for _, entry in pool.candidates[candidateIndex]:
if committee_index.isNone() or entry.data.index == committee_index.get():
var singleAttestation = Attestation(
var singleAttestation = phase0.Attestation(
aggregation_bits: CommitteeValidatorsBits.init(entry.committee_len),
data: entry.data)

Expand Down Expand Up @@ -555,7 +557,7 @@ proc check_attestation_compatible*(

proc getAttestationsForBlock*(pool: var AttestationPool,
state: ForkyHashedBeaconState,
cache: var StateCache): seq[Attestation] =
cache: var StateCache): seq[phase0.Attestation] =
## Retrieve attestations that may be added to a new block at the slot of the
## given state
## https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/phase0/validator.md#attestations
Expand Down Expand Up @@ -641,7 +643,7 @@ proc getAttestationsForBlock*(pool: var AttestationPool,
state.data.previous_epoch_attestations.maxLen -
state.data.previous_epoch_attestations.len()

var res: seq[Attestation]
var res: seq[phase0.Attestation]
let totalCandidates = candidates.len()
while candidates.len > 0 and res.lenu64() < MAX_ATTESTATIONS:
let entryCacheKey = block:
Expand Down Expand Up @@ -698,7 +700,7 @@ proc getAttestationsForBlock*(pool: var AttestationPool,

proc getAttestationsForBlock*(pool: var AttestationPool,
state: ForkedHashedBeaconState,
cache: var StateCache): seq[Attestation] =
cache: var StateCache): seq[phase0.Attestation] =
withState(state):
pool.getAttestationsForBlock(forkyState, cache)

Expand All @@ -717,13 +719,13 @@ func bestValidation(aggregates: openArray[Validation]): (int, int) =
bestIndex = i
(bestIndex, best)

func getAggregatedAttestation*(pool: var AttestationPool,
slot: Slot,
attestation_data_root: Eth2Digest): Opt[Attestation] =
func getAggregatedAttestation*(
pool: var AttestationPool, slot: Slot, attestation_data_root: Eth2Digest):
Opt[phase0.Attestation] =
let
candidateIdx = pool.candidateIdx(slot)
if candidateIdx.isNone:
return Opt.none(Attestation)
return Opt.none(phase0.Attestation)

pool.candidates[candidateIdx.get].withValue(attestation_data_root, entry):
entry[].updateAggregates()
Expand All @@ -733,19 +735,19 @@ func getAggregatedAttestation*(pool: var AttestationPool,
# Found the right hash, no need to look further
return Opt.some(entry[].toAttestation(entry[].aggregates[bestIndex]))

Opt.none(Attestation)
Opt.none(phase0.Attestation)

func getAggregatedAttestation*(pool: var AttestationPool,
slot: Slot,
index: CommitteeIndex): Opt[Attestation] =
func getAggregatedAttestation*(
pool: var AttestationPool, slot: Slot, index: CommitteeIndex):
Opt[phase0.Attestation] =
## 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)
if candidateIdx.isNone:
return Opt.none(Attestation)
return Opt.none(phase0.Attestation)

var res: Opt[Attestation]
var res: Opt[phase0.Attestation]
for _, entry in pool.candidates[candidateIdx.get].mpairs():
doAssert entry.data.slot == slot
if index != entry.data.index:
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/consensus_object_pools/spec_cache.nim
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ iterator get_attesting_indices*(shufflingRef: ShufflingRef,
yield validator_index

iterator get_attesting_indices*(
dag: ChainDAGRef, attestation: TrustedAttestation): ValidatorIndex =
dag: ChainDAGRef, attestation: phase0.TrustedAttestation): ValidatorIndex =
block: # `return` is not allowed in an inline iterator
let
slot =
Expand Down
4 changes: 2 additions & 2 deletions beacon_chain/gossip_processing/eth2_processor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ proc clearDoppelgangerProtection*(self: var Eth2Processor) =
self.doppelgangerDetection.broadcastStartEpoch = FAR_FUTURE_EPOCH

proc checkForPotentialDoppelganger(
self: var Eth2Processor, attestation: Attestation,
self: var Eth2Processor, attestation: phase0.Attestation,
attesterIndices: openArray[ValidatorIndex]) =
# Only check for attestations after node launch. There might be one slot of
# overlap in quick intra-slot restarts so trade off a few true negatives in
Expand All @@ -364,7 +364,7 @@ proc checkForPotentialDoppelganger(

proc processAttestation*(
self: ref Eth2Processor, src: MsgSource,
attestation: Attestation, subnet_id: SubnetId,
attestation: phase0.Attestation, subnet_id: SubnetId,
checkSignature: bool = true): Future[ValidationRes] {.async: (raises: [CancelledError]).} =
var wallTime = self.getCurrentBeaconTime()
let (afterGenesis, wallSlot) = wallTime.toSlot()
Expand Down
5 changes: 3 additions & 2 deletions beacon_chain/gossip_processing/gossip_validation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ func check_beacon_and_target_block(
ok(target)

func check_aggregation_count(
attestation: Attestation, singular: bool): Result[void, ValidationError] =
attestation: phase0.Attestation, singular: bool):
Result[void, ValidationError] =
let ones = attestation.aggregation_bits.countOnes()
if singular and ones != 1:
return errReject("Attestation must have a single attestation bit set")
Expand Down Expand Up @@ -650,7 +651,7 @@ proc validateBeaconBlock*(
proc validateAttestation*(
pool: ref AttestationPool,
batchCrypto: ref BatchCrypto,
attestation: Attestation,
attestation: phase0.Attestation,
wallTime: BeaconTime,
subnet_id: SubnetId, checkSignature: bool):
Future[Result[
Expand Down
4 changes: 2 additions & 2 deletions beacon_chain/networking/eth2_network.nim
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ template gossipMaxSize(T: untyped): uint32 =
# Attestation, AttesterSlashing, and SignedAggregateAndProof, which all
# have lists bounded at MAX_VALIDATORS_PER_COMMITTEE (2048) items, thus
# having max sizes significantly smaller than GOSSIP_MAX_SIZE.
elif T is Attestation or T is AttesterSlashing or
elif T is phase0.Attestation or T is AttesterSlashing or
T is SignedAggregateAndProof or T is phase0.SignedBeaconBlock or
T is altair.SignedBeaconBlock or T is SomeForkyLightClientObject:
GOSSIP_MAX_SIZE
Expand Down Expand Up @@ -2565,7 +2565,7 @@ proc getWallEpoch(node: Eth2Node): Epoch =
node.getBeaconTime().slotOrZero.epoch

proc broadcastAttestation*(
node: Eth2Node, subnet_id: SubnetId, attestation: Attestation):
node: Eth2Node, subnet_id: SubnetId, attestation: phase0.Attestation):
Future[SendResult] {.async: (raises: [CancelledError], raw: true).} =
# Regardless of the contents of the attestation,
# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/altair/p2p-interface.md#transitioning-the-gossip
Expand Down
4 changes: 2 additions & 2 deletions beacon_chain/nimbus_beacon_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ proc initFullNode(
getBeaconTime: GetBeaconTimeFn) {.async.} =
template config(): auto = node.config

proc onAttestationReceived(data: Attestation) =
proc onAttestationReceived(data: phase0.Attestation) =
node.eventBus.attestQueue.emit(data)
proc onSyncContribution(data: SignedContributionAndProof) =
node.eventBus.contribQueue.emit(data)
Expand Down Expand Up @@ -1753,7 +1753,7 @@ proc installMessageValidators(node: BeaconNode) =
let subnet_id = it
node.network.addAsyncValidator(
getAttestationTopic(digest, subnet_id), proc (
attestation: Attestation
attestation: phase0.Attestation
): Future[ValidationResult] {.async: (raises: [CancelledError]).} =
return toValidationResult(
await node.processor.processAttestation(
Expand Down
4 changes: 2 additions & 2 deletions beacon_chain/rpc/rest_beacon_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
Opt.some(rslot.get())
else:
Opt.none(Slot)
var res: seq[Attestation]
var res: seq[phase0.Attestation]
for item in node.attestationPool[].attestations(vslot, vindex):
res.add(item)
RestApiResponse.jsonResponse(res)
Expand All @@ -1204,7 +1204,7 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
block:
if contentBody.isNone():
return RestApiResponse.jsonError(Http400, EmptyRequestBodyError)
let dres = decodeBody(seq[Attestation], contentBody.get())
let dres = decodeBody(seq[phase0.Attestation], contentBody.get())
if dres.isErr():
return RestApiResponse.jsonError(Http400,
InvalidAttestationObjectError,
Expand Down
10 changes: 5 additions & 5 deletions beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ createJsonFlavor RestJson

RestJson.useDefaultSerializationFor(
AggregateAndProof,
Attestation,
AttestationData,
AttesterSlashing,
BLSToExecutionChange,
Expand Down Expand Up @@ -180,7 +179,6 @@ RestJson.useDefaultSerializationFor(
SyncCommittee,
SyncCommitteeContribution,
SyncCommitteeMessage,
TrustedAttestation,
Validator,
ValidatorRegistrationV1,
VoluntaryExit,
Expand Down Expand Up @@ -258,10 +256,12 @@ RestJson.useDefaultSerializationFor(
electra_mev.ExecutionPayloadAndBlobsBundle,
electra_mev.SignedBlindedBeaconBlock,
electra_mev.SignedBuilderBid,
phase0.Attestation,
phase0.BeaconBlock,
phase0.BeaconBlockBody,
phase0.BeaconState,
phase0.SignedBeaconBlock,
phase0.TrustedAttestation
)

# TODO
Expand Down Expand Up @@ -349,7 +349,7 @@ type
ForkedMaybeBlindedBeaconBlock

EncodeArrays* =
seq[Attestation] |
seq[phase0.Attestation] |
seq[PrepareBeaconProposer] |
seq[RemoteKeystoreInfo] |
seq[RestCommitteeSubscription] |
Expand Down Expand Up @@ -1705,7 +1705,7 @@ proc readValue*(reader: var JsonReader[RestJson],
Opt[List[ProposerSlashing, Limit MAX_PROPOSER_SLASHINGS]]
attester_slashings:
Opt[List[AttesterSlashing, Limit MAX_ATTESTER_SLASHINGS]]
attestations: Opt[List[Attestation, Limit MAX_ATTESTATIONS]]
attestations: Opt[List[phase0.Attestation, Limit MAX_ATTESTATIONS]]
deposits: Opt[List[Deposit, Limit MAX_DEPOSITS]]
voluntary_exits: Opt[List[SignedVoluntaryExit, Limit MAX_VOLUNTARY_EXITS]]
sync_aggregate: Opt[SyncAggregate]
Expand Down Expand Up @@ -1749,7 +1749,7 @@ proc readValue*(reader: var JsonReader[RestJson],
reader.raiseUnexpectedField("Multiple `attestations` fields found",
"RestPublishedBeaconBlockBody")
attestations = Opt.some(
reader.readValue(List[Attestation, Limit MAX_ATTESTATIONS]))
reader.readValue(List[phase0.Attestation, Limit MAX_ATTESTATIONS]))
of "deposits":
if deposits.isSome():
reader.raiseUnexpectedField("Multiple `deposits` fields found",
Expand Down
3 changes: 2 additions & 1 deletion beacon_chain/spec/eth2_apis/rest_beacon_calls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ proc getPoolAttestations*(
meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Beacon/getPoolAttestations

proc submitPoolAttestations*(body: seq[Attestation]): RestPlainResponse {.
proc submitPoolAttestations*(body: seq[phase0.Attestation]):
RestPlainResponse {.
rest, endpoint: "/eth/v1/beacon/pool/attestations",
meth: MethodPost.}
## https://ethereum.github.io/beacon-APIs/#/Beacon/submitPoolAttestations
Expand Down
6 changes: 3 additions & 3 deletions beacon_chain/spec/eth2_apis/rest_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,9 @@ type

# Types based on the OAPI yaml file - used in responses to requests
GetBeaconHeadResponse* = DataEnclosedObject[Slot]
GetAggregatedAttestationResponse* = DataEnclosedObject[Attestation]
GetAggregatedAttestationResponse* = DataEnclosedObject[phase0.Attestation]
GetAttesterDutiesResponse* = DataRootEnclosedObject[seq[RestAttesterDuty]]
GetBlockAttestationsResponse* = DataEnclosedObject[seq[Attestation]]
GetBlockAttestationsResponse* = DataEnclosedObject[seq[phase0.Attestation]]
GetBlockHeaderResponse* = DataOptimisticAndFinalizedObject[RestBlockHeaderInfo]
GetBlockHeadersResponse* = DataEnclosedObject[seq[RestBlockHeaderInfo]]
GetBlockRootResponse* = DataOptimisticObject[RestRoot]
Expand All @@ -553,7 +553,7 @@ type
GetPeerCountResponse* = DataMetaEnclosedObject[RestPeerCount]
GetPeerResponse* = DataMetaEnclosedObject[RestNodePeer]
GetPeersResponse* = DataMetaEnclosedObject[seq[RestNodePeer]]
GetPoolAttestationsResponse* = DataEnclosedObject[seq[Attestation]]
GetPoolAttestationsResponse* = DataEnclosedObject[seq[phase0.Attestation]]
GetPoolAttesterSlashingsResponse* = DataEnclosedObject[seq[AttesterSlashing]]
GetPoolProposerSlashingsResponse* = DataEnclosedObject[seq[ProposerSlashing]]
GetPoolVoluntaryExitsResponse* = DataEnclosedObject[seq[SignedVoluntaryExit]]
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/spec/mev/electra_mev.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type
graffiti*: GraffitiBytes
proposer_slashings*: List[ProposerSlashing, Limit MAX_PROPOSER_SLASHINGS]
attester_slashings*: List[AttesterSlashing, Limit MAX_ATTESTER_SLASHINGS]
attestations*: List[Attestation, Limit MAX_ATTESTATIONS]
attestations*: List[phase0.Attestation, Limit MAX_ATTESTATIONS]
deposits*: List[Deposit, Limit MAX_DEPOSITS]
voluntary_exits*: List[SignedVoluntaryExit, Limit MAX_VOLUNTARY_EXITS]
sync_aggregate*: SyncAggregate
Expand Down
Loading
Loading