mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-03-02 19:20:34 +00:00
Merge pull request #3311 from dapplion/add_validator_to_registry
Add add_validator_to_registry fn
This commit is contained in:
commit
12512ef818
@ -45,7 +45,7 @@
|
|||||||
- [Modified `slash_validator`](#modified-slash_validator)
|
- [Modified `slash_validator`](#modified-slash_validator)
|
||||||
- [Block processing](#block-processing)
|
- [Block processing](#block-processing)
|
||||||
- [Modified `process_attestation`](#modified-process_attestation)
|
- [Modified `process_attestation`](#modified-process_attestation)
|
||||||
- [Modified `apply_deposit`](#modified-apply_deposit)
|
- [Modified `add_validator_to_registry`](#modified-add_validator_to_registry)
|
||||||
- [Sync aggregate processing](#sync-aggregate-processing)
|
- [Sync aggregate processing](#sync-aggregate-processing)
|
||||||
- [Epoch processing](#epoch-processing)
|
- [Epoch processing](#epoch-processing)
|
||||||
- [Justification and finalization](#justification-and-finalization)
|
- [Justification and finalization](#justification-and-finalization)
|
||||||
@ -508,40 +508,23 @@ def process_attestation(state: BeaconState, attestation: Attestation) -> None:
|
|||||||
increase_balance(state, get_beacon_proposer_index(state), proposer_reward)
|
increase_balance(state, get_beacon_proposer_index(state), proposer_reward)
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Modified `apply_deposit`
|
#### Modified `add_validator_to_registry`
|
||||||
|
|
||||||
*Note*: The function `apply_deposit` is modified to initialize `inactivity_scores`, `previous_epoch_participation`, and `current_epoch_participation`.
|
*Note*: The function `add_validator_to_registry` is modified to initialize `inactivity_scores`, `previous_epoch_participation`, and `current_epoch_participation`.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def apply_deposit(state: BeaconState,
|
def add_validator_to_registry(state: BeaconState,
|
||||||
pubkey: BLSPubkey,
|
pubkey: BLSPubkey,
|
||||||
withdrawal_credentials: Bytes32,
|
withdrawal_credentials: Bytes32,
|
||||||
amount: uint64,
|
amount: uint64) -> None:
|
||||||
signature: BLSSignature) -> None:
|
index = get_index_for_new_validator(state)
|
||||||
validator_pubkeys = [validator.pubkey for validator in state.validators]
|
validator = get_validator_from_deposit(pubkey, withdrawal_credentials, amount)
|
||||||
if pubkey not in validator_pubkeys:
|
set_or_append_list(state.validators, index, validator)
|
||||||
# Verify the deposit signature (proof of possession) which is not checked by the deposit contract
|
set_or_append_list(state.balances, index, amount)
|
||||||
deposit_message = DepositMessage(
|
# [New in Altair]
|
||||||
pubkey=pubkey,
|
set_or_append_list(state.previous_epoch_participation, index, ParticipationFlags(0b0000_0000))
|
||||||
withdrawal_credentials=withdrawal_credentials,
|
set_or_append_list(state.current_epoch_participation, index, ParticipationFlags(0b0000_0000))
|
||||||
amount=amount,
|
set_or_append_list(state.inactivity_scores, index, uint64(0))
|
||||||
)
|
|
||||||
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):
|
|
||||||
index = get_index_for_new_validator(state)
|
|
||||||
validator = get_validator_from_deposit(pubkey, withdrawal_credentials, amount)
|
|
||||||
set_or_append_list(state.validators, index, validator)
|
|
||||||
set_or_append_list(state.balances, index, amount)
|
|
||||||
# [New in Altair]
|
|
||||||
set_or_append_list(state.previous_epoch_participation, index, ParticipationFlags(0b0000_0000))
|
|
||||||
set_or_append_list(state.current_epoch_participation, index, ParticipationFlags(0b0000_0000))
|
|
||||||
set_or_append_list(state.inactivity_scores, index, uint64(0))
|
|
||||||
else:
|
|
||||||
# Increase balance by deposit amount
|
|
||||||
index = ValidatorIndex(validator_pubkeys.index(pubkey))
|
|
||||||
increase_balance(state, index, amount)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Sync aggregate processing
|
#### Sync aggregate processing
|
||||||
|
@ -1849,6 +1849,15 @@ def get_validator_from_deposit(pubkey: BLSPubkey, withdrawal_credentials: Bytes3
|
|||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
def add_validator_to_registry(state: BeaconState,
|
||||||
|
pubkey: BLSPubkey,
|
||||||
|
withdrawal_credentials: Bytes32,
|
||||||
|
amount: uint64) -> None:
|
||||||
|
state.validators.append(get_validator_from_deposit(pubkey, withdrawal_credentials, amount))
|
||||||
|
state.balances.append(amount)
|
||||||
|
```
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def apply_deposit(state: BeaconState,
|
def apply_deposit(state: BeaconState,
|
||||||
pubkey: BLSPubkey,
|
pubkey: BLSPubkey,
|
||||||
@ -1865,12 +1874,8 @@ def apply_deposit(state: BeaconState,
|
|||||||
)
|
)
|
||||||
domain = compute_domain(DOMAIN_DEPOSIT) # Fork-agnostic domain since deposits are valid across forks
|
domain = compute_domain(DOMAIN_DEPOSIT) # Fork-agnostic domain since deposits are valid across forks
|
||||||
signing_root = compute_signing_root(deposit_message, domain)
|
signing_root = compute_signing_root(deposit_message, domain)
|
||||||
if not bls.Verify(pubkey, signing_root, signature):
|
if bls.Verify(pubkey, signing_root, signature):
|
||||||
return
|
add_validator_to_registry(state, pubkey, withdrawal_credentials, amount)
|
||||||
|
|
||||||
# Add validator and balance entries
|
|
||||||
state.validators.append(get_validator_from_deposit(pubkey, withdrawal_credentials, amount))
|
|
||||||
state.balances.append(amount)
|
|
||||||
else:
|
else:
|
||||||
# Increase balance by deposit amount
|
# Increase balance by deposit amount
|
||||||
index = ValidatorIndex(validator_pubkeys.index(pubkey))
|
index = ValidatorIndex(validator_pubkeys.index(pubkey))
|
||||||
|
@ -55,7 +55,7 @@ It consists of four main sections:
|
|||||||
- [ENR structure](#enr-structure)
|
- [ENR structure](#enr-structure)
|
||||||
- [Attestation subnet bitfield](#attestation-subnet-bitfield)
|
- [Attestation subnet bitfield](#attestation-subnet-bitfield)
|
||||||
- [`eth2` field](#eth2-field)
|
- [`eth2` field](#eth2-field)
|
||||||
- [Attestation subnet subcription](#attestation-subnet-subcription)
|
- [Attestation subnet subscription](#attestation-subnet-subscription)
|
||||||
- [Design decision rationale](#design-decision-rationale)
|
- [Design decision rationale](#design-decision-rationale)
|
||||||
- [Transport](#transport-1)
|
- [Transport](#transport-1)
|
||||||
- [Why are we defining specific transports?](#why-are-we-defining-specific-transports)
|
- [Why are we defining specific transports?](#why-are-we-defining-specific-transports)
|
||||||
@ -1002,7 +1002,7 @@ Clients MAY connect to peers with the same `fork_digest` but a different `next_f
|
|||||||
Unless `ENRForkID` is manually updated to matching prior to the earlier `next_fork_epoch` of the two clients,
|
Unless `ENRForkID` is manually updated to matching prior to the earlier `next_fork_epoch` of the two clients,
|
||||||
these connecting clients will be unable to successfully interact starting at the earlier `next_fork_epoch`.
|
these connecting clients will be unable to successfully interact starting at the earlier `next_fork_epoch`.
|
||||||
|
|
||||||
### Attestation subnet subcription
|
### Attestation subnet subscription
|
||||||
|
|
||||||
Because Phase 0 does not have shards and thus does not have Shard Committees, there is no stable backbone to the attestation subnets (`beacon_attestation_{subnet_id}`). To provide this stability, each beacon node should:
|
Because Phase 0 does not have shards and thus does not have Shard Committees, there is no stable backbone to the attestation subnets (`beacon_attestation_{subnet_id}`). To provide this stability, each beacon node should:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user