Skip to content
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
8 changes: 8 additions & 0 deletions .github/workflows/ci-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ jobs:
env PKG_CONFIG_PATH="$(realpath depends/$HOST_TRIPLET/lib/pkgconfig):$PKG_CONFIG_PATH" \
cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=$(realpath depends/$HOST_TRIPLET/toolchain.cmake) \
-DBUILD_CLI=ON -DBUILD_TESTS=ON -DENABLE_CRASH_HOOKS=ON -DBUILD_GUI=ON \
-DBUILD_BENCH=ON -DBUILD_BENCH_SPARK=ON \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
$CMAKE_EXTRA_FLAGS \
-S$(realpath .) -B$(realpath build)
Expand All @@ -260,6 +261,7 @@ jobs:
env PKG_CONFIG_PATH="$(realpath depends/$HOST_TRIPLET/lib/pkgconfig):$PKG_CONFIG_PATH" \
cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=$(realpath depends/$HOST_TRIPLET/toolchain.cmake) \
-DBUILD_CLI=ON -DBUILD_TESTS=OFF -DENABLE_CRASH_HOOKS=ON \
-DBUILD_BENCH=ON -DBUILD_BENCH_SPARK=ON \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
$CMAKE_EXTRA_FLAGS \
-DBUILD_GUI=ON -S$(realpath .) -B$(realpath build)
Expand All @@ -280,6 +282,7 @@ jobs:
env PKG_CONFIG_PATH="$(pwd)/depends/$HOST_TRIPLET/lib/pkgconfig:$PKG_CONFIG_PATH" \
cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=$(pwd)/depends/$HOST_TRIPLET/toolchain.cmake \
-DBUILD_CLI=ON -DBUILD_TESTS=OFF -DENABLE_CRASH_HOOKS=ON -DBUILD_GUI=ON \
-DBUILD_BENCH=ON -DBUILD_BENCH_SPARK=ON \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
$CMAKE_EXTRA_FLAGS \
-S$(pwd) -B$(pwd)/build
Expand All @@ -297,6 +300,11 @@ jobs:
set -exo pipefail
cp -rf build/bin/* build/src/
qa/pull-tester/rpc-tests.py -extended
- name: Run Benchmarks
if: matrix.is_linux
run: |
set -exo pipefail
build/bin/bench_firo
- name: Prepare Files for Artifact
run: |
set -exo pipefail
Expand Down
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ if(BUILD_GUI)
endif()

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

Expand Down Expand Up @@ -339,6 +340,7 @@ if(BUILD_FOR_FUZZING)
set(BUILD_TESTS OFF)
set(BUILD_GUI_TESTS OFF)
set(BUILD_BENCH OFF)
set(BUILD_BENCH_SPARK OFF)
set(BUILD_FUZZ_BINARY ON)

target_compile_definitions(core_interface INTERFACE
Expand Down Expand Up @@ -853,7 +855,7 @@ if(DEFINED ENV{LDFLAGS})
deduplicate_flags(CMAKE_EXE_LINKER_FLAGS)
endif()

if(BUILD_TESTS)
if(BUILD_TESTS OR BUILD_BENCH)
enable_testing()
endif()

Expand Down Expand Up @@ -956,6 +958,7 @@ message("Tests:")
message(" test_firo ........................ ${BUILD_TESTS}")
message(" test_firo-qt ..................... ${BUILD_GUI_TESTS}")
message(" bench_firo ....................... ${BUILD_BENCH}")
message(" Spark benchmarks ................. ${BUILD_BENCH_SPARK}")
message(" fuzz binary ......................... ${BUILD_FUZZ_BINARY}")
message("")
if(CMAKE_CROSSCOMPILING)
Expand Down Expand Up @@ -1006,4 +1009,4 @@ if(WIN32 AND MINGW AND STATIC_BUILD)
# Ensure we link against static versions of system libraries
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bstatic")
endif()
endif()
endif()
16 changes: 10 additions & 6 deletions cmake/script/GenerateHeaderFromRaw.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ file(READ ${RAW_SOURCE_PATH} hex_content HEX)
string(REGEX REPLACE "................" "\\0\n" formatted_bytes "${hex_content}")
string(REGEX REPLACE "[^\n][^\n]" "std::byte{0x\\0}, " formatted_bytes "${formatted_bytes}")

string(LENGTH "${hex_content}" content_length)
math(EXPR array_size "${content_length} / 2")

cmake_path(GET HEADER_PATH PARENT_PATH header_dir)
file(MAKE_DIRECTORY "${header_dir}")

set(header_content
"#include <cstddef>
#include <span>
"#include <array>
#include <cstddef>

namespace ${RAW_NAMESPACE} {
inline constexpr std::byte detail_${raw_source_basename}_raw[] {
inline constexpr std::array<std::byte, ${array_size}> ${raw_source_basename} {{
${formatted_bytes}
};

inline constexpr std::span ${raw_source_basename}{detail_${raw_source_basename}_raw};
}};
}
")
file(WRITE ${HEADER_PATH} "${header_content}")
15 changes: 10 additions & 5 deletions cmake/utilities.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@

function(apply_wrapped_exception_flags target_name)
if(ENABLE_CRASH_HOOKS AND CRASH_HOOKS_WRAPPED_CXX_ABI)
# We need to wrap exceptions to catch them in the crash handler
# We need to pass both compile flags and link flags to ensure that the wrapped exceptions are used in all cases
target_compile_options(${target_name} PRIVATE ${LDFLAGS_WRAP_EXCEPTIONS})
# Apple linker does not support -Wl,--wrap=
get_target_property(target_type ${target_name} TYPE)
if(target_type STREQUAL "STATIC_LIBRARY")
set(wrap_scope INTERFACE)
else()
set(wrap_scope PRIVATE)
endif()

# The wrappers are resolved by the final executable link step. Static
# libraries therefore propagate the requirement to their consumers.
if(NOT APPLE)
target_link_options(${target_name} PRIVATE ${LDFLAGS_WRAP_EXCEPTIONS})
target_link_options(${target_name} ${wrap_scope} ${LDFLAGS_WRAP_EXCEPTIONS})
endif()
endif()
endfunction()
Expand Down
7 changes: 5 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ target_link_libraries(bitcoin_util
bitcoin_crypto
Boost::thread
Boost::chrono
Boost::program_options
univalue
secp256k1
leveldb
Expand Down Expand Up @@ -357,8 +358,8 @@ target_link_libraries(firo_node
OpenSSL::SSL
${MINIUPNP_LIBRARY}
${ZLIB_LIBRARY}
$<TARGET_NAME_IF_EXISTS:libevent::core>
$<TARGET_NAME_IF_EXISTS:libevent::extra>
$<TARGET_NAME_IF_EXISTS:libevent::core>
$<TARGET_NAME_IF_EXISTS:libevent::pthreads>
$<TARGET_NAME_IF_EXISTS:USDT::headers>
$<$<BOOL:${WIN32}>:windows_system>
Expand Down Expand Up @@ -533,6 +534,8 @@ endif()

if(BUILD_BENCH)
add_subdirectory(bench)
elseif(BUILD_BENCH_SPARK)
message(FATAL_ERROR "BUILD_BENCH_SPARK requires BUILD_BENCH=ON. Please add -DBUILD_BENCH=ON to your CMake command.")
endif()

if(BUILD_TESTS)
Expand Down Expand Up @@ -570,4 +573,4 @@ if(INSTALL_MAN AND NOT WIN32)
RENAME firo-tx.1
)
endif()
endif()
endif()
12 changes: 12 additions & 0 deletions src/bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ target_link_libraries(bench_firo
core_interface
firo_node
Boost::headers
Boost::filesystem
secp256k1pp
)

if(ENABLE_WALLET)
Expand All @@ -44,3 +46,13 @@ add_test(NAME bench_sanity_check_high_priority
install(TARGETS bench_firo
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(BUILD_BENCH_SPARK)
target_sources(bench_firo
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/spark_bpplus.cpp
${CMAKE_CURRENT_SOURCE_DIR}/spark_chaum.cpp
${CMAKE_CURRENT_SOURCE_DIR}/spark_grootle.cpp
${CMAKE_CURRENT_SOURCE_DIR}/spark_schnorr.cpp
)
endif()
22 changes: 19 additions & 3 deletions src/bench/bench_bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

#include "bench.h"

#include "chainparams.h"
#include "key.h"
#include "pubkey.h"
#include "stacktraces.h"
#include "validation.h"
#include "util.h"

#include <string>

int
main(int argc, char** argv)
{
Expand All @@ -17,10 +21,22 @@ main(int argc, char** argv)
RegisterPrettyTerminateHander();
#endif
ECC_Start();
SetupEnvironment();
fPrintToDebugLog = false; // don't want to write to debug.log file
{
ECCVerifyHandle globalVerifyHandle;

SetupEnvironment();
SelectParams(CBaseChainParams::MAIN);
fPrintToDebugLog = false; // don't want to write to debug.log file

double elapsed_time_for_one = 1.0;
for (int i = 1; i < argc; ++i) {
if (std::string(argv[i]) == "-sanity-check") {
elapsed_time_for_one = 0.001;
}
}

benchmark::BenchRunner::RunAll();
benchmark::BenchRunner::RunAll(elapsed_time_for_one);
}

ECC_Stop();
}
20 changes: 11 additions & 9 deletions src/bench/checkblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,32 @@
#include "streams.h"
#include "consensus/validation.h"

namespace block_bench {
#include "bench/data/block413567.raw.h"
}

// These are the two major time-sinks which happen after we have fully received
// a block off the wire, but before we can relay the block on to peers using
// compact block relay.

static void DeserializeBlockTest(benchmark::State& state)
{
CDataStream stream((const char*)block_bench::block413567,
(const char*)&block_bench::block413567[sizeof(block_bench::block413567)],
CDataStream stream((const char*)benchmark::data::block413567.data(),
(const char*)benchmark::data::block413567.data() + benchmark::data::block413567.size(),
SER_NETWORK, PROTOCOL_VERSION);
char a;
stream.write(&a, 1); // Prevent compaction

while (state.KeepRunning()) {
CBlock block;
stream >> block;
assert(stream.Rewind(sizeof(block_bench::block413567)));
bool rewound = stream.Rewind(benchmark::data::block413567.size());
assert(rewound);
}
}

static void DeserializeAndCheckBlockTest(benchmark::State& state)
{
CDataStream stream((const char*)block_bench::block413567,
(const char*)&block_bench::block413567[sizeof(block_bench::block413567)],
CDataStream stream((const char*)benchmark::data::block413567.data(),
(const char*)benchmark::data::block413567.data() + benchmark::data::block413567.size(),
SER_NETWORK, PROTOCOL_VERSION);
char a;
stream.write(&a, 1); // Prevent compaction
Expand All @@ -45,10 +44,13 @@ static void DeserializeAndCheckBlockTest(benchmark::State& state)
while (state.KeepRunning()) {
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
stream >> block;
assert(stream.Rewind(sizeof(block_bench::block413567)));
bool rewound = stream.Rewind(benchmark::data::block413567.size());
assert(rewound);

// block413567.raw is a Bitcoin Core benchmark vector; keep the
// full-block structural checks, but do not require Firo PoW validity.
CValidationState validationState;
assert(CheckBlock(block, validationState, params));
assert(CheckBlock(block, validationState, params, false, true, 0));
}
}

Expand Down
34 changes: 34 additions & 0 deletions src/bench/coin_selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,42 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "bench.h"

#include "dbwrapper.h"
#include "llmq/quorums_instantsend.h"
#include "wallet/wallet.h"

#include <boost/foreach.hpp>
#include <set>

namespace {

class ScopedInstantSendManager
{
public:
ScopedInstantSendManager()
: db("", 1 << 20, true, true)
, manager(db)
, previous(llmq::quorumInstantSendManager)
{
if (previous == nullptr) {
llmq::quorumInstantSendManager = &manager;
}
}

~ScopedInstantSendManager()
{
if (previous == nullptr) {
llmq::quorumInstantSendManager = nullptr;
}
}

private:
CDBWrapper db;
llmq::CInstantSendManager manager;
llmq::CInstantSendManager* const previous;
};

static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<COutput>& vCoins)
{
int nInput = 0;
Expand All @@ -33,6 +64,7 @@ static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<CO
// (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484)
static void CoinSelection(benchmark::State& state)
{
ScopedInstantSendManager instant_send;
const CWallet wallet;
std::vector<COutput> vCoins;
LOCK(wallet.cs_wallet);
Expand All @@ -57,4 +89,6 @@ static void CoinSelection(benchmark::State& state)
}
}

} // namespace

BENCHMARK(CoinSelection);
2 changes: 1 addition & 1 deletion src/bench/mempool_eviction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static void AddTx(const CTransaction& tx, const CAmount& nFee, CTxMemPool& pool)
unsigned int sigOpCost = 4;
LockPoints lp;
pool.addUnchecked(tx.GetHash(), CTxMemPoolEntry(
MakeTransactionRef(tx), nFee, nTime, dPriority, nHeight,
MakeTransactionRef(tx), nFee, nTime, nHeight,
tx.GetValueOut(), spendsCoinbase, sigOpCost, lp));
}

Expand Down
Loading