Added topups
This commit is contained in:
parent
d6d1f88ac1
commit
4ec40f06f3
|
@ -34,6 +34,7 @@ The primary source of load on the beacon chain are "attestations". Attestations
|
||||||
| --- | --- | :---: | - |
|
| --- | --- | :---: | - |
|
||||||
| `SHARD_COUNT` | 2**10 (= 1,024)| shards |
|
| `SHARD_COUNT` | 2**10 (= 1,024)| shards |
|
||||||
| `DEPOSIT_SIZE` | 2**5 (= 32) | ETH |
|
| `DEPOSIT_SIZE` | 2**5 (= 32) | ETH |
|
||||||
|
| `MIN_TOPUP_SIZE` | 1 | ETH |
|
||||||
| `MIN_ONLINE_DEPOSIT_SIZE` | 2**4 (= 16) | ETH |
|
| `MIN_ONLINE_DEPOSIT_SIZE` | 2**4 (= 16) | ETH |
|
||||||
| `GWEI_PER_ETH` | 10**9 | Gwei/ETH |
|
| `GWEI_PER_ETH` | 10**9 | Gwei/ETH |
|
||||||
| `DEPOSIT_CONTRACT_ADDRESS` | **TBD** | - |
|
| `DEPOSIT_CONTRACT_ADDRESS` | **TBD** | - |
|
||||||
|
@ -743,6 +744,7 @@ Now, to add a validator:
|
||||||
```python
|
```python
|
||||||
def add_validator(state: State,
|
def add_validator(state: State,
|
||||||
pubkey: int,
|
pubkey: int,
|
||||||
|
deposit_size: int,
|
||||||
proof_of_possession: bytes,
|
proof_of_possession: bytes,
|
||||||
withdrawal_credentials: Hash32,
|
withdrawal_credentials: Hash32,
|
||||||
randao_commitment: Hash32,
|
randao_commitment: Hash32,
|
||||||
|
@ -756,23 +758,32 @@ def add_validator(state: State,
|
||||||
sig=proof_of_possession,
|
sig=proof_of_possession,
|
||||||
domain=get_domain(state, current_slot, DOMAIN_DEPOSIT))
|
domain=get_domain(state, current_slot, DOMAIN_DEPOSIT))
|
||||||
# Pubkey uniqueness
|
# Pubkey uniqueness
|
||||||
assert pubkey not in [v.pubkey for v in state.validators]
|
validator_pubkeys = [v.pubkey for v in state.validators]
|
||||||
rec = ValidatorRecord(
|
if pubkey not in validator_pubkeys:
|
||||||
pubkey=pubkey,
|
assert deposit_size == DEPOSIT_SIZE`
|
||||||
withdrawal_credentials=withdrawal_credentials,
|
rec = ValidatorRecord(
|
||||||
randao_commitment=randao_commitment,
|
pubkey=pubkey,
|
||||||
randao_skips=0,
|
withdrawal_credentials=withdrawal_credentials,
|
||||||
balance=DEPOSIT_SIZE * GWEI_PER_ETH,
|
randao_commitment=randao_commitment,
|
||||||
|
randao_skips=0,
|
||||||
|
balance=DEPOSIT_SIZE * GWEI_PER_ETH,
|
||||||
status=status,
|
status=status,
|
||||||
last_status_change_slot=current_slot,
|
last_status_change_slot=current_slot,
|
||||||
exit_seq=0
|
exit_seq=0
|
||||||
)
|
)
|
||||||
index = min_empty_validator(state.validators)
|
index = min_empty_validator(state.validators)
|
||||||
if index is None:
|
if index is None:
|
||||||
state.validators.append(rec)
|
state.validators.append(rec)
|
||||||
return len(state.validators) - 1
|
return len(state.validators) - 1
|
||||||
|
else:
|
||||||
|
state.validators[index] = rec
|
||||||
|
return index
|
||||||
else:
|
else:
|
||||||
state.validators[index] = rec
|
index = validator_pubkeys.index(pubkey)
|
||||||
|
val = state.validators[index]
|
||||||
|
assert val.withdrawal_credentials == withdrawal_credentials
|
||||||
|
assert deposit_size >= MIN_TOPUP_SIZE
|
||||||
|
val.balance += deposit_size
|
||||||
return index
|
return index
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -959,9 +970,7 @@ def verify_merkle_branch(leaf: Hash32, branch: [Hash32], depth: int, index: int,
|
||||||
return value == root
|
return value == root
|
||||||
```
|
```
|
||||||
|
|
||||||
Verify that `deposit_data.msg_value == DEPOSIT_SIZE` and `block.slot - (deposit_data.timestamp - state.genesis_time) // SLOT_DURATION < DELETION_PERIOD`.
|
Run `add_validator(validators, deposit_data.deposit_params.pubkey, deposit_data.msg_value, deposit_data.deposit_params.proof_of_possession, deposit_data.deposit_params.withdrawal_credentials, deposit_data.deposit_params.randao_commitment, PENDING_ACTIVATION, block.slot)`.
|
||||||
|
|
||||||
Run `add_validator(validators, deposit_data.deposit_params.pubkey, deposit_data.deposit_params.proof_of_possession, deposit_data.deposit_params.withdrawal_credentials, deposit_data.deposit_params.randao_commitment, PENDING_ACTIVATION, block.slot)`.
|
|
||||||
|
|
||||||
## State recalculations (every `CYCLE_LENGTH` slots)
|
## State recalculations (every `CYCLE_LENGTH` slots)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue