2020-05-06 13:23:45 +00:00
|
|
|
# beacon_chain
|
2023-01-12 17:11:38 +00:00
|
|
|
# Copyright (c) 2018-2023 Status Research & Development GmbH
|
2020-05-06 13:23:45 +00:00
|
|
|
# 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-10-19 14:09:26 +00:00
|
|
|
# Everything needed to run a full Beacon Node
|
2020-05-06 13:23:45 +00:00
|
|
|
|
|
|
|
import
|
2020-10-28 07:55:36 +00:00
|
|
|
std/osproc,
|
2020-05-22 17:04:52 +00:00
|
|
|
|
2020-05-06 13:23:45 +00:00
|
|
|
# Nimble packages
|
2022-08-19 10:30:07 +00:00
|
|
|
chronos, json_rpc/servers/httpserver, presto, bearssl/rand,
|
2020-05-06 13:23:45 +00:00
|
|
|
|
|
|
|
# Local modules
|
2022-06-07 17:01:11 +00:00
|
|
|
"."/[beacon_clock, beacon_chain_db, conf, light_client],
|
2022-08-25 03:53:59 +00:00
|
|
|
./gossip_processing/[eth2_processor, block_processor, optimistic_processor],
|
2021-03-05 13:12:00 +00:00
|
|
|
./networking/eth2_network,
|
2023-05-15 05:05:12 +00:00
|
|
|
./el/el_manager,
|
2021-10-18 16:37:27 +00:00
|
|
|
./consensus_object_pools/[
|
2023-04-28 12:57:35 +00:00
|
|
|
blockchain_dag, blob_quarantine, block_quarantine, consensus_manager,
|
|
|
|
exit_pool, attestation_pool, sync_committee_msg_pool],
|
2022-06-19 05:57:52 +00:00
|
|
|
./spec/datatypes/[base, altair],
|
2022-07-25 20:12:53 +00:00
|
|
|
./spec/eth2_apis/dynamic_fee_recipients,
|
2022-08-25 03:53:59 +00:00
|
|
|
./sync/[sync_manager, request_manager],
|
2022-07-06 16:11:44 +00:00
|
|
|
./validators/[
|
2022-08-19 10:30:07 +00:00
|
|
|
action_tracker, message_router, validator_monitor, validator_pool,
|
|
|
|
keystore_management],
|
2022-01-05 14:49:10 +00:00
|
|
|
./rpc/state_ttl_cache
|
2020-05-06 13:23:45 +00:00
|
|
|
|
2020-10-28 07:55:36 +00:00
|
|
|
export
|
2022-06-07 17:01:11 +00:00
|
|
|
osproc, chronos, httpserver, presto, action_tracker,
|
|
|
|
beacon_clock, beacon_chain_db, conf, light_client,
|
|
|
|
attestation_pool, sync_committee_msg_pool, validator_pool,
|
2023-05-15 05:05:12 +00:00
|
|
|
eth2_network, el_manager, request_manager, sync_manager,
|
2022-08-25 03:53:59 +00:00
|
|
|
eth2_processor, optimistic_processor, blockchain_dag, block_quarantine,
|
|
|
|
base, exit_pool, message_router, validator_monitor,
|
2022-07-25 20:12:53 +00:00
|
|
|
consensus_manager, dynamic_fee_recipients
|
2020-05-22 17:04:52 +00:00
|
|
|
|
2020-05-06 13:23:45 +00:00
|
|
|
type
|
2022-06-17 15:27:28 +00:00
|
|
|
EventBus* = object
|
2022-06-20 05:53:39 +00:00
|
|
|
blocksQueue*: AsyncEventQueue[EventBeaconBlockObject]
|
2022-06-17 15:27:28 +00:00
|
|
|
headQueue*: AsyncEventQueue[HeadChangeInfoObject]
|
|
|
|
reorgQueue*: AsyncEventQueue[ReorgInfoObject]
|
2023-01-12 17:11:38 +00:00
|
|
|
finUpdateQueue*: AsyncEventQueue[
|
|
|
|
RestVersioned[ForkedLightClientFinalityUpdate]]
|
|
|
|
optUpdateQueue*: AsyncEventQueue[
|
|
|
|
RestVersioned[ForkedLightClientOptimisticUpdate]]
|
2022-06-17 15:27:28 +00:00
|
|
|
attestQueue*: AsyncEventQueue[Attestation]
|
|
|
|
contribQueue*: AsyncEventQueue[SignedContributionAndProof]
|
|
|
|
exitQueue*: AsyncEventQueue[SignedVoluntaryExit]
|
|
|
|
finalQueue*: AsyncEventQueue[FinalizationInfoObject]
|
|
|
|
|
2020-05-06 13:23:45 +00:00
|
|
|
BeaconNode* = ref object
|
|
|
|
nickname*: string
|
2020-06-29 17:30:19 +00:00
|
|
|
graffitiBytes*: GraffitiBytes
|
2020-05-06 13:23:45 +00:00
|
|
|
network*: Eth2Node
|
2021-03-19 02:22:45 +00:00
|
|
|
netKeys*: NetKeyPair
|
2020-05-06 13:23:45 +00:00
|
|
|
db*: BeaconChainDB
|
|
|
|
config*: BeaconNodeConf
|
2021-02-22 16:17:48 +00:00
|
|
|
attachedValidators*: ref ValidatorPool
|
2022-08-25 03:53:59 +00:00
|
|
|
optimisticProcessor*: OptimisticProcessor
|
2022-06-07 17:01:11 +00:00
|
|
|
lightClient*: LightClient
|
2021-06-01 11:13:40 +00:00
|
|
|
dag*: ChainDAGRef
|
2021-12-06 09:49:01 +00:00
|
|
|
quarantine*: ref Quarantine
|
2023-04-28 12:57:35 +00:00
|
|
|
blobQuarantine*: ref BlobQuarantine
|
2020-08-20 16:30:47 +00:00
|
|
|
attestationPool*: ref AttestationPool
|
2021-08-28 22:27:51 +00:00
|
|
|
syncCommitteeMsgPool*: ref SyncCommitteeMsgPool
|
2022-05-23 12:02:54 +00:00
|
|
|
lightClientPool*: ref LightClientPool
|
2023-01-19 22:00:40 +00:00
|
|
|
validatorChangePool*: ref ValidatorChangePool
|
2023-03-05 01:40:21 +00:00
|
|
|
elManager*: ELManager
|
2021-03-17 18:46:45 +00:00
|
|
|
restServer*: RestServerRef
|
2022-08-19 10:30:07 +00:00
|
|
|
keymanagerHost*: ref KeymanagerHost
|
2021-12-22 12:37:31 +00:00
|
|
|
keymanagerServer*: RestServerRef
|
2023-02-16 17:25:48 +00:00
|
|
|
keystoreCache*: KeystoreCacheRef
|
2022-06-17 15:27:28 +00:00
|
|
|
eventBus*: EventBus
|
2020-09-01 13:44:40 +00:00
|
|
|
vcProcess*: Process
|
2020-08-12 09:29:11 +00:00
|
|
|
requestManager*: RequestManager
|
2022-04-08 16:22:49 +00:00
|
|
|
syncManager*: SyncManager[Peer, PeerId]
|
|
|
|
backfiller*: SyncManager[Peer, PeerId]
|
2020-07-02 15:14:11 +00:00
|
|
|
genesisSnapshotContent*: string
|
2020-08-20 16:30:47 +00:00
|
|
|
processor*: ref Eth2Processor
|
2021-05-28 16:34:00 +00:00
|
|
|
blockProcessor*: ref BlockProcessor
|
2021-03-11 10:10:57 +00:00
|
|
|
consensusManager*: ref ConsensusManager
|
2020-11-29 21:35:39 +00:00
|
|
|
attachedValidatorBalanceTotal*: uint64
|
2021-08-09 12:54:45 +00:00
|
|
|
gossipState*: GossipState
|
2022-08-25 03:53:59 +00:00
|
|
|
blocksGossipState*: GossipState
|
2021-08-20 08:58:15 +00:00
|
|
|
beaconClock*: BeaconClock
|
2021-10-14 10:38:38 +00:00
|
|
|
restKeysCache*: Table[ValidatorPubKey, ValidatorIndex]
|
2021-12-20 19:20:31 +00:00
|
|
|
validatorMonitor*: ref ValidatorMonitor
|
2022-01-05 14:49:10 +00:00
|
|
|
stateTtlCache*: StateTtlCache
|
2022-07-06 16:11:44 +00:00
|
|
|
router*: ref MessageRouter
|
2022-08-23 16:19:52 +00:00
|
|
|
dynamicFeeRecipientsStore*: ref DynamicFeeRecipientsStore
|
2022-09-13 11:52:26 +00:00
|
|
|
externalBuilderRegistrations*:
|
|
|
|
Table[ValidatorPubKey, SignedValidatorRegistrationV1]
|
2023-02-07 14:53:36 +00:00
|
|
|
dutyValidatorCount*: int
|
|
|
|
## Number of validators that we've checked for activation
|
2020-05-06 13:23:45 +00:00
|
|
|
|
2020-05-22 17:04:52 +00:00
|
|
|
const
|
|
|
|
MaxEmptySlotCount* = uint64(10*60) div SECONDS_PER_SLOT
|
2020-05-06 13:23:45 +00:00
|
|
|
|
2020-09-07 15:04:33 +00:00
|
|
|
# TODO stew/sequtils2
|
2020-10-28 18:35:31 +00:00
|
|
|
template findIt*(s: openArray, predicate: untyped): int =
|
2020-05-27 17:06:28 +00:00
|
|
|
var res = -1
|
|
|
|
for i, it {.inject.} in s:
|
|
|
|
if predicate:
|
|
|
|
res = i
|
|
|
|
break
|
|
|
|
res
|
2020-10-27 09:00:57 +00:00
|
|
|
|
2022-08-19 10:30:07 +00:00
|
|
|
template rng*(node: BeaconNode): ref HmacDrbgContext =
|
|
|
|
node.network.rng
|
|
|
|
|
2020-10-27 09:00:57 +00:00
|
|
|
proc currentSlot*(node: BeaconNode): Slot =
|
|
|
|
node.beaconClock.now.slotOrZero
|
2023-05-25 15:38:56 +00:00
|
|
|
|
2023-06-25 12:00:17 +00:00
|
|
|
func getPayloadBuilderAddress*(config: BeaconNodeConf): Opt[string] =
|
|
|
|
if config.payloadBuilderEnable:
|
|
|
|
Opt.some config.payloadBuilderUrl
|
|
|
|
else:
|
|
|
|
Opt.none(string)
|
|
|
|
|
2023-06-02 11:06:33 +00:00
|
|
|
proc getPayloadBuilderClient*(
|
|
|
|
node: BeaconNode, validator_index: uint64): RestResult[RestClientRef] =
|
2023-06-25 12:00:17 +00:00
|
|
|
if not node.config.payloadBuilderEnable:
|
|
|
|
return err "Payload builder globally disabled"
|
|
|
|
|
|
|
|
let
|
|
|
|
defaultPayloadBuilderAddress = node.config.getPayloadBuilderAddress
|
|
|
|
pubkey = withState(node.dag.headState):
|
|
|
|
if validator_index >= forkyState.data.validators.lenu64:
|
|
|
|
return err "Validator index too high"
|
|
|
|
forkyState.data.validators.item(validator_index).pubkey
|
|
|
|
payloadBuilderAddress =
|
|
|
|
if node.keyManagerHost.isNil:
|
|
|
|
defaultPayloadBuilderAddress
|
|
|
|
else:
|
|
|
|
node.keyManagerHost[].getBuilderConfig(pubkey).valueOr:
|
|
|
|
defaultPayloadBuilderAddress
|
|
|
|
|
|
|
|
if payloadBuilderAddress.isNone:
|
|
|
|
return err "Payload builder disabled"
|
|
|
|
let res = RestClientRef.new(payloadBuilderAddress.get)
|
|
|
|
if res.isOk and res.get.isNil:
|
|
|
|
err "Got nil payload builder REST client reference"
|
2023-05-25 15:38:56 +00:00
|
|
|
else:
|
2023-06-25 12:00:17 +00:00
|
|
|
res
|