mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-02-22 07:18:10 +00:00
Apply @hwwhww suggestions
This commit is contained in:
parent
de5be63399
commit
fae77eb53d
@ -10,12 +10,10 @@
|
|||||||
- [Constants](#constants)
|
- [Constants](#constants)
|
||||||
- [Misc](#misc)
|
- [Misc](#misc)
|
||||||
- [Preset](#preset)
|
- [Preset](#preset)
|
||||||
- [State list lengths](#state-list-lengths)
|
|
||||||
- [Execution](#execution)
|
- [Execution](#execution)
|
||||||
- [Containers](#containers)
|
- [Containers](#containers)
|
||||||
- [New containers](#new-containers)
|
- [New containers](#new-containers)
|
||||||
- [`DepositReceipt`](#depositreceipt)
|
- [`DepositReceipt`](#depositreceipt)
|
||||||
- [`IndexedDepositData`](#indexeddepositdata)
|
|
||||||
- [Extended Containers](#extended-containers)
|
- [Extended Containers](#extended-containers)
|
||||||
- [`ExecutionPayload`](#executionpayload)
|
- [`ExecutionPayload`](#executionpayload)
|
||||||
- [`ExecutionPayloadHeader`](#executionpayloadheader)
|
- [`ExecutionPayloadHeader`](#executionpayloadheader)
|
||||||
@ -23,7 +21,8 @@
|
|||||||
- [Beacon chain state transition function](#beacon-chain-state-transition-function)
|
- [Beacon chain state transition function](#beacon-chain-state-transition-function)
|
||||||
- [Block processing](#block-processing)
|
- [Block processing](#block-processing)
|
||||||
- [Modified `process_operations`](#modified-process_operations)
|
- [Modified `process_operations`](#modified-process_operations)
|
||||||
- [New `get_validator_from_deposit_receipt`](#new-get_validator_from_deposit_receipt)
|
- [New `get_validator_from_deposit_data`](#new-get_validator_from_deposit_data)
|
||||||
|
- [New `apply_deposit`](#new-apply_deposit)
|
||||||
- [New `process_deposit_receipt`](#new-process_deposit_receipt)
|
- [New `process_deposit_receipt`](#new-process_deposit_receipt)
|
||||||
- [Modified `process_deposit`](#modified-process_deposit)
|
- [Modified `process_deposit`](#modified-process_deposit)
|
||||||
- [Modified `process_execution_payload`](#modified-process_execution_payload)
|
- [Modified `process_execution_payload`](#modified-process_execution_payload)
|
||||||
@ -51,12 +50,6 @@ The following values are (non-configurable) constants used throughout the specif
|
|||||||
|
|
||||||
## Preset
|
## Preset
|
||||||
|
|
||||||
### State list lengths
|
|
||||||
|
|
||||||
| Name | Value |
|
|
||||||
| - | - |
|
|
||||||
| `PENDING_DEPOSITS_LIMIT` | `2**32` (= 4,294,967,296) |
|
|
||||||
|
|
||||||
### Execution
|
### Execution
|
||||||
|
|
||||||
| Name | Value | Description |
|
| Name | Value | Description |
|
||||||
@ -78,17 +71,6 @@ class DepositReceipt(Container):
|
|||||||
index: uint64
|
index: uint64
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `IndexedDepositData`
|
|
||||||
|
|
||||||
```python
|
|
||||||
class IndexedDepositData(Container):
|
|
||||||
pubkey: BLSPubkey
|
|
||||||
withdrawal_credentials: Bytes32
|
|
||||||
amount: Gwei
|
|
||||||
index: uint64
|
|
||||||
epoch: Epoch
|
|
||||||
```
|
|
||||||
|
|
||||||
### Extended Containers
|
### Extended Containers
|
||||||
|
|
||||||
#### `ExecutionPayload`
|
#### `ExecutionPayload`
|
||||||
@ -211,9 +193,11 @@ def process_block(state: BeaconState, block: BeaconBlock) -> None:
|
|||||||
```python
|
```python
|
||||||
def process_operations(state: BeaconState, body: BeaconBlockBody) -> None:
|
def process_operations(state: BeaconState, body: BeaconBlockBody) -> None:
|
||||||
# Prevent potential underflow introduced by mixing two deposit processing flows
|
# Prevent potential underflow introduced by mixing two deposit processing flows
|
||||||
unprocessed_deposits_count = max(0, state.eth1_data.deposit_count - state.eth1_deposit_index) # [New in EIP-6110]
|
# [New in EIP-6110]
|
||||||
# Verify that outstanding deposits are processed up to the maximum number of deposits
|
if state.eth1_data.deposit_count > state.eth1_deposit_index:
|
||||||
assert len(body.deposits) == min(MAX_DEPOSITS, unprocessed_deposits_count) # [Modified in EIP-6110]
|
assert len(body.deposits) == min(MAX_DEPOSITS, state.eth1_data.deposit_count - state.eth1_deposit_index)
|
||||||
|
else:
|
||||||
|
assert len(body.deposits) == 0
|
||||||
|
|
||||||
def for_ops(operations: Sequence[Any], fn: Callable[[BeaconState, Any], None]) -> None:
|
def for_ops(operations: Sequence[Any], fn: Callable[[BeaconState, Any], None]) -> None:
|
||||||
for operation in operations:
|
for operation in operations:
|
||||||
@ -231,16 +215,15 @@ def process_operations(state: BeaconState, body: BeaconBlockBody) -> None:
|
|||||||
for_ops(body.execution_payload.deposit_receipts, process_deposit_receipt)
|
for_ops(body.execution_payload.deposit_receipts, process_deposit_receipt)
|
||||||
```
|
```
|
||||||
|
|
||||||
#### New `get_validator_from_deposit_receipt`
|
#### New `get_validator_from_deposit_data`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def get_validator_from_deposit_receipt(deposit_receipt: DepositReceipt) -> Validator:
|
def get_validator_from_deposit_data(pubkey: BLSPubkey, withdrawal_credentials: Bytes32, amount: uint64) -> Validator:
|
||||||
amount = deposit_receipt.amount
|
|
||||||
effective_balance = min(amount - amount % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE)
|
effective_balance = min(amount - amount % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE)
|
||||||
|
|
||||||
return Validator(
|
return Validator(
|
||||||
pubkey=deposit_receipt.pubkey,
|
pubkey=pubkey,
|
||||||
withdrawal_credentials=deposit_receipt.withdrawal_credentials,
|
withdrawal_credentials=withdrawal_credentials,
|
||||||
activation_eligibility_epoch=FAR_FUTURE_EPOCH,
|
activation_eligibility_epoch=FAR_FUTURE_EPOCH,
|
||||||
activation_epoch=FAR_FUTURE_EPOCH,
|
activation_epoch=FAR_FUTURE_EPOCH,
|
||||||
exit_epoch=FAR_FUTURE_EPOCH,
|
exit_epoch=FAR_FUTURE_EPOCH,
|
||||||
@ -249,6 +232,39 @@ def get_validator_from_deposit_receipt(deposit_receipt: DepositReceipt) -> Valid
|
|||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### New `apply_deposit`
|
||||||
|
|
||||||
|
```python
|
||||||
|
def apply_deposit(state: BeaconState,
|
||||||
|
pubkey: BLSPubkey,
|
||||||
|
withdrawal_credentials: Bytes32,
|
||||||
|
amount: uint64,
|
||||||
|
signature: BLSSignature,
|
||||||
|
) -> None:
|
||||||
|
validator_pubkeys = [validator.pubkey for validator in state.validators]
|
||||||
|
if pubkey not in validator_pubkeys:
|
||||||
|
# Verify the deposit signature (proof of possession) which is not checked by the deposit contract
|
||||||
|
deposit_message = DepositMessage(
|
||||||
|
pubkey=pubkey,
|
||||||
|
withdrawal_credentials=withdrawal_credentials,
|
||||||
|
amount=amount,
|
||||||
|
)
|
||||||
|
domain = compute_domain(DOMAIN_DEPOSIT) # Fork-agnostic domain since deposits are valid across forks
|
||||||
|
signing_root = compute_signing_root(deposit_message, domain)
|
||||||
|
# Initialize validator if the deposit signature is valid
|
||||||
|
if bls.Verify(pubkey, signing_root, signature):
|
||||||
|
state.validators.append(get_validator_from_deposit_data(pubkey, withdrawal_credentials, amount))
|
||||||
|
state.balances.append(amount)
|
||||||
|
state.previous_epoch_participation.append(ParticipationFlags(0b0000_0000))
|
||||||
|
state.current_epoch_participation.append(ParticipationFlags(0b0000_0000))
|
||||||
|
state.inactivity_scores.append(uint64(0))
|
||||||
|
else:
|
||||||
|
# Increase balance by deposit amount
|
||||||
|
index = ValidatorIndex(validator_pubkeys.index(pubkey))
|
||||||
|
increase_balance(state, index, amount)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
#### New `process_deposit_receipt`
|
#### New `process_deposit_receipt`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
@ -261,34 +277,18 @@ def process_deposit_receipt(state: BeaconState, deposit_receipt: DepositReceipt)
|
|||||||
if state.eth1_deposit_index >= state.deposit_receipts_start_index:
|
if state.eth1_deposit_index >= state.deposit_receipts_start_index:
|
||||||
state.eth1_deposit_index = deposit_receipt.index + 1
|
state.eth1_deposit_index = deposit_receipt.index + 1
|
||||||
|
|
||||||
pubkey = deposit_receipt.pubkey
|
apply_deposit(
|
||||||
amount = deposit_receipt.amount
|
state=state,
|
||||||
validator_pubkeys = [validator.pubkey for validator in state.validators]
|
pubkey=deposit_receipt.pubkey,
|
||||||
if pubkey not in validator_pubkeys:
|
withdrawal_credentials=deposit_receipt.withdrawal_credentials,
|
||||||
# Verify the deposit signature (proof of possession) which is not checked by the deposit contract
|
amount=deposit_receipt.amount,
|
||||||
deposit_message = DepositMessage(
|
signature=deposit_receipt.signature,
|
||||||
pubkey=deposit_receipt.pubkey,
|
)
|
||||||
withdrawal_credentials=deposit_receipt.withdrawal_credentials,
|
|
||||||
amount=deposit_receipt.amount,
|
|
||||||
)
|
|
||||||
domain = compute_domain(DOMAIN_DEPOSIT) # Fork-agnostic domain since deposits are valid across forks
|
|
||||||
signing_root = compute_signing_root(deposit_message, domain)
|
|
||||||
# Initialize validator if the deposit signature is valid
|
|
||||||
if bls.Verify(pubkey, signing_root, deposit_receipt.signature):
|
|
||||||
state.validators.append(get_validator_from_deposit_receipt(deposit_receipt))
|
|
||||||
state.balances.append(amount)
|
|
||||||
state.previous_epoch_participation.append(ParticipationFlags(0b0000_0000))
|
|
||||||
state.current_epoch_participation.append(ParticipationFlags(0b0000_0000))
|
|
||||||
state.inactivity_scores.append(uint64(0))
|
|
||||||
else:
|
|
||||||
# Increase balance by deposit amount
|
|
||||||
index = ValidatorIndex(validator_pubkeys.index(pubkey))
|
|
||||||
increase_balance(state, index, amount)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Modified `process_deposit`
|
#### Modified `process_deposit`
|
||||||
|
|
||||||
*Note*: The function `process_deposit` is modified to prevent deposits from being processed in the second time (due to `process_deposit_receipt`).
|
*Note*: The function `process_deposit` is modified to prevent deposits from being processed the second time (due to `process_deposit_receipt`).
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def process_deposit(state: BeaconState, deposit: Deposit) -> None:
|
def process_deposit(state: BeaconState, deposit: Deposit) -> None:
|
||||||
@ -310,29 +310,13 @@ def process_deposit(state: BeaconState, deposit: Deposit) -> None:
|
|||||||
# Deposits must be processed in order
|
# Deposits must be processed in order
|
||||||
state.eth1_deposit_index += 1
|
state.eth1_deposit_index += 1
|
||||||
|
|
||||||
pubkey = deposit.data.pubkey
|
apply_deposit(
|
||||||
amount = deposit.data.amount
|
state=state,
|
||||||
validator_pubkeys = [validator.pubkey for validator in state.validators]
|
pubkey=deposit.data.pubkey,
|
||||||
if pubkey not in validator_pubkeys:
|
withdrawal_credentials=deposit.data.withdrawal_credentials,
|
||||||
# Verify the deposit signature (proof of possession) which is not checked by the deposit contract
|
amount=deposit.data.amount,
|
||||||
deposit_message = DepositMessage(
|
signature=deposit.data.signature,
|
||||||
pubkey=deposit.data.pubkey,
|
)
|
||||||
withdrawal_credentials=deposit.data.withdrawal_credentials,
|
|
||||||
amount=deposit.data.amount,
|
|
||||||
)
|
|
||||||
domain = compute_domain(DOMAIN_DEPOSIT) # Fork-agnostic domain since deposits are valid across forks
|
|
||||||
signing_root = compute_signing_root(deposit_message, domain)
|
|
||||||
# Initialize validator if the deposit signature is valid
|
|
||||||
if bls.Verify(pubkey, signing_root, deposit.data.signature):
|
|
||||||
state.validators.append(get_validator_from_deposit(deposit))
|
|
||||||
state.balances.append(amount)
|
|
||||||
state.previous_epoch_participation.append(ParticipationFlags(0b0000_0000))
|
|
||||||
state.current_epoch_participation.append(ParticipationFlags(0b0000_0000))
|
|
||||||
state.inactivity_scores.append(uint64(0))
|
|
||||||
else:
|
|
||||||
# Increase balance by deposit amount
|
|
||||||
index = ValidatorIndex(validator_pubkeys.index(pubkey))
|
|
||||||
increase_balance(state, index, amount)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Modified `process_execution_payload`
|
#### Modified `process_execution_payload`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user