Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
13f3d36
Introduce merkle tree implementation
Harrm Nov 6, 2024
04f6899
Fix for CLang
Harrm Nov 6, 2024
e0f8466
IWYU fixes and update qtils
Harrm Nov 7, 2024
a07da52
Put changes across different column families in a common batch
Harrm Nov 12, 2024
d6a218e
Fixes for Apple Clang
Nov 7, 2024
8d9fccb
Fix for Mac CLang
Harrm Nov 12, 2024
464930d
Move some code to cpp files
Harrm Nov 12, 2024
573b68d
Batches fix
Harrm Nov 14, 2024
9f4801f
Update qtils
Harrm Nov 15, 2024
8fcebe1
Merge with master
Harrm Apr 8, 2025
cae439d
Introduce merkle tree implementation
Harrm Nov 6, 2024
12faebd
Put changes across different column families in a common batch
Harrm Nov 12, 2024
9152495
Update qtils
Harrm Nov 15, 2024
414d0ee
rename jam to morum
Harrm Apr 8, 2025
e84efef
rename jam to morum
Harrm Apr 10, 2025
57ec932
Fix buildVersion and update qdrvm crates
Harrm Apr 11, 2025
3bb2b01
Fix makefile
Harrm Apr 11, 2025
25d9fde
Update for GCC 15
Harrm Jun 18, 2025
d0b7209
Merge branch 'master' of github.com:qdrvm/cpp-jam into feature/tree
Harrm Jun 18, 2025
be8872e
Merging with master
Harrm Jun 18, 2025
a81f3a5
Various merge fixes
Harrm Jun 19, 2025
2ecaae8
Delete .vscode/settings.json
Harrm Jun 19, 2025
70e7404
Fix for common types
Harrm Jun 19, 2025
6ea5975
Try simple gcc-14 switch
Harrm Jun 19, 2025
93f9f48
Try simple gcc-14 switch
Harrm Jun 19, 2025
5d4431f
Try simple gcc-14 switch
Harrm Jun 19, 2025
09a475a
Try simple gcc-14 switch
Harrm Jun 19, 2025
0b48db3
Fix warnings
Harrm Jun 19, 2025
3a2c38e
Fix warning
Harrm Jun 19, 2025
f011d21
Fix warning
Harrm Jun 19, 2025
0db15ee
Fix null opt
Harrm Jun 20, 2025
3a402e4
Couple small fixes
Harrm Jun 20, 2025
de5ab3c
Couple small fixes
Harrm Jun 20, 2025
c3669e2
Fix benchmark
Harrm Jun 20, 2025
8573df7
review fixes
Harrm Jun 23, 2025
5d749ab
Review fixes
Harrm Jun 23, 2025
a5b58e2
Review fixes
Harrm Jun 24, 2025
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
2 changes: 2 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CompileFlags:
Add: [-D__cpp_concepts=202002L]
7 changes: 7 additions & 0 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ jobs:
toolchain: stable
components: rustfmt, clippy

- name: switch to gcc-14 on linux
if: ${{ startsWith(matrix.os, 'ubuntu') }}
run: |
sudo apt install gcc-14 g++-14
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 100 --slave /usr/bin/g++ g++ /usr/bin/g++-14 --slave /usr/bin/gcov gcov /usr/bin/gcov-14
sudo update-alternatives --set gcc /usr/bin/gcc-14

- name: "Restore cache dependencies"
id: cache-restore
if: ${{ env.USE_CACHE == 'true' }}
Expand Down
11 changes: 4 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
Expand All @@ -34,12 +30,13 @@
# IDE auxiliaries
.idea

/build
/build-ex
/build*
/cmake-build-*

/.build
/.venv
/.vcpkg
/.build*
.vscode

CMakeUserPresets.json
/vcpkg_installed
109 changes: 81 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,36 @@

cmake_minimum_required(VERSION 3.25)

option(TESTING "Build and run test suite" ON)
if (TESTING)
list(APPEND VCPKG_MANIFEST_FEATURES test)
endif ()
option(MORUM_BUILD_TESTS "Build tests" ON)
option(MORUM_BUILD_BENCHMARKS "Build benchmarks" ON)
option(MORUM_BUILD_TRACY "Enable Tracy profiler" OFF)

set(CMAKE_CXX_STANDARD 20)
if (MORUM_BUILD_TESTS)
list(APPEND VCPKG_MANIFEST_FEATURES "test")
endif()
if (MORUM_BUILD_BENCHMARKS)
list(APPEND VCPKG_MANIFEST_FEATURES "benchmark")
endif()
if (MORUM_BUILD_TRACY)
list(APPEND VCPKG_MANIFEST_FEATURES "tracy")
endif()

project(morum
VERSION 0.1.0
LANGUAGES C CXX
)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_CXX_EXTENSIONS OFF)
Copy link
Member

@xDimon xDimon Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't off extensions, please. We are using "statement expressions" in some places.

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API ON)

project(cpp-jam
VERSION 0.0.1
LANGUAGES CXX C
)
add_compile_options(-Wall -Wextra -Werror)

if ((CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-flto=thin)
endif()

if(DEFINED CMAKE_TOOLCHAIN_FILE AND CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg")
if(DEFINED VCPKG_TARGET_TRIPLET AND VCPKG_TARGET_TRIPLET)
Expand Down Expand Up @@ -61,21 +76,28 @@ include(GNUInstallDirs)
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message(STATUS "Boost_DIR: ${Boost_DIR}")

find_package(Python3 REQUIRED)

find_package(PkgConfig REQUIRED)
pkg_check_modules(libb2 REQUIRED IMPORTED_TARGET GLOBAL libb2)
option(MORUM_ASAN "Enable address sanitizer" OFF)
option(MORUM_TSAN "Enable address sanitizer" OFF)
option(MORUM_UBSAN "Enable address sanitizer" OFF)
option(MORUM_TRACE "Enable tracing" OFF)

find_package(Boost CONFIG REQUIRED COMPONENTS algorithm outcome program_options property_tree)
set(Python3_FIND_VIRTUALENV ONLY)
find_package(Python3 REQUIRED)
find_package(Boost CONFIG REQUIRED COMPONENTS algorithm program_options outcome property_tree)
find_package(fmt CONFIG REQUIRED)
find_package(yaml-cpp CONFIG REQUIRED)
find_package(qdrvm-crates CONFIG REQUIRED)
find_package(scale CONFIG REQUIRED)
find_package(soralog CONFIG REQUIRED)
find_package(Boost.DI CONFIG REQUIRED)
find_package(qtils CONFIG REQUIRED)
find_package(prometheus-cpp CONFIG REQUIRED)
find_package(RocksDB CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(qdrvm-crates CONFIG REQUIRED)

find_library(BLAKE2_LIB blake2b)
add_library(blake2b STATIC IMPORTED)
set_property(TARGET blake2b PROPERTY IMPORTED_LOCATION ${BLAKE2_LIB})

# TODO Temporarily commented out until gcc is updated (gcc-13 crashes because of this).
# if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
Expand All @@ -92,20 +114,51 @@ target_include_directories(headers INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

include_directories(${CMAKE_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${CMAKE_SOURCE_DIR}/src/third_party)
include_directories(${CMAKE_SOURCE_DIR}/src/_TODO)
include_directories(${CMAKE_BINARY_DIR}/generated)
if (MORUM_ASAN)
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()

if (MORUM_UBSAN)
add_compile_options(-fsanitize=undefined -fno-sanitize-recovery=undefined)
add_link_options(-fsanitize=undefined)
endif()

add_subdirectory(src)
if (MORUM_TSAN)
add_compile_options(-fsanitize=thread)
add_link_options(-fsanitize=thread)
endif()

if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
option(QTILS_ASSERT "Enable asserts" OFF)
else()
option(QTILS_ASSERT "Enable asserts" ON)
endif()

if (TESTING)
enable_testing()
add_subdirectory(src)

find_package(GTest CONFIG REQUIRED)
set(GTEST_DEPS GTest::gtest_main)
if(MORUM_BUILD_BENCHMARKS)
find_package(benchmark CONFIG REQUIRED)
add_subdirectory(benchmark)
endif()

add_subdirectory(test-vectors)
add_subdirectory(tests)
if(MORUM_BUILD_TESTS)
find_package(GTest CONFIG REQUIRED)
set(GTEST_DEPS GTest::gtest_main)

enable_testing()

function (morum_add_test TEST_NAME TEST_SRC)
add_executable(${TEST_NAME} ${TEST_SRC})
target_include_directories(${TEST_NAME}
PUBLIC
${CMAKE_SOURCE_DIR}/include
)
add_compile_definitions(${TEST_NAME} PUBLIC MORUM_TEST_BUILD)
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME} WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/test_bin")
set_target_properties(${TEST_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/test_bin")
endfunction()

add_subdirectory(test-vectors)
add_subdirectory(test)
endif ()
33 changes: 29 additions & 4 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,39 @@
"version": 2,
"configurePresets": [
{
"name": "default",
"name": "vcpkg",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"CMAKE_BUILD_TYPE": "Debug",
"VCPKG_OVERLAY_PORTS": "${sourceDir}/vcpkg-overlay"
}
},
{
"name": "dev",
"inherits": "vcpkg",
"binaryDir": "${sourceDir}/build-dev",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"QTILS_ASSERT": "ON",
"MORUM_BUILD_TRACY": "ON",
"MORUM_ASAN": "OFF",
"MORUM_UBSAN": "OFF",
"MORUM_TSAN": "OFF"
}
},
{
"name": "debug",
"inherits": "vcpkg",
"binaryDir": "${sourceDir}/build-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"MORUM_BUILD_TRACY": "ON",
"MORUM_BUILD_TESTS": "ON",
"MORUM_ASAN": "OFF",
"MORUM_UBSAN": "OFF",
"MORUM_TSAN": "OFF"
}
}
]
}
}
4 changes: 2 additions & 2 deletions CODESTYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
#include <boost/...>
#include <fmt/...>
#include <gtest/...>
#include <jam_crust.h>
#include <ark_vrf/...>
#include <qtils/...>
#include <scale/...>

// project
#include <jam/...>
#include <morum/...>
#include <test-vectors/...>
```
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ configure:
@echo "=== Configuring..."
export PATH="$$HOME/.cargo/bin:$$PATH" && \
source $$HOME/.cargo/env 2>/dev/null || true && \
VCPKG_ROOT=$(VCPKG) cmake --preset=default -DPython3_EXECUTABLE="$(VENV)/bin/python3" -B $(BUILD) $(PROJECT)
VCPKG_ROOT=$(VCPKG) cmake --preset=debug -DPython3_EXECUTABLE="$(VENV)/bin/python3" -B $(BUILD) $(PROJECT)

build:
@echo "=== Building..."
Expand Down
3 changes: 3 additions & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

add_executable(set_get_benchmark merkle_tree/set_get.cpp)
target_link_libraries(set_get_benchmark benchmark::benchmark merkle_tree)
124 changes: 124 additions & 0 deletions benchmark/merkle_tree/set_get.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#include <cstddef>
#include <expected>
#include <filesystem>
#include <memory>
#include <optional>
#include <random>
#include <ranges>
#include <string>
#include <utility>
#include <vector>

#include <benchmark/benchmark.h>
#include <client/TracyScoped.hpp>
#include <tracy/Tracy.hpp>
#include <qtils/final_action.hpp>

#include <morum/archive_backend.hpp>
#include <morum/common.hpp>
#include <morum/db.hpp>
#include <morum/merkle_tree.hpp>

constexpr unsigned seed = 42;
static std::mt19937_64 rand_engine{seed};

template <std::ranges::input_range R>
void fill_random(R &&span) {
static std::uniform_int_distribution<uint8_t> dist(0, 255);

for (auto &byte : span) {
byte = dist(rand_engine);
}
}

morum::Hash32 random_hash() {
morum::Hash32 hash;
fill_random(hash);
return hash;
}

qtils::ByteVec random_vector(size_t min_size = 1, size_t max_size = 128) {
std::uniform_int_distribution<size_t> dist(min_size, max_size);
size_t size = dist(rand_engine);

qtils::ByteVec v(size);
fill_random(v);
return v;
}

std::unique_ptr<morum::ArchiveTrieDb> trie_db;
morum::Hash32 last_root{};

static void BM_SetGet(benchmark::State &state) {
rand_engine.seed(42);
constexpr int INSERTION_NUM = 1000;

for (auto _ : state) {
ZoneNamedN(loop_zone, "loop", true);

auto tree = trie_db->load_tree(last_root).value().value();

std::vector<std::pair<morum::Hash32, qtils::ByteVec>> insertions;
for (int i = 0; i < INSERTION_NUM; i++) {
insertions.emplace_back(random_hash(), random_vector());
}
{
ZoneNamedN(setter_zone, "set", true);
for (auto &[k, v] : insertions) {
tree->set(k, qtils::ByteVec{v}).value();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Возможно тут стоит вставить ассерт на наличие результата

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will throw an exception and kill the benchmark, which in this place works fine in my opinion.

}
}
{
ZoneNamedN(getter_zone, "get", true);

for (auto &[k, v] : insertions) {
tree->get(k).value();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Возможно тут стоит вставить ассерт на наличие результата

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will throw an exception and kill the benchmark, which in this place works fine in my opinion.

}
}
{
ZoneNamedN(calculate_hash_zone, "calculate_hash", true);
trie_db->get_root_and_store(*tree).value();
}

FrameMark;
}
}

BENCHMARK(BM_SetGet);


int main(int argc, char **argv) {
char arg0_default[] = "benchmark";
char *args_default = arg0_default;
if (argc == 0) {
argc = 1;
argv = &args_default;
}

qtils::FinalAction cleanup{[]() {
trie_db.reset();
std::filesystem::remove_all("./test_db");
}};

auto db = std::shared_ptr{morum::open_db("./test_db").value()};

trie_db = std::make_unique<morum::ArchiveTrieDb>(db);

auto tree = trie_db->empty_tree();
constexpr int INSERTION_NUM = 5000;
{
ZoneNamedN(setter_zone, "initial insertions", true);

for (int i = 0; i < INSERTION_NUM; i++) {
tree->set(random_hash(), qtils::ByteVec{random_vector()}).value();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Возможно тут стоит вставить ассерт на наличие результата

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will throw an exception and kill the benchmark, which in this place works fine in my opinion.

}
}
last_root = trie_db->get_root_and_store(*tree).value();
::benchmark::Initialize(&argc, argv);
if (::benchmark::ReportUnrecognizedArguments(argc, argv)) {
return 1;
}
::benchmark::RunSpecifiedBenchmarks();
::benchmark::Shutdown();
return 0;
}
2 changes: 1 addition & 1 deletion example/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ logging:
level: trace
is_fallback: true
children:
- name: jam
- name: morum
children:
- name: modules
children:
Expand Down
Loading
Loading