mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-13 20:24:22 +00:00
Fixed as per hww's comments
This commit is contained in:
parent
14f49aaacb
commit
4a93374025
@ -186,8 +186,8 @@ Unless otherwise indicated, code appearing in `this style` is to be interpreted
|
|||||||
|
|
||||||
| Name | Value |
|
| Name | Value |
|
||||||
| - | - |
|
| - | - |
|
||||||
| `INITIAL_FORK_VERSION` | `0` |
|
| `GENESIS_FORK_VERSION` | `0` |
|
||||||
| `INITIAL_SLOT_NUMBER` | `0` |
|
| `GENESIS_SLOT` | `0` |
|
||||||
| `ZERO_HASH` | `bytes([0] * 32)` |
|
| `ZERO_HASH` | `bytes([0] * 32)` |
|
||||||
| `FAR_FUTURE_SLOT` | `2**63` |
|
| `FAR_FUTURE_SLOT` | `2**63` |
|
||||||
|
|
||||||
@ -1013,28 +1013,6 @@ def get_effective_balance(state: State, index: int) -> int:
|
|||||||
return min(state.validator_balances[index], MAX_DEPOSIT * GWEI_PER_ETH)
|
return min(state.validator_balances[index], MAX_DEPOSIT * GWEI_PER_ETH)
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `get_new_validator_registry_delta_chain_tip`
|
|
||||||
|
|
||||||
```python
|
|
||||||
def get_new_validator_registry_delta_chain_tip(current_validator_registry_delta_chain_tip: Hash32,
|
|
||||||
validator_index: int,
|
|
||||||
pubkey: int,
|
|
||||||
slot: int,
|
|
||||||
flag: int) -> Hash32:
|
|
||||||
"""
|
|
||||||
Compute the next root in the validator registry delta chain.
|
|
||||||
"""
|
|
||||||
return hash_tree_root(
|
|
||||||
ValidatorRegistryDeltaBlock(
|
|
||||||
latest_registry_delta_root=current_validator_registry_delta_chain_tip,
|
|
||||||
validator_index=validator_index,
|
|
||||||
pubkey=pubkey,
|
|
||||||
slot=slot,
|
|
||||||
flag=flag,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `get_fork_version`
|
#### `get_fork_version`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
@ -1144,11 +1122,11 @@ def integer_squareroot(n: int) -> int:
|
|||||||
|
|
||||||
### On startup
|
### On startup
|
||||||
|
|
||||||
A valid block with slot `INITIAL_SLOT_NUMBER` (a "genesis block") has the following values. Other validity rules (e.g. requiring a signature) do not apply.
|
A valid block with slot `GENESIS_SLOT` (a "genesis block") has the following values. Other validity rules (e.g. requiring a signature) do not apply.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
{
|
{
|
||||||
slot=INITIAL_SLOT_NUMBER,
|
slot=GENESIS_SLOT,
|
||||||
parent_root=ZERO_HASH,
|
parent_root=ZERO_HASH,
|
||||||
state_root=STARTUP_STATE_ROOT,
|
state_root=STARTUP_STATE_ROOT,
|
||||||
randao_reveal=ZERO_HASH,
|
randao_reveal=ZERO_HASH,
|
||||||
@ -1175,18 +1153,18 @@ def get_initial_beacon_state(initial_validator_deposits: List[Deposit],
|
|||||||
processed_pow_receipt_root: Hash32) -> BeaconState:
|
processed_pow_receipt_root: Hash32) -> BeaconState:
|
||||||
state = BeaconState(
|
state = BeaconState(
|
||||||
# Misc
|
# Misc
|
||||||
slot=INITIAL_SLOT_NUMBER,
|
slot=GENESIS_SLOT,
|
||||||
genesis_time=genesis_time,
|
genesis_time=genesis_time,
|
||||||
fork_data=ForkData(
|
fork_data=ForkData(
|
||||||
pre_fork_version=INITIAL_FORK_VERSION,
|
pre_fork_version=GENESIS_FORK_VERSION,
|
||||||
post_fork_version=INITIAL_FORK_VERSION,
|
post_fork_version=GENESIS_FORK_VERSION,
|
||||||
fork_slot=INITIAL_SLOT_NUMBER,
|
fork_slot=GENESIS_SLOT,
|
||||||
),
|
),
|
||||||
|
|
||||||
# Validator registry
|
# Validator registry
|
||||||
validator_registry=[],
|
validator_registry=[],
|
||||||
validator_balances=[],
|
validator_balances=[],
|
||||||
validator_registry_latest_change_slot=INITIAL_SLOT_NUMBER,
|
validator_registry_latest_change_slot=GENESIS_SLOT,
|
||||||
validator_registry_exit_count=0,
|
validator_registry_exit_count=0,
|
||||||
validator_registry_delta_chain_tip=ZERO_HASH,
|
validator_registry_delta_chain_tip=ZERO_HASH,
|
||||||
|
|
||||||
@ -1201,13 +1179,13 @@ def get_initial_beacon_state(initial_validator_deposits: List[Deposit],
|
|||||||
poc_challenges=[],
|
poc_challenges=[],
|
||||||
|
|
||||||
# Finality
|
# Finality
|
||||||
previous_justified_slot=INITIAL_SLOT_NUMBER,
|
previous_justified_slot=GENESIS_SLOT,
|
||||||
justified_slot=INITIAL_SLOT_NUMBER,
|
justified_slot=GENESIS_SLOT,
|
||||||
justification_bitfield=0,
|
justification_bitfield=0,
|
||||||
finalized_slot=INITIAL_SLOT_NUMBER,
|
finalized_slot=GENESIS_SLOT,
|
||||||
|
|
||||||
# Recent state
|
# Recent state
|
||||||
latest_crosslinks=[CrosslinkRecord(slot=INITIAL_SLOT_NUMBER, shard_block_root=ZERO_HASH) for _ in range(SHARD_COUNT)],
|
latest_crosslinks=[CrosslinkRecord(slot=GENESIS_SLOT, shard_block_root=ZERO_HASH) for _ in range(SHARD_COUNT)],
|
||||||
latest_block_roots=[ZERO_HASH for _ in range(LATEST_BLOCK_ROOTS_LENGTH)],
|
latest_block_roots=[ZERO_HASH for _ in range(LATEST_BLOCK_ROOTS_LENGTH)],
|
||||||
latest_penalized_exit_balances=[0 for _ in LATEST_PENALIZED_EXIT_LENGTH],
|
latest_penalized_exit_balances=[0 for _ in LATEST_PENALIZED_EXIT_LENGTH],
|
||||||
latest_attestations=[],
|
latest_attestations=[],
|
||||||
@ -1230,10 +1208,10 @@ def get_initial_beacon_state(initial_validator_deposits: List[Deposit],
|
|||||||
poc_commitment=deposit.deposit_data.deposit_input.poc_commitment,
|
poc_commitment=deposit.deposit_data.deposit_input.poc_commitment,
|
||||||
)
|
)
|
||||||
if get_effective_balance(state, validator_index) == MAX_DEPOSIT * GWEI_PER_ETH:
|
if get_effective_balance(state, validator_index) == MAX_DEPOSIT * GWEI_PER_ETH:
|
||||||
activate_validator(state, validator_index)
|
activate_validator(state, validator_index, True)
|
||||||
|
|
||||||
# set initial committee shuffling
|
# set initial committee shuffling
|
||||||
initial_shuffling = get_shuffling(ZERO_HASH, state.validator_registry, 0, INITIAL_SLOT_NUMBER)
|
initial_shuffling = get_shuffling(ZERO_HASH, state.validator_registry, 0, GENESIS_SLOT)
|
||||||
state.shard_committees_at_slots = initial_shuffling + initial_shuffling
|
state.shard_committees_at_slots = initial_shuffling + initial_shuffling
|
||||||
|
|
||||||
# set initial persistent shuffling
|
# set initial persistent shuffling
|
||||||
@ -1348,45 +1326,34 @@ def process_deposit(state: BeaconState,
|
|||||||
|
|
||||||
### Routines for updating validator status
|
### Routines for updating validator status
|
||||||
|
|
||||||
|
_Note that all functions in this section mutate `state`_.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def activate_validator(state: BeaconState,
|
def activate_validator(state: BeaconState, index: int, immediate: bool) -> None:
|
||||||
index: int) -> None:
|
|
||||||
"""
|
|
||||||
Activate the validator with the given ``index``.
|
|
||||||
Note that this function mutates ``state``.
|
|
||||||
"""
|
|
||||||
validator = state.validator_registry[index]
|
validator = state.validator_registry[index]
|
||||||
if validator.activation_slot <= state.slot:
|
if validator.activation_slot <= state.slot:
|
||||||
return
|
return
|
||||||
|
|
||||||
validator.activation_slot = state.slot + ENTRY_EXIT_DELAY
|
validator.activation_slot = state.slot + (0 if immediate else ENTRY_EXIT_DELAY)
|
||||||
state.validator_registry_delta_chain_tip = get_new_validator_registry_delta_chain_tip(
|
state.validator_registry_delta_chain_tip = hash_tree_root(
|
||||||
current_validator_registry_delta_chain_tip=state.validator_registry_delta_chain_tip,
|
ValidatorRegistryDeltaBlock(
|
||||||
validator_index=index,
|
current_validator_registry_delta_chain_tip=state.validator_registry_delta_chain_tip,
|
||||||
pubkey=validator.pubkey,
|
validator_index=index,
|
||||||
slot=validator.activation_slot,
|
pubkey=validator.pubkey,
|
||||||
flag=ACTIVATION,
|
slot=validator.activation_slot,
|
||||||
|
flag=ACTIVATION,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def initiate_validator_exit(state: BeaconState,
|
def initiate_validator_exit(state: BeaconState, index: int) -> None:
|
||||||
index: int) -> None:
|
|
||||||
"""
|
|
||||||
Initiate exit for the validator with the given ``index``.
|
|
||||||
Note that this function mutates ``state``.
|
|
||||||
"""
|
|
||||||
validator = state.validator_registry[index]
|
validator = state.validator_registry[index]
|
||||||
validator.status_flags |= INITIATED_EXIT
|
validator.status_flags |= INITIATED_EXIT
|
||||||
```
|
```
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def exit_validator(state: BeaconState,
|
def exit_validator(state: BeaconState, index: int) -> None:
|
||||||
index: int) -> None:
|
|
||||||
"""
|
|
||||||
Exit the validator with the given ``index``.
|
|
||||||
Note that this function mutates ``state``.
|
|
||||||
"""
|
|
||||||
validator = state.validator_registry[index]
|
validator = state.validator_registry[index]
|
||||||
|
|
||||||
if validator.exit_slot < state.slot + ENTRY_EXIT_DELAY:
|
if validator.exit_slot < state.slot + ENTRY_EXIT_DELAY:
|
||||||
@ -1415,9 +1382,7 @@ def exit_validator(state: BeaconState,
|
|||||||
```
|
```
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def penalize_validator(state: BeaconState,
|
def penalize_validator(state: BeaconState, index: int) -> None:
|
||||||
index: int) -> None:
|
|
||||||
|
|
||||||
exit_validator(state, index)
|
exit_validator(state, index)
|
||||||
state.latest_penalized_exit_balances[(state.slot // EPOCH_LENGTH) % LATEST_PENALIZED_EXIT_LENGTH] += get_effective_balance(state, index)
|
state.latest_penalized_exit_balances[(state.slot // EPOCH_LENGTH) % LATEST_PENALIZED_EXIT_LENGTH] += get_effective_balance(state, index)
|
||||||
|
|
||||||
@ -1429,9 +1394,7 @@ def penalize_validator(state: BeaconState,
|
|||||||
```
|
```
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def set_validator_withdrawable(state: BeaconState,
|
def prepare_validator_for_withdrawal(state: BeaconState, index: int) -> None:
|
||||||
index: int) -> None:
|
|
||||||
|
|
||||||
state.validator_registry[index].status_flags |= WITHDRAWABLE
|
state.validator_registry[index].status_flags |= WITHDRAWABLE
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -1758,7 +1721,7 @@ def update_validator_registry(state: BeaconState) -> None:
|
|||||||
break
|
break
|
||||||
|
|
||||||
# Activate validator
|
# Activate validator
|
||||||
activate_validator(state, index)
|
activate_validator(state, index, False)
|
||||||
|
|
||||||
# Exit validators within the allowable balance churn
|
# Exit validators within the allowable balance churn
|
||||||
balance_churn = 0
|
balance_churn = 0
|
||||||
@ -1809,7 +1772,7 @@ def process_penalties_and_exits(state: BeaconState) -> None:
|
|||||||
# TODO: calculate and apply penalties for slashed validators
|
# TODO: calculate and apply penalties for slashed validators
|
||||||
penalty = 1
|
penalty = 1
|
||||||
state.validator_balances[index] -= penalty
|
state.validator_balances[index] -= penalty
|
||||||
set_validator_withdrawable(state, index)
|
prepare_validator_for_withdrawal(state, index)
|
||||||
withdrawn_so_far += 1
|
withdrawn_so_far += 1
|
||||||
if withdrawn_so_far >= MAX_WITHDRAWALS_PER_EPOCH:
|
if withdrawn_so_far >= MAX_WITHDRAWALS_PER_EPOCH:
|
||||||
break
|
break
|
||||||
|
Loading…
x
Reference in New Issue
Block a user