Skip to content

Commit

Permalink
Fix block hash computation for fork transition tests
Browse files Browse the repository at this point in the history
When overriding `execution_requests`, have to sync EL payload block hash
as the requests are linked to it. Note that this was only caught now
because the new request tests were added after the latest fixes applied.
  • Loading branch information
etan-status committed Nov 26, 2024
1 parent 148ccca commit 3096a16
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tests/core/pyspec/eth2spec/test/helpers/fork_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@
prepare_state_and_deposit,
prepare_deposit_request,
)
from eth2spec.test.helpers.execution_payload import (
compute_el_block_hash_for_block,
)
from eth2spec.test.helpers.proposer_slashings import (
get_valid_proposer_slashing,
)
from eth2spec.test.helpers.forks import (
get_next_fork_transition,
is_post_bellatrix,
is_post_electra,
)
from eth2spec.test.helpers.state import (
Expand Down Expand Up @@ -57,13 +61,15 @@ class OperationType(Enum):
CONSOLIDATION_REQUEST = auto()


def _set_operations_by_dict(block, operation_dict):
def _set_operations_by_dict(spec, block, operation_dict):
for key, value in operation_dict.items():
# to handle e.g. `execution_requests.deposits` and `deposits`
obj = block.body
for attr in key.split('.')[:-1]:
obj = getattr(obj, attr)
setattr(obj, key.split('.')[-1], value)
if is_post_bellatrix(spec):
block.body.execution_payload.block_hash = compute_el_block_hash_for_block(spec, block)


def _state_transition_and_sign_block_at_slot(spec,
Expand All @@ -87,7 +93,7 @@ def _state_transition_and_sign_block_at_slot(spec,
block.body.sync_aggregate = sync_aggregate

if operation_dict:
_set_operations_by_dict(block, operation_dict)
_set_operations_by_dict(spec, block, operation_dict)

assert state.latest_block_header.slot < block.slot
assert state.slot == block.slot
Expand Down Expand Up @@ -403,7 +409,7 @@ def _check_state():
if is_right_before_fork:
# add a block with operation.
block = build_empty_block_for_next_slot(spec, state)
_set_operations_by_dict(block, operation_dict)
_set_operations_by_dict(spec, block, operation_dict)
signed_block = state_transition_and_sign_block(spec, state, block)
blocks.append(pre_tag(signed_block))

Expand Down

0 comments on commit 3096a16

Please sign in to comment.