From 66e1a2858f9fbebf5e00539d1a34b78025673d37 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Wed, 21 Apr 2021 00:24:44 +0800 Subject: [PATCH] Use `ALTAIR_FORK_EPOCH` instead of `ALTAIR_FORK_SLOT` --- configs/README.md | 2 +- configs/mainnet/altair.yaml | 2 +- configs/mainnet/merge.yaml | 2 +- configs/mainnet/sharding.yaml | 2 +- configs/minimal/altair.yaml | 2 +- configs/minimal/merge.yaml | 2 +- configs/minimal/sharding.yaml | 2 +- specs/altair/fork.md | 6 +++--- specs/das/fork-choice.md | 2 +- tests/core/pyspec/eth2spec/test/helpers/state.py | 5 +++-- 10 files changed, 14 insertions(+), 13 deletions(-) diff --git a/configs/README.md b/configs/README.md index 15529e590..2cf4e3f60 100644 --- a/configs/README.md +++ b/configs/README.md @@ -15,7 +15,7 @@ Over time, the need to sync an older state may be deprecated. In this case, the prefix on the new constant may be removed, and the old constant will keep a special name before completely being removed. A previous iteration of forking made use of "timelines", but this collides with the definitions used in the spec (constants for special forking slots, etc.), and was not integrated sufficiently in any of the spec tools or implementations. -Instead, the config essentially doubles as fork definition now, e.g. changing the value for `ALTAIR_FORK_SLOT` changes the fork. +Instead, the config essentially doubles as fork definition now, e.g. changing the value for `ALTAIR_FORK_EPOCH` changes the fork. Another reason to prefer forking through constants is the ability to program a forking moment based on context, instead of being limited to a static slot number. diff --git a/configs/mainnet/altair.yaml b/configs/mainnet/altair.yaml index 44490f982..3cd4b8419 100644 --- a/configs/mainnet/altair.yaml +++ b/configs/mainnet/altair.yaml @@ -38,7 +38,7 @@ DOMAIN_CONTRIBUTION_AND_PROOF: 0x09000000 # 0x01000000 ALTAIR_FORK_VERSION: 0x01000000 # TBD -ALTAIR_FORK_SLOT: 18446744073709551615 +ALTAIR_FORK_EPOCH: 18446744073709551615 # Sync protocol diff --git a/configs/mainnet/merge.yaml b/configs/mainnet/merge.yaml index b4667f5b5..4e012ac05 100644 --- a/configs/mainnet/merge.yaml +++ b/configs/mainnet/merge.yaml @@ -4,4 +4,4 @@ # --------------------------------------------------------------- MERGE_FORK_VERSION: 0x02000000 # TBD, temporarily max uint64 value: 2**64 - 1 -MERGE_FORK_SLOT: 18446744073709551615 +MERGE_FORK_EPOCH: 18446744073709551615 diff --git a/configs/mainnet/sharding.yaml b/configs/mainnet/sharding.yaml index 4773aa5f5..b3c22c354 100644 --- a/configs/mainnet/sharding.yaml +++ b/configs/mainnet/sharding.yaml @@ -4,7 +4,7 @@ # --------------------------------------------------------------- SHARDING_FORK_VERSION: 0x03000000 # TBD, temporarily max uint64 value: 2**64 - 1 -SHARDING_FORK_SLOT: 18446744073709551615 +SHARDING_FORK_EPOCH: 18446744073709551615 # Beacon-chain diff --git a/configs/minimal/altair.yaml b/configs/minimal/altair.yaml index 10bdf318b..f9b30eea2 100644 --- a/configs/minimal/altair.yaml +++ b/configs/minimal/altair.yaml @@ -38,7 +38,7 @@ DOMAIN_CONTRIBUTION_AND_PROOF: 0x09000000 # [customized] Highest byte set to 0x01 to avoid collisions with mainnet versioning ALTAIR_FORK_VERSION: 0x01000001 # [customized] -ALTAIR_FORK_SLOT: 18446744073709551615 +ALTAIR_FORK_EPOCH: 18446744073709551615 # Sync protocol diff --git a/configs/minimal/merge.yaml b/configs/minimal/merge.yaml index 394595d02..3b50cd5ca 100644 --- a/configs/minimal/merge.yaml +++ b/configs/minimal/merge.yaml @@ -4,4 +4,4 @@ # --------------------------------------------------------------- MERGE_FORK_VERSION: 0x02000001 # TBD, temporarily max uint64 value: 2**64 - 1 -MERGE_FORK_SLOT: 18446744073709551615 +MERGE_FORK_EPOCH: 18446744073709551615 diff --git a/configs/minimal/sharding.yaml b/configs/minimal/sharding.yaml index f32e2827d..c6ca8b560 100644 --- a/configs/minimal/sharding.yaml +++ b/configs/minimal/sharding.yaml @@ -4,7 +4,7 @@ # --------------------------------------------------------------- SHARDING_FORK_VERSION: 0x03000001 # TBD, temporarily max uint64 value: 2**64 - 1 -MERGE_FORK_SLOT: 18446744073709551615 +MERGE_FORK_EPOCH: 18446744073709551615 # Beacon-chain diff --git a/specs/altair/fork.md b/specs/altair/fork.md index b51466c1e..739584309 100644 --- a/specs/altair/fork.md +++ b/specs/altair/fork.md @@ -26,17 +26,17 @@ Warning: this configuration is not definitive. | Name | Value | | - | - | | `ALTAIR_FORK_VERSION` | `Version('0x01000000')` | -| `ALTAIR_FORK_SLOT` | `Slot(18446744073709551615)` **TBD** | +| `ALTAIR_FORK_EPOCH` | `Epoch(18446744073709551615)` **TBD** | ## Fork to Altair ### Fork trigger -TBD. Social consensus, along with state conditions such as epoch boundary, finality, deposits, active validator count, etc. may be part of the decision process to trigger the fork. For now we assume the condition will be triggered at slot `ALTAIR_FORK_SLOT`, where `ALTAIR_FORK_SLOT % SLOTS_PER_EPOCH == 0`. +TBD. Social consensus, along with state conditions such as epoch boundary, finality, deposits, active validator count, etc. may be part of the decision process to trigger the fork. For now we assume the condition will be triggered at epoch `ALTAIR_FORK_EPOCH`. ### Upgrading the state -After `process_slots` of Phase 0 finishes, if `state.slot == ALTAIR_FORK_SLOT`, an irregular state change is made to upgrade to Altair. +After `process_slots` of Phase 0 finishes, if `state.slot % SLOTS_PER_EPOCH == 0` and `compute_epoch_at_slot(state.slot) == ALTAIR_FORK_EPOCH`, an irregular state change is made to upgrade to Altair. ```python def upgrade_to_altair(pre: phase0.BeaconState) -> BeaconState: diff --git a/specs/das/fork-choice.md b/specs/das/fork-choice.md index 329c033a7..ec9f3ab59 100644 --- a/specs/das/fork-choice.md +++ b/specs/das/fork-choice.md @@ -37,7 +37,7 @@ def get_new_dependencies(state: BeaconState) -> Set[DataCommitment]: ```python def get_all_dependencies(store: Store, block: BeaconBlock) -> Set[DataCommitment]: - if block.slot < SHARDING_FORK_SLOT: + if compute_epoch_at_slot(block.slot) < SHARDING_FORK_EPOCH: return set() else: latest = get_new_dependencies(store.block_states[hash_tree_root(block)]) diff --git a/tests/core/pyspec/eth2spec/test/helpers/state.py b/tests/core/pyspec/eth2spec/test/helpers/state.py index 8980053f5..d61df7610 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/state.py +++ b/tests/core/pyspec/eth2spec/test/helpers/state.py @@ -42,9 +42,10 @@ def transition_to_slot_via_block(spec, state, slot): def transition_to_valid_shard_slot(spec, state): """ - Transition to slot `spec.SHARDING_FORK_SLOT + 1` and fork at `spec.SHARDING_FORK_SLOT`. + Transition to slot `compute_epoch_at_slot(spec.SHARDING_FORK_EPOCH) + 1` + and fork at `compute_epoch_at_slot(spec.SHARDING_FORK_EPOCH)`. """ - transition_to(spec, state, spec.SHARDING_FORK_SLOT) + transition_to(spec, state, spec.compute_epoch_at_slot(spec.SHARDING_FORK_EPOCH)) next_slot(spec, state)