added wrappers for execution an consensus layers

This commit is contained in:
Pedro Miranda 2024-10-19 02:31:37 +01:00
parent 1804471dc9
commit 14d5488062
3 changed files with 59 additions and 30 deletions

View File

@ -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"

View File

@ -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

View File

@ -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: