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-05-22 17:04:52 +00:00
|
|
|
# Standard library
|
2020-09-01 13:44:40 +00:00
|
|
|
tables, osproc,
|
2020-05-22 17:04:52 +00:00
|
|
|
|
2020-05-06 13:23:45 +00:00
|
|
|
# Nimble packages
|
|
|
|
chronos, json_rpc/rpcserver, metrics,
|
2020-05-22 17:04:52 +00:00
|
|
|
chronicles,
|
2020-05-06 13:23:45 +00:00
|
|
|
|
|
|
|
# Local modules
|
2020-06-05 09:57:40 +00:00
|
|
|
spec/[datatypes, crypto, digest],
|
|
|
|
conf, time, beacon_chain_db,
|
2020-07-30 19:18:17 +00:00
|
|
|
attestation_pool, eth2_network,
|
2020-07-31 14:49:06 +00:00
|
|
|
block_pools/[chain_dag, quarantine],
|
2020-06-03 08:46:29 +00:00
|
|
|
beacon_node_types, mainchain_monitor, request_manager,
|
2020-08-20 16:30:47 +00:00
|
|
|
sync_manager,
|
|
|
|
./eth2_processor
|
2020-05-06 13:23:45 +00:00
|
|
|
|
2020-05-25 17:33:03 +00:00
|
|
|
# This removes an invalid Nim warning that the digest module is unused here
|
|
|
|
# It's currently used for `shortLog(head.blck.root)`
|
|
|
|
type Eth2Digest = digest.Eth2Digest
|
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-05-06 13:23:45 +00:00
|
|
|
mainchainMonitor*: MainchainMonitor
|
|
|
|
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
|
|
|
|
|
|
|
# Metrics
|
2020-07-28 13:54:32 +00:00
|
|
|
proc updateHead*(node: BeaconNode, wallSlot: Slot): BlockRef =
|
2020-08-26 15:23:34 +00:00
|
|
|
## Trigger fork choice and returns the new head block.
|
|
|
|
## Can return `nil`
|
2020-08-20 16:30:47 +00:00
|
|
|
node.processor[].updateHead(wallSlot)
|
2020-05-27 17:06:28 +00:00
|
|
|
|
2020-09-07 15:04:33 +00:00
|
|
|
# TODO stew/sequtils2
|
2020-07-22 21:01:44 +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
|