From 96dcb1cf95614011f9b0aead46e4517e15c25715 Mon Sep 17 00:00:00 2001 From: Dustin Brody Date: Thu, 14 Nov 2019 19:48:12 +0100 Subject: [PATCH] Remove shard-relating code --- beacon_chain/beacon_node.nim | 16 +----- beacon_chain/spec/datatypes.nim | 13 ----- beacon_chain/spec/state_transition_epoch.nim | 7 --- beacon_chain/spec/validator.nim | 59 -------------------- tests/mocking/mock_attestations.nim | 19 ++----- 5 files changed, 5 insertions(+), 109 deletions(-) diff --git a/beacon_chain/beacon_node.nim b/beacon_chain/beacon_node.nim index c3a9dce73..c03b5a544 100644 --- a/beacon_chain/beacon_node.nim +++ b/beacon_chain/beacon_node.nim @@ -544,31 +544,17 @@ proc handleAttestations(node: BeaconNode, head: BlockRef, slot: Slot) = # version here that calculates the committee for a single slot only node.blockPool.withState(node.stateCache, attestationHead): var cache = get_empty_per_epoch_cache() - let - epoch = compute_epoch_at_slot(slot) - committees_per_slot = - # get_committee_count_at_slot(state, slot) - get_committee_count_at_slot(state, epoch.compute_start_slot_at_epoch) - offset = committees_per_slot * (slot mod SLOTS_PER_EPOCH) - slot_start_shard = (get_start_shard(state, epoch) + offset) mod SHARD_COUNT + let committees_per_slot = get_committee_count_at_slot(state, slot) for committee_index in 0'u64.. epoch: - check_epoch -= 1.Epoch - shard = (shard + SHARD_COUNT - get_shard_delta(state, check_epoch)) mod - SHARD_COUNT - return shard - -# TODO remove when shim layer isn't needed -func get_slot_and_index*(state: BeaconState, epoch: Epoch, shard: Shard): auto = - let gcc_index = - (shard + SHARD_COUNT - get_start_shard(state, epoch)) mod SHARD_COUNT - - # Want (slot % SLOTS_PER_EPOCH) * committees_per_slot + index to result in - # same index, where - # committees_per_slot = get_committee_count_at_slot(state, slot) - # https://github.com/ethereum/eth2.0-specs/blob/v0.9.1/specs/core/0_beacon-chain.md#get_beacon_committee - let committees_per_slot = - get_committee_count_at_slot(state, compute_start_slot_at_epoch(epoch)) - - # get_beacon_committee(...) uses a straightforward linear mapping, row-centric - # minimize the `index` offset (s.t. >= 0) and maximize `slot`. - let - slot = gcc_index div committees_per_slot - index = gcc_index mod committees_per_slot - - # TODO it might be bad if slot >= SLOTS_PER_EPOCH in this construction, - # but not necessarily - (compute_start_slot_at_epoch(epoch) + slot, index) - # https://github.com/ethereum/eth2.0-specs/blob/v0.9.1/specs/core/0_beacon-chain.md#compute_committee func compute_committee(indices: seq[ValidatorIndex], seed: Eth2Digest, index: uint64, count: uint64, stateCache: var StateCache): seq[ValidatorIndex] = @@ -186,25 +140,12 @@ func get_beacon_committee*(state: BeaconState, slot: Slot, index: uint64, cache: cache ) -# https://github.com/ethereum/eth2.0-specs/blob/v0.8.4/specs/core/0_beacon-chain.md#get_crosslink_committee -func get_crosslink_committee*(state: BeaconState, epoch: Epoch, shard: Shard, - stateCache: var StateCache): seq[ValidatorIndex] = - - doAssert shard >= 0'u64 - - if epoch notin stateCache.start_shard_cache: - stateCache.start_shard_cache[epoch] = get_start_shard(state, epoch) - - let (gbc_slot, gbc_index) = get_slot_and_index(state, epoch, shard) - get_beacon_committee(state, gbc_slot, gbc_index, stateCache) - # Not from spec func get_empty_per_epoch_cache*(): StateCache = result.crosslink_committee_cache = initTable[tuple[a: int, b: Eth2Digest], seq[ValidatorIndex]]() result.active_validator_indices_cache = initTable[Epoch, seq[ValidatorIndex]]() - result.start_shard_cache = initTable[Epoch, Shard]() result.committee_count_cache = initTable[Epoch, uint64]() # https://github.com/ethereum/eth2.0-specs/blob/v0.9.1/specs/core/0_beacon-chain.md#compute_proposer_index diff --git a/tests/mocking/mock_attestations.nim b/tests/mocking/mock_attestations.nim index ea461693b..95c76124a 100644 --- a/tests/mocking/mock_attestations.nim +++ b/tests/mocking/mock_attestations.nim @@ -23,7 +23,7 @@ import proc mockAttestationData( state: BeaconState, slot: Slot, - shard: Shard): AttestationData = + index: uint64): AttestationData = doAssert state.slot >= slot if slot == state.slot: @@ -47,13 +47,8 @@ proc mockAttestationData( let target_epoch = compute_epoch_at_slot(slot) - # Constructed to be provide exact equivalent index... to compute_committee(...) - # as using epoch/shard. - let (r_slot, r_index) = get_slot_and_index(state, target_epoch, shard) - doAssert r_slot == slot - doAssert r_index == 0 result.slot = slot - result.index = r_index + result.index = index result.target = Checkpoint( epoch: target_epoch, root: epoch_boundary_root @@ -105,14 +100,8 @@ proc mockAttestationImpl( var cache = get_empty_per_epoch_cache() let - epoch = compute_epoch_at_slot(slot) - epoch_start_shard = get_start_shard(state, epoch) committees_per_slot = get_committee_count_at_slot( - state, epoch.compute_start_slot_at_epoch) - shard = ( - epoch_start_shard + - committees_per_slot * (slot mod SLOTS_PER_EPOCH) - ) mod SHARD_COUNT + state, slot) beacon_committee = get_beacon_committee( state, @@ -122,7 +111,7 @@ proc mockAttestationImpl( ) committee_size = beacon_committee.len - result.data = mockAttestationData(state, slot, shard) + result.data = mockAttestationData(state, slot, 0) result.aggregation_bits = init(CommitteeValidatorsBits, committee_size) # fillAggregateAttestation