update get_crosslink_committee(...) to 0.8.0 and fix https://github.com/status-im/nim-beacon-chain/issues/307
This commit is contained in:
parent
bf037eab5e
commit
d7905351eb
|
@ -469,7 +469,7 @@ proc handleAttestations(node: BeaconNode, head: BlockRef, slot: Slot) =
|
|||
node.blockPool.withState(node.stateCache, attestationHead):
|
||||
var cache = get_empty_per_epoch_cache()
|
||||
let epoch = compute_epoch_of_slot(slot)
|
||||
for committee_index in 0'u64 ..< get_epoch_committee_count(state, epoch):
|
||||
for committee_index in 0'u64 ..< get_committee_count(state, epoch):
|
||||
## TODO verify that this is the correct mapping; it's consistent with
|
||||
## other code
|
||||
let
|
||||
|
|
|
@ -268,7 +268,7 @@ func get_attestation_data_slot*(state: BeaconState,
|
|||
func get_attestation_data_slot*(state: BeaconState,
|
||||
data: AttestationData): Slot =
|
||||
get_attestation_data_slot(
|
||||
state, data, get_epoch_committee_count(state, data.target_epoch))
|
||||
state, data, get_committee_count(state, data.target_epoch))
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.0/specs/core/0_beacon-chain.md#get_block_root_at_slot
|
||||
func get_block_root_at_slot*(state: BeaconState,
|
||||
|
|
|
@ -80,8 +80,8 @@ func get_active_validator_indices*(state: BeaconState, epoch: Epoch):
|
|||
if is_active_validator(val, epoch):
|
||||
result.add idx.ValidatorIndex
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#get_epoch_committee_count
|
||||
func get_epoch_committee_count*(state: BeaconState, epoch: Epoch): uint64 =
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#get_committee_count
|
||||
func get_committee_count*(state: BeaconState, epoch: Epoch): uint64 =
|
||||
# Return the number of committees at ``epoch``.
|
||||
let active_validator_indices = get_active_validator_indices(state, epoch)
|
||||
clamp(
|
||||
|
@ -174,8 +174,8 @@ func get_domain*(
|
|||
func get_domain*(state: BeaconState, domain_type: DomainType): Domain =
|
||||
get_domain(state, domain_type, get_current_epoch(state))
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#generate_seed
|
||||
func generate_seed*(state: BeaconState, epoch: Epoch): Eth2Digest =
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#get_seed
|
||||
func get_seed*(state: BeaconState, epoch: Epoch): Eth2Digest =
|
||||
# Generate a seed for the given ``epoch``.
|
||||
|
||||
var seed_input : array[32*3, byte]
|
||||
|
|
|
@ -261,7 +261,7 @@ proc processAttestations(
|
|||
committee_count = if epoch in committee_count_cache:
|
||||
committee_count_cache[epoch]
|
||||
else:
|
||||
get_epoch_committee_count(state, epoch)
|
||||
get_committee_count(state, epoch)
|
||||
committee_count_cache[epoch] = committee_count
|
||||
|
||||
# Spec content
|
||||
|
|
|
@ -219,7 +219,7 @@ func process_crosslinks(state: var BeaconState, stateCache: var StateCache) =
|
|||
# This issue comes up regularly -- iterating means an int type,
|
||||
# which then needs re-conversion back to specialized type.
|
||||
let epoch = epoch_int.Epoch
|
||||
for offset in 0'u64 ..< get_epoch_committee_count(state, epoch):
|
||||
for offset in 0'u64 ..< get_committee_count(state, epoch):
|
||||
let
|
||||
shard = (get_start_shard(state, epoch) + offset) mod SHARD_COUNT
|
||||
crosslink_committee =
|
||||
|
@ -325,7 +325,7 @@ func get_crosslink_deltas(state: BeaconState, cache: var StateCache):
|
|||
rewards = repeat(0'u64, len(state.validators))
|
||||
penalties = repeat(0'u64, len(state.validators))
|
||||
let epoch = get_previous_epoch(state)
|
||||
for offset in 0'u64 ..< get_epoch_committee_count(state, epoch):
|
||||
for offset in 0'u64 ..< get_committee_count(state, epoch):
|
||||
let
|
||||
shard = (get_start_shard(state, epoch) + offset) mod SHARD_COUNT
|
||||
crosslink_committee =
|
||||
|
|
|
@ -92,7 +92,7 @@ func get_previous_epoch*(state: BeaconState): Epoch =
|
|||
func get_shard_delta*(state: BeaconState, epoch: Epoch): uint64 =
|
||||
## Return the number of shards to increment ``state.start_shard``
|
||||
## during ``epoch``.
|
||||
min(get_epoch_committee_count(state, epoch),
|
||||
min(get_committee_count(state, epoch),
|
||||
(SHARD_COUNT - SHARD_COUNT div SLOTS_PER_EPOCH).uint64)
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.0/specs/core/0_beacon-chain.md#get_start_shard
|
||||
|
@ -136,14 +136,13 @@ func compute_committee(indices: seq[ValidatorIndex], seed: Eth2Digest,
|
|||
start.int .. (endIdx.int-1),
|
||||
indices[stateCache.crosslink_committee_cache[key][it]])
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#get_crosslink_committee
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.0/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
|
||||
# This seems to be required, basically, to be true? But I'm not entirely sure
|
||||
#doAssert shard >= get_start_shard(state, epoch)
|
||||
doAssert shard < SHARD_COUNT
|
||||
|
||||
## This is a somewhat more fragile, but high-ROI, caching setup --
|
||||
## get_active_validator_indices() is slow to run in a loop and only
|
||||
|
@ -154,9 +153,9 @@ func get_crosslink_committee*(state: BeaconState, epoch: Epoch, shard: Shard,
|
|||
|
||||
compute_committee(
|
||||
stateCache.active_validator_indices_cache[epoch],
|
||||
generate_seed(state, epoch),
|
||||
get_seed(state, epoch),
|
||||
(shard + SHARD_COUNT - get_start_shard(state, epoch)) mod SHARD_COUNT,
|
||||
get_epoch_committee_count(state, epoch),
|
||||
get_committee_count(state, epoch),
|
||||
stateCache
|
||||
)
|
||||
|
||||
|
@ -177,11 +176,11 @@ func get_beacon_proposer_index*(state: BeaconState, stateCache: var StateCache):
|
|||
let
|
||||
epoch = get_current_epoch(state)
|
||||
committees_per_slot =
|
||||
get_epoch_committee_count(state, epoch) div SLOTS_PER_EPOCH
|
||||
get_committee_count(state, epoch) div SLOTS_PER_EPOCH
|
||||
offset = committees_per_slot * (state.slot mod SLOTS_PER_EPOCH)
|
||||
shard = (get_start_shard(state, epoch) + offset) mod SHARD_COUNT
|
||||
first_committee = get_crosslink_committee(state, epoch, shard, stateCache)
|
||||
seed = generate_seed(state, epoch)
|
||||
seed = get_seed(state, epoch)
|
||||
|
||||
var
|
||||
i = 0
|
||||
|
|
|
@ -104,7 +104,7 @@ cli do(slots = 448,
|
|||
epoch = compute_epoch_of_slot(state.slot)
|
||||
scass = withTimerRet(timers[tShuffle]):
|
||||
mapIt(
|
||||
0'u64 .. (get_epoch_committee_count(state, epoch) - 1),
|
||||
0'u64 .. (get_committee_count(state, epoch) - 1),
|
||||
get_crosslink_committee(state, epoch,
|
||||
(it + get_start_shard(state, epoch)) mod SHARD_COUNT,
|
||||
cache))
|
||||
|
|
|
@ -145,7 +145,7 @@ proc find_shard_committee(
|
|||
state: BeaconState, validator_index: ValidatorIndex): auto =
|
||||
let epoch = compute_epoch_of_slot(state.slot)
|
||||
var cache = get_empty_per_epoch_cache()
|
||||
for shard in 0'u64 ..< get_epoch_committee_count(state, epoch):
|
||||
for shard in 0'u64 ..< get_committee_count(state, epoch):
|
||||
let committee = get_crosslink_committee(state, epoch,
|
||||
(shard + get_start_shard(state, epoch)) mod SHARD_COUNT, cache)
|
||||
if validator_index in committee:
|
||||
|
|
Loading…
Reference in New Issue