From 14d5488062a2baf3594a30f60d888c72dd32543b Mon Sep 17 00:00:00 2001 From: Pedro Miranda Date: Sat, 19 Oct 2024 02:31:37 +0100 Subject: [PATCH] added wrappers for execution an consensus layers --- .../consensus/consensus_wrapper.nim | 23 ++++++++++ .../execution/execution_wrapper.nim | 24 +++++++++++ nimbus_unified/nimbus_unified.nim | 42 ++++++------------- 3 files changed, 59 insertions(+), 30 deletions(-) create mode 100644 nimbus_unified/consensus/consensus_wrapper.nim create mode 100644 nimbus_unified/execution/execution_wrapper.nim diff --git a/nimbus_unified/consensus/consensus_wrapper.nim b/nimbus_unified/consensus/consensus_wrapper.nim new file mode 100644 index 000000000..0182ffb5e --- /dev/null +++ b/nimbus_unified/consensus/consensus_wrapper.nim @@ -0,0 +1,23 @@ +# nimbus_unified +# Copyright (c) 2024 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. + +import chronicles, std/[os, atomics], ../configs/nimbus_configs +export nimbus_configs + +## log +logScope: + topics = "Consensus layer" + +proc consensusWrapper*(parameters: TaskParameters) = + info "Consensus wrapper:", worker = parameters.name + while true: + sleep(3000) + info "looping consensus" + if isShutDownRequired.load() == true: + break + + warn "\tExiting consensus wrapper" diff --git a/nimbus_unified/execution/execution_wrapper.nim b/nimbus_unified/execution/execution_wrapper.nim new file mode 100644 index 000000000..21522849c --- /dev/null +++ b/nimbus_unified/execution/execution_wrapper.nim @@ -0,0 +1,24 @@ +# nimbus_unified +# Copyright (c) 2024 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. + +import chronicles, std/[os, atomics], ../configs/nimbus_configs +export nimbus_configs + +## log +logScope: + topics = "Execution layer" + +proc executionWrapper*(parameters: TaskParameters) = + info "Execution wrapper:", worker = parameters.name + + while true: + sleep(2000) + info "looping execution" + if isShutDownRequired.load() == true: + break + + warn "\tExiting execution:", worker = parameters.name diff --git a/nimbus_unified/nimbus_unified.nim b/nimbus_unified/nimbus_unified.nim index 27ab23205..4271cc602 100644 --- a/nimbus_unified/nimbus_unified.nim +++ b/nimbus_unified/nimbus_unified.nim @@ -5,39 +5,26 @@ # * 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. -import std/[atomics, os, tables], chronicles, beacon_chain/nimbus_binary_common - -## Exceptions -type NimbusTasksError* = object of CatchableError - -#task shutdown flag -var isShutDownRequired*: Atomic[bool] -isShutDownRequired.store(false) - -## Configuration -## TODO: implement a json (or other format like yaml) config reader for config reading (file config scenarios) -## or extract from other nimbus components -## TODO: implement a command line reader to read arguments -type NimbusConfig* = object - configTable: Table[string, string] - -## Nimbus workers arguments (thread arguments) -type TaskParameters* = object - name*: string - configs*: string - # TODO: replace this with the extracted configs from NimbusConfig needed by the worker +import + std/[atomics, os], + chronicles, + consensus/consensus_wrapper, + execution/execution_wrapper ## Constants const cNimbusMaxTasks* = 5 const cNimbusTaskTimeoutMs* = 5000 +## Exceptions +type NimbusTasksError* = object of CatchableError + ## Task and associated task information type NimbusTask* = ref object name*: string timeoutMs*: uint32 threadHandler*: Thread[TaskParameters] -## Task scheduler and manager +## Task manager type NimbusTasks* = ref object taskList*: array[cNimbusMaxTasks, NimbusTask] @@ -53,8 +40,7 @@ logScope: proc executionLayerHandler(parameters: TaskParameters) {.thread.} = info "Started task:", task = parameters.name while true: - sleep(3000) - info "exec" + executionWrapper(parameters) if isShutDownRequired.load() == true: break info "\tExiting task;", task = parameters.name @@ -62,14 +48,10 @@ proc executionLayerHandler(parameters: TaskParameters) {.thread.} = ## Consensus Layer handler proc consensusLayerHandler(parameters: TaskParameters) {.thread.} = info "Started task:", task = parameters.name - while true: - sleep(3000) - info "exec" - if isShutDownRequired.load() == true: - break + consensusWrapper(parameters) info "\tExiting task:", task = parameters.name -## Waits for tasks to finish +## Waits for tasks to finish (joinThreads) proc joinTasks(tasks: var NimbusTasks) = for i in 0 .. cNimbusMaxTasks - 1: if not tasks.taskList[i].isNil: