From 16d8a1ebebedfecdade599d03b912ef0d0ec65af Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 5 May 2025 16:16:52 -0500 Subject: [PATCH 1/2] Add checks to ensure presets/configs for yaml/spec match --- configs/mainnet.yaml | 1 + configs/minimal.yaml | 1 + setup.py | 31 ++++++++++++++++++++++++++ specs/_features/eip7732/fork-choice.md | 16 ++++++------- specs/_features/eip7805/fork.md | 2 +- 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/configs/mainnet.yaml b/configs/mainnet.yaml index 60e9f39b6c..3437d68441 100644 --- a/configs/mainnet.yaml +++ b/configs/mainnet.yaml @@ -181,6 +181,7 @@ PROPOSER_SELECTION_GAP: 2 # EIP7732 MAX_REQUEST_PAYLOADS: 128 +PROPOSER_SCORE_BOOST_EIP7732: 20 # EIP7805 ATTESTATION_DEADLINE: 4 diff --git a/configs/minimal.yaml b/configs/minimal.yaml index 750457a2dd..500122461d 100644 --- a/configs/minimal.yaml +++ b/configs/minimal.yaml @@ -178,6 +178,7 @@ PROPOSER_SELECTION_GAP: 1 # EIP7732 MAX_REQUEST_PAYLOADS: 128 +PROPOSER_SCORE_BOOST_EIP7732: 20 # EIP7805 ATTESTATION_DEADLINE: 2 diff --git a/setup.py b/setup.py index bd7ad6a18c..67d7fab596 100644 --- a/setup.py +++ b/setup.py @@ -197,6 +197,33 @@ def parse_markdown(content: str): return gfm.parse(content) +def check_yaml_matches_spec(var_name, yaml, value_def): + """ + This function performs a sanity check for presets & configs. To a certain degree, it ensures + that the values in the specifications match those in the yaml files. + """ + if var_name == "TERMINAL_BLOCK_HASH": + # This is just Hash32() in the specs, that's fine + return + + try: + assert yaml[var_name] == repr(eval(value_def.value)), \ + f"mismatch for {var_name}: {yaml[var_name]} vs {eval(value_def.value)}" + except NameError: + # We use a var in the definition of a new var, replace usages + # Reverse sort so that overridden values come first + updated_value = value_def.value + for var in sorted(yaml.keys(), reverse=True): + if var in updated_value: + updated_value = updated_value.replace(var, yaml[var]) + try: + assert yaml[var_name] == repr(eval(updated_value)), \ + f"mismatch for {var_name}: {yaml[var_name]} vs {eval(updated_value)}" + except NameError: + # Okay it's probably something more serious, let's ignore + pass + + def get_spec(file_name: Path, preset: Dict[str, str], config: Dict[str, str], preset_name=str) -> SpecObject: functions: Dict[str, str] = {} protocols: Dict[str, ProtocolDefinition] = {} @@ -300,8 +327,12 @@ def get_spec(file_name: Path, preset: Dict[str, str], config: Dict[str, str], pr value_def = _parse_value(name, value) if name in preset: + if preset_name == "mainnet": + check_yaml_matches_spec(name, preset, value_def) preset_vars[name] = VariableDefinition(value_def.type_name, preset[name], value_def.comment, None) elif name in config: + if preset_name == "mainnet": + check_yaml_matches_spec(name, config, value_def) config_vars[name] = VariableDefinition(value_def.type_name, config[name], value_def.comment, None) else: if name in ('ENDIANNESS', 'KZG_ENDIANNESS'): diff --git a/specs/_features/eip7732/fork-choice.md b/specs/_features/eip7732/fork-choice.md index b48dc3e5a6..4d60c84990 100644 --- a/specs/_features/eip7732/fork-choice.md +++ b/specs/_features/eip7732/fork-choice.md @@ -41,13 +41,13 @@ This is the modification of the fork choice accompanying the EIP-7732 upgrade. ## Constants -| Name | Value | -| -------------------------- | ----------------------------- | -| `PAYLOAD_TIMELY_THRESHOLD` | `PTC_SIZE // 2` (= 256) | -| `INTERVALS_PER_SLOT` | `4` # [modified in EIP-7732] | -| `PROPOSER_SCORE_BOOST` | `20` # [modified in EIP-7732] | -| `PAYLOAD_WITHHOLD_BOOST` | `40` | -| `PAYLOAD_REVEAL_BOOST` | `40` | +| Name | Value | +| ------------------------------ | ----------------------------- | +| `PAYLOAD_TIMELY_THRESHOLD` | `PTC_SIZE // 2` (= 256) | +| `INTERVALS_PER_SLOT` | `4` # [modified in EIP-7732] | +| `PROPOSER_SCORE_BOOST_EIP7732` | `20` # [modified in EIP-7732] | +| `PAYLOAD_WITHHOLD_BOOST` | `40` | +| `PAYLOAD_REVEAL_BOOST` | `40` | ## Containers @@ -266,7 +266,7 @@ def compute_proposer_boost(store: Store, state: BeaconState, node: ChildNode) -> if (node.slot < proposer_boost_slot) and (ancestor.is_payload_present != node.is_payload_present): return Gwei(0) committee_weight = get_total_active_balance(state) // SLOTS_PER_EPOCH - return (committee_weight * PROPOSER_SCORE_BOOST) // 100 + return (committee_weight * PROPOSER_SCORE_BOOST_EIP7732) // 100 ``` ### New `compute_withhold_boost` diff --git a/specs/_features/eip7805/fork.md b/specs/_features/eip7805/fork.md index 9b8db68bf6..894a313f06 100644 --- a/specs/_features/eip7805/fork.md +++ b/specs/_features/eip7805/fork.md @@ -24,7 +24,7 @@ Warning: this configuration is not definitive. | Name | Value | | ---------------------- | ------------------------------------- | -| `EIP7805_FORK_VERSION` | `Version('0x10000000')` | +| `EIP7805_FORK_VERSION` | `Version('0x0a000000')` | | `EIP7805_FORK_EPOCH` | `Epoch(18446744073709551615)` **TBD** | ## Helper functions From 7a1802eae2ac81a881c899659c70c97a3f0cc107 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 5 May 2025 16:27:47 -0500 Subject: [PATCH 2/2] Simplify --- setup.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/setup.py b/setup.py index 67d7fab596..66cf6bbdb3 100644 --- a/setup.py +++ b/setup.py @@ -206,22 +206,18 @@ def check_yaml_matches_spec(var_name, yaml, value_def): # This is just Hash32() in the specs, that's fine return + # We use a var in the definition of a new var, replace usages + # Reverse sort so that overridden values come first + updated_value = value_def.value + for var in sorted(yaml.keys(), reverse=True): + if var in updated_value: + updated_value = updated_value.replace(var, yaml[var]) try: - assert yaml[var_name] == repr(eval(value_def.value)), \ - f"mismatch for {var_name}: {yaml[var_name]} vs {eval(value_def.value)}" + assert yaml[var_name] == repr(eval(updated_value)), \ + f"mismatch for {var_name}: {yaml[var_name]} vs {eval(updated_value)}" except NameError: - # We use a var in the definition of a new var, replace usages - # Reverse sort so that overridden values come first - updated_value = value_def.value - for var in sorted(yaml.keys(), reverse=True): - if var in updated_value: - updated_value = updated_value.replace(var, yaml[var]) - try: - assert yaml[var_name] == repr(eval(updated_value)), \ - f"mismatch for {var_name}: {yaml[var_name]} vs {eval(updated_value)}" - except NameError: - # Okay it's probably something more serious, let's ignore - pass + # Okay it's probably something more serious, let's ignore + pass def get_spec(file_name: Path, preset: Dict[str, str], config: Dict[str, str], preset_name=str) -> SpecObject: