startup cleanup
* fix several memory leaks due to temporaries not being reset during init * avoid massive main() function with lots of stuff in it * disable nim-prompt (unused) * reuse validator pool instance in eth2_processor * style cleanup
This commit is contained in:
parent
3f6834cce7
commit
0dbc7162ac
|
@ -37,7 +37,7 @@ type
|
|||
netKeys*: KeyPair
|
||||
db*: BeaconChainDB
|
||||
config*: BeaconNodeConf
|
||||
attachedValidators*: ValidatorPool
|
||||
attachedValidators*: ref ValidatorPool
|
||||
chainDag*: ChainDAGRef
|
||||
quarantine*: QuarantineRef
|
||||
attestationPool*: ref AttestationPool
|
||||
|
|
|
@ -511,7 +511,7 @@ type
|
|||
desc: "Delay in seconds between retries after unsuccessful attempts to connect to a beacon node"
|
||||
name: "retry-delay" }: int
|
||||
|
||||
proc defaultDataDir*(conf: BeaconNodeConf|ValidatorClientConf): string =
|
||||
proc defaultDataDir*(config: BeaconNodeConf|ValidatorClientConf): string =
|
||||
let dataDir = when defined(windows):
|
||||
"AppData" / "Roaming" / "Nimbus"
|
||||
elif defined(macosx):
|
||||
|
@ -521,29 +521,29 @@ proc defaultDataDir*(conf: BeaconNodeConf|ValidatorClientConf): string =
|
|||
|
||||
getHomeDir() / dataDir / "BeaconNode"
|
||||
|
||||
func dumpDir*(conf: BeaconNodeConf|ValidatorClientConf): string =
|
||||
conf.dataDir / "dump"
|
||||
func dumpDir*(config: BeaconNodeConf|ValidatorClientConf): string =
|
||||
config.dataDir / "dump"
|
||||
|
||||
func dumpDirInvalid*(conf: BeaconNodeConf|ValidatorClientConf): string =
|
||||
conf.dumpDir / "invalid" # things that failed validation
|
||||
func dumpDirInvalid*(config: BeaconNodeConf|ValidatorClientConf): string =
|
||||
config.dumpDir / "invalid" # things that failed validation
|
||||
|
||||
func dumpDirIncoming*(conf: BeaconNodeConf|ValidatorClientConf): string =
|
||||
conf.dumpDir / "incoming" # things that couldn't be validated (missingparent etc)
|
||||
func dumpDirIncoming*(config: BeaconNodeConf|ValidatorClientConf): string =
|
||||
config.dumpDir / "incoming" # things that couldn't be validated (missingparent etc)
|
||||
|
||||
func dumpDirOutgoing*(conf: BeaconNodeConf|ValidatorClientConf): string =
|
||||
conf.dumpDir / "outgoing" # things we produced
|
||||
func dumpDirOutgoing*(config: BeaconNodeConf|ValidatorClientConf): string =
|
||||
config.dumpDir / "outgoing" # things we produced
|
||||
|
||||
proc createDumpDirs*(conf: BeaconNodeConf) =
|
||||
if conf.dumpEnabled:
|
||||
let resInv = secureCreatePath(conf.dumpDirInvalid)
|
||||
proc createDumpDirs*(config: BeaconNodeConf) =
|
||||
if config.dumpEnabled:
|
||||
let resInv = secureCreatePath(config.dumpDirInvalid)
|
||||
if resInv.isErr():
|
||||
warn "Could not create dump directory", path = conf.dumpDirInvalid
|
||||
let resInc = secureCreatePath(conf.dumpDirIncoming)
|
||||
warn "Could not create dump directory", path = config.dumpDirInvalid
|
||||
let resInc = secureCreatePath(config.dumpDirIncoming)
|
||||
if resInc.isErr():
|
||||
warn "Could not create dump directory", path = conf.dumpDirIncoming
|
||||
let resOut = secureCreatePath(conf.dumpDirOutgoing)
|
||||
warn "Could not create dump directory", path = config.dumpDirIncoming
|
||||
let resOut = secureCreatePath(config.dumpDirOutgoing)
|
||||
if resOut.isErr():
|
||||
warn "Could not create dump directory", path = conf.dumpDirOutgoing
|
||||
warn "Could not create dump directory", path = config.dumpDirOutgoing
|
||||
|
||||
func parseCmdArg*(T: type GraffitiBytes, input: TaintedString): T
|
||||
{.raises: [ValueError, Defect].} =
|
||||
|
@ -611,65 +611,65 @@ proc parseCmdArg*(T: type enr.Record, p: TaintedString): T
|
|||
proc completeCmdArg*(T: type enr.Record, val: TaintedString): seq[string] =
|
||||
return @[]
|
||||
|
||||
func validatorsDir*(conf: BeaconNodeConf|ValidatorClientConf): string =
|
||||
string conf.validatorsDirFlag.get(InputDir(conf.dataDir / "validators"))
|
||||
func validatorsDir*(config: BeaconNodeConf|ValidatorClientConf): string =
|
||||
string config.validatorsDirFlag.get(InputDir(config.dataDir / "validators"))
|
||||
|
||||
func secretsDir*(conf: BeaconNodeConf|ValidatorClientConf): string =
|
||||
string conf.secretsDirFlag.get(InputDir(conf.dataDir / "secrets"))
|
||||
func secretsDir*(config: BeaconNodeConf|ValidatorClientConf): string =
|
||||
string config.secretsDirFlag.get(InputDir(config.dataDir / "secrets"))
|
||||
|
||||
func walletsDir*(conf: BeaconNodeConf): string =
|
||||
if conf.walletsDirFlag.isSome:
|
||||
conf.walletsDirFlag.get.string
|
||||
func walletsDir*(config: BeaconNodeConf): string =
|
||||
if config.walletsDirFlag.isSome:
|
||||
config.walletsDirFlag.get.string
|
||||
else:
|
||||
conf.dataDir / "wallets"
|
||||
config.dataDir / "wallets"
|
||||
|
||||
func outWalletName*(conf: BeaconNodeConf): Option[WalletName] =
|
||||
func outWalletName*(config: BeaconNodeConf): Option[WalletName] =
|
||||
proc fail {.noReturn.} =
|
||||
raiseAssert "outWalletName should be used only in the right context"
|
||||
|
||||
case conf.cmd
|
||||
case config.cmd
|
||||
of wallets:
|
||||
case conf.walletsCmd
|
||||
of WalletsCmd.create: conf.createdWalletNameFlag
|
||||
of WalletsCmd.restore: conf.restoredWalletNameFlag
|
||||
case config.walletsCmd
|
||||
of WalletsCmd.create: config.createdWalletNameFlag
|
||||
of WalletsCmd.restore: config.restoredWalletNameFlag
|
||||
of WalletsCmd.list: fail()
|
||||
of deposits:
|
||||
# TODO: Uncomment when the deposits create command is restored
|
||||
#case conf.depositsCmd
|
||||
#of DepositsCmd.create: conf.newWalletNameFlag
|
||||
#case config.depositsCmd
|
||||
#of DepositsCmd.create: config.newWalletNameFlag
|
||||
#else: fail()
|
||||
fail()
|
||||
else:
|
||||
fail()
|
||||
|
||||
func outWalletFile*(conf: BeaconNodeConf): Option[OutFile] =
|
||||
func outWalletFile*(config: BeaconNodeConf): Option[OutFile] =
|
||||
proc fail {.noReturn.} =
|
||||
raiseAssert "outWalletName should be used only in the right context"
|
||||
|
||||
case conf.cmd
|
||||
case config.cmd
|
||||
of wallets:
|
||||
case conf.walletsCmd
|
||||
of WalletsCmd.create: conf.createdWalletFileFlag
|
||||
of WalletsCmd.restore: conf.restoredWalletFileFlag
|
||||
case config.walletsCmd
|
||||
of WalletsCmd.create: config.createdWalletFileFlag
|
||||
of WalletsCmd.restore: config.restoredWalletFileFlag
|
||||
of WalletsCmd.list: fail()
|
||||
of deposits:
|
||||
# TODO: Uncomment when the deposits create command is restored
|
||||
#case conf.depositsCmd
|
||||
#of DepositsCmd.create: conf.newWalletFileFlag
|
||||
#case config.depositsCmd
|
||||
#of DepositsCmd.create: config.newWalletFileFlag
|
||||
#else: fail()
|
||||
fail()
|
||||
else:
|
||||
fail()
|
||||
|
||||
func databaseDir*(conf: BeaconNodeConf|ValidatorClientConf): string =
|
||||
conf.dataDir / "db"
|
||||
func databaseDir*(config: BeaconNodeConf|ValidatorClientConf): string =
|
||||
config.dataDir / "db"
|
||||
|
||||
func defaultListenAddress*(conf: BeaconNodeConf|ValidatorClientConf): ValidIpAddress =
|
||||
func defaultListenAddress*(config: BeaconNodeConf|ValidatorClientConf): ValidIpAddress =
|
||||
# TODO: How should we select between IPv4 and IPv6
|
||||
# Maybe there should be a config option for this.
|
||||
(static ValidIpAddress.init("0.0.0.0"))
|
||||
|
||||
func defaultAdminListenAddress*(conf: BeaconNodeConf|ValidatorClientConf): ValidIpAddress =
|
||||
func defaultAdminListenAddress*(config: BeaconNodeConf|ValidatorClientConf): ValidIpAddress =
|
||||
(static ValidIpAddress.init("127.0.0.1"))
|
||||
|
||||
template writeValue*(writer: var JsonWriter,
|
||||
|
|
|
@ -1114,8 +1114,7 @@ proc getEth1BlockHash*(url: string, blockId: RtBlockIdentifier): Future[BlockHas
|
|||
await web3.close()
|
||||
|
||||
proc testWeb3Provider*(web3Url: Uri,
|
||||
depositContractAddress: Option[Eth1Address],
|
||||
depositContractDeployedAt: Option[BlockHashOrNumber]) {.async.} =
|
||||
depositContractAddress: Eth1Address) {.async.} =
|
||||
template mustSucceed(action: static string, expr: untyped): untyped =
|
||||
try: expr
|
||||
except CatchableError as err:
|
||||
|
@ -1133,14 +1132,13 @@ proc testWeb3Provider*(web3Url: Uri,
|
|||
echo "Network: ", network
|
||||
echo "Latest block: ", latestBlock.number.uint64
|
||||
|
||||
if depositContractAddress.isSome:
|
||||
let ns = web3.contractSender(DepositContract, depositContractAddress.get)
|
||||
try:
|
||||
let depositRoot = awaitWithRetries(
|
||||
ns.get_deposit_root.call(blockNumber = latestBlock.number.uint64))
|
||||
echo "Deposit root: ", depositRoot
|
||||
except CatchableError as err:
|
||||
echo "Web3 provider is not archive mode"
|
||||
let ns = web3.contractSender(DepositContract, depositContractAddress)
|
||||
try:
|
||||
let depositRoot = awaitWithRetries(
|
||||
ns.get_deposit_root.call(blockNumber = latestBlock.number.uint64))
|
||||
echo "Deposit root: ", depositRoot
|
||||
except CatchableError as err:
|
||||
echo "Web3 provider is not archive mode: ", err.msg
|
||||
|
||||
when hasGenesisDetection:
|
||||
proc init*(T: type Eth1Monitor,
|
||||
|
@ -1261,4 +1259,3 @@ when hasGenesisDetection:
|
|||
else:
|
||||
doAssert bnStatus == BeaconNodeStatus.Stopping
|
||||
return new BeaconStateRef # cannot return nil...
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import
|
|||
std/[os, strutils],
|
||||
chronicles, stew/shims/net, stew/results, bearssl,
|
||||
eth/keys, eth/p2p/discoveryv5/[enr, protocol, node],
|
||||
conf
|
||||
./conf
|
||||
|
||||
export protocol, keys
|
||||
|
||||
|
@ -74,7 +74,7 @@ proc loadBootstrapFile*(bootstrapFile: string,
|
|||
quit 1
|
||||
|
||||
proc new*(T: type Eth2DiscoveryProtocol,
|
||||
conf: BeaconNodeConf,
|
||||
config: BeaconNodeConf,
|
||||
ip: Option[ValidIpAddress], tcpPort, udpPort: Port,
|
||||
pk: PrivateKey,
|
||||
enrFields: openArray[(string, seq[byte])], rng: ref BrHmacDrbgContext):
|
||||
|
@ -84,14 +84,14 @@ proc new*(T: type Eth2DiscoveryProtocol,
|
|||
# * for setting up a specific key
|
||||
# * for using a persistent database
|
||||
var bootstrapEnrs: seq[enr.Record]
|
||||
for node in conf.bootstrapNodes:
|
||||
for node in config.bootstrapNodes:
|
||||
addBootstrapNode(node, bootstrapEnrs)
|
||||
loadBootstrapFile(string conf.bootstrapNodesFile, bootstrapEnrs)
|
||||
loadBootstrapFile(string config.bootstrapNodesFile, bootstrapEnrs)
|
||||
|
||||
let persistentBootstrapFile = conf.dataDir / "bootstrap_nodes.txt"
|
||||
let persistentBootstrapFile = config.dataDir / "bootstrap_nodes.txt"
|
||||
if fileExists(persistentBootstrapFile):
|
||||
loadBootstrapFile(persistentBootstrapFile, bootstrapEnrs)
|
||||
|
||||
newProtocol(pk, ip, tcpPort, udpPort, enrFields, bootstrapEnrs,
|
||||
bindIp = conf.listenAddress, enrAutoUpdate = conf.enrAutoUpdate,
|
||||
bindIp = config.listenAddress, enrAutoUpdate = config.enrAutoUpdate,
|
||||
rng = rng)
|
||||
|
|
|
@ -21,11 +21,10 @@ import
|
|||
libp2p/stream/connection,
|
||||
eth/[keys, async_utils], eth/p2p/p2p_protocol_dsl,
|
||||
eth/net/nat, eth/p2p/discoveryv5/[enr, node],
|
||||
# Beacon node modules
|
||||
version, conf, eth2_discovery, libp2p_json_serialization, conf,
|
||||
ssz/ssz_serialization,
|
||||
peer_pool, spec/[datatypes, digest, helpers, network], ./time,
|
||||
keystore_management
|
||||
"."/[
|
||||
version, conf, eth2_discovery, libp2p_json_serialization,
|
||||
ssz/ssz_serialization, peer_pool, time, keystore_management],
|
||||
./spec/[datatypes, digest, helpers, network]
|
||||
|
||||
import libp2p/protocols/pubsub/gossipsub
|
||||
|
||||
|
@ -600,10 +599,11 @@ proc performProtocolHandshakes*(peer: Peer, incoming: bool) {.async.} =
|
|||
proc initProtocol(name: string,
|
||||
peerInit: PeerStateInitializer,
|
||||
networkInit: NetworkStateInitializer): ProtocolInfoObj =
|
||||
result.name = name
|
||||
result.messages = @[]
|
||||
result.peerStateInitializer = peerInit
|
||||
result.networkStateInitializer = networkInit
|
||||
ProtocolInfoObj(
|
||||
name: name,
|
||||
messages: @[],
|
||||
peerStateInitializer: peerInit,
|
||||
networkStateInitializer: networkInit)
|
||||
|
||||
proc registerProtocol(protocol: ProtocolInfo) =
|
||||
# TODO: This can be done at compile-time in the future
|
||||
|
@ -913,8 +913,8 @@ proc runDiscoveryLoop*(node: Eth2Node) {.async.} =
|
|||
# when no peers are in the routing table. Don't run it in continuous loop.
|
||||
await sleepAsync(1.seconds)
|
||||
|
||||
proc getPersistentNetMetadata*(conf: BeaconNodeConf): Eth2Metadata =
|
||||
let metadataPath = conf.dataDir / nodeMetadataFilename
|
||||
proc getPersistentNetMetadata*(config: BeaconNodeConf): Eth2Metadata =
|
||||
let metadataPath = config.dataDir / nodeMetadataFilename
|
||||
if not fileExists(metadataPath):
|
||||
result = Eth2Metadata()
|
||||
for i in 0 ..< ATTESTATION_SUBNET_COUNT:
|
||||
|
@ -1058,53 +1058,60 @@ proc onConnEvent(node: Eth2Node, peerId: PeerID, event: ConnEvent) {.async.} =
|
|||
peer = peerId, peer_state = peer.connectionState
|
||||
peer.connectionState = Disconnected
|
||||
|
||||
proc init*(T: type Eth2Node, conf: BeaconNodeConf, enrForkId: ENRForkID,
|
||||
switch: Switch, pubsub: GossipSub, ip: Option[ValidIpAddress],
|
||||
tcpPort, udpPort: Port, privKey: keys.PrivateKey, discovery: bool,
|
||||
rng: ref BrHmacDrbgContext): T =
|
||||
new result
|
||||
result.switch = switch
|
||||
result.pubsub = pubsub
|
||||
result.wantedPeers = conf.maxPeers
|
||||
result.peerPool = newPeerPool[Peer, PeerID](maxPeers = conf.maxPeers)
|
||||
proc new*(T: type Eth2Node, config: BeaconNodeConf, enrForkId: ENRForkID,
|
||||
switch: Switch, pubsub: GossipSub, ip: Option[ValidIpAddress],
|
||||
tcpPort, udpPort: Port, privKey: keys.PrivateKey, discovery: bool,
|
||||
rng: ref BrHmacDrbgContext): T =
|
||||
let
|
||||
metadata = getPersistentNetMetadata(config)
|
||||
when not defined(local_testnet):
|
||||
result.connectTimeout = 1.minutes
|
||||
result.seenThreshold = 5.minutes
|
||||
let
|
||||
connectTimeout = 1.minutes
|
||||
seenThreshold = 5.minutes
|
||||
else:
|
||||
result.connectTimeout = 10.seconds
|
||||
result.seenThreshold = 10.seconds
|
||||
result.seenTable = initTable[PeerID, SeenItem]()
|
||||
result.connTable = initHashSet[PeerID]()
|
||||
# Its important here to create AsyncQueue with limited size, otherwise
|
||||
# it could produce HIGH cpu usage.
|
||||
result.connQueue = newAsyncQueue[PeerAddr](ConcurrentConnections)
|
||||
# TODO: The persistent net metadata should only be used in the case of reusing
|
||||
# the previous netkey.
|
||||
result.metadata = getPersistentNetMetadata(conf)
|
||||
result.forkId = enrForkId
|
||||
result.discovery = Eth2DiscoveryProtocol.new(
|
||||
conf, ip, tcpPort, udpPort, privKey,
|
||||
{"eth2": SSZ.encode(result.forkId), "attnets": SSZ.encode(result.metadata.attnets)},
|
||||
rng)
|
||||
result.discoveryEnabled = discovery
|
||||
result.rng = rng
|
||||
let
|
||||
connectTimeout = 10.seconds
|
||||
seenThreshold = 10.seconds
|
||||
|
||||
newSeq result.protocolStates, allProtocols.len
|
||||
let node = T(
|
||||
switch: switch,
|
||||
pubsub: pubsub,
|
||||
wantedPeers: config.maxPeers,
|
||||
peerPool: newPeerPool[Peer, PeerID](maxPeers = config.maxPeers),
|
||||
# Its important here to create AsyncQueue with limited size, otherwise
|
||||
# it could produce HIGH cpu usage.
|
||||
connQueue: newAsyncQueue[PeerAddr](ConcurrentConnections),
|
||||
# TODO: The persistent net metadata should only be used in the case of reusing
|
||||
# the previous netkey.
|
||||
metadata: metadata,
|
||||
forkId: enrForkId,
|
||||
discovery: Eth2DiscoveryProtocol.new(
|
||||
config, ip, tcpPort, udpPort, privKey,
|
||||
{"eth2": SSZ.encode(enrForkId), "attnets": SSZ.encode(metadata.attnets)},
|
||||
rng),
|
||||
discoveryEnabled: discovery,
|
||||
rng: rng,
|
||||
connectTimeout: connectTimeout,
|
||||
seenThreshold: seenThreshold,
|
||||
)
|
||||
|
||||
newSeq node.protocolStates, allProtocols.len
|
||||
for proto in allProtocols:
|
||||
if proto.networkStateInitializer != nil:
|
||||
result.protocolStates[proto.index] = proto.networkStateInitializer(result)
|
||||
node.protocolStates[proto.index] = proto.networkStateInitializer(node)
|
||||
|
||||
for msg in proto.messages:
|
||||
if msg.protocolMounter != nil:
|
||||
msg.protocolMounter result
|
||||
msg.protocolMounter node
|
||||
|
||||
let node = result
|
||||
proc peerHook(peerId: PeerID, event: ConnEvent): Future[void] {.gcsafe.} =
|
||||
onConnEvent(node, peerId, event)
|
||||
|
||||
switch.addConnEventHandler(peerHook, ConnEventKind.Connected)
|
||||
switch.addConnEventHandler(peerHook, ConnEventKind.Disconnected)
|
||||
|
||||
node
|
||||
|
||||
template publicKey*(node: Eth2Node): keys.PublicKey =
|
||||
node.discovery.privKey.toPublicKey
|
||||
|
||||
|
@ -1306,15 +1313,15 @@ proc p2pProtocolBackendImpl*(p: P2PProtocol): Backend =
|
|||
result.implementProtocolInit = proc (p: P2PProtocol): NimNode =
|
||||
return newCall(initProtocol, newLit(p.name), p.peerInit, p.netInit)
|
||||
|
||||
proc setupNat(conf: BeaconNodeConf): tuple[ip: Option[ValidIpAddress],
|
||||
proc setupNat(config: BeaconNodeConf): tuple[ip: Option[ValidIpAddress],
|
||||
tcpPort: Port,
|
||||
udpPort: Port] =
|
||||
# defaults
|
||||
result.tcpPort = conf.tcpPort
|
||||
result.udpPort = conf.udpPort
|
||||
result.tcpPort = config.tcpPort
|
||||
result.udpPort = config.udpPort
|
||||
|
||||
var nat: NatStrategy
|
||||
case conf.nat.toLowerAscii:
|
||||
case config.nat.toLowerAscii:
|
||||
of "any":
|
||||
nat = NatAny
|
||||
of "none":
|
||||
|
@ -1324,16 +1331,16 @@ proc setupNat(conf: BeaconNodeConf): tuple[ip: Option[ValidIpAddress],
|
|||
of "pmp":
|
||||
nat = NatPmp
|
||||
else:
|
||||
if conf.nat.startsWith("extip:"):
|
||||
if config.nat.startsWith("extip:"):
|
||||
try:
|
||||
# any required port redirection is assumed to be done by hand
|
||||
result.ip = some(ValidIpAddress.init(conf.nat[6..^1]))
|
||||
result.ip = some(ValidIpAddress.init(config.nat[6..^1]))
|
||||
nat = NatNone
|
||||
except ValueError:
|
||||
error "nor a valid IP address", address = conf.nat[6..^1]
|
||||
error "nor a valid IP address", address = config.nat[6..^1]
|
||||
quit QuitFailure
|
||||
else:
|
||||
error "not a valid NAT mechanism", value = conf.nat
|
||||
error "not a valid NAT mechanism", value = config.nat
|
||||
quit QuitFailure
|
||||
|
||||
if nat != NatNone:
|
||||
|
@ -1367,10 +1374,10 @@ template tcpEndPoint(address, port): auto =
|
|||
MultiAddress.init(address, tcpProtocol, port)
|
||||
|
||||
proc getPersistentNetKeys*(rng: var BrHmacDrbgContext,
|
||||
conf: BeaconNodeConf): KeyPair =
|
||||
case conf.cmd
|
||||
config: BeaconNodeConf): KeyPair =
|
||||
case config.cmd
|
||||
of noCommand, record:
|
||||
if conf.netKeyFile == "random":
|
||||
if config.netKeyFile == "random":
|
||||
let res = PrivateKey.random(Secp256k1, rng)
|
||||
if res.isErr():
|
||||
fatal "Could not generate random network key file"
|
||||
|
@ -1386,17 +1393,17 @@ proc getPersistentNetKeys*(rng: var BrHmacDrbgContext,
|
|||
return KeyPair(seckey: privKey, pubkey: privKey.getKey().tryGet())
|
||||
else:
|
||||
let keyPath =
|
||||
if isAbsolute(conf.netKeyFile):
|
||||
conf.netKeyFile
|
||||
if isAbsolute(config.netKeyFile):
|
||||
config.netKeyFile
|
||||
else:
|
||||
conf.dataDir / conf.netKeyFile
|
||||
config.dataDir / config.netKeyFile
|
||||
|
||||
if fileAccessible(keyPath, {AccessFlags.Find}):
|
||||
info "Network key storage is present, unlocking", key_path = keyPath
|
||||
|
||||
# Insecure password used only for automated testing.
|
||||
let insecurePassword =
|
||||
if conf.netKeyInsecurePassword:
|
||||
if config.netKeyInsecurePassword:
|
||||
some(NetworkInsecureKeyPassword)
|
||||
else:
|
||||
none[string]()
|
||||
|
@ -1423,7 +1430,7 @@ proc getPersistentNetKeys*(rng: var BrHmacDrbgContext,
|
|||
|
||||
# Insecure password used only for automated testing.
|
||||
let insecurePassword =
|
||||
if conf.netKeyInsecurePassword:
|
||||
if config.netKeyInsecurePassword:
|
||||
some(NetworkInsecureKeyPassword)
|
||||
else:
|
||||
none[string]()
|
||||
|
@ -1438,15 +1445,15 @@ proc getPersistentNetKeys*(rng: var BrHmacDrbgContext,
|
|||
return KeyPair(seckey: privKey, pubkey: pubKey)
|
||||
|
||||
of createTestnet:
|
||||
if conf.netKeyFile == "random":
|
||||
if config.netKeyFile == "random":
|
||||
fatal "Could not create testnet using `random` network key"
|
||||
quit QuitFailure
|
||||
|
||||
let keyPath =
|
||||
if isAbsolute(conf.netKeyFile):
|
||||
conf.netKeyFile
|
||||
if isAbsolute(config.netKeyFile):
|
||||
config.netKeyFile
|
||||
else:
|
||||
conf.dataDir / conf.netKeyFile
|
||||
config.dataDir / config.netKeyFile
|
||||
|
||||
let rres = PrivateKey.random(Secp256k1, rng)
|
||||
if rres.isErr():
|
||||
|
@ -1458,7 +1465,7 @@ proc getPersistentNetKeys*(rng: var BrHmacDrbgContext,
|
|||
|
||||
# Insecure password used only for automated testing.
|
||||
let insecurePassword =
|
||||
if conf.netKeyInsecurePassword:
|
||||
if config.netKeyInsecurePassword:
|
||||
some(NetworkInsecureKeyPassword)
|
||||
else:
|
||||
none[string]()
|
||||
|
@ -1501,7 +1508,7 @@ func msgIdProvider(m: messages.Message): seq[byte] =
|
|||
except CatchableError:
|
||||
gossipId(m.data, false)
|
||||
|
||||
proc newBeaconSwitch*(conf: BeaconNodeConf, seckey: PrivateKey,
|
||||
proc newBeaconSwitch*(config: BeaconNodeConf, seckey: PrivateKey,
|
||||
address: MultiAddress,
|
||||
rng: ref BrHmacDrbgContext): Switch =
|
||||
proc createMplex(conn: Connection): Muxer =
|
||||
|
@ -1514,7 +1521,7 @@ proc newBeaconSwitch*(conf: BeaconNodeConf, seckey: PrivateKey,
|
|||
muxers = {MplexCodec: mplexProvider}.toTable
|
||||
secureManagers = [Secure(newNoise(rng, seckey))]
|
||||
|
||||
peerInfo.agentVersion = conf.agentString
|
||||
peerInfo.agentVersion = config.agentString
|
||||
|
||||
let identify = newIdentify(peerInfo)
|
||||
|
||||
|
@ -1524,15 +1531,15 @@ proc newBeaconSwitch*(conf: BeaconNodeConf, seckey: PrivateKey,
|
|||
identify,
|
||||
muxers,
|
||||
secureManagers,
|
||||
maxConnections = conf.maxPeers)
|
||||
maxConnections = config.maxPeers)
|
||||
|
||||
proc createEth2Node*(rng: ref BrHmacDrbgContext,
|
||||
conf: BeaconNodeConf,
|
||||
config: BeaconNodeConf,
|
||||
netKeys: KeyPair,
|
||||
enrForkId: ENRForkID): Eth2Node =
|
||||
var
|
||||
(extIp, extTcpPort, extUdpPort) = setupNat(conf)
|
||||
hostAddress = tcpEndPoint(conf.listenAddress, conf.tcpPort)
|
||||
(extIp, extTcpPort, extUdpPort) = setupNat(config)
|
||||
hostAddress = tcpEndPoint(config.listenAddress, config.tcpPort)
|
||||
announcedAddresses = if extIp.isNone(): @[]
|
||||
else: @[tcpEndPoint(extIp.get(), extTcpPort)]
|
||||
|
||||
|
@ -1543,7 +1550,7 @@ proc createEth2Node*(rng: ref BrHmacDrbgContext,
|
|||
# TODO nim-libp2p still doesn't have support for announcing addresses
|
||||
# that are different from the host address (this is relevant when we
|
||||
# are running behind a NAT).
|
||||
var switch = newBeaconSwitch(conf, netKeys.seckey, hostAddress, rng)
|
||||
var switch = newBeaconSwitch(config, netKeys.seckey, hostAddress, rng)
|
||||
|
||||
let
|
||||
params = GossipSubParams(
|
||||
|
@ -1587,11 +1594,11 @@ proc createEth2Node*(rng: ref BrHmacDrbgContext,
|
|||
|
||||
switch.mount(pubsub)
|
||||
|
||||
result = Eth2Node.init(conf, enrForkId, switch, pubsub,
|
||||
extIp, extTcpPort, extUdpPort,
|
||||
netKeys.seckey.asEthKey,
|
||||
discovery = conf.discv5Enabled,
|
||||
rng = rng)
|
||||
Eth2Node.new(config, enrForkId, switch, pubsub,
|
||||
extIp, extTcpPort, extUdpPort,
|
||||
netKeys.seckey.asEthKey,
|
||||
discovery = config.discv5Enabled,
|
||||
rng = rng)
|
||||
|
||||
proc announcedENR*(node: Eth2Node): enr.Record =
|
||||
doAssert node.discovery != nil, "The Eth2Node must be initialized"
|
||||
|
|
|
@ -5,7 +5,7 @@ import
|
|||
spec/[datatypes, digest, crypto, keystore],
|
||||
stew/io2, libp2p/crypto/crypto as lcrypto,
|
||||
nimcrypto/utils as ncrutils,
|
||||
conf, ssz/merkleization, network_metadata, filepath
|
||||
"."/[conf, ssz/merkleization, network_metadata, filepath]
|
||||
|
||||
export
|
||||
keystore
|
||||
|
@ -280,13 +280,13 @@ iterator validatorKeysFromDirs*(validatorsDir, secretsDir: string): ValidatorPri
|
|||
except OSError:
|
||||
quit 1
|
||||
|
||||
iterator validatorKeys*(conf: BeaconNodeConf|ValidatorClientConf): ValidatorPrivKey =
|
||||
let validatorsDir = conf.validatorsDir
|
||||
iterator validatorKeys*(config: BeaconNodeConf|ValidatorClientConf): ValidatorPrivKey =
|
||||
let validatorsDir = config.validatorsDir
|
||||
try:
|
||||
for kind, file in walkDir(validatorsDir):
|
||||
if kind == pcDir:
|
||||
let keyName = splitFile(file).name
|
||||
let key = loadKeystore(validatorsDir, conf.secretsDir, keyName, conf.nonInteractive)
|
||||
let key = loadKeystore(validatorsDir, config.secretsDir, keyName, config.nonInteractive)
|
||||
if key.isSome:
|
||||
yield key.get
|
||||
else:
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -64,7 +64,7 @@ proc addLocalValidator*(node: BeaconNode,
|
|||
state: BeaconState,
|
||||
privKey: ValidatorPrivKey) =
|
||||
let pubKey = privKey.toPubKey()
|
||||
node.attachedValidators.addLocalValidator(
|
||||
node.attachedValidators[].addLocalValidator(
|
||||
pubKey, privKey, findValidator(state, pubKey))
|
||||
|
||||
proc addLocalValidators*(node: BeaconNode) =
|
||||
|
@ -87,11 +87,11 @@ proc addRemoteValidators*(node: BeaconNode) =
|
|||
inStream: node.vcProcess.inputStream,
|
||||
outStream: node.vcProcess.outputStream,
|
||||
pubKeyStr: $key))
|
||||
node.attachedValidators.addRemoteValidator(key, v)
|
||||
node.attachedValidators[].addRemoteValidator(key, v)
|
||||
|
||||
proc getAttachedValidator*(node: BeaconNode,
|
||||
pubkey: ValidatorPubKey): AttachedValidator =
|
||||
node.attachedValidators.getValidator(pubkey)
|
||||
node.attachedValidators[].getValidator(pubkey)
|
||||
|
||||
proc getAttachedValidator*(node: BeaconNode,
|
||||
state: BeaconState,
|
||||
|
@ -464,7 +464,7 @@ proc handleProposal(node: BeaconNode, head: BlockRef, slot: Slot):
|
|||
return head
|
||||
|
||||
let validator =
|
||||
node.attachedValidators.getValidator(proposer.get()[1])
|
||||
node.attachedValidators[].getValidator(proposer.get()[1])
|
||||
|
||||
if validator != nil:
|
||||
return await proposeBlock(node, validator, proposer.get()[0], head, slot)
|
||||
|
@ -569,7 +569,7 @@ proc updateValidatorMetrics*(node: BeaconNode) =
|
|||
|
||||
var total: Gwei
|
||||
var i = 0
|
||||
for _, v in node.attachedValidators.validators:
|
||||
for _, v in node.attachedValidators[].validators:
|
||||
let balance =
|
||||
if v.index.isNone():
|
||||
0.Gwei
|
||||
|
@ -597,7 +597,7 @@ proc updateValidatorMetrics*(node: BeaconNode) =
|
|||
|
||||
proc handleValidatorDuties*(node: BeaconNode, lastSlot, slot: Slot) {.async.} =
|
||||
## Perform validator duties - create blocks, vote and aggregate existing votes
|
||||
if node.attachedValidators.count == 0:
|
||||
if node.attachedValidators[].count == 0:
|
||||
# Nothing to do because we have no validator attached
|
||||
return
|
||||
|
||||
|
|
Loading…
Reference in New Issue