ValidatorRecord -> Validator

This commit is contained in:
Dustin Brody 2019-01-17 10:27:11 -08:00 committed by zah
parent 38c2cc72fa
commit f30b4f822e
10 changed files with 18 additions and 18 deletions

View File

@ -65,7 +65,7 @@ func process_deposit(state: var BeaconState,
if pubkey notin validator_pubkeys: if pubkey notin validator_pubkeys:
# Add new validator # Add new validator
let validator = ValidatorRecord( let validator = Validator(
status: UNUSED, status: UNUSED,
pubkey: pubkey, pubkey: pubkey,
withdrawal_credentials: withdrawal_credentials, withdrawal_credentials: withdrawal_credentials,

View File

@ -309,7 +309,7 @@ type
## For versioning hard forks ## For versioning hard forks
# Validator registry # Validator registry
validator_registry*: seq[ValidatorRecord] validator_registry*: seq[Validator]
validator_balances*: seq[uint64] ##\ validator_balances*: seq[uint64] ##\
## Validator balances in Gwei! ## Validator balances in Gwei!
@ -359,7 +359,7 @@ type
latest_deposit_root*: Eth2Digest latest_deposit_root*: Eth2Digest
deposit_roots*: seq[DepositRootVote] deposit_roots*: seq[DepositRootVote]
ValidatorRecord* = object Validator* = object
pubkey*: ValidatorPubKey pubkey*: ValidatorPubKey
withdrawal_credentials*: Eth2Digest withdrawal_credentials*: Eth2Digest
randao_commitment*: Eth2Digest ##\ randao_commitment*: Eth2Digest ##\

View File

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

View File

@ -13,7 +13,7 @@ import
./crypto, ./datatypes, ./digest, ./helpers ./crypto, ./datatypes, ./digest, ./helpers
func min_empty_validator_index*( func min_empty_validator_index*(
validators: seq[ValidatorRecord], validators: seq[Validator],
validator_balances: seq[uint64], validator_balances: seq[uint64],
current_slot: uint64): Option[int] = current_slot: uint64): Option[int] =
for i, v in validators: for i, v in validators:
@ -22,14 +22,14 @@ func min_empty_validator_index*(
ZERO_BALANCE_VALIDATOR_TTL.uint64 <= current_slot: ZERO_BALANCE_VALIDATOR_TTL.uint64 <= current_slot:
return some(i) return some(i)
func get_active_validator_indices*(validators: openArray[ValidatorRecord]): seq[Uint24] = func get_active_validator_indices*(validators: openArray[Validator]): seq[Uint24] =
## Select the active validators ## Select the active validators
for idx, val in validators: for idx, val in validators:
if is_active_validator(val): if is_active_validator(val):
result.add idx.Uint24 result.add idx.Uint24
func get_shuffling*(seed: Eth2Digest, func get_shuffling*(seed: Eth2Digest,
validators: openArray[ValidatorRecord], validators: openArray[Validator],
crosslinking_start_shard: uint64 crosslinking_start_shard: uint64
): array[EPOCH_LENGTH, seq[ShardCommittee]] = ): array[EPOCH_LENGTH, seq[ShardCommittee]] =
## Split up validators into groups at the start of every epoch, ## Split up validators into groups at the start of every epoch,

View File

@ -11,7 +11,7 @@ type
else: else:
index: uint32 index: uint32
ValidatorSet = seq[ValidatorRecord] ValidatorSet = seq[Validator]
p2pProtocol BeaconSync(version = 1, p2pProtocol BeaconSync(version = 1,
shortName = "bcs"): shortName = "bcs"):

View File

@ -34,7 +34,7 @@ proc createStateSnapshot*(startup: ChainStartupData, outFile: string) =
startup.genesisTime, startup.genesisTime,
Eth2Digest(), {}) Eth2Digest(), {})
var vr: ValidatorRecord var vr: Validator
Json.saveFile(outFile, initialState, pretty = true) Json.saveFile(outFile, initialState, pretty = true)
echo "Wrote ", outFile echo "Wrote ", outFile

View File

@ -3,7 +3,7 @@ import
eth_common, stint, nimcrypto, byteutils eth_common, stint, nimcrypto, byteutils
type type
ValidatorRecord {.packed.} = object Validator {.packed.} = object
# The validator's public key # The validator's public key
pubkey: Uint256 pubkey: Uint256
# What shard the validator's balance will be sent to # What shard the validator's balance will be sent to
@ -111,7 +111,7 @@ proc serializeETH[T](x: T): seq[byte] =
echo "Total size (bytes): " & $result.len echo "Total size (bytes): " & $result.len
when isMainModule: when isMainModule:
let x = ValidatorRecord( let x = Validator(
pubkey: high(Uint256), # 0xFFFF...FFFF pubkey: high(Uint256), # 0xFFFF...FFFF
withdrawal_shard: 4455, withdrawal_shard: 4455,
withdrawal_address: hexToPaddedByteArray[20]("0x1234"), withdrawal_address: hexToPaddedByteArray[20]("0x1234"),

View File

@ -105,8 +105,8 @@ suite "Simple serialization":
suite "Tree hashing": suite "Tree hashing":
# TODO Nothing but smoke tests for now.. # TODO Nothing but smoke tests for now..
test "Hash ValidatorRecord": test "Hash Validator":
let vr = ValidatorRecord() let vr = Validator()
check: hash_tree_root(vr).len > 0 check: hash_tree_root(vr).len > 0
test "Hash ShardCommittee": test "Hash ShardCommittee":

View File

@ -20,7 +20,7 @@ suite "Validators":
test "Smoke validator shuffling": test "Smoke validator shuffling":
let let
validators = repeat( validators = repeat(
ValidatorRecord( Validator(
status: ACTIVE status: ACTIVE
), 32*1024) ), 32*1024)

View File

@ -20,7 +20,7 @@ func makeValidatorPrivKey(i: int): ValidatorPrivKey =
func makeFakeHash*(i: int): Eth2Digest = func makeFakeHash*(i: int): Eth2Digest =
copyMem(result.data[0].addr, i.unsafeAddr, min(sizeof(result.data), sizeof(i))) copyMem(result.data[0].addr, i.unsafeAddr, min(sizeof(result.data), sizeof(i)))
func hackPrivKey(v: ValidatorRecord): ValidatorPrivKey = func hackPrivKey(v: Validator): ValidatorPrivKey =
## Extract private key, per above hack ## Extract private key, per above hack
var i: int var i: int
copyMem( copyMem(
@ -28,7 +28,7 @@ func hackPrivKey(v: ValidatorRecord): ValidatorPrivKey =
min(sizeof(v.withdrawal_credentials.data), sizeof(i))) min(sizeof(v.withdrawal_credentials.data), sizeof(i)))
makeValidatorPrivKey(i) makeValidatorPrivKey(i)
func hackReveal(v: ValidatorRecord): Eth2Digest = func hackReveal(v: Validator): Eth2Digest =
result = v.withdrawal_credentials result = v.withdrawal_credentials
for i in 0..randaoRounds: for i in 0..randaoRounds:
let tmp = repeat_hash(result, 1) let tmp = repeat_hash(result, 1)