mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-21 00:08:28 +00:00
refactored types
This commit is contained in:
parent
0c202a7852
commit
2b9aadb4b9
@ -20,6 +20,7 @@ type NimbusConfig* = object
|
|||||||
type TaskParameters* = object
|
type TaskParameters* = object
|
||||||
name*: string
|
name*: string
|
||||||
configs*: string
|
configs*: string
|
||||||
|
beaconNodeConfigs*: BeaconNodeConf
|
||||||
# TODO: replace this with the extracted configs from NimbusConfig needed by the worker
|
# TODO: replace this with the extracted configs from NimbusConfig needed by the worker
|
||||||
|
|
||||||
## Task shutdown flag
|
## Task shutdown flag
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
# * 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.
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
|
-d:"libp2p_pki_schemes=secp256k1"
|
||||||
|
|
||||||
-d:"chronicles_sinks=textlines[dynamic],json[dynamic]"
|
-d:"chronicles_sinks=textlines[dynamic],json[dynamic]"
|
||||||
-d:"chronicles_runtime_filtering=on"
|
-d:"chronicles_runtime_filtering=on"
|
||||||
-d:"chronicles_disable_thread_id"
|
-d:"chronicles_disable_thread_id"
|
||||||
@ -12,3 +14,4 @@
|
|||||||
@if release:
|
@if release:
|
||||||
-d:"chronicles_line_numbers:0"
|
-d:"chronicles_line_numbers:0"
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -9,7 +9,9 @@ import
|
|||||||
std/[atomics, os],
|
std/[atomics, os],
|
||||||
chronicles,
|
chronicles,
|
||||||
consensus/consensus_wrapper,
|
consensus/consensus_wrapper,
|
||||||
execution/execution_wrapper
|
execution/execution_wrapper,
|
||||||
|
beacon_chain/[conf, conf_common],
|
||||||
|
beacon_chain/[beacon_chain_db]
|
||||||
|
|
||||||
## Constants
|
## Constants
|
||||||
const cNimbusMaxTasks* = 5
|
const cNimbusMaxTasks* = 5
|
||||||
@ -69,7 +71,6 @@ proc joinTasks(tasks: var NimbusTasks) =
|
|||||||
## Note that thread handler passed by argument needs to have the signature: proc foobar(NimbusParameters)
|
## Note that thread handler passed by argument needs to have the signature: proc foobar(NimbusParameters)
|
||||||
proc addNewTask*(
|
proc addNewTask*(
|
||||||
tasks: var NimbusTasks,
|
tasks: var NimbusTasks,
|
||||||
name: string,
|
|
||||||
timeout: uint32,
|
timeout: uint32,
|
||||||
taskHandler: proc(config: TaskParameters) {.thread.},
|
taskHandler: proc(config: TaskParameters) {.thread.},
|
||||||
parameters: var TaskParameters,
|
parameters: var TaskParameters,
|
||||||
@ -79,10 +80,10 @@ proc addNewTask*(
|
|||||||
for i in 0 .. cNimbusMaxTasks - 1:
|
for i in 0 .. cNimbusMaxTasks - 1:
|
||||||
if tasks.taskList[i].isNil:
|
if tasks.taskList[i].isNil:
|
||||||
tasks.taskList[i] = NimbusTask.new
|
tasks.taskList[i] = NimbusTask.new
|
||||||
tasks.taskList[i].name = name
|
tasks.taskList[i].name = parameters.name
|
||||||
tasks.taskList[i].timeoutMs = timeout
|
tasks.taskList[i].timeoutMs = timeout
|
||||||
currentIndex = i
|
currentIndex = i
|
||||||
parameters.name = name
|
parameters.name = parameters.name
|
||||||
break
|
break
|
||||||
|
|
||||||
if currentIndex < 0:
|
if currentIndex < 0:
|
||||||
@ -100,48 +101,61 @@ proc monitor*(tasksList: var NimbusTasks, config: NimbusConfig) =
|
|||||||
|
|
||||||
# -check an atomic (to be created when needed) if it s required to shutdown
|
# -check an atomic (to be created when needed) if it s required to shutdown
|
||||||
# this will atomic flag solves:
|
# this will atomic flag solves:
|
||||||
# - non responding thread
|
# - non responding thread
|
||||||
# - thread that required shutdown
|
# - thread that required shutdown
|
||||||
|
|
||||||
sleep(cNimbusTaskTimeoutMs)
|
sleep(cNimbusTaskTimeoutMs)
|
||||||
|
|
||||||
## create running workers
|
## create running workers
|
||||||
proc startTasks*(tasksList: var NimbusTasks, configs: NimbusConfig) =
|
proc startTasks*(
|
||||||
# TODO: extract configs for each task from NimbusConfig
|
tasksList: var NimbusTasks, configs: NimbusConfig, beaconConfigs: var BeaconNodeConf
|
||||||
# or extract them somewhere else and passs them here
|
) =
|
||||||
var
|
let
|
||||||
paramsExecution: TaskParameters =
|
|
||||||
TaskParameters(configs: "task configs extracted from NimbusConfig go here")
|
|
||||||
paramsConsensus: TaskParameters =
|
|
||||||
TaskParameters(configs: "task configs extracted from NimbusConfig go here")
|
|
||||||
|
|
||||||
tasksList.addNewTask(
|
# TODO: extract configs for each task from NimbusConfig
|
||||||
"Execution Layer", cNimbusTaskTimeoutMs, executionLayerHandler, paramsExecution
|
# or extract them somewhere else and passs them here
|
||||||
)
|
execName = "Execution Layer"
|
||||||
tasksList.addNewTask(
|
consName = "Consensus Layer"
|
||||||
"Consensus Layer", cNimbusTaskTimeoutMs, consensusLayerHandler, paramsConsensus
|
var
|
||||||
)
|
paramsExecution: TaskParameters = TaskParameters(
|
||||||
|
name: execName,
|
||||||
|
configs: "task configs extracted from NimbusConfig go here",
|
||||||
|
beaconNodeConfigs: beaconConfigs,
|
||||||
|
)
|
||||||
|
paramsConsensus: TaskParameters = TaskParameters(
|
||||||
|
name: execName,
|
||||||
|
configs: "task configs extracted from NimbusConfig go here",
|
||||||
|
beaconNodeConfigs: beaconConfigs,
|
||||||
|
)
|
||||||
|
|
||||||
|
tasksList.addNewTask(cNimbusTaskTimeoutMs, executionLayerHandler, paramsExecution)
|
||||||
|
tasksList.addNewTask(cNimbusTaskTimeoutMs, consensusLayerHandler, paramsConsensus)
|
||||||
|
|
||||||
# ------
|
# ------
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
info "Starting Nimbus"
|
info "Starting Nimbus"
|
||||||
## TODO
|
## TODO
|
||||||
## - make banner and config
|
|
||||||
## - file limits
|
## - file limits
|
||||||
## - check if we have permissions to create data folder if needed
|
## - check if we have permissions to create data folder if needed
|
||||||
## - setup logging
|
## - setup logging
|
||||||
|
## - read configuration
|
||||||
# TODO - read configuration
|
## - implement config reader for all components
|
||||||
# TODO - implement config reader for all components
|
|
||||||
let nimbusConfigs = NimbusConfig()
|
let nimbusConfigs = NimbusConfig()
|
||||||
var tasksList: NimbusTasks = NimbusTasks.new
|
var tasksList: NimbusTasks = NimbusTasks.new
|
||||||
|
|
||||||
## this code snippet requires a conf.nim file (eg: beacon_lc_bridge_conf.nim)
|
##TODO: this is an adapted call os the vars required by makeBannerAndConfig
|
||||||
# var config = makeBannerAndConfig("Nimbus client ", NimbusConfig)
|
##these values need to be read from some config file
|
||||||
# setupLogging(config.logLevel, config.logStdout, config.logFile)
|
const SPEC_VERSION = "1.5.0-alpha.8"
|
||||||
|
const copyrights = "status"
|
||||||
|
const nimBanner = "nimbus"
|
||||||
|
const clientId = "beacon node"
|
||||||
|
var beaconNodeConfig = makeBannerAndConfig(
|
||||||
|
clientId, copyrights, nimBanner, SPEC_VERSION, [], BeaconNodeConf
|
||||||
|
).valueOr:
|
||||||
|
quit(0)
|
||||||
|
|
||||||
tasksList.startTasks(nimbusConfigs)
|
tasksList.startTasks(nimbusConfigs, beaconNodeConfig)
|
||||||
|
|
||||||
## Graceful shutdown by handling of Ctrl+C signal
|
## Graceful shutdown by handling of Ctrl+C signal
|
||||||
proc controlCHandler() {.noconv.} =
|
proc controlCHandler() {.noconv.} =
|
||||||
@ -158,6 +172,7 @@ when isMainModule:
|
|||||||
tasksList.joinTasks()
|
tasksList.joinTasks()
|
||||||
notice "Shutting down now"
|
notice "Shutting down now"
|
||||||
quit(0)
|
quit(0)
|
||||||
|
|
||||||
setControlCHook(controlCHandler)
|
setControlCHook(controlCHandler)
|
||||||
|
|
||||||
#start monitoring
|
#start monitoring
|
||||||
|
Loading…
x
Reference in New Issue
Block a user