Skip to content

Commit 00ae0d5

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 3ac6df4 commit 00ae0d5

File tree

10 files changed

+237
-273
lines changed

10 files changed

+237
-273
lines changed

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,17 +359,20 @@ libnimbusevm: | build deps
359359

360360
# usual cleaning
361361
clean: | clean-common
362-
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}
362+
rm -rf build/{nimbus_client,nimbus_execution_client,fluffy,libverifproxy,nimbus_verified_proxy}
363+
rm -rf build/{$(TOOLS_CSV),$(FLUFFY_TOOLS_CSV)}
364+
rm -rf build/{all_tests_nimbus,all_tests,test_kvstore_rocksdb,test_rpc,all_fluffy_tests,all_history_network_custom_chain_tests,test_portal_testnet,utp_test_app,utp_test}
365+
rm -rf build/{*.dSYM}
363366
rm -rf tools/t8n/{t8n,t8n_test}
364367
rm -rf tools/evmstate/{evmstate,evmstate_test}
365368
ifneq ($(USE_LIBBACKTRACE), 0)
366369
+ $(MAKE) -C vendor/nim-libbacktrace clean $(HANDLE_OUTPUT)
367370
endif
368371

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

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

nimbus.nimble

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ when declared(namedBin):
4040
"execution_chain/nimbus_execution_client": "nimbus_execution_client",
4141
"fluffy/fluffy": "fluffy",
4242
"nimbus_verified_proxy/nimbus_verified_proxy": "nimbus_verified_proxy",
43+
"nimbus/nimbus_client": "nimbus_client",
4344
}.toTable()
4445

4546
import std/os
@@ -127,10 +128,10 @@ task nimbus_verified_proxy, "Build Nimbus verified proxy":
127128
task nimbus_verified_proxy_test, "Run Nimbus verified proxy tests":
128129
test "nimbus_verified_proxy/tests", "test_proof_validation", "-d:chronicles_log_level=ERROR -d:nimbus_db_backend=sqlite"
129130

130-
## nimbus tasks
131+
## Nimbus tasks
131132

132133
task nimbus, "Build Nimbus":
133134
buildBinary "nimbus", "nimbus/", "-d:chronicles_log_level=TRACE"
134135

135136
task nimbus_test, "Run Nimbus tests":
136-
test "nimbus/tests/","all_tests", "-d:chronicles_log_level=ERROR"
137+
test "nimbus/tests/","all_tests_nimbus", "-d:chronicles_log_level=ERROR -d:testing"

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: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,31 @@
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],
1012
chronicles,
11-
options,
12-
#eth2-configs
13-
beacon_chain/nimbus_binary_common,
14-
#eth1-configs
15-
../../execution_chain/nimbus_desc
13+
#eth2
14+
beacon_chain/nimbus_binary_common
15+
16+
export setupFileLimits
1617

17-
export BeaconNodeConf, NimbusConf
18+
## log
19+
logScope:
20+
topics = "Service manager"
1821

1922
## Exceptions
2023
type NimbusServiceError* = object of CatchableError
2124

2225
## Constants
23-
## TODO: evaluate the proposed timeouts
24-
const cNimbusMaxServices* = 2
25-
const cNimbusServiceTimeoutMs* = 3000
26+
const
27+
cNimbusServiceTimeoutMs* = 3000
28+
cThreadTimeAck* = 10
2629

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

3134
## Nimbus service arguments
3235
type
@@ -37,25 +40,21 @@ type
3740
LayerConfig* = object
3841
case kind*: ConfigKind
3942
of Consensus:
40-
consensusConfig*: seq[string]
43+
consensusOptions*: seq[string]
4144
of Execution:
42-
executionConfig*: seq[string]
45+
executionOptions*: seq[string]
4346

4447
NimbusService* = ref object
4548
name*: string
4649
layerConfig*: LayerConfig
4750
serviceHandler*: Thread[ptr Channel[pointer]]
48-
serviceChannel: ptr Channel[pointer]
51+
serviceChannel*: ptr Channel[pointer] = nil
52+
serviceFunc*: proc(ch: ptr Channel[pointer]) {.thread.}
4953

5054
Nimbus* = ref object
5155
serviceList*: seq[NimbusService]
5256

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

nimbus/consensus/consensus_layer.nim

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,34 @@
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+
#signal main thread that data is read
29+
isConfigRead.store(true)
1930

2031
try:
21-
while isShutDownRequired.load() == false:
32+
while true:
2233
info "consensus ..."
2334
sleep(cNimbusServiceTimeoutMs + 1000)
24-
25-
isShutDownRequired.store(true)
2635
except CatchableError as e:
2736
fatal "error", message = e.msg
28-
isShutDownRequired.store(true)
2937

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

nimbus/execution/execution_layer.nim

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,34 @@
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+
#signal main thread that data is read
29+
isConfigRead.store(true)
1930

2031
try:
21-
while isShutDownRequired.load() == false:
32+
while true:
2233
info "execution ..."
2334
sleep(cNimbusServiceTimeoutMs)
24-
25-
isShutDownRequired.store(true)
2635
except CatchableError as e:
2736
fatal "error", message = e.msg
28-
isShutDownRequired.store(true)
2937

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

0 commit comments

Comments
 (0)