mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-12 11:44:41 +00:00
lint
This commit is contained in:
parent
751738f411
commit
d9b97578c0
@ -149,14 +149,17 @@ def on_tick(store: Store, time: int) -> None:
|
|||||||
```python
|
```python
|
||||||
def on_block(store: Store, block: BeaconBlock) -> None:
|
def on_block(store: Store, block: BeaconBlock) -> None:
|
||||||
# Make a copy of the state to avoid mutability issues
|
# Make a copy of the state to avoid mutability issues
|
||||||
parent_block = store.blocks[block.parent_root]
|
assert block.parent_root in store.block_states
|
||||||
pre_state = store.block_states[block.parent_root].copy()
|
pre_state = store.block_states[block.parent_root].copy()
|
||||||
# Blocks cannot be in the future. If they are, their consideration must be delayed until the are in the past.
|
# Blocks cannot be in the future. If they are, their consideration must be delayed until the are in the past.
|
||||||
assert store.time >= pre_state.genesis_time + block.slot * SECONDS_PER_SLOT
|
assert store.time >= pre_state.genesis_time + block.slot * SECONDS_PER_SLOT
|
||||||
# Add new block to the store
|
# Add new block to the store
|
||||||
store.blocks[signing_root(block)] = block
|
store.blocks[signing_root(block)] = block
|
||||||
# Check block is a descendant of the finalized block
|
# Check block is a descendant of the finalized block
|
||||||
assert get_ancestor(store, signing_root(block), store.blocks[store.finalized_checkpoint.root].slot) == store.finalized_checkpoint.root
|
assert (
|
||||||
|
get_ancestor(store, signing_root(block), store.blocks[store.finalized_checkpoint.root].slot) ==
|
||||||
|
store.finalized_checkpoint.root
|
||||||
|
)
|
||||||
# Check that block is later than the finalized epoch slot
|
# Check that block is later than the finalized epoch slot
|
||||||
assert block.slot > get_epoch_start_slot(store.finalized_checkpoint.epoch)
|
assert block.slot > get_epoch_start_slot(store.finalized_checkpoint.epoch)
|
||||||
# Check the block is valid and compute the post-state
|
# Check the block is valid and compute the post-state
|
||||||
@ -184,13 +187,14 @@ def on_attestation(store: Store, attestation: Attestation) -> None:
|
|||||||
# Cannot calculate the current shuffling if have not seen the target
|
# Cannot calculate the current shuffling if have not seen the target
|
||||||
assert target.root in store.blocks
|
assert target.root in store.blocks
|
||||||
|
|
||||||
# Attestations cannot be from future epochs. If they are, their consideration must be delayed until the are in the past.
|
# Attestations cannot be from future epochs. If they are, delay consideration until the epoch arrivesr
|
||||||
base_state = store.block_states[target.root].copy()
|
base_state = store.block_states[target.root].copy()
|
||||||
assert store.time >= base_state.genesis_time + get_epoch_start_slot(target.epoch) * SECONDS_PER_SLOT
|
assert store.time >= base_state.genesis_time + get_epoch_start_slot(target.epoch) * SECONDS_PER_SLOT
|
||||||
|
|
||||||
# Store target checkpoint state if not yet seen
|
# Store target checkpoint state if not yet seen
|
||||||
if target not in store.checkpoint_states:
|
if target not in store.checkpoint_states:
|
||||||
store.checkpoint_states[target] = process_slots(base_state, get_epoch_start_slot(target.epoch))
|
process_slots(base_state, get_epoch_start_slot(target.epoch))
|
||||||
|
store.checkpoint_states[target] = base_state
|
||||||
target_state = store.checkpoint_states[target]
|
target_state = store.checkpoint_states[target]
|
||||||
|
|
||||||
# Attestations can only affect the fork choice of subsequent slots.
|
# Attestations can only affect the fork choice of subsequent slots.
|
||||||
|
@ -11,7 +11,7 @@ def run_on_attestation(spec, state, store, attestation, valid=True):
|
|||||||
if not valid:
|
if not valid:
|
||||||
try:
|
try:
|
||||||
spec.on_attestation(store, attestation)
|
spec.on_attestation(store, attestation)
|
||||||
except:
|
except AssertionError:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
assert False
|
assert False
|
||||||
@ -131,4 +131,4 @@ def test_on_attestation_invalid_attestation(spec, state):
|
|||||||
attestation = get_valid_attestation(spec, state, slot=block.slot)
|
attestation = get_valid_attestation(spec, state, slot=block.slot)
|
||||||
# make attestation invalid
|
# make attestation invalid
|
||||||
attestation.custody_bitfield = b'\xf0' + attestation.custody_bitfield[1:]
|
attestation.custody_bitfield = b'\xf0' + attestation.custody_bitfield[1:]
|
||||||
run_on_attestation(spec, state, store, attestation, False)
|
run_on_attestation(spec, state, store, attestation, False)
|
||||||
|
@ -9,7 +9,7 @@ def run_on_block(spec, state, store, block, valid=True):
|
|||||||
if not valid:
|
if not valid:
|
||||||
try:
|
try:
|
||||||
spec.on_block(store, block)
|
spec.on_block(store, block)
|
||||||
except:
|
except AssertionError:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
assert False
|
assert False
|
||||||
@ -88,8 +88,11 @@ def test_on_block_before_finalized(spec, state):
|
|||||||
time = 100
|
time = 100
|
||||||
spec.on_tick(store, time)
|
spec.on_tick(store, time)
|
||||||
|
|
||||||
store.finalized_checkpoint = spec.Checkpoint(epoch=store.finalized_checkpoint.epoch + 2, root=store.finalized_checkpoint.root)
|
store.finalized_checkpoint = spec.Checkpoint(
|
||||||
|
epoch=store.finalized_checkpoint.epoch + 2,
|
||||||
|
root=store.finalized_checkpoint.root
|
||||||
|
)
|
||||||
|
|
||||||
# Fail receiving block of `GENESIS_SLOT + 1` slot
|
# Fail receiving block of `GENESIS_SLOT + 1` slot
|
||||||
block = build_empty_block_for_next_slot(spec, state)
|
block = build_empty_block_for_next_slot(spec, state)
|
||||||
run_on_block(spec, state, store, block, False)
|
run_on_block(spec, state, store, block, False)
|
||||||
|
@ -1 +0,0 @@
|
|||||||
|
|
Loading…
x
Reference in New Issue
Block a user