Skip to content

Commit

Permalink
Add BeaconState.deposit_index (ethereum/consensus-specs#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
hwwhww committed Feb 17, 2019
1 parent 4225dd6 commit 148e2c6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions eth2/beacon/on_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def get_genesis_beacon_state(*,
# Ethereum 1.0 chain data
latest_eth1_data=latest_eth1_data,
eth1_data_votes=(),
deposit_index=len(genesis_validator_deposits),
)

# Process initial deposits
Expand Down
6 changes: 5 additions & 1 deletion eth2/beacon/types/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class BeaconState(rlp.Serializable):
# Ethereum 1.0 chain
('latest_eth1_data', Eth1Data),
('eth1_data_votes', CountableList(Eth1DataVote)),
('deposit_index', uint64),
]

def __init__(
Expand Down Expand Up @@ -122,7 +123,8 @@ def __init__(
latest_attestations: Sequence[PendingAttestationRecord],
# Ethereum 1.0 chain
latest_eth1_data: Eth1Data,
eth1_data_votes: Sequence[Eth1DataVote]) -> None:
eth1_data_votes: Sequence[Eth1DataVote],
deposit_index: int) -> None:
if len(validator_registry) != len(validator_balances):
raise ValueError(
"The length of validator_registry and validator_balances should be the same."
Expand Down Expand Up @@ -159,6 +161,7 @@ def __init__(
# Ethereum 1.0 chain
latest_eth1_data=latest_eth1_data,
eth1_data_votes=eth1_data_votes,
deposit_index=deposit_index,
)

def __repr__(self) -> str:
Expand Down Expand Up @@ -244,6 +247,7 @@ def create_filled_state(cls,
# Ethereum 1.0 chain data
latest_eth1_data=Eth1Data.create_empty_data(),
eth1_data_votes=(),
deposit_index=len(activated_genesis_validators),
)

def update_validator_registry(self,
Expand Down
1 change: 1 addition & 0 deletions tests/eth2/beacon/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def sample_beacon_state_params(sample_fork_params, sample_eth1_data_params):
'batched_block_roots': (),
'latest_eth1_data': Eth1Data(**sample_eth1_data_params),
'eth1_data_votes': (),
'deposit_index': 0,
}


Expand Down
3 changes: 2 additions & 1 deletion tests/eth2/beacon/test_on_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_get_genesis_beacon_state(

validator_count = 5

genesis_validator_deposits = (
genesis_validator_deposits = tuple(
Deposit(
branch=(
b'\x11' * 32
Expand Down Expand Up @@ -171,5 +171,6 @@ def test_get_genesis_beacon_state(
# Ethereum 1.0 chain data
assert state.latest_eth1_data == latest_eth1_data
assert len(state.eth1_data_votes) == 0
assert state.deposit_index == len(genesis_validator_deposits)

assert state.validator_registry[0].is_active(genesis_epoch)

0 comments on commit 148e2c6

Please sign in to comment.