Skip to content

Commit 7d36b1f

Browse files
committed
Merge with master
1 parent c0bd73d commit 7d36b1f

File tree

19 files changed

+91
-86
lines changed

19 files changed

+91
-86
lines changed

CMakeLists.txt

+12-10
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,40 @@ if (MORUM_BUILD_TRACY)
2020
list(APPEND VCPKG_MANIFEST_FEATURES "tracy")
2121
endif()
2222

23-
project(cpp-jam
23+
project(morum
2424
VERSION 0.1.0
2525
LANGUAGES C CXX
2626
)
27+
2728
set(CMAKE_CXX_STANDARD 23)
2829
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2930
set(CMAKE_CXX_EXTENSIONS OFF)
3031
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
31-
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
3232
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
3333

3434
add_compile_options(-Wall -Wextra)
3535

36-
option(MORUM_TRACE "Enable tracing" OFF)
36+
if ((CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
37+
add_compile_options(-flto=thin)
38+
endif()
3739

38-
find_package(PkgConfig REQUIRED)
39-
pkg_check_modules(libb2 REQUIRED IMPORTED_TARGET GLOBAL libb2)
40+
option(MORUM_ASAN "Enable address sanitizer" OFF)
41+
option(MORUM_TSAN "Enable address sanitizer" OFF)
42+
option(MORUM_UBSAN "Enable address sanitizer" OFF)
43+
option(MORUM_TRACE "Enable tracing" OFF)
4044

4145
find_package(Python3 REQUIRED)
42-
find_package(Boost CONFIG REQUIRED)
46+
find_package(Boost CONFIG REQUIRED COMPONENTS algorithm program_options outcome)
4347
find_package(fmt CONFIG REQUIRED)
4448
find_package(yaml-cpp CONFIG REQUIRED)
45-
find_package(jam_crust CONFIG REQUIRED)
4649
find_package(scale CONFIG REQUIRED)
4750
find_package(soralog CONFIG REQUIRED)
48-
find_package(schnorrkel_crust CONFIG REQUIRED)
4951
find_package(Boost.DI CONFIG REQUIRED)
5052
find_package(qtils CONFIG REQUIRED)
5153
find_package(prometheus-cpp CONFIG REQUIRED)
5254
find_package(RocksDB CONFIG REQUIRED)
5355
find_package(nlohmann_json CONFIG REQUIRED)
56+
find_package(qdrvm-crates CONFIG REQUIRED)
5457

5558
find_library(BLAKE2_LIB blake2b)
5659
add_library(blake2b STATIC IMPORTED)
@@ -62,7 +65,6 @@ target_include_directories(headers INTERFACE
6265
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
6366
)
6467

65-
6668
if (MORUM_ASAN)
6769
add_compile_options(-fsanitize=address)
6870
add_link_options(-fsanitize=address)
@@ -72,6 +74,7 @@ if (MORUM_UBSAN)
7274
add_compile_options(-fsanitize=undefined -fno-sanitize-recovery=undefined)
7375
add_link_options(-fsanitize=undefined)
7476
endif()
77+
7578
if (MORUM_TSAN)
7679
add_compile_options(-fsanitize=thread)
7780
add_link_options(-fsanitize=thread)
@@ -83,7 +86,6 @@ else()
8386
option(QTILS_ASSERT "Enable asserts" ON)
8487
endif()
8588

86-
8789
add_subdirectory(src)
8890

8991
if(MORUM_BUILD_BENCHMARKS)

CMakePresets.json

-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"MORUM_BUILD_TRACY": "ON",
2020
"MORUM_ASAN": "OFF",
2121
"MORUM_UBSAN": "OFF",
22-
"MORUM_MSAN": "OFF",
2322
"MORUM_TSAN": "OFF"
2423
}
2524
},
@@ -33,7 +32,6 @@
3332
"MORUM_BUILD_TESTS": "ON",
3433
"MORUM_ASAN": "OFF",
3534
"MORUM_UBSAN": "OFF",
36-
"MORUM_MSAN": "OFF",
3735
"MORUM_TSAN": "OFF"
3836
}
3937
}

benchmark/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22
add_executable(set_get_benchmark merkle_tree/set_get.cpp)
3-
target_link_libraries(set_get_benchmark benchmark::benchmark merkle_tree Tracy::TracyClient)
3+
target_link_libraries(set_get_benchmark benchmark::benchmark merkle_tree)

include/morum/common.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ namespace morum {
9191
} // namespace morum
9292

9393
template <>
94-
struct fmt::formatter<morum::StorageError, char> {
94+
struct std::formatter<morum::StorageError, char> {
9595
template <class ParseContext>
9696
constexpr ParseContext::iterator parse(ParseContext &ctx) {
9797
auto it = ctx.begin();
@@ -102,7 +102,7 @@ struct fmt::formatter<morum::StorageError, char> {
102102
FmtContext::iterator format(const morum::StorageError &e,
103103
FmtContext &ctx) const {
104104
auto out = ctx.out();
105-
fmt::format_to(out,
105+
std::format_to(out,
106106
"From {}:{} - {}\n",
107107
e.origin.file_name(),
108108
e.origin.line(),

src/app/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ set(BUILD_VERSION_CPP "${CMAKE_BINARY_DIR}/generated/app/build_version.cpp")
88
set(GET_VERSION_SCRIPT "${CMAKE_SOURCE_DIR}/scripts/get_version.sh")
99
add_custom_command(
1010
OUTPUT ${BUILD_VERSION_CPP}
11-
COMMAND echo "// Auto-generated file\\n" > ${BUILD_VERSION_CPP}
12-
COMMAND echo "#include <string>\\n" >> ${BUILD_VERSION_CPP}
11+
COMMAND echo "// Auto-generated file\n" > ${BUILD_VERSION_CPP}
12+
COMMAND echo "#include <string>\n" >> ${BUILD_VERSION_CPP}
1313
COMMAND echo "namespace jam {" >> ${BUILD_VERSION_CPP}
1414
COMMAND echo " const std::string &buildVersion() {" >> ${BUILD_VERSION_CPP}
1515
COMMAND printf " static const std::string buildVersion(\"" >> ${BUILD_VERSION_CPP}

src/crypto/ed25519.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#include <schnorrkel_crust.h>
7+
#include <schnorrkel/schnorrkel.h>
88
#include <qtils/bytes.hpp>
99

1010
namespace jam::crypto::ed25519 {

src/merkle_tree/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ target_include_directories(merkle_tree
33
PUBLIC
44
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
55
)
6-
target_link_libraries(merkle_tree PUBLIC blake2b Tracy::TracyClient)
6+
target_link_libraries(merkle_tree PUBLIC blake2b)
77
add_library(morum::merkle_tree ALIAS merkle_tree)
88
if (MORUM_TRACE)
99
add_compile_definitions(merkle_tree PUBLIC MORUM_ENABLE_TRACE)

src/merkle_tree/db.cpp

+33-33
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@
55
*/
66

77
#include <morum/db.hpp>
8-
8+
#include <qtils/assert.hpp>
9+
#include <qtils/bytestr.hpp>
10+
#include <qtils/macro/unwrap.hpp>
911
#include <rocksdb/db.h>
1012
#include <rocksdb/options.h>
1113
#include <rocksdb/slice.h>
1214
#include <rocksdb/status.h>
1315
#include <rocksdb/write_batch.h>
14-
#include <qtils/assert.hpp>
15-
#include <qtils/byte_utils.hpp>
16-
#include <qtils/macro/unwrap.hpp>
1716

1817
namespace morum {
1918

2019
template <typename T>
21-
std::expected<T, StorageError> wrap_status(
22-
T &&t, const rocksdb::Status &status) {
20+
std::expected<T, StorageError> wrap_status(T &&t,
21+
const rocksdb::Status &status) {
2322
if (!status.ok()) {
2423
return std::unexpected(StorageError{status.ToString()});
2524
}
@@ -83,7 +82,7 @@ namespace morum {
8382
// a vector of column family handles
8483
QTILS_ASSERT_EQ(family_idx++, static_cast<int>(family));
8584
desc.emplace_back(std::string{to_string_nocheck(family)},
86-
rocksdb::ColumnFamilyOptions{});
85+
rocksdb::ColumnFamilyOptions{});
8786
}
8887

8988
QTILS_UNWRAP_void(wrap_status(
@@ -102,17 +101,17 @@ namespace morum {
102101
class RocksDbBatch final : public RocksDb::Batch,
103102
public RocksDbColumnFamily::Batch {
104103
public:
105-
RocksDbBatch(
106-
std::shared_ptr<RocksDb> db, rocksdb::ColumnFamilyHandle *default_cf)
104+
RocksDbBatch(std::shared_ptr<RocksDb> db,
105+
rocksdb::ColumnFamilyHandle *default_cf)
107106
: db{db}, default_cf{default_cf} {
108107
QTILS_ASSERT(db != nullptr);
109108
QTILS_ASSERT(default_cf != nullptr);
110109
}
111110

112111
virtual ~RocksDbBatch() = default;
113112

114-
std::expected<void, StorageError> write(
115-
qtils::ByteSpan key, qtils::ByteSpan value) override {
113+
std::expected<void, StorageError> write(qtils::ByteSpan key,
114+
qtils::ByteSpan value) override {
116115
return wrap_status(
117116
batch.Put(default_cf, qtils::byte2str(key), qtils::byte2str(value)));
118117
}
@@ -122,26 +121,26 @@ namespace morum {
122121
}
123122

124123
std::expected<void, StorageError> write(ColumnFamilyId cf,
125-
qtils::ByteSpan key,
126-
qtils::ByteSpan value) override {
124+
qtils::ByteSpan key,
125+
qtils::ByteSpan value) override {
127126
return wrap_status(batch.Put(db->handles[static_cast<size_t>(cf)],
128-
qtils::byte2str(key),
129-
qtils::byte2str(value)));
127+
qtils::byte2str(key),
128+
qtils::byte2str(value)));
130129
}
131130

132-
std::expected<void, StorageError> remove(
133-
ColumnFamilyId cf, qtils::ByteSpan key) override {
134-
return wrap_status(batch.Delete(
135-
db->handles[static_cast<size_t>(cf)], qtils::byte2str(key)));
131+
std::expected<void, StorageError> remove(ColumnFamilyId cf,
132+
qtils::ByteSpan key) override {
133+
return wrap_status(batch.Delete(db->handles[static_cast<size_t>(cf)],
134+
qtils::byte2str(key)));
136135
}
137136

138137
std::shared_ptr<RocksDb> db;
139138
rocksdb::ColumnFamilyHandle *default_cf;
140139
rocksdb::WriteBatch batch;
141140
};
142141

143-
RocksDb::RocksDb(
144-
rocksdb::DB *db, std::vector<rocksdb::ColumnFamilyHandle *> &&handles)
142+
RocksDb::RocksDb(rocksdb::DB *db,
143+
std::vector<rocksdb::ColumnFamilyHandle *> &&handles)
145144
: db{db}, handles{std::move(handles)} {
146145
QTILS_ASSERT(db != nullptr);
147146
}
@@ -162,7 +161,8 @@ namespace morum {
162161
}
163162

164163
std::unique_ptr<RocksDb::Batch> RocksDb::start_batch() {
165-
return std::make_unique<RocksDbBatch>(shared_from_this(),
164+
return std::make_unique<RocksDbBatch>(
165+
shared_from_this(),
166166
handles.at(std::to_underlying(ColumnFamilyId::DEFAULT)));
167167
}
168168

@@ -174,8 +174,8 @@ namespace morum {
174174
return wrap_status(db->Write(rocksdb::WriteOptions{}, &rocks_batch->batch));
175175
}
176176

177-
RocksDbColumnFamily::RocksDbColumnFamily(
178-
std::shared_ptr<RocksDb> db, ColumnFamilyId family)
177+
RocksDbColumnFamily::RocksDbColumnFamily(std::shared_ptr<RocksDb> db,
178+
ColumnFamilyId family)
179179
: db{db}, handle{db->handles.at(std::to_underlying(family))} {}
180180

181181
std::expected<void, StorageError> RocksDbColumnFamily::write(
@@ -193,9 +193,9 @@ namespace morum {
193193
RocksDbColumnFamily::read(qtils::ByteSpan key) const {
194194
std::string value;
195195
auto status = db->db->Get(rocksdb::ReadOptions{},
196-
handle,
197-
rocksdb::Slice{qtils::byte2str(key)},
198-
&value);
196+
handle,
197+
rocksdb::Slice{qtils::byte2str(key)},
198+
&value);
199199
if (status.IsNotFound()) {
200200
return std::nullopt;
201201
}
@@ -204,13 +204,13 @@ namespace morum {
204204
}
205205

206206
std::expected<std::optional<size_t>, StorageError>
207-
RocksDbColumnFamily::read_to(
208-
qtils::ByteSpan key, qtils::ByteSpanMut value) const {
207+
RocksDbColumnFamily::read_to(qtils::ByteSpan key,
208+
qtils::ByteSpanMut value) const {
209209
std::string res;
210210
auto status = db->db->Get(rocksdb::ReadOptions{},
211-
handle,
212-
rocksdb::Slice{qtils::byte2str(key)},
213-
&res);
211+
handle,
212+
rocksdb::Slice{qtils::byte2str(key)},
213+
&res);
214214
if (status.IsNotFound()) {
215215
return std::nullopt;
216216
}
@@ -240,4 +240,4 @@ namespace morum {
240240
db->db->Write(rocksdb::WriteOptions{}, &rocks_batch->batch));
241241
}
242242

243-
} // namespace morum
243+
} // namespace morum

src/merkle_tree/merkle_tree.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ namespace morum {
129129
QTILS_ASSERT(id == 0);
130130
return {};
131131
}
132-
QTILS_UNWRAP(auto &parent_opt, find_parent_branch(key));
132+
QTILS_UNWRAP(const auto &parent_opt, find_parent_branch(key));
133133
if (!parent_opt) {
134134
// parent must be a leaf root
135135
QTILS_ASSERT(get_root()->is_leaf());
@@ -180,20 +180,20 @@ namespace morum {
180180

181181
std::expected<std::optional<qtils::ByteSpan>, StorageError> MerkleTree::get(
182182
const Hash32 &key) const {
183-
QTILS_UNWRAP(auto &leaf_id_opt, find_leaf(key));
183+
QTILS_UNWRAP(const auto &leaf_id_opt, find_leaf(key));
184184
if (!leaf_id_opt) {
185185
return std::nullopt;
186186
}
187187
auto leaf_id = *leaf_id_opt;
188188
auto &leaf = nodes_->get(leaf_id)->as_leaf();
189-
QTILS_UNWRAP(auto &value, get_value(leaf.hash_or_value()));
189+
QTILS_UNWRAP(const auto &value, get_value(leaf.hash_or_value()));
190190

191191
return value;
192192
}
193193

194194
std::expected<bool, StorageError> MerkleTree::exists(
195195
const Hash32 &key) const {
196-
QTILS_UNWRAP(auto &leaf_opt, find_leaf(key));
196+
QTILS_UNWRAP(const auto &leaf_opt, find_leaf(key));
197197
return leaf_opt.has_value();
198198
}
199199

@@ -228,7 +228,7 @@ namespace morum {
228228
if (auto it = value_cache_.find(hash); it != value_cache_.end()) {
229229
return it->second;
230230
}
231-
QTILS_UNWRAP(auto &value_opt, value_storage_->read(hash));
231+
QTILS_UNWRAP(const auto & value_opt, value_storage_->read(hash));
232232
if (!value_opt) {
233233
return std::unexpected(StorageError{"Value missing"});
234234
}
@@ -253,7 +253,7 @@ namespace morum {
253253
while (current->is_branch()) {
254254
auto bit = get_bit(key, path.size_bits());
255255
path.end_bit++;
256-
QTILS_UNWRAP(auto &child_opt,
256+
QTILS_UNWRAP(const auto & child_opt,
257257
get_child_idx(const_cast<Branch &>(current->as_branch()), bit, path));
258258
if (!child_opt || nodes_->get(*child_opt)->is_leaf()) {
259259
MORUM_TRACE("parent is {}, path {}", current_idx, path);
@@ -284,7 +284,7 @@ namespace morum {
284284
NodeId current_id = 0;
285285
size_t path_len = 0;
286286
while (current->is_branch()) {
287-
QTILS_UNWRAP(auto &child_opt,
287+
QTILS_UNWRAP(const auto & child_opt,
288288
get_child_idx(const_cast<Branch &>(current->as_branch()),
289289
get_bit(key, path_len),
290290
qtils::BitSpan<>{key, 0, path_len}));

test-vectors/disputes/CMakeLists.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
add_test_vector(disputes tiny full)
88

99
add_test_vector_libraries(disputes
10-
jam_crust::jam_crust
11-
PkgConfig::libb2
12-
schnorrkel_crust::schnorrkel_crust
10+
blake2b
11+
schnorrkel::schnorrkel
1312
)
1413

tests/CMakeLists.txt renamed to test-vectors/history/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# SPDX-License-Identifier: Apache-2.0
55
#
66

7-
message(STATUS "There are no tests yet")
7+
add_test_vector(history)

test-vectors/jamtestvectors

Submodule jamtestvectors updated 480 files

test-vectors/safrole/CMakeLists.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@
77
add_test_vector(safrole tiny full)
88

99
add_test_vector_libraries(safrole
10-
jam_crust::jam_crust
11-
PkgConfig::libb2
10+
blake2b
1211
)

test/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ target_include_directories(compatibility_test
1010
target_link_libraries(compatibility_test merkle_tree nlohmann_json::nlohmann_json qtils::qtils)
1111

1212
morum_add_test(tree_test merkle_tree/tree_test.cpp)
13-
target_link_libraries(tree_test merkle_tree RocksDB::rocksdb Tracy::TracyClient)
13+
target_link_libraries(tree_test merkle_tree RocksDB::rocksdb)
1414

1515
morum_add_test(primitives_test merkle_tree/primitives_test.cpp)
1616
target_link_libraries(primitives_test merkle_tree)

0 commit comments

Comments
 (0)