From 582309150105cae6eedd3557c92cdfd5aef1f43c Mon Sep 17 00:00:00 2001 From: Dustin Brody Date: Wed, 16 Jan 2019 03:39:16 -0800 Subject: [PATCH] some more fields, plumbing, comment fixes --- beacon_chain/spec/beaconstate.nim | 38 +++++++++++++++++++++++-------- beacon_chain/spec/datatypes.nim | 10 ++++++-- beacon_chain/spec/validator.nim | 2 ++ beacon_chain/state_transition.nim | 6 ++++- 4 files changed, 43 insertions(+), 13 deletions(-) diff --git a/beacon_chain/spec/beaconstate.nim b/beacon_chain/spec/beaconstate.nim index 3e62223d1..7720cfca2 100644 --- a/beacon_chain/spec/beaconstate.nim +++ b/beacon_chain/spec/beaconstate.nim @@ -51,14 +51,13 @@ func process_deposit(state: var BeaconState, proof_of_possession: ValidatorSig, withdrawal_credentials: Eth2Digest, randao_commitment: Eth2Digest, - flags: UpdateFlags): Uint24 = + custody_commitment: Eth2Digest): Uint24 = ## Process a deposit from Ethereum 1.0. - if skipValidation notin flags: - # TODO return error - doAssert validate_proof_of_possession( - state, pubkey, proof_of_possession, withdrawal_credentials, - randao_commitment) + # TODO return error + doAssert validate_proof_of_possession( + state, pubkey, proof_of_possession, withdrawal_credentials, + randao_commitment) let validator_pubkeys = state.validator_registry.mapIt(it.pubkey) @@ -71,7 +70,15 @@ func process_deposit(state: var BeaconState, randao_layers: 0, status: PENDING_ACTIVATION, latest_status_change_slot: state.slot, - exit_count: 0 + activation_slot: FAR_FUTURE_SLOT, + exit_slot: FAR_FUTURE_SLOT, + withdrawal_slot: FAR_FUTURE_SLOT, + penalized_slot: FAR_FUTURE_SLOT, + exit_count: 0, + status_flags: 0, + custody_commitment: custody_commitment, + latest_custody_reseed_slot: GENESIS_SLOT, + penultimate_custody_reseed_slot: GENESIS_SLOT ) let index = min_empty_validator_index( @@ -109,6 +116,7 @@ func activate_validator(state: var BeaconState, state.validator_registry_delta_chain_tip, index, validator.pubkey, + validator.activation_slot, ACTIVATION, ) @@ -162,6 +170,7 @@ func exit_validator(state: var BeaconState, state.validator_registry_delta_chain_tip, index, validator.pubkey, + validator.exit_slot, ValidatorSetDeltaFlags.EXIT ) @@ -219,16 +228,25 @@ func get_initial_beacon_state*( validator_registry_exit_count: 0, validator_registry_delta_chain_tip: ZERO_HASH, + # Randomness and committees + previous_epoch_start_shard: GENESIS_START_SHARD, + current_epoch_start_shard: GENESIS_START_SHARD, + previous_epoch_calculation_slot: GENESIS_SLOT, + current_epoch_calculation_slot: GENESIS_SLOT, + previous_epoch_randao_mix: ZERO_HASH, + current_epoch_randao_mix: ZERO_HASH, + # Finality previous_justified_slot: GENESIS_SLOT, justified_slot: GENESIS_SLOT, + justification_bitfield: 0, finalized_slot: GENESIS_SLOT, - # PoW receipt root + # Deposit root latest_deposit_root: latest_deposit_root, ) - # handle initial deposits and activations + # Process initial deposits for deposit in initial_validator_deposits: let validator_index = process_deposit( state, @@ -237,7 +255,7 @@ func get_initial_beacon_state*( deposit.deposit_data.deposit_input.proof_of_possession, deposit.deposit_data.deposit_input.withdrawal_credentials, deposit.deposit_data.deposit_input.randao_commitment, - flags + deposit.deposit_data.deposit_input.custody_commitment, ) if state.validator_balances[validator_index] >= MAX_DEPOSIT: update_validator_status(state, validator_index, ACTIVE) diff --git a/beacon_chain/spec/datatypes.nim b/beacon_chain/spec/datatypes.nim index 2a1d77244..21c5dd1b0 100644 --- a/beacon_chain/spec/datatypes.nim +++ b/beacon_chain/spec/datatypes.nim @@ -390,10 +390,15 @@ type exit_count*: uint64 ##\ ## Exit counter when validator exited (or 0) + status_flags*: uint64 + custody_commitment*: Eth2Digest - last_poc_change_slot*: uint64 - second_last_poc_change_slot*: uint64 + latest_custody_reseed_slot*: uint64 ##\ + ## Slot of latest custody reseed + + penultimate_custody_reseed_slot*: uint64 ##\ + ## Slot of second-latest custody reseed CrosslinkRecord* = object slot*: uint64 @@ -438,6 +443,7 @@ type latest_registry_delta_root*: Eth2Digest validator_index*: Uint24 pubkey*: ValidatorPubKey + slot*: uint64 flag*: ValidatorSetDeltaFlags ValidatorStatusCodes* {.pure.} = enum diff --git a/beacon_chain/spec/validator.nim b/beacon_chain/spec/validator.nim index 1aca2144b..809d46b57 100644 --- a/beacon_chain/spec/validator.nim +++ b/beacon_chain/spec/validator.nim @@ -68,6 +68,7 @@ func get_new_validator_registry_delta_chain_tip*( current_validator_registry_delta_chain_tip: Eth2Digest, index: Uint24, pubkey: ValidatorPubKey, + slot: uint64, flag: ValidatorSetDeltaFlags): Eth2Digest = ## Compute the next hash in the validator registry delta hash chain. @@ -75,5 +76,6 @@ func get_new_validator_registry_delta_chain_tip*( latest_registry_delta_root: current_validator_registry_delta_chain_tip, validator_index: index, pubkey: pubkey, + slot: slot, flag: flag )) diff --git a/beacon_chain/state_transition.nim b/beacon_chain/state_transition.nim index 263b56661..4883f2c41 100644 --- a/beacon_chain/state_transition.nim +++ b/beacon_chain/state_transition.nim @@ -101,7 +101,7 @@ func processRandao( return true func processDepositRoot(state: var BeaconState, blck: BeaconBlock) = - ## https://github.com/ethereum/eth2.0-specs/blob/master/specs/core/0_beacon-chain.md#pow-receipt-root + ## https://github.com/ethereum/eth2.0-specs/blob/master/specs/core/0_beacon-chain.md#deposit-root for x in state.deposit_roots.mitems(): if blck.deposit_root == x.deposit_root: @@ -264,6 +264,10 @@ proc processDeposits(state: var BeaconState, blck: BeaconBlock): bool = # TODO! Spec writing in progress true +func initiate_validator_exit(state: var BeaconState, index: int) = + var validator = state.validator_registry[index] + validator.status_flags = validator.status_flags or INITIATED_EXIT + proc processExits( state: var BeaconState, blck: BeaconBlock, flags: UpdateFlags): bool = ## https://github.com/ethereum/eth2.0-specs/blob/master/specs/core/0_beacon-chain.md#exits-1