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:
# Add new validator
let validator = ValidatorRecord(
let validator = Validator(
status: UNUSED,
pubkey: pubkey,
withdrawal_credentials: withdrawal_credentials,

View File

@ -309,7 +309,7 @@ type
## For versioning hard forks
# Validator registry
validator_registry*: seq[ValidatorRecord]
validator_registry*: seq[Validator]
validator_balances*: seq[uint64] ##\
## Validator balances in Gwei!
@ -359,7 +359,7 @@ type
latest_deposit_root*: Eth2Digest
deposit_roots*: seq[DepositRootVote]
ValidatorRecord* = object
Validator* = object
pubkey*: ValidatorPubKey
withdrawal_credentials*: 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)
)
#func is_active_validator*(validator: ValidatorRecord, slot: uint64): bool =
#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: ValidatorRecord): bool =
func is_active_validator*(validator: Validator): bool =
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
for idx, val in validators:
#if is_active_validator(val, slot):

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@ import
eth_common, stint, nimcrypto, byteutils
type
ValidatorRecord {.packed.} = object
Validator {.packed.} = object
# The validator's public key
pubkey: Uint256
# 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
when isMainModule:
let x = ValidatorRecord(
let x = Validator(
pubkey: high(Uint256), # 0xFFFF...FFFF
withdrawal_shard: 4455,
withdrawal_address: hexToPaddedByteArray[20]("0x1234"),

View File

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

View File

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

View File

@ -20,7 +20,7 @@ func makeValidatorPrivKey(i: int): ValidatorPrivKey =
func makeFakeHash*(i: int): Eth2Digest =
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
var i: int
copyMem(
@ -28,7 +28,7 @@ func hackPrivKey(v: ValidatorRecord): ValidatorPrivKey =
min(sizeof(v.withdrawal_credentials.data), sizeof(i)))
makeValidatorPrivKey(i)
func hackReveal(v: ValidatorRecord): Eth2Digest =
func hackReveal(v: Validator): Eth2Digest =
result = v.withdrawal_credentials
for i in 0..randaoRounds:
let tmp = repeat_hash(result, 1)