Spec updates (#64)

* s/CrosslinkRecord/Crosslink/

* {MIN,MAX}_DEPOSIT to {MIN,MAX}_DEPOSIT_AMOUNT; rm SHARD_PERSISTENT_COMMITTEE_CHANGE_PERIOD; per https://github.com/ethereum/eth2.0-specs/issues/378 and 35adc9c61a rm persistent_committees, persistent_committee_reassignments, and ShardReassignmentRecord

* complete switchover from status/ValidatorStatusCodes to status_flags/INITIATED_EXIT/WITHDRAWABLE validator representation
This commit is contained in:
Dustin Brody 2019-01-21 18:26:58 +00:00 committed by Mamy Ratsimbazafy
parent 8606a47094
commit eed9ea8f0a
7 changed files with 19 additions and 79 deletions

View File

@ -15,7 +15,7 @@ func get_effective_balance*(state: BeaconState, index: Uint24): uint64 =
# influence. Validators may also lose balance if they fail to do their duty
# in which case their influence decreases. Once they drop below a certain
# balance, they're removed from the validator registry.
min(state.validator_balances[index], MAX_DEPOSIT * GWEI_PER_ETH)
min(state.validator_balances[index], MAX_DEPOSIT_AMOUNT)
func sum_effective_balances*(
state: BeaconState, validator_indices: openArray[Uint24]): uint64 =
@ -66,7 +66,6 @@ func process_deposit(state: var BeaconState,
if pubkey notin validator_pubkeys:
# Add new validator
let validator = Validator(
status: UNUSED,
pubkey: pubkey,
withdrawal_credentials: withdrawal_credentials,
randao_commitment: randao_commitment,
@ -108,7 +107,6 @@ func activate_validator(state: var BeaconState,
## Activate the validator with the given ``index``.
let validator = addr state.validator_registry[index]
validator.status = ACTIVE
validator.activation_slot = if genesis: GENESIS_SLOT else: state.slot + ENTRY_EXIT_DELAY
state.validator_registry_delta_chain_tip =
get_new_validator_registry_delta_chain_tip(
@ -253,14 +251,14 @@ func get_initial_beacon_state*(
deposit.deposit_data.deposit_input.custody_commitment,
)
if state.validator_balances[validator_index] >= MAX_DEPOSIT:
if state.validator_balances[validator_index] >= MAX_DEPOSIT_AMOUNT:
activate_validator(state, validator_index, true)
# Process initial activations
#for validator_index in 0 ..< state.validator_registry.len:
# let vi = validator_index.Uint24
# if get_effective_balance(state, vi) > MAX_DEPOSIT * GWEI_PER_ETH:
# activate_validator(state, vi, true)
for validator_index in 0 ..< state.validator_registry.len:
let vi = validator_index.Uint24
if get_effective_balance(state, vi) > MAX_DEPOSIT_AMOUNT:
activate_validator(state, vi, true)
# set initial committee shuffling
let
@ -272,13 +270,6 @@ func get_initial_beacon_state*(
state.shard_committees_at_slots[i] = n
state.shard_committees_at_slots[EPOCH_LENGTH + i] = n
# set initial persistent shuffling
let active_validator_indices =
get_active_validator_indices(state.validator_registry, state.slot)
state.persistent_committees = split(shuffle(
active_validator_indices, ZERO_HASH), SHARD_COUNT)
state
func get_block_root*(state: BeaconState,
@ -336,7 +327,7 @@ func update_validator_registry*(state: var BeaconState) =
# The maximum balance churn in Gwei (for deposits and exits separately)
max_balance_churn = max(
MAX_DEPOSIT * GWEI_PER_ETH,
MAX_DEPOSIT_AMOUNT,
total_balance div (2 * MAX_BALANCE_CHURN_QUOTIENT)
)
@ -344,7 +335,7 @@ func update_validator_registry*(state: var BeaconState) =
var balance_churn = 0'u64
for index, validator in state.validator_registry:
if validator.activation_slot > state.slot + ENTRY_EXIT_DELAY and
state.validator_balances[index] >= MAX_DEPOSIT * GWEI_PER_ETH:
state.validator_balances[index] >= MAX_DEPOSIT_AMOUNT:
# Check the balance churn would be within the allowance
balance_churn += get_effective_balance(state, index.Uint24)
if balance_churn > max_balance_churn:

View File

@ -83,10 +83,10 @@ const
# Deposit contract
DEPOSIT_CONTRACT_TREE_DEPTH* = 2^5
MIN_DEPOSIT* = 2'u64^0 ##\
MIN_DEPOSIT_AMOUNT* = 2'u64^0 * GWEI_PER_ETH ##\
## Minimum amounth of ETH that can be deposited in one call - deposits can
## be used either to top up an existing validator or commit to a new one
MAX_DEPOSIT* = 2'u64^5 ##\
MAX_DEPOSIT_AMOUNT* = 2'u64^5 * GWEI_PER_ETH ##\
## Maximum amounth of ETH that can be deposited in one call
# Initial values
@ -126,9 +126,6 @@ const
SEED_LOOKAHEAD* = 64 ##\
## slots (~6.4 minutes)
SHARD_PERSISTENT_COMMITTEE_CHANGE_PERIOD* = 2'u64^17 ##\
## slots (~9 days)
ENTRY_EXIT_DELAY* = 256 ##\
## slots (~25.6 minutes)
@ -331,9 +328,7 @@ type
previous_epoch_randao_mix*: Eth2Digest
current_epoch_randao_mix*: Eth2Digest
persistent_committees*: seq[seq[Uint24]]
persistent_committee_reassignments*: seq[ShardReassignmentRecord]
# Custody challenges
custody_challenges*: seq[CustodyChallenge]
# Finality
@ -343,7 +338,7 @@ type
finalized_slot*: uint64
# Recent state
latest_crosslinks*: array[SHARD_COUNT, CrosslinkRecord]
latest_crosslinks*: array[SHARD_COUNT, Crosslink]
latest_block_roots*: array[LATEST_BLOCK_ROOTS_LENGTH.int, Eth2Digest] ##\
## Needed to process attestations, older to newer
@ -371,7 +366,6 @@ type
## Number of proposals the proposer missed, and thus the number of times to
## apply hash function to randao reveal
status*: ValidatorStatusCodes
latest_status_change_slot*: uint64 ##\
## Slot when validator last changed status (or 0)
@ -400,7 +394,7 @@ type
penultimate_custody_reseed_slot*: uint64 ##\
## Slot of second-latest custody reseed
CrosslinkRecord* = object
Crosslink* = object
slot*: uint64
shard_block_root*: Eth2Digest ##\
## Shard chain block root
@ -414,16 +408,6 @@ type
total_validator_count*: uint64 ##\
## Total validator count (for proofs of custody)
ShardReassignmentRecord* = object
validator_index*: Uint24 ##\
## Which validator to reassign
shard*: uint64 ##\
## To which shard
slot*: uint64 ##\
## When
Eth1Data* = object
deposit_root*: Eth2Digest ##\
## Data being voted for
@ -453,10 +437,6 @@ type
slot*: uint64
flag*: ValidatorSetDeltaFlags
ValidatorStatusCodes* {.pure.} = enum
UNUSED = 0
ACTIVE = 1
ValidatorSetDeltaFlags* {.pure.} = enum
Activation = 0
Exit = 1

View File

@ -181,12 +181,9 @@ proc is_surround_vote*(attestation_data_1: AttestationData,
(attestation_data_2.slot < attestation_data_1.slot)
)
#func is_active_validator*(validator: Validator, slot: uint64): bool =
# ### Checks if validator is active
# validator.activation_slot <= slot and slot < validator.exit_slot
func is_active_validator*(validator: Validator, slot: uint64): bool =
validator.status == ACTIVE
### Checks if validator is active
validator.activation_slot <= slot and slot < validator.exit_slot
func get_active_validator_indices*(validators: openArray[Validator], slot: uint64): seq[Uint24] =
## Gets indices of active validators from validators

View File

@ -615,7 +615,7 @@ func processEpoch(state: var BeaconState) =
for shard_committee in sac:
if 3'u64 * total_attesting_balance(shard_committee) >=
2'u64 * total_balance_sac(shard_committee):
state.latest_crosslinks[shard_committee.shard] = CrosslinkRecord(
state.latest_crosslinks[shard_committee.shard] = Crosslink(
slot: state.slot + EPOCH_LENGTH,
shard_block_root: winning_root(shard_committee))
@ -733,34 +733,6 @@ func processEpoch(state: var BeaconState) =
state.shard_committees_at_slots[i + EPOCH_LENGTH] = v
# Note that `start_shard` is not changed from the last epoch.
block: # Proposer reshuffling
let num_validators_to_reshuffle =
len(active_validator_indices) div
SHARD_PERSISTENT_COMMITTEE_CHANGE_PERIOD.int
for i in 0..<num_validators_to_reshuffle:
# Multiplying i to 2 to ensure we have different input to all the required hashes in the shuffling
# and none of the hashes used for entropy in this loop will be the same
# TODO Modulo of hash value.. hm...
let
validator_index = 0.Uint24 # TODO active_validator_indices[hash(state.latest_randao_mixes[state.slot % LATEST_RANDAO_MIXES_LENGTH] + bytes8(i * 2)) % len(active_validator_indices)]
new_shard = 0'u64 # TODO hash(state.randao_mix + bytes8(i * 2 + 1)) mod SHARD_COUNT
shard_reassignment_record = ShardReassignmentRecord(
validator_index: validator_index,
shard: new_shard,
slot: state.slot + SHARD_PERSISTENT_COMMITTEE_CHANGE_PERIOD
)
state.persistent_committee_reassignments.add(shard_reassignment_record)
while len(state.persistent_committee_reassignments) > 0 and
state.persistent_committee_reassignments[0].slot <= state.slot:
let reassignment = state.persistent_committee_reassignments[0]
state.persistent_committee_reassignments.delete(0)
for committee in state.persistent_committees.mitems():
if reassignment.validator_index in committee:
committee.delete(committee.find(reassignment.validator_index))
state.persistent_committees[reassignment.shard.int].add(
reassignment.validator_index)
block: # Final updates
state.latest_attestations.keepItIf(
not (it.data.slot + EPOCH_LENGTH < state.slot)

View File

@ -63,7 +63,7 @@ proc main() =
startupData.validatorDeposits.add Deposit(
deposit_data: DepositData(
amount: MAX_DEPOSIT * GWEI_PER_ETH,
amount: MAX_DEPOSIT_AMOUNT,
timestamp: now(),
deposit_input: DepositInput(
pubkey: pubKey,

View File

@ -21,7 +21,7 @@ suite "Validators":
let
validators = repeat(
Validator(
status: ACTIVE
exit_slot: FAR_FUTURE_SLOT
), 32*1024)
# TODO the shuffling looks really odd, probably buggy

View File

@ -67,7 +67,7 @@ func makeDeposit(i: int, flags: UpdateFlags): Deposit =
withdrawal_credentials: withdrawal_credentials,
randao_commitment: randao_commitment
),
amount: MAX_DEPOSIT * GWEI_PER_ETH,
amount: MAX_DEPOSIT_AMOUNT,
)
)