diff --git a/research/state_sim.nim b/research/state_sim.nim index a932ecc8a..e7dc2be63 100644 --- a/research/state_sim.nim +++ b/research/state_sim.nim @@ -57,7 +57,7 @@ cli do(slots = SLOTS_PER_EPOCH * 6, validators = SLOTS_PER_EPOCH * 11, # One per shard is minimum json_interval = SLOTS_PER_EPOCH, prefix = 0, - attesterRatio {.desc: "ratio of validators that attest in each round"} = 0.75, + attesterRatio {.desc: "ratio of validators that attest in each round"} = 0.73, validate = true): let flags = if validate: {} else: {skipValidation} @@ -83,6 +83,10 @@ cli do(slots = SLOTS_PER_EPOCH * 6, else: write(stdout, ".") + # TODO doAssert against this up-front + # indexed attestation: validator index beyond max validators per committee + # len(indices) <= MAX_VALIDATORS_PER_COMMITTEE + for i in 0.. attestations_idx: - var target_slot_attestations = - getOrDefault(attestations, target_slot) - target_slot_attestations.add attestation - attestations[target_slot] = target_slot_attestations + doAssert target_slot > attestations_idx + var target_slot_attestations = + getOrDefault(attestations, target_slot) + target_slot_attestations.add attestation + attestations[target_slot] = target_slot_attestations flushFile(stdout) diff --git a/tests/test_peer_pool.nim b/tests/test_peer_pool.nim index a7c194043..3b85d78b1 100644 --- a/tests/test_peer_pool.nim +++ b/tests/test_peer_pool.nim @@ -1,8 +1,8 @@ # beacon_chain # Copyright (c) 2019 Status Research & Development GmbH # Licensed and distributed under either of -# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT). -# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0). +# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). +# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. import diff --git a/tests/testutil.nim b/tests/testutil.nim index 021b3086c..dcdc6eeac 100644 --- a/tests/testutil.nim +++ b/tests/testutil.nim @@ -164,11 +164,14 @@ proc find_beacon_committee( proc makeAttestation*( state: BeaconState, beacon_block_root: Eth2Digest, - validator_index: ValidatorIndex, cache: var StateCache, + committee: seq[ValidatorIndex], slot: Slot, index: uint64, + validator_index: auto, cache: var StateCache, flags: UpdateFlags = {}): Attestation = + # Avoids state_sim silliness; as it's responsible for all validators, + # transforming, from monotonic enumerable index -> committee index -> + # montonoic enumerable index, is wasteful and slow. Most test callers + # want ValidatorIndex, so that's supported too. let - (committee, slot, index) = - find_beacon_committee(state, validator_index, cache) validator = state.validators[validator_index] sac_index = committee.find(validator_index) data = makeAttestationData(state, slot, index, beacon_block_root) @@ -197,6 +200,15 @@ proc makeAttestation*( signature: sig ) +proc makeAttestation*( + state: BeaconState, beacon_block_root: Eth2Digest, + validator_index: ValidatorIndex, cache: var StateCache, + flags: UpdateFlags = {}): Attestation = + let (committee, slot, index) = + find_beacon_committee(state, validator_index, cache) + makeAttestation(state, beacon_block_root, committee, slot, index, + validator_index, cache, flags) + proc makeTestDB*(tailState: BeaconState, tailBlock: BeaconBlock): BeaconChainDB = result = init(BeaconChainDB, newMemoryDB()) BlockPool.preInit(result, tailState, tailBlock)