From 7e630bf8bfcec497001026a7b0d0d2d66703add6 Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Mon, 19 Nov 2018 18:47:57 +0200 Subject: [PATCH] Fixed compilation errors. Reenabled test --- beacon_chain/private/helpers.nim | 4 ++-- beacon_chain/state_transition.nim | 8 ++++---- tests/all_tests.nim | 4 ++-- tests/test_block_processing.nim | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/beacon_chain/private/helpers.nim b/beacon_chain/private/helpers.nim index 6f70d5b8b..95a271da9 100644 --- a/beacon_chain/private/helpers.nim +++ b/beacon_chain/private/helpers.nim @@ -95,7 +95,7 @@ func get_new_shuffling*(seed: Blake2_256_Digest, validators: seq[ValidatorRecord result.add committees func get_shards_and_committees_for_slot*(state: BeaconState, - slot: uint64): ShardAndCommittee = + slot: uint64): seq[ShardAndCommittee] = # TODO: Spec why is active_state an argument? # TODO: this returns a scalar, not vector, but its return type in spec is a seq/list? @@ -103,7 +103,7 @@ func get_shards_and_committees_for_slot*(state: BeaconState, assert earliest_slot_in_array <= slot assert slot < earliest_slot_in_array + CYCLE_LENGTH * 2 - return state.shard_and_committee_for_slots[int slot - earliest_slot_in_array] + return @[state.shard_and_committee_for_slots[int slot - earliest_slot_in_array]] # TODO, slot is a uint64; will be an issue on int32 arch. # Clarify with EF if light clients will need the beacon chain diff --git a/beacon_chain/state_transition.nim b/beacon_chain/state_transition.nim index a447e501f..f4e26a256 100644 --- a/beacon_chain/state_transition.nim +++ b/beacon_chain/state_transition.nim @@ -26,7 +26,7 @@ import milagro_crypto # nimble install https://github.com/status-im/nim-milagro-crypto@#master -func process_block*(active_state: ActiveState, crystallized_state: CrystallizedState, blck: BeaconBlock, slot: uint64) = +func process_block*(active_state: BeaconState, crystallized_state: BeaconState, blck: BeaconBlock, slot: uint64) = # TODO: unfinished spec for attestation in blck.attestations: @@ -40,7 +40,7 @@ func process_block*(active_state: ActiveState, crystallized_state: CrystallizedS # TODO - don't allocate in tight loop var parent_hashes = newSeq[Blake2_256_Digest](CYCLE_LENGTH - attestation.oblique_parent_hashes.len) for idx, val in parent_hashes.mpairs: - val = get_block_hash(active_state, blck, slot - CYCLE_LENGTH + cast[uint64](idx) + 1) + val = get_block_hash(active_state, blck, cast[int](slot - CYCLE_LENGTH + cast[uint64](idx) + 1)) parent_hashes.add attestation.oblique_parent_hashes # Let attestation_indices be get_shards_and_committees_for_slot(crystallized_state, slot)[x], choosing x so that attestation_indices.shard_id equals the shard_id value provided to find the set of validators that is creating this attestation record. @@ -49,7 +49,7 @@ func process_block*(active_state: ActiveState, crystallized_state: CrystallizedS var x = 1 record_creator = shard_and_committees[0] - while record_creator.shard_id != attestation.shard_id: + while record_creator.shard_id != attestation.shard: record_creator = shard_and_committees[x] inc x record_creator @@ -84,7 +84,7 @@ func process_block*(active_state: ActiveState, crystallized_state: CrystallizedS ctx.update(cast[ptr byte](parent_hashes[0].addr), size_p_hashes) var be_shard_id: array[2, byte] # Unsure, spec doesn't mention big-endian representation - bigEndian16(be_shard_id.addr, attestation.shard_id.unsafeAddr) + bigEndian16(be_shard_id.addr, attestation.shard.unsafeAddr) ctx.update be_shard_id ctx.update attestation.shard_block_hash.data diff --git a/tests/all_tests.nim b/tests/all_tests.nim index fa3cf66c9..89bb553b3 100644 --- a/tests/all_tests.nim +++ b/tests/all_tests.nim @@ -6,5 +6,5 @@ # at your option. This file may not be copied, modified, or distributed except according to those terms. import - ./test_ssz - # ./test_block_processing + ./test_ssz, + ./test_block_processing diff --git a/tests/test_block_processing.nim b/tests/test_block_processing.nim index 79adc7ed5..2b67d129e 100644 --- a/tests/test_block_processing.nim +++ b/tests/test_block_processing.nim @@ -13,8 +13,8 @@ suite "Block processing": ## For now just test that we can compile and execute block processing with mock data. test "Mock process_block": - let actState = ActiveState() - let crystState = CrystallizedState() + let actState = BeaconState() + let crystState = BeaconState() let blck = BeaconBlock() let slot = 10'u