From 125660c5af055209c8bdeb422947f85e4b518626 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Sun, 30 Jun 2019 03:20:11 +0800 Subject: [PATCH] Update input `deposits` type from `Sequence[Deposit]` to `List[Deposit, 2**DEPOSIT_CONTRACT_TREE_DEPTH` and fix tests --- specs/core/0_beacon-chain.md | 17 ++++++++++------- .../pyspec/eth2spec/test/helpers/deposits.py | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 5aa57c294..a77ec77a3 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1092,9 +1092,8 @@ def slash_validator(state: BeaconState, ### Genesis trigger -Before genesis has been triggered and whenever the deposit contract emits a `Deposit` log, call the function `is_genesis_trigger(deposits: Sequence[Deposit], timestamp: uint64) -> bool` where: - -* `deposits` is the list of all deposits, ordered chronologically, up to and including the deposit triggering the latest `Deposit` log +Before genesis has been triggered and for every Ethereum 1.0 block call `is_genesis_trigger(deposits: Sequence[Deposit], timestamp: uint64) -> bool` where: +* `deposits` is the SSZ list of all deposits, ordered chronologically, up to and including the deposit triggering the latest `Deposit` log * `timestamp` is the Unix timestamp in the Ethereum 1.0 block that emitted the latest `Deposit` log When `is_genesis_trigger(deposits, timestamp) is True` for the first time, let: @@ -1114,9 +1113,11 @@ def is_genesis_trigger(deposits: List[Deposit, 2**DEPOSIT_CONTRACT_TREE_DEPTH], # Process deposits state = BeaconState() - leaves = list(map(lambda deposit: hash_tree_root(deposit.data), deposits)) + leaves = list(map(lambda deposit: deposit.data, deposits)) for deposit_index, deposit in enumerate(deposits): - state.eth1_data.deposit_root = hash_tree_root(leaves) + state.eth1_data.deposit_root = hash_tree_root( + List[DepositData, 2**DEPOSIT_CONTRACT_TREE_DEPTH](*leaves[:deposit_index + 1]) + ) state.eth1_data.deposit_count = deposit_index + 1 state.eth1_deposit_index = deposit_index process_deposit(state, deposit) @@ -1146,9 +1147,11 @@ def get_genesis_beacon_state(deposits: List[Deposit, 2**DEPOSIT_CONTRACT_TREE_DE ) # Process genesis deposits - leaves = list(map(lambda deposit: hash_tree_root(deposit.data), deposits)) + leaves = list(map(lambda deposit: deposit.data, deposits)) for deposit_index, deposit in enumerate(deposits): - state.eth1_data.deposit_root = hash_tree_root(leaves) + state.eth1_data.deposit_root = hash_tree_root( + List[DepositData, 2**DEPOSIT_CONTRACT_TREE_DEPTH](*leaves[:deposit_index + 1]) + ) state.eth1_data.deposit_count = deposit_index + 1 state.eth1_deposit_index = deposit_index process_deposit(state, deposit) diff --git a/test_libs/pyspec/eth2spec/test/helpers/deposits.py b/test_libs/pyspec/eth2spec/test/helpers/deposits.py index b46363e62..f79dcf3ff 100644 --- a/test_libs/pyspec/eth2spec/test/helpers/deposits.py +++ b/test_libs/pyspec/eth2spec/test/helpers/deposits.py @@ -75,7 +75,7 @@ def prepare_genesis_deposits(spec, genesis_validator_count, amount, signed=False ) genesis_deposits.append(deposit) - return genesis_deposits, root + return List[spec.Deposit, 2**spec.DEPOSIT_CONTRACT_TREE_DEPTH](*genesis_deposits), root def prepare_state_and_deposit(spec, state, validator_index, amount, withdrawal_credentials=None, signed=False):