Skip to content
Draft
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: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ commands:
command: |
if [[ "<<parameters.compiler_id>>" == "clang" ]]
then
conan_profile=linux_x64_clang_16_release
conan_profile=linux_x64_clang_18_release
else
conan_profile=linux_x64_gcc_11_release
fi
Expand Down Expand Up @@ -132,7 +132,7 @@ commands:
- run:
name: "CMake Fuzzer"
working_directory: ~/build
command: cmake ../project -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONAN_PROFILE=linux_x64_clang_16_release -DCMAKE_TOOLCHAIN_FILE=../project/cmake/toolchain/clang_libcxx.cmake -DSILKWORM_FUZZER=ON
command: cmake ../project -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONAN_PROFILE=linux_x64_clang_18_release -DCMAKE_TOOLCHAIN_FILE=../project/cmake/toolchain/clang_libcxx.cmake -DSILKWORM_FUZZER=ON
- run:
name: "Build Fuzzer"
command: |
Expand Down Expand Up @@ -256,7 +256,7 @@ jobs:
- build_using_conan:
build_type: Debug
compiler_id: clang
compiler_version: 17
compiler_version: 18
- test:
sanitizer: address,undefined

Expand Down Expand Up @@ -415,7 +415,7 @@ jobs:
parameters:
clang_version_min:
type: integer
default: 16
default: 18
clang_version_latest:
type: integer
default: 18
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/fuzzer-common-steps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ runs:
steps:
- name: Install Compiler
shell: bash
run: cmake/setup/compiler_install.sh clang 16
run: cmake/setup/compiler_install.sh clang 18

- name: Clean Build Directory
shell: bash
Expand All @@ -28,7 +28,7 @@ runs:
- name: Configure CMake
shell: bash
working-directory: ${{runner.workspace}}/silkworm/build
run: CC=clang-16 CXX=clang++-16 cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONAN_PROFILE=linux_x64_clang_16_release -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchain/clang_libcxx.cmake -DSILKWORM_FUZZER=ON -DSILKWORM_FUZZER_SANITIZERS=${{inputs.fuzzer_sanitizers}}
run: CC=clang-16 CXX=clang++-16 cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONAN_PROFILE=linux_x64_clang_18_release -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchain/clang_libcxx.cmake -DSILKWORM_FUZZER=ON -DSILKWORM_FUZZER_SANITIZERS=${{inputs.fuzzer_sanitizers}}

- name: Build Silkworm Fuzzer Test
shell: bash
Expand Down
5 changes: 0 additions & 5 deletions cmake/conan_quiet.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ set(GTest_FIND_QUIETLY YES)
set(LibtorrentRasterbar_FIND_QUIETLY YES)
set(Snappy_FIND_QUIETLY YES)
set(Microsoft.GSL_FIND_QUIETLY YES)
set(OpenSSL_FIND_QUIETLY YES)
set(fmt_FIND_QUIETLY YES)
set(roaring_FIND_QUIETLY YES)
set(BZip2_FIND_QUIETLY YES)
Expand All @@ -25,15 +24,11 @@ set(asio-grpc_FIND_QUIETLY YES)
set(benchmark_FIND_QUIETLY YES)
set(gmp_FIND_QUIETLY YES)
set(Boost_FIND_QUIETLY YES)
set(SQLite3_FIND_QUIETLY YES)
set(mimalloc_FIND_QUIETLY YES)
set(re2_FIND_QUIETLY YES)
set(gRPC_FIND_QUIETLY YES)
set(protobuf_FIND_QUIETLY YES)
set(ZLIB_FIND_QUIETLY YES)
set(Protobuf_FIND_QUIETLY YES)
set(BZip2_FIND_QUIETLY YES)
set(SQLiteCpp_FIND_QUIETLY YES)
set(GTest_FIND_QUIETLY YES)
set(nlohmann_json_FIND_QUIETLY YES)
set(libdeflate_FIND_QUIETLY YES)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
os=Linux
arch=x86_64
compiler=clang
compiler.version=16
compiler.version=18
compiler.libcxx=libc++
compiler.cppstd=17
build_type=Debug
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
os=Linux
arch=x86_64
compiler=clang
compiler.version=16
compiler.version=18
compiler.libcxx=libc++
compiler.cppstd=17
build_type=Release
2 changes: 1 addition & 1 deletion docs/fuzzer.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ To build the fuzzer use the following:
```bash
mkdir build
cd build
cmake ../project -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONAN_PROFILE=linux_x64_clang_16_release -DCMAKE_TOOLCHAIN_FILE=../project/cmake/toolchain/clang_libcxx.cmake -DSILKWORM_FUZZER=ON
cmake ../project -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONAN_PROFILE=linux_x64_clang_18_release -DCMAKE_TOOLCHAIN_FILE=../project/cmake/toolchain/clang_libcxx.cmake -DSILKWORM_FUZZER=ON
cmake --build --target rpcdaemon_fuzzer_test
cmake –-build --target rpcdaemon_fuzzer_diagnostics
```
Expand Down
17 changes: 14 additions & 3 deletions silkworm/db/datastore/kvdb/mdbx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ namespace detail {
}

std::string slice_as_hex(const Slice& data) {
return ::mdbx::to_hex(data).as_string();
return std::string(::mdbx::to_hex(data).as_string());
}

std::string slice_as_string(const Slice& data) {
return std::string(data.as_string());
}

silkworm::Bytes slice_as_bytes(const Slice& data) {
return silkworm::Bytes{reinterpret_cast<const unsigned char*>(data.data()), data.size()};
}

log::Args log_args_for_commit_latency(const MDBX_commit_latency& commit_latency) {
Expand Down Expand Up @@ -106,7 +114,7 @@ ::mdbx::env_managed open_env(const EnvConfig& config) {
throw std::runtime_error("Database map size is too small. Min required " + human_size(db_file_size));
}

uint32_t flags{MDBX_NOTLS | MDBX_NORDAHEAD | MDBX_COALESCE | MDBX_SYNC_DURABLE}; // Default flags
uint32_t flags{MDBX_NORDAHEAD | MDBX_SYNC_DURABLE}; // Default flags

if (config.read_ahead) {
flags &= ~MDBX_NORDAHEAD;
Expand All @@ -133,6 +141,9 @@ ::mdbx::env_managed open_env(const EnvConfig& config) {
if (config.shared) {
flags |= MDBX_ACCEDE;
}
if (config.no_sticky_threads) {
flags |= MDBX_NOSTICKYTHREADS;
}
if (config.write_map) {
flags |= MDBX_WRITEMAP;
}
Expand Down Expand Up @@ -574,7 +585,7 @@ std::vector<std::string> list_maps(::mdbx::txn& tx, bool throw_notfound) {
::mdbx::map_handle main_map{1};
auto main_cursor{tx.open_cursor(main_map)};
for (auto it{main_cursor.to_first(throw_notfound)}; it.done; it = main_cursor.to_next(throw_notfound)) {
map_names.push_back(it.key.as_string());
map_names.push_back(detail::slice_as_string(it.key));
}
return map_names;
}
Expand Down
3 changes: 3 additions & 0 deletions silkworm/db/datastore/kvdb/mdbx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ namespace detail {

std::string dump_mdbx_result(const CursorResult& result);
std::string slice_as_hex(const Slice& data);
std::string slice_as_string(const Slice& data);
silkworm::Bytes slice_as_bytes(const Slice& data);
} // namespace detail

class ROTxn;
Expand Down Expand Up @@ -367,6 +369,7 @@ struct EnvConfig {
bool in_memory{false}; // Whether this db is in memory
bool shared{false}; // Whether this process opens a db already opened by another process
bool read_ahead{false}; // Whether to enable mdbx read ahead
bool no_sticky_threads{false}; // Whether to allow moving db transactions between threads
bool write_map{false}; // Whether to enable mdbx write map
size_t page_size{os::page_size()}; // Mdbx page size
size_t max_size{3_Tebi}; // Mdbx max map size
Expand Down
40 changes: 28 additions & 12 deletions silkworm/db/datastore/kvdb/memory_mutation_cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,14 @@ CursorResult MemoryMutationCursor::to_current_next_multi() {
}

CursorResult MemoryMutationCursor::to_current_next_multi(bool throw_notfound) {
if (config_.value_mode == ::mdbx::value_mode::single) {
if (throw_notfound) {
throw_error_notfound();
} else {
return CursorResult{{}, {}, false};
}
}

if (is_table_cleared()) {
return memory_cursor_->to_current_next_multi(throw_notfound);
}
Expand Down Expand Up @@ -598,7 +606,7 @@ CursorResult MemoryMutationCursor::find_multivalue(const Slice& key, const Slice
const auto memory_result = memory_cursor_->find_multivalue(key, value, false);

auto db_result = cursor_->find_multivalue(key, value, false);
if (db_result.key && is_entry_deleted(db_result.key, db_result.value)) {
if (db_result.done && is_entry_deleted(db_result.key, db_result.value)) {
db_result = next_on_db(MoveType::kNextDup, throw_notfound);
}

Expand Down Expand Up @@ -702,7 +710,7 @@ CursorResult MemoryMutationCursor::next_on_db(MemoryMutationCursor::MoveType typ
CursorResult result = next_by_type(type, throw_notfound);
if (!result.done) return result;

while (result.key && result.value && is_entry_deleted(result.key, result.value)) {
while (result.done && result.value && is_entry_deleted(result.key, result.value)) {
result = next_by_type(type, throw_notfound);
if (!result.done) return result;
}
Expand All @@ -711,19 +719,27 @@ CursorResult MemoryMutationCursor::next_on_db(MemoryMutationCursor::MoveType typ
}

CursorResult MemoryMutationCursor::next_by_type(MemoryMutationCursor::MoveType type, bool throw_notfound) {
switch (type) {
case MoveType::kNext: {
return cursor_->to_next(throw_notfound);
}
case MoveType::kNextDup: {
return cursor_->to_current_next_multi(throw_notfound);
}
case MoveType::kNextNoDup: {
return cursor_->to_next_first_multi(throw_notfound);
try {
switch (type) {
case MoveType::kNext: {
return cursor_->to_next(throw_notfound);
}
case MoveType::kNextDup: {
return cursor_->to_current_next_multi(throw_notfound);
}
case MoveType::kNextNoDup: {
return cursor_->to_next_first_multi(throw_notfound);
}
default: { // Avoid GCC complaining w/ error: control reaches end of non-void function
return CursorResult{{}, {}, false};
}
}
default: { // Avoid GCC complaining w/ error: control reaches end of non-void function
} catch (const mdbx::no_data& ex) {
// special case when cursor moves beyond existing data and is not handled by MDBX_NOTFOUND
if (!throw_notfound) {
return CursorResult{{}, {}, false};
}
throw ex;
}
}

Expand Down
21 changes: 11 additions & 10 deletions silkworm/db/kv/api/local_cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace silkworm::db::kv::api {

using namespace silkworm::datastore::kvdb;
using datastore::kvdb::detail::slice_as_bytes;
using datastore::kvdb::detail::slice_as_hex;

Task<void> LocalCursor::open_cursor(std::string_view table_name, bool is_dup_sorted) {
Expand All @@ -33,7 +34,7 @@ Task<KeyValue> LocalCursor::seek(ByteView key) {

if (result) {
SILK_DEBUG << "LocalCursor::seek found: key: " << key << " value: " << slice_as_hex(result.value);
co_return KeyValue{string_to_bytes(result.key.as_string()), string_to_bytes(result.value.as_string())};
co_return KeyValue{slice_as_bytes(result.key), slice_as_bytes(result.value)};
} else {
SILK_DEBUG << "LocalCursor::seek not found key: " << key;
co_return KeyValue{};
Expand All @@ -49,7 +50,7 @@ Task<KeyValue> LocalCursor::seek_exact(ByteView key) {
SILK_DEBUG << "LocalCursor::seek_exact result: " << detail::dump_mdbx_result(result);
if (result) {
SILK_DEBUG << "LocalCursor::seek_exact found: key: " << key << " value: " << slice_as_hex(result.value);
co_return KeyValue{string_to_bytes(result.key.as_string()), string_to_bytes(result.value.as_string())};
co_return KeyValue{slice_as_bytes(result.key), slice_as_bytes(result.value)};
}
SILK_ERROR << "LocalCursor::seek_exact !result key: " << key; // TODO(canepat) handle properly?
}
Expand All @@ -66,7 +67,7 @@ Task<KeyValue> LocalCursor::first() {
}

SILK_DEBUG << "LocalCursor::first: key: " << slice_as_hex(result.key) << " value: " << slice_as_hex(result.value);
co_return KeyValue{string_to_bytes(result.key.as_string()), string_to_bytes(result.value.as_string())};
co_return KeyValue{slice_as_bytes(result.key), slice_as_bytes(result.value)};
}

Task<KeyValue> LocalCursor::last() {
Expand All @@ -79,7 +80,7 @@ Task<KeyValue> LocalCursor::last() {
}

SILK_DEBUG << "LocalCursor::last: key: " << slice_as_hex(result.key) << " value: " << slice_as_hex(result.value);
co_return KeyValue{string_to_bytes(result.key.as_string()), string_to_bytes(result.value.as_string())};
co_return KeyValue{slice_as_bytes(result.key), slice_as_bytes(result.value)};
}

Task<KeyValue> LocalCursor::next() {
Expand All @@ -91,7 +92,7 @@ Task<KeyValue> LocalCursor::next() {
if (result) {
SILK_DEBUG << "LocalCursor::next: "
<< " key: " << string_view_to_byte_view(result.key.as_string()) << " value: " << string_view_to_byte_view(result.value.as_string());
co_return KeyValue{string_to_bytes(result.key.as_string()), string_to_bytes(result.value.as_string())};
co_return KeyValue{slice_as_bytes(result.key), slice_as_bytes(result.value)};
} else {
SILK_ERROR << "LocalCursor::next !result"; // TODO(canepat) handle properly?
}
Expand All @@ -107,7 +108,7 @@ Task<KeyValue> LocalCursor::previous() {
if (result) {
SILK_DEBUG << "LocalCursor::previous: "
<< " key: " << string_view_to_byte_view(result.key.as_string()) << " value: " << string_view_to_byte_view(result.value.as_string());
co_return KeyValue{string_to_bytes(result.key.as_string()), string_to_bytes(result.value.as_string())};
co_return KeyValue{slice_as_bytes(result.key), slice_as_bytes(result.value)};
} else {
SILK_ERROR << "LocalCursor::previous !result"; // TODO(canepat) handle properly?
}
Expand All @@ -123,7 +124,7 @@ Task<KeyValue> LocalCursor::next_dup() {
if (result) {
SILK_DEBUG << "LocalCursor::next_dup: "
<< " key: " << string_view_to_byte_view(result.key.as_string()) << " value: " << string_view_to_byte_view(result.value.as_string());
co_return KeyValue{string_to_bytes(result.key.as_string()), string_to_bytes(result.value.as_string())};
co_return KeyValue{slice_as_bytes(result.key), slice_as_bytes(result.value)};
} else {
SILK_ERROR << "LocalCursor::next_dup !result"; // TODO(canepat) handle properly?
}
Expand All @@ -138,9 +139,9 @@ Task<Bytes> LocalCursor::seek_both(ByteView key, ByteView value) {

if (result) {
SILK_DEBUG << "LocalCursor::seek_both key: " << string_view_to_byte_view(result.key.as_string()) << " value: " << string_view_to_byte_view(result.value.as_string());
co_return string_to_bytes(result.value.as_string());
co_return slice_as_bytes(result.value);
}
co_return string_to_bytes("");
co_return Bytes{};
}

Task<KeyValue> LocalCursor::seek_both_exact(ByteView key, ByteView value) {
Expand All @@ -152,7 +153,7 @@ Task<KeyValue> LocalCursor::seek_both_exact(ByteView key, ByteView value) {
if (result) {
SILK_DEBUG << "LocalCursor::seek_both_exact: "
<< " key: " << string_view_to_byte_view(result.key.as_string()) << " value: " << string_view_to_byte_view(result.value.as_string());
co_return KeyValue{string_to_bytes(result.key.as_string()), string_to_bytes(result.value.as_string())};
co_return KeyValue{slice_as_bytes(result.key), slice_as_bytes(result.value)};
} else {
SILK_ERROR << "LocalCursor::seek_both_exact !found key: " << key << " subkey:" << value;
}
Expand Down
3 changes: 2 additions & 1 deletion silkworm/db/kv/grpc/server/kv_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ using boost::asio::as_tuple;
using namespace boost::asio::experimental::awaitable_operators;
using boost::asio::steady_timer;
using boost::asio::use_awaitable;
using datastore::kvdb::detail::slice_as_string;

api::Version higher_version_ignoring_patch(api::Version lhs, api::Version rhs) {
uint32_t lhs_major = std::get<0>(lhs);
Expand Down Expand Up @@ -350,7 +351,7 @@ bool TxCall::save_cursors(std::vector<CursorPosition>& positions) {
}
mdbx::slice key = result.key;
mdbx::slice value = result.value;
positions.emplace_back(CursorPosition{key.as_string(), value.as_string()});
positions.emplace_back(CursorPosition{slice_as_string(key), slice_as_string(value)});
}
}

Expand Down
Loading
Loading