From 3bfdc917e13ec56c50ca8f0ff4b60485ab0b1a72 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Mon, 18 Oct 2021 13:38:08 -0600 Subject: [PATCH 1/3] ad TBH_ACTIVATION_EPOCH --- configs/mainnet.yaml | 4 +++- configs/minimal.yaml | 4 +++- specs/merge/beacon-chain.md | 3 ++- specs/merge/client-settings.md | 9 +++++---- specs/merge/fork-choice.md | 6 ++++-- specs/merge/validator.md | 5 +++++ 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/configs/mainnet.yaml b/configs/mainnet.yaml index 77d7a136f..74896c90f 100644 --- a/configs/mainnet.yaml +++ b/configs/mainnet.yaml @@ -7,8 +7,10 @@ PRESET_BASE: 'mainnet' # --------------------------------------------------------------- # TBD, 2**256-2**10 is a placeholder TERMINAL_TOTAL_DIFFICULTY: 115792089237316195423570985008687907853269984665640564039457584007913129638912 -# By default, don't use this param +# By default, don't use these params TERMINAL_BLOCK_HASH: 0x0000000000000000000000000000000000000000000000000000000000000000 +TBH_ACTIVATION_EPOCH: 18446744073709551615 + # Genesis diff --git a/configs/minimal.yaml b/configs/minimal.yaml index a8b30fd54..35e321e84 100644 --- a/configs/minimal.yaml +++ b/configs/minimal.yaml @@ -7,8 +7,10 @@ PRESET_BASE: 'minimal' # --------------------------------------------------------------- # TBD, 2**256-2**10 is a placeholder TERMINAL_TOTAL_DIFFICULTY: 115792089237316195423570985008687907853269984665640564039457584007913129638912 -# By default, don't use this param +# By default, don't use these params TERMINAL_BLOCK_HASH: 0x0000000000000000000000000000000000000000000000000000000000000000 +TBH_ACTIVATION_EPOCH: 18446744073709551615 + # Genesis diff --git a/specs/merge/beacon-chain.md b/specs/merge/beacon-chain.md index f5977db5e..12919b474 100644 --- a/specs/merge/beacon-chain.md +++ b/specs/merge/beacon-chain.md @@ -74,7 +74,8 @@ This patch adds transaction execution to the beacon chain as part of the Merge f | Name | Value | | - | - | | `TERMINAL_TOTAL_DIFFICULTY` | **TBD** | -| `TERMINAL_BLOCK_HASH` | `Hash32('0x0000000000000000000000000000000000000000000000000000000000000000')` | +| `TERMINAL_BLOCK_HASH` | `Hash32()` | +| `TBH_ACTIVATION_EPOCH` | `FAR_FUTURE_EPOCH` | ## Containers diff --git a/specs/merge/client-settings.md b/specs/merge/client-settings.md index 4a4b38d3e..63ddfe5ae 100644 --- a/specs/merge/client-settings.md +++ b/specs/merge/client-settings.md @@ -18,11 +18,12 @@ This document specifies configurable settings that clients must implement for th To coordinate manual overrides to [`TERMINAL_TOTAL_DIFFICULTY`](./beacon-chain.md#Transition-settings) parameter, clients must provide `--terminal-total-difficulty-override` as a configurable setting. The value provided by this setting must take precedence over pre-configured `TERMINAL_TOTAL_DIFFICULTY` parameter. Clients should accept the setting as a decimal value (i.e., *not* hexadecimal). -Except under exceptional scenarios, this setting is expected to not be used. Sufficient warning to the user about this exceptional configurable setting should be provided. +Except under exceptional scenarios, this setting is not expected to be used. Sufficient warning to the user about this exceptional configurable setting should be provided. ### Override terminal block hash -To allow for transition coordination around a specific PoW block, clients must also provide `--terminal-block-hash-override` as a configurable setting. -The value provided by this setting takes precedence over the pre-configured `TERMINAL_BLOCK_HASH` parameter. +To allow for transition coordination around a specific PoW block, clients must also provide `--terminal-block-hash-override` and `--terminal-block-hash-epoch-override` as configurable settings. +* The value provided by `--terminal-block-hash-override` takes precedence over the pre-configured `TERMINAL_BLOCK_HASH` parameter. +* The value provided by `--terminal-block-hash-epoch-override` takes precedence over the pre-configured `TBH_ACTIVATION_EPOCH` parameter. -Except under exceptional scenarios, this setting is expected to not be used. Sufficient warning to the user about this exceptional configurable setting should be provided. +Except under exceptional scenarios, these settings are not expected to be used. Sufficient warning to the user about this exceptional configurable setting should be provided. diff --git a/specs/merge/fork-choice.md b/specs/merge/fork-choice.md index ea4a5588a..f1f5e265c 100644 --- a/specs/merge/fork-choice.md +++ b/specs/merge/fork-choice.md @@ -74,8 +74,8 @@ Used by fork-choice handler, `on_block`. ```python def is_valid_terminal_pow_block(block: PowBlock, parent: PowBlock) -> bool: - if block.block_hash == TERMINAL_BLOCK_HASH: - return True + if TERMINAL_BLOCK_HASH != Hash32(): + return block.block_hash == TERMINAL_BLOCK_HASH is_total_difficulty_reached = block.total_difficulty >= TERMINAL_TOTAL_DIFFICULTY is_parent_total_difficulty_valid = parent.total_difficulty < TERMINAL_TOTAL_DIFFICULTY @@ -113,6 +113,8 @@ def on_block(store: Store, signed_block: SignedBeaconBlock) -> None: pow_block = get_pow_block(block.body.execution_payload.parent_hash) pow_parent = get_pow_block(pow_block.parent_hash) assert is_valid_terminal_pow_block(pow_block, pow_parent) + if TERMINAL_BLOCK_HASH != Hash32(): + assert compute_epoch_at_slot(block.slot) >= TBH_ACTIVATION_EPOCH # Add new block to the store store.blocks[hash_tree_root(block)] = block diff --git a/specs/merge/validator.md b/specs/merge/validator.md index 2de4ef6b1..f15f62f3d 100644 --- a/specs/merge/validator.md +++ b/specs/merge/validator.md @@ -127,6 +127,11 @@ def prepare_execution_payload(state: BeaconState, fee_recipient: ExecutionAddress, execution_engine: ExecutionEngine) -> Optional[PayloadId]: if not is_merge_complete(state): + is_tbh_override_set = TERMINAL_BLOCK_HASH != Hash32() + if is_tbh_override_set and get_current_epoch(state.slot) < TBH_ACTIVATION_EPOCH: + # TBH is set but activation epoch is not yet reached, no prepare payload call is needed + return None + terminal_pow_block = get_terminal_pow_block(pow_chain) if terminal_pow_block is None: # Pre-merge, no prepare payload call is needed From ba582b3e3a1848a856281869977dc2cdacf64504 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Tue, 19 Oct 2021 11:25:50 +0800 Subject: [PATCH 2/3] Fix setup.py parser and rename `TBH_ACTIVATION_EPOCH` -> `TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH` --- configs/mainnet.yaml | 2 +- configs/minimal.yaml | 2 +- setup.py | 2 +- specs/merge/beacon-chain.md | 2 +- specs/merge/client-settings.md | 2 +- specs/merge/fork-choice.md | 2 +- specs/merge/validator.md | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/configs/mainnet.yaml b/configs/mainnet.yaml index 74896c90f..6d23073b7 100644 --- a/configs/mainnet.yaml +++ b/configs/mainnet.yaml @@ -9,7 +9,7 @@ PRESET_BASE: 'mainnet' TERMINAL_TOTAL_DIFFICULTY: 115792089237316195423570985008687907853269984665640564039457584007913129638912 # By default, don't use these params TERMINAL_BLOCK_HASH: 0x0000000000000000000000000000000000000000000000000000000000000000 -TBH_ACTIVATION_EPOCH: 18446744073709551615 +TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH: 18446744073709551615 diff --git a/configs/minimal.yaml b/configs/minimal.yaml index 35e321e84..4f99fce31 100644 --- a/configs/minimal.yaml +++ b/configs/minimal.yaml @@ -9,7 +9,7 @@ PRESET_BASE: 'minimal' TERMINAL_TOTAL_DIFFICULTY: 115792089237316195423570985008687907853269984665640564039457584007913129638912 # By default, don't use these params TERMINAL_BLOCK_HASH: 0x0000000000000000000000000000000000000000000000000000000000000000 -TBH_ACTIVATION_EPOCH: 18446744073709551615 +TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH: 18446744073709551615 diff --git a/setup.py b/setup.py index 863761daa..fe990fbee 100644 --- a/setup.py +++ b/setup.py @@ -603,7 +603,7 @@ def objects_to_spec(preset_name: str, # Access global dict of config vars for runtime configurables for name in spec_object.config_vars.keys(): - functions_spec = functions_spec.replace(name, 'config.' + name) + functions_spec = re.sub(r"\b%s\b" % name, 'config.' + name, functions_spec) def format_config_var(name: str, vardef: VariableDefinition) -> str: if vardef.type_name is None: diff --git a/specs/merge/beacon-chain.md b/specs/merge/beacon-chain.md index 12919b474..2e1fd88fb 100644 --- a/specs/merge/beacon-chain.md +++ b/specs/merge/beacon-chain.md @@ -75,7 +75,7 @@ This patch adds transaction execution to the beacon chain as part of the Merge f | - | - | | `TERMINAL_TOTAL_DIFFICULTY` | **TBD** | | `TERMINAL_BLOCK_HASH` | `Hash32()` | -| `TBH_ACTIVATION_EPOCH` | `FAR_FUTURE_EPOCH` | +| `TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH` | `FAR_FUTURE_EPOCH` | ## Containers diff --git a/specs/merge/client-settings.md b/specs/merge/client-settings.md index 63ddfe5ae..64f912372 100644 --- a/specs/merge/client-settings.md +++ b/specs/merge/client-settings.md @@ -24,6 +24,6 @@ Except under exceptional scenarios, this setting is not expected to be used. Suf To allow for transition coordination around a specific PoW block, clients must also provide `--terminal-block-hash-override` and `--terminal-block-hash-epoch-override` as configurable settings. * The value provided by `--terminal-block-hash-override` takes precedence over the pre-configured `TERMINAL_BLOCK_HASH` parameter. -* The value provided by `--terminal-block-hash-epoch-override` takes precedence over the pre-configured `TBH_ACTIVATION_EPOCH` parameter. +* The value provided by `--terminal-block-hash-epoch-override` takes precedence over the pre-configured `TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH` parameter. Except under exceptional scenarios, these settings are not expected to be used. Sufficient warning to the user about this exceptional configurable setting should be provided. diff --git a/specs/merge/fork-choice.md b/specs/merge/fork-choice.md index f1f5e265c..d5fa08ee2 100644 --- a/specs/merge/fork-choice.md +++ b/specs/merge/fork-choice.md @@ -114,7 +114,7 @@ def on_block(store: Store, signed_block: SignedBeaconBlock) -> None: pow_parent = get_pow_block(pow_block.parent_hash) assert is_valid_terminal_pow_block(pow_block, pow_parent) if TERMINAL_BLOCK_HASH != Hash32(): - assert compute_epoch_at_slot(block.slot) >= TBH_ACTIVATION_EPOCH + assert compute_epoch_at_slot(block.slot) >= TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH # Add new block to the store store.blocks[hash_tree_root(block)] = block diff --git a/specs/merge/validator.md b/specs/merge/validator.md index f15f62f3d..e0066ddce 100644 --- a/specs/merge/validator.md +++ b/specs/merge/validator.md @@ -128,7 +128,7 @@ def prepare_execution_payload(state: BeaconState, execution_engine: ExecutionEngine) -> Optional[PayloadId]: if not is_merge_complete(state): is_tbh_override_set = TERMINAL_BLOCK_HASH != Hash32() - if is_tbh_override_set and get_current_epoch(state.slot) < TBH_ACTIVATION_EPOCH: + if is_tbh_override_set and get_current_epoch(state.slot) < TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH: # TBH is set but activation epoch is not yet reached, no prepare payload call is needed return None From 294b60a48befc76177ca72caadbe3a77f27ca8eb Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Tue, 19 Oct 2021 09:24:07 -0600 Subject: [PATCH 3/3] pr feedback --- specs/merge/fork-choice.md | 2 ++ specs/merge/validator.md | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/specs/merge/fork-choice.md b/specs/merge/fork-choice.md index d5fa08ee2..83bba3adf 100644 --- a/specs/merge/fork-choice.md +++ b/specs/merge/fork-choice.md @@ -110,9 +110,11 @@ def on_block(store: Store, signed_block: SignedBeaconBlock) -> None: # [New in Merge] if is_merge_block(pre_state, block.body): + # Check the parent PoW block of execution payload is a valid terminal PoW block. pow_block = get_pow_block(block.body.execution_payload.parent_hash) pow_parent = get_pow_block(pow_block.parent_hash) assert is_valid_terminal_pow_block(pow_block, pow_parent) + # If `TERMINAL_BLOCK_HASH` is used as an override, the activation epoch must be reached. if TERMINAL_BLOCK_HASH != Hash32(): assert compute_epoch_at_slot(block.slot) >= TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH diff --git a/specs/merge/validator.md b/specs/merge/validator.md index e0066ddce..88bf96643 100644 --- a/specs/merge/validator.md +++ b/specs/merge/validator.md @@ -127,9 +127,10 @@ def prepare_execution_payload(state: BeaconState, fee_recipient: ExecutionAddress, execution_engine: ExecutionEngine) -> Optional[PayloadId]: if not is_merge_complete(state): - is_tbh_override_set = TERMINAL_BLOCK_HASH != Hash32() - if is_tbh_override_set and get_current_epoch(state.slot) < TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH: - # TBH is set but activation epoch is not yet reached, no prepare payload call is needed + is_terminal_block_hash_set = TERMINAL_BLOCK_HASH != Hash32() + is_activation_epoch_reached = get_current_epoch(state.slot) < TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH + if is_terminal_block_hash_set and is_activation_epoch_reached: + # Terminal block hash is set but activation epoch is not yet reached, no prepare payload call is needed return None terminal_pow_block = get_terminal_pow_block(pow_chain)