Skip to content
Draft
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ set(WASMEDGE_ID 3fbf6c6a39a5fd065e8964a979d5edcddf877cca)

include("cmake/Hunter/init.cmake")

add_compile_options(-gdwarf-4)
if (${CMAKE_BUILD_TYPE} MATCHES "^(Debug|RelWithDebInfo)$")
add_compile_options(-gdwarf-4 -fno-omit-frame-pointer)
endif()

project(kagome
VERSION 0.9.3
LANGUAGES C CXX
Expand Down
34 changes: 34 additions & 0 deletions cmake/toolchain/compiler/gcc-14.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
if(DEFINED POLLY_COMPILER_GCC_13_CMAKE_)
return()
else()
set(POLLY_COMPILER_GCC_13_CMAKE_ 1)
endif()

find_program(CMAKE_C_COMPILER gcc-14)
find_program(CMAKE_CXX_COMPILER g++-14)

if(NOT CMAKE_C_COMPILER)
message(FATAL_ERROR "gcc-14 not found")
endif()

if(NOT CMAKE_CXX_COMPILER)
message(FATAL_ERROR "g++-14 not found")
endif()

set(
CMAKE_C_COMPILER
"${CMAKE_C_COMPILER}"
CACHE
STRING
"C compiler"
FORCE
)

set(
CMAKE_CXX_COMPILER
"${CMAKE_CXX_COMPILER}"
CACHE
STRING
"C++ compiler"
FORCE
)
2 changes: 2 additions & 0 deletions cmake/toolchain/gcc-14_cxx20.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include(${CMAKE_CURRENT_LIST_DIR}/compiler/gcc-14.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cxx20.cmake)
3 changes: 3 additions & 0 deletions cmake/toolchain/gcc-14_mold_cxx20.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include(${CMAKE_CURRENT_LIST_DIR}/compiler/gcc-14.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cxx20.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/linker/mold.cmake)
10 changes: 9 additions & 1 deletion core/api/jrpc/value_converter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ namespace kagome::api {
inline jsonrpc::Value makeValue(const uint64_t &);
inline jsonrpc::Value makeValue(const std::nullptr_t &);
inline jsonrpc::Value makeValue(const std::nullopt_t &);
inline jsonrpc::Value makeValue(const std::nullopt_t &);

template <typename T>
inline jsonrpc::Value makeValue(const std::reference_wrapper<T> &v);
Expand All @@ -49,6 +48,9 @@ namespace kagome::api {
template <typename... Ts>
inline jsonrpc::Value makeValue(const boost::variant<Ts...> &v);

template <typename... Ts>
inline jsonrpc::Value makeValue(const std::variant<Ts...> &v);

template <typename T1, typename T2>
inline jsonrpc::Value makeValue(const std::pair<T1, T2> &val);

Expand Down Expand Up @@ -138,6 +140,12 @@ namespace kagome::api {
[](const auto &value) { return makeValue(value); });
}

template <typename... Ts>
inline jsonrpc::Value makeValue(const std::variant<Ts...> &v) {
return visit_in_place(v,
[](const auto &value) { return makeValue(value); });
}

template <typename T1, typename T2>
inline jsonrpc::Value makeValue(const std::pair<T1, T2> &val) {
jArray data;
Expand Down
48 changes: 31 additions & 17 deletions core/api/service/impl/api_service_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,27 +576,41 @@ namespace kagome::api {
SessionPtr &session,
primitives::events::ChainEventType event_type,
const primitives::events::ChainEventParams &event_params) {
std::string_view name;
switch (event_type) {
case primitives::events::ChainEventType::kNewHeads: {
name = kRpcEventNewHeads;
} break;
case primitives::events::ChainEventType::kFinalizedHeads: {
name = kRpcEventFinalizedHeads;
} break;
case primitives::events::ChainEventType::kFinalizedRuntimeVersion: {
name = kRpcEventRuntimeVersion;
} break;
case primitives::events::ChainEventType::kNewRuntime:
return;
case primitives::events::ChainEventType::kNewHeads:
sendEvent(server_,
session,
logger_,
set_id,
kRpcEventNewHeads,
api::makeValue(std::get<primitives::events::HeadsEventParams>(
event_params)));
break;
case primitives::events::ChainEventType::kFinalizedHeads:
sendEvent(server_,
session,
logger_,
set_id,
kRpcEventFinalizedHeads,
api::makeValue(std::get<primitives::events::HeadsEventParams>(
event_params)));
break;
case primitives::events::ChainEventType::kFinalizedRuntimeVersion:
sendEvent(server_,
session,
logger_,
set_id,
kRpcEventRuntimeVersion,
api::makeValue(
std::get<primitives::events::RuntimeVersionEventParams>(
event_params)));
break;
default:
BOOST_ASSERT(!"Unknown chain event");
SL_WARN(logger_,
"Received unexpected chain event {}",
static_cast<int>(event_type));
return;
}

BOOST_ASSERT(!name.empty());
sendEvent(
server_, session, logger_, set_id, name, api::makeValue(event_params));
}

void ApiServiceImpl::onExtrinsicEvent(
Expand Down
49 changes: 30 additions & 19 deletions core/application/impl/app_configuration_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <limits>
#include <regex>
#include <string>
#include <string_view>

#include <fmt/ranges.h>
#include <fmt/std.h>
Expand Down Expand Up @@ -133,30 +134,40 @@ namespace kagome::application {
return name;
}

using namespace std::literals;

static constexpr std::
array<std::pair<std::string_view, application::SyncMethod>, 6>
kSyncMethods{
std::pair{"Full"sv, application::SyncMethod::Full},
{"Fast"sv, application::SyncMethod::Fast},
{"FastWithoutState"sv,
application::SyncMethod::FastWithoutState},
{"Warp"sv, application::SyncMethod::Warp},
{"Unsafe"sv, application::SyncMethod::Unsafe},
{"Auto"sv, application::SyncMethod::Auto},
};

std::optional<application::SyncMethod> str_to_sync_method(
std::string_view str) {
using SM = application::SyncMethod;
if (str == "Full") {
return SM::Full;
}
if (str == "Fast") {
return SM::Fast;
}
if (str == "FastWithoutState") {
return SM::FastWithoutState;
}
if (str == "Warp") {
return SM::Warp;
}
if (str == "Unsafe") {
return SM::Unsafe;
}
if (str == "Auto") {
return SM::Auto;
for (auto &[method_name, method] : kSyncMethods) {
if (str == method_name) {
return method;
}
}
return std::nullopt;
}

std::array<std::string_view, kSyncMethods.size()> get_sync_methods() {
std::array<std::string_view, kSyncMethods.size()> sync_methods;
auto it = sync_methods.begin();
for (auto &[name, _] : kSyncMethods) {
*it = name;
++it;
}
return sync_methods;
}

std::optional<AppConfiguration::AllowUnsafeRpc> parseAllowUnsafeRpc(
std::string_view str) {
if (str == "unsafe") {
Expand Down Expand Up @@ -868,7 +879,7 @@ namespace kagome::application {
("dev", "if node run in development mode")
("dev-with-wipe", "if needed to wipe base path (only for dev mode)")
("sync", po::value<std::string>()->default_value(def_full_sync),
"choose the desired sync method (Full, Fast). Full is used by default.")
fmt::format("choose the desired sync method ({}). Full is used by default.", get_sync_methods()).c_str())
("wasm-execution", po::value<std::string>()->default_value(def_wasm_execution),
fmt::format("choose the desired wasm execution method ({})", execution_methods_str).c_str())
("wasm-interpreter", po::value<std::string>()->default_value(def_wasm_interpreter),
Expand Down
27 changes: 17 additions & 10 deletions core/blockchain/impl/block_tree_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ namespace kagome::blockchain {
extrinsic_event_key_repo,
std::shared_ptr<const class JustificationStoragePolicy>
justification_storage_policy,
std::shared_ptr<storage::trie::TrieStorage> trie_storage,
std::shared_ptr<storage::trie_pruner::TriePruner> state_pruner,
common::MainThreadPool &main_thread_pool) {
BOOST_ASSERT(storage != nullptr);
Expand Down Expand Up @@ -269,6 +270,7 @@ namespace kagome::blockchain {
std::move(extrinsic_events_engine),
std::move(extrinsic_event_key_repo),
std::move(justification_storage_policy),
trie_storage,
state_pruner,
main_thread_pool));
// Add non-finalized block to the block tree
Expand Down Expand Up @@ -393,19 +395,21 @@ namespace kagome::blockchain {
extrinsic_event_key_repo,
std::shared_ptr<const JustificationStoragePolicy>
justification_storage_policy,
std::shared_ptr<storage::trie::TrieStorage> trie_storage,
std::shared_ptr<storage::trie_pruner::TriePruner> state_pruner,
common::MainThreadPool &main_thread_pool)
: block_tree_data_{BlockTreeData{
.storage_ = std::move(storage),
.state_pruner_ = std::move(state_pruner),
.tree_ = std::make_unique<CachedTree>(finalized),
.hasher_ = std::move(hasher),
.extrinsic_event_key_repo_ = std::move(extrinsic_event_key_repo),
.justification_storage_policy_ =
std::move(justification_storage_policy),
.genesis_block_hash_ = {},
.blocks_pruning_ = {app_config.blocksPruning(), finalized.number},
}},
.storage_ = std::move(storage),
.trie_storage_ = std::move(trie_storage),
.state_pruner_ = std::move(state_pruner),
.tree_ = std::make_unique<CachedTree>(finalized),
.hasher_ = std::move(hasher),
.extrinsic_event_key_repo_ = std::move(extrinsic_event_key_repo),
.justification_storage_policy_ =
std::move(justification_storage_policy),
.genesis_block_hash_ = {},
.blocks_pruning_ = {app_config.blocksPruning(), finalized.number},
}},
chain_events_engine_{std::move(chain_events_engine)},
main_pool_handler_{main_thread_pool.handlerStarted()},
extrinsic_events_engine_{std::move(extrinsic_events_engine)} {
Expand All @@ -415,6 +419,7 @@ namespace kagome::blockchain {
BOOST_ASSERT(p.hasher_ != nullptr);
BOOST_ASSERT(p.extrinsic_event_key_repo_ != nullptr);
BOOST_ASSERT(p.justification_storage_policy_ != nullptr);
BOOST_ASSERT(p.trie_storage_ != nullptr);
BOOST_ASSERT(p.state_pruner_ != nullptr);

// Register metrics
Expand Down Expand Up @@ -1311,6 +1316,8 @@ namespace kagome::blockchain {
}
extrinsics.emplace_back(std::move(ext));
}
notifyChainEventsEngine(
primitives::events::ChainEventType::kDiscardedHeads, block_header);
p.state_pruner_->schedulePrune(
block_header.state_root,
block_header.blockInfo(),
Expand Down
21 changes: 13 additions & 8 deletions core/blockchain/impl/block_tree_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace kagome::blockchain {
extrinsic_event_key_repo,
std::shared_ptr<const class JustificationStoragePolicy>
justification_storage_policy,
std::shared_ptr<storage::trie::TrieStorage> trie_storage,
std::shared_ptr<storage::trie_pruner::TriePruner> state_pruner,
common::MainThreadPool &main_thread_pool);

Expand Down Expand Up @@ -177,6 +178,7 @@ namespace kagome::blockchain {

struct BlockTreeData {
std::shared_ptr<BlockStorage> storage_;
std::shared_ptr<storage::trie::TrieStorage> trie_storage_;
std::shared_ptr<storage::trie_pruner::TriePruner> state_pruner_;
std::unique_ptr<CachedTree> tree_;
std::shared_ptr<crypto::Hasher> hasher_;
Expand Down Expand Up @@ -204,34 +206,37 @@ namespace kagome::blockchain {
extrinsic_event_key_repo,
std::shared_ptr<const class JustificationStoragePolicy>
justification_storage_policy,
std::shared_ptr<storage::trie::TrieStorage> trie_storage,
std::shared_ptr<storage::trie_pruner::TriePruner> state_pruner,
common::MainThreadPool &main_thread_pool);

outcome::result<void> reorgAndPrune(BlockTreeData &p,
outcome::result<void> reorgAndPrune(BlockTreeData &data,
const ReorgAndPrune &changes);

outcome::result<primitives::BlockHeader> getBlockHeaderNoLock(
const BlockTreeData &p, const primitives::BlockHash &block_hash) const;
const BlockTreeData &data,
const primitives::BlockHash &block_hash) const;

outcome::result<void> pruneTrie(const BlockTreeData &block_tree_data,
primitives::BlockNumber new_finalized);

primitives::BlockInfo getLastFinalizedNoLock(const BlockTreeData &p) const;
primitives::BlockInfo bestBlockNoLock(const BlockTreeData &p) const;
primitives::BlockInfo getLastFinalizedNoLock(
const BlockTreeData &data) const;
primitives::BlockInfo bestBlockNoLock(const BlockTreeData &data) const;

bool hasDirectChainNoLock(const BlockTreeData &p,
bool hasDirectChainNoLock(const BlockTreeData &data,
const primitives::BlockHash &ancestor,
const primitives::BlockHash &descendant) const;
std::vector<primitives::BlockHash> getLeavesNoLock(
const BlockTreeData &p) const;
const BlockTreeData &data) const;

BlockTree::BlockHashVecRes getDescendingChainToBlockNoLock(
const BlockTreeData &p,
const BlockTreeData &data,
const primitives::BlockHash &to_block,
uint64_t maximum) const;

outcome::result<void> addExistingBlockNoLock(
BlockTreeData &p,
BlockTreeData &data,
const primitives::BlockHash &block_hash,
const primitives::BlockHeader &block_header);

Expand Down
Loading
Loading