nimbus-eth2/beacon_chain/validator_pool.nim

64 lines
2.3 KiB
Nim
Raw Normal View History

import
tables,
chronos, chronicles,
spec/[datatypes, crypto, digest, state_transition_block], ssz,
beacon_node_types
func init*(T: type ValidatorPool): T =
2018-11-29 01:08:34 +00:00
result.validators = initTable[ValidatorPubKey, AttachedValidator]()
template count*(pool: ValidatorPool): int =
pool.validators.len
proc addLocalValidator*(pool: var ValidatorPool,
2018-11-29 01:08:34 +00:00
pubKey: ValidatorPubKey,
privKey: ValidatorPrivKey) =
let v = AttachedValidator(pubKey: pubKey,
2018-12-08 14:17:47 +00:00
kind: inProcess,
privKey: privKey)
2018-12-08 14:17:47 +00:00
pool.validators[pubKey] = v
info "Local validator attached", pubKey, validator = shortLog(v)
func getValidator*(pool: ValidatorPool,
2018-11-29 01:08:34 +00:00
validatorKey: ValidatorPubKey): AttachedValidator =
pool.validators.getOrDefault(validatorKey)
2020-03-04 21:27:11 +00:00
# TODO: Honest validator - https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/validator.md
proc signBlockProposal*(v: AttachedValidator, fork: Fork, slot: Slot,
blockRoot: Eth2Digest): Future[ValidatorSig] {.async.} =
2018-11-29 01:08:34 +00:00
if v.kind == inProcess:
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 = get_block_signature(fork, slot, blockRoot, v.privKey)
else:
2019-09-08 18:27:09 +00:00
error "Unimplemented"
quit 1
proc signAttestation*(v: AttachedValidator,
attestation: AttestationData,
fork: Fork): Future[ValidatorSig] {.async.} =
2018-11-29 01:08:34 +00:00
if v.kind == inProcess:
# 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))
result = get_attestation_signature(fork, attestation, v.privKey)
else:
2019-09-08 18:27:09 +00:00
error "Unimplemented"
quit 1
2020-03-04 21:27:11 +00:00
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/validator.md#randao-reveal
func genRandaoReveal*(k: ValidatorPrivKey, fork: Fork, slot: Slot):
ValidatorSig =
get_epoch_signature(fork, slot, k)
func genRandaoReveal*(v: AttachedValidator, fork: Fork, slot: Slot):
ValidatorSig =
genRandaoReveal(v.privKey, fork, slot)