Skip to content

Commit bced179

Browse files
committed
Capella
1 parent 99d6500 commit bced179

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

spec/fork.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Warning: this configuration is not definitive.
3030
| `ALTAIR_FORK_EPOCH` | `Epoch(74240)` (Oct 27, 2021, 10:56:23am UTC) |
3131
| `BELLATRIX_FORK_VERSION` | `Version('0x02000000')` |
3232
| `BELLATRIX_FORK_EPOCH` | `Epoch(144896)` (Sept 6, 2022, 11:34:47am UTC) |
33+
| `CAPELLA_FORK_VERSION` | `Version('0x03000000')` |
34+
| `CAPELLA_FORK_EPOCH` | `Epoch(194048)` (April 12, 2023, 10:27:35pm UTC) |
3335

3436
## Helper functions
3537

@@ -42,6 +44,8 @@ def compute_fork_version(epoch: Epoch) -> Version:
4244
"""
4345
Return the fork version at the given ``epoch``.
4446
"""
47+
if epoch >= CAPELLA_FORK_EPOCH:
48+
return CAPELLA_FORK_VERSION
4549
if epoch >= BELLATRIX_FORK_EPOCH:
4650
return BELLATRIX_FORK_VERSION
4751
if epoch >= ALTAIR_FORK_EPOCH:
@@ -196,3 +200,91 @@ def upgrade_to_bellatrix(pre: altair.BeaconState) -> BeaconState:
196200

197201
return post
198202
```
203+
204+
## Fork to Capella
205+
206+
### Fork trigger
207+
208+
The fork is triggered at epoch `CAPELLA_FORK_EPOCH`.
209+
210+
Note that for the pure Capella networks, we don't apply `upgrade_to_capella` since it starts with Capella version logic.
211+
212+
### Upgrading the state
213+
214+
If `state.slot % SLOTS_PER_EPOCH == 0` and `compute_epoch_at_slot(state.slot) == CAPELLA_FORK_EPOCH`,
215+
an irregular state change is made to upgrade to Capella.
216+
217+
The upgrade occurs after the completion of the inner loop of `process_slots` that sets `state.slot` equal to `CAPELLA_FORK_EPOCH * SLOTS_PER_EPOCH`.
218+
Care must be taken when transitioning through the fork boundary as implementations will need a modified [state transition function](../phase0/beacon-chain.md#beacon-chain-state-transition-function) that deviates from the Phase 0 document.
219+
In particular, the outer `state_transition` function defined in the Phase 0 document will not expose the precise fork slot to execute the upgrade in the presence of skipped slots at the fork boundary. Instead, the logic must be within `process_slots`.
220+
221+
```python
222+
def upgrade_to_capella(pre: bellatrix.BeaconState) -> BeaconState:
223+
epoch = bellatrix.get_current_epoch(pre)
224+
latest_execution_payload_header = ExecutionPayloadHeader(
225+
parent_hash=pre.latest_execution_payload_header.parent_hash,
226+
fee_recipient=pre.latest_execution_payload_header.fee_recipient,
227+
state_root=pre.latest_execution_payload_header.state_root,
228+
receipts_root=pre.latest_execution_payload_header.receipts_root,
229+
logs_bloom=pre.latest_execution_payload_header.logs_bloom,
230+
prev_randao=pre.latest_execution_payload_header.prev_randao,
231+
block_number=pre.latest_execution_payload_header.block_number,
232+
gas_limit=pre.latest_execution_payload_header.gas_limit,
233+
gas_used=pre.latest_execution_payload_header.gas_used,
234+
timestamp=pre.latest_execution_payload_header.timestamp,
235+
extra_data=pre.latest_execution_payload_header.extra_data,
236+
base_fee_per_gas=pre.latest_execution_payload_header.base_fee_per_gas,
237+
block_hash=pre.latest_execution_payload_header.block_hash,
238+
transactions_root=pre.latest_execution_payload_header.transactions_root,
239+
withdrawals_root=Root(), # [New in Capella]
240+
)
241+
post = BeaconState(
242+
# Versioning
243+
genesis_time=pre.genesis_time,
244+
genesis_validators_root=pre.genesis_validators_root,
245+
slot=pre.slot,
246+
fork=Fork(
247+
previous_version=pre.fork.current_version,
248+
current_version=CAPELLA_FORK_VERSION,
249+
epoch=epoch,
250+
),
251+
# History
252+
latest_block_header=pre.latest_block_header,
253+
block_roots=pre.block_roots,
254+
state_roots=pre.state_roots,
255+
historical_roots=pre.historical_roots,
256+
# Eth1
257+
eth1_data=pre.eth1_data,
258+
eth1_data_votes=pre.eth1_data_votes,
259+
eth1_deposit_index=pre.eth1_deposit_index,
260+
# Registry
261+
validators=pre.validators,
262+
balances=pre.balances,
263+
# Randomness
264+
randao_mixes=pre.randao_mixes,
265+
# Slashings
266+
slashings=pre.slashings,
267+
# Participation
268+
previous_epoch_participation=pre.previous_epoch_participation,
269+
current_epoch_participation=pre.current_epoch_participation,
270+
# Finality
271+
justification_bits=pre.justification_bits,
272+
previous_justified_checkpoint=pre.previous_justified_checkpoint,
273+
current_justified_checkpoint=pre.current_justified_checkpoint,
274+
finalized_checkpoint=pre.finalized_checkpoint,
275+
# Inactivity
276+
inactivity_scores=pre.inactivity_scores,
277+
# Sync
278+
current_sync_committee=pre.current_sync_committee,
279+
next_sync_committee=pre.next_sync_committee,
280+
# Execution-layer
281+
latest_execution_payload_header=latest_execution_payload_header,
282+
# Withdrawals
283+
next_withdrawal_index=WithdrawalIndex(0), # [New in Capella]
284+
next_withdrawal_validator_index=ValidatorIndex(0), # [New in Capella]
285+
# Deep history valid from Capella onwards
286+
historical_summaries=List[HistoricalSummary, HISTORICAL_ROOTS_LIMIT]([]), # [New in Capella]
287+
)
288+
289+
return post
290+
```

0 commit comments

Comments
 (0)