small repairs and additions

This commit is contained in:
Pedro Miranda 2024-10-23 12:10:35 +01:00
parent 7b15c09b45
commit 79aa0fb46e
4 changed files with 34 additions and 19 deletions

View File

@ -8,8 +8,10 @@
[![Status: #nimbus-general](https://img.shields.io/badge/status-nimbus--general-orange.svg)](https://join.status.im/nimbus-general)
# NOTE - whole document to be concluded...
# description
Nimbus Unified combines Ethereum execution and consensus layer functionalities, featuring a fully integrated beacon node), validator duties, and execution layer support. This setup allows the Nimbus client to handle both Ethereum consensus (Eth2) and execution (Eth1) tasks within a single package.
Nimbus Unified combines Ethereum execution and consensus layer functionalities, featuring a fully integrated beacon node, validator duties, and execution layer support. This setup allows the Nimbus client to handle both Ethereum consensus (Eth2) and execution (Eth1) tasks within a single package.
--> meh, requires improvement
# documentation
@ -45,4 +47,4 @@ or
* Apache License, Version 2.0: [LICENSE-APACHEv2](LICENSE-APACHEv2) or https://www.apache.org/licenses/LICENSE-2.0
at your option. These files may not be copied, modified, or distributed except according to those terms.
These files may not be copied, modified, or distributed except according to those terms.

View File

@ -12,7 +12,8 @@ type NimbusTasksError* = object of CatchableError
## Configuration
## TODO: implement a json (or other format like yaml) config reader for config reading (file config scenarios)
## TODO: implement a command line reader to read arguments
## 1) implement a command line reader to read arguments
## 2) good option to adhere to other projects conventions and use the in place support to read and load
type NimbusConfig* = object
configTable: Table[string, string]
@ -20,16 +21,19 @@ type NimbusConfig* = object
type TaskParameters* = object
name*: string
configs*: string
beaconNodeConfigs*: BeaconNodeConf
# TODO: replace this with the extracted configs from NimbusConfig needed by the worker
beaconNodeConfigs*: BeaconNodeConf #
## Task shutdown flag
##
## The behaviour required: this thread needs to atomically change the flag value when
## a shutdown is required or when detects a stopped thread.
##
## Given the behaviour wanted, atomic operations are sufficient without barriers or fences. Compilers
## may reorder instructions, but given that the order is not important, this does not affect
## the semantic wanted: If instructions are reordered, the worker will fail to read on the current iteration
## but will read it correctly on the next iteration ( this thread is the only on which changes the flag behaviour,
## and will always change it to true)
##
## With this we avoid the overhead of locks
var isShutDownRequired*: Atomic[bool]
isShutDownRequired.store(false)

View File

@ -23,7 +23,7 @@ logScope:
topics = "Consensus layer"
## following procedures are copies from nimbus_beacon_node.nim.
## TODO: extract from that file into a common file
## TODO: if possible, extract from that file into a common file
## runs beacon node
## adapted from nimbus-eth2
@ -62,6 +62,7 @@ proc doRunBeaconNode(
# except Exception as exc:
# raiseAssert exc.msg # TODO fix metrics
## adapted/copied from nimbus-eth2
proc fetchGenesisState(
metadata: Eth2NetworkMetadata,
genesisState = none(InputFile),
@ -96,6 +97,7 @@ proc fetchGenesisState(
else:
nil
## adapted/copied from nimbus-eth2
proc doRunTrustedNodeSync(
db: BeaconChainDB,
metadata: Eth2NetworkMetadata,
@ -138,7 +140,7 @@ proc consensusWrapper*(parameters: TaskParameters) {.raises: [CatchableError].}
doRunBeaconNode(config, rng)
except CatchableError as e:
fatal "error", message = e.msg
quit 1
# TODO: we need to create an dedicated atomic asking task manager to join threads
let
metadata = loadEth2Network(config)
@ -149,16 +151,18 @@ proc consensusWrapper*(parameters: TaskParameters) {.raises: [CatchableError].}
waitFor(
db.doRunTrustedNodeSync(
metadata, config.databaseDir, config.eraDir, "http://127.0.0.1:5052",
config.stateId, config.lcTrustedBlockRoot, config.backfillBlocks, config.reindex,
config.downloadDepositSnapshot, genesisState,
config.stateId, config.lcTrustedBlockRoot, config.backfillBlocks,
config.reindex, config.downloadDepositSnapshot, genesisState,
)
)
except CatchableError as e:
fatal "error", message = e.msg
quit 1
# TODO: we need to create an dedicated atomic asking task manager to join threads
fatal "error", message = e.MsgSource
db.close()
# TODO: nice to start creating some binary launch scripts
# --web3-url=http://127.0.0.1:8551 --jwt-secret=/tmp/jwtsecret --log-level=TRACE
# --network=${NETWORK} \
# --data-dir="${DATA_DIR}" \

View File

@ -15,12 +15,10 @@ import
beacon_chain/[beacon_chain_db]
## Constants
## TODO: evaluate the proposed timeouts with team
const cNimbusMaxTasks* = 5
const cNimbusTaskTimeoutMs* = 5000
## Exceptions
type NimbusTasksError* = object of CatchableError
## Task and associated task information
type NimbusTask* = ref object
name*: string
@ -99,7 +97,12 @@ proc addNewTask*(
if currentIndex < 0:
raise newException(NimbusTasksError, "No free slots on Nimbus Tasks")
createThread(tasks.taskList[currentIndex].threadHandler, taskHandler, parameters)
try:
createThread(tasks.taskList[currentIndex].threadHandler, taskHandler, parameters)
except CatchableError as e:
# TODO: joinThreads
fatal "error creating task (thread)", msg=e.msg
info "Created task:", task = tasks.taskList[currentIndex].name
## Task monitoring
@ -109,8 +112,8 @@ proc monitor*(tasksList: var NimbusTasks, config: NimbusConfig) =
while true:
info "checking tasks ... "
# -check an atomic (to be created when needed) if it s required to shutdown
# this will atomic flag solves:
# -check tasks flag (to be created when needed) if it's required to shutdown
# this atomic flag solves:
# - non responding thread
# - thread that required shutdown
@ -123,7 +126,8 @@ proc startTasks*(
let
# TODO: extract configs for each task from NimbusConfig
# or extract them somewhere else and passs them here
# or extract them somewhere else and passs them here.
# check nimbus_configs annotations.
execName = "Execution Layer"
consName = "Consensus Layer"
var
@ -149,7 +153,7 @@ when isMainModule:
## - file limits
## - check if we have permissions to create data folder if needed
## - setup logging
## - read configuration
## - read configuration (check nimbus_configs file anottations)
## - implement config reader for all components
let nimbusConfigs = NimbusConfig()
var tasksList: NimbusTasks = NimbusTasks.new
@ -168,6 +172,7 @@ when isMainModule:
tasksList.startTasks(nimbusConfigs, beaconNodeConfig)
## Graceful shutdown by handling of Ctrl+C signal
## TODO: we might need to declare it per thread
proc controlCHandler() {.noconv.} =
when defined(windows):
# workaround for https://github.com/nim-lang/Nim/issues/4057