Skip to content

Commit 971b448

Browse files
authored
add libnimbus_lc.a C library (#5122)
Add a new C library for processing light client data based on the Nimbus implementation. This can be used from other, non-Nimbus components.
1 parent 346d05a commit 971b448

File tree

17 files changed

+2709
-13
lines changed

17 files changed

+2709
-13
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,16 @@ jobs:
6464
- name: Check copyright year (Linux)
6565
if: github.event_name == 'pull_request' && runner.os == 'Linux'
6666
run: |
67-
excluded_extensions="ans|json|md|png|txt"
67+
excluded_files="config.yaml"
68+
excluded_extensions="ans|json|md|png|ssz|txt"
6869
6970
current_year=$(date +"%Y")
7071
outdated_files=()
7172
while read -r file; do
7273
if ! grep -qE 'Copyright \(c\) .*'$current_year' Status Research & Development GmbH' "$file"; then
7374
outdated_files+=("$file")
7475
fi
75-
done < <(git diff --name-only --diff-filter=AM --ignore-submodules HEAD^ HEAD | grep -vE '\.('$excluded_extensions')$' || true)
76+
done < <(git diff --name-only --diff-filter=AM --ignore-submodules HEAD^ HEAD | grep -vE '(\.('$excluded_extensions')|'$excluded_files')$' || true)
7677
7778
if (( ${#outdated_files[@]} )); then
7879
echo "The following files do not have an up-to-date copyright year:"

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ build/
5151
test_keymanager_api
5252
test_sim
5353

54-
/libnfuzz_linkerArgs.txt
54+
/*linkerArgs.txt
5555

5656
# scripts/geth_binaries.sh
5757
geth-*.tar.gz

Makefile

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,14 @@ endif
5454

5555
# unconditionally built by the default Make target
5656
# TODO re-enable ncli_query if/when it works again
57+
TOOLS_CORE_CUSTOMCOMPILE := \
58+
libnimbus_lc.a
59+
5760
TOOLS_CORE := \
5861
deposit_contract \
5962
resttest \
6063
logtrace \
61-
mev_mock \
64+
mev_mock \
6265
ncli \
6366
ncli_db \
6467
ncli_split_keystore \
@@ -69,7 +72,8 @@ TOOLS_CORE := \
6972
nimbus_validator_client \
7073
nimbus_signing_node \
7174
validator_db_aggregator \
72-
ncli_testnet
75+
ncli_testnet \
76+
$(TOOLS_CORE_CUSTOMCOMPILE)
7377

7478
# This TOOLS/TOOLS_CORE decomposition is a workaroud so nimbus_beacon_node can
7579
# build on its own, and if/when that becomes a non-issue, it can be recombined
@@ -280,7 +284,8 @@ XML_TEST_BINARIES := \
280284
# test suite
281285
TEST_BINARIES := \
282286
state_sim \
283-
block_sim
287+
block_sim \
288+
test_libnimbus_lc
284289
.PHONY: $(TEST_BINARIES) $(XML_TEST_BINARIES) force_build_alone_all_tests
285290

286291
# Preset-dependent tests
@@ -392,14 +397,23 @@ endif
392397
rm -rf 0000-*.json t_slashprot_migration.* *.log block_sim_db
393398
for TEST_BINARY in $(TEST_BINARIES); do \
394399
PARAMS=""; \
400+
REDIRECT=""; \
395401
if [[ "$${TEST_BINARY}" == "state_sim" ]]; then PARAMS="--validators=8000 --slots=160"; \
396402
elif [[ "$${TEST_BINARY}" == "block_sim" ]]; then PARAMS="--validators=8000 --slots=160"; \
403+
elif [[ "$${TEST_BINARY}" == "test_libnimbus_lc" ]]; then REDIRECT="$${TEST_BINARY}.log"; \
397404
fi; \
398405
echo -e "\nRunning $${TEST_BINARY} $${PARAMS}\n"; \
399-
build/$${TEST_BINARY} $${PARAMS} || { \
400-
echo -e "\n$${TEST_BINARY} $${PARAMS} failed; Last 50 lines from the log:"; \
401-
tail -n50 "$${TEST_BINARY}.log"; exit 1; \
402-
}; \
406+
if [[ "$${REDIRECT}" != "" ]]; then \
407+
build/$${TEST_BINARY} $${PARAMS} > "$${REDIRECT}" && echo "OK" || { \
408+
echo -e "\n$${TEST_BINARY} $${PARAMS} failed; Last 50 lines from the log:"; \
409+
tail -n50 "$${TEST_BINARY}.log"; exit 1; \
410+
}; \
411+
else \
412+
build/$${TEST_BINARY} $${PARAMS} || { \
413+
echo -e "\n$${TEST_BINARY} $${PARAMS} failed; Last 50 lines from the log:"; \
414+
tail -n50 "$${TEST_BINARY}.log"; exit 1; \
415+
}; \
416+
fi; \
403417
done; \
404418
rm -rf 0000-*.json t_slashprot_migration.* *.log block_sim_db
405419

@@ -419,7 +433,7 @@ build/generate_makefile: tools/generate_makefile.nim | deps-common
419433
# It also requires Make to pass open file descriptors to the GCC process,
420434
# which is not possible if we let Nim handle this, so we generate and use a
421435
# makefile instead.
422-
$(TOOLS): | build deps
436+
$(filter-out $(TOOLS_CORE_CUSTOMCOMPILE),$(TOOLS)): | build deps
423437
+ for D in $(TOOLS_DIRS); do [ -e "$${D}/$@.nim" ] && TOOL_DIR="$${D}" && break; done && \
424438
echo -e $(BUILD_MSG) "build/$@" && \
425439
MAKE="$(MAKE)" V="$(V)" $(ENV_SCRIPT) scripts/compile_nim_program.sh $@ "$${TOOL_DIR}/$@.nim" $(NIM_PARAMS) && \
@@ -728,6 +742,34 @@ gnosis-chain-dev-deposit: | gnosis-build deposit_contract
728742
clean-gnosis-chain:
729743
$(call CLEAN_NETWORK,gnosis-chain)
730744

745+
###
746+
### libnimbus_lc
747+
###
748+
749+
libnimbus_lc.a: | build deps
750+
+ echo -e $(BUILD_MSG) "build/$@" && \
751+
set -x && \
752+
rm -f build/$@ && \
753+
$(ENV_SCRIPT) $(NIMC) c -d:disable_libbacktrace -d:release --app:staticlib --noMain --nimcache:nimcache/libnimbus_lc_static -o:build/$@ $(NIM_PARAMS) beacon_chain/libnimbus_lc/libnimbus_lc.nim $(SILENCE_WARNINGS) && \
754+
echo -e $(BUILD_END_MSG) "build/$@"
755+
756+
# `-Wno-maybe-uninitialized` in Linux: https://github.com/nim-lang/Nim/issues/22246
757+
test_libnimbus_lc: libnimbus_lc.a
758+
+ echo -e $(BUILD_MSG) "build/$@" && \
759+
set -x && \
760+
case "$$(uname)" in \
761+
Darwin) \
762+
clang -D__DIR__="\"beacon_chain/libnimbus_lc\"" --std=c17 -Weverything -Werror -Wno-declaration-after-statement -Wno-nullability-extension -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -o build/test_libnimbus_lc beacon_chain/libnimbus_lc/test_libnimbus_lc.c build/libnimbus_lc.a -framework Security; \
763+
;; \
764+
MINGW64_*) \
765+
gcc -D__DIR__="\"beacon_chain/libnimbus_lc\"" --std=c17 -Wall -Wextra -pedantic -Werror -pedantic-errors -flto -o build/test_libnimbus_lc -D_CRT_SECURE_NO_WARNINGS beacon_chain/libnimbus_lc/test_libnimbus_lc.c build/libnimbus_lc.a; \
766+
;; \
767+
*) \
768+
gcc -D__DIR__="\"beacon_chain/libnimbus_lc\"" --std=c17 -Wall -Wextra -pedantic -Werror -pedantic-errors -Wno-maybe-uninitialized -flto -o build/test_libnimbus_lc beacon_chain/libnimbus_lc/test_libnimbus_lc.c build/libnimbus_lc.a; \
769+
;; \
770+
esac && \
771+
echo -e $(BUILD_END_MSG) "build/$@"
772+
731773
###
732774
### Other
733775
###

0 commit comments

Comments
 (0)