2
0
mirror of https://github.com/status-im/nimbus-eth2.git synced 2025-01-11 23:04:26 +00:00

Remove shard-relating code

This commit is contained in:
Dustin Brody 2019-11-14 19:48:12 +01:00
parent e32bbac600
commit 96dcb1cf95
No known key found for this signature in database
GPG Key ID: 3D7A11A0156519DC
5 changed files with 5 additions and 109 deletions

@ -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..<committees_per_slot:
let
shard = Shard((slot_start_shard + committee_index) mod SHARD_COUNT)
shard_committee = get_crosslink_committee(state, epoch, shard, cache)
committee = get_beacon_committee(state, slot, committee_index, cache)
for index_in_committee, validatorIdx in committee:
let validator = node.getAttachedValidator(state, validatorIdx)
if validator != nil:
let ad = makeAttestationData(state, slot, committee_index, blck.root)
let
(hm_slot, hm_index) = get_slot_and_index(state, epoch, shard)
shard_ad = makeAttestationData(state, hm_slot, hm_index, blck.root)
doAssert slot == hm_slot
doAssert hm_index == committee_index
attestations.add((ad, committee.len, index_in_committee, validator))
#attestations.add((shard_ad, committee.len, index_in_committee, validator))
for a in attestations:
traceAsyncErrors sendAttestation(

@ -82,9 +82,6 @@ type
ValidatorIndex* = distinct uint32
Gwei* = uint64
# TODO remove
Shard* = uint64
BitList*[maxLen: static int] = distinct BitSeq
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.1/specs/core/0_beacon-chain.md#proposerslashing
@ -287,7 +284,6 @@ type
## VALIDATOR_REGISTRY_LIMIT
# Shuffling
start_shard* {.dontSerialize.}: Shard
randao_mixes*: array[EPOCHS_PER_HISTORICAL_VECTOR, Eth2Digest]
# Slashings
@ -374,9 +370,6 @@ type
Table[tuple[a: int, b: Eth2Digest], seq[ValidatorIndex]]
active_validator_indices_cache*:
Table[Epoch, seq[ValidatorIndex]]
start_shard_cache*: Table[Epoch, Shard]
# TODO still used?
committee_count_cache*: Table[Epoch, uint64]
when networkBackend == rlpxBackend:
@ -648,12 +641,6 @@ chronicles.formatIt Epoch: it.shortLog
chronicles.formatIt BeaconBlock: it.shortLog
chronicles.formatIt AttestationData: it.shortLog
# TODO remove
const SHARD_COUNT* = (MAX_COMMITTEES_PER_SLOT * SLOTS_PER_EPOCH).uint64
static:
doAssert SHARD_COUNT.int == MAX_COMMITTEES_PER_SLOT * SLOTS_PER_EPOCH
import json_serialization
export json_serialization
export writeValue, readValue

@ -398,13 +398,6 @@ proc process_final_updates*(state: var BeaconState) =
)
state.historical_roots.add (hash_tree_root(historical_batch))
# TODO remove this when start_shard finally goes away, but doesn't
# interfere with 0.9.0. Gone after 0.8.4.
# Update start shard
state.start_shard =
(state.start_shard + get_shard_delta(state, current_epoch)) mod
SHARD_COUNT
# Rotate current/previous epoch attestations
state.previous_epoch_attestations = state.current_epoch_attestations
state.current_epoch_attestations = @[]

@ -87,52 +87,6 @@ func get_previous_epoch*(state: BeaconState): Epoch =
else:
current_epoch - 1
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.4/specs/core/0_beacon-chain.md#get_shard_delta
func get_shard_delta*(state: BeaconState, epoch: Epoch): uint64 =
## Return the number of shards to increment ``state.start_shard``
## during ``epoch``.
min(get_committee_count_at_slot(state, epoch.compute_start_slot_at_epoch) *
SLOTS_PER_EPOCH,
(SHARD_COUNT - SHARD_COUNT div SLOTS_PER_EPOCH).uint64)
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.4/specs/core/0_beacon-chain.md#get_start_shard
func get_start_shard*(state: BeaconState, epoch: Epoch): Shard =
# Return the start shard of the 0th committee at ``epoch``.
doAssert epoch <= get_current_epoch(state) + 1
var
check_epoch = get_current_epoch(state) + 1
shard =
(state.start_shard +
get_shard_delta(state, get_current_epoch(state))) mod SHARD_COUNT
while check_epoch > 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

@ -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