Merge is_genesis_trigger into get_genesis_state
This commit is contained in:
parent
22476420f3
commit
d00b5b9ea0
|
@ -94,7 +94,6 @@
|
|||
- [`initiate_validator_exit`](#initiate_validator_exit)
|
||||
- [`slash_validator`](#slash_validator)
|
||||
- [Genesis](#genesis)
|
||||
- [Genesis trigger](#genesis-trigger)
|
||||
- [Genesis state](#genesis-state)
|
||||
- [Genesis block](#genesis-block)
|
||||
- [Beacon chain state transition function](#beacon-chain-state-transition-function)
|
||||
|
@ -190,7 +189,7 @@ The following values are (non-configurable) constants used throughout the specif
|
|||
| `MIN_PER_EPOCH_CHURN_LIMIT` | `2**2` (= 4) |
|
||||
| `CHURN_LIMIT_QUOTIENT` | `2**16` (= 65,536) |
|
||||
| `SHUFFLE_ROUND_COUNT` | `90` |
|
||||
| `GENESIS_ACTIVE_VALIDATOR_COUNT` | `2**16` (= 65,536) |
|
||||
| `MIN_GENESIS_ACTIVE_VALIDATOR_COUNT` | `2**16` (= 65,536) |
|
||||
| `MIN_GENESIS_TIME` | `1578009600` (Jan 3, 2020) |
|
||||
| `JUSTIFICATION_BITS_LENGTH` | `4` |
|
||||
|
||||
|
@ -1091,35 +1090,28 @@ def slash_validator(state: BeaconState,
|
|||
|
||||
## Genesis
|
||||
|
||||
### Genesis trigger
|
||||
### Genesis state
|
||||
|
||||
Before genesis has been triggered and for every Ethereum 1.0 block call `is_genesis_trigger(deposits: Sequence[Deposit], timestamp: uint64) -> bool` where:
|
||||
Before the Ethereum 2.0 genesis has been triggered and for every Ethereum 1.0 block, call `get_genesis_beacon_state(eth1_block_hash, eth1_timestamp, deposits)` where:
|
||||
|
||||
* `deposits` is the sequence of all deposits, ordered chronologically, up to and including the deposit triggering the latest `Deposit` log
|
||||
* `timestamp` is the Unix timestamp in the Ethereum 1.0 block that emitted the latest `Deposit` log
|
||||
* `eth1_block_hash` is the hash of the Ethereum 1.0 block
|
||||
* `eth1_timestamp` is the Unix timestamp corresponding to `eth1_block_hash`
|
||||
* `deposits` is the sequence of all deposits, ordered chronologically, up to the block with hash `eth1_block_hash`
|
||||
|
||||
When `is_genesis_trigger(deposits, timestamp) is True` for the first time, let:
|
||||
The genesis state `genesis_state` is defined as the return value of the first call to `get_genesis_beacon_state` that does not trigger an `assert`.
|
||||
|
||||
* `genesis_deposits = deposits`
|
||||
* `genesis_time = timestamp - timestamp % SECONDS_PER_DAY + 2 * SECONDS_PER_DAY`
|
||||
* `genesis_eth1_block_hash` is the Ethereum 1.0 block hash that emitted the log for the last deposit in `deposits`
|
||||
|
||||
*Note*: The function `is_genesis_trigger` has yet to be agreed upon by the community, and can be updated as necessary. We define the following testing placeholder:
|
||||
*Note*: The two constants `MIN_GENESIS_TIME` and `MIN_GENESIS_ACTIVE_VALIDATOR_COUNT` in `get_genesis_beacon_state` have yet to be agreed upon by the community, and can be updated as necessary.
|
||||
|
||||
```python
|
||||
def is_genesis_trigger(deposits: Sequence[Deposit], timestamp: uint64) -> bool:
|
||||
# Do not deploy too early
|
||||
if timestamp - timestamp % SECONDS_PER_DAY + 2 * SECONDS_PER_DAY < MIN_GENESIS_TIME:
|
||||
return False
|
||||
# Process genesis deposits
|
||||
state = BeaconState()
|
||||
process_genesis_deposits(state, deposits)
|
||||
# Check active validator count
|
||||
return len(get_active_validator_indices(state, GENESIS_EPOCH)) >= GENESIS_ACTIVE_VALIDATOR_COUNT
|
||||
```
|
||||
def get_genesis_beacon_state(eth1_block_hash: Hash, eth1_timestamp: int, deposits: Sequence[Deposit]) -> BeaconState:
|
||||
state = BeaconState(
|
||||
genesis_time=timestamp - timestamp % SECONDS_PER_DAY + 2 * SECONDS_PER_DAY,
|
||||
eth1_data=Eth1Data(block_hash=genesis_eth1_block_hash),
|
||||
latest_block_header=BeaconBlockHeader(body_root=hash_tree_root(BeaconBlockBody())),
|
||||
)
|
||||
assert state.genesis_time >= MIN_GENESIS_TIME
|
||||
|
||||
```python
|
||||
def process_genesis_deposits(state: BeaconState, deposits: Sequence[Deposit]) -> None:
|
||||
# Process deposits
|
||||
leaves = list(map(lambda deposit: deposit.data, deposits))
|
||||
for deposit_index, deposit in enumerate(deposits):
|
||||
state.eth1_data.deposit_root = hash_tree_root(
|
||||
|
@ -1133,23 +1125,7 @@ def process_genesis_deposits(state: BeaconState, deposits: Sequence[Deposit]) ->
|
|||
if validator.effective_balance == MAX_EFFECTIVE_BALANCE:
|
||||
validator.activation_eligibility_epoch = GENESIS_EPOCH
|
||||
validator.activation_epoch = GENESIS_EPOCH
|
||||
```
|
||||
|
||||
### Genesis state
|
||||
|
||||
Let `genesis_state = get_genesis_beacon_state(genesis_deposits, genesis_time, genesis_eth1_block_hash)`.
|
||||
|
||||
```python
|
||||
def get_genesis_beacon_state(deposits: Sequence[Deposit],
|
||||
genesis_time: int,
|
||||
genesis_eth1_block_hash: Hash) -> BeaconState:
|
||||
# Process genesis deposits
|
||||
state = BeaconState(
|
||||
genesis_time=genesis_time,
|
||||
eth1_data=Eth1Data(block_hash=genesis_eth1_block_hash),
|
||||
latest_block_header=BeaconBlockHeader(body_root=hash_tree_root(BeaconBlockBody())),
|
||||
)
|
||||
process_genesis_deposits(state, deposits)
|
||||
assert len(get_active_validator_indices(state, GENESIS_EPOCH)) >= MIN_GENESIS_ACTIVE_VALIDATOR_COUNT
|
||||
|
||||
# Populate active_index_roots
|
||||
genesis_active_index_root = hash_tree_root(
|
||||
|
|
Loading…
Reference in New Issue