2018-11-23 23:58:49 +00:00
|
|
|
import
|
|
|
|
tables, random,
|
|
|
|
asyncdispatch2,
|
2018-11-29 01:08:34 +00:00
|
|
|
spec/[datatypes, crypto]
|
2018-11-23 23:58:49 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
ValidatorKind = enum
|
|
|
|
inProcess
|
|
|
|
remote
|
|
|
|
|
|
|
|
ValidatorConnection = object
|
|
|
|
|
2018-11-29 01:08:34 +00:00
|
|
|
RandaoSecret = seq[byte]
|
2018-11-23 23:58:49 +00:00
|
|
|
|
|
|
|
AttachedValidator* = ref object
|
2018-11-26 13:33:06 +00:00
|
|
|
idx*: int
|
2018-11-23 23:58:49 +00:00
|
|
|
case kind: ValidatorKind
|
|
|
|
of inProcess:
|
2018-11-29 01:08:34 +00:00
|
|
|
privKey: ValidatorPrivKey
|
|
|
|
randaoSecret: RandaoSecret
|
2018-11-23 23:58:49 +00:00
|
|
|
else:
|
|
|
|
connection: ValidatorConnection
|
|
|
|
|
|
|
|
ValidatorPool* = object
|
2018-11-29 01:08:34 +00:00
|
|
|
validators: Table[ValidatorPubKey, AttachedValidator]
|
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
|
|
|
|
|
|
|
proc addLocalValidator*(pool: var ValidatorPool,
|
2018-11-29 01:08:34 +00:00
|
|
|
idx: int,
|
|
|
|
pubKey: ValidatorPubKey,
|
|
|
|
privKey: ValidatorPrivKey,
|
|
|
|
randaoSecret: RandaoSecret) =
|
|
|
|
pool.validators[pubKey] = AttachedValidator(idx: idx,
|
|
|
|
kind: inProcess,
|
|
|
|
privKey: privKey,
|
|
|
|
randaoSecret: randaoSecret)
|
2018-11-23 23:58:49 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
proc signBlockProposal*(v: AttachedValidator,
|
2018-11-29 01:08:34 +00:00
|
|
|
proposal: ProposalSignedData): Future[ValidatorSig] {.async.} =
|
|
|
|
if v.kind == inProcess:
|
2018-11-23 23:58:49 +00:00
|
|
|
await sleepAsync(1)
|
|
|
|
# TODO:
|
|
|
|
# return sign(proposal, v.privKey)
|
|
|
|
else:
|
|
|
|
# TODO:
|
|
|
|
# send RPC
|
|
|
|
discard
|
|
|
|
|
|
|
|
proc signAttestation*(v: AttachedValidator,
|
2018-11-29 01:08:34 +00:00
|
|
|
attestation: AttestationSignedData): Future[ValidatorSig] {.async.} =
|
2018-11-23 23:58:49 +00:00
|
|
|
# TODO: implement this
|
2018-11-29 01:08:34 +00:00
|
|
|
if v.kind == inProcess:
|
2018-11-23 23:58:49 +00:00
|
|
|
await sleepAsync(1)
|
|
|
|
# TODO:
|
|
|
|
# return sign(proposal, v.privKey)
|
|
|
|
else:
|
|
|
|
# TODO:
|
|
|
|
# send RPC
|
|
|
|
discard
|
|
|
|
|