From 603c83522e8a5903c04c423ca759ecb7c244c67f Mon Sep 17 00:00:00 2001 From: tersec Date: Wed, 17 Apr 2024 22:44:29 +0200 Subject: [PATCH] explicitly refer to phase0.{Attestation,TrustedAttestation} rather than sans module name (#6214) --- beacon_chain/beacon_node.nim | 2 +- .../attestation_pool.nim | 44 ++++++++++--------- .../consensus_object_pools/spec_cache.nim | 2 +- .../gossip_processing/eth2_processor.nim | 4 +- .../gossip_processing/gossip_validation.nim | 5 ++- beacon_chain/networking/eth2_network.nim | 4 +- beacon_chain/nimbus_beacon_node.nim | 4 +- beacon_chain/rpc/rest_beacon_api.nim | 4 +- .../eth2_apis/eth2_rest_serialization.nim | 10 ++--- .../spec/eth2_apis/rest_beacon_calls.nim | 3 +- beacon_chain/spec/eth2_apis/rest_types.nim | 6 +-- beacon_chain/spec/mev/electra_mev.nim | 2 +- beacon_chain/spec/state_transition.nim | 17 ++++--- beacon_chain/validator_client/api.nim | 4 +- beacon_chain/validator_client/scoring.nim | 4 +- beacon_chain/validators/message_router.nim | 4 +- beacon_chain/validators/validator_duties.nim | 5 ++- beacon_chain/validators/validator_monitor.nim | 2 +- ncli/ncli.nim | 2 +- nfuzz/libnfuzz.nim | 2 +- research/block_sim.nim | 8 ++-- research/wss_sim.nim | 6 +-- .../altair/test_fixture_operations.nim | 4 +- .../phase0/test_fixture_operations.nim | 4 +- .../test_fixture_fork_choice.nim | 4 +- tests/test_attestation_pool.nim | 10 ++--- tests/test_message_signatures.nim | 5 ++- tests/test_toblindedblock.nim | 2 +- tests/test_validator_client.nim | 10 ++--- tests/testblockutil.nim | 16 +++---- 30 files changed, 104 insertions(+), 95 deletions(-) diff --git a/beacon_chain/beacon_node.nim b/beacon_chain/beacon_node.nim index a92f72b10..e54406176 100644 --- a/beacon_chain/beacon_node.nim +++ b/beacon_chain/beacon_node.nim @@ -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] diff --git a/beacon_chain/consensus_object_pools/attestation_pool.nim b/beacon_chain/consensus_object_pools/attestation_pool.nim index d41fa8dc3..d90de3319 100644 --- a/beacon_chain/consensus_object_pools/attestation_pool.nim +++ b/beacon_chain/consensus_object_pools/attestation_pool.nim @@ -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 @@ -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() @@ -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) @@ -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) = @@ -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()) @@ -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) @@ -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 @@ -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: @@ -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) @@ -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() @@ -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: diff --git a/beacon_chain/consensus_object_pools/spec_cache.nim b/beacon_chain/consensus_object_pools/spec_cache.nim index dfbca5d78..b44096eaa 100644 --- a/beacon_chain/consensus_object_pools/spec_cache.nim +++ b/beacon_chain/consensus_object_pools/spec_cache.nim @@ -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 = diff --git a/beacon_chain/gossip_processing/eth2_processor.nim b/beacon_chain/gossip_processing/eth2_processor.nim index c2bfafb05..c00b735e8 100644 --- a/beacon_chain/gossip_processing/eth2_processor.nim +++ b/beacon_chain/gossip_processing/eth2_processor.nim @@ -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 @@ -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() diff --git a/beacon_chain/gossip_processing/gossip_validation.nim b/beacon_chain/gossip_processing/gossip_validation.nim index 991521901..84ee3f8cb 100644 --- a/beacon_chain/gossip_processing/gossip_validation.nim +++ b/beacon_chain/gossip_processing/gossip_validation.nim @@ -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") @@ -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[ diff --git a/beacon_chain/networking/eth2_network.nim b/beacon_chain/networking/eth2_network.nim index ccb300fc4..c24c19c7e 100644 --- a/beacon_chain/networking/eth2_network.nim +++ b/beacon_chain/networking/eth2_network.nim @@ -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 @@ -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 diff --git a/beacon_chain/nimbus_beacon_node.nim b/beacon_chain/nimbus_beacon_node.nim index 85bcd5201..d686a8682 100644 --- a/beacon_chain/nimbus_beacon_node.nim +++ b/beacon_chain/nimbus_beacon_node.nim @@ -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) @@ -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( diff --git a/beacon_chain/rpc/rest_beacon_api.nim b/beacon_chain/rpc/rest_beacon_api.nim index 0a24dad32..404ec62e9 100644 --- a/beacon_chain/rpc/rest_beacon_api.nim +++ b/beacon_chain/rpc/rest_beacon_api.nim @@ -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) @@ -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, diff --git a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim index 7d1fc5e55..434fe9e07 100644 --- a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim +++ b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim @@ -45,7 +45,6 @@ createJsonFlavor RestJson RestJson.useDefaultSerializationFor( AggregateAndProof, - Attestation, AttestationData, AttesterSlashing, BLSToExecutionChange, @@ -180,7 +179,6 @@ RestJson.useDefaultSerializationFor( SyncCommittee, SyncCommitteeContribution, SyncCommitteeMessage, - TrustedAttestation, Validator, ValidatorRegistrationV1, VoluntaryExit, @@ -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 @@ -349,7 +349,7 @@ type ForkedMaybeBlindedBeaconBlock EncodeArrays* = - seq[Attestation] | + seq[phase0.Attestation] | seq[PrepareBeaconProposer] | seq[RemoteKeystoreInfo] | seq[RestCommitteeSubscription] | @@ -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] @@ -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", diff --git a/beacon_chain/spec/eth2_apis/rest_beacon_calls.nim b/beacon_chain/spec/eth2_apis/rest_beacon_calls.nim index d611b1838..62724e382 100644 --- a/beacon_chain/spec/eth2_apis/rest_beacon_calls.nim +++ b/beacon_chain/spec/eth2_apis/rest_beacon_calls.nim @@ -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 diff --git a/beacon_chain/spec/eth2_apis/rest_types.nim b/beacon_chain/spec/eth2_apis/rest_types.nim index 1d9b1191b..06f537094 100644 --- a/beacon_chain/spec/eth2_apis/rest_types.nim +++ b/beacon_chain/spec/eth2_apis/rest_types.nim @@ -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] @@ -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]] diff --git a/beacon_chain/spec/mev/electra_mev.nim b/beacon_chain/spec/mev/electra_mev.nim index e29049819..83d5116ab 100644 --- a/beacon_chain/spec/mev/electra_mev.nim +++ b/beacon_chain/spec/mev/electra_mev.nim @@ -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 diff --git a/beacon_chain/spec/state_transition.nim b/beacon_chain/spec/state_transition.nim index fb9bd2491..13e0ec0d3 100644 --- a/beacon_chain/spec/state_transition.nim +++ b/beacon_chain/spec/state_transition.nim @@ -353,7 +353,7 @@ func partialBeaconBlock*( randao_reveal: ValidatorSig, eth1_data: Eth1Data, graffiti: GraffitiBytes, - attestations: seq[Attestation], + attestations: seq[phase0.Attestation], deposits: seq[Deposit], validator_changes: BeaconBlockValidatorChanges, sync_aggregate: SyncAggregate, @@ -372,7 +372,8 @@ func partialBeaconBlock*( graffiti: graffiti, proposer_slashings: validator_changes.proposer_slashings, attester_slashings: validator_changes.attester_slashings, - attestations: List[Attestation, Limit MAX_ATTESTATIONS](attestations), + attestations: + List[phase0.Attestation, Limit MAX_ATTESTATIONS](attestations), deposits: List[Deposit, Limit MAX_DEPOSITS](deposits), voluntary_exits: validator_changes.voluntary_exits)) @@ -404,7 +405,7 @@ proc makeBeaconBlockWithRewards*( randao_reveal: ValidatorSig, eth1_data: Eth1Data, graffiti: GraffitiBytes, - attestations: seq[Attestation], + attestations: seq[phase0.Attestation], deposits: seq[Deposit], validator_changes: BeaconBlockValidatorChanges, sync_aggregate: SyncAggregate, @@ -462,7 +463,9 @@ proc makeBeaconBlockWithRewards*( hash_tree_root(graffiti), hash_tree_root(validator_changes.proposer_slashings), hash_tree_root(validator_changes.attester_slashings), - hash_tree_root(List[Attestation, Limit MAX_ATTESTATIONS](attestations)), + hash_tree_root( + List[phase0.Attestation, Limit MAX_ATTESTATIONS]( + attestations)), hash_tree_root(List[Deposit, Limit MAX_DEPOSITS](deposits)), hash_tree_root(validator_changes.voluntary_exits), hash_tree_root(sync_aggregate), @@ -508,7 +511,7 @@ proc makeBeaconBlock*( cfg: RuntimeConfig, state: var ForkedHashedBeaconState, proposer_index: ValidatorIndex, randao_reveal: ValidatorSig, eth1_data: Eth1Data, graffiti: GraffitiBytes, - attestations: seq[Attestation], deposits: seq[Deposit], + attestations: seq[phase0.Attestation], deposits: seq[Deposit], validator_changes: BeaconBlockValidatorChanges, sync_aggregate: SyncAggregate, executionPayload: ForkyExecutionPayloadForSigning, @@ -530,7 +533,7 @@ proc makeBeaconBlock*( cfg: RuntimeConfig, state: var ForkedHashedBeaconState, proposer_index: ValidatorIndex, randao_reveal: ValidatorSig, eth1_data: Eth1Data, graffiti: GraffitiBytes, - attestations: seq[Attestation], deposits: seq[Deposit], + attestations: seq[phase0.Attestation], deposits: seq[Deposit], validator_changes: BeaconBlockValidatorChanges, sync_aggregate: SyncAggregate, executionPayload: ForkyExecutionPayloadForSigning, @@ -548,7 +551,7 @@ proc makeBeaconBlock*( cfg: RuntimeConfig, state: var ForkedHashedBeaconState, proposer_index: ValidatorIndex, randao_reveal: ValidatorSig, eth1_data: Eth1Data, graffiti: GraffitiBytes, - attestations: seq[Attestation], deposits: seq[Deposit], + attestations: seq[phase0.Attestation], deposits: seq[Deposit], validator_changes: BeaconBlockValidatorChanges, sync_aggregate: SyncAggregate, executionPayload: ForkyExecutionPayloadForSigning, diff --git a/beacon_chain/validator_client/api.nim b/beacon_chain/validator_client/api.nim index c6263ee30..c27e49217 100644 --- a/beacon_chain/validator_client/api.nim +++ b/beacon_chain/validator_client/api.nim @@ -1489,7 +1489,7 @@ proc produceAttestationData*( proc submitPoolAttestations*( vc: ValidatorClientRef, - data: seq[Attestation], + data: seq[phase0.Attestation], strategy: ApiStrategyKind ): Future[bool] {.async.} = const @@ -1635,7 +1635,7 @@ proc getAggregatedAttestation*( slot: Slot, root: Eth2Digest, strategy: ApiStrategyKind - ): Future[Attestation] {.async.} = + ): Future[phase0.Attestation] {.async.} = const RequestName = "getAggregatedAttestation" diff --git a/beacon_chain/validator_client/scoring.nim b/beacon_chain/validator_client/scoring.nim index c2646ed4b..2b401b25d 100644 --- a/beacon_chain/validator_client/scoring.nim +++ b/beacon_chain/validator_client/scoring.nim @@ -161,7 +161,7 @@ proc getSyncCommitteeMessageDataScore*( vc.rootsSeen, vc.beaconClock.now().slotOrZero(), cdata) proc processVotes(bits: var CommitteeBitsArray, - attestation: Attestation): int = + attestation: phase0.Attestation): int = doAssert(len(attestation.aggregation_bits) <= len(bits)) var res = 0 for index in 0 ..< len(attestation.aggregation_bits): @@ -171,7 +171,7 @@ proc processVotes(bits: var CommitteeBitsArray, bits[index] = true res -proc getUniqueVotes*(attestations: openArray[Attestation]): int = +proc getUniqueVotes*(attestations: openArray[phase0.Attestation]): int = var res = 0 attested: Table[Slot, CommitteeTable] diff --git a/beacon_chain/validators/message_router.nim b/beacon_chain/validators/message_router.nim index dee771a41..30d630a64 100644 --- a/beacon_chain/validators/message_router.nim +++ b/beacon_chain/validators/message_router.nim @@ -191,7 +191,7 @@ proc routeSignedBeaconBlock*( ok(blockRef) proc routeAttestation*( - router: ref MessageRouter, attestation: Attestation, + router: ref MessageRouter, attestation: phase0.Attestation, subnet_id: SubnetId, checkSignature: bool): Future[SendResult] {.async: (raises: [CancelledError]).} = ## Process and broadcast attestation - processing will register the it with @@ -223,7 +223,7 @@ proc routeAttestation*( return ok() proc routeAttestation*( - router: ref MessageRouter, attestation: Attestation): + router: ref MessageRouter, attestation: phase0.Attestation): Future[SendResult] {.async: (raises: [CancelledError]).} = # Compute subnet, then route attestation let diff --git a/beacon_chain/validators/validator_duties.nim b/beacon_chain/validators/validator_duties.nim index 82a04671e..95e9aaef4 100644 --- a/beacon_chain/validators/validator_duties.nim +++ b/beacon_chain/validators/validator_duties.nim @@ -30,8 +30,9 @@ type data*: AttestationData proc toAttestation*( - registered: RegisteredAttestation, signature: ValidatorSig): Attestation = - Attestation.init( + registered: RegisteredAttestation, signature: ValidatorSig): + phase0.Attestation = + phase0.Attestation.init( [registered.index_in_committee], registered.committee_len, registered.data, signature).expect("valid data") diff --git a/beacon_chain/validators/validator_monitor.nim b/beacon_chain/validators/validator_monitor.nim index 0ad7fba7d..7ebb9b3e2 100644 --- a/beacon_chain/validators/validator_monitor.nim +++ b/beacon_chain/validators/validator_monitor.nim @@ -660,7 +660,7 @@ proc registerAttestation*( self: var ValidatorMonitor, src: MsgSource, seen_timestamp: BeaconTime, - attestation: Attestation, + attestation: phase0.Attestation, idx: ValidatorIndex) = let slot = attestation.data.slot diff --git a/ncli/ncli.nim b/ncli/ncli.nim index e706e3a48..2ceefbcb1 100644 --- a/ncli/ncli.nim +++ b/ncli/ncli.nim @@ -233,7 +233,7 @@ proc doSSZ(conf: NcliConf) = case kind of "attester_slashing": printit(AttesterSlashing) - of "attestation": printit(Attestation) + of "attestation": printit(phase0.Attestation) of "phase0_signed_block": printit(phase0.SignedBeaconBlock) of "altair_signed_block": printit(altair.SignedBeaconBlock) of "bellatrix_signed_block": printit(bellatrix.SignedBeaconBlock) diff --git a/nfuzz/libnfuzz.nim b/nfuzz/libnfuzz.nim index b5d1b63e5..7b9565e41 100644 --- a/nfuzz/libnfuzz.nim +++ b/nfuzz/libnfuzz.nim @@ -21,7 +21,7 @@ import type AttestationInput = object state: phase0.BeaconState - attestation: Attestation + attestation: phase0.Attestation AttesterSlashingInput = object state: phase0.BeaconState attesterSlashing: AttesterSlashing diff --git a/research/block_sim.nim b/research/block_sim.nim index bb8823ebc..a58a095cf 100644 --- a/research/block_sim.nim +++ b/research/block_sim.nim @@ -63,7 +63,7 @@ proc makeSimulationBlock( randao_reveal: ValidatorSig, eth1_data: Eth1Data, graffiti: GraffitiBytes, - attestations: seq[Attestation], + attestations: seq[phase0.Attestation], deposits: seq[Deposit], exits: BeaconBlockValidatorChanges, sync_aggregate: SyncAggregate, @@ -106,7 +106,7 @@ proc makeSimulationBlock( randao_reveal: ValidatorSig, eth1_data: Eth1Data, graffiti: GraffitiBytes, - attestations: seq[Attestation], + attestations: seq[phase0.Attestation], deposits: seq[Deposit], exits: BeaconBlockValidatorChanges, sync_aggregate: SyncAggregate, @@ -149,7 +149,7 @@ proc makeSimulationBlock( randao_reveal: ValidatorSig, eth1_data: Eth1Data, graffiti: GraffitiBytes, - attestations: seq[Attestation], + attestations: seq[phase0.Attestation], deposits: seq[Deposit], exits: BeaconBlockValidatorChanges, sync_aggregate: SyncAggregate, @@ -259,7 +259,7 @@ cli do(slots = SLOTS_PER_EPOCH * 7, get_attestation_signature( fork, genesis_validators_root, data, MockPrivKeys[validator_index]) - attestation = Attestation.init( + attestation = phase0.Attestation.init( [uint64 index_in_committee], committee.len, data, sig.toValidatorSig()).expect("valid data") diff --git a/research/wss_sim.nim b/research/wss_sim.nim index 7ea00ba5d..67c91ebab 100644 --- a/research/wss_sim.nim +++ b/research/wss_sim.nim @@ -164,7 +164,7 @@ cli do(validatorsDir: string, secretsDir: string, blockRoot = withState(state[]): forkyState.latest_block_root cache: StateCache info: ForkedEpochInfo - aggregates: seq[Attestation] + aggregates: seq[phase0.Attestation] syncAggregate = SyncAggregate.init() let @@ -341,7 +341,7 @@ cli do(validatorsDir: string, secretsDir: string, forkyState.data, slot, committee_index, cache) var - attestation = Attestation( + attestation = phase0.Attestation( data: makeAttestationData( forkyState.data, slot, committee_index, blockRoot), aggregation_bits: CommitteeValidatorsBits.init(committee.len)) @@ -395,4 +395,4 @@ cli do(validatorsDir: string, secretsDir: string, syncAggregate.sync_committee_bits.setBit(i) if inited: - syncAggregate.sync_committee_signature = finish(agg).toValidatorSig() + syncAggregate.sync_committee_signature = finish(agg).toValidatorSig() \ No newline at end of file diff --git a/tests/consensus_spec/altair/test_fixture_operations.nim b/tests/consensus_spec/altair/test_fixture_operations.nim index 2ebc89410..6565a876a 100644 --- a/tests/consensus_spec/altair/test_fixture_operations.nim +++ b/tests/consensus_spec/altair/test_fixture_operations.nim @@ -70,7 +70,7 @@ proc runTest[T, U]( suite baseDescription & "Attestation " & preset(): proc applyAttestation( - preState: var altair.BeaconState, attestation: Attestation): + preState: var altair.BeaconState, attestation: phase0.Attestation): Result[void, cstring] = var cache: StateCache let @@ -85,7 +85,7 @@ suite baseDescription & "Attestation " & preset(): ok() for path in walkTests(OpAttestationsDir): - runTest[Attestation, typeof applyAttestation]( + runTest[phase0.Attestation, typeof applyAttestation]( OpAttestationsDir, suiteName, "Attestation", "attestation", applyAttestation, path) diff --git a/tests/consensus_spec/phase0/test_fixture_operations.nim b/tests/consensus_spec/phase0/test_fixture_operations.nim index 3e4fbfb1e..aeefa9bd3 100644 --- a/tests/consensus_spec/phase0/test_fixture_operations.nim +++ b/tests/consensus_spec/phase0/test_fixture_operations.nim @@ -68,7 +68,7 @@ proc runTest[T, U]( suite baseDescription & "Attestation " & preset(): proc applyAttestation( - preState: var phase0.BeaconState, attestation: Attestation): + preState: var phase0.BeaconState, attestation: phase0.Attestation): Result[void, cstring] = var cache: StateCache doAssert (? process_attestation( @@ -76,7 +76,7 @@ suite baseDescription & "Attestation " & preset(): ok() for path in walkTests(OpAttestationsDir): - runTest[Attestation, typeof applyAttestation]( + runTest[phase0.Attestation, typeof applyAttestation]( OpAttestationsDir, suiteName, "Attestation", "attestation", applyAttestation, path) diff --git a/tests/consensus_spec/test_fixture_fork_choice.nim b/tests/consensus_spec/test_fixture_fork_choice.nim index 87fdfdd17..1061d1707 100644 --- a/tests/consensus_spec/test_fixture_fork_choice.nim +++ b/tests/consensus_spec/test_fixture_fork_choice.nim @@ -55,7 +55,7 @@ type of opOnTick: tick: int of opOnAttestation: - att: Attestation + att: phase0.Attestation of opOnBlock: blck: ForkedSignedBeaconBlock blobData: Opt[BlobData] @@ -115,7 +115,7 @@ proc loadOps( let filename = step["attestation"].getStr() let att = parseTest( path/filename & ".ssz_snappy", - SSZ, Attestation + SSZ, phase0.Attestation ) result.add Operation(kind: opOnAttestation, att: att) diff --git a/tests/test_attestation_pool.nim b/tests/test_attestation_pool.nim index 2a74cc784..4e2e85356 100644 --- a/tests/test_attestation_pool.nim +++ b/tests/test_attestation_pool.nim @@ -28,7 +28,7 @@ import from std/sequtils import toSeq from ./testbcutil import addHeadBlock -func combine(tgt: var Attestation, src: Attestation) = +func combine(tgt: var phase0.Attestation, src: phase0.Attestation) = ## Combine the signature and participation bitfield, with the assumption that ## the same data is being signed - if the signatures overlap, they are not ## combined. @@ -47,7 +47,7 @@ func combine(tgt: var Attestation, src: Attestation) = agg.aggregate(src.signature.load.get()) tgt.signature = agg.finish().toValidatorSig() -func loadSig(a: Attestation): CookedSig = +func loadSig(a: phase0.Attestation): CookedSig = a.signature.load.get() proc pruneAtFinalization(dag: ChainDAGRef, attPool: AttestationPool) = @@ -666,7 +666,7 @@ suite "Attestation pool processing" & preset(): # ------------------------------------------------------------- # Pass an epoch - var attestations: seq[Attestation] + var attestations: seq[phase0.Attestation] for epoch in 0 ..< 5: let start_slot = start_slot(Epoch epoch) @@ -703,7 +703,7 @@ suite "Attestation pool processing" & preset(): for v in 0 ..< committee.len * 2 div 3 + 1: aggregation_bits[v] = true - attestations.add Attestation( + attestations.add phase0.Attestation( aggregation_bits: aggregation_bits, data: makeAttestationData(state[], getStateField(state[], slot), committee_index, blockRef.get().root) @@ -729,4 +729,4 @@ suite "Attestation pool processing" & preset(): epochRef, blckRef, unrealized, signedBlock.message, blckRef.slot.start_beacon_time) - doAssert: b10Add_clone.error == VerifierError.Duplicate + doAssert: b10Add_clone.error == VerifierError.Duplicate \ No newline at end of file diff --git a/tests/test_message_signatures.nim b/tests/test_message_signatures.nim index ce23c90e0..41b9031bc 100644 --- a/tests/test_message_signatures.nim +++ b/tests/test_message_signatures.nim @@ -61,7 +61,8 @@ suite "Message signatures": test "Aggregate and proof signatures": let aggregate_and_proof = AggregateAndProof( - aggregate: Attestation(aggregation_bits: CommitteeValidatorsBits.init(8))) + aggregate: phase0.Attestation( + aggregation_bits: CommitteeValidatorsBits.init(8))) check: # Matching public/private keys and genesis validator roots @@ -271,4 +272,4 @@ suite "Message signatures": fork0, genesis_validators_root0, slot, subcommittee_index, load(pubkey0).get, get_sync_committee_selection_proof( fork0, genesis_validators_root1, slot, - subcommittee_index, privkey0).toValidatorSig) + subcommittee_index, privkey0).toValidatorSig) \ No newline at end of file diff --git a/tests/test_toblindedblock.nim b/tests/test_toblindedblock.nim index 646a662b8..646220835 100644 --- a/tests/test_toblindedblock.nim +++ b/tests/test_toblindedblock.nim @@ -56,7 +56,7 @@ template bellatrix_steps() = check: b.message.body.attester_slashings.add(default(AttesterSlashing)) do_check check: b.message.body.attestations.add( - Attestation(aggregation_bits: CommitteeValidatorsBits.init(1))) + phase0.Attestation(aggregation_bits: CommitteeValidatorsBits.init(1))) do_check check: b.message.body.deposits.add(default(Deposit)) do_check diff --git a/tests/test_validator_client.nim b/tests/test_validator_client.nim index d2220b891..fea8e5808 100644 --- a/tests/test_validator_client.nim +++ b/tests/test_validator_client.nim @@ -465,8 +465,8 @@ proc init(t: typedesc[ProduceAttestationDataResponse], target: Checkpoint(epoch: Epoch(ad.target)) )) -proc init(t: typedesc[Attestation], bits: string, - slot: Slot = GENESIS_SLOT, index: uint64 = 0'u64): Attestation = +proc init(t: typedesc[phase0.Attestation], bits: string, + slot: Slot = GENESIS_SLOT, index: uint64 = 0'u64): phase0.Attestation = let jdata = "{\"data\":\"" & bits & "\"}" bits = @@ -767,8 +767,8 @@ suite "Validator Client test suite": test "getUniqueVotes() test vectors": for vector in AttestationBitsVectors: let - a1 = Attestation.init(vector[0][0][0], vector[0][0][1], vector[0][0][2]) - a2 = Attestation.init(vector[0][1][0], vector[0][1][1], vector[0][1][2]) + a1 = phase0.Attestation.init(vector[0][0][0], vector[0][0][1], vector[0][0][2]) + a2 = phase0.Attestation.init(vector[0][1][0], vector[0][1][1], vector[0][1][2]) check getUniqueVotes([a1, a2]) == vector[1] asyncTest "firstSuccessParallel() API timeout test": @@ -905,4 +905,4 @@ suite "Validator Client test suite": res.isOk() len(res.get().data) == 1 res.get().data[0].index == 100000 - res.get().data[0].is_live == true + res.get().data[0].is_live == true \ No newline at end of file diff --git a/tests/testblockutil.nim b/tests/testblockutil.nim index 204539eed..ecbe8ef19 100644 --- a/tests/testblockutil.nim +++ b/tests/testblockutil.nim @@ -157,7 +157,7 @@ proc addTestBlock*( state: var ForkedHashedBeaconState, cache: var StateCache, eth1_data: Eth1Data = Eth1Data(), - attestations: seq[Attestation] = newSeq[Attestation](), + attestations: seq[phase0.Attestation] = newSeq[phase0.Attestation](), deposits: seq[Deposit] = newSeq[Deposit](), sync_aggregate: SyncAggregate = SyncAggregate.init(), graffiti: GraffitiBytes = default(GraffitiBytes), @@ -242,7 +242,7 @@ proc makeTestBlock*( state: ForkedHashedBeaconState, cache: var StateCache, eth1_data = Eth1Data(), - attestations = newSeq[Attestation](), + attestations = newSeq[phase0.Attestation](), deposits = newSeq[Deposit](), sync_aggregate = SyncAggregate.init(), graffiti = default(GraffitiBytes), @@ -323,7 +323,7 @@ func makeAttestation( state: ForkedHashedBeaconState, beacon_block_root: Eth2Digest, committee: seq[ValidatorIndex], slot: Slot, committee_index: CommitteeIndex, validator_index: ValidatorIndex, cache: var StateCache, - flags: UpdateFlags = {}): Attestation = + flags: UpdateFlags = {}): phase0.Attestation = let index_in_committee = committee.find(validator_index) data = makeAttestationData(state, slot, committee_index, beacon_block_root) @@ -341,7 +341,7 @@ func makeAttestation( getStateField(state, genesis_validators_root), data, committee, aggregation_bits) - Attestation( + phase0.Attestation( data: data, aggregation_bits: aggregation_bits, signature: sig @@ -364,7 +364,7 @@ func find_beacon_committee( func makeAttestation*( state: ForkedHashedBeaconState, beacon_block_root: Eth2Digest, - validator_index: ValidatorIndex, cache: var StateCache): Attestation = + validator_index: ValidatorIndex, cache: var StateCache): phase0.Attestation = let (committee, slot, index) = find_beacon_committee(state, validator_index, cache) makeAttestation(state, beacon_block_root, committee, slot, index, @@ -373,7 +373,7 @@ func makeAttestation*( func makeFullAttestations*( state: ForkedHashedBeaconState, beacon_block_root: Eth2Digest, slot: Slot, cache: var StateCache, - flags: UpdateFlags = {}): seq[Attestation] = + flags: UpdateFlags = {}): seq[phase0.Attestation] = # Create attestations in which the full committee participates for each shard # that should be attested to during a particular slot let committees_per_slot = get_committee_count_per_slot( @@ -384,7 +384,7 @@ func makeFullAttestations*( data = makeAttestationData(state, slot, committee_index, beacon_block_root) doAssert committee.len() >= 1 - var attestation = Attestation( + var attestation = phase0.Attestation( aggregation_bits: CommitteeValidatorsBits.init(committee.len), data: data) for i in 0..