eth1 vote period constant in epochs: update configs, phase1, tests

This commit is contained in:
protolambda 2020-03-10 18:36:53 +01:00
parent cfcb7b2f01
commit 2d7a292d36
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
6 changed files with 23 additions and 19 deletions

View File

@ -82,8 +82,8 @@ SLOTS_PER_EPOCH: 32
MIN_SEED_LOOKAHEAD: 1 MIN_SEED_LOOKAHEAD: 1
# 2**2 (= 4) epochs 25.6 minutes # 2**2 (= 4) epochs 25.6 minutes
MAX_SEED_LOOKAHEAD: 4 MAX_SEED_LOOKAHEAD: 4
# 2**10 (= 1,024) slots ~1.7 hours # 2**5 (= 32) epochs ~3.4 hours
SLOTS_PER_ETH1_VOTING_PERIOD: 1024 EPOCHS_PER_ETH1_VOTING_PERIOD: 32
# 2**13 (= 8,192) slots ~13 hours # 2**13 (= 8,192) slots ~13 hours
SLOTS_PER_HISTORICAL_ROOT: 8192 SLOTS_PER_HISTORICAL_ROOT: 8192
# 2**8 (= 256) epochs ~27 hours # 2**8 (= 256) epochs ~27 hours

View File

@ -82,7 +82,7 @@ MIN_SEED_LOOKAHEAD: 1
# 2**2 (= 4) epochs # 2**2 (= 4) epochs
MAX_SEED_LOOKAHEAD: 4 MAX_SEED_LOOKAHEAD: 4
# [customized] higher frequency new deposits from eth1 for testing # [customized] higher frequency new deposits from eth1 for testing
SLOTS_PER_ETH1_VOTING_PERIOD: 16 EPOCHS_PER_ETH1_VOTING_PERIOD: 2
# [customized] smaller state # [customized] smaller state
SLOTS_PER_HISTORICAL_ROOT: 64 SLOTS_PER_HISTORICAL_ROOT: 64
# 2**8 (= 256) epochs # 2**8 (= 256) epochs

View File

@ -129,7 +129,7 @@ To submit a deposit:
### Process deposit ### Process deposit
Deposits cannot be processed into the beacon chain until the Eth1 block in which they were deposited or any of its descendants is added to the beacon chain `state.eth1_data`. This takes _a minimum_ of `ETH1_FOLLOW_DISTANCE` Eth1 blocks (~4 hours) plus `SLOTS_PER_ETH1_VOTING_PERIOD` slots (~3.4 hours). Once the requisite Eth1 data is added, the deposit will normally be added to a beacon chain block and processed into the `state.validators` within an epoch or two. The validator is then in a queue to be activated. Deposits cannot be processed into the beacon chain until the Eth1 block in which they were deposited or any of its descendants is added to the beacon chain `state.eth1_data`. This takes _a minimum_ of `ETH1_FOLLOW_DISTANCE` Eth1 blocks (~4 hours) plus `EPOCHS_PER_ETH1_VOTING_PERIOD * SLOTS_PER_EPOCH` slots (~3.4 hours). Once the requisite Eth1 data is added, the deposit will normally be added to a beacon chain block and processed into the `state.validators` within an epoch or two. The validator is then in a queue to be activated.
### Validator index ### Validator index
@ -269,7 +269,7 @@ def compute_time_at_slot(state: BeaconState, slot: Slot) -> uint64:
```python ```python
def voting_period_start_time(state: BeaconState) -> uint64: def voting_period_start_time(state: BeaconState) -> uint64:
eth1_voting_period_start_slot = Slot(state.slot - state.slot % SLOTS_PER_ETH1_VOTING_PERIOD) eth1_voting_period_start_slot = Slot(state.slot - state.slot % (EPOCHS_PER_ETH1_VOTING_PERIOD * SLOTS_PER_EPOCH))
return compute_time_at_slot(state, eth1_voting_period_start_slot) return compute_time_at_slot(state, eth1_voting_period_start_slot)
``` ```

View File

@ -253,7 +253,7 @@ class BeaconState(Container):
historical_roots: List[Root, HISTORICAL_ROOTS_LIMIT] historical_roots: List[Root, HISTORICAL_ROOTS_LIMIT]
# Eth1 # Eth1
eth1_data: Eth1Data eth1_data: Eth1Data
eth1_data_votes: List[Eth1Data, SLOTS_PER_ETH1_VOTING_PERIOD] eth1_data_votes: List[Eth1Data, EPOCHS_PER_ETH1_VOTING_PERIOD * SLOTS_PER_EPOCH]
eth1_deposit_index: uint64 eth1_deposit_index: uint64
# Registry # Registry
validators: List[Validator, VALIDATOR_REGISTRY_LIMIT] validators: List[Validator, VALIDATOR_REGISTRY_LIMIT]

View File

@ -11,7 +11,7 @@ def run_process_final_updates(spec, state):
@with_all_phases @with_all_phases
@spec_state_test @spec_state_test
def test_eth1_vote_no_reset(spec, state): def test_eth1_vote_no_reset(spec, state):
assert spec.SLOTS_PER_ETH1_VOTING_PERIOD > spec.SLOTS_PER_EPOCH assert spec.EPOCHS_PER_ETH1_VOTING_PERIOD > 1
# skip ahead to the end of the epoch # skip ahead to the end of the epoch
state.slot = spec.SLOTS_PER_EPOCH - 1 state.slot = spec.SLOTS_PER_EPOCH - 1
for i in range(state.slot + 1): # add a vote for each skipped slot. for i in range(state.slot + 1): # add a vote for each skipped slot.
@ -29,7 +29,7 @@ def test_eth1_vote_no_reset(spec, state):
@spec_state_test @spec_state_test
def test_eth1_vote_reset(spec, state): def test_eth1_vote_reset(spec, state):
# skip ahead to the end of the voting period # skip ahead to the end of the voting period
state.slot = spec.SLOTS_PER_ETH1_VOTING_PERIOD - 1 state.slot = (spec.EPOCHS_PER_ETH1_VOTING_PERIOD * spec.SLOTS_PER_EPOCH) - 1
for i in range(state.slot + 1): # add a vote for each skipped slot. for i in range(state.slot + 1): # add a vote for each skipped slot.
state.eth1_data_votes.append( state.eth1_data_votes.append(
spec.Eth1Data(deposit_root=b'\xaa' * 32, spec.Eth1Data(deposit_root=b'\xaa' * 32,

View File

@ -486,10 +486,12 @@ def test_historical_batch(spec, state):
@spec_state_test @spec_state_test
def test_eth1_data_votes_consensus(spec, state): def test_eth1_data_votes_consensus(spec, state):
# Don't run when it will take very, very long to simulate. Minimal configuration suffices. # Don't run when it will take very, very long to simulate. Minimal configuration suffices.
if spec.SLOTS_PER_ETH1_VOTING_PERIOD > 16: if spec.EPOCHS_PER_ETH1_VOTING_PERIOD > 2:
return return
offset_block = build_empty_block(spec, state, slot=spec.SLOTS_PER_ETH1_VOTING_PERIOD - 1) voting_period_slots = spec.EPOCHS_PER_ETH1_VOTING_PERIOD * spec.SLOTS_PER_EPOCH
offset_block = build_empty_block(spec, state, slot=voting_period_slots - 1)
state_transition_and_sign_block(spec, state, offset_block) state_transition_and_sign_block(spec, state, offset_block)
yield 'pre', state yield 'pre', state
@ -499,14 +501,14 @@ def test_eth1_data_votes_consensus(spec, state):
blocks = [] blocks = []
for i in range(0, spec.SLOTS_PER_ETH1_VOTING_PERIOD): for i in range(0, voting_period_slots):
block = build_empty_block_for_next_slot(spec, state) block = build_empty_block_for_next_slot(spec, state)
# wait for over 50% for A, then start voting B # wait for over 50% for A, then start voting B
block.body.eth1_data.block_hash = b if i * 2 > spec.SLOTS_PER_ETH1_VOTING_PERIOD else a block.body.eth1_data.block_hash = b if i * 2 > voting_period_slots else a
signed_block = state_transition_and_sign_block(spec, state, block) signed_block = state_transition_and_sign_block(spec, state, block)
blocks.append(signed_block) blocks.append(signed_block)
assert len(state.eth1_data_votes) == spec.SLOTS_PER_ETH1_VOTING_PERIOD assert len(state.eth1_data_votes) == voting_period_slots
assert state.eth1_data.block_hash == a assert state.eth1_data.block_hash == a
# transition to next eth1 voting period # transition to next eth1 voting period
@ -519,7 +521,7 @@ def test_eth1_data_votes_consensus(spec, state):
yield 'post', state yield 'post', state
assert state.eth1_data.block_hash == a assert state.eth1_data.block_hash == a
assert state.slot % spec.SLOTS_PER_ETH1_VOTING_PERIOD == 0 assert state.slot % voting_period_slots == 0
assert len(state.eth1_data_votes) == 1 assert len(state.eth1_data_votes) == 1
assert state.eth1_data_votes[0].block_hash == c assert state.eth1_data_votes[0].block_hash == c
@ -528,12 +530,14 @@ def test_eth1_data_votes_consensus(spec, state):
@spec_state_test @spec_state_test
def test_eth1_data_votes_no_consensus(spec, state): def test_eth1_data_votes_no_consensus(spec, state):
# Don't run when it will take very, very long to simulate. Minimal configuration suffices. # Don't run when it will take very, very long to simulate. Minimal configuration suffices.
if spec.SLOTS_PER_ETH1_VOTING_PERIOD > 16: if spec.EPOCHS_PER_ETH1_VOTING_PERIOD > 2:
return return
voting_period_slots = spec.EPOCHS_PER_ETH1_VOTING_PERIOD * spec.SLOTS_PER_EPOCH
pre_eth1_hash = state.eth1_data.block_hash pre_eth1_hash = state.eth1_data.block_hash
offset_block = build_empty_block(spec, state, slot=spec.SLOTS_PER_ETH1_VOTING_PERIOD - 1) offset_block = build_empty_block(spec, state, slot=voting_period_slots - 1)
state_transition_and_sign_block(spec, state, offset_block) state_transition_and_sign_block(spec, state, offset_block)
yield 'pre', state yield 'pre', state
@ -542,14 +546,14 @@ def test_eth1_data_votes_no_consensus(spec, state):
blocks = [] blocks = []
for i in range(0, spec.SLOTS_PER_ETH1_VOTING_PERIOD): for i in range(0, voting_period_slots):
block = build_empty_block_for_next_slot(spec, state) block = build_empty_block_for_next_slot(spec, state)
# wait for precisely 50% for A, then start voting B for other 50% # wait for precisely 50% for A, then start voting B for other 50%
block.body.eth1_data.block_hash = b if i * 2 >= spec.SLOTS_PER_ETH1_VOTING_PERIOD else a block.body.eth1_data.block_hash = b if i * 2 >= voting_period_slots else a
signed_block = state_transition_and_sign_block(spec, state, block) signed_block = state_transition_and_sign_block(spec, state, block)
blocks.append(signed_block) blocks.append(signed_block)
assert len(state.eth1_data_votes) == spec.SLOTS_PER_ETH1_VOTING_PERIOD assert len(state.eth1_data_votes) == voting_period_slots
assert state.eth1_data.block_hash == pre_eth1_hash assert state.eth1_data.block_hash == pre_eth1_hash
yield 'blocks', blocks yield 'blocks', blocks