2022-06-09 08:50:36 +00:00
|
|
|
# beacon_chain
|
|
|
|
# Copyright (c) 2021-2022 Status Research & Development GmbH
|
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2021-08-12 13:08:20 +00:00
|
|
|
import
|
2022-09-29 07:57:14 +00:00
|
|
|
std/[tables, os, sets, sequtils, strutils, uri],
|
2022-08-19 10:30:07 +00:00
|
|
|
stew/[base10, results, byteutils],
|
|
|
|
bearssl/rand, chronos, presto, presto/client as presto_client,
|
|
|
|
chronicles, confutils, json_serialization/std/[options, net],
|
|
|
|
metrics, metrics/chronos_httpserver,
|
|
|
|
".."/spec/datatypes/[phase0, altair],
|
|
|
|
".."/spec/[eth2_merkleization, helpers, signatures, validator],
|
2022-10-21 14:53:30 +00:00
|
|
|
".."/spec/eth2_apis/[eth2_rest_serialization, rest_beacon_client,
|
|
|
|
dynamic_fee_recipients],
|
2022-08-19 10:30:07 +00:00
|
|
|
".."/validators/[keystore_management, validator_pool, slashing_protection],
|
|
|
|
".."/[conf, beacon_clock, version, nimbus_binary_common]
|
|
|
|
|
2022-10-29 09:00:51 +00:00
|
|
|
from std/times import Time, toUnix, fromUnix, getTime
|
|
|
|
|
2022-08-19 10:30:07 +00:00
|
|
|
export
|
|
|
|
os, sets, sequtils, chronos, presto, chronicles, confutils,
|
|
|
|
nimbus_binary_common, version, conf, options, tables, results, base10,
|
|
|
|
byteutils, presto_client, eth2_rest_serialization, rest_beacon_client,
|
|
|
|
phase0, altair, helpers, signatures, validator, eth2_merkleization,
|
2022-10-21 14:53:30 +00:00
|
|
|
beacon_clock, keystore_management, slashing_protection, validator_pool,
|
2022-10-29 09:00:51 +00:00
|
|
|
dynamic_fee_recipients, Time, toUnix, fromUnix, getTime
|
2021-07-13 11:15:07 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
SYNC_TOLERANCE* = 4'u64
|
|
|
|
SLOT_LOOKAHEAD* = 1.seconds
|
|
|
|
HISTORICAL_DUTIES_EPOCHS* = 2'u64
|
|
|
|
TIME_DELAY_FROM_SLOT* = 79.milliseconds
|
|
|
|
SUBSCRIPTION_BUFFER_SLOTS* = 2'u64
|
2022-10-29 09:00:51 +00:00
|
|
|
EPOCHS_BETWEEN_VALIDATOR_REGISTRATION* = 1
|
2021-07-13 11:15:07 +00:00
|
|
|
|
2022-07-29 08:36:20 +00:00
|
|
|
DelayBuckets* = [-Inf, -4.0, -2.0, -1.0, -0.5, -0.1, -0.05,
|
|
|
|
0.05, 0.1, 0.5, 1.0, 2.0, 4.0, 8.0, Inf]
|
|
|
|
|
2021-07-13 11:15:07 +00:00
|
|
|
type
|
|
|
|
ServiceState* {.pure.} = enum
|
|
|
|
Initialized, Running, Error, Closing, Closed
|
|
|
|
|
|
|
|
BlockServiceEventRef* = ref object of RootObj
|
|
|
|
slot*: Slot
|
|
|
|
proposers*: seq[ValidatorPubKey]
|
|
|
|
|
2022-10-29 09:00:51 +00:00
|
|
|
RegistrationKind* {.pure.} = enum
|
2023-02-15 15:10:31 +00:00
|
|
|
Cached, IncorrectTime, MissingIndex, MissingFee, MissingGasLimit
|
|
|
|
ErrorSignature, NoSignature
|
2022-10-29 09:00:51 +00:00
|
|
|
|
|
|
|
PendingValidatorRegistration* = object
|
|
|
|
registration*: SignedValidatorRegistrationV1
|
|
|
|
future*: Future[SignatureResult]
|
|
|
|
|
2021-07-13 11:15:07 +00:00
|
|
|
ClientServiceRef* = ref object of RootObj
|
2022-07-13 14:43:57 +00:00
|
|
|
name*: string
|
2021-07-13 11:15:07 +00:00
|
|
|
state*: ServiceState
|
|
|
|
lifeFut*: Future[void]
|
|
|
|
client*: ValidatorClientRef
|
|
|
|
|
|
|
|
DutiesServiceRef* = ref object of ClientServiceRef
|
|
|
|
|
|
|
|
FallbackServiceRef* = ref object of ClientServiceRef
|
2023-02-23 00:11:00 +00:00
|
|
|
changesEvent*: AsyncEvent
|
2021-07-13 11:15:07 +00:00
|
|
|
|
|
|
|
ForkServiceRef* = ref object of ClientServiceRef
|
|
|
|
|
|
|
|
AttestationServiceRef* = ref object of ClientServiceRef
|
|
|
|
|
|
|
|
BlockServiceRef* = ref object of ClientServiceRef
|
|
|
|
|
2022-05-10 10:03:40 +00:00
|
|
|
SyncCommitteeServiceRef* = ref object of ClientServiceRef
|
|
|
|
|
2022-07-21 16:54:07 +00:00
|
|
|
DoppelgangerServiceRef* = ref object of ClientServiceRef
|
|
|
|
enabled*: bool
|
|
|
|
|
2021-07-13 11:15:07 +00:00
|
|
|
DutyAndProof* = object
|
|
|
|
epoch*: Epoch
|
|
|
|
dependentRoot*: Eth2Digest
|
|
|
|
data*: RestAttesterDuty
|
|
|
|
slotSig*: Option[ValidatorSig]
|
|
|
|
|
2022-05-10 10:03:40 +00:00
|
|
|
SyncCommitteeDuty* = object
|
|
|
|
pubkey*: ValidatorPubKey
|
|
|
|
validator_index*: ValidatorIndex
|
|
|
|
validator_sync_committee_index*: IndexInSyncCommittee
|
|
|
|
|
|
|
|
SyncCommitteeSubscriptionInfo* = object
|
|
|
|
validator_index*: ValidatorIndex
|
|
|
|
validator_sync_committee_indices*: seq[IndexInSyncCommittee]
|
|
|
|
|
2021-07-13 11:15:07 +00:00
|
|
|
ProposerTask* = object
|
|
|
|
duty*: RestProposerDuty
|
|
|
|
future*: Future[void]
|
|
|
|
|
|
|
|
ProposedData* = object
|
|
|
|
epoch*: Epoch
|
|
|
|
dependentRoot*: Eth2Digest
|
|
|
|
duties*: seq[ProposerTask]
|
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
BeaconNodeRole* {.pure.} = enum
|
|
|
|
Duties,
|
|
|
|
AttestationData, AttestationPublish,
|
|
|
|
AggregatedData, AggregatedPublish,
|
|
|
|
BlockProposalData, BlockProposalPublish,
|
|
|
|
SyncCommitteeData, SyncCommitteePublish
|
|
|
|
|
2021-07-13 11:15:07 +00:00
|
|
|
BeaconNodeServer* = object
|
|
|
|
client*: RestClientRef
|
|
|
|
endpoint*: string
|
2021-10-20 09:58:38 +00:00
|
|
|
config*: Option[RestSpecVC]
|
2021-07-13 11:15:07 +00:00
|
|
|
ident*: Option[string]
|
2021-08-03 15:17:11 +00:00
|
|
|
genesis*: Option[RestGenesis]
|
2021-07-13 11:15:07 +00:00
|
|
|
syncInfo*: Option[RestSyncInfo]
|
|
|
|
status*: RestBeaconNodeStatus
|
2022-09-29 07:57:14 +00:00
|
|
|
roles*: set[BeaconNodeRole]
|
|
|
|
logIdent*: string
|
|
|
|
index*: int
|
2021-07-13 11:15:07 +00:00
|
|
|
|
|
|
|
EpochDuties* = object
|
|
|
|
duties*: Table[Epoch, DutyAndProof]
|
|
|
|
|
2022-05-10 10:03:40 +00:00
|
|
|
EpochSyncDuties* = object
|
2022-11-24 07:46:35 +00:00
|
|
|
duties*: Table[Epoch, SyncCommitteeDuty]
|
2022-05-10 10:03:40 +00:00
|
|
|
|
2021-07-13 11:15:07 +00:00
|
|
|
RestBeaconNodeStatus* {.pure.} = enum
|
2023-02-23 00:11:00 +00:00
|
|
|
Offline, ## BN is offline.
|
|
|
|
Online, ## BN is online, passed checkOnline() check.
|
|
|
|
Incompatible, ## BN configuration is NOT compatible with VC configuration.
|
|
|
|
Compatible, ## BN configuration is compatible with VC configuration.
|
|
|
|
NotSynced, ## BN is not in sync.
|
|
|
|
OptSynced, ## BN is optimistically synced (EL is not in sync).
|
|
|
|
Synced ## BN and EL are synced.
|
|
|
|
|
|
|
|
BeaconNodesCounters* = object
|
|
|
|
data*: array[int(high(RestBeaconNodeStatus)) + 1, int]
|
2021-07-13 11:15:07 +00:00
|
|
|
|
|
|
|
BeaconNodeServerRef* = ref BeaconNodeServer
|
|
|
|
|
|
|
|
AttesterMap* = Table[ValidatorPubKey, EpochDuties]
|
2022-05-10 10:03:40 +00:00
|
|
|
SyncCommitteeDutiesMap* = Table[ValidatorPubKey, EpochSyncDuties]
|
2021-07-13 11:15:07 +00:00
|
|
|
ProposerMap* = Table[Epoch, ProposedData]
|
|
|
|
|
2022-07-21 16:54:07 +00:00
|
|
|
DoppelgangerStatus* {.pure.} = enum
|
|
|
|
None, Checking, Passed
|
|
|
|
|
|
|
|
DoppelgangerAttempt* {.pure.} = enum
|
|
|
|
None, Failure, SuccessTrue, SuccessFalse
|
|
|
|
|
2021-07-13 11:15:07 +00:00
|
|
|
ValidatorClient* = object
|
|
|
|
config*: ValidatorClientConf
|
2022-07-29 08:36:20 +00:00
|
|
|
metricsServer*: Option[MetricsHttpServerRef]
|
2021-07-13 11:15:07 +00:00
|
|
|
graffitiBytes*: GraffitiBytes
|
|
|
|
beaconNodes*: seq[BeaconNodeServerRef]
|
|
|
|
fallbackService*: FallbackServiceRef
|
|
|
|
forkService*: ForkServiceRef
|
|
|
|
dutiesService*: DutiesServiceRef
|
|
|
|
attestationService*: AttestationServiceRef
|
|
|
|
blockService*: BlockServiceRef
|
2022-05-10 10:03:40 +00:00
|
|
|
syncCommitteeService*: SyncCommitteeServiceRef
|
2022-07-21 16:54:07 +00:00
|
|
|
doppelgangerService*: DoppelgangerServiceRef
|
2022-07-13 14:43:57 +00:00
|
|
|
runSlotLoopFut*: Future[void]
|
2023-02-16 17:25:48 +00:00
|
|
|
runKeystoreCachePruningLoopFut*: Future[void]
|
2022-07-13 14:43:57 +00:00
|
|
|
sigintHandleFut*: Future[void]
|
|
|
|
sigtermHandleFut*: Future[void]
|
2022-08-19 10:30:07 +00:00
|
|
|
keymanagerHost*: ref KeymanagerHost
|
|
|
|
keymanagerServer*: RestServerRef
|
2023-02-16 17:25:48 +00:00
|
|
|
keystoreCache*: KeystoreCacheRef
|
2021-07-13 11:15:07 +00:00
|
|
|
beaconClock*: BeaconClock
|
2022-08-19 10:30:07 +00:00
|
|
|
attachedValidators*: ref ValidatorPool
|
2022-02-16 11:31:23 +00:00
|
|
|
forks*: seq[Fork]
|
|
|
|
forksAvailable*: AsyncEvent
|
2022-07-14 21:11:25 +00:00
|
|
|
nodesAvailable*: AsyncEvent
|
2022-10-21 14:53:30 +00:00
|
|
|
indicesAvailable*: AsyncEvent
|
2022-12-09 16:05:55 +00:00
|
|
|
doppelExit*: AsyncEvent
|
2021-07-13 11:15:07 +00:00
|
|
|
attesters*: AttesterMap
|
|
|
|
proposers*: ProposerMap
|
2022-05-10 10:03:40 +00:00
|
|
|
syncCommitteeDuties*: SyncCommitteeDutiesMap
|
2021-08-03 15:17:11 +00:00
|
|
|
beaconGenesis*: RestGenesis
|
2021-07-13 11:15:07 +00:00
|
|
|
proposerTasks*: Table[Slot, seq[ProposerTask]]
|
2022-10-21 14:53:30 +00:00
|
|
|
dynamicFeeRecipientsStore*: ref DynamicFeeRecipientsStore
|
2022-10-29 09:00:51 +00:00
|
|
|
validatorsRegCache*: Table[ValidatorPubKey, SignedValidatorRegistrationV1]
|
2022-08-19 10:30:07 +00:00
|
|
|
rng*: ref HmacDrbgContext
|
2021-07-13 11:15:07 +00:00
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
ApiFailure* {.pure.} = enum
|
|
|
|
Communication, Invalid, NotFound, NotSynced, Internal, Unexpected
|
|
|
|
|
|
|
|
ApiNodeFailure* = object
|
|
|
|
node*: BeaconNodeServerRef
|
|
|
|
failure*: ApiFailure
|
|
|
|
|
2021-07-13 11:15:07 +00:00
|
|
|
ValidatorClientRef* = ref ValidatorClient
|
|
|
|
|
|
|
|
ValidatorClientError* = object of CatchableError
|
|
|
|
ValidatorApiError* = object of ValidatorClientError
|
2023-02-23 00:11:00 +00:00
|
|
|
data*: seq[ApiNodeFailure]
|
2021-07-13 11:15:07 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
DefaultDutyAndProof* = DutyAndProof(epoch: Epoch(0xFFFF_FFFF_FFFF_FFFF'u64))
|
|
|
|
SlotDuration* = int64(SECONDS_PER_SLOT).seconds
|
2022-01-05 13:41:39 +00:00
|
|
|
OneThirdDuration* = int64(SECONDS_PER_SLOT).seconds div INTERVALS_PER_SLOT
|
2022-09-29 07:57:14 +00:00
|
|
|
AllBeaconNodeRoles* = {
|
|
|
|
BeaconNodeRole.Duties,
|
|
|
|
BeaconNodeRole.AttestationData,
|
|
|
|
BeaconNodeRole.AttestationPublish,
|
|
|
|
BeaconNodeRole.AggregatedData,
|
|
|
|
BeaconNodeRole.AggregatedPublish,
|
|
|
|
BeaconNodeRole.BlockProposalData,
|
|
|
|
BeaconNodeRole.BlockProposalPublish,
|
|
|
|
BeaconNodeRole.SyncCommitteeData,
|
|
|
|
BeaconNodeRole.SyncCommitteePublish,
|
|
|
|
}
|
|
|
|
|
|
|
|
proc `$`*(roles: set[BeaconNodeRole]): string =
|
|
|
|
if card(roles) > 0:
|
|
|
|
if roles != AllBeaconNodeRoles:
|
|
|
|
var res: seq[string]
|
|
|
|
if BeaconNodeRole.Duties in roles:
|
|
|
|
res.add("duties")
|
|
|
|
if BeaconNodeRole.AttestationData in roles:
|
|
|
|
res.add("attestation-data")
|
|
|
|
if BeaconNodeRole.AttestationPublish in roles:
|
|
|
|
res.add("attestation-publish")
|
|
|
|
if BeaconNodeRole.AggregatedData in roles:
|
|
|
|
res.add("aggregated-data")
|
|
|
|
if BeaconNodeRole.AggregatedPublish in roles:
|
|
|
|
res.add("aggregated-publish")
|
|
|
|
if BeaconNodeRole.BlockProposalData in roles:
|
|
|
|
res.add("block-data")
|
|
|
|
if BeaconNodeRole.BlockProposalPublish in roles:
|
|
|
|
res.add("block-publish")
|
|
|
|
if BeaconNodeRole.SyncCommitteeData in roles:
|
|
|
|
res.add("sync-data")
|
|
|
|
if BeaconNodeRole.SyncCommitteePublish in roles:
|
|
|
|
res.add("sync-publish")
|
|
|
|
res.join(",")
|
|
|
|
else:
|
|
|
|
"{all}"
|
|
|
|
else:
|
|
|
|
"{}"
|
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
proc `$`*(status: RestBeaconNodeStatus): string =
|
|
|
|
case status
|
|
|
|
of RestBeaconNodeStatus.Offline: "offline"
|
|
|
|
of RestBeaconNodeStatus.Online: "online"
|
|
|
|
of RestBeaconNodeStatus.Incompatible: "incompatible"
|
|
|
|
of RestBeaconNodeStatus.Compatible: "compatible"
|
|
|
|
of RestBeaconNodeStatus.NotSynced: "bn-unsynced"
|
|
|
|
of RestBeaconNodeStatus.OptSynced: "el-unsynced"
|
|
|
|
of RestBeaconNodeStatus.Synced: "synced"
|
|
|
|
|
|
|
|
proc `$`*(failure: ApiFailure): string =
|
|
|
|
case failure
|
|
|
|
of ApiFailure.Communication: "Connection with beacon node has been lost"
|
|
|
|
of ApiFailure.Invalid: "Invalid response received from beacon node"
|
|
|
|
of ApiFailure.NotFound: "Beacon node did not found requested entity"
|
|
|
|
of ApiFailure.NotSynced: "Beacon node not in sync with network"
|
|
|
|
of ApiFailure.Internal: "Beacon node reports internal failure"
|
|
|
|
of ApiFailure.Unexpected: "Beacon node reports unexpected status"
|
|
|
|
|
|
|
|
proc getNodeCounts*(vc: ValidatorClientRef): BeaconNodesCounters =
|
|
|
|
var res = BeaconNodesCounters()
|
|
|
|
for node in vc.beaconNodes: inc(res.data[int(node.status)])
|
|
|
|
res
|
|
|
|
|
|
|
|
proc getFailureReason*(exc: ref ValidatorApiError): string =
|
|
|
|
var counts: array[int(high(ApiFailure)) + 1, int]
|
2023-02-23 16:02:17 +00:00
|
|
|
let
|
|
|
|
errors = exc[].data
|
|
|
|
errorsCount = len(errors)
|
2023-02-23 00:11:00 +00:00
|
|
|
|
2023-02-23 16:02:17 +00:00
|
|
|
if errorsCount > 1:
|
2023-02-23 00:11:00 +00:00
|
|
|
var maxFailure =
|
|
|
|
block:
|
|
|
|
var maxCount = -1
|
|
|
|
var res = ApiFailure.Unexpected
|
|
|
|
for item in errors:
|
|
|
|
inc(counts[int(item.failure)])
|
|
|
|
if counts[int(item.failure)] > maxCount:
|
|
|
|
maxCount = counts[int(item.failure)]
|
|
|
|
res = item.failure
|
|
|
|
res
|
|
|
|
$maxFailure
|
2023-02-23 16:02:17 +00:00
|
|
|
elif errorsCount == 1:
|
2023-02-23 00:11:00 +00:00
|
|
|
$errors[0].failure
|
2023-02-23 16:02:17 +00:00
|
|
|
else:
|
|
|
|
exc.msg
|
2023-02-23 00:11:00 +00:00
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
proc shortLog*(roles: set[BeaconNodeRole]): string =
|
|
|
|
var r = "AGBSD"
|
|
|
|
if BeaconNodeRole.AttestationData in roles:
|
|
|
|
if BeaconNodeRole.AttestationPublish in roles: r[0] = 'A' else: r[0] = 'a'
|
|
|
|
else:
|
|
|
|
if BeaconNodeRole.AttestationPublish in roles: r[0] = '+' else: r[0] = '-'
|
|
|
|
if BeaconNodeRole.AggregatedData in roles:
|
|
|
|
if BeaconNodeRole.AggregatedPublish in roles: r[1] = 'G' else: r[1] = 'g'
|
|
|
|
else:
|
|
|
|
if BeaconNodeRole.AggregatedPublish in roles: r[1] = '+' else: r[1] = '-'
|
|
|
|
if BeaconNodeRole.BlockProposalData in roles:
|
|
|
|
if BeaconNodeRole.BlockProposalPublish in roles: r[2] = 'B' else: r[2] = 'b'
|
|
|
|
else:
|
|
|
|
if BeaconNodeRole.BlockProposalPublish in roles: r[2] = '+' else: r[2] = '-'
|
|
|
|
if BeaconNodeRole.SyncCommitteeData in roles:
|
|
|
|
if BeaconNodeRole.SyncCommitteePublish in roles:
|
|
|
|
r[3] = 'S' else: r[3] = 's'
|
|
|
|
else:
|
|
|
|
if BeaconNodeRole.SyncCommitteePublish in roles:
|
|
|
|
r[3] = '+' else: r[3] = '-'
|
|
|
|
if BeaconNodeRole.Duties in roles: r[4] = 'D' else: r[4] = '-'
|
|
|
|
r
|
2021-07-13 11:15:07 +00:00
|
|
|
|
|
|
|
proc `$`*(bn: BeaconNodeServerRef): string =
|
|
|
|
if bn.ident.isSome():
|
2022-09-29 07:57:14 +00:00
|
|
|
bn.logIdent & "[" & bn.ident.get() & "]"
|
2021-07-13 11:15:07 +00:00
|
|
|
else:
|
2022-09-29 07:57:14 +00:00
|
|
|
bn.logIdent
|
2021-07-13 11:15:07 +00:00
|
|
|
|
2022-10-14 12:19:17 +00:00
|
|
|
proc validatorLog*(key: ValidatorPubKey,
|
|
|
|
index: ValidatorIndex): string =
|
|
|
|
var res = shortLog(key)
|
|
|
|
res.add('@')
|
|
|
|
res.add(Base10.toString(uint64(index)))
|
|
|
|
res
|
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
chronicles.expandIt(BeaconNodeServerRef):
|
|
|
|
node = $it
|
|
|
|
node_index = it.index
|
|
|
|
node_roles = shortLog(it.roles)
|
2021-07-13 11:15:07 +00:00
|
|
|
|
|
|
|
chronicles.expandIt(RestAttesterDuty):
|
|
|
|
pubkey = shortLog(it.pubkey)
|
|
|
|
slot = it.slot
|
|
|
|
validator_index = it.validator_index
|
|
|
|
committee_index = it.committee_index
|
|
|
|
committee_length = it.committee_length
|
|
|
|
committees_at_slot = it.committees_at_slot
|
|
|
|
validator_committee_index = it.validator_committee_index
|
|
|
|
|
2022-10-21 14:53:30 +00:00
|
|
|
chronicles.expandIt(SyncCommitteeDuty):
|
|
|
|
pubkey = shortLog(it.pubkey)
|
|
|
|
validator_index = it.validator_index
|
|
|
|
validator_sync_committee_index = it.validator_sync_committee_index
|
|
|
|
|
2021-07-13 11:15:07 +00:00
|
|
|
proc stop*(csr: ClientServiceRef) {.async.} =
|
2022-07-14 21:11:25 +00:00
|
|
|
debug "Stopping service", service = csr.name
|
2021-07-13 11:15:07 +00:00
|
|
|
if csr.state == ServiceState.Running:
|
|
|
|
csr.state = ServiceState.Closing
|
|
|
|
if not(csr.lifeFut.finished()):
|
|
|
|
await csr.lifeFut.cancelAndWait()
|
|
|
|
csr.state = ServiceState.Closed
|
2022-07-14 21:11:25 +00:00
|
|
|
debug "Service stopped", service = csr.name
|
2021-07-13 11:15:07 +00:00
|
|
|
|
|
|
|
proc isDefault*(dap: DutyAndProof): bool =
|
|
|
|
dap.epoch == Epoch(0xFFFF_FFFF_FFFF_FFFF'u64)
|
|
|
|
|
|
|
|
proc isDefault*(prd: ProposedData): bool =
|
|
|
|
prd.epoch == Epoch(0xFFFF_FFFF_FFFF_FFFF'u64)
|
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
proc parseRoles*(data: string): Result[set[BeaconNodeRole], cstring] =
|
|
|
|
var res: set[BeaconNodeRole]
|
|
|
|
if len(data) == 0:
|
|
|
|
return ok(AllBeaconNodeRoles)
|
|
|
|
let parts = data.split("roles=")
|
|
|
|
if (len(parts) != 2) or (len(parts[0]) != 0):
|
|
|
|
return err("Invalid beacon node roles string")
|
|
|
|
let sroles = parts[1].split(",")
|
|
|
|
for srole in sroles:
|
|
|
|
case toLower(strip(srole))
|
|
|
|
of "":
|
|
|
|
discard
|
|
|
|
of "all":
|
|
|
|
res.incl(AllBeaconNodeRoles)
|
|
|
|
of "attestation":
|
|
|
|
res.incl({BeaconNodeRole.AttestationData,
|
|
|
|
BeaconNodeRole.AttestationPublish})
|
|
|
|
of "block":
|
|
|
|
res.incl({BeaconNodeRole.BlockProposalData,
|
|
|
|
BeaconNodeRole.BlockProposalPublish})
|
|
|
|
of "aggregated":
|
|
|
|
res.incl({BeaconNodeRole.AggregatedData,
|
|
|
|
BeaconNodeRole.AggregatedPublish})
|
|
|
|
of "sync":
|
|
|
|
res.incl({BeaconNodeRole.SyncCommitteeData,
|
|
|
|
BeaconNodeRole.SyncCommitteePublish})
|
|
|
|
of "attestation-data":
|
|
|
|
res.incl(BeaconNodeRole.AttestationData)
|
|
|
|
of "attestation-publish":
|
|
|
|
res.incl(BeaconNodeRole.AttestationPublish)
|
|
|
|
of "aggregated-data":
|
|
|
|
res.incl(BeaconNodeRole.AggregatedData)
|
|
|
|
of "aggregated-publish":
|
|
|
|
res.incl(BeaconNodeRole.AggregatedPublish)
|
|
|
|
of "block-data":
|
|
|
|
res.incl(BeaconNodeRole.BlockProposalData)
|
|
|
|
of "block-publish":
|
|
|
|
res.incl(BeaconNodeRole.BlockProposalPublish)
|
|
|
|
of "sync-data":
|
|
|
|
res.incl(BeaconNodeRole.SyncCommitteeData)
|
|
|
|
of "sync-publish":
|
|
|
|
res.incl(BeaconNodeRole.SyncCommitteePublish)
|
|
|
|
of "duties":
|
|
|
|
res.incl(BeaconNodeRole.Duties)
|
|
|
|
else:
|
|
|
|
return err("Invalid beacon node role string found")
|
|
|
|
ok(res)
|
|
|
|
|
|
|
|
proc init*(t: typedesc[BeaconNodeServerRef], remote: Uri,
|
|
|
|
index: int): Result[BeaconNodeServerRef, string] =
|
|
|
|
doAssert(index >= 0)
|
|
|
|
let
|
|
|
|
flags = {RestClientFlag.CommaSeparatedArray}
|
|
|
|
client =
|
|
|
|
block:
|
|
|
|
let res = RestClientRef.new($remote, flags = flags)
|
|
|
|
if res.isErr(): return err($res.error())
|
|
|
|
res.get()
|
|
|
|
roles =
|
|
|
|
block:
|
|
|
|
let res = parseRoles(remote.anchor)
|
|
|
|
if res.isErr(): return err($res.error())
|
|
|
|
res.get()
|
|
|
|
|
|
|
|
let server = BeaconNodeServerRef(
|
|
|
|
client: client, endpoint: $remote, index: index, roles: roles,
|
|
|
|
logIdent: client.address.hostname & ":" &
|
2023-02-23 00:11:00 +00:00
|
|
|
Base10.toString(client.address.port),
|
|
|
|
status: RestBeaconNodeStatus.Offline
|
2022-09-29 07:57:14 +00:00
|
|
|
)
|
|
|
|
ok(server)
|
|
|
|
|
|
|
|
proc getMissingRoles*(n: openArray[BeaconNodeServerRef]): set[BeaconNodeRole] =
|
|
|
|
var res: set[BeaconNodeRole] = AllBeaconNodeRoles
|
|
|
|
for node in n.items():
|
|
|
|
res.excl(node.roles)
|
|
|
|
res
|
|
|
|
|
2021-07-13 11:15:07 +00:00
|
|
|
proc init*(t: typedesc[DutyAndProof], epoch: Epoch, dependentRoot: Eth2Digest,
|
|
|
|
duty: RestAttesterDuty,
|
|
|
|
slotSig: Option[ValidatorSig]): DutyAndProof =
|
|
|
|
DutyAndProof(epoch: epoch, dependentRoot: dependentRoot, data: duty,
|
|
|
|
slotSig: slotSig)
|
|
|
|
|
|
|
|
proc init*(t: typedesc[ProposedData], epoch: Epoch, dependentRoot: Eth2Digest,
|
2022-04-08 16:22:49 +00:00
|
|
|
data: openArray[ProposerTask]): ProposedData =
|
2021-07-13 11:15:07 +00:00
|
|
|
ProposedData(epoch: epoch, dependentRoot: dependentRoot, duties: @data)
|
|
|
|
|
|
|
|
proc getCurrentSlot*(vc: ValidatorClientRef): Option[Slot] =
|
|
|
|
let
|
|
|
|
wallTime = vc.beaconClock.now()
|
|
|
|
wallSlot = wallTime.toSlot()
|
|
|
|
|
|
|
|
if not(wallSlot.afterGenesis):
|
2022-01-11 10:01:54 +00:00
|
|
|
let checkGenesisTime = vc.beaconClock.fromNow(start_beacon_time(Slot(0)))
|
2021-07-13 11:15:07 +00:00
|
|
|
warn "Jump in time detected, something wrong with wallclock",
|
|
|
|
wall_time = wallTime, genesisIn = checkGenesisTime.offset
|
|
|
|
none[Slot]()
|
|
|
|
else:
|
|
|
|
some(wallSlot.slot)
|
|
|
|
|
|
|
|
proc getAttesterDutiesForSlot*(vc: ValidatorClientRef,
|
2021-07-15 08:17:32 +00:00
|
|
|
slot: Slot): seq[DutyAndProof] =
|
2022-05-10 10:03:40 +00:00
|
|
|
## Returns all `DutyAndProof` for the given `slot`.
|
2021-07-15 08:17:32 +00:00
|
|
|
var res: seq[DutyAndProof]
|
2021-07-13 11:15:07 +00:00
|
|
|
let epoch = slot.epoch()
|
2022-05-10 10:03:40 +00:00
|
|
|
for key, item in vc.attesters:
|
2021-07-13 11:15:07 +00:00
|
|
|
let duty = item.duties.getOrDefault(epoch, DefaultDutyAndProof)
|
|
|
|
if not(duty.isDefault()):
|
|
|
|
if duty.data.slot == slot:
|
2021-07-15 08:17:32 +00:00
|
|
|
res.add(duty)
|
2021-07-13 11:15:07 +00:00
|
|
|
res
|
|
|
|
|
2022-05-10 10:03:40 +00:00
|
|
|
proc getSyncCommitteeDutiesForSlot*(vc: ValidatorClientRef,
|
2022-11-24 07:46:35 +00:00
|
|
|
slot: Slot): seq[SyncCommitteeDuty] =
|
|
|
|
## Returns all `SyncCommitteeDuty` for the given `slot`.
|
|
|
|
var res: seq[SyncCommitteeDuty]
|
2022-05-10 10:03:40 +00:00
|
|
|
let epoch = slot.epoch()
|
|
|
|
for key, item in mpairs(vc.syncCommitteeDuties):
|
|
|
|
item.duties.withValue(epoch, duty):
|
|
|
|
res.add(duty[])
|
|
|
|
res
|
|
|
|
|
2021-07-13 11:15:07 +00:00
|
|
|
proc getDurationToNextAttestation*(vc: ValidatorClientRef,
|
|
|
|
slot: Slot): string =
|
2022-01-11 10:01:54 +00:00
|
|
|
var minSlot = FAR_FUTURE_SLOT
|
2021-07-13 11:15:07 +00:00
|
|
|
let currentEpoch = slot.epoch()
|
|
|
|
for epoch in [currentEpoch, currentEpoch + 1'u64]:
|
2022-05-10 10:03:40 +00:00
|
|
|
for key, item in vc.attesters:
|
2021-07-13 11:15:07 +00:00
|
|
|
let duty = item.duties.getOrDefault(epoch, DefaultDutyAndProof)
|
|
|
|
if not(duty.isDefault()):
|
2022-01-11 10:01:54 +00:00
|
|
|
let dutySlotTime = duty.data.slot
|
2022-07-13 14:43:57 +00:00
|
|
|
if (duty.data.slot < minSlot) and (duty.data.slot >= slot):
|
2022-01-11 10:01:54 +00:00
|
|
|
minSlot = duty.data.slot
|
|
|
|
if minSlot != FAR_FUTURE_SLOT:
|
2021-07-13 11:15:07 +00:00
|
|
|
break
|
2022-01-11 10:01:54 +00:00
|
|
|
|
|
|
|
if minSlot == FAR_FUTURE_SLOT:
|
2021-07-13 11:15:07 +00:00
|
|
|
"<unknown>"
|
|
|
|
else:
|
2022-01-11 10:01:54 +00:00
|
|
|
$(minSlot.attestation_deadline() - slot.start_beacon_time())
|
2021-07-13 11:15:07 +00:00
|
|
|
|
|
|
|
proc getDurationToNextBlock*(vc: ValidatorClientRef, slot: Slot): string =
|
2022-01-11 10:01:54 +00:00
|
|
|
var minSlot = FAR_FUTURE_SLOT
|
2021-07-13 11:15:07 +00:00
|
|
|
let currentEpoch = slot.epoch()
|
|
|
|
for epoch in [currentEpoch, currentEpoch + 1'u64]:
|
|
|
|
let data = vc.proposers.getOrDefault(epoch)
|
|
|
|
if not(data.isDefault()):
|
|
|
|
for item in data.duties:
|
2022-08-19 10:30:07 +00:00
|
|
|
if item.duty.pubkey in vc.attachedValidators[]:
|
2022-07-13 14:43:57 +00:00
|
|
|
if (item.duty.slot < minSlot) and (item.duty.slot >= slot):
|
2022-01-11 10:01:54 +00:00
|
|
|
minSlot = item.duty.slot
|
|
|
|
if minSlot != FAR_FUTURE_SLOT:
|
2021-07-13 11:15:07 +00:00
|
|
|
break
|
2022-01-11 10:01:54 +00:00
|
|
|
if minSlot == FAR_FUTURE_SLOT:
|
2021-07-13 11:15:07 +00:00
|
|
|
"<unknown>"
|
|
|
|
else:
|
2022-01-11 10:01:54 +00:00
|
|
|
$(minSlot.block_deadline() - slot.start_beacon_time())
|
2021-07-13 11:15:07 +00:00
|
|
|
|
|
|
|
iterator attesterDutiesForEpoch*(vc: ValidatorClientRef,
|
|
|
|
epoch: Epoch): DutyAndProof =
|
2022-05-10 10:03:40 +00:00
|
|
|
for key, item in vc.attesters:
|
2021-07-13 11:15:07 +00:00
|
|
|
let epochDuties = item.duties.getOrDefault(epoch)
|
|
|
|
if not(isDefault(epochDuties)):
|
|
|
|
yield epochDuties
|
|
|
|
|
2022-05-10 10:03:40 +00:00
|
|
|
proc syncMembersSubscriptionInfoForEpoch*(
|
|
|
|
vc: ValidatorClientRef,
|
|
|
|
epoch: Epoch): seq[SyncCommitteeSubscriptionInfo] =
|
|
|
|
var res: seq[SyncCommitteeSubscriptionInfo]
|
|
|
|
for key, item in mpairs(vc.syncCommitteeDuties):
|
|
|
|
var cur: SyncCommitteeSubscriptionInfo
|
|
|
|
var initialized = false
|
|
|
|
|
|
|
|
item.duties.withValue(epoch, epochDuties):
|
|
|
|
if not initialized:
|
2022-11-24 07:46:35 +00:00
|
|
|
cur.validator_index = epochDuties.validator_index
|
2022-05-10 10:03:40 +00:00
|
|
|
initialized = true
|
|
|
|
cur.validator_sync_committee_indices.add(
|
2022-11-24 07:46:35 +00:00
|
|
|
epochDuties.validator_sync_committee_index)
|
2022-05-10 10:03:40 +00:00
|
|
|
|
|
|
|
if initialized:
|
|
|
|
res.add cur
|
|
|
|
|
|
|
|
res
|
|
|
|
|
2022-01-11 10:01:54 +00:00
|
|
|
proc getDelay*(vc: ValidatorClientRef, deadline: BeaconTime): TimeDiff =
|
|
|
|
vc.beaconClock.now() - deadline
|
2021-07-19 14:31:02 +00:00
|
|
|
|
2022-12-09 16:05:55 +00:00
|
|
|
proc getValidatorForDuties*(vc: ValidatorClientRef,
|
2023-02-20 11:28:56 +00:00
|
|
|
key: ValidatorPubKey, slot: Slot,
|
|
|
|
doppelActivity = false,
|
|
|
|
slashingSafe = false): Opt[AttachedValidator] =
|
|
|
|
vc.attachedValidators[].getValidatorForDuties(
|
|
|
|
key, slot, doppelActivity, slashingSafe)
|
2022-02-16 11:31:23 +00:00
|
|
|
|
|
|
|
proc forkAtEpoch*(vc: ValidatorClientRef, epoch: Epoch): Fork =
|
|
|
|
# If schedule is present, it MUST not be empty.
|
|
|
|
doAssert(len(vc.forks) > 0)
|
|
|
|
var res: Fork
|
|
|
|
for item in vc.forks:
|
|
|
|
if item.epoch <= epoch:
|
|
|
|
res = item
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
res
|
2022-05-10 10:03:40 +00:00
|
|
|
|
2022-07-13 14:43:57 +00:00
|
|
|
proc getSubcommitteeIndex*(index: IndexInSyncCommittee): SyncSubcommitteeIndex =
|
|
|
|
SyncSubcommitteeIndex(uint16(index) div SYNC_SUBCOMMITTEE_SIZE)
|
2022-07-21 16:54:07 +00:00
|
|
|
|
|
|
|
proc currentSlot*(vc: ValidatorClientRef): Slot =
|
|
|
|
vc.beaconClock.now().slotOrZero()
|
|
|
|
|
|
|
|
proc addValidator*(vc: ValidatorClientRef, keystore: KeystoreData) =
|
2022-09-17 05:30:07 +00:00
|
|
|
let
|
|
|
|
slot = vc.currentSlot()
|
|
|
|
feeRecipient = vc.config.validatorsDir.getSuggestedFeeRecipient(
|
|
|
|
keystore.pubkey, vc.config.defaultFeeRecipient).valueOr(
|
|
|
|
vc.config.defaultFeeRecipient)
|
2023-02-15 15:10:31 +00:00
|
|
|
gasLimit = vc.config.validatorsDir.getSuggestedGasLimit(
|
|
|
|
keystore.pubkey, vc.config.suggestedGasLimit).valueOr(
|
|
|
|
vc.config.suggestedGasLimit)
|
2023-02-07 14:53:36 +00:00
|
|
|
|
2023-02-15 15:10:31 +00:00
|
|
|
discard vc.attachedValidators[].addValidator(keystore, feeRecipient, gasLimit)
|
2022-07-21 16:54:07 +00:00
|
|
|
|
|
|
|
proc removeValidator*(vc: ValidatorClientRef,
|
|
|
|
pubkey: ValidatorPubKey) {.async.} =
|
2023-02-20 11:28:56 +00:00
|
|
|
let validator = vc.attachedValidators[].getValidator(pubkey).valueOr:
|
|
|
|
return
|
|
|
|
# Remove validator from ValidatorPool.
|
|
|
|
vc.attachedValidators[].removeValidator(pubkey)
|
|
|
|
|
|
|
|
case validator.kind
|
|
|
|
of ValidatorKind.Local:
|
|
|
|
discard
|
|
|
|
of ValidatorKind.Remote:
|
|
|
|
# We must close all the REST clients running for the remote validator.
|
|
|
|
let pending =
|
|
|
|
block:
|
|
|
|
var res: seq[Future[void]]
|
|
|
|
for item in validator.clients:
|
|
|
|
res.add(item[0].closeWait())
|
|
|
|
res
|
|
|
|
await allFutures(pending)
|
2022-07-21 16:54:07 +00:00
|
|
|
|
2022-10-21 14:53:30 +00:00
|
|
|
proc getFeeRecipient*(vc: ValidatorClientRef, pubkey: ValidatorPubKey,
|
|
|
|
validatorIdx: ValidatorIndex,
|
|
|
|
epoch: Epoch): Opt[Eth1Address] =
|
|
|
|
let dynamicRecipient = vc.dynamicFeeRecipientsStore[].getDynamicFeeRecipient(
|
|
|
|
validatorIdx, epoch)
|
|
|
|
if dynamicRecipient.isSome():
|
|
|
|
Opt.some(dynamicRecipient.get())
|
|
|
|
else:
|
|
|
|
let staticRecipient = getSuggestedFeeRecipient(
|
|
|
|
vc.config.validatorsDir, pubkey, vc.config.defaultFeeRecipient)
|
|
|
|
if staticRecipient.isOk():
|
|
|
|
Opt.some(staticRecipient.get())
|
|
|
|
else:
|
|
|
|
Opt.none(Eth1Address)
|
|
|
|
|
2023-02-15 15:10:31 +00:00
|
|
|
proc getGasLimit*(vc: ValidatorClientRef,
|
|
|
|
pubkey: ValidatorPubKey): uint64 =
|
|
|
|
getSuggestedGasLimit(
|
|
|
|
vc.config.validatorsDir, pubkey, vc.config.suggestedGasLimit).valueOr:
|
|
|
|
vc.config.suggestedGasLimit
|
|
|
|
|
2022-10-21 14:53:30 +00:00
|
|
|
proc prepareProposersList*(vc: ValidatorClientRef,
|
|
|
|
epoch: Epoch): seq[PrepareBeaconProposer] =
|
|
|
|
var res: seq[PrepareBeaconProposer]
|
|
|
|
for validator in vc.attachedValidators[].items():
|
|
|
|
if validator.index.isSome():
|
|
|
|
let
|
|
|
|
index = validator.index.get()
|
|
|
|
feeRecipient = vc.getFeeRecipient(validator.pubkey, index, epoch)
|
|
|
|
if feeRecipient.isSome():
|
|
|
|
res.add(PrepareBeaconProposer(validator_index: index,
|
|
|
|
fee_recipient: feeRecipient.get()))
|
|
|
|
res
|
2022-10-29 09:00:51 +00:00
|
|
|
|
|
|
|
proc isDefault*(reg: SignedValidatorRegistrationV1): bool =
|
|
|
|
(reg.message.timestamp == 0'u64) or (reg.message.gas_limit == 0'u64)
|
|
|
|
|
|
|
|
proc isExpired*(vc: ValidatorClientRef,
|
|
|
|
reg: SignedValidatorRegistrationV1, slot: Slot): bool =
|
|
|
|
let
|
|
|
|
regTime = fromUnix(int64(reg.message.timestamp))
|
|
|
|
regSlot =
|
|
|
|
block:
|
|
|
|
let res = vc.beaconClock.toSlot(regTime)
|
|
|
|
if not(res.afterGenesis):
|
|
|
|
# This case should not be happend, but it could in case of time jumps
|
|
|
|
# (time could be modified by admin or ntpd).
|
|
|
|
return false
|
|
|
|
uint64(res.slot)
|
|
|
|
|
|
|
|
if regSlot > slot:
|
|
|
|
# This case should not be happened, but if it happens (time could be
|
|
|
|
# modified by admin or ntpd).
|
|
|
|
false
|
|
|
|
else:
|
|
|
|
if (slot - regSlot) div SLOTS_PER_EPOCH >=
|
|
|
|
EPOCHS_BETWEEN_VALIDATOR_REGISTRATION:
|
|
|
|
false
|
|
|
|
else:
|
|
|
|
true
|
|
|
|
|
2023-02-15 15:10:31 +00:00
|
|
|
proc getValidatorRegistration(
|
2022-10-29 09:00:51 +00:00
|
|
|
vc: ValidatorClientRef,
|
|
|
|
validator: AttachedValidator,
|
|
|
|
timestamp: Time,
|
|
|
|
fork: Fork
|
|
|
|
): Result[PendingValidatorRegistration, RegistrationKind] =
|
|
|
|
if validator.index.isNone():
|
|
|
|
debug "Validator registration missing validator index",
|
|
|
|
validator = shortLog(validator)
|
|
|
|
return err(RegistrationKind.MissingIndex)
|
|
|
|
|
|
|
|
let
|
|
|
|
vindex = validator.index.get()
|
|
|
|
cached = vc.validatorsRegCache.getOrDefault(validator.pubkey)
|
|
|
|
currentSlot =
|
|
|
|
block:
|
|
|
|
let res = vc.beaconClock.toSlot(timestamp)
|
|
|
|
if not(res.afterGenesis):
|
|
|
|
return err(RegistrationKind.IncorrectTime)
|
|
|
|
res.slot
|
|
|
|
|
|
|
|
if cached.isDefault() or vc.isExpired(cached, currentSlot):
|
|
|
|
let feeRecipient = vc.getFeeRecipient(validator.pubkey, vindex,
|
|
|
|
currentSlot.epoch())
|
|
|
|
if feeRecipient.isNone():
|
|
|
|
debug "Could not get fee recipient for registration data",
|
|
|
|
validator = shortLog(validator)
|
|
|
|
return err(RegistrationKind.MissingFee)
|
2023-02-15 15:10:31 +00:00
|
|
|
let gasLimit = vc.getGasLimit(validator.pubkey)
|
2022-10-29 09:00:51 +00:00
|
|
|
var registration =
|
|
|
|
SignedValidatorRegistrationV1(
|
|
|
|
message: ValidatorRegistrationV1(
|
|
|
|
fee_recipient:
|
|
|
|
ExecutionAddress(data: distinctBase(feeRecipient.get())),
|
2023-02-15 15:10:31 +00:00
|
|
|
gas_limit: gasLimit,
|
2022-10-29 09:00:51 +00:00
|
|
|
timestamp: uint64(timestamp.toUnix()),
|
|
|
|
pubkey: validator.pubkey
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
let sigfut = validator.getBuilderSignature(fork, registration.message)
|
|
|
|
if sigfut.finished():
|
|
|
|
# This is short-path if we able to create signature locally.
|
|
|
|
if not(sigfut.done()):
|
|
|
|
let exc = sigfut.readError()
|
|
|
|
debug "Got unexpected exception while signing validator registration",
|
|
|
|
validator = shortLog(validator), error_name = $exc.name,
|
|
|
|
error_msg = $exc.msg
|
|
|
|
return err(RegistrationKind.ErrorSignature)
|
|
|
|
let sigres = sigfut.read()
|
|
|
|
if sigres.isErr():
|
|
|
|
debug "Failed to get signature for validator registration",
|
|
|
|
validator = shortLog(validator), error = sigres.error()
|
|
|
|
return err(RegistrationKind.NoSignature)
|
|
|
|
registration.signature = sigres.get()
|
|
|
|
# Updating cache table with new signed registration data
|
|
|
|
vc.validatorsRegCache[registration.message.pubkey] = registration
|
|
|
|
ok(PendingValidatorRegistration(registration: registration, future: nil))
|
|
|
|
else:
|
|
|
|
# Remote signature service involved, cache will be updated later.
|
|
|
|
ok(PendingValidatorRegistration(registration: registration,
|
|
|
|
future: sigfut))
|
|
|
|
else:
|
|
|
|
# Returning cached result.
|
|
|
|
err(RegistrationKind.Cached)
|
|
|
|
|
|
|
|
proc prepareRegistrationList*(
|
|
|
|
vc: ValidatorClientRef,
|
|
|
|
timestamp: Time,
|
|
|
|
fork: Fork
|
|
|
|
): Future[seq[SignedValidatorRegistrationV1]] {.async.} =
|
|
|
|
|
|
|
|
var
|
|
|
|
messages: seq[SignedValidatorRegistrationV1]
|
|
|
|
futures: seq[Future[SignatureResult]]
|
|
|
|
registrations: seq[SignedValidatorRegistrationV1]
|
|
|
|
total = vc.attachedValidators[].count()
|
|
|
|
succeed = 0
|
|
|
|
bad = 0
|
|
|
|
errors = 0
|
|
|
|
indexMissing = 0
|
|
|
|
feeMissing = 0
|
2023-02-15 15:10:31 +00:00
|
|
|
gasLimit = 0
|
2022-10-29 09:00:51 +00:00
|
|
|
cached = 0
|
|
|
|
timed = 0
|
|
|
|
|
|
|
|
for validator in vc.attachedValidators[].items():
|
2023-02-15 15:10:31 +00:00
|
|
|
let res = vc.getValidatorRegistration(validator, timestamp, fork)
|
2022-10-29 09:00:51 +00:00
|
|
|
if res.isOk():
|
|
|
|
let preg = res.get()
|
|
|
|
if preg.future.isNil():
|
|
|
|
registrations.add(preg.registration)
|
|
|
|
else:
|
|
|
|
messages.add(preg.registration)
|
|
|
|
futures.add(preg.future)
|
|
|
|
else:
|
|
|
|
case res.error()
|
|
|
|
of RegistrationKind.Cached: inc(cached)
|
|
|
|
of RegistrationKind.IncorrectTime: inc(timed)
|
|
|
|
of RegistrationKind.NoSignature: inc(bad)
|
|
|
|
of RegistrationKind.ErrorSignature: inc(errors)
|
|
|
|
of RegistrationKind.MissingIndex: inc(indexMissing)
|
|
|
|
of RegistrationKind.MissingFee: inc(feeMissing)
|
2023-02-15 15:10:31 +00:00
|
|
|
of RegistrationKind.MissingGasLimit: inc(gasLimit)
|
2022-10-29 09:00:51 +00:00
|
|
|
|
|
|
|
succeed = len(registrations)
|
|
|
|
|
|
|
|
if len(futures) > 0:
|
|
|
|
await allFutures(futures)
|
|
|
|
|
|
|
|
for index, future in futures.pairs():
|
|
|
|
if future.done():
|
|
|
|
let sres = future.read()
|
|
|
|
if sres.isOk():
|
|
|
|
var reg = messages[index]
|
|
|
|
reg.signature = sres.get()
|
|
|
|
registrations.add(reg)
|
|
|
|
# Updating cache table
|
|
|
|
vc.validatorsRegCache[reg.message.pubkey] = reg
|
|
|
|
inc(succeed)
|
|
|
|
else:
|
|
|
|
inc(bad)
|
|
|
|
else:
|
|
|
|
inc(errors)
|
|
|
|
|
|
|
|
debug "Validator registrations prepared", total = total, succeed = succeed,
|
|
|
|
cached = cached, bad = bad, errors = errors,
|
|
|
|
index_missing = indexMissing, fee_missing = feeMissing,
|
|
|
|
incorrect_time = timed
|
|
|
|
|
|
|
|
return registrations
|
2023-02-23 00:11:00 +00:00
|
|
|
|
|
|
|
proc init*(t: typedesc[ApiNodeFailure], node: BeaconNodeServerRef,
|
|
|
|
failure: ApiFailure): ApiNodeFailure =
|
|
|
|
ApiNodeFailure(node: node, failure: failure)
|