2020-05-06 13:23:45 +00:00
|
|
|
# beacon_chain
|
|
|
|
# Copyright (c) 2018-2020 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.
|
|
|
|
|
|
|
|
# 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
|
2020-10-28 07:55:36 +00:00
|
|
|
chronos, json_rpc/rpcserver,
|
2020-05-06 13:23:45 +00:00
|
|
|
|
|
|
|
# Local modules
|
2020-10-28 07:55:36 +00:00
|
|
|
./conf, ./time, ./beacon_chain_db, ./attestation_pool, ./eth2_network,
|
2020-11-03 19:02:43 +00:00
|
|
|
./beacon_node_types, ./eth1_monitor, ./request_manager,
|
2020-10-28 07:55:36 +00:00
|
|
|
./sync_manager, ./eth2_processor,
|
|
|
|
./block_pools/[chain_dag, quarantine],
|
|
|
|
./spec/datatypes
|
2020-05-06 13:23:45 +00:00
|
|
|
|
2020-10-28 07:55:36 +00:00
|
|
|
export
|
|
|
|
osproc, chronos, rpcserver, conf, time, beacon_chain_db,
|
2020-11-03 19:02:43 +00:00
|
|
|
attestation_pool, eth2_network, beacon_node_types, eth1_monitor,
|
2020-10-28 07:55:36 +00:00
|
|
|
request_manager, sync_manager, eth2_processor, chain_Dag, quarantine,
|
|
|
|
datatypes
|
2020-05-22 17:04:52 +00:00
|
|
|
|
2020-05-06 13:23:45 +00:00
|
|
|
type
|
|
|
|
RpcServer* = RpcHttpServer
|
2020-07-01 11:41:40 +00:00
|
|
|
KeyPair* = eth2_network.KeyPair
|
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
|
|
|
|
netKeys*: KeyPair
|
|
|
|
db*: BeaconChainDB
|
|
|
|
config*: BeaconNodeConf
|
|
|
|
attachedValidators*: ValidatorPool
|
2020-07-31 14:49:06 +00:00
|
|
|
chainDag*: ChainDAGRef
|
|
|
|
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
|
|
|
beaconClock*: BeaconClock
|
|
|
|
rpcServer*: RpcServer
|
2020-09-01 13:44:40 +00:00
|
|
|
vcProcess*: Process
|
2020-05-06 13:23:45 +00:00
|
|
|
forkDigest*: ForkDigest
|
2020-08-12 09:29:11 +00:00
|
|
|
requestManager*: RequestManager
|
2020-06-03 08:46:29 +00:00
|
|
|
syncManager*: SyncManager[Peer, PeerID]
|
2020-05-06 13:23:45 +00:00
|
|
|
topicBeaconBlocks*: string
|
|
|
|
topicAggregateAndProofs*: string
|
2020-08-12 09:29:11 +00:00
|
|
|
blockProcessingLoop*: Future[void]
|
2020-06-03 08:46:29 +00:00
|
|
|
onSecondLoop*: Future[void]
|
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
|
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
|
|
|
|
|
|
|
proc currentSlot*(node: BeaconNode): Slot =
|
|
|
|
node.beaconClock.now.slotOrZero
|