2020-05-06 13:23:45 +00:00
|
|
|
# beacon_chain
|
2024-01-06 14:26:56 +00:00
|
|
|
# Copyright (c) 2018-2024 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.
|
|
|
|
|
2024-03-12 20:51:18 +00:00
|
|
|
{.push raises: [].}
|
|
|
|
|
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
|
2023-12-05 21:08:18 +00:00
|
|
|
chronos, 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,
|
2024-10-30 05:38:53 +00:00
|
|
|
data_column_quarantine, attestation_pool, sync_committee_msg_pool, validator_change_pool,
|
|
|
|
blockchain_list],
|
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,
|
2024-10-30 05:38:53 +00:00
|
|
|
./spec/signatures_batch,
|
|
|
|
./sync/[sync_manager, request_manager, sync_types],
|
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
|
2023-12-05 21:08:18 +00:00
|
|
|
osproc, chronos, presto, action_tracker,
|
2022-06-07 17:01:11 +00:00
|
|
|
beacon_clock, beacon_chain_db, conf, light_client,
|
2023-12-23 05:55:47 +00:00
|
|
|
attestation_pool, sync_committee_msg_pool, validator_change_pool,
|
2024-03-25 18:09:31 +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,
|
2023-12-23 05:55:47 +00:00
|
|
|
base, message_router, validator_monitor, validator_pool,
|
2024-10-30 05:38:53 +00:00
|
|
|
consensus_manager, dynamic_fee_recipients, sync_types
|
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
|
|
|
|
headQueue*: AsyncEventQueue[HeadChangeInfoObject]
|
2023-12-22 13:52:43 +00:00
|
|
|
blocksQueue*: AsyncEventQueue[EventBeaconBlockObject]
|
2024-04-17 20:44:29 +00:00
|
|
|
attestQueue*: AsyncEventQueue[phase0.Attestation]
|
2023-12-22 13:52:43 +00:00
|
|
|
exitQueue*: AsyncEventQueue[SignedVoluntaryExit]
|
|
|
|
blsToExecQueue*: AsyncEventQueue[SignedBLSToExecutionChange]
|
2023-12-22 17:54:55 +00:00
|
|
|
propSlashQueue*: AsyncEventQueue[ProposerSlashing]
|
2024-04-21 05:49:11 +00:00
|
|
|
attSlashQueue*: AsyncEventQueue[phase0.AttesterSlashing]
|
2024-01-13 09:52:13 +00:00
|
|
|
blobSidecarQueue*: AsyncEventQueue[BlobSidecarInfoObject]
|
2023-12-22 13:52:43 +00:00
|
|
|
finalQueue*: AsyncEventQueue[FinalizationInfoObject]
|
2022-06-17 15:27:28 +00:00
|
|
|
reorgQueue*: AsyncEventQueue[ReorgInfoObject]
|
2023-12-22 13:52:43 +00:00
|
|
|
contribQueue*: AsyncEventQueue[SignedContributionAndProof]
|
2023-01-12 17:11:38 +00:00
|
|
|
finUpdateQueue*: AsyncEventQueue[
|
|
|
|
RestVersioned[ForkedLightClientFinalityUpdate]]
|
|
|
|
optUpdateQueue*: AsyncEventQueue[
|
|
|
|
RestVersioned[ForkedLightClientOptimisticUpdate]]
|
2024-10-30 05:38:53 +00:00
|
|
|
optFinHeaderUpdateQueue*: AsyncEventQueue[ForkedLightClientHeader]
|
2022-06-17 15:27:28 +00:00
|
|
|
|
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
|
2024-11-04 11:19:43 +00:00
|
|
|
optimisticFcuFut*: Future[(PayloadExecutionStatus, Opt[Hash32])]
|
2024-06-14 01:23:17 +00:00
|
|
|
.Raising([CancelledError])
|
2022-06-07 17:01:11 +00:00
|
|
|
lightClient*: LightClient
|
2021-06-01 11:13:40 +00:00
|
|
|
dag*: ChainDAGRef
|
2024-10-30 05:38:53 +00:00
|
|
|
list*: ChainListRef
|
2021-12-06 09:49:01 +00:00
|
|
|
quarantine*: ref Quarantine
|
2023-04-28 12:57:35 +00:00
|
|
|
blobQuarantine*: ref BlobQuarantine
|
2024-10-22 05:19:34 +00:00
|
|
|
dataColumnQuarantine*: ref DataColumnQuarantine
|
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]
|
2024-10-30 05:38:53 +00:00
|
|
|
untrustedManager*: SyncManager[Peer, PeerId]
|
|
|
|
syncOverseer*: SyncOverseerRef
|
2020-07-02 15:14:11 +00:00
|
|
|
genesisSnapshotContent*: string
|
2020-08-20 16:30:47 +00:00
|
|
|
processor*: ref Eth2Processor
|
2024-10-30 05:38:53 +00:00
|
|
|
batchVerifier*: ref BatchVerifier
|
2021-05-28 16:34:00 +00:00
|
|
|
blockProcessor*: ref BlockProcessor
|
2021-03-11 10:10:57 +00:00
|
|
|
consensusManager*: ref ConsensusManager
|
2024-03-19 13:22:07 +00:00
|
|
|
attachedValidatorBalanceTotal*: Gwei
|
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
|
2023-06-28 13:33:07 +00:00
|
|
|
processingDelay*: Opt[Duration]
|
2024-01-11 22:34:10 +00:00
|
|
|
lastValidAttestedBlock*: Opt[BlockSlot]
|
2024-06-20 18:57:08 +00:00
|
|
|
shutdownEvent*: AsyncEvent
|
2020-05-06 13:23:45 +00:00
|
|
|
|
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-09-20 17:00:37 +00:00
|
|
|
proc getPayloadBuilderAddress*(
|
|
|
|
node: BeaconNode, pubkey: ValidatorPubKey): Opt[string] =
|
|
|
|
let defaultPayloadBuilderAddress = node.config.getPayloadBuilderAddress
|
|
|
|
if node.keymanagerHost.isNil:
|
|
|
|
defaultPayloadBuilderAddress
|
|
|
|
else:
|
|
|
|
node.keymanagerHost[].getBuilderConfig(pubkey).valueOr:
|
|
|
|
defaultPayloadBuilderAddress
|
|
|
|
|
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
|
|
|
|
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
|
2023-09-20 17:00:37 +00:00
|
|
|
payloadBuilderAddress = node.getPayloadBuilderAddress(pubkey)
|
2023-06-25 12:00:17 +00:00
|
|
|
|
|
|
|
if payloadBuilderAddress.isNone:
|
|
|
|
return err "Payload builder disabled"
|
2024-09-24 04:23:38 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
flags = {RestClientFlag.CommaSeparatedArray,
|
|
|
|
RestClientFlag.ResolveAlways}
|
|
|
|
socketFlags = {SocketFlags.TcpNoDelay}
|
|
|
|
|
|
|
|
RestClientRef.new(payloadBuilderAddress.get, flags = flags,
|
|
|
|
socketFlags = socketFlags)
|