From 7e70d16da924c6ff78fd8bba3a8b6c7561e56e7e Mon Sep 17 00:00:00 2001 From: Dustin Brody Date: Thu, 14 Nov 2019 20:03:08 +0100 Subject: [PATCH] remove BeaconStateNew and associated testing scaffolding/infrastructure --- beacon_chain/spec/datatypes.nim | 106 ------------------ .../test_fixture_operations_deposits.nim | 17 +-- tests/official/test_fixture_sanity_blocks.nim | 7 +- tests/official/test_fixture_sanity_slots.nim | 7 +- .../test_fixture_state_transition_epoch.nim | 7 +- 5 files changed, 9 insertions(+), 135 deletions(-) diff --git a/beacon_chain/spec/datatypes.nim b/beacon_chain/spec/datatypes.nim index cacb75109..14173d1be 100644 --- a/beacon_chain/spec/datatypes.nim +++ b/beacon_chain/spec/datatypes.nim @@ -190,64 +190,6 @@ type deposits*: List[Deposit, MAX_DEPOSITS] voluntary_exits*: List[VoluntaryExit, MAX_VOLUNTARY_EXITS] - # https://github.com/ethereum/eth2.0-specs/blob/v0.9.1/specs/core/0_beacon-chain.md#beaconstate - BeaconStateNew* = object - # Versioning - genesis_time*: uint64 - slot*: Slot - fork*: Fork - - # History - latest_block_header*: BeaconBlockHeader ##\ - ## `latest_block_header.state_root == ZERO_HASH` temporarily - - block_roots*: array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest] ##\ - ## Needed to process attestations, older to newer - - state_roots*: array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest] - - historical_roots*: seq[Eth2Digest] ##\ - ## model List with HISTORICAL_ROOTS_LIMIT limit as seq - ## TODO bound explicitly somewhere - - # Eth1 - eth1_data*: Eth1Data - - eth1_data_votes*: seq[Eth1Data] ##\ - ## As with `hitorical_roots`, this is a `List`. TODO bound explicitly. - - eth1_deposit_index*: uint64 - - # Registry - validators*: seq[Validator] - balances*: seq[uint64] ##\ - ## Validator balances in Gwei! - ## Also more `List`s which need to be bounded explicitly at - ## VALIDATOR_REGISTRY_LIMIT - - # Randomness - randao_mixes*: array[EPOCHS_PER_HISTORICAL_VECTOR, Eth2Digest] - - # Slashings - slashings*: array[EPOCHS_PER_SLASHINGS_VECTOR, uint64] ##\ - ## Per-epoch sums of slashed effective balances - - # Attestations - previous_epoch_attestations*: seq[PendingAttestation] - current_epoch_attestations*: seq[PendingAttestation] - - # Finality - justification_bits*: uint8 ##\ - ## Bit set for every recent justified epoch - ## Model a Bitvector[4] as a one-byte uint, which should remain consistent - ## with ssz/hashing. - - previous_justified_checkpoint*: Checkpoint ##\ - ## Previous epoch snapshot - - current_justified_checkpoint*: Checkpoint - finalized_checkpoint*: Checkpoint - # https://github.com/ethereum/eth2.0-specs/blob/v0.9.1/specs/core/0_beacon-chain.md#beaconstate BeaconState* = object # Versioning @@ -511,54 +453,6 @@ proc `$`*(x: ValidatorIndex): auto = $(x.int64) ethTimeUnit Slot ethTimeUnit Epoch -func GetOldBeaconState*(newState: BeaconStateNew): BeaconState = - BeaconState( - genesis_time: newState.genesis_time, - slot: newState.slot, - fork: newState.fork, - latest_block_header: newState.latest_block_header, - block_roots: newState.block_roots, - state_roots: newState.state_roots, - historical_roots: newState.historical_roots, - eth1_data: newState.eth1_data, - eth1_data_votes: newState.eth1_data_votes, - eth1_deposit_index: newState.eth1_deposit_index, - validators: newState.validators, - balances: newState.balances, - randao_mixes: newState.randao_mixes, - slashings: newState.slashings, - previous_epoch_attestations: newState.previous_epoch_attestations, - current_epoch_attestations: newState.current_epoch_attestations, - justification_bits: newState.justification_bits, - previous_justified_checkpoint: newState.previous_justified_checkpoint, - current_justified_checkpoint: newState.current_justified_checkpoint, - finalized_checkpoint: newState.finalized_checkpoint - ) - -func GetNewBeaconState*(oldState: BeaconState): BeaconStateNew = - BeaconStateNew( - genesis_time: oldState.genesis_time, - slot: oldState.slot, - fork: oldState.fork, - latest_block_header: oldState.latest_block_header, - block_roots: oldState.block_roots, - state_roots: oldState.state_roots, - historical_roots: oldState.historical_roots, - eth1_data: oldState.eth1_data, - eth1_data_votes: oldState.eth1_data_votes, - eth1_deposit_index: oldState.eth1_deposit_index, - validators: oldState.validators, - balances: oldState.balances, - randao_mixes: oldState.randao_mixes, - slashings: oldState.slashings, - previous_epoch_attestations: oldState.previous_epoch_attestations, - current_epoch_attestations: oldState.current_epoch_attestations, - justification_bits: oldState.justification_bits, - previous_justified_checkpoint: oldState.previous_justified_checkpoint, - current_justified_checkpoint: oldState.current_justified_checkpoint, - finalized_checkpoint: oldState.finalized_checkpoint - ) - Json.useCustomSerialization(BeaconState.justification_bits): read: let s = reader.readValue(string) diff --git a/tests/official/test_fixture_operations_deposits.nim b/tests/official/test_fixture_operations_deposits.nim index 58407bdb5..ce196c667 100644 --- a/tests/official/test_fixture_operations_deposits.nim +++ b/tests/official/test_fixture_operations_deposits.nim @@ -40,29 +40,24 @@ template runTest(testName: string, identifier: untyped) = prefix = "[Invalid] " test prefix & testName & " (" & astToStr(identifier) & ")": - var stateRef, postRef: ref BeaconStateNew - var sr_pre, sr_post: ref BeaconState + var stateRef, postRef: ref BeaconState var depositRef: ref Deposit new depositRef new stateRef - new sr_pre - new sr_post depositRef[] = parseTest(testDir/"deposit.ssz", SSZ, Deposit) - stateRef[] = parseTest(testDir/"pre.ssz", SSZ, BeaconStateNew) - sr_pre[] = GetOldBeaconState(stateRef[]) + stateRef[] = parseTest(testDir/"pre.ssz", SSZ, BeaconState) if existsFile(testDir/"post.ssz"): new postRef - postRef[] = parseTest(testDir/"post.ssz", SSZ, BeaconStateNew) - sr_post[] = GetOldBeaconState(postRef[]) + postRef[] = parseTest(testDir/"post.ssz", SSZ, BeaconState) if postRef.isNil: expect(AssertionError): - let done = process_deposit(sr_pre[], depositRef[], flags) + discard process_deposit(stateRef[], depositRef[], flags) else: - let done = process_deposit(sr_pre[], depositRef[], flags) - reportDiff(sr_pre, sr_post) + discard process_deposit(stateRef[], depositRef[], flags) + reportDiff(stateRef, postRef) `testImpl _ operations_deposits _ identifier`() diff --git a/tests/official/test_fixture_sanity_blocks.nim b/tests/official/test_fixture_sanity_blocks.nim index f25a83a78..50013389e 100644 --- a/tests/official/test_fixture_sanity_blocks.nim +++ b/tests/official/test_fixture_sanity_blocks.nim @@ -46,12 +46,7 @@ template runValidTest(testName: string, identifier: untyped, num_blocks: int): u # Checks: # check: stateRef.hash_tree_root() == postRef.hash_tree_root() - var sr_pre, sr_post: ref BeaconStateNew - new sr_pre - new sr_post - sr_pre[] = GetNewBeaconState(stateRef[]) - sr_post[] = GetNewBeaconState(postRef[]) - reportDiff(sr_pre, sr_post) + reportDiff(stateRef, postRef) `testImpl _ blck _ identifier`() diff --git a/tests/official/test_fixture_sanity_slots.nim b/tests/official/test_fixture_sanity_slots.nim index 811fc8cbb..1a2b47ff7 100644 --- a/tests/official/test_fixture_sanity_slots.nim +++ b/tests/official/test_fixture_sanity_slots.nim @@ -39,12 +39,7 @@ template runTest(testName: string, identifier: untyped, num_slots: uint64): unty process_slots(stateRef[], stateRef.slot + num_slots) # check: stateRef.hash_tree_root() == postRef.hash_tree_root() - var sr_pre, sr_post: ref BeaconStateNew - new sr_pre - new sr_post - sr_pre[] = GetNewBeaconState(stateRef[]) - sr_post[] = GetNewBeaconState(postRef[]) - reportDiff(sr_pre, sr_post) + reportDiff(stateRef, postRef) `testImpl _ slots _ identifier`() diff --git a/tests/official/test_fixture_state_transition_epoch.nim b/tests/official/test_fixture_state_transition_epoch.nim index 36de79d83..4f11ac26c 100644 --- a/tests/official/test_fixture_state_transition_epoch.nim +++ b/tests/official/test_fixture_state_transition_epoch.nim @@ -50,12 +50,7 @@ template runSuite(suiteDir, testName: string, transitionProc: untyped{ident}, us else: transitionProc(stateRef[]) - var sr_pre, sr_post: ref BeaconStateNew - new sr_pre - new sr_post - sr_pre[] = GetNewBeaconState(stateRef[]) - sr_post[] = GetNewBeaconState(postRef[]) - reportDiff(sr_pre, sr_post) + reportDiff(stateRef, postRef) `suiteImpl _ transitionProc`()