From d559f4ee89ad408a4e7b86d4192de5ca25abdab6 Mon Sep 17 00:00:00 2001 From: Dustin Brody Date: Wed, 15 Apr 2020 11:01:36 +0200 Subject: [PATCH] create distinct CommitteeIndex type --- beacon_chain/attestation_aggregation.nim | 13 +++++-------- beacon_chain/beacon_node.nim | 10 +++++----- beacon_chain/spec/beaconstate.nim | 6 ++++-- beacon_chain/spec/datatypes.nim | 4 ++++ beacon_chain/spec/helpers.nim | 5 +++++ beacon_chain/spec/validator.nim | 16 ++++++++++------ research/state_sim.nim | 2 +- tests/mocking/mock_attestations.nim | 4 ++-- .../justification_finalization_helpers.nim | 2 +- tests/test_attestation_pool.nim | 14 +++++++------- tests/test_state_transition.nim | 2 +- tests/testblockutil.nim | 5 +++-- 12 files changed, 48 insertions(+), 35 deletions(-) diff --git a/beacon_chain/attestation_aggregation.nim b/beacon_chain/attestation_aggregation.nim index 64e0d24f5..87bbe8ea8 100644 --- a/beacon_chain/attestation_aggregation.nim +++ b/beacon_chain/attestation_aggregation.nim @@ -12,9 +12,8 @@ import ./attestation_pool, ./beacon_node_types, ./ssz # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/validator.md#aggregation-selection -func is_aggregator(state: BeaconState, slot: Slot, index: uint64, +func is_aggregator(state: BeaconState, slot: Slot, index: CommitteeIndex, slot_signature: ValidatorSig): bool = - # TODO index is a CommitteeIndex, aka uint64 var cache = get_empty_per_epoch_cache() let @@ -23,10 +22,8 @@ func is_aggregator(state: BeaconState, slot: Slot, index: uint64, bytes_to_int(eth2hash(slot_signature.toRaw()).data[0..7]) mod modulo == 0 proc aggregate_attestations*( - pool: AttestationPool, state: BeaconState, index: uint64, + pool: AttestationPool, state: BeaconState, index: CommitteeIndex, privkey: ValidatorPrivKey, trailing_distance: uint64): Option[AggregateAndProof] = - # TODO alias CommitteeIndex to actual type then convert various uint64's here - doAssert state.slot >= trailing_distance # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/p2p-interface.md#configuration @@ -41,7 +38,7 @@ proc aggregate_attestations*( doAssert state.slot >= slot # TODO performance issue for future, via get_active_validator_indices(...) - doAssert index < get_committee_count_at_slot(state, slot) + doAssert index.uint64 < get_committee_count_at_slot(state, slot) # TODO for testing purposes, refactor this into the condition check # and just calculation @@ -54,7 +51,7 @@ proc aggregate_attestations*( # TODO this won't actually match anything let attestation_data = AttestationData( slot: slot, - index: index, + index: index.uint64, beacon_block_root: get_block_root_at_slot(state, slot)) # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/validator.md#construct-aggregate @@ -65,7 +62,7 @@ proc aggregate_attestations*( if attestation.data == attestation_data: # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/validator.md#aggregateandproof return some(AggregateAndProof( - aggregator_index: index, + aggregator_index: index.uint64, aggregate: attestation, selection_proof: slot_signature)) diff --git a/beacon_chain/beacon_node.nim b/beacon_chain/beacon_node.nim index 0268ec0b9..ff58e59c9 100644 --- a/beacon_chain/beacon_node.nim +++ b/beacon_chain/beacon_node.nim @@ -546,8 +546,8 @@ proc handleAttestations(node: BeaconNode, head: BlockRef, slot: Slot) = let committees_per_slot = get_committee_count_at_slot(state, slot) for committee_index in 0'u64..= 1