Skip to content

nimbus initial commit #3036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ on:
- '**/*.md'
- 'hive_integration/**'
- 'fluffy/**'
- 'nimbus/**'
- '.github/workflows/fluffy*.yml'
- 'nimbus_verified_proxy/**'
- '.github/workflows/nimbus_verified_proxy.yml'
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/kurtosis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2024 Status Research & Development GmbH
# Copyright (c) 2025 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
Expand All @@ -20,6 +20,7 @@ on:
- '**/*.md'
- 'hive_integration/**'
- 'fluffy/**'
- 'nimbus/**'
- '.github/workflows/fluffy*.yml'
- 'nimbus_verified_proxy/**'
- '.github/workflows/nimbus_verified_proxy.yml'
Expand All @@ -32,6 +33,7 @@ on:
- '**/*.md'
- 'hive_integration/**'
- 'fluffy/**'
- 'nimbus/**'
- '.github/workflows/fluffy*.yml'
- 'nimbus_verified_proxy/**'
- '.github/workflows/nimbus_verified_proxy.yml'
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2024 Status Research & Development GmbH
# Copyright (c) 2025 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
Expand All @@ -21,7 +21,7 @@ ADD . /root/nimbus-eth1

RUN cd /root/nimbus-eth1 \
&& make -j$(nproc) update-from-ci \
&& make -j$(nproc) V=1 LOG_LEVEL=TRACE nimbus
&& make -j$(nproc) V=1 LOG_LEVEL=TRACE nimbus_execution_client

# --------------------------------- #
# Starting new image to reduce size #
Expand Down
17 changes: 13 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,6 @@ nimbus_execution_client: | build deps rocksdb
echo -e $(BUILD_MSG) "build/nimbus_execution_client" && \
$(ENV_SCRIPT) nim c $(NIM_PARAMS) -d:chronicles_log_level=TRACE -o:build/nimbus_execution_client "execution_chain/nimbus_execution_client.nim"

nimbus: nimbus_execution_client
echo "The nimbus target is deprecated and will soon change meaning, use 'nimbus_execution_client' instead"

# symlink
nimbus.nims:
ln -s nimbus.nimble $@
Expand Down Expand Up @@ -365,13 +362,25 @@ libnimbusevm: | build deps

# usual cleaning
clean: | clean-common
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}
rm -rf build/{nimbus_client,nimbus_execution_client,fluffy,libverifproxy,nimbus_verified_proxy}
rm -rf build/{$(TOOLS_CSV),$(FLUFFY_TOOLS_CSV)}
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}
rm -rf build/*.dSYM
rm -rf tools/t8n/{t8n,t8n_test}
rm -rf tools/evmstate/{evmstate,evmstate_test}
ifneq ($(USE_LIBBACKTRACE), 0)
+ $(MAKE) -C vendor/nim-libbacktrace clean $(HANDLE_OUTPUT)
endif

# Nimbus
nimbus: | build deps
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim c $(NIM_PARAMS) --threads:on -d:chronicles_log_level=TRACE -o:build/nimbus_client "nimbus/nimbus.nim"

all_tests_nimbus: | build deps
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim c -r $(NIM_PARAMS) -d:testing --threads:on -d:chronicles_log_level=ERROR -o:build/$@ "nimbus/tests/[email protected]"

# Note about building Nimbus as a library:
#
# There were `wrappers`, `wrappers-static`, `libnimbus.so` and `libnimbus.a`
Expand Down
9 changes: 9 additions & 0 deletions nimbus.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ when declared(namedBin):
"execution_chain/nimbus_execution_client": "nimbus_execution_client",
"fluffy/fluffy": "fluffy",
"nimbus_verified_proxy/nimbus_verified_proxy": "nimbus_verified_proxy",
"nimbus/nimbus_client": "nimbus_client",
}.toTable()

import std/[os, strutils]
Expand Down Expand Up @@ -137,3 +138,11 @@ task build_fuzzers, "Build fuzzer test cases":
for file in walkDirRec("tests/networking/fuzzing/"):
if file.endsWith("nim"):
exec "nim c -c -d:release " & file

## Nimbus tasks

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

task nimbus_test, "Run Nimbus tests":
test "nimbus/tests/", "all_tests_nimbus", "-d:chronicles_log_level=ERROR -d:testing"
43 changes: 43 additions & 0 deletions nimbus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Nimbus

<!-- [![Github Actions CI](tbd) -->
[![License: Apache](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

[![Discord: Nimbus](https://img.shields.io/badge/discord-nimbus-orange.svg)](https://discord.gg/XRxWahP)
[![Status: #nimbus-general](https://img.shields.io/badge/status-nimbus--general-orange.svg)](https://join.status.im/nimbus-general)


# description
tbd
For in-depth configuration and functionality of Nimbus execution and consensus layer refer to:
- [Nimbus-eth1 - Execution layer client](https://github.com/status-im/nimbus-eth1) Documentation
- [Nimbus-eth2 - Consensus layer client](https://github.com/status-im/nimbus-eth2) Documentation

tbc
# dependencies
tbd
# how to
## configuration
todo
## commands
todo
## compile
tbd
- mac os, windows, and linux

]$ make nimbus
## collaborate
- Use [Status Nim style guide](https://status-im.github.io/nim-style-guide/) to maintain code consistency.
- Format your code using the [Nim Pretty Printer (nph)](https://github.com/arnetheduck/nph) to ensure consistency across the codebase. Run it as part of your pull request process.
## License

Licensed and distributed under either of

* MIT license: [LICENSE-MIT](LICENSE-MIT) or https://opensource.org/licenses/MIT

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.
57 changes: 57 additions & 0 deletions nimbus/common/utils.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Nimbus
# Copyright (c) 2025 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.

{.push raises: [].}

import results, ../conf, chronicles

## Serialize table string elements
proc serializeTableElement*(offset: var uint, elem: string) =
if offset <= 0:
fatal "memory offset can't be zero"
quit(QuitFailure)

let optLen = uint(elem.len) #element size

copyMem(cast[pointer](offset), addr optLen, sizeof(uint))
offset += uint(sizeof(uint))

if optLen > 0:
copyMem(cast[pointer](offset), unsafeAddr elem[0], elem.len) #element data
offset += uint(elem.len)

## Deserialize table string elements
proc deserializeTableElement*(offset: var uint): string =
var strLen: uint #element size
copyMem(addr strLen, cast[pointer](offset), sizeof(uint))
offset += uint(sizeof(uint))

var strData = ""
if strLen > 0:
strData = newString(strLen) #element
copyMem(addr strData[0], cast[pointer](offset), uint(strLen))
offset += uint(strLen)

strData

## Parse data from a given channel.
## schema: (table size:Uint) | [ (option size:Uint) (option data:byte) (arg size: Uint) (arg data:byte)]
proc parseChannelData*(p: pointer): Result[NimbusConfigTable, string] =
var
readOffset = cast[uint](p)
confTable = NimbusConfigTable()
totalSize: uint = 0

copyMem(addr totalSize, cast[pointer](readOffset), sizeof(uint))
readOffset += uint(sizeof(uint))

while readOffset < cast[uint](p) + totalSize:
let opt = deserializeTableElement(readOffset)
let arg = deserializeTableElement(readOffset)
confTable[opt] = arg

ok confTable
56 changes: 56 additions & 0 deletions nimbus/conf.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Nimbus
# Copyright (c) 2025 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.

{.push raises: [].}

import
std/[atomics, tables],
chronicles,
#eth2
beacon_chain/nimbus_binary_common

export setupFileLimits

## log
logScope:
topics = "Service manager"

## Exceptions
type NimbusServiceError* = object of CatchableError

## Constants
const
cNimbusServiceTimeoutMs* = 3000
cThreadTimeAck* = 10

# configuration read by threads
var isConfigRead*: Atomic[bool]
isConfigRead.store(false)

## Nimbus service arguments
type
NimbusConfigTable* = Table[string, string]

ConfigKind* = enum
Execution
Consensus

LayerConfig* = object
case kind*: ConfigKind
of Consensus:
consensusOptions*: NimbusConfigTable
of Execution:
executionOptions*: NimbusConfigTable

NimbusService* = ref object
name*: string
layerConfig*: LayerConfig
serviceHandler*: Thread[ptr Channel[pointer]]
serviceFunc*: proc(ch: ptr Channel[pointer]) {.thread.}

Nimbus* = ref object
serviceList*: seq[NimbusService]
38 changes: 38 additions & 0 deletions nimbus/consensus/consensus_layer.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Nimbus
# Copyright (c) 2025 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.

{.push raises: [].}

import std/[atomics, os], chronos, chronicles, ../conf, ../common/utils, results

logScope:
topics = "Consensus layer"

## Consensus Layer handler
proc consensusLayerHandler*(channel: ptr Channel[pointer]) =
var p: pointer
try:
p = channel[].recv()
except Exception as e:
fatal " service unable to receive configuration", err = e.msg
quit(QuitFailure)

let configs = parseChannelData(p).valueOr:
fatal "unable to parse service data", message = error
quit(QuitFailure)

#signal main thread that data is read
isConfigRead.store(true)

try:
while true:
info "consensus ..."
sleep(cNimbusServiceTimeoutMs)
except CatchableError as e:
fatal "error", message = e.msg

warn "\tExiting consensus layer"
38 changes: 38 additions & 0 deletions nimbus/execution/execution_layer.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Nimbus
# Copyright (c) 2025 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.

{.push raises: [].}

import std/[atomics, os], chronicles, ../conf, ../common/utils, results

logScope:
topics = "Execution layer"

## Execution Layer handler
proc executionLayerHandler*(channel: ptr Channel[pointer]) =
var p: pointer
try:
p = channel[].recv()
except Exception as e:
fatal "service unable to receive configuration", err = e.msg
quit(QuitFailure)

let configs = parseChannelData(p).valueOr:
fatal "unable to parse service data", message = error
quit(QuitFailure)

#signal main thread that data is read
isConfigRead.store(true)

try:
while true:
info "execution ..."
sleep(cNimbusServiceTimeoutMs)
except CatchableError as e:
fatal "error", message = e.msg

warn "\tExiting execution layer"
16 changes: 16 additions & 0 deletions nimbus/nimbus.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Nimbus
# Copyright (c) 2025 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.

-d:"libp2p_pki_schemes=secp256k1"

-d:"chronicles_sinks=textlines[dynamic],json[dynamic]"
-d:"chronicles_runtime_filtering=on"
-d:"chronicles_disable_thread_id"

@if release:
-d:"chronicles_line_numbers:0"
@end
Loading
Loading