Skip to content

Commit

Permalink
update diff table
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Nov 9, 2023
1 parent 5eeb564 commit 284fa13
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ethereum_config_check.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Ethereum key checkk
name: Ethereum key check

on:
push:
Expand Down
74 changes: 26 additions & 48 deletions consensus.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,30 @@ Refer to [gnosischain/configs/mainnet/config.yaml](https://github.com/gnosischai

Note that modified preset values will result in different SSZ data structures, such that a client compiled with the Ethereum mainnet preset can't deserialize a state from the Gnosis Beacon Chain.

### phase0
```
ETHEREUM_SPEC_COMMIT: v1.4.0-beta.4
```

### Preset diff

| Name | Ethereum spec | Gnosis spec |
| -------------------------------------- | ------- | ------ |
| `BASE_REWARD_FACTOR` | `64` | `25` |
| `SLOTS_PER_EPOCH` | `32` | `16` |
| `EPOCHS_PER_SYNC_COMMITTEE_PERIOD` | `256 ` | `512` |
| `MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP` | `16384` | `8192` |
| `MAX_WITHDRAWALS_PER_PAYLOAD` | `16` | `8` |

### Config diff

| Name | Ethereum spec | Gnosis spec |
| ------------------------------------ | ------------- | ------------ |
| `PRESET_BASE` | `mainnet` | `gnosis` |
| `CHURN_LIMIT_QUOTIENT` | `65536` | `4096` |
| `SECONDS_PER_SLOT` | `12` | `5` |
| `SECONDS_PER_ETH1_BLOCK` | `14` | `6` |
| `ETH1_FOLLOW_DISTANCE` | `2048` | `1024` |
| `TERMINAL_TOTAL_DIFFICULTY` | `58750000000000000000000` | `8626000000000000000000058750000000000000000000` |
| `MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT` | `8` | `2` |
| `MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS` | `4096` | `16384` |

**Preset**

| Name | Value |
| -------------------- | ----- |
| `BASE_REWARD_FACTOR` | `25` |
| `SLOTS_PER_EPOCH` | `16` |

**Config**

| Name | Value |
| ------------------------------------ | -------------------------------------------- |
| `SECONDS_PER_SLOT` | `5` |
| `SECONDS_PER_ETH1_BLOCK` | `6` |
| `ETH1_FOLLOW_DISTANCE` | `1024` |
| `CHURN_LIMIT_QUOTIENT` | `4096` |
| `DEPOSIT_CHAIN_ID` | `100` |
| `DEPOSIT_NETWORK_ID` | `100` |
| `DEPOSIT_CONTRACT_ADDRESS` | `0x0b98057ea310f4d31f2a452b414647007d1645d9` |
| `MIN_GENESIS_TIME` | `1638968400` |
| `MIN_GENESIS_ACTIVE_VALIDATOR_COUNT` | `4096` |
| `GENESIS_FORK_VERSION` | `0x00000064` |
| `GENESIS_DELAY` | `6000` |

### altair

**Preset**

| Name | Value |
| ---------------------------------- | ----- |
| `EPOCHS_PER_SYNC_COMMITTEE_PERIOD` | `512` |

**Config**

| Name | Value |
| --------------------- | ------------ |
| `ALTAIR_FORK_VERSION` | `0x01000064` |
| `ALTAIR_FORK_EPOCH` | `512` |

### bellatrix

**Config**

| Name | Value |
| --------------------------- | ------------------------------------------------ |
| `BELLATRIX_FORK_VERSION` | `0x02000064` |
| `BELLATRIX_FORK_EPOCH` | `385536` |
| `TERMINAL_TOTAL_DIFFICULTY` | `8626000000000000000000058750000000000000000000` |
119 changes: 102 additions & 17 deletions scripts/assert_declare_ethereum_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import sys
import argparse
import difflib
import re
import json

# Install dependecies:
#
Expand All @@ -12,16 +14,13 @@
#
# python3 scripts/assert_declare_ethereum_vars.py

# Default commit for the pinned version
DEFAULT_COMMIT = 'v1.4.0-beta.4'

# URL of the YAML file in the GitHub repo
# 'https://raw.githubusercontent.com/ethereum/consensus-specs/dev/configs/mainnet.yaml'
remote_base_url = 'https://raw.githubusercontent.com/ethereum/consensus-specs'
REMOTE_BASE_URL = 'https://raw.githubusercontent.com/ethereum/consensus-specs'

# Path to the local YAML file
files = [
# local file # remote url path
FILES = [
# local file # remote url path
('consensus/config/gnosis.yaml', 'configs/mainnet.yaml'),
('consensus/preset/gnosis/phase0.yaml', 'presets/mainnet/phase0.yaml'),
('consensus/preset/gnosis/altair.yaml', 'presets/mainnet/altair.yaml'),
Expand All @@ -30,14 +29,37 @@
('consensus/preset/gnosis/deneb.yaml', 'presets/mainnet/deneb.yaml'),
]

def load_yaml_from_github(url):
ETHEREUM_SPEC_COMMIT_PREFIX = "ETHEREUM_SPEC_COMMIT: "
CONSENSUS_SPEC_FILEPATH = "consensus.md"

# Keys to ignore for the config / preset diff tables
IGNORE_CONFIG_KEYS = [
'_FORK_EPOCH',
'_FORK_VERSION',
'MIN_GENESIS_TIME',
'MIN_GENESIS_ACTIVE_VALIDATOR_COUNT',
'GENESIS_DELAY',
'CONFIG_NAME',
'DEPOSIT_CONTRACT_ADDRESS',
'DEPOSIT_CHAIN_ID',
'DEPOSIT_NETWORK_ID',
]
IGNORE_CONFIG_KEYS_REGEX = [re.compile(pattern) for pattern in IGNORE_CONFIG_KEYS]

def read_default_commit_from_md(file_path):
with open(file_path, 'r') as file:
for line in file:
if line.startswith(ETHEREUM_SPEC_COMMIT_PREFIX):
return line[len(ETHEREUM_SPEC_COMMIT_PREFIX):].strip()

def load_str_from_github(url):
with urllib.request.urlopen(url) as response:
if response.status == 200:
return response.read().decode('utf-8')
else:
raise Exception("Failed to download file from GitHub")

def load_yaml_from_local(path):
def load_str_from_local(path):
with open(path, 'r') as file:
return file.read()

Expand All @@ -53,28 +75,78 @@ def compare_yaml_keys(github_yaml, local_yaml):

return new_keys, missing_keys

def assert_deep_equal_dict(a, b, id):
try:
assert a == b
except AssertionError:
a_str = json.dumps(a, indent=4, sort_keys=True)
b_str = json.dumps(b, indent=4, sort_keys=True)
diff = difflib.ndiff(a_str.splitlines(), b_str.splitlines())
diff_str = '\n'.join(diff)
raise AssertionError(f"Difference found in {id} :\n{diff_str}")

# Function to compare two dictionaries and create a diff
def create_diff(local_yaml, github_yaml):
diff = {}
all_keys = set(local_yaml.keys()).union(set(github_yaml.keys()))
for key in all_keys:
if any(regex.search(key) for regex in IGNORE_CONFIG_KEYS_REGEX):
continue
local_value = local_yaml.get(key, "Not Present")
github_value = github_yaml.get(key, "Not Present")
if local_value != github_value:
diff[key] = {'ethereum': str(github_value), 'gnosis': str(local_value)}
return diff

def parse_md_table_to_json(md_content):
"""Parse a markdown table and convert it to a JSON-like dictionary."""
json_data = {}
lines = md_content.splitlines()
for line in lines[2:]: # Skip header lines
if '|' in line:
parts = [part.strip() for part in line.strip().split('|')]
if len(parts) < 4:
raise Exception(f"expected 3 but found {len(parts)} columns in table row {line}")
key = parts[1].strip('`')
ethereum = parts[2].strip('`')
gnosis = parts[3].strip('`')
json_data[key] = {'ethereum': ethereum, 'gnosis': gnosis}
return json_data

def extract_config_diff_section(md_content):
return re.search(r'### Config diff\n(.*?)(?=\n###|$)', md_content, re.DOTALL).group(1).strip()

def extract_preset_diff_section(md_content):
return re.search(r'### Preset diff\n(.*?)(?=\n###|$)', md_content, re.DOTALL).group(1).strip()


parser = argparse.ArgumentParser(description='Compare YAML keys.')
parser.add_argument('--dev', action='store_true', help='check against dev branch')
args = parser.parse_args()

for local_file_path, remote_url_path in files:
commit = 'dev' if args.dev else DEFAULT_COMMIT
default_commit = read_default_commit_from_md(CONSENSUS_SPEC_FILEPATH)
print("default_commit", default_commit)

url = f"{remote_base_url}/{commit}/{remote_url_path}"
github_yaml_str = load_yaml_from_github(url)
local_yaml_str = load_yaml_from_local(local_file_path)
config_diff = {}
preset_diff = {}

for local_file_path, remote_url_path in FILES:
commit = 'dev' if args.dev else default_commit

url = f"{REMOTE_BASE_URL}/{commit}/{remote_url_path}"
print(url)
github_yaml_str = load_str_from_github(url)
local_yaml_str = load_str_from_local(local_file_path)
github_yaml = yaml.safe_load(github_yaml_str)
local_yaml = yaml.safe_load(local_yaml_str)

new_keys, missing_keys = compare_yaml_keys(github_yaml, local_yaml)

print(local_file_path, commit, remote_url_path)
if new_keys:
print("New keys found in GitHub YAML not used in local YAML:", new_keys)
sys.exit(1)
raise Exception(f"New keys found in GitHub YAML not used in local YAML: {new_keys}")
elif missing_keys:
print("Keys in local YAML not found in GitHub YAML:", missing_keys)
sys.exit(1)
raise Exception(f"Keys in local YAML not found in GitHub YAML: {missing_keys}")
else:
print("No differences in keys found.")

Expand All @@ -85,3 +157,16 @@ def compare_yaml_keys(github_yaml, local_yaml):
)
print('\n'.join(line for line in diff if line.startswith(('+', '-'))))

diff = create_diff(local_yaml, github_yaml)
if "config" in local_file_path:
config_diff = {**config_diff, **diff}
else:
preset_diff = {**preset_diff, **diff}

consensus_spec_str = load_str_from_local(CONSENSUS_SPEC_FILEPATH)
config_diff_table = parse_md_table_to_json(extract_config_diff_section(consensus_spec_str))
preset_diff_table = parse_md_table_to_json(extract_preset_diff_section(consensus_spec_str))

assert_deep_equal_dict(config_diff, config_diff_table, "config diff table")
assert_deep_equal_dict(preset_diff, preset_diff_table, "preset diff table")

0 comments on commit 284fa13

Please sign in to comment.