Skip to content

Commit 99d6500

Browse files
committed
Bellatrix
1 parent 75f7a8a commit 99d6500

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

spec/fork.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Warning: this configuration is not definitive.
2828
| - | - |
2929
| `ALTAIR_FORK_VERSION` | `Version('0x01000000')` |
3030
| `ALTAIR_FORK_EPOCH` | `Epoch(74240)` (Oct 27, 2021, 10:56:23am UTC) |
31+
| `BELLATRIX_FORK_VERSION` | `Version('0x02000000')` |
32+
| `BELLATRIX_FORK_EPOCH` | `Epoch(144896)` (Sept 6, 2022, 11:34:47am UTC) |
3133

3234
## Helper functions
3335

@@ -40,6 +42,8 @@ def compute_fork_version(epoch: Epoch) -> Version:
4042
"""
4143
Return the fork version at the given ``epoch``.
4244
"""
45+
if epoch >= BELLATRIX_FORK_EPOCH:
46+
return BELLATRIX_FORK_VERSION
4347
if epoch >= ALTAIR_FORK_EPOCH:
4448
return ALTAIR_FORK_VERSION
4549
return GENESIS_FORK_VERSION
@@ -124,3 +128,71 @@ def upgrade_to_altair(pre: phase0.BeaconState) -> BeaconState:
124128
post.next_sync_committee = get_next_sync_committee(post)
125129
return post
126130
```
131+
132+
## Fork to Bellatrix
133+
134+
### Fork trigger
135+
136+
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 `BELLATRIX_FORK_EPOCH`.
137+
138+
Note that for the pure Bellatrix networks, we don't apply `upgrade_to_bellatrix` since it starts with Bellatrix version logic.
139+
140+
### Upgrading the state
141+
142+
As with the Phase0-to-Altair upgrade, the `state_transition` is modified to upgrade the `BeaconState`.
143+
The `BeaconState` upgrade runs as part of `process_slots`, slots with missing block proposals do not affect the upgrade time.
144+
145+
If `state.slot % SLOTS_PER_EPOCH == 0` and `compute_epoch_at_slot(state.slot) == BELLATRIX_FORK_EPOCH`, an irregular state change is made to upgrade to Bellatrix.
146+
The upgrade occurs after the completion of the inner loop of `process_slots` that sets `state.slot` equal to `BELLATRIX_FORK_EPOCH * SLOTS_PER_EPOCH`.
147+
148+
When multiple upgrades are scheduled for the same epoch (common for test-networks),
149+
all the upgrades run in sequence before resuming the regular state transition.
150+
151+
```python
152+
def upgrade_to_bellatrix(pre: altair.BeaconState) -> BeaconState:
153+
epoch = altair.get_current_epoch(pre)
154+
post = BeaconState(
155+
# Versioning
156+
genesis_time=pre.genesis_time,
157+
genesis_validators_root=pre.genesis_validators_root,
158+
slot=pre.slot,
159+
fork=Fork(
160+
previous_version=pre.fork.current_version,
161+
current_version=BELLATRIX_FORK_VERSION,
162+
epoch=epoch,
163+
),
164+
# History
165+
latest_block_header=pre.latest_block_header,
166+
block_roots=pre.block_roots,
167+
state_roots=pre.state_roots,
168+
historical_roots=pre.historical_roots,
169+
# Eth1
170+
eth1_data=pre.eth1_data,
171+
eth1_data_votes=pre.eth1_data_votes,
172+
eth1_deposit_index=pre.eth1_deposit_index,
173+
# Registry
174+
validators=pre.validators,
175+
balances=pre.balances,
176+
# Randomness
177+
randao_mixes=pre.randao_mixes,
178+
# Slashings
179+
slashings=pre.slashings,
180+
# Participation
181+
previous_epoch_participation=pre.previous_epoch_participation,
182+
current_epoch_participation=pre.current_epoch_participation,
183+
# Finality
184+
justification_bits=pre.justification_bits,
185+
previous_justified_checkpoint=pre.previous_justified_checkpoint,
186+
current_justified_checkpoint=pre.current_justified_checkpoint,
187+
finalized_checkpoint=pre.finalized_checkpoint,
188+
# Inactivity
189+
inactivity_scores=pre.inactivity_scores,
190+
# Sync
191+
current_sync_committee=pre.current_sync_committee,
192+
next_sync_committee=pre.next_sync_committee,
193+
# Execution-layer
194+
latest_execution_payload_header=ExecutionPayloadHeader(),
195+
)
196+
197+
return post
198+
```

0 commit comments

Comments
 (0)