fix remaining test 0.9.0 test fixtures and switch back to non-transitiontest setup; remove get_committee_count(...); keep SHARD_COUNT consistent with MAX_COMMITTEES_PER_SLOT

This commit is contained in:
Dustin Brody 2019-11-11 09:11:46 +01:00 committed by zah
parent 3192d1fb4d
commit 949d735155
14 changed files with 30 additions and 61 deletions

View File

@ -57,11 +57,8 @@ task test, "Run all tests":
#buildBinary "test_fixture_ssz_static", "tests/official/", "-r -d:release -d:chronicles_log_level=DEBUG -d:const_preset=minimal"
#buildBinary "test_fixture_ssz_static", "tests/official/", "-r -d:release -d:chronicles_log_level=DEBUG -d:const_preset=mainnet"
buildBinary "transition_0_9_0", "tests/", "-r -d:release -d:chronicles_log_level=DEBUG -d:const_preset=minimal"
buildBinary "transition_0_9_0", "tests/", "-r -d:release -d:chronicles_log_level=DEBUG -d:const_preset=mainnet"
#buildBinary "all_fixtures_require_ssz", "tests/official/", "-r -d:release -d:chronicles_log_level=DEBUG -d:const_preset=minimal"
#buildBinary "all_fixtures_require_ssz", "tests/official/", "-r -d:release -d:chronicles_log_level=DEBUG -d:const_preset=mainnet"
buildBinary "all_fixtures_require_ssz", "tests/official/", "-r -d:release -d:chronicles_log_level=DEBUG -d:const_preset=minimal"
buildBinary "all_fixtures_require_ssz", "tests/official/", "-r -d:release -d:chronicles_log_level=DEBUG -d:const_preset=mainnet"
# State sim; getting into 3rd epoch useful
buildBinary "state_sim", "research/", "-r -d:release", "--validators=128 --slots=24"

View File

@ -513,7 +513,8 @@ proc handleAttestations(node: BeaconNode, head: BlockRef, slot: Slot) =
var cache = get_empty_per_epoch_cache()
let
epoch = compute_epoch_at_slot(slot)
committees_per_slot = get_committee_count(state, epoch) div SLOTS_PER_EPOCH
committees_per_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

View File

@ -303,7 +303,8 @@ func get_attestation_data_slot*(state: BeaconState,
func get_attestation_data_slot*(state: BeaconState,
data: AttestationData): Slot =
get_attestation_data_slot(
state, data, get_committee_count(state, data.target.epoch))
state, data, get_committee_count_at_slot(
state, data.target.epoch.compute_start_slot_at_epoch) * SLOTS_PER_EPOCH)
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.0/specs/core/0_beacon-chain.md#get_block_root_at_slot
func get_block_root_at_slot*(state: BeaconState,

View File

@ -665,11 +665,6 @@ chronicles.formatIt Epoch: it.shortLog
chronicles.formatIt BeaconBlock: it.shortLog
chronicles.formatIt AttestationData: it.shortLog
static:
# Ensure that get_crosslink_committee(...) can access all committees, which
# requires that SHARD_COUNT >= get_committee_count(...)
doAssert SHARD_COUNT >= SLOTS_PER_EPOCH, "Shard count should match or exceed number of slots per epoch"
import json_serialization
export json_serialization
export writeValue, readValue

View File

@ -54,7 +54,7 @@ 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.9.0/specs/core/0_beacon-chain.md#get_committee_count
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.0/specs/core/0_beacon-chain.md#get_committee_count_at_slot
func get_committee_count_at_slot*(state: BeaconState, slot: Slot): uint64 =
# Return the number of committees at ``slot``.
let epoch = compute_epoch_at_slot(slot)
@ -68,18 +68,6 @@ func get_committee_count_at_slot*(state: BeaconState, slot: Slot): uint64 =
# committees.
doAssert (SLOTS_PER_EPOCH * MAX_COMMITTEES_PER_SLOT).uint64 >= result
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.4/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)
let committees_per_slot = clamp(
len(active_validator_indices) div SLOTS_PER_EPOCH div TARGET_COMMITTEE_SIZE,
1, SHARD_COUNT div SLOTS_PER_EPOCH).uint64
result = committees_per_slot * SLOTS_PER_EPOCH
# Otherwise, get_crosslink_committee(...) cannot access some committees.
doAssert SHARD_COUNT >= result
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.0/specs/core/0_beacon-chain.md#get_current_epoch
func get_current_epoch*(state: BeaconState): Epoch =
# Return the current epoch.

View File

@ -24,10 +24,9 @@ const
MAX_COMMITTEES_PER_SLOT* = 64
SHARD_COUNT* {.intdefine.} = 1024 ##\
## Number of shards supported by the network - validators will jump around
## between these shards and provide attestations to their state.
## Compile with -d:SHARD_COUNT=4 for fewer shard (= better with low validator counts)
# TODO remove
SHARD_COUNT* = 2048 ##\
## SLOTS_PER_EPOCH * MAX_COMMITTEES_PER_SLOT
TARGET_COMMITTEE_SIZE* = 2^7 ##\
## Number of validators in the committee attesting to one shard

View File

@ -22,13 +22,14 @@ const
# ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.4/configs/minimal.yaml#L4
# TODO remove
SHARD_COUNT* {.intdefine.} = 8
# Changed
MAX_COMMITTEES_PER_SLOT* = 4
TARGET_COMMITTEE_SIZE* = 4
# TODO remove
SHARD_COUNT* = 32 ##\
## SLOTS_PER_EPOCH * MAX_COMMITTEES_PER_SLOT
# Unchanged
MAX_VALIDATORS_PER_COMMITTEE* = 2048
MIN_PER_EPOCH_CHURN_LIMIT* = 4

View File

@ -24,7 +24,7 @@ func shortLog*(x: Checkpoint): string =
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.4/specs/core/0_beacon-chain.md#get_attesting_indices
# TODO there's another one of these, check for redundancy
func get_attesting_indices*(
func get_attesting_indices(
state: BeaconState, attestations: openarray[PendingAttestation],
stateCache: var StateCache): HashSet[ValidatorIndex] =
result = initSet[ValidatorIndex]()

View File

@ -91,7 +91,8 @@ 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_committee_count(state, 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
@ -159,11 +160,12 @@ 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.8.4/specs/core/0_beacon-chain.md#get_beacon_committee
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.0/specs/core/0_beacon-chain.md#get_beacon_committee
func get_beacon_committee*(state: BeaconState, slot: Slot, index: uint64, cache: var StateCache): seq[ValidatorIndex] =
# Return the beacon committee at ``slot`` for ``index``.
let
epoch = compute_epoch_at_slot(slot)
# TODO use state caching for this or not?
committees_per_slot = get_committee_count_at_slot(state, slot)
## This is a somewhat more fragile, but high-ROI, caching setup --
@ -173,19 +175,16 @@ func get_beacon_committee*(state: BeaconState, slot: Slot, index: uint64, cache:
cache.active_validator_indices_cache[epoch] =
get_active_validator_indices(state, epoch)
if epoch notin cache.committee_count_cache:
cache.committee_count_cache[epoch] = get_committee_count(state, epoch)
# TODO remove or replace this...
#if epoch notin cache.committee_count_cache:
# cache.committee_count_cache[epoch] = get_committee_count(state, epoch)
# TODO profiling & make sure caches populated
compute_committee(
cache.active_validator_indices_cache[epoch],
get_seed(state, epoch, DOMAIN_BEACON_ATTESTER),
(slot mod SLOTS_PER_EPOCH) * committees_per_slot + index,
# TODO switch to 0.9's
# committees_per_slot * SLOTS_PER_EPOCH,
cache.committee_count_cache[epoch],
committees_per_slot * SLOTS_PER_EPOCH,
cache
)

View File

@ -97,7 +97,8 @@ cli do(slots = 448'u,
epoch = compute_epoch_at_slot(state.slot)
scass = withTimerRet(timers[tShuffle]):
mapIt(
0'u64 .. (get_committee_count(state, epoch) - 1),
0'u64 .. (get_committee_count_at_slot(state, state.slot) *
SLOTS_PER_EPOCH - 1),
get_crosslink_committee(state, epoch,
(it + get_start_shard(state, epoch)) mod SHARD_COUNT,
cache))

View File

@ -108,7 +108,8 @@ proc mockAttestationImpl(
let
epoch = compute_epoch_at_slot(slot)
epoch_start_shard = get_start_shard(state, epoch)
committees_per_slot = get_committee_count(state, epoch) div SLOTS_PER_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)

View File

@ -22,7 +22,7 @@ iterator getShardsForSlot(state: BeaconState, slot: Slot): Shard =
let
epoch = compute_epoch_at_slot(slot)
epoch_start_shard = get_start_shard(state, epoch)
committees_per_slot = get_committee_count(state, epoch) div SLOTS_PER_EPOCH
committees_per_slot = get_committee_count_at_slot(state, slot)
shard = epoch_start_shard + committees_per_slot * (slot mod SLOTS_PER_EPOCH)
for i in 0 ..< committees_per_slot.int:

View File

@ -161,7 +161,8 @@ proc find_shard_committee(
state: BeaconState, validator_index: ValidatorIndex): auto =
let epoch = compute_epoch_at_slot(state.slot)
var cache = get_empty_per_epoch_cache()
for shard in 0'u64 ..< get_committee_count(state, epoch):
for shard in 0'u64 ..< get_committee_count_at_slot(
state, epoch.compute_start_slot_at_epoch) * SLOTS_PER_EPOCH:
let committee = get_crosslink_committee(state, epoch,
(shard + get_start_shard(state, epoch)) mod SHARD_COUNT, cache)
if validator_index in committee:

View File

@ -1,15 +0,0 @@
import
official/test_fixture_bls,
official/test_fixture_operations_attester_slashings,
official/test_fixture_operations_proposer_slashings,
official/test_fixture_shuffling,
official/test_fixture_operations_block_header,
official/test_fixture_sanity_blocks,
official/test_fixture_ssz_generic_types,
official/test_fixture_sanity_slots,
official/test_fixture_operations_voluntary_exit,
official/test_fixture_ssz_uint,
official/test_fixture_operations_deposits,
spec_block_processing/test_process_attestation,
spec_block_processing/test_process_deposits,
spec_epoch_processing/test_process_justification_and_finalization