2020-05-06 13:23:45 +00:00
|
|
|
# beacon_chain
|
2022-06-07 17:01:11 +00:00
|
|
|
# Copyright (c) 2018-2022 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,
|
2021-03-03 06:23:05 +00:00
|
|
|
./eth1/eth1_monitor,
|
2021-10-18 16:37:27 +00:00
|
|
|
./consensus_object_pools/[
|
2022-07-13 14:13:54 +00:00
|
|
|
blockchain_dag, 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,
|
2022-08-25 03:53:59 +00:00
|
|
|
eth2_network, eth1_monitor, request_manager, sync_manager,
|
|
|
|
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]
|
2022-06-19 05:57:52 +00:00
|
|
|
finUpdateQueue*: AsyncEventQueue[altair.LightClientFinalityUpdate]
|
|
|
|
optUpdateQueue*: AsyncEventQueue[altair.LightClientOptimisticUpdate]
|
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
|
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
|
2020-09-14 14:26:31 +00:00
|
|
|
exitPool*: ref ExitPool
|
2020-11-03 01:21:07 +00:00
|
|
|
eth1Monitor*: Eth1Monitor
|
2022-08-01 06:41:47 +00:00
|
|
|
payloadBuilderRestClient*: RestClientRef
|
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
|
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
|
2021-10-18 09:11:44 +00:00
|
|
|
actionTracker*: ActionTracker
|
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-06-15 02:38:27 +00:00
|
|
|
nextExchangeTransitionConfTime*: Moment
|
2022-07-06 16:11:44 +00:00
|
|
|
router*: ref MessageRouter
|
2022-08-23 16:19:52 +00:00
|
|
|
dynamicFeeRecipientsStore*: ref DynamicFeeRecipientsStore
|
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
|