From 6502cc1149921c9a27201e5021b341d00030b37e Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 11 Jun 2020 00:40:09 +0800 Subject: [PATCH] Separate config files by phases --- configs/README.md | 2 +- configs/{mainnet.yaml => mainnet_phase0.yaml} | 67 ----------------- configs/mainnet_phase1.yaml | 69 ++++++++++++++++++ configs/{minimal.yaml => minimal_phase0.yaml} | 70 ------------------ configs/minimal_phase1.yaml | 71 +++++++++++++++++++ .../pyspec/eth2spec/config/config_util.py | 22 ++++-- 6 files changed, 157 insertions(+), 144 deletions(-) rename configs/{mainnet.yaml => mainnet_phase0.yaml} (69%) create mode 100644 configs/mainnet_phase1.yaml rename configs/{minimal.yaml => minimal_phase0.yaml} (69%) create mode 100644 configs/minimal_phase1.yaml diff --git a/configs/README.md b/configs/README.md index 4ca54e014..be3c60e6f 100644 --- a/configs/README.md +++ b/configs/README.md @@ -32,4 +32,4 @@ Each preset is a key-value mapping. Presets may contain comments to describe the values. -See [`mainnet.yaml`](./mainnet.yaml) for a complete example. +See [`mainnet_phase0.yaml`](./mainnet_phase0.yaml) for a complete example. diff --git a/configs/mainnet.yaml b/configs/mainnet_phase0.yaml similarity index 69% rename from configs/mainnet.yaml rename to configs/mainnet_phase0.yaml index 3631b7045..39cfddf77 100644 --- a/configs/mainnet.yaml +++ b/configs/mainnet_phase0.yaml @@ -151,70 +151,3 @@ DOMAIN_DEPOSIT: 0x03000000 DOMAIN_VOLUNTARY_EXIT: 0x04000000 DOMAIN_SELECTION_PROOF: 0x05000000 DOMAIN_AGGREGATE_AND_PROOF: 0x06000000 -# Phase 1 -DOMAIN_SHARD_PROPOSAL: 0x80000000 -DOMAIN_SHARD_COMMITTEE: 0x81000000 -DOMAIN_LIGHT_CLIENT: 0x82000000 -DOMAIN_CUSTODY_BIT_SLASHING: 0x83000000 - - -# Phase 1: Upgrade from Phase 0 -# --------------------------------------------------------------- -PHASE_1_FORK_VERSION: 0x01000000 -# [STUB] -PHASE_1_GENESIS_SLOT: 32 -INITIAL_ACTIVE_SHARDS: 64 - -# Phase 1: General -# --------------------------------------------------------------- -# 2**10` (= 1024) -MAX_SHARDS: 1024 -# 2**3 (= 8) | online epochs | ~51 min -ONLINE_PERIOD: 8 -# 2**7 (= 128) -LIGHT_CLIENT_COMMITTEE_SIZE: 128 -# 2**8 (= 256) | epochs | ~27 hours -LIGHT_CLIENT_COMMITTEE_PERIOD: 256 -# 2**18 (= 262,144) -SHARD_BLOCK_CHUNK_SIZE: 262144 -# 2**2 (= 4) -MAX_SHARD_BLOCK_CHUNKS: 4 -# 3 * 2**16` (= 196,608) -TARGET_SHARD_BLOCK_SIZE: 196608 -# Note: MAX_SHARD_BLOCKS_PER_ATTESTATION is derived from the list length. -SHARD_BLOCK_OFFSETS: [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233] -# len(SHARD_BLOCK_OFFSETS) -MAX_SHARD_BLOCKS_PER_ATTESTATION: 12 -# 2**14 (= 16,384) Gwei -MAX_GASPRICE: 16384 -# 2**3 (= 8) Gwei -MIN_GASPRICE: 8 -# 2**3 (= 8) -GASPRICE_ADJUSTMENT_COEFFICIENT: 8 - - -# Phase 1: Custody Game -# --------------------------------------------------------------- - -# Time parameters -# 2**1 (= 2) epochs, 12.8 minutes -RANDAO_PENALTY_EPOCHS: 2 -# 2**14 (= 16,384) epochs ~73 days -EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS: 16384 -# 2**11 (= 2,048) epochs, ~9 days -EPOCHS_PER_CUSTODY_PERIOD: 2048 -# 2**11 (= 2,048) epochs, ~9 days -CUSTODY_PERIOD_TO_RANDAO_PADDING: 2048 -# 2**7 (= 128) epochs, ~14 hours -MAX_REVEAL_LATENESS_DECREMENT: 128 - -# Max operations -# 2**8 (= 256) -MAX_CUSTODY_KEY_REVEALS: 256 -MAX_EARLY_DERIVED_SECRET_REVEALS: 1 -MAX_CUSTODY_SLASHINGS: 1 - -# Reward and penalty quotients -EARLY_DERIVED_SECRET_REVEAL_SLOT_REWARD_MULTIPLE: 2 -# 2**8 (= 256) -MINOR_REWARD_QUOTIENT: 256 diff --git a/configs/mainnet_phase1.yaml b/configs/mainnet_phase1.yaml new file mode 100644 index 000000000..f85c538c8 --- /dev/null +++ b/configs/mainnet_phase1.yaml @@ -0,0 +1,69 @@ +# Mainnet preset - phase 1 + + +# Phase 1: Upgrade from Phase 0 +# --------------------------------------------------------------- +PHASE_1_FORK_VERSION: 0x01000000 +# [STUB] +PHASE_1_GENESIS_SLOT: 32 +INITIAL_ACTIVE_SHARDS: 64 + +# Phase 1: General +# --------------------------------------------------------------- +# Phase 1 domain +DOMAIN_SHARD_PROPOSAL: 0x80000000 +DOMAIN_SHARD_COMMITTEE: 0x81000000 +DOMAIN_LIGHT_CLIENT: 0x82000000 +DOMAIN_CUSTODY_BIT_SLASHING: 0x83000000 + +# 2**10` (= 1024) +MAX_SHARDS: 1024 +# 2**3 (= 8) | online epochs | ~51 min +ONLINE_PERIOD: 8 +# 2**7 (= 128) +LIGHT_CLIENT_COMMITTEE_SIZE: 128 +# 2**8 (= 256) | epochs | ~27 hours +LIGHT_CLIENT_COMMITTEE_PERIOD: 256 +# 2**18 (= 262,144) +SHARD_BLOCK_CHUNK_SIZE: 262144 +# 2**2 (= 4) +MAX_SHARD_BLOCK_CHUNKS: 4 +# 3 * 2**16` (= 196,608) +TARGET_SHARD_BLOCK_SIZE: 196608 +# Note: MAX_SHARD_BLOCKS_PER_ATTESTATION is derived from the list length. +SHARD_BLOCK_OFFSETS: [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233] +# len(SHARD_BLOCK_OFFSETS) +MAX_SHARD_BLOCKS_PER_ATTESTATION: 12 +# 2**14 (= 16,384) Gwei +MAX_GASPRICE: 16384 +# 2**3 (= 8) Gwei +MIN_GASPRICE: 8 +# 2**3 (= 8) +GASPRICE_ADJUSTMENT_COEFFICIENT: 8 + + +# Phase 1: Custody Game +# --------------------------------------------------------------- + +# Time parameters +# 2**1 (= 2) epochs, 12.8 minutes +RANDAO_PENALTY_EPOCHS: 2 +# 2**14 (= 16,384) epochs ~73 days +EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS: 16384 +# 2**11 (= 2,048) epochs, ~9 days +EPOCHS_PER_CUSTODY_PERIOD: 2048 +# 2**11 (= 2,048) epochs, ~9 days +CUSTODY_PERIOD_TO_RANDAO_PADDING: 2048 +# 2**7 (= 128) epochs, ~14 hours +MAX_REVEAL_LATENESS_DECREMENT: 128 + +# Max operations +# 2**8 (= 256) +MAX_CUSTODY_KEY_REVEALS: 256 +MAX_EARLY_DERIVED_SECRET_REVEALS: 1 +MAX_CUSTODY_SLASHINGS: 1 + +# Reward and penalty quotients +EARLY_DERIVED_SECRET_REVEAL_SLOT_REWARD_MULTIPLE: 2 +# 2**8 (= 256) +MINOR_REWARD_QUOTIENT: 256 diff --git a/configs/minimal.yaml b/configs/minimal_phase0.yaml similarity index 69% rename from configs/minimal.yaml rename to configs/minimal_phase0.yaml index 174694add..524d0d5f9 100644 --- a/configs/minimal.yaml +++ b/configs/minimal_phase0.yaml @@ -151,73 +151,3 @@ DOMAIN_DEPOSIT: 0x03000000 DOMAIN_VOLUNTARY_EXIT: 0x04000000 DOMAIN_SELECTION_PROOF: 0x05000000 DOMAIN_AGGREGATE_AND_PROOF: 0x06000000 -# Phase 1 -DOMAIN_SHARD_PROPOSAL: 0x80000000 -DOMAIN_SHARD_COMMITTEE: 0x81000000 -DOMAIN_LIGHT_CLIENT: 0x82000000 -DOMAIN_CUSTODY_BIT_SLASHING: 0x83000000 - - -# Phase 1: Upgrade from Phase 0 -# --------------------------------------------------------------- -# [customized] for testnet distinction -PHASE_1_FORK_VERSION: 0x01000001 -# [customized] for testing -PHASE_1_GENESIS_SLOT: 8 -# [customized] reduced for testing -INITIAL_ACTIVE_SHARDS: 2 - - -# Phase 1: General -# --------------------------------------------------------------- -# [customized] reduced for testing -MAX_SHARDS: 8 -# 2**3 (= 8) | online epochs -ONLINE_PERIOD: 8 -# 2**7 (= 128) -LIGHT_CLIENT_COMMITTEE_SIZE: 128 -# 2**8 (= 256) | epochs -LIGHT_CLIENT_COMMITTEE_PERIOD: 256 -# 2**18 (= 262,144) -SHARD_BLOCK_CHUNK_SIZE: 262144 -# 2**2 (= 4) -MAX_SHARD_BLOCK_CHUNKS: 4 -# 3 * 2**16` (= 196,608) -TARGET_SHARD_BLOCK_SIZE: 196608 -# Note: MAX_SHARD_BLOCKS_PER_ATTESTATION is derived from the list length. -SHARD_BLOCK_OFFSETS: [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233] -# len(SHARD_BLOCK_OFFSETS) -MAX_SHARD_BLOCKS_PER_ATTESTATION: 12 -# 2**14 (= 16,384) Gwei -MAX_GASPRICE: 16384 -# 2**3 (= 8) Gwei -MIN_GASPRICE: 8 -# 2**3 (= 8) -GASPRICE_ADJUSTMENT_COEFFICIENT: 8 - - -# Phase 1: Custody Game -# --------------------------------------------------------------- - -# Time parameters -# 2**1 (= 2) epochs -RANDAO_PENALTY_EPOCHS: 2 -# [customized] quicker for testing -EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS: 4096 -# 2**11 (= 2,048) epochs -EPOCHS_PER_CUSTODY_PERIOD: 2048 -# 2**11 (= 2,048) epochs -CUSTODY_PERIOD_TO_RANDAO_PADDING: 2048 -# 2**7 (= 128) epochs -MAX_REVEAL_LATENESS_DECREMENT: 128 - -# Max operations -# 2**8 (= 256) -MAX_CUSTODY_KEY_REVEALS: 256 -MAX_EARLY_DERIVED_SECRET_REVEALS: 1 -MAX_CUSTODY_SLASHINGS: 1 - -# Reward and penalty quotients -EARLY_DERIVED_SECRET_REVEAL_SLOT_REWARD_MULTIPLE: 2 -# 2**8 (= 256) -MINOR_REWARD_QUOTIENT: 256 diff --git a/configs/minimal_phase1.yaml b/configs/minimal_phase1.yaml new file mode 100644 index 000000000..a7066ed92 --- /dev/null +++ b/configs/minimal_phase1.yaml @@ -0,0 +1,71 @@ +# Minimal preset - phase 1 + + +# Phase 1: Upgrade from Phase 0 +# --------------------------------------------------------------- +# [customized] for testnet distinction +PHASE_1_FORK_VERSION: 0x01000001 +# [customized] for testing +PHASE_1_GENESIS_SLOT: 8 +# [customized] reduced for testing +INITIAL_ACTIVE_SHARDS: 2 + +# Phase 1: General +# --------------------------------------------------------------- +# Phase 1 domain +DOMAIN_SHARD_PROPOSAL: 0x80000000 +DOMAIN_SHARD_COMMITTEE: 0x81000000 +DOMAIN_LIGHT_CLIENT: 0x82000000 +DOMAIN_CUSTODY_BIT_SLASHING: 0x83000000 + +# [customized] reduced for testing +MAX_SHARDS: 8 +# 2**3 (= 8) | online epochs +ONLINE_PERIOD: 8 +# 2**7 (= 128) +LIGHT_CLIENT_COMMITTEE_SIZE: 128 +# 2**8 (= 256) | epochs +LIGHT_CLIENT_COMMITTEE_PERIOD: 256 +# 2**18 (= 262,144) +SHARD_BLOCK_CHUNK_SIZE: 262144 +# 2**2 (= 4) +MAX_SHARD_BLOCK_CHUNKS: 4 +# 3 * 2**16` (= 196,608) +TARGET_SHARD_BLOCK_SIZE: 196608 +# Note: MAX_SHARD_BLOCKS_PER_ATTESTATION is derived from the list length. +SHARD_BLOCK_OFFSETS: [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233] +# len(SHARD_BLOCK_OFFSETS) +MAX_SHARD_BLOCKS_PER_ATTESTATION: 12 +# 2**14 (= 16,384) Gwei +MAX_GASPRICE: 16384 +# 2**3 (= 8) Gwei +MIN_GASPRICE: 8 +# 2**3 (= 8) +GASPRICE_ADJUSTMENT_COEFFICIENT: 8 + + +# Phase 1: Custody Game +# --------------------------------------------------------------- + +# Time parameters +# 2**1 (= 2) epochs +RANDAO_PENALTY_EPOCHS: 2 +# [customized] quicker for testing +EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS: 4096 +# 2**11 (= 2,048) epochs +EPOCHS_PER_CUSTODY_PERIOD: 2048 +# 2**11 (= 2,048) epochs +CUSTODY_PERIOD_TO_RANDAO_PADDING: 2048 +# 2**7 (= 128) epochs +MAX_REVEAL_LATENESS_DECREMENT: 128 + +# Max operations +# 2**8 (= 256) +MAX_CUSTODY_KEY_REVEALS: 256 +MAX_EARLY_DERIVED_SECRET_REVEALS: 1 +MAX_CUSTODY_SLASHINGS: 1 + +# Reward and penalty quotients +EARLY_DERIVED_SECRET_REVEAL_SLOT_REWARD_MULTIPLE: 2 +# 2**8 (= 256) +MINOR_REWARD_QUOTIENT: 256 diff --git a/tests/core/pyspec/eth2spec/config/config_util.py b/tests/core/pyspec/eth2spec/config/config_util.py index c43c1521b..9a6f3c648 100644 --- a/tests/core/pyspec/eth2spec/config/config_util.py +++ b/tests/core/pyspec/eth2spec/config/config_util.py @@ -1,8 +1,10 @@ -from ruamel.yaml import YAML -from pathlib import Path +import os from os.path import join +from pathlib import Path from typing import Dict, Any +from ruamel.yaml import YAML + config: Dict[str, Any] = {} @@ -35,11 +37,19 @@ def load_config_file(configs_dir: str, presets_name: str) -> Dict[str, Any]: :param presets_name: The name of the presets. (lowercase snake_case) :return: Dictionary, mapping of constant-name -> constant-value """ - path = Path(join(configs_dir, presets_name + '.yaml')) - yaml = YAML(typ='base') - loaded = yaml.load(path) + _, _, config_files = next(os.walk(configs_dir)) + config_files.sort() + loaded_config = {} + for config_file_name in config_files: + if config_file_name.startswith(presets_name): + yaml = YAML(typ='base') + path = Path(join(configs_dir, config_file_name)) + loaded = yaml.load(path) + loaded_config.update(loaded) + assert loaded_config != {} + out: Dict[str, Any] = dict() - for k, v in loaded.items(): + for k, v in loaded_config.items(): if isinstance(v, list): # Clean up integer values. YAML parser renders lists of ints as list of str out[k] = [int(item) if item.isdigit() else item for item in v]