diff --git a/beacon_chain/spec/beaconstate.nim b/beacon_chain/spec/beaconstate.nim index 03635cbf9..e9dc57b55 100644 --- a/beacon_chain/spec/beaconstate.nim +++ b/beacon_chain/spec/beaconstate.nim @@ -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, diff --git a/beacon_chain/spec/datatypes.nim b/beacon_chain/spec/datatypes.nim index a34afc008..cedde1aca 100644 --- a/beacon_chain/spec/datatypes.nim +++ b/beacon_chain/spec/datatypes.nim @@ -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 ##\ diff --git a/beacon_chain/spec/helpers.nim b/beacon_chain/spec/helpers.nim index 26745a88b..92089669d 100644 --- a/beacon_chain/spec/helpers.nim +++ b/beacon_chain/spec/helpers.nim @@ -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): diff --git a/beacon_chain/spec/validator.nim b/beacon_chain/spec/validator.nim index 809d46b57..341128a1e 100644 --- a/beacon_chain/spec/validator.nim +++ b/beacon_chain/spec/validator.nim @@ -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, diff --git a/beacon_chain/sync_protocol.nim b/beacon_chain/sync_protocol.nim index aca03d510..df220ab86 100644 --- a/beacon_chain/sync_protocol.nim +++ b/beacon_chain/sync_protocol.nim @@ -11,7 +11,7 @@ type else: index: uint32 - ValidatorSet = seq[ValidatorRecord] + ValidatorSet = seq[Validator] p2pProtocol BeaconSync(version = 1, shortName = "bcs"): diff --git a/beacon_chain/trusted_state_snapshots.nim b/beacon_chain/trusted_state_snapshots.nim index c6ed9fcf2..7ef73160e 100644 --- a/beacon_chain/trusted_state_snapshots.nim +++ b/beacon_chain/trusted_state_snapshots.nim @@ -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 diff --git a/research/sereth.nim b/research/sereth.nim index 1c970944a..84d07adcc 100644 --- a/research/sereth.nim +++ b/research/sereth.nim @@ -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"), diff --git a/tests/test_ssz.nim b/tests/test_ssz.nim index e99d8c17e..58248061f 100644 --- a/tests/test_ssz.nim +++ b/tests/test_ssz.nim @@ -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": diff --git a/tests/test_validator.nim b/tests/test_validator.nim index 89a3808e9..f6283895a 100644 --- a/tests/test_validator.nim +++ b/tests/test_validator.nim @@ -20,7 +20,7 @@ suite "Validators": test "Smoke validator shuffling": let validators = repeat( - ValidatorRecord( + Validator( status: ACTIVE ), 32*1024) diff --git a/tests/testutil.nim b/tests/testutil.nim index d8bda6668..568d35232 100644 --- a/tests/testutil.nim +++ b/tests/testutil.nim @@ -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)