working through test issues

This commit is contained in:
Danny Ryan 2021-11-12 12:36:02 -07:00
parent fb34e162ef
commit cd3d2ce692
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
3 changed files with 10 additions and 13 deletions

View File

@ -372,18 +372,6 @@ def on_block(store: Store, signed_block: SignedBeaconBlock) -> None:
# Update finalized checkpoint # Update finalized checkpoint
if state.finalized_checkpoint.epoch > store.finalized_checkpoint.epoch: if state.finalized_checkpoint.epoch > store.finalized_checkpoint.epoch:
store.finalized_checkpoint = state.finalized_checkpoint store.finalized_checkpoint = state.finalized_checkpoint
# Potentially update justified if different from store
if store.justified_checkpoint != state.current_justified_checkpoint:
# Update justified if new justified is later than store justified
if state.current_justified_checkpoint.epoch > store.justified_checkpoint.epoch:
store.justified_checkpoint = state.current_justified_checkpoint
return
# Update justified if store justified is not in chain with finalized checkpoint
finalized_slot = compute_start_slot_at_epoch(store.finalized_checkpoint.epoch)
ancestor_at_finalized_slot = get_ancestor(store, store.justified_checkpoint.root, finalized_slot)
if ancestor_at_finalized_slot != store.finalized_checkpoint.root:
store.justified_checkpoint = state.current_justified_checkpoint store.justified_checkpoint = state.current_justified_checkpoint
``` ```

View File

@ -166,6 +166,7 @@ def add_block(spec,
raise raise
block_root = signed_block.message.hash_tree_root() block_root = signed_block.message.hash_tree_root()
print(encode_hex(block_root))
assert store.blocks[block_root] == signed_block.message assert store.blocks[block_root] == signed_block.message
assert store.block_states[block_root].hash_tree_root() == signed_block.message.state_root assert store.block_states[block_root].hash_tree_root() == signed_block.message.state_root
test_steps.append({ test_steps.append({
@ -186,6 +187,7 @@ def add_block(spec,
}, },
} }
}) })
print(test_steps[-1])
return store.block_states[signed_block.message.hash_tree_root()] return store.block_states[signed_block.message.hash_tree_root()]

View File

@ -658,6 +658,7 @@ def test_new_finalized_slot_is_justified_checkpoint_ancestor(spec, state):
""" """
test_steps = [] test_steps = []
# Initialization # Initialization
print("INIT")
store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state)
yield 'anchor_state', state yield 'anchor_state', state
yield 'anchor_block', anchor_block yield 'anchor_block', anchor_block
@ -679,12 +680,14 @@ def test_new_finalized_slot_is_justified_checkpoint_ancestor(spec, state):
state, store, _ = yield from apply_next_epoch_with_attestations( state, store, _ = yield from apply_next_epoch_with_attestations(
spec, state, store, False, True, test_steps=test_steps) spec, state, store, False, True, test_steps=test_steps)
print("INIT FIN")
assert state.finalized_checkpoint.epoch == store.finalized_checkpoint.epoch == 2 assert state.finalized_checkpoint.epoch == store.finalized_checkpoint.epoch == 2
assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 4 assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 4
assert store.justified_checkpoint == state.current_justified_checkpoint assert store.justified_checkpoint == state.current_justified_checkpoint
# Create another chain # Create another chain
# Forking from epoch 3 # Forking from epoch 3
print("FORK")
all_blocks = [] all_blocks = []
slot = spec.compute_start_slot_at_epoch(3) slot = spec.compute_start_slot_at_epoch(3)
block_root = spec.get_block_root_at_slot(state, slot) block_root = spec.get_block_root_at_slot(state, slot)
@ -696,6 +699,7 @@ def test_new_finalized_slot_is_justified_checkpoint_ancestor(spec, state):
assert another_state.finalized_checkpoint.epoch == 3 assert another_state.finalized_checkpoint.epoch == 3
assert another_state.current_justified_checkpoint.epoch == 4 assert another_state.current_justified_checkpoint.epoch == 4
print("APPLY FORK TO FORK CHOICE")
pre_store_justified_checkpoint_root = store.justified_checkpoint.root pre_store_justified_checkpoint_root = store.justified_checkpoint.root
for block in all_blocks: for block in all_blocks:
# FIXME: Once `on_block` and `on_attestation` logic is fixed, # FIXME: Once `on_block` and `on_attestation` logic is fixed,
@ -707,6 +711,9 @@ def test_new_finalized_slot_is_justified_checkpoint_ancestor(spec, state):
assert ancestor_at_finalized_slot == store.finalized_checkpoint.root assert ancestor_at_finalized_slot == store.finalized_checkpoint.root
assert store.finalized_checkpoint == another_state.finalized_checkpoint assert store.finalized_checkpoint == another_state.finalized_checkpoint
# Thus should fail with the fix. Once show fail, swap to ==
assert store.justified_checkpoint != another_state.current_justified_checkpoint assert store.justified_checkpoint != another_state.current_justified_checkpoint
print(store.finalized_checkpoint)
print(store.justified_checkpoint)
yield 'steps', test_steps yield 'steps', test_steps