Skip to content

Commit 4a8f36d

Browse files
committed
bench: integrate Spark component benchmarks into bench_firo
1 parent 3997f07 commit 4a8f36d

15 files changed

Lines changed: 612 additions & 1277 deletions

.github/workflows/ci-master.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ jobs:
240240
env PKG_CONFIG_PATH="$(realpath depends/$HOST_TRIPLET/lib/pkgconfig):$PKG_CONFIG_PATH" \
241241
cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=$(realpath depends/$HOST_TRIPLET/toolchain.cmake) \
242242
-DBUILD_CLI=ON -DBUILD_TESTS=ON -DENABLE_CRASH_HOOKS=ON -DBUILD_GUI=ON \
243+
-DBUILD_BENCH=ON -DBUILD_BENCH_SPARK=ON \
243244
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
244245
$CMAKE_EXTRA_FLAGS \
245246
-S$(realpath .) -B$(realpath build)
@@ -260,6 +261,7 @@ jobs:
260261
env PKG_CONFIG_PATH="$(realpath depends/$HOST_TRIPLET/lib/pkgconfig):$PKG_CONFIG_PATH" \
261262
cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=$(realpath depends/$HOST_TRIPLET/toolchain.cmake) \
262263
-DBUILD_CLI=ON -DBUILD_TESTS=OFF -DENABLE_CRASH_HOOKS=ON \
264+
-DBUILD_BENCH=ON -DBUILD_BENCH_SPARK=ON \
263265
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
264266
$CMAKE_EXTRA_FLAGS \
265267
-DBUILD_GUI=ON -S$(realpath .) -B$(realpath build)
@@ -280,6 +282,7 @@ jobs:
280282
env PKG_CONFIG_PATH="$(pwd)/depends/$HOST_TRIPLET/lib/pkgconfig:$PKG_CONFIG_PATH" \
281283
cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=$(pwd)/depends/$HOST_TRIPLET/toolchain.cmake \
282284
-DBUILD_CLI=ON -DBUILD_TESTS=OFF -DENABLE_CRASH_HOOKS=ON -DBUILD_GUI=ON \
285+
-DBUILD_BENCH=ON -DBUILD_BENCH_SPARK=ON \
283286
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
284287
$CMAKE_EXTRA_FLAGS \
285288
-S$(pwd) -B$(pwd)/build
@@ -297,6 +300,11 @@ jobs:
297300
set -exo pipefail
298301
cp -rf build/bin/* build/src/
299302
qa/pull-tester/rpc-tests.py -extended
303+
- name: Run Benchmarks
304+
if: matrix.is_linux
305+
run: |
306+
set -exo pipefail
307+
build/bin/bench_firo
300308
- name: Prepare Files for Artifact
301309
run: |
302310
set -exo pipefail

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ if(BUILD_GUI)
283283
endif()
284284

285285
option(BUILD_BENCH "Build bench_firo executable." OFF)
286+
option(BUILD_BENCH_SPARK "Build Spark benchmarks into bench_firo." OFF)
286287
option(BUILD_FUZZ_BINARY "Build fuzz binary." OFF)
287288
option(BUILD_FOR_FUZZING "Build for fuzzing. Enabling this will disable all other targets and override BUILD_FUZZ_BINARY." OFF)
288289

@@ -339,6 +340,7 @@ if(BUILD_FOR_FUZZING)
339340
set(BUILD_TESTS OFF)
340341
set(BUILD_GUI_TESTS OFF)
341342
set(BUILD_BENCH OFF)
343+
set(BUILD_BENCH_SPARK OFF)
342344
set(BUILD_FUZZ_BINARY ON)
343345

344346
target_compile_definitions(core_interface INTERFACE
@@ -853,7 +855,7 @@ if(DEFINED ENV{LDFLAGS})
853855
deduplicate_flags(CMAKE_EXE_LINKER_FLAGS)
854856
endif()
855857

856-
if(BUILD_TESTS)
858+
if(BUILD_TESTS OR BUILD_BENCH)
857859
enable_testing()
858860
endif()
859861

@@ -956,6 +958,7 @@ message("Tests:")
956958
message(" test_firo ........................ ${BUILD_TESTS}")
957959
message(" test_firo-qt ..................... ${BUILD_GUI_TESTS}")
958960
message(" bench_firo ....................... ${BUILD_BENCH}")
961+
message(" Spark benchmarks ................. ${BUILD_BENCH_SPARK}")
959962
message(" fuzz binary ......................... ${BUILD_FUZZ_BINARY}")
960963
message("")
961964
if(CMAKE_CROSSCOMPILING)
@@ -1006,4 +1009,4 @@ if(WIN32 AND MINGW AND STATIC_BUILD)
10061009
# Ensure we link against static versions of system libraries
10071010
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bstatic")
10081011
endif()
1009-
endif()
1012+
endif()

cmake/script/GenerateHeaderFromRaw.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ string(REGEX REPLACE "[^\n][^\n]" "std::byte{0x\\0}, " formatted_bytes "${format
1111
string(LENGTH "${hex_content}" content_length)
1212
math(EXPR array_size "${content_length} / 2")
1313

14+
cmake_path(GET HEADER_PATH PARENT_PATH header_dir)
15+
file(MAKE_DIRECTORY "${header_dir}")
16+
1417
set(header_content
1518
"#include <array>
1619
#include <cstddef>

cmake/utilities.cmake

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44

55
function(apply_wrapped_exception_flags target_name)
66
if(ENABLE_CRASH_HOOKS AND CRASH_HOOKS_WRAPPED_CXX_ABI)
7-
# We need to wrap exceptions to catch them in the crash handler
8-
# We need to pass both compile flags and link flags to ensure that the wrapped exceptions are used in all cases
9-
target_compile_options(${target_name} PRIVATE ${LDFLAGS_WRAP_EXCEPTIONS})
10-
# Apple linker does not support -Wl,--wrap=
7+
get_target_property(target_type ${target_name} TYPE)
8+
if(target_type STREQUAL "STATIC_LIBRARY")
9+
set(wrap_scope INTERFACE)
10+
else()
11+
set(wrap_scope PRIVATE)
12+
endif()
13+
14+
# The wrappers are resolved by the final executable link step. Static
15+
# libraries therefore propagate the requirement to their consumers.
1116
if(NOT APPLE)
12-
target_link_options(${target_name} PRIVATE ${LDFLAGS_WRAP_EXCEPTIONS})
17+
target_link_options(${target_name} ${wrap_scope} ${LDFLAGS_WRAP_EXCEPTIONS})
1318
endif()
1419
endif()
1520
endfunction()

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ target_link_libraries(bitcoin_util
7171
bitcoin_crypto
7272
Boost::thread
7373
Boost::chrono
74+
Boost::program_options
7475
univalue
7576
secp256k1
7677
leveldb

src/bench/CMakeLists.txt

Lines changed: 6 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -47,87 +47,12 @@ install(TARGETS bench_firo
4747
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
4848
)
4949

50-
# Spark/Lelantus benchmarking framework
51-
option(BUILD_BENCH_SPARK "Build Spark/Lelantus benchmarks" OFF)
52-
5350
if(BUILD_BENCH_SPARK)
54-
message(STATUS "Building Spark benchmarks")
55-
56-
# Generic benchmarking framework library
57-
add_library(firo_benchmark STATIC
58-
${CMAKE_CURRENT_SOURCE_DIR}/benchmark.cpp
59-
)
60-
61-
target_include_directories(firo_benchmark PUBLIC
62-
${CMAKE_CURRENT_SOURCE_DIR}
63-
)
64-
65-
# Optional: Enable Linux perf counters (requires explicit opt-in)
66-
option(ENABLE_BENCH_PERF_COUNTERS "Enable Linux perf counters in benchmarks (Linux only)" OFF)
67-
68-
if(ENABLE_BENCH_PERF_COUNTERS)
69-
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
70-
target_compile_definitions(firo_benchmark PUBLIC BENCH_PERF_COUNTERS)
71-
message(STATUS " Linux perf counters: ENABLED")
72-
else()
73-
message(WARNING " ENABLE_BENCH_PERF_COUNTERS is only supported on Linux, ignoring")
74-
endif()
75-
else()
76-
message(STATUS " Linux perf counters: DISABLED (use -DENABLE_BENCH_PERF_COUNTERS=ON to enable)")
77-
endif()
78-
79-
# Grootle proof benchmarks
80-
add_executable(bench_spark_grootle
81-
${CMAKE_CURRENT_SOURCE_DIR}/spark_grootle.cpp
82-
)
83-
84-
target_link_libraries(bench_spark_grootle
85-
firo_benchmark
86-
firo_node
87-
Boost::filesystem
88-
secp256k1pp
89-
)
90-
91-
# BPPlus (Bulletproofs+) benchmarks
92-
add_executable(bench_spark_bpplus
93-
${CMAKE_CURRENT_SOURCE_DIR}/spark_bpplus.cpp
94-
)
95-
96-
target_link_libraries(bench_spark_bpplus
97-
firo_benchmark
98-
firo_node
99-
Boost::filesystem
100-
secp256k1pp
101-
)
102-
103-
# Chaum proof benchmarks
104-
add_executable(bench_spark_chaum
105-
${CMAKE_CURRENT_SOURCE_DIR}/spark_chaum.cpp
106-
)
107-
108-
target_link_libraries(bench_spark_chaum
109-
firo_benchmark
110-
firo_node
111-
Boost::filesystem
112-
secp256k1pp
113-
)
114-
115-
# Schnorr signature benchmarks
116-
add_executable(bench_spark_schnorr
117-
${CMAKE_CURRENT_SOURCE_DIR}/spark_schnorr.cpp
118-
)
119-
120-
target_link_libraries(bench_spark_schnorr
121-
firo_benchmark
122-
firo_node
123-
Boost::filesystem
124-
secp256k1pp
125-
)
126-
127-
# Install benchmark executables
128-
install(TARGETS bench_spark_grootle bench_spark_bpplus bench_spark_chaum bench_spark_schnorr
129-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
51+
target_sources(bench_firo
52+
PRIVATE
53+
${CMAKE_CURRENT_SOURCE_DIR}/spark_bpplus.cpp
54+
${CMAKE_CURRENT_SOURCE_DIR}/spark_chaum.cpp
55+
${CMAKE_CURRENT_SOURCE_DIR}/spark_grootle.cpp
56+
${CMAKE_CURRENT_SOURCE_DIR}/spark_schnorr.cpp
13057
)
131-
132-
message(STATUS " Benchmarks: bench_spark_grootle, bench_spark_bpplus, bench_spark_chaum, bench_spark_schnorr")
13358
endif()

src/bench/bench_bitcoin.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
#include "bench.h"
66

7+
#include "chainparams.h"
78
#include "key.h"
9+
#include "pubkey.h"
810
#include "stacktraces.h"
911
#include "validation.h"
1012
#include "util.h"
1113

14+
#include <string>
15+
1216
int
1317
main(int argc, char** argv)
1418
{
@@ -17,10 +21,22 @@ main(int argc, char** argv)
1721
RegisterPrettyTerminateHander();
1822
#endif
1923
ECC_Start();
20-
SetupEnvironment();
21-
fPrintToDebugLog = false; // don't want to write to debug.log file
24+
{
25+
ECCVerifyHandle globalVerifyHandle;
26+
27+
SetupEnvironment();
28+
SelectParams(CBaseChainParams::MAIN);
29+
fPrintToDebugLog = false; // don't want to write to debug.log file
30+
31+
double elapsed_time_for_one = 1.0;
32+
for (int i = 1; i < argc; ++i) {
33+
if (std::string(argv[i]) == "-sanity-check") {
34+
elapsed_time_for_one = 0.001;
35+
}
36+
}
2237

23-
benchmark::BenchRunner::RunAll();
38+
benchmark::BenchRunner::RunAll(elapsed_time_for_one);
39+
}
2440

2541
ECC_Stop();
2642
}

0 commit comments

Comments
 (0)