Skip to content

Commit 1f5d0ba

Browse files
author
pmmiranda
committed
refined initial project:
- removed dead code. - removed some structures not needed yet - thread communication with shared data via channels.
1 parent 3df62ff commit 1f5d0ba

File tree

9 files changed

+216
-156
lines changed

9 files changed

+216
-156
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,17 +360,17 @@ libnimbusevm: | build deps
360360

361361
# usual cleaning
362362
clean: | clean-common
363-
rm -rf build/{nimbus,nimbus_execution_client,fluffy,libverifproxy,nimbus_verified_proxy,$(TOOLS_CSV),$(FLUFFY_TOOLS_CSV),all_tests,test_kvstore_rocksdb,test_rpc,all_fluffy_tests,all_history_network_custom_chain_tests,test_portal_testnet,utp_test_app,utp_test,*.dSYM}
363+
rm -rf build/{nimbus_client,nimbus_execution_client,fluffy,libverifproxy,nimbus_verified_proxy,$(TOOLS_CSV),$(FLUFFY_TOOLS_CSV),all_tests,test_kvstore_rocksdb,test_rpc,all_fluffy_tests,all_history_network_custom_chain_tests,test_portal_testnet,utp_test_app,utp_test,*.dSYM}
364364
rm -rf tools/t8n/{t8n,t8n_test}
365365
rm -rf tools/evmstate/{evmstate,evmstate_test}
366366
ifneq ($(USE_LIBBACKTRACE), 0)
367367
+ $(MAKE) -C vendor/nim-libbacktrace clean $(HANDLE_OUTPUT)
368368
endif
369369

370370
# Nimbus
371-
nimbus: | build deps rocksdb
371+
nimbus: | build deps
372372
echo -e $(BUILD_MSG) "build/$@" && \
373-
$(ENV_SCRIPT) nim c $(NIM_PARAMS) -d:release --parallelBuild:1 -d:libp2p_pki_schemes=secp256k1 -u:metrics -o:build/nimbus "nimbus/nimbus.nim"
373+
$(ENV_SCRIPT) nim c $(NIM_PARAMS) --threads:on -d:chronicles_log_level=TRACE -o:build/nimbus_client "nimbus/nimbus.nim"
374374

375375
all_tests_nimbus: | build deps
376376
echo -e $(BUILD_MSG) "build/$@" && \

nimbus/common/utils.nim

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Nimbus
2+
# Copyright (c) 2025 Status Research & Development GmbH
3+
# Licensed and distributed under either of
4+
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
5+
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
6+
# at your option. This file may not be copied, modified, or distributed except according to those terms.
7+
8+
{.push raises: [].}
9+
10+
import results
11+
export results
12+
13+
#Parses specific data from a given channel if given in following binary format:
14+
# (array size Uint) | [ (element size Uint) (element data)]
15+
proc parseChannelData*(p: pointer): Result[seq[string], string] =
16+
# Start reading from base pointer
17+
var readOffset = cast[uint](p)
18+
var recoveredStrings: seq[string]
19+
var totalSize: uint = 0
20+
21+
# length
22+
copyMem(addr totalSize, cast[pointer](readOffset), sizeof(uint))
23+
readOffset += uint(sizeof(uint))
24+
25+
while readOffset < cast[uint](p) + totalSize:
26+
#seq element size
27+
var strLen: uint
28+
copyMem(addr strLen, cast[pointer](readOffset), sizeof(uint))
29+
readOffset += uint(sizeof(uint))
30+
31+
#element
32+
var strData = newString(strLen)
33+
copyMem(addr strData[0], cast[pointer](readOffset), uint(strLen))
34+
readOffset += uint(strLen)
35+
36+
recoveredStrings.add(strData)
37+
38+
ok recoveredStrings

nimbus/conf.nim

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,27 @@
55
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
66
# at your option. This file may not be copied, modified, or distributed except according to those terms.
77

8+
{.push raises: [].}
9+
810
import
911
std/[os, atomics],
10-
chronicles,
11-
options,
12-
#eth2-configs
13-
beacon_chain/nimbus_binary_common,
14-
#eth1-configs
15-
../../execution_chain/nimbus_desc
12+
chronicles
1613

17-
export BeaconNodeConf, NimbusConf
14+
## log
15+
logScope:
16+
topics = "Service manager"
1817

1918
## Exceptions
2019
type NimbusServiceError* = object of CatchableError
2120

2221
## Constants
23-
## TODO: evaluate the proposed timeouts
24-
const cNimbusMaxServices* = 2
25-
const cNimbusServiceTimeoutMs* = 3000
22+
const
23+
cNimbusServiceTimeoutMs* = 3000
24+
cThreadTimeAck* = 10
2625

27-
## log
28-
logScope:
29-
topics = "Service manager"
26+
# configuration read by threads
27+
var isConfigRead*: Atomic[bool]
28+
isConfigRead.store(false)
3029

3130
## Nimbus service arguments
3231
type
@@ -37,25 +36,21 @@ type
3736
LayerConfig* = object
3837
case kind*: ConfigKind
3938
of Consensus:
40-
consensusConfig*: seq[string]
39+
consensusOptions*: seq[string]
4140
of Execution:
42-
executionConfig*: seq[string]
41+
executionOptions*: seq[string]
4342

4443
NimbusService* = ref object
4544
name*: string
4645
layerConfig*: LayerConfig
4746
serviceHandler*: Thread[ptr Channel[pointer]]
48-
serviceChannel: ptr Channel[pointer]
47+
serviceChannel*: ptr Channel[pointer] = nil
48+
serviceFunc*: proc(ch: ptr Channel[pointer]) {.thread.}
4949

5050
Nimbus* = ref object
5151
serviceList*: seq[NimbusService]
5252

53-
#replace with cond var
54-
## Service shutdown
55-
var isShutDownRequired*: Atomic[bool]
56-
isShutDownRequired.store(false)
57-
58-
# filesystem specs
53+
## filesystem specs
5954
proc defaultDataDir*(): string =
6055
let dataDir =
6156
when defined(windows):

nimbus/consensus/consensus_layer.nim

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,37 @@
55
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
66
# at your option. This file may not be copied, modified, or distributed except according to those terms.
77

8-
import std/[atomics, os], chronicles, ../configs/nimbus_configs
8+
{.push raises: [].}
99

10-
export nimbus_configs
10+
import std/[atomics, os], chronicles, ../conf, ../common/utils
1111

1212
logScope:
1313
topics = "Consensus layer"
1414

15-
proc consensusLayer*(params: ServiceParameters) {.raises: [CatchableError].} =
16-
var config = params.layerConfig
15+
## Consensus Layer handler
16+
proc consensusLayerHandler*(channel: ptr Channel[pointer]) =
17+
var p: pointer
18+
try:
19+
p = channel[].recv()
20+
except Exception as e:
21+
fatal " service unable to receive configuration", err = e.msg
22+
quit(QuitFailure)
23+
24+
let configs = parseChannelData(p).valueOr:
25+
fatal "unable to parse service data", message = error
26+
quit(QuitFailure)
1727

18-
doAssert config.kind == Consensus
28+
info "consensus configs", params = configs
29+
echo configs
30+
31+
#signal main thread that data is read
32+
isConfigRead.store(true)
1933

2034
try:
21-
while isShutDownRequired.load() == false:
35+
while true:
2236
info "consensus ..."
2337
sleep(cNimbusServiceTimeoutMs + 1000)
24-
25-
isShutDownRequired.store(true)
2638
except CatchableError as e:
2739
fatal "error", message = e.msg
28-
isShutDownRequired.store(true)
2940

30-
isShutDownRequired.store(true)
3141
warn "\tExiting consensus layer"

nimbus/execution/execution_layer.nim

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,37 @@
55
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
66
# at your option. This file may not be copied, modified, or distributed except according to those terms.
77

8-
import std/[atomics, os], chronicles, ../configs/nimbus_configs
8+
{.push raises: [].}
99

10-
export nimbus_configs
10+
import std/[atomics, os], chronicles, ../conf, ../common/utils
1111

1212
logScope:
1313
topics = "Execution layer"
1414

15-
proc executionLayer*(params: ServiceParameters) {.raises: [CatchableError].} =
16-
var config = params.layerConfig
15+
## Execution Layer handler
16+
proc executionLayerHandler*(channel: ptr Channel[pointer]) =
17+
var p: pointer
18+
try:
19+
p = channel[].recv()
20+
except Exception as e:
21+
fatal "service unable to receive configuration", err = e.msg
22+
quit(QuitFailure)
23+
24+
let configs = parseChannelData(p).valueOr:
25+
fatal "unable to parse service data", message = error
26+
quit(QuitFailure)
1727

18-
doAssert config.kind == Execution
28+
info "execution configs", params = configs
29+
echo configs
30+
31+
#signal main thread that data is read
32+
isConfigRead.store(true)
1933

2034
try:
21-
while isShutDownRequired.load() == false:
35+
while true:
2236
info "execution ..."
2337
sleep(cNimbusServiceTimeoutMs)
24-
25-
isShutDownRequired.store(true)
2638
except CatchableError as e:
2739
fatal "error", message = e.msg
28-
isShutDownRequired.store(true)
2940

30-
isShutDownRequired.store(true)
3141
warn "\tExiting execution layer"

0 commit comments

Comments
 (0)