Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,65 @@ def fund_via_withdrawals(
new_payload,
payload_attributes.parent_beacon_block_root,
)

def bump_block_gas_limit(
self,
block_count: int,
) -> List[EnginePayloadMetadata]:
"""
Build empty block to increase the block gas limit to target.
"""
if block_count <= 0:
return []
assert self.testing_rpc is not None, (
"bump_block_gas_limit requires testing_rpc"
)
captured: List[EnginePayloadMetadata] = []
with self.block_building_lock:
for _ in range(block_count):
head_block = self.get_block_by_number("latest")
assert head_block is not None
next_timestamp = int(HexNumber(head_block["timestamp"]) + 1)
payload_attributes = self._payload_attributes(
next_timestamp=next_timestamp,
)
new_payload = self.testing_rpc.build_block(
parent_block_hash=Hash(head_block["hash"]),
payload_attributes=payload_attributes,
transactions=[],
extra_data=Bytes(b""),
)
captured.append(
self._finalize_payload(
new_payload,
payload_attributes.parent_beacon_block_root,
)
)
return captured

def set_canonical_head(self, head_block_hash: Hash) -> None:
"""
Reorg the canonical head to head_block_hash via
``engine_forkchoiceUpdated``.
"""
head_block = self.get_block_by_hash(head_block_hash)
assert head_block is not None, (
f"cannot reset head to unknown block {head_block_hash}"
)
Comment on lines +391 to +394
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is unnecessary, since the client itself will make the same complaint if it cannot find the block.
It's just one less RPC call to make IMO.

head_fork = self.fork.fork_at(
block_number=HexNumber(head_block["number"]),
timestamp=HexNumber(head_block["timestamp"]),
)
Comment on lines +395 to +398
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now the reason behind the previous call, but perhaps the solution is that we should never expect TransitionFork here and assume that ChainBuilderEthRPC is always going to be initialized with Fork, otherwise error out.

fcu_version = head_fork.engine_forkchoice_updated_version()
assert fcu_version is not None, (
"Fork does not support engine forkchoice_updated"
)
Comment on lines +399 to +402
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do this once during initialization of ChainBuilderEthRPC, save fcu_version as a field of the chain builder instance, and then just use it as self.fcu_version.
This is also under the assumption that fork is always Fork and never TransitionFork.

response = self.engine_rpc.forkchoice_updated(
ForkchoiceState(head_block_hash=head_block_hash),
None,
version=fcu_version,
)
assert response.payload_status.status == PayloadStatusEnum.VALID, (
f"forkchoice_updated reset to {head_block_hash} was not VALID "
f"(got {response.payload_status.status})"
)
Loading
Loading