2020-05-06 13:23:45 +00:00
|
|
|
# beacon_chain
|
2021-05-20 10:44:13 +00:00
|
|
|
# Copyright (c) 2018-2021 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.
|
|
|
|
|
|
|
|
# Common routines for a BeaconNode and a BeaconValidator node
|
|
|
|
|
|
|
|
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
|
2021-03-26 17:57:02 +00:00
|
|
|
chronos, json_rpc/servers/httpserver, presto,
|
2020-05-06 13:23:45 +00:00
|
|
|
|
|
|
|
# Local modules
|
2021-03-05 13:12:00 +00:00
|
|
|
./conf, ./beacon_clock, ./beacon_chain_db,
|
2021-03-03 06:23:05 +00:00
|
|
|
./beacon_node_types,
|
2021-05-28 16:34:00 +00:00
|
|
|
./gossip_processing/[eth2_processor, block_processor, consensus_manager],
|
2021-03-05 13:12:00 +00:00
|
|
|
./networking/eth2_network,
|
2021-03-03 06:23:05 +00:00
|
|
|
./eth1/eth1_monitor,
|
2021-03-04 09:13:44 +00:00
|
|
|
./consensus_object_pools/[blockchain_dag, block_quarantine, attestation_pool],
|
2021-06-21 08:35:24 +00:00
|
|
|
./spec/datatypes/base,
|
2021-03-02 10:27:45 +00:00
|
|
|
./sync/[sync_manager, request_manager]
|
2020-05-06 13:23:45 +00:00
|
|
|
|
2020-10-28 07:55:36 +00:00
|
|
|
export
|
2021-03-26 14:11:06 +00:00
|
|
|
osproc, chronos, httpserver, conf, beacon_clock, beacon_chain_db,
|
2020-11-03 19:02:43 +00:00
|
|
|
attestation_pool, eth2_network, beacon_node_types, eth1_monitor,
|
2021-03-04 09:13:44 +00:00
|
|
|
request_manager, sync_manager, eth2_processor, blockchain_dag, block_quarantine,
|
2021-06-21 08:35:24 +00:00
|
|
|
base
|
2020-05-22 17:04:52 +00:00
|
|
|
|
2020-05-06 13:23:45 +00:00
|
|
|
type
|
|
|
|
RpcServer* = RpcHttpServer
|
|
|
|
|
|
|
|
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
|
2021-06-01 11:13:40 +00:00
|
|
|
dag*: ChainDAGRef
|
2020-07-31 14:49:06 +00:00
|
|
|
quarantine*: QuarantineRef
|
2020-08-20 16:30:47 +00:00
|
|
|
attestationPool*: ref AttestationPool
|
2020-09-14 14:26:31 +00:00
|
|
|
exitPool*: ref ExitPool
|
2020-11-03 01:21:07 +00:00
|
|
|
eth1Monitor*: Eth1Monitor
|
2020-05-06 13:23:45 +00:00
|
|
|
rpcServer*: RpcServer
|
2021-03-17 18:46:45 +00:00
|
|
|
restServer*: RestServerRef
|
2020-09-01 13:44:40 +00:00
|
|
|
vcProcess*: Process
|
2020-08-12 09:29:11 +00:00
|
|
|
requestManager*: RequestManager
|
2020-06-03 08:46:29 +00:00
|
|
|
syncManager*: SyncManager[Peer, PeerID]
|
2020-07-02 15:14:11 +00:00
|
|
|
genesisSnapshotContent*: string
|
2020-08-12 17:48:31 +00:00
|
|
|
attestationSubnets*: AttestationSubnets
|
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
|
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
|
|
|
|
2021-07-07 09:09:47 +00:00
|
|
|
template beaconClock*(node: BeaconNode): BeaconClock =
|
|
|
|
node.dag.beaconClock
|
|
|
|
|
2020-10-27 09:00:57 +00:00
|
|
|
proc currentSlot*(node: BeaconNode): Slot =
|
|
|
|
node.beaconClock.now.slotOrZero
|