cache beacon committee size calculation (#1363)
* cache beacon committee size calculation this fixes a bug in get_validator_churn_limit as well * fix * make committee counts consistently uint64 mixing feels like the worst of the two worlds
This commit is contained in:
parent
e9193fc9da
commit
e0a18a3105
|
@ -42,13 +42,13 @@ proc aggregate_attestations*(
|
||||||
doAssert slot + ATTESTATION_PROPAGATION_SLOT_RANGE >= state.slot
|
doAssert slot + ATTESTATION_PROPAGATION_SLOT_RANGE >= state.slot
|
||||||
doAssert state.slot >= slot
|
doAssert state.slot >= slot
|
||||||
|
|
||||||
|
var cache = StateCache()
|
||||||
# TODO performance issue for future, via get_active_validator_indices(...)
|
# TODO performance issue for future, via get_active_validator_indices(...)
|
||||||
doAssert index.uint64 < get_committee_count_at_slot(state, slot)
|
doAssert index.uint64 < get_committee_count_per_slot(state, slot, cache)
|
||||||
|
|
||||||
# TODO for testing purposes, refactor this into the condition check
|
# TODO for testing purposes, refactor this into the condition check
|
||||||
# and just calculation
|
# and just calculation
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/validator.md#aggregation-selection
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/validator.md#aggregation-selection
|
||||||
var cache = StateCache()
|
|
||||||
if not is_aggregator(state, slot, index, slot_signature, cache):
|
if not is_aggregator(state, slot, index, slot_signature, cache):
|
||||||
return none(AggregateAndProof)
|
return none(AggregateAndProof)
|
||||||
|
|
||||||
|
@ -171,8 +171,7 @@ proc isValidAttestation*(
|
||||||
epochInfo = blck.getEpochInfo(state)
|
epochInfo = blck.getEpochInfo(state)
|
||||||
requiredSubnetIndex =
|
requiredSubnetIndex =
|
||||||
compute_subnet_for_attestation(
|
compute_subnet_for_attestation(
|
||||||
get_committee_count_at_slot(
|
get_committee_count_per_slot(epochInfo),
|
||||||
epochInfo.shuffled_active_validator_indices.len.uint64),
|
|
||||||
attestation.data.slot, attestation.data.index.CommitteeIndex)
|
attestation.data.slot, attestation.data.index.CommitteeIndex)
|
||||||
|
|
||||||
if requiredSubnetIndex != topicCommitteeIndex:
|
if requiredSubnetIndex != topicCommitteeIndex:
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
import
|
import
|
||||||
extras, beacon_chain_db,
|
extras, beacon_chain_db,
|
||||||
stew/results,
|
stew/results,
|
||||||
spec/[crypto, datatypes, digest, presets]
|
spec/[crypto, datatypes, digest, helpers, presets]
|
||||||
|
|
||||||
|
|
||||||
import
|
import
|
||||||
|
@ -212,3 +212,9 @@ proc isValidBeaconBlock*(
|
||||||
current_slot: Slot, flags: UpdateFlags): Result[void, BlockError] =
|
current_slot: Slot, flags: UpdateFlags): Result[void, BlockError] =
|
||||||
isValidBeaconBlock(
|
isValidBeaconBlock(
|
||||||
pool.dag, pool.quarantine, signed_beacon_block, current_slot, flags)
|
pool.dag, pool.quarantine, signed_beacon_block, current_slot, flags)
|
||||||
|
|
||||||
|
func count_active_validators*(epochInfo: EpochRef): uint64 =
|
||||||
|
epochInfo.shuffled_active_validator_indices.len.uint64
|
||||||
|
|
||||||
|
func get_committee_count_per_slot*(epochInfo: EpochRef): uint64 =
|
||||||
|
get_committee_count_per_slot(count_active_validators(epochInfo))
|
||||||
|
|
|
@ -506,8 +506,8 @@ proc createBeaconStateAux(preset: RuntimePreset,
|
||||||
eth1Block.voteData.block_hash,
|
eth1Block.voteData.block_hash,
|
||||||
eth1Block.timestamp.uint64,
|
eth1Block.timestamp.uint64,
|
||||||
deposits, {})
|
deposits, {})
|
||||||
let activeValidators = count_active_validator_indices(result[], GENESIS_EPOCH)
|
let activeValidators = count_active_validators(result[], GENESIS_EPOCH, StateCache())
|
||||||
eth1Block.knownGoodDepositsCount = some activeValidators.uint64
|
eth1Block.knownGoodDepositsCount = some activeValidators
|
||||||
|
|
||||||
proc createBeaconState(m: MainchainMonitor, eth1Block: Eth1Block): BeaconStateRef =
|
proc createBeaconState(m: MainchainMonitor, eth1Block: Eth1Block): BeaconStateRef =
|
||||||
createBeaconStateAux(
|
createBeaconStateAux(
|
||||||
|
|
|
@ -115,8 +115,10 @@ func compute_activation_exit_epoch*(epoch: Epoch): Epoch =
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#get_validator_churn_limit
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#get_validator_churn_limit
|
||||||
func get_validator_churn_limit(state: BeaconState, cache: var StateCache): uint64 =
|
func get_validator_churn_limit(state: BeaconState, cache: var StateCache): uint64 =
|
||||||
# Return the validator churn limit for the current epoch.
|
# Return the validator churn limit for the current epoch.
|
||||||
max(MIN_PER_EPOCH_CHURN_LIMIT,
|
max(
|
||||||
len(cache.shuffled_active_validator_indices).uint64 div CHURN_LIMIT_QUOTIENT)
|
MIN_PER_EPOCH_CHURN_LIMIT,
|
||||||
|
count_active_validators(
|
||||||
|
state, state.get_current_epoch(), cache) div CHURN_LIMIT_QUOTIENT)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#initiate_validator_exit
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#initiate_validator_exit
|
||||||
func initiate_validator_exit*(state: var BeaconState,
|
func initiate_validator_exit*(state: var BeaconState,
|
||||||
|
@ -588,12 +590,11 @@ proc check_attestation*(
|
||||||
attestation = shortLog(attestation)
|
attestation = shortLog(attestation)
|
||||||
trace "process_attestation: beginning"
|
trace "process_attestation: beginning"
|
||||||
|
|
||||||
let committee_count_at_slot =
|
let committees_per_slot =
|
||||||
get_committee_count_at_slot(get_shuffled_active_validator_indices(
|
get_committee_count_per_slot(state, data.slot, stateCache)
|
||||||
state, state.get_current_epoch(), stateCache).len.uint64).uint64
|
if not (data.index < committees_per_slot):
|
||||||
if not (data.index < committee_count_at_slot):
|
|
||||||
warn "Data index exceeds committee count",
|
warn "Data index exceeds committee count",
|
||||||
committee_count = committee_count_at_slot
|
committee_count = committees_per_slot
|
||||||
return
|
return
|
||||||
|
|
||||||
if not isValidAttestationTargetEpoch(state.get_current_epoch(), data):
|
if not isValidAttestationTargetEpoch(state.get_current_epoch(), data):
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
# Standard lib
|
# Standard lib
|
||||||
math,
|
std/[math, sequtils, tables],
|
||||||
# Third-party
|
# Third-party
|
||||||
stew/endians2,
|
stew/endians2,
|
||||||
# Internal
|
# Internal
|
||||||
|
@ -57,10 +57,16 @@ func is_active_validator*(validator: Validator, epoch: Epoch): bool =
|
||||||
validator.activation_epoch <= epoch and epoch < validator.exit_epoch
|
validator.activation_epoch <= epoch and epoch < validator.exit_epoch
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#get_active_validator_indices
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#get_active_validator_indices
|
||||||
func count_active_validator_indices*(state: BeaconState, epoch: Epoch): int =
|
func count_active_validators*(state: BeaconState,
|
||||||
for val in state.validators:
|
epoch: Epoch,
|
||||||
if is_active_validator(val, epoch):
|
cache: StateCache): uint64 =
|
||||||
result += 1
|
if epoch in cache.shuffled_active_validator_indices:
|
||||||
|
try:
|
||||||
|
cache.shuffled_active_validator_indices[epoch].len.uint64
|
||||||
|
except KeyError:
|
||||||
|
raiseAssert "just checked"
|
||||||
|
else:
|
||||||
|
countIt(state.validators, is_active_validator(it, epoch)).uint64
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#get_active_validator_indices
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#get_active_validator_indices
|
||||||
func get_active_validator_indices*(state: BeaconState, epoch: Epoch):
|
func get_active_validator_indices*(state: BeaconState, epoch: Epoch):
|
||||||
|
@ -70,13 +76,15 @@ func get_active_validator_indices*(state: BeaconState, epoch: Epoch):
|
||||||
if is_active_validator(val, epoch):
|
if is_active_validator(val, epoch):
|
||||||
result.add idx.ValidatorIndex
|
result.add idx.ValidatorIndex
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#get_committee_count_at_slot
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#get_committee_count_per_slot
|
||||||
func get_committee_count_at_slot*(num_active_validators: uint64): uint64 =
|
func get_committee_count_per_slot*(num_active_validators: uint64): uint64 =
|
||||||
clamp(
|
clamp(
|
||||||
num_active_validators div SLOTS_PER_EPOCH div TARGET_COMMITTEE_SIZE,
|
num_active_validators div SLOTS_PER_EPOCH div TARGET_COMMITTEE_SIZE,
|
||||||
1, MAX_COMMITTEES_PER_SLOT).uint64
|
1'u64, MAX_COMMITTEES_PER_SLOT)
|
||||||
|
|
||||||
func get_committee_count_at_slot*(state: BeaconState, slot: Slot): uint64 =
|
func get_committee_count_per_slot*(state: BeaconState,
|
||||||
|
epoch: Epoch,
|
||||||
|
cache: StateCache): uint64 =
|
||||||
# Return the number of committees at ``slot``.
|
# Return the number of committees at ``slot``.
|
||||||
|
|
||||||
# TODO this is mostly used in for loops which have indexes which then need to
|
# TODO this is mostly used in for loops which have indexes which then need to
|
||||||
|
@ -84,12 +92,16 @@ func get_committee_count_at_slot*(state: BeaconState, slot: Slot): uint64 =
|
||||||
# with better and more type-safe use pattern, probably beginning with using a
|
# with better and more type-safe use pattern, probably beginning with using a
|
||||||
# CommitteeIndex return type here.
|
# CommitteeIndex return type here.
|
||||||
let
|
let
|
||||||
epoch = compute_epoch_at_slot(slot)
|
active_validator_count = count_active_validators(state, epoch, cache)
|
||||||
active_validator_count = count_active_validator_indices(state, epoch)
|
result = get_committee_count_per_slot(active_validator_count)
|
||||||
result = get_committee_count_at_slot(active_validator_count.uint64)
|
|
||||||
|
|
||||||
# Otherwise, get_beacon_committee(...) cannot access some committees.
|
# Otherwise, get_beacon_committee(...) cannot access some committees.
|
||||||
doAssert (SLOTS_PER_EPOCH * MAX_COMMITTEES_PER_SLOT).uint64 >= result
|
doAssert (SLOTS_PER_EPOCH * MAX_COMMITTEES_PER_SLOT) >= uint64(result)
|
||||||
|
|
||||||
|
func get_committee_count_per_slot*(state: BeaconState,
|
||||||
|
slot: Slot,
|
||||||
|
cache: StateCache): uint64 =
|
||||||
|
get_committee_count_per_slot(state, slot.compute_epoch_at_slot, cache)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#get_current_epoch
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#get_current_epoch
|
||||||
func get_current_epoch*(state: BeaconState): Epoch =
|
func get_current_epoch*(state: BeaconState): Epoch =
|
||||||
|
|
|
@ -84,9 +84,11 @@ func getAttestationTopic*(forkDigest: ForkDigest, subnetIndex: uint64):
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raiseAssert e.msg
|
raiseAssert e.msg
|
||||||
|
|
||||||
func getAttestationTopic*(forkDigest: ForkDigest, attestation: Attestation, num_active_validators: uint64): string =
|
func getAttestationTopic*(forkDigest: ForkDigest,
|
||||||
|
attestation: Attestation,
|
||||||
|
num_active_validators: uint64): string =
|
||||||
getAttestationTopic(
|
getAttestationTopic(
|
||||||
forkDigest,
|
forkDigest,
|
||||||
compute_subnet_for_attestation(
|
compute_subnet_for_attestation(
|
||||||
get_committee_count_at_slot(num_active_validators),
|
get_committee_count_per_slot(num_active_validators),
|
||||||
attestation.data.slot, attestation.data.index.CommitteeIndex))
|
attestation.data.slot, attestation.data.index.CommitteeIndex))
|
||||||
|
|
|
@ -154,14 +154,14 @@ func get_beacon_committee*(
|
||||||
get_shuffled_active_validator_indices(state, epoch)
|
get_shuffled_active_validator_indices(state, epoch)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
let committee_count = get_committee_count_at_slot(
|
let committees_per_slot = get_committee_count_per_slot(
|
||||||
cache.shuffled_active_validator_indices[epoch].len.uint64)
|
cache.shuffled_active_validator_indices[epoch].len.uint64)
|
||||||
compute_committee(
|
compute_committee(
|
||||||
cache.shuffled_active_validator_indices[epoch],
|
cache.shuffled_active_validator_indices[epoch],
|
||||||
get_seed(state, epoch, DOMAIN_BEACON_ATTESTER),
|
get_seed(state, epoch, DOMAIN_BEACON_ATTESTER),
|
||||||
(slot mod SLOTS_PER_EPOCH) * committee_count +
|
(slot mod SLOTS_PER_EPOCH) * committees_per_slot +
|
||||||
index.uint64,
|
index.uint64,
|
||||||
committee_count * SLOTS_PER_EPOCH
|
committees_per_slot * SLOTS_PER_EPOCH
|
||||||
)
|
)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raiseAssert "values are added to cache before using them"
|
raiseAssert "values are added to cache before using them"
|
||||||
|
@ -289,7 +289,7 @@ func get_committee_assignment*(
|
||||||
|
|
||||||
let start_slot = compute_start_slot_at_epoch(epoch)
|
let start_slot = compute_start_slot_at_epoch(epoch)
|
||||||
for slot in start_slot ..< start_slot + SLOTS_PER_EPOCH:
|
for slot in start_slot ..< start_slot + SLOTS_PER_EPOCH:
|
||||||
for index in 0 ..< get_committee_count_at_slot(state, slot):
|
for index in 0'u64 ..< get_committee_count_per_slot(state, slot, cache):
|
||||||
let idx = index.CommitteeIndex
|
let idx = index.CommitteeIndex
|
||||||
let committee = get_beacon_committee(state, slot, idx, cache)
|
let committee = get_beacon_committee(state, slot, idx, cache)
|
||||||
if validator_index in committee:
|
if validator_index in committee:
|
||||||
|
@ -306,16 +306,17 @@ func get_committee_assignments*(
|
||||||
var cache = StateCache()
|
var cache = StateCache()
|
||||||
let start_slot = compute_start_slot_at_epoch(epoch)
|
let start_slot = compute_start_slot_at_epoch(epoch)
|
||||||
|
|
||||||
# get_committee_count_at_slot is constant throughout an epoch
|
# get_committee_count_per_slot is constant throughout an epoch
|
||||||
let committee_count_at_slot = get_committee_count_at_slot(state, start_slot)
|
let committees_per_slot =
|
||||||
|
get_committee_count_per_slot(state, start_slot, cache)
|
||||||
|
|
||||||
for slot in start_slot ..< start_slot + SLOTS_PER_EPOCH:
|
for slot in start_slot ..< start_slot + SLOTS_PER_EPOCH:
|
||||||
for index in 0 ..< committee_count_at_slot:
|
for index in 0'u64 ..< committees_per_slot:
|
||||||
let idx = index.CommitteeIndex
|
let idx = index.CommitteeIndex
|
||||||
if not disjoint(validator_indices,
|
if not disjoint(validator_indices,
|
||||||
get_beacon_committee(state, slot, idx, cache).toHashSet):
|
get_beacon_committee(state, slot, idx, cache).toHashSet):
|
||||||
result.add(
|
result.add(
|
||||||
(compute_subnet_for_attestation(committee_count_at_slot, slot, idx),
|
(compute_subnet_for_attestation(committees_per_slot, slot, idx),
|
||||||
slot))
|
slot))
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/validator.md#validator-assignments
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/validator.md#validator-assignments
|
||||||
|
|
|
@ -237,7 +237,7 @@ proc installValidatorApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
|
||||||
|
|
||||||
proc forSlot(slot: Slot, res: var seq[BeaconStatesCommitteesTuple]) =
|
proc forSlot(slot: Slot, res: var seq[BeaconStatesCommitteesTuple]) =
|
||||||
if index == 0: # TODO this means if the parameter is missing (its optional)
|
if index == 0: # TODO this means if the parameter is missing (its optional)
|
||||||
let committees_per_slot = get_committee_count_at_slot(state, slot)
|
let committees_per_slot = get_committee_count_per_slot(state, slot, cache)
|
||||||
for committee_index in 0'u64..<committees_per_slot:
|
for committee_index in 0'u64..<committees_per_slot:
|
||||||
res.add(getCommittee(slot, committee_index.CommitteeIndex))
|
res.add(getCommittee(slot, committee_index.CommitteeIndex))
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -123,7 +123,7 @@ proc sendAttestation*(node: BeaconNode, attestation: Attestation) =
|
||||||
BlockSlot(blck: attestationBlck, slot: attestation.data.slot)):
|
BlockSlot(blck: attestationBlck, slot: attestation.data.slot)):
|
||||||
node.sendAttestation(
|
node.sendAttestation(
|
||||||
attestation,
|
attestation,
|
||||||
blck.getEpochInfo(state).shuffled_active_validator_indices.len.uint64)
|
count_active_validators(blck.getEpochInfo(state)))
|
||||||
|
|
||||||
proc createAndSendAttestation(node: BeaconNode,
|
proc createAndSendAttestation(node: BeaconNode,
|
||||||
fork: Fork,
|
fork: Fork,
|
||||||
|
@ -331,13 +331,9 @@ proc handleAttestations(node: BeaconNode, head: BlockRef, slot: Slot) =
|
||||||
node.blockPool.withState(node.blockPool.tmpState, attestationHead):
|
node.blockPool.withState(node.blockPool.tmpState, attestationHead):
|
||||||
var cache = getEpochCache(attestationHead.blck, state)
|
var cache = getEpochCache(attestationHead.blck, state)
|
||||||
let
|
let
|
||||||
committees_per_slot = get_committee_count_at_slot(state, slot)
|
committees_per_slot = get_committee_count_per_slot(state, slot, cache)
|
||||||
num_active_validators =
|
num_active_validators =
|
||||||
try:
|
count_active_validators(state, slot.compute_epoch_at_slot, cache)
|
||||||
cache.shuffled_active_validator_indices[
|
|
||||||
slot.compute_epoch_at_slot].len.uint64
|
|
||||||
except KeyError:
|
|
||||||
raiseAssert "getEpochCache(...) didn't fill cache"
|
|
||||||
|
|
||||||
for committee_index in 0'u64..<committees_per_slot:
|
for committee_index in 0'u64..<committees_per_slot:
|
||||||
let committee = get_beacon_committee(
|
let committee = get_beacon_committee(
|
||||||
|
@ -394,9 +390,10 @@ proc broadcastAggregatedAttestations(
|
||||||
|
|
||||||
let bs = BlockSlot(blck: aggregationHead, slot: aggregationSlot)
|
let bs = BlockSlot(blck: aggregationHead, slot: aggregationSlot)
|
||||||
node.blockPool.withState(node.blockPool.tmpState, bs):
|
node.blockPool.withState(node.blockPool.tmpState, bs):
|
||||||
|
var cache = getEpochCache(aggregationHead, state)
|
||||||
let
|
let
|
||||||
committees_per_slot = get_committee_count_at_slot(state, aggregationSlot)
|
committees_per_slot =
|
||||||
var cache = StateCache()
|
get_committee_count_per_slot(state, aggregationSlot, cache)
|
||||||
for committee_index in 0'u64..<committees_per_slot:
|
for committee_index in 0'u64..<committees_per_slot:
|
||||||
let committee = get_beacon_committee(
|
let committee = get_beacon_committee(
|
||||||
state, aggregationSlot, committee_index.CommitteeIndex, cache)
|
state, aggregationSlot, committee_index.CommitteeIndex, cache)
|
||||||
|
|
|
@ -24,6 +24,7 @@ import
|
||||||
../beacon_chain/[
|
../beacon_chain/[
|
||||||
attestation_pool, block_pool, beacon_node_types, beacon_chain_db,
|
attestation_pool, block_pool, beacon_node_types, beacon_chain_db,
|
||||||
interop, validator_pool],
|
interop, validator_pool],
|
||||||
|
../beacon_chain/block_pools/candidate_chains,
|
||||||
eth/db/[kvstore, kvstore_sqlite3],
|
eth/db/[kvstore, kvstore_sqlite3],
|
||||||
../beacon_chain/ssz/[merkleization, ssz_serialization],
|
../beacon_chain/ssz/[merkleization, ssz_serialization],
|
||||||
./simutils
|
./simutils
|
||||||
|
@ -67,8 +68,8 @@ cli do(slots = SLOTS_PER_EPOCH * 6,
|
||||||
attestationHead = blockPool.head.blck.atSlot(slot)
|
attestationHead = blockPool.head.blck.atSlot(slot)
|
||||||
|
|
||||||
blockPool.withState(blockPool.tmpState, attestationHead):
|
blockPool.withState(blockPool.tmpState, attestationHead):
|
||||||
var cache = StateCache()
|
var cache = getEpochCache(attestationHead.blck, state)
|
||||||
let committees_per_slot = get_committee_count_at_slot(state, slot)
|
let committees_per_slot = get_committee_count_per_slot(state, slot, cache)
|
||||||
|
|
||||||
for committee_index in 0'u64..<committees_per_slot:
|
for committee_index in 0'u64..<committees_per_slot:
|
||||||
let committee = get_beacon_committee(
|
let committee = get_beacon_committee(
|
||||||
|
|
|
@ -107,12 +107,12 @@ cli do(slots = SLOTS_PER_EPOCH * 6,
|
||||||
# some variation
|
# some variation
|
||||||
let
|
let
|
||||||
target_slot = state[].data.slot + MIN_ATTESTATION_INCLUSION_DELAY - 1
|
target_slot = state[].data.slot + MIN_ATTESTATION_INCLUSION_DELAY - 1
|
||||||
commitee_count = get_committee_count_at_slot(state[].data, target_slot)
|
committees_per_slot = get_committee_count_per_slot(state[].data, target_slot, cache)
|
||||||
|
|
||||||
let
|
let
|
||||||
scass = withTimerRet(timers[tShuffle]):
|
scass = withTimerRet(timers[tShuffle]):
|
||||||
mapIt(
|
mapIt(
|
||||||
0 ..< commitee_count.int,
|
0 ..< committees_per_slot.int,
|
||||||
get_beacon_committee(state[].data, target_slot, it.CommitteeIndex, cache))
|
get_beacon_committee(state[].data, target_slot, it.CommitteeIndex, cache))
|
||||||
|
|
||||||
for i, scas in scass:
|
for i, scas in scass:
|
||||||
|
|
|
@ -39,14 +39,13 @@ proc addMockAttestations*(
|
||||||
get_shuffled_active_validator_indices(state, epoch)
|
get_shuffled_active_validator_indices(state, epoch)
|
||||||
var remaining_balance = state.get_total_active_balance(cache).int64 * 2 div 3
|
var remaining_balance = state.get_total_active_balance(cache).int64 * 2 div 3
|
||||||
|
|
||||||
let start_slot = compute_start_slot_at_epoch(epoch)
|
let
|
||||||
|
start_slot = compute_start_slot_at_epoch(epoch)
|
||||||
|
committees_per_slot = get_committee_count_per_slot(state, epoch, cache)
|
||||||
|
|
||||||
# for-loop of distinct type is broken: https://github.com/nim-lang/Nim/issues/12074
|
# for-loop of distinct type is broken: https://github.com/nim-lang/Nim/issues/12074
|
||||||
for slot in start_slot.uint64 ..< start_slot.uint64 + SLOTS_PER_EPOCH:
|
for slot in start_slot.uint64 ..< start_slot.uint64 + SLOTS_PER_EPOCH:
|
||||||
for index in 0 ..< get_committee_count_at_slot(state, slot.Slot):
|
for index in 0'u64 ..< committees_per_slot:
|
||||||
# TODO: can we move cache out of the loops
|
|
||||||
var cache = StateCache()
|
|
||||||
|
|
||||||
let committee = get_beacon_committee(
|
let committee = get_beacon_committee(
|
||||||
state, slot.Slot, index.CommitteeIndex, cache)
|
state, slot.Slot, index.CommitteeIndex, cache)
|
||||||
|
|
||||||
|
|
|
@ -291,11 +291,9 @@ suiteReport "Attestation pool processing" & preset():
|
||||||
doAssert: b10Add_clone.error == Duplicate
|
doAssert: b10Add_clone.error == Duplicate
|
||||||
|
|
||||||
wrappedTimedTest "Trying to add a duplicate block from an old pruned epoch is tagged as an error":
|
wrappedTimedTest "Trying to add a duplicate block from an old pruned epoch is tagged as an error":
|
||||||
var cache = StateCache()
|
|
||||||
|
|
||||||
blockpool[].addFlags {skipBLSValidation}
|
blockpool[].addFlags {skipBLSValidation}
|
||||||
pool.forkChoice_v2.proto_array.prune_threshold = 1
|
pool.forkChoice_v2.proto_array.prune_threshold = 1
|
||||||
|
var cache = StateCache()
|
||||||
let
|
let
|
||||||
b10 = makeTestBlock(state.data, blockPool[].tail.root, cache)
|
b10 = makeTestBlock(state.data, blockPool[].tail.root, cache)
|
||||||
b10Add = blockpool[].addRawBlock(b10) do (
|
b10Add = blockpool[].addRawBlock(b10) do (
|
||||||
|
@ -326,8 +324,10 @@ suiteReport "Attestation pool processing" & preset():
|
||||||
let start_slot = compute_start_slot_at_epoch(Epoch epoch)
|
let start_slot = compute_start_slot_at_epoch(Epoch epoch)
|
||||||
for slot in start_slot ..< start_slot + SLOTS_PER_EPOCH:
|
for slot in start_slot ..< start_slot + SLOTS_PER_EPOCH:
|
||||||
|
|
||||||
let new_block = makeTestBlock(state.data, block_root, cache, attestations = attestations)
|
let new_block = makeTestBlock(
|
||||||
let block_ok = state_transition(defaultRuntimePreset, state.data, new_block, {skipBLSValidation}, noRollback)
|
state.data, block_root, cache, attestations = attestations)
|
||||||
|
let block_ok = state_transition(
|
||||||
|
defaultRuntimePreset, state.data, new_block, {skipBLSValidation}, noRollback)
|
||||||
doAssert: block_ok
|
doAssert: block_ok
|
||||||
|
|
||||||
block_root = new_block.root
|
block_root = new_block.root
|
||||||
|
@ -344,7 +344,7 @@ suiteReport "Attestation pool processing" & preset():
|
||||||
blockPool[].updateHead(head)
|
blockPool[].updateHead(head)
|
||||||
|
|
||||||
attestations.setlen(0)
|
attestations.setlen(0)
|
||||||
for index in 0 ..< get_committee_count_at_slot(state.data.data, slot.Slot):
|
for index in 0'u64 ..< get_committee_count_per_slot(state.data.data, slot.Slot, cache):
|
||||||
let committee = get_beacon_committee(
|
let committee = get_beacon_committee(
|
||||||
state.data.data, state.data.data.slot, index.CommitteeIndex, cache)
|
state.data.data, state.data.data.slot, index.CommitteeIndex, cache)
|
||||||
|
|
||||||
|
|
|
@ -189,8 +189,8 @@ proc find_beacon_committee(
|
||||||
state: BeaconState, validator_index: ValidatorIndex,
|
state: BeaconState, validator_index: ValidatorIndex,
|
||||||
cache: var StateCache): auto =
|
cache: var StateCache): auto =
|
||||||
let epoch = compute_epoch_at_slot(state.slot)
|
let epoch = compute_epoch_at_slot(state.slot)
|
||||||
for epoch_committee_index in 0'u64 ..< get_committee_count_at_slot(
|
for epoch_committee_index in 0'u64 ..< get_committee_count_per_slot(
|
||||||
state, epoch.compute_start_slot_at_epoch) * SLOTS_PER_EPOCH:
|
state, epoch, cache) * SLOTS_PER_EPOCH:
|
||||||
let
|
let
|
||||||
slot = ((epoch_committee_index mod SLOTS_PER_EPOCH) +
|
slot = ((epoch_committee_index mod SLOTS_PER_EPOCH) +
|
||||||
epoch.compute_start_slot_at_epoch.uint64).Slot
|
epoch.compute_start_slot_at_epoch.uint64).Slot
|
||||||
|
@ -216,9 +216,9 @@ proc makeFullAttestations*(
|
||||||
# Create attestations in which the full committee participates for each shard
|
# Create attestations in which the full committee participates for each shard
|
||||||
# that should be attested to during a particular slot
|
# that should be attested to during a particular slot
|
||||||
let
|
let
|
||||||
count = get_committee_count_at_slot(state, slot)
|
committees_per_slot = get_committee_count_per_slot(state, slot, cache)
|
||||||
|
|
||||||
for index in 0..<count:
|
for index in 0'u64..<committees_per_slot:
|
||||||
let
|
let
|
||||||
committee = get_beacon_committee(
|
committee = get_beacon_committee(
|
||||||
state, slot, index.CommitteeIndex, cache)
|
state, slot, index.CommitteeIndex, cache)
|
||||||
|
|
Loading…
Reference in New Issue