From f618f3c59d4bc60913c775d8fb85244988d3117f Mon Sep 17 00:00:00 2001 From: protolambda Date: Thu, 18 Mar 2021 01:06:37 +0100 Subject: [PATCH] move custody-specific operations to custody spec --- specs/custody/custody-game.md | 49 ++++++++++++++++++++++++++++++++++ specs/sharding/beacon-chain.md | 28 +++++++++---------- 2 files changed, 61 insertions(+), 16 deletions(-) diff --git a/specs/custody/custody-game.md b/specs/custody/custody-game.md index d7f0f8c2a..95bdf4b7e 100644 --- a/specs/custody/custody-game.md +++ b/specs/custody/custody-game.md @@ -39,6 +39,7 @@ - [`get_randao_epoch_for_custody_period`](#get_randao_epoch_for_custody_period) - [`get_custody_period_for_validator`](#get_custody_period_for_validator) - [Per-block processing](#per-block-processing) + - [Block processing](#block-processing) - [Custody Game Operations](#custody-game-operations) - [Chunk challenges](#chunk-challenges) - [Custody chunk response](#custody-chunk-response) @@ -46,6 +47,7 @@ - [Early derived secret reveals](#early-derived-secret-reveals) - [Custody Slashings](#custody-slashings) - [Per-epoch processing](#per-epoch-processing) + - [Epoch transition](#epoch-transition) - [Handling of reveal deadlines](#handling-of-reveal-deadlines) - [Final updates](#final-updates) @@ -348,6 +350,18 @@ def get_custody_period_for_validator(validator_index: ValidatorIndex, epoch: Epo ## Per-block processing +### Block processing + +```python +def process_block(state: BeaconState, block: BeaconBlock) -> None: + process_block_header(state, block) + process_randao(state, block.body) + process_eth1_data(state, block.body) + process_light_client_aggregate(state, block.body) + process_operations(state, block.body) + process_custody_game_operations(state, block.body) +``` + ### Custody Game Operations ```python @@ -605,6 +619,41 @@ def process_custody_slashing(state: BeaconState, signed_custody_slashing: Signed ## Per-epoch processing +### Epoch transition + +This epoch transition overrides the phase0 epoch transition: + +```python +def process_epoch(state: BeaconState) -> None: + process_justification_and_finalization(state) + process_rewards_and_penalties(state) + process_registry_updates(state) + + # Proof of custody + process_reveal_deadlines(state) + process_challenge_deadlines(state) + + process_slashings(state) + + # Sharding + process_pending_headers(state) + charge_confirmed_header_fees(state) + reset_pending_headers(state) + + # Final updates + # Phase 0 + process_eth1_data_reset(state) + process_effective_balance_updates(state) + process_slashings_reset(state) + process_randao_mixes_reset(state) + process_historical_roots_update(state) + process_participation_record_updates(state) + # Proof of custody + process_custody_final_updates(state) + + process_shard_epoch_increment(state) +``` + ### Handling of reveal deadlines ```python diff --git a/specs/sharding/beacon-chain.md b/specs/sharding/beacon-chain.md index 4b0ec4db3..b578570a2 100644 --- a/specs/sharding/beacon-chain.md +++ b/specs/sharding/beacon-chain.md @@ -49,7 +49,7 @@ - [`process_shard_header`](#process_shard_header) - [Epoch transition](#epoch-transition) - [Pending headers](#pending-headers) - - [Custody game updates](#custody-game-updates) + - [Shard epoch increment](#shard-epoch-increment) @@ -125,7 +125,7 @@ We define the following Python custom types for type hinting and readability: ## Updated containers -The following containers have updated definitions in Phase 1. +The following containers have updated definitions to support Sharding. ### `AttestationData` @@ -167,7 +167,8 @@ class BeaconState(phase0.BeaconState): ## New containers -The following containers are new in Phase 1. +The shard data itself is network-layer only, and can be found in the [P2P specification](./p2p-interface.md). +The beacon chain registers just the commitments of the shard data. ### `DataCommitment` @@ -435,9 +436,6 @@ def process_operations(state: BeaconState, body: BeaconBlockBody) -> None: for_ops(body.attestations, process_attestation) for_ops(body.deposits, process_deposit) for_ops(body.voluntary_exits, process_voluntary_exit) - - # See custody game spec. - process_custody_game_operations(state, body) ``` ### New Attestation processing @@ -550,10 +548,6 @@ def process_epoch(state: BeaconState) -> None: process_rewards_and_penalties(state) process_registry_updates(state) - # Proof of custody - process_reveal_deadlines(state) - process_challenge_deadlines(state) - process_slashings(state) # Sharding @@ -569,10 +563,8 @@ def process_epoch(state: BeaconState) -> None: process_randao_mixes_reset(state) process_historical_roots_update(state) process_participation_record_updates(state) - # Proof of custody - process_custody_final_updates(state) - # Update current_epoch_start_shard - state.current_epoch_start_shard = get_start_shard(state, Slot(state.slot + 1)) + + process_shard_epoch_increment(state) ``` #### Pending headers @@ -682,6 +674,10 @@ def reset_pending_headers(state: BeaconState) -> None: )) ``` -#### Custody game updates +#### Shard epoch increment -`process_reveal_deadlines`, `process_challenge_deadlines` and `process_custody_final_updates` are defined in [the Custody Game spec](./custody-game.md). +```python +def process_shard_epoch_increment(state: BeaconState) -> None: + # Update current_epoch_start_shard + state.current_epoch_start_shard = get_start_shard(state, Slot(state.slot + 1)) +```