commit
4bec151d7f
|
@ -47,10 +47,10 @@ func validate_proof_of_possession(state: BeaconState,
|
||||||
|
|
||||||
func process_deposit(state: var BeaconState,
|
func process_deposit(state: var BeaconState,
|
||||||
pubkey: ValidatorPubKey,
|
pubkey: ValidatorPubKey,
|
||||||
deposit: uint64,
|
amount: uint64,
|
||||||
proof_of_possession: ValidatorSig,
|
proof_of_possession: ValidatorSig,
|
||||||
withdrawal_credentials: Eth2Digest,
|
withdrawal_credentials: Eth2Digest,
|
||||||
randao_commitment: Eth2Digest) : ValidatorIndex =
|
randao_commitment: Eth2Digest) =
|
||||||
## Process a deposit from Ethereum 1.0.
|
## Process a deposit from Ethereum 1.0.
|
||||||
|
|
||||||
if false:
|
if false:
|
||||||
|
@ -77,16 +77,9 @@ func process_deposit(state: var BeaconState,
|
||||||
status_flags: 0,
|
status_flags: 0,
|
||||||
)
|
)
|
||||||
|
|
||||||
let index = min_empty_validator_index(
|
# Note: In phase 2 registry indices that have been withdrawn for a long time will be recycled.
|
||||||
state.validator_registry, state.validator_balances, state.slot)
|
state.validator_registry.add(validator)
|
||||||
if index.isNone():
|
state.validator_balances.add(amount)
|
||||||
state.validator_registry.add(validator)
|
|
||||||
state.validator_balances.add(deposit)
|
|
||||||
(len(state.validator_registry) - 1).ValidatorIndex
|
|
||||||
else:
|
|
||||||
state.validator_registry[index.get()] = validator
|
|
||||||
state.validator_balances[index.get()] = deposit
|
|
||||||
index.get().ValidatorIndex
|
|
||||||
else:
|
else:
|
||||||
# Increase balance by deposit amount
|
# Increase balance by deposit amount
|
||||||
let index = validator_pubkeys.find(pubkey)
|
let index = validator_pubkeys.find(pubkey)
|
||||||
|
@ -94,8 +87,7 @@ func process_deposit(state: var BeaconState,
|
||||||
assert state.validator_registry[index].withdrawal_credentials ==
|
assert state.validator_registry[index].withdrawal_credentials ==
|
||||||
withdrawal_credentials
|
withdrawal_credentials
|
||||||
|
|
||||||
state.validator_balances[index] += deposit
|
state.validator_balances[index] += amount
|
||||||
index.ValidatorIndex
|
|
||||||
|
|
||||||
func get_entry_exit_effect_epoch*(epoch: EpochNumber): EpochNumber =
|
func get_entry_exit_effect_epoch*(epoch: EpochNumber): EpochNumber =
|
||||||
## An entry or exit triggered in the ``epoch`` given by the input takes effect at
|
## An entry or exit triggered in the ``epoch`` given by the input takes effect at
|
||||||
|
@ -189,11 +181,10 @@ func get_initial_beacon_state*(
|
||||||
# Misc
|
# Misc
|
||||||
slot: GENESIS_SLOT,
|
slot: GENESIS_SLOT,
|
||||||
genesis_time: genesis_time,
|
genesis_time: genesis_time,
|
||||||
# rm fork_slot init in favor of epoch
|
|
||||||
fork: Fork(
|
fork: Fork(
|
||||||
previous_version: GENESIS_FORK_VERSION,
|
previous_version: GENESIS_FORK_VERSION,
|
||||||
current_version: GENESIS_FORK_VERSION,
|
current_version: GENESIS_FORK_VERSION,
|
||||||
fork_slot: GENESIS_SLOT,
|
epoch: GENESIS_EPOCH,
|
||||||
),
|
),
|
||||||
|
|
||||||
validator_registry_update_epoch: GENESIS_EPOCH,
|
validator_registry_update_epoch: GENESIS_EPOCH,
|
||||||
|
@ -220,7 +211,7 @@ func get_initial_beacon_state*(
|
||||||
|
|
||||||
# Process initial deposits
|
# Process initial deposits
|
||||||
for deposit in initial_validator_deposits:
|
for deposit in initial_validator_deposits:
|
||||||
let validator_index = process_deposit(
|
process_deposit(
|
||||||
state,
|
state,
|
||||||
deposit.deposit_data.deposit_input.pubkey,
|
deposit.deposit_data.deposit_input.pubkey,
|
||||||
deposit.deposit_data.amount,
|
deposit.deposit_data.amount,
|
||||||
|
@ -229,13 +220,10 @@ func get_initial_beacon_state*(
|
||||||
deposit.deposit_data.deposit_input.randao_commitment,
|
deposit.deposit_data.deposit_input.randao_commitment,
|
||||||
)
|
)
|
||||||
|
|
||||||
if state.validator_balances[validator_index] >= MAX_DEPOSIT_AMOUNT:
|
|
||||||
activate_validator(state, validator_index, true)
|
|
||||||
|
|
||||||
# Process initial activations
|
# Process initial activations
|
||||||
for validator_index in 0 ..< state.validator_registry.len:
|
for validator_index in 0 ..< state.validator_registry.len:
|
||||||
let vi = validator_index.ValidatorIndex
|
let vi = validator_index.ValidatorIndex
|
||||||
if get_effective_balance(state, vi) > MAX_DEPOSIT_AMOUNT:
|
if get_effective_balance(state, vi) >= MAX_DEPOSIT_AMOUNT:
|
||||||
activate_validator(state, vi, true)
|
activate_validator(state, vi, true)
|
||||||
|
|
||||||
state
|
state
|
||||||
|
|
|
@ -128,9 +128,6 @@ const
|
||||||
ENTRY_EXIT_DELAY* = 256 ##\
|
ENTRY_EXIT_DELAY* = 256 ##\
|
||||||
## slots (~25.6 minutes)
|
## slots (~25.6 minutes)
|
||||||
|
|
||||||
ZERO_BALANCE_VALIDATOR_TTL* = 2'u64^22 ##\
|
|
||||||
## slots (~291 days)
|
|
||||||
|
|
||||||
DEPOSIT_ROOT_VOTING_PERIOD* = 2'u64^10 ##\
|
DEPOSIT_ROOT_VOTING_PERIOD* = 2'u64^10 ##\
|
||||||
## slots (~1.7 hours)
|
## slots (~1.7 hours)
|
||||||
|
|
||||||
|
@ -347,7 +344,7 @@ type
|
||||||
pubkey*: ValidatorPubKey
|
pubkey*: ValidatorPubKey
|
||||||
withdrawal_credentials*: Eth2Digest
|
withdrawal_credentials*: Eth2Digest
|
||||||
|
|
||||||
# TODO remove randao_commitment, randao_layers, latest_status_change_slot
|
# TODO remove randao_commitment, randao_layers
|
||||||
randao_commitment*: Eth2Digest ##\
|
randao_commitment*: Eth2Digest ##\
|
||||||
## RANDAO commitment created by repeatedly taking the hash of a secret value
|
## RANDAO commitment created by repeatedly taking the hash of a secret value
|
||||||
## so as to create "onion layers" around it. For every block that a
|
## so as to create "onion layers" around it. For every block that a
|
||||||
|
@ -360,9 +357,6 @@ type
|
||||||
## Number of proposals the proposer missed, and thus the number of times to
|
## Number of proposals the proposer missed, and thus the number of times to
|
||||||
## apply hash function to randao reveal
|
## apply hash function to randao reveal
|
||||||
|
|
||||||
latest_status_change_slot*: uint64 ##\
|
|
||||||
## Slot when validator last changed status (or 0)
|
|
||||||
|
|
||||||
activation_epoch*: EpochNumber ##\
|
activation_epoch*: EpochNumber ##\
|
||||||
## Slot when validator activated
|
## Slot when validator activated
|
||||||
|
|
||||||
|
@ -413,8 +407,8 @@ type
|
||||||
|
|
||||||
Fork* = object
|
Fork* = object
|
||||||
previous_version*: uint64 # Previous fork version
|
previous_version*: uint64 # Previous fork version
|
||||||
current_version*: uint64 # Current fork version
|
current_version*: uint64 # Current fork version
|
||||||
fork_slot*: uint64 # Fork slot number TODO should be epoch
|
epoch*: uint64 # Fork epoch number
|
||||||
|
|
||||||
ValidatorRegistryDeltaBlock* = object
|
ValidatorRegistryDeltaBlock* = object
|
||||||
latest_registry_delta_root*: Eth2Digest
|
latest_registry_delta_root*: Eth2Digest
|
||||||
|
|
|
@ -119,9 +119,11 @@ func integer_squareroot*(n: SomeInteger): SomeInteger =
|
||||||
y = (x + n div x) div 2
|
y = (x + n div x) div 2
|
||||||
x
|
x
|
||||||
|
|
||||||
func get_fork_version*(fork: Fork, slot: uint64): uint64 =
|
func get_fork_version*(fork: Fork, epoch: EpochNumber): uint64 =
|
||||||
if slot < fork.fork_slot: fork.previous_version
|
if epoch < fork.epoch:
|
||||||
else: fork.current_version
|
fork.previous_version
|
||||||
|
else:
|
||||||
|
fork.current_version
|
||||||
|
|
||||||
func get_domain*(
|
func get_domain*(
|
||||||
fork: Fork, slot: uint64, domain_type: SignatureDomain): uint64 =
|
fork: Fork, slot: uint64, domain_type: SignatureDomain): uint64 =
|
||||||
|
|
|
@ -12,16 +12,6 @@ import
|
||||||
../ssz,
|
../ssz,
|
||||||
./crypto, ./datatypes, ./digest, ./helpers
|
./crypto, ./datatypes, ./digest, ./helpers
|
||||||
|
|
||||||
func min_empty_validator_index*(
|
|
||||||
validators: seq[Validator],
|
|
||||||
validator_balances: seq[uint64],
|
|
||||||
current_slot: uint64): Option[int] =
|
|
||||||
for i, v in validators:
|
|
||||||
if validator_balances[i] == 0 and
|
|
||||||
v.latest_status_change_slot +
|
|
||||||
ZERO_BALANCE_VALIDATOR_TTL.uint64 <= current_slot:
|
|
||||||
return some(i)
|
|
||||||
|
|
||||||
func xorSeed(seed: Eth2Digest, x: uint64): Eth2Digest =
|
func xorSeed(seed: Eth2Digest, x: uint64): Eth2Digest =
|
||||||
## Integers are all encoded as bigendian
|
## Integers are all encoded as bigendian
|
||||||
## Helper for get_shuffling in lieu of generally better bitwise handling
|
## Helper for get_shuffling in lieu of generally better bitwise handling
|
||||||
|
@ -154,5 +144,5 @@ func get_beacon_proposer_index*(state: BeaconState, slot: uint64): ValidatorInde
|
||||||
# TODO this index is invalid outside of the block state transition function
|
# TODO this index is invalid outside of the block state transition function
|
||||||
# because presently, `state.slot += 1` happens before this function
|
# because presently, `state.slot += 1` happens before this function
|
||||||
# is called - see also testutil.getNextBeaconProposerIndex
|
# is called - see also testutil.getNextBeaconProposerIndex
|
||||||
let first_committee = get_crosslink_committees_at_slot(state, slot)[0][0]
|
let (first_committee, _) = get_crosslink_committees_at_slot(state, slot)[0]
|
||||||
first_committee[slot.int mod len(first_committee)]
|
first_committee[slot.int mod len(first_committee)]
|
||||||
|
|
|
@ -34,10 +34,6 @@ suite "Block processing":
|
||||||
|
|
||||||
state.slot == genesisState.slot + 1
|
state.slot == genesisState.slot + 1
|
||||||
|
|
||||||
# When proposer skips their proposal, randao layer is still peeled!
|
|
||||||
state.validator_registry[proposer_index].randao_layers ==
|
|
||||||
genesisState.validator_registry[proposer_index].randao_layers + 1
|
|
||||||
|
|
||||||
test "Passes from genesis state, empty block":
|
test "Passes from genesis state, empty block":
|
||||||
var
|
var
|
||||||
state = genesisState
|
state = genesisState
|
||||||
|
@ -53,10 +49,6 @@ suite "Block processing":
|
||||||
|
|
||||||
state.slot == genesisState.slot + 1
|
state.slot == genesisState.slot + 1
|
||||||
|
|
||||||
# Proposer proposed, no need for additional peeling
|
|
||||||
state.validator_registry[proposer_index].randao_layers ==
|
|
||||||
genesisState.validator_registry[proposer_index].randao_layers
|
|
||||||
|
|
||||||
test "Passes through epoch update, no block":
|
test "Passes through epoch update, no block":
|
||||||
var
|
var
|
||||||
state = genesisState
|
state = genesisState
|
||||||
|
@ -122,9 +114,7 @@ suite "Block processing":
|
||||||
check:
|
check:
|
||||||
state.latest_attestations.len == 1
|
state.latest_attestations.len == 1
|
||||||
|
|
||||||
# TODO Can't run more than 127 for now:
|
while state.slot < 191:
|
||||||
# https://github.com/ethereum/eth2.0-specs/issues/352
|
|
||||||
while state.slot < 127:
|
|
||||||
discard updateState(
|
discard updateState(
|
||||||
state, previous_block_root, none(BeaconBlock), {})
|
state, previous_block_root, none(BeaconBlock), {})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue