Update input `deposits` type from `Sequence[Deposit]` to `List[Deposit, 2**DEPOSIT_CONTRACT_TREE_DEPTH` and fix tests
This commit is contained in:
parent
ff185c3486
commit
125660c5af
|
@ -1092,9 +1092,8 @@ def slash_validator(state: BeaconState,
|
||||||
|
|
||||||
### Genesis trigger
|
### 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:
|
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
|
||||||
* `deposits` is the 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
|
* `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:
|
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
|
# Process deposits
|
||||||
state = BeaconState()
|
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):
|
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_data.deposit_count = deposit_index + 1
|
||||||
state.eth1_deposit_index = deposit_index
|
state.eth1_deposit_index = deposit_index
|
||||||
process_deposit(state, deposit)
|
process_deposit(state, deposit)
|
||||||
|
@ -1146,9 +1147,11 @@ def get_genesis_beacon_state(deposits: List[Deposit, 2**DEPOSIT_CONTRACT_TREE_DE
|
||||||
)
|
)
|
||||||
|
|
||||||
# Process genesis deposits
|
# 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):
|
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_data.deposit_count = deposit_index + 1
|
||||||
state.eth1_deposit_index = deposit_index
|
state.eth1_deposit_index = deposit_index
|
||||||
process_deposit(state, deposit)
|
process_deposit(state, deposit)
|
||||||
|
|
|
@ -75,7 +75,7 @@ def prepare_genesis_deposits(spec, genesis_validator_count, amount, signed=False
|
||||||
)
|
)
|
||||||
genesis_deposits.append(deposit)
|
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):
|
def prepare_state_and_deposit(spec, state, validator_index, amount, withdrawal_credentials=None, signed=False):
|
||||||
|
|
Loading…
Reference in New Issue