Cosmetic genesis cleanups
This commit is contained in:
parent
ef90e23dda
commit
bf20031755
|
@ -93,7 +93,10 @@
|
|||
- [Routines for updating validator status](#routines-for-updating-validator-status)
|
||||
- [`initiate_validator_exit`](#initiate_validator_exit)
|
||||
- [`slash_validator`](#slash_validator)
|
||||
- [On genesis](#on-genesis)
|
||||
- [Genesis](#genesis)
|
||||
- [`Eth2Genesis`](#eth2genesis)
|
||||
- [Genesis state](#genesis-state)
|
||||
- [Genesis block](#genesis-block)
|
||||
- [Beacon chain state transition function](#beacon-chain-state-transition-function)
|
||||
- [State caching](#state-caching)
|
||||
- [Per-epoch processing](#per-epoch-processing)
|
||||
|
@ -1171,30 +1174,29 @@ def slash_validator(state: BeaconState, slashed_index: ValidatorIndex, whistlebl
|
|||
decrease_balance(state, slashed_index, whistleblowing_reward)
|
||||
```
|
||||
|
||||
## On genesis
|
||||
## Genesis
|
||||
|
||||
When enough full deposits have been made to the deposit contract, an `Eth2Genesis` log is emitted. Construct a corresponding `genesis_state` and `genesis_block` as follows:
|
||||
### `Eth2Genesis`
|
||||
|
||||
* Let `genesis_validator_deposits` be the list of deposits, ordered chronologically, up to and including the deposit that triggered the `Eth2Genesis` log.
|
||||
* Let `genesis_time` be the timestamp specified in the `Eth2Genesis` log.
|
||||
* Let `genesis_eth1_data` be the `Eth1Data` object where:
|
||||
* `genesis_eth1_data.deposit_root` is the `deposit_root` contained in the `Eth2Genesis` log.
|
||||
* `genesis_eth1_data.deposit_count` is the `deposit_count` contained in the `Eth2Genesis` log.
|
||||
* `genesis_eth1_data.block_hash` is the hash of the Ethereum 1.0 block that emitted the `Eth2Genesis` log.
|
||||
* Let `genesis_state = get_genesis_beacon_state(genesis_validator_deposits, genesis_time, genesis_eth1_data)`.
|
||||
* Let `genesis_block = BeaconBlock(state_root=hash_tree_root(genesis_state))`.
|
||||
When enough deposits of size `MAX_EFFECTIVE_BALANCE` have been made to the deposit contract an `Eth2Genesis` log is emitted triggering the genesis of the beacon chain. Let:
|
||||
|
||||
* `eth2genesis` be the object corresponding to `Eth2Genesis`
|
||||
* `genesis_eth1_data` be object of type `Eth1Data` where
|
||||
* `genesis_eth1_data.deposit_root = eth2genesis.deposit_root`
|
||||
* `genesis_eth1_data.deposit_count = eth2genesis.deposit_count`
|
||||
* `genesis_eth1_data.block_hash` is the hash of the Ethereum 1.0 block that emitted the `Eth2Genesis` log
|
||||
* `genesis_deposits` be the object of type `List[Deposit]` with deposits ordered chronologically up to and including the deposit that triggered the `Eth2Genesis` log
|
||||
|
||||
### Genesis state
|
||||
|
||||
Let `genesis_state = get_genesis_beacon_state(eth2genesis.genesis_time, genesis_eth1_data, genesis_deposits)`.
|
||||
|
||||
```python
|
||||
def get_genesis_beacon_state(genesis_validator_deposits: List[Deposit],
|
||||
genesis_time: int,
|
||||
genesis_eth1_data: Eth1Data) -> BeaconState:
|
||||
"""
|
||||
Get the genesis ``BeaconState``.
|
||||
"""
|
||||
def get_genesis_beacon_state(genesis_time: int, eth1_data: Eth1Data, deposits: List[Deposit]) -> BeaconState:
|
||||
state = BeaconState(genesis_time=genesis_time, latest_eth1_data=genesis_eth1_data)
|
||||
|
||||
# Process genesis deposits
|
||||
for deposit in genesis_validator_deposits:
|
||||
for deposit in deposits:
|
||||
process_deposit(state, deposit)
|
||||
|
||||
# Process genesis activations
|
||||
|
@ -1203,6 +1205,7 @@ def get_genesis_beacon_state(genesis_validator_deposits: List[Deposit],
|
|||
validator.activation_eligibility_epoch = GENESIS_EPOCH
|
||||
validator.activation_epoch = GENESIS_EPOCH
|
||||
|
||||
# Populate latest_active_index_roots
|
||||
genesis_active_index_root = hash_tree_root(get_active_validator_indices(state, GENESIS_EPOCH))
|
||||
for index in range(LATEST_ACTIVE_INDEX_ROOTS_LENGTH):
|
||||
state.latest_active_index_roots[index] = genesis_active_index_root
|
||||
|
@ -1210,6 +1213,10 @@ def get_genesis_beacon_state(genesis_validator_deposits: List[Deposit],
|
|||
return state
|
||||
```
|
||||
|
||||
### Genesis block
|
||||
|
||||
Let `genesis_block = BeaconBlock(state_root=hash_tree_root(genesis_state))`.
|
||||
|
||||
## Beacon chain state transition function
|
||||
|
||||
We now define the state transition function. At a high level, the state transition is made up of four parts:
|
||||
|
|
Loading…
Reference in New Issue