EIP-7251: format/lint fixes/docs, add validator guide
This commit is contained in:
parent
b18bbd8c61
commit
982a983072
|
@ -472,7 +472,6 @@ def queue_excess_active_balance(state: BeaconState, index: ValidatorIndex) -> No
|
||||||
|
|
||||||
#### New `compute_exit_epoch_and_update_churn`
|
#### New `compute_exit_epoch_and_update_churn`
|
||||||
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def compute_exit_epoch_and_update_churn(state: BeaconState, exit_balance: Gwei) -> Epoch:
|
def compute_exit_epoch_and_update_churn(state: BeaconState, exit_balance: Gwei) -> Epoch:
|
||||||
earliest_exit_epoch = compute_activation_exit_epoch(get_current_epoch(state))
|
earliest_exit_epoch = compute_activation_exit_epoch(get_current_epoch(state))
|
||||||
|
@ -570,12 +569,16 @@ def process_epoch(state: BeaconState) -> None:
|
||||||
|
|
||||||
#### Updated `process_registry_updates`
|
#### Updated `process_registry_updates`
|
||||||
|
|
||||||
|
`process_registry_updates` uses the updated definition of `initiate_validator_exit`
|
||||||
|
and changes how the activation epochs are computed for eligible validators.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def process_registry_updates(state: BeaconState) -> None:
|
def process_registry_updates(state: BeaconState) -> None:
|
||||||
# Process activation eligibility and ejections
|
# Process activation eligibility and ejections
|
||||||
for index, validator in enumerate(state.validators):
|
for index, validator in enumerate(state.validators):
|
||||||
if is_eligible_for_activation_queue(validator):
|
if is_eligible_for_activation_queue(validator):
|
||||||
validator.activation_eligibility_epoch = get_current_epoch(state) + 1
|
validator.activation_eligibility_epoch = get_current_epoch(state) + 1
|
||||||
|
|
||||||
if (
|
if (
|
||||||
is_active_validator(validator, get_current_epoch(state))
|
is_active_validator(validator, get_current_epoch(state))
|
||||||
and validator.effective_balance <= EJECTION_BALANCE
|
and validator.effective_balance <= EJECTION_BALANCE
|
||||||
|
@ -607,7 +610,7 @@ def process_pending_balance_deposits(state: BeaconState) -> None:
|
||||||
state.pending_balance_deposits = state.pending_balance_deposits[next_deposit_index:]
|
state.pending_balance_deposits = state.pending_balance_deposits[next_deposit_index:]
|
||||||
|
|
||||||
if len(state.pending_balance_deposits) == 0:
|
if len(state.pending_balance_deposits) == 0:
|
||||||
state.deposit_balance_to_consume = 0
|
state.deposit_balance_to_consume = Gwei(0)
|
||||||
else:
|
else:
|
||||||
state.deposit_balance_to_consume = available_for_processing - processed_amount
|
state.deposit_balance_to_consume = available_for_processing - processed_amount
|
||||||
```
|
```
|
||||||
|
@ -638,6 +641,8 @@ def process_pending_consolidations(state: BeaconState) -> None:
|
||||||
|
|
||||||
#### Updated `process_effective_balance_updates`
|
#### Updated `process_effective_balance_updates`
|
||||||
|
|
||||||
|
`process_effective_balance_updates` is updated with a new limit for the maximum effective balance.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def process_effective_balance_updates(state: BeaconState) -> None:
|
def process_effective_balance_updates(state: BeaconState) -> None:
|
||||||
# Update effective balances with hysteresis
|
# Update effective balances with hysteresis
|
||||||
|
@ -779,14 +784,16 @@ def process_operations(state: BeaconState, body: BeaconBlockBody) -> None:
|
||||||
for_ops(body.deposits, process_deposit) # [Modified in EIP7251]
|
for_ops(body.deposits, process_deposit) # [Modified in EIP7251]
|
||||||
for_ops(body.voluntary_exits, process_voluntary_exit) # [Modified in EIP7251]
|
for_ops(body.voluntary_exits, process_voluntary_exit) # [Modified in EIP7251]
|
||||||
for_ops(body.bls_to_execution_changes, process_bls_to_execution_change)
|
for_ops(body.bls_to_execution_changes, process_bls_to_execution_change)
|
||||||
for_ops(body.execution_payload.withdraw_requests, process_execution_layer_withdraw_request) # New in EIP7251
|
for_ops(body.execution_payload.withdraw_requests, process_execution_layer_withdraw_request) # [New in EIP7251]
|
||||||
for_ops(body.consolidations, process_consolidation) # New in EIP7251
|
for_ops(body.consolidations, process_consolidation) # [New in EIP7251]
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Deposits
|
##### Deposits
|
||||||
|
|
||||||
###### Updated `apply_deposit`
|
###### Updated `apply_deposit`
|
||||||
|
|
||||||
|
*NOTE*: `process_deposit` is updated with a new definition of `apply_deposit`.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def apply_deposit(state: BeaconState,
|
def apply_deposit(state: BeaconState,
|
||||||
pubkey: BLSPubkey,
|
pubkey: BLSPubkey,
|
||||||
|
@ -819,7 +826,7 @@ def apply_deposit(state: BeaconState,
|
||||||
def is_valid_deposit_signature(pubkey: BLSPubkey,
|
def is_valid_deposit_signature(pubkey: BLSPubkey,
|
||||||
withdrawal_credentials: Bytes32,
|
withdrawal_credentials: Bytes32,
|
||||||
amount: uint64,
|
amount: uint64,
|
||||||
signature: BLSSignature) -> None:
|
signature: BLSSignature) -> bool:
|
||||||
deposit_message = DepositMessage(
|
deposit_message = DepositMessage(
|
||||||
pubkey=pubkey,
|
pubkey=pubkey,
|
||||||
withdrawal_credentials=withdrawal_credentials,
|
withdrawal_credentials=withdrawal_credentials,
|
||||||
|
|
|
@ -131,8 +131,7 @@ def upgrade_to_eip7251(pre: deneb.BeaconState) -> BeaconState:
|
||||||
# Ensure early adopters of compounding credentials go through the activation churn
|
# Ensure early adopters of compounding credentials go through the activation churn
|
||||||
for index, validator in enumerate(post.validators):
|
for index, validator in enumerate(post.validators):
|
||||||
if has_compounding_withdrawal_credential(validator):
|
if has_compounding_withdrawal_credential(validator):
|
||||||
queue_excess_active_balance(post, index)
|
queue_excess_active_balance(post, ValidatorIndex(index))
|
||||||
|
|
||||||
return post
|
return post
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
# EIP-7251 -- Honest Validator
|
||||||
|
|
||||||
|
## Table of contents
|
||||||
|
|
||||||
|
<!-- TOC -->
|
||||||
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
||||||
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
||||||
|
|
||||||
|
- [Introduction](#introduction)
|
||||||
|
- [Prerequisites](#prerequisites)
|
||||||
|
- [Beacon chain responsibilities](#beacon-chain-responsibilities)
|
||||||
|
- [Block and sidecar proposal](#block-and-sidecar-proposal)
|
||||||
|
- [Constructing the `BeaconBlockBody`](#constructing-the-beaconblockbody)
|
||||||
|
- [ExecutionPayload](#executionpayload)
|
||||||
|
|
||||||
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||||
|
<!-- /TOC -->
|
||||||
|
|
||||||
|
## Introduction
|
||||||
|
|
||||||
|
This document represents the changes to be made in the code of an "honest validator".
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
This document is an extension of the [Deneb -- Honest Validator](../deneb/validator.md) guide.
|
||||||
|
All behaviors and definitions defined in this document, and documents it extends, carry over unless explicitly noted or overridden.
|
||||||
|
|
||||||
|
All terminology, constants, functions, and protocol mechanics defined in the updated [Beacon Chain doc of EIP-7251](./beacon-chain.md) are requisite for this document and used throughout.
|
||||||
|
Please see related Beacon Chain doc before continuing and use them as a reference throughout.
|
||||||
|
|
||||||
|
## Beacon chain responsibilities
|
||||||
|
|
||||||
|
All validator responsibilities remain unchanged other than those noted below.
|
||||||
|
|
||||||
|
### Block and sidecar proposal
|
||||||
|
|
||||||
|
#### Constructing the `BeaconBlockBody`
|
||||||
|
|
||||||
|
##### ExecutionPayload
|
||||||
|
|
||||||
|
`prepare_execution_payload` is updated from the Deneb specs.
|
||||||
|
|
||||||
|
*Note*: In this section, `state` is the state of the slot for the block proposal _without_ the block yet applied.
|
||||||
|
That is, `state` is the `previous_state` processed through any empty slots up to the assigned slot using `process_slots(previous_state, slot)`.
|
||||||
|
|
||||||
|
*Note*: The only change to `prepare_execution_payload` is the new definition of `get_expected_withdrawals`.
|
||||||
|
|
||||||
|
```python
|
||||||
|
def prepare_execution_payload(state: BeaconState,
|
||||||
|
safe_block_hash: Hash32,
|
||||||
|
finalized_block_hash: Hash32,
|
||||||
|
suggested_fee_recipient: ExecutionAddress,
|
||||||
|
execution_engine: ExecutionEngine) -> Optional[PayloadId]:
|
||||||
|
# Verify consistency of the parent hash with respect to the previous execution payload header
|
||||||
|
parent_hash = state.latest_execution_payload_header.block_hash
|
||||||
|
|
||||||
|
# Set the forkchoice head and initiate the payload build process
|
||||||
|
withdrawals, _ = get_expected_withdrawals(state) # [Modified in EIP-7251]
|
||||||
|
|
||||||
|
payload_attributes = PayloadAttributes(
|
||||||
|
timestamp=compute_timestamp_at_slot(state, state.slot),
|
||||||
|
prev_randao=get_randao_mix(state, get_current_epoch(state)),
|
||||||
|
suggested_fee_recipient=suggested_fee_recipient,
|
||||||
|
withdrawals=withdrawals,
|
||||||
|
parent_beacon_block_root=hash_tree_root(state.latest_block_header),
|
||||||
|
)
|
||||||
|
return execution_engine.notify_forkchoice_updated(
|
||||||
|
head_block_hash=parent_hash,
|
||||||
|
safe_block_hash=safe_block_hash,
|
||||||
|
finalized_block_hash=finalized_block_hash,
|
||||||
|
payload_attributes=payload_attributes,
|
||||||
|
)
|
||||||
|
```
|
Loading…
Reference in New Issue