From 0ad344bf7291d7f3528e1e78318788a48ae087da Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Thu, 4 Nov 2021 15:58:48 +0600 Subject: [PATCH 1/2] Make notify_forkchoice_updated return payload id value --- setup.py | 2 +- specs/merge/fork-choice.md | 10 ++++++++-- specs/merge/validator.md | 27 +-------------------------- 3 files changed, 10 insertions(+), 29 deletions(-) diff --git a/setup.py b/setup.py index 4bb26bccd1..355f6e2c19 100644 --- a/setup.py +++ b/setup.py @@ -530,7 +530,7 @@ def execute_payload(self: ExecutionEngine, execution_payload: ExecutionPayload) def notify_forkchoice_updated(self: ExecutionEngine, head_block_hash: Hash32, finalized_block_hash: Hash32, - payload_attributes: Optional[PayloadAttributes]) -> None: + payload_attributes: Optional[PayloadAttributes]) -> Optional[PayloadId]: pass def get_payload(self: ExecutionEngine, payload_id: PayloadId) -> ExecutionPayload: diff --git a/specs/merge/fork-choice.md b/specs/merge/fork-choice.md index bf1634de4f..d4d437bf12 100644 --- a/specs/merge/fork-choice.md +++ b/specs/merge/fork-choice.md @@ -29,6 +29,12 @@ This is the modification of the fork choice according to the executable beacon c *Note*: It introduces the process of transition from the last PoW block to the first PoS block. +## Custom types + +| Name | SSZ equivalent | Description | +| - | - | - | +| `PayloadId` | `Bytes8` | Identifier of a payload building process | + ## Protocols ### `ExecutionEngine` @@ -46,13 +52,13 @@ This function performs two actions *atomically*: and corresponding state, up to and including `finalized_block_hash`. Additionally, if `payload_attributes` is provided, this function sets in motion a payload build process on top of -`head_block_hash` with the result to be gathered by a followup call to `get_payload`. +`head_block_hash` and returns an identifier of initiated process. ```python def notify_forkchoice_updated(self: ExecutionEngine, head_block_hash: Hash32, finalized_block_hash: Hash32, - payload_attributes: Optional[PayloadAttributes]) -> None: + payload_attributes: Optional[PayloadAttributes]) -> Optional[PayloadId]: ... ``` diff --git a/specs/merge/validator.md b/specs/merge/validator.md index f47ede4f79..61a60bcd89 100644 --- a/specs/merge/validator.md +++ b/specs/merge/validator.md @@ -38,12 +38,6 @@ All behaviors and definitions defined in this document, and documents it extends All terminology, constants, functions, and protocol mechanics defined in the updated Beacon Chain doc of [The Merge](./beacon-chain.md) are requisite for this document and used throughout. Please see related Beacon Chain doc before continuing and use them as a reference throughout. -## Custom types - -| Name | SSZ equivalent | Description | -| - | - | - | -| `PayloadId` | `Bytes8` | Identifier of a payload building process | - ## Helpers ### `get_pow_block_at_terminal_total_difficulty` @@ -75,24 +69,6 @@ def get_terminal_pow_block(pow_chain: Dict[Hash32, PowBlock]) -> Optional[PowBlo return get_pow_block_at_terminal_total_difficulty(pow_chain) ``` -### `get_payload_id` - -Given the `head_block_hash` and the `payload_attributes` that were used to -initiate the build process via `notify_forkchoice_updated`, `get_payload_id()` -returns the `payload_id` used to retrieve the payload via `get_payload`. - -```python -def get_payload_id(parent_hash: Hash32, payload_attributes: PayloadAttributes) -> PayloadId: - return PayloadId( - hash( - parent_hash - + uint_to_bytes(payload_attributes.timestamp) - + payload_attributes.random - + payload_attributes.fee_recipient - )[0:8] - ) -``` - *Note*: This function does *not* use simple serialize `hash_tree_root` as to avoid requiring simple serialize hashing capabilities in the Execution Layer. @@ -168,8 +144,7 @@ def prepare_execution_payload(state: BeaconState, random=get_randao_mix(state, get_current_epoch(state)), fee_recipient=fee_recipient, ) - execution_engine.notify_forkchoice_updated(parent_hash, finalized_block_hash, payload_attributes) - return get_payload_id(parent_hash, payload_attributes) + return execution_engine.notify_forkchoice_updated(parent_hash, finalized_block_hash, payload_attributes) ``` 2. Set `block.body.execution_payload = get_execution_payload(payload_id, execution_engine)`, where: From a3380db5976866f701abb83b4da89a359589de45 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Thu, 4 Nov 2021 16:30:23 +0600 Subject: [PATCH 2/2] Fix toc --- specs/merge/fork-choice.md | 1 + specs/merge/validator.md | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/specs/merge/fork-choice.md b/specs/merge/fork-choice.md index d4d437bf12..9d4f84d7fa 100644 --- a/specs/merge/fork-choice.md +++ b/specs/merge/fork-choice.md @@ -8,6 +8,7 @@ - [Introduction](#introduction) +- [Custom types](#custom-types) - [Protocols](#protocols) - [`ExecutionEngine`](#executionengine) - [`notify_forkchoice_updated`](#notify_forkchoice_updated) diff --git a/specs/merge/validator.md b/specs/merge/validator.md index 61a60bcd89..1ff55ad1bb 100644 --- a/specs/merge/validator.md +++ b/specs/merge/validator.md @@ -10,11 +10,9 @@ - [Introduction](#introduction) - [Prerequisites](#prerequisites) -- [Custom types](#custom-types) - [Helpers](#helpers) - [`get_pow_block_at_terminal_total_difficulty`](#get_pow_block_at_terminal_total_difficulty) - [`get_terminal_pow_block`](#get_terminal_pow_block) - - [`get_payload_id`](#get_payload_id) - [Protocols](#protocols) - [`ExecutionEngine`](#executionengine) - [`get_payload`](#get_payload)