Add `process_shard_block` verification
This commit is contained in:
parent
4a46fb2a8a
commit
661959c13e
|
@ -92,11 +92,8 @@ def process_shard_block(shard_state: ShardState,
|
||||||
prev_gasprice = shard_state.gasprice
|
prev_gasprice = shard_state.gasprice
|
||||||
shard_block_length = len(block.body)
|
shard_block_length = len(block.body)
|
||||||
shard_state.gasprice = compute_updated_gasprice(prev_gasprice, uint64(shard_block_length))
|
shard_state.gasprice = compute_updated_gasprice(prev_gasprice, uint64(shard_block_length))
|
||||||
if shard_block_length == 0:
|
if shard_block_length != 0:
|
||||||
latest_block_root = shard_state.latest_block_root
|
shard_state.latest_block_root = hash_tree_root(block)
|
||||||
else:
|
|
||||||
latest_block_root = hash_tree_root(block)
|
|
||||||
shard_state.latest_block_root = latest_block_root
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Fraud proofs
|
## Fraud proofs
|
||||||
|
|
|
@ -16,7 +16,8 @@ from eth2spec.test.helpers.state import transition_to_valid_shard_slot
|
||||||
def run_shard_blocks(spec, shard_state, signed_shard_block,
|
def run_shard_blocks(spec, shard_state, signed_shard_block,
|
||||||
beacon_parent_state,
|
beacon_parent_state,
|
||||||
validate=True, valid=True):
|
validate=True, valid=True):
|
||||||
yield 'pre', shard_state.copy()
|
pre_shard_state = shard_state.copy()
|
||||||
|
yield 'pre', pre_shard_state
|
||||||
yield 'signed_shard_block', signed_shard_block
|
yield 'signed_shard_block', signed_shard_block
|
||||||
yield 'validate', validate
|
yield 'validate', validate
|
||||||
yield 'beacon_parent_state', beacon_parent_state
|
yield 'beacon_parent_state', beacon_parent_state
|
||||||
|
@ -29,11 +30,24 @@ def run_shard_blocks(spec, shard_state, signed_shard_block,
|
||||||
shard_state, signed_shard_block, validate=validate, beacon_parent_state=beacon_parent_state)
|
shard_state, signed_shard_block, validate=validate, beacon_parent_state=beacon_parent_state)
|
||||||
)
|
)
|
||||||
yield 'post', None
|
yield 'post', None
|
||||||
else:
|
return
|
||||||
|
|
||||||
spec.shard_state_transition(shard_state, signed_shard_block,
|
spec.shard_state_transition(shard_state, signed_shard_block,
|
||||||
validate=validate, beacon_parent_state=beacon_parent_state)
|
validate=validate, beacon_parent_state=beacon_parent_state)
|
||||||
yield 'post', shard_state
|
yield 'post', shard_state
|
||||||
|
|
||||||
|
# Verify `process_shard_block`
|
||||||
|
block = signed_shard_block.message
|
||||||
|
|
||||||
|
assert shard_state.slot == block.slot
|
||||||
|
|
||||||
|
shard_block_length = len(block.body)
|
||||||
|
assert shard_state.gasprice == spec.compute_updated_gasprice(pre_shard_state.gasprice, shard_block_length)
|
||||||
|
if shard_block_length != 0:
|
||||||
|
shard_state.latest_block_root == block.hash_tree_root()
|
||||||
|
else:
|
||||||
|
shard_state.latest_block_root == pre_shard_state.latest_block_root
|
||||||
|
|
||||||
|
|
||||||
@with_all_phases_except([PHASE0])
|
@with_all_phases_except([PHASE0])
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
|
|
Loading…
Reference in New Issue