Skip to content

Commit

Permalink
delete build_empy_execution_payload_header
Browse files Browse the repository at this point in the history
  • Loading branch information
KatyaRyazantseva committed Dec 16, 2024
1 parent bffbb18 commit e9c9a0a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 51 deletions.
70 changes: 21 additions & 49 deletions tests/core/pyspec/eth2spec/test/helpers/execution_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,58 +267,30 @@ def compute_el_block_hash_for_block(spec, block):
spec, block.body.execution_payload, block.parent_root, requests_hash)


def build_empty_execution_payload_header(spec, state):
latest = state.latest_execution_payload_header
timestamp = spec.compute_timestamp_at_slot(state, state.slot)
execution_payload = build_empty_execution_payload(spec, state)

execution_payload_header = spec.ExecutionPayloadHeader(
parent_hash = latest.block_hash,
fee_recipient = spec.ExecutionAddress(),
state_root = latest.state_root,
receipts_root = spec.Bytes32(),
logs_bloom = spec.ByteVector[spec.BYTES_PER_LOGS_BLOOM](),
prev_randao = spec.Bytes32(),
block_number = 0,
gas_limit = 0,
gas_used = 0,
timestamp = timestamp,
extra_data = spec.ByteList[spec.MAX_EXTRA_DATA_BYTES](),
base_fee_per_gas = 0,
block_hash = compute_el_block_hash(spec, execution_payload, state),
transactions_root = spec.hash_tree_root(execution_payload.transactions),
)
if is_post_capella(spec):
execution_payload_header.withdrawals_root = spec.Root()

if is_post_deneb(spec):
execution_payload_header.blob_gas_used = 0
execution_payload_header.excess_blob_gas = 0

return execution_payload_header


def build_randomized_execution_payload_header(spec, state, rng=Random(10000)):
execution_payload_header = build_empty_execution_payload_header(spec, state)
execution_payload = build_randomized_execution_payload(spec, state)

execution_payload_header.fee_recipient = spec.ExecutionAddress(get_random_bytes_list(rng, 20)),
execution_payload_header.state_root = spec.Bytes32(get_random_bytes_list(rng, 32)),
execution_payload_header.receipts_root = spec.Bytes32(get_random_bytes_list(rng, 32)),
execution_payload_header.logs_bloom = spec.ByteVector[spec.BYTES_PER_LOGS_BLOOM](
get_random_bytes_list(rng, spec.BYTES_PER_LOGS_BLOOM)
),
execution_payload_header.prev_randao = spec.Bytes32(get_random_bytes_list(rng, 32)),
execution_payload_header.block_number = rng.randint(0, int(10e10)),
execution_payload_header.gas_limit = rng.randint(0, int(10e10)),
execution_payload_header.gas_used = rng.randint(0, int(10e10)),
extra_data_length = rng.randint(0, spec.MAX_EXTRA_DATA_BYTES)
execution_payload_header.extra_data = spec.ByteList[spec.MAX_EXTRA_DATA_BYTES](
get_random_bytes_list(rng, extra_data_length)
),
execution_payload_header.base_fee_per_gas = rng.randint(0, int(10e10)),
execution_payload_header.block_hash = compute_el_block_hash(spec, execution_payload, state),
execution_payload_header.transactions_root = spec.hash_tree_root(execution_payload.transactions),

execution_payload_header = spec.ExecutionPayloadHeader(
parent_hash=spec.Hash32(spec.hash(bytearray(rng.getrandbits(8) for _ in range(32)))),
fee_recipient=spec.ExecutionAddress(get_random_bytes_list(rng, 20)),
state_root=spec.Bytes32(get_random_bytes_list(rng, 32)),
receipts_root=spec.Bytes32(get_random_bytes_list(rng, 32)),
logs_bloom=spec.ByteVector[spec.BYTES_PER_LOGS_BLOOM](
get_random_bytes_list(rng, spec.BYTES_PER_LOGS_BLOOM)
),
prev_randao=spec.Bytes32(get_random_bytes_list(rng, 32)),
block_number=rng.randint(0, int(10e10)),
gas_limit=rng.randint(0, int(10e10)),
gas_used=rng.randint(0, int(10e10)),
timestamp=spec.compute_timestamp_at_slot(state, state.slot),
extra_data=spec.ByteList[spec.MAX_EXTRA_DATA_BYTES](
get_random_bytes_list(rng, extra_data_length)
),
base_fee_per_gas=rng.randint(0, int(10e10)),
block_hash=compute_el_block_hash(spec, execution_payload, state),
transactions_root=spec.hash_tree_root(execution_payload.transactions),
)

if is_post_capella(spec):
execution_payload_header.withdrawals_root = spec.hash_tree_root(execution_payload.withdrawals)
Expand Down
2 changes: 1 addition & 1 deletion tests/core/pyspec/eth2spec/test/helpers/withdrawals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def get_expected_withdrawals(spec, state):


def get_random_withdrawal(spec, state, rng):
if is_post_electra:
if is_post_electra(spec):
amount = rng.randint(0, spec.MAX_EFFECTIVE_BALANCE_ELECTRA)
else:
amount = rng.randint(0, spec.MAX_EFFECTIVE_BALANCE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
randomize_state as randomize_state_helper,
patch_state_to_non_leaking,
randomize_execution_payload_header,
)
)
from eth2spec.test.helpers.blob import (
get_sample_blob_tx,
)
Expand Down

0 comments on commit e9c9a0a

Please sign in to comment.