2018-11-23 23:58:49 +00:00
|
|
|
import
|
2019-03-12 15:03:14 +00:00
|
|
|
tables,
|
2019-04-06 07:46:07 +00:00
|
|
|
chronos, chronicles,
|
|
|
|
spec/[datatypes, crypto, digest, helpers], ssz,
|
2019-03-12 15:03:14 +00:00
|
|
|
beacon_node_types
|
2018-11-23 23:58:49 +00:00
|
|
|
|
|
|
|
proc init*(T: type ValidatorPool): T =
|
2018-11-29 01:08:34 +00:00
|
|
|
result.validators = initTable[ValidatorPubKey, AttachedValidator]()
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
template count*(pool: ValidatorPool): int =
|
|
|
|
pool.validators.len
|
|
|
|
|
2018-11-23 23:58:49 +00:00
|
|
|
proc addLocalValidator*(pool: var ValidatorPool,
|
2019-10-03 01:51:44 +00:00
|
|
|
idx: ValidatorIndex,
|
2018-11-29 01:08:34 +00:00
|
|
|
pubKey: ValidatorPubKey,
|
2019-02-14 21:41:04 +00:00
|
|
|
privKey: ValidatorPrivKey) =
|
2019-10-03 01:51:44 +00:00
|
|
|
let v = AttachedValidator(idx: idx,
|
|
|
|
pubKey: pubKey,
|
2018-12-08 14:17:47 +00:00
|
|
|
kind: inProcess,
|
2019-02-14 21:41:04 +00:00
|
|
|
privKey: privKey)
|
2018-12-08 14:17:47 +00:00
|
|
|
pool.validators[pubKey] = v
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2019-04-06 07:46:07 +00:00
|
|
|
info "Local validator attached", pubKey, validator = shortLog(v)
|
|
|
|
|
2018-11-26 13:33:06 +00:00
|
|
|
proc getValidator*(pool: ValidatorPool,
|
2018-11-29 01:08:34 +00:00
|
|
|
validatorKey: ValidatorPubKey): AttachedValidator =
|
|
|
|
pool.validators.getOrDefault(validatorKey)
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2019-04-29 16:48:30 +00:00
|
|
|
proc signBlockProposal*(v: AttachedValidator, state: BeaconState, slot: Slot,
|
2019-04-06 07:46:07 +00:00
|
|
|
blockRoot: Eth2Digest): Future[ValidatorSig] {.async.} =
|
2019-10-07 02:34:45 +00:00
|
|
|
|
2018-11-29 01:08:34 +00:00
|
|
|
if v.kind == inProcess:
|
2019-10-07 02:34:45 +00:00
|
|
|
# TODO state might become invalid after any async calls - it's fragile to
|
|
|
|
# care about this in here
|
|
|
|
let
|
|
|
|
domain =
|
initial 0.9.0 spec sync (#509)
* rename compute_epoch_of_slot(...) to compute_epoch_at_slot(...)
* remove some unnecessary imports; remove some crosslink-related code and tests; complete renaming of compute_epoch_of_slot(...) to compute_epoch_at_slot(...)
* rm more transfer-related code and tests; rm more unnecessary strutils imports
* rm remaining unused imports
* remove useless get_empty_per_epoch_cache(...)/compute_start_slot_of_epoch(...) calls
* rename compute_start_slot_of_epoch(...) to compute_start_slot_at_epoch(...)
* rename ACTIVATION_EXIT_DELAY to MAX_SEED_LOOKAHEAD
* update domain types to 0.9.0
* mark AttesterSlashing, IndexedAttestation, AttestationDataAndCustodyBit, DepositData, BeaconBlockHeader, Fork, integer_squareroot(...), and process_voluntary_exit(...) as 0.9.0
* mark increase_balance(...), decrease_balance(...), get_block_root(...), CheckPoint, Deposit, PendingAttestation, HistoricalBatch, is_active_validator(...), and is_slashable_attestation_data(...) as 0.9.0
* mark compute_activation_exit_epoch(...), bls_verify(...), Validator, get_active_validator_indices(...), get_current_epoch(...), get_total_active_balance(...), and get_previous_epoch(...) as 0.9.0
* mark get_block_root_at_slot(...), ProposerSlashing, get_domain(...), VoluntaryExit, mainnet preset Gwei values, minimal preset max operations, process_block_header(...), and is_slashable_validator(...) as 0.9.0
* mark makeWithdrawalCredentials(...), get_validator_churn_limit(...), get_total_balance(...), is_valid_indexed_attestation(...), bls_aggregate_pubkeys(...), initial genesis value/constants, Attestation, get_randao_mix(...), mainnet preset max operations per block constants, minimal preset Gwei values and time parameters, process_eth1_data(...), get_shuffled_seq(...), compute_committee(...), and process_slots(...) as 0.9.0; partially update get_indexed_attestation(...) to 0.9.0 by removing crosslink refs and associated tests
* mark initiate_validator_exit(...), process_registry_updates(...), BeaconBlock, Eth1Data, compute_domain(...), process_randao(...), process_attester_slashing(...), get_base_reward(...), and process_slot(...) as 0.9.0
2019-10-30 19:41:19 +00:00
|
|
|
get_domain(state, DOMAIN_BEACON_PROPOSER, compute_epoch_at_slot(slot))
|
2019-09-08 22:35:13 +00:00
|
|
|
# TODO this is an ugly hack to fake a delay and subsequent async reordering
|
|
|
|
# for the purpose of testing the external validator delay - to be
|
|
|
|
# replaced by something more sensible
|
2019-03-29 14:45:38 +00:00
|
|
|
await sleepAsync(chronos.milliseconds(1))
|
2019-09-08 22:35:13 +00:00
|
|
|
|
|
|
|
result = bls_sign(v.privKey, blockRoot.data, domain)
|
2018-11-23 23:58:49 +00:00
|
|
|
else:
|
2019-09-08 18:27:09 +00:00
|
|
|
error "Unimplemented"
|
|
|
|
quit 1
|
2018-11-23 23:58:49 +00:00
|
|
|
|
|
|
|
proc signAttestation*(v: AttachedValidator,
|
2019-09-08 18:09:01 +00:00
|
|
|
attestation: AttestationData,
|
|
|
|
state: BeaconState): Future[ValidatorSig] {.async.} =
|
2018-11-29 01:08:34 +00:00
|
|
|
if v.kind == inProcess:
|
2019-09-08 22:35:13 +00:00
|
|
|
let
|
|
|
|
attestationRoot = hash_tree_root(
|
|
|
|
AttestationDataAndCustodyBit(data: attestation, custody_bit: false))
|
initial 0.9.0 spec sync (#509)
* rename compute_epoch_of_slot(...) to compute_epoch_at_slot(...)
* remove some unnecessary imports; remove some crosslink-related code and tests; complete renaming of compute_epoch_of_slot(...) to compute_epoch_at_slot(...)
* rm more transfer-related code and tests; rm more unnecessary strutils imports
* rm remaining unused imports
* remove useless get_empty_per_epoch_cache(...)/compute_start_slot_of_epoch(...) calls
* rename compute_start_slot_of_epoch(...) to compute_start_slot_at_epoch(...)
* rename ACTIVATION_EXIT_DELAY to MAX_SEED_LOOKAHEAD
* update domain types to 0.9.0
* mark AttesterSlashing, IndexedAttestation, AttestationDataAndCustodyBit, DepositData, BeaconBlockHeader, Fork, integer_squareroot(...), and process_voluntary_exit(...) as 0.9.0
* mark increase_balance(...), decrease_balance(...), get_block_root(...), CheckPoint, Deposit, PendingAttestation, HistoricalBatch, is_active_validator(...), and is_slashable_attestation_data(...) as 0.9.0
* mark compute_activation_exit_epoch(...), bls_verify(...), Validator, get_active_validator_indices(...), get_current_epoch(...), get_total_active_balance(...), and get_previous_epoch(...) as 0.9.0
* mark get_block_root_at_slot(...), ProposerSlashing, get_domain(...), VoluntaryExit, mainnet preset Gwei values, minimal preset max operations, process_block_header(...), and is_slashable_validator(...) as 0.9.0
* mark makeWithdrawalCredentials(...), get_validator_churn_limit(...), get_total_balance(...), is_valid_indexed_attestation(...), bls_aggregate_pubkeys(...), initial genesis value/constants, Attestation, get_randao_mix(...), mainnet preset max operations per block constants, minimal preset Gwei values and time parameters, process_eth1_data(...), get_shuffled_seq(...), compute_committee(...), and process_slots(...) as 0.9.0; partially update get_indexed_attestation(...) to 0.9.0 by removing crosslink refs and associated tests
* mark initiate_validator_exit(...), process_registry_updates(...), BeaconBlock, Eth1Data, compute_domain(...), process_randao(...), process_attester_slashing(...), get_base_reward(...), and process_slot(...) as 0.9.0
2019-10-30 19:41:19 +00:00
|
|
|
domain = get_domain(state, DOMAIN_BEACON_ATTESTER, attestation.target.epoch)
|
2019-09-08 22:35:13 +00:00
|
|
|
|
2019-10-07 02:34:45 +00:00
|
|
|
# TODO this is an ugly hack to fake a delay and subsequent async reordering
|
|
|
|
# for the purpose of testing the external validator delay - to be
|
|
|
|
# replaced by something more sensible
|
|
|
|
await sleepAsync(chronos.milliseconds(1))
|
|
|
|
|
2019-09-08 22:35:13 +00:00
|
|
|
result = bls_sign(v.privKey, attestationRoot.data, domain)
|
2018-11-23 23:58:49 +00:00
|
|
|
else:
|
2019-09-08 18:27:09 +00:00
|
|
|
error "Unimplemented"
|
|
|
|
quit 1
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2019-02-20 01:33:58 +00:00
|
|
|
func genRandaoReveal*(k: ValidatorPrivKey, state: BeaconState, slot: Slot):
|
2019-02-07 20:13:10 +00:00
|
|
|
ValidatorSig =
|
2019-09-08 22:35:13 +00:00
|
|
|
let
|
initial 0.9.0 spec sync (#509)
* rename compute_epoch_of_slot(...) to compute_epoch_at_slot(...)
* remove some unnecessary imports; remove some crosslink-related code and tests; complete renaming of compute_epoch_of_slot(...) to compute_epoch_at_slot(...)
* rm more transfer-related code and tests; rm more unnecessary strutils imports
* rm remaining unused imports
* remove useless get_empty_per_epoch_cache(...)/compute_start_slot_of_epoch(...) calls
* rename compute_start_slot_of_epoch(...) to compute_start_slot_at_epoch(...)
* rename ACTIVATION_EXIT_DELAY to MAX_SEED_LOOKAHEAD
* update domain types to 0.9.0
* mark AttesterSlashing, IndexedAttestation, AttestationDataAndCustodyBit, DepositData, BeaconBlockHeader, Fork, integer_squareroot(...), and process_voluntary_exit(...) as 0.9.0
* mark increase_balance(...), decrease_balance(...), get_block_root(...), CheckPoint, Deposit, PendingAttestation, HistoricalBatch, is_active_validator(...), and is_slashable_attestation_data(...) as 0.9.0
* mark compute_activation_exit_epoch(...), bls_verify(...), Validator, get_active_validator_indices(...), get_current_epoch(...), get_total_active_balance(...), and get_previous_epoch(...) as 0.9.0
* mark get_block_root_at_slot(...), ProposerSlashing, get_domain(...), VoluntaryExit, mainnet preset Gwei values, minimal preset max operations, process_block_header(...), and is_slashable_validator(...) as 0.9.0
* mark makeWithdrawalCredentials(...), get_validator_churn_limit(...), get_total_balance(...), is_valid_indexed_attestation(...), bls_aggregate_pubkeys(...), initial genesis value/constants, Attestation, get_randao_mix(...), mainnet preset max operations per block constants, minimal preset Gwei values and time parameters, process_eth1_data(...), get_shuffled_seq(...), compute_committee(...), and process_slots(...) as 0.9.0; partially update get_indexed_attestation(...) to 0.9.0 by removing crosslink refs and associated tests
* mark initiate_validator_exit(...), process_registry_updates(...), BeaconBlock, Eth1Data, compute_domain(...), process_randao(...), process_attester_slashing(...), get_base_reward(...), and process_slot(...) as 0.9.0
2019-10-30 19:41:19 +00:00
|
|
|
domain = get_domain(state, DOMAIN_RANDAO, compute_epoch_at_slot(slot))
|
|
|
|
root = hash_tree_root(compute_epoch_at_slot(slot).uint64).data
|
2019-09-08 22:35:13 +00:00
|
|
|
|
|
|
|
bls_sign(k, root, domain)
|
2019-02-07 20:13:10 +00:00
|
|
|
|
2019-02-20 01:33:58 +00:00
|
|
|
func genRandaoReveal*(v: AttachedValidator, state: BeaconState, slot: Slot):
|
2019-02-07 20:13:10 +00:00
|
|
|
ValidatorSig =
|
2019-02-14 21:41:04 +00:00
|
|
|
genRandaoReveal(v.privKey, state, slot)
|