PR feedback

This commit is contained in:
Danny Ryan 2019-04-24 11:44:03 -06:00
parent 7f720133fa
commit 9e8a9a26fd
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
1 changed files with 10 additions and 5 deletions

View File

@ -73,7 +73,7 @@ def next_epoch_with_attestations(state,
return state, blocks, post_state return state, blocks, post_state
def test_finality_from_genesis_rule_4(state): def test_finality_rule_4(state):
test_state = deepcopy(state) test_state = deepcopy(state)
blocks = [] blocks = []
@ -81,8 +81,10 @@ def test_finality_from_genesis_rule_4(state):
prev_state, new_blocks, test_state = next_epoch_with_attestations(test_state, True, False) prev_state, new_blocks, test_state = next_epoch_with_attestations(test_state, True, False)
blocks += new_blocks blocks += new_blocks
# justification/finalization skipped at GENESIS_EPOCH
if epoch == 0: if epoch == 0:
check_finality(test_state, prev_state, False, False, False) check_finality(test_state, prev_state, False, False, False)
# justification/finalization skipped at GENESIS_EPOCH + 1
elif epoch == 1: elif epoch == 1:
check_finality(test_state, prev_state, False, False, False) check_finality(test_state, prev_state, False, False, False)
elif epoch == 2: elif epoch == 2:
@ -132,8 +134,6 @@ def test_finality_rule_2(state):
blocks = [] blocks = []
for epoch in range(3): for epoch in range(3):
old_previous_justified_epoch = test_state.previous_justified_epoch
old_previous_justified_root = test_state.previous_justified_root
if epoch == 0: if epoch == 0:
prev_state, new_blocks, test_state = next_epoch_with_attestations(test_state, True, False) prev_state, new_blocks, test_state = next_epoch_with_attestations(test_state, True, False)
check_finality(test_state, prev_state, True, False, False) check_finality(test_state, prev_state, True, False, False)
@ -144,8 +144,8 @@ def test_finality_rule_2(state):
prev_state, new_blocks, test_state = next_epoch_with_attestations(test_state, False, True) prev_state, new_blocks, test_state = next_epoch_with_attestations(test_state, False, True)
# finalized by rule 2 # finalized by rule 2
check_finality(test_state, prev_state, True, False, True) check_finality(test_state, prev_state, True, False, True)
assert test_state.finalized_epoch == old_previous_justified_epoch assert test_state.finalized_epoch == prev_state.previous_justified_epoch
assert test_state.finalized_root == old_previous_justified_root assert test_state.finalized_root == prev_state.previous_justified_root
blocks += new_blocks blocks += new_blocks
@ -170,19 +170,24 @@ def test_finality_rule_3(state):
blocks += new_blocks blocks += new_blocks
check_finality(test_state, prev_state, True, False, False) check_finality(test_state, prev_state, True, False, False)
# In epoch N, JE is set to N, prev JE is set to N-1
prev_state, new_blocks, test_state = next_epoch_with_attestations(test_state, True, False) prev_state, new_blocks, test_state = next_epoch_with_attestations(test_state, True, False)
blocks += new_blocks blocks += new_blocks
check_finality(test_state, prev_state, True, True, True) check_finality(test_state, prev_state, True, True, True)
# In epoch N+1, JE is N, prev JE is N-1, and not enough messages get in to do anything
prev_state, new_blocks, test_state = next_epoch_with_attestations(test_state, False, False) prev_state, new_blocks, test_state = next_epoch_with_attestations(test_state, False, False)
blocks += new_blocks blocks += new_blocks
check_finality(test_state, prev_state, False, True, False) check_finality(test_state, prev_state, False, True, False)
# In epoch N+2, JE is N, prev JE is N, and enough messages from the previous epoch get in to justify N+1.
# N+1 now becomes the JE. Not enough messages from epoch N+2 itself get in to justify N+2
prev_state, new_blocks, test_state = next_epoch_with_attestations(test_state, False, True) prev_state, new_blocks, test_state = next_epoch_with_attestations(test_state, False, True)
blocks += new_blocks blocks += new_blocks
# rule 2 # rule 2
check_finality(test_state, prev_state, True, False, True) check_finality(test_state, prev_state, True, False, True)
# In epoch N+3, LJE is N+1, prev LJE is N, and enough messages get in to justify epochs N+2 and N+3.
prev_state, new_blocks, test_state = next_epoch_with_attestations(test_state, True, True) prev_state, new_blocks, test_state = next_epoch_with_attestations(test_state, True, True)
blocks += new_blocks blocks += new_blocks
# rule 3 # rule 3