Skip to content

Commit

Permalink
git: Merge branch 'master' into feature/elliptic_curve_functions
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
  • Loading branch information
xDimon committed Jan 30, 2024
2 parents 5bca65d + bfdc75d commit 360f9ea
Show file tree
Hide file tree
Showing 146 changed files with 1,213 additions and 792 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:
env:
BUILD_DIR: build
CI: true
KAGOME_IN_DOCKER: 1
CTEST_OUTPUT_ON_FAILURE: 1
GITHUB_HUNTER_USERNAME: ${{ secrets.HUNTER_USERNAME }}
GITHUB_HUNTER_TOKEN: ${{ secrets.HUNTER_TOKEN }}
Expand Down Expand Up @@ -47,7 +48,7 @@ jobs:
run: ./housekeeping/make_build.sh -DCLEAR_OBJS=ON -DCOVERAGE=OFF -DWASM_COMPILER=WasmEdge -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/cxx20.cmake
env:
CI:

KAGOME_IN_DOCKER: 0
Linux:
if: ${{ !(github.ref == 'refs/heads/master' || startsWith( github.ref, 'refs/tags/' )) }}
strategy:
Expand All @@ -59,7 +60,7 @@ jobs:

name: "${{ matrix.options.name }}"
runs-on: ubuntu-latest
container: qdrvm/kagome-dev@sha256:14d5aa92c971073e82ba9bbac9b615701e99c71f64e58bdd45e5b3dbc09944bd
container: qdrvm/kagome-dev@sha256:2d70246c32418a3dd45c246d3f5c2dd99bdafde145b903271849affe476c4cfc
steps:
- uses: actions/checkout@dc323e67f16fb5f7663d20ff7941f27f5809e9b6
- uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed
Expand Down Expand Up @@ -97,7 +98,7 @@ jobs:

name: "${{ matrix.options.name }}"
runs-on: [ self-hosted ]
container: qdrvm/kagome-dev@sha256:14d5aa92c971073e82ba9bbac9b615701e99c71f64e58bdd45e5b3dbc09944bd
container: qdrvm/kagome-dev@sha256:2d70246c32418a3dd45c246d3f5c2dd99bdafde145b903271849affe476c4cfc
steps:
- uses: actions/checkout@dc323e67f16fb5f7663d20ff7941f27f5809e9b6
- uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed
Expand Down Expand Up @@ -135,7 +136,7 @@ jobs:

name: "${{ matrix.options.name }}"
runs-on: [ self-hosted ]
container: qdrvm/kagome-dev@sha256:14d5aa92c971073e82ba9bbac9b615701e99c71f64e58bdd45e5b3dbc09944bd
container: qdrvm/kagome-dev@sha256:2d70246c32418a3dd45c246d3f5c2dd99bdafde145b903271849affe476c4cfc
steps:
- uses: actions/checkout@dc323e67f16fb5f7663d20ff7941f27f5809e9b6
- uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed
Expand All @@ -159,7 +160,7 @@ jobs:
clang-tidy:
name: "Linux: clang-tidy"
runs-on: ubuntu-latest
container: qdrvm/kagome-dev@sha256:14d5aa92c971073e82ba9bbac9b615701e99c71f64e58bdd45e5b3dbc09944bd
container: qdrvm/kagome-dev@sha256:2d70246c32418a3dd45c246d3f5c2dd99bdafde145b903271849affe476c4cfc
steps:
- uses: actions/checkout@dc323e67f16fb5f7663d20ff7941f27f5809e9b6
with:
Expand All @@ -180,7 +181,7 @@ jobs:
if: ${{ github.ref == 'refs/heads/master' || startsWith( github.ref, 'refs/tags/') || contains( github.event.pull_request.labels.*.name, 'Non-master self-hosted') }}
name: "Self-hosted: Linux: gcc-12 coverage/sonar"
runs-on: [ self-hosted ]
container: qdrvm/kagome-dev@sha256:14d5aa92c971073e82ba9bbac9b615701e99c71f64e58bdd45e5b3dbc09944bd
container: qdrvm/kagome-dev@sha256:2d70246c32418a3dd45c246d3f5c2dd99bdafde145b903271849affe476c4cfc
steps:
- uses: actions/checkout@dc323e67f16fb5f7663d20ff7941f27f5809e9b6
- uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed
Expand Down Expand Up @@ -228,7 +229,7 @@ jobs:
build-type: "Release"
name: "${{ matrix.options.name }}"
runs-on: ubuntu-latest
container: qdrvm/kagome-dev@sha256:14d5aa92c971073e82ba9bbac9b615701e99c71f64e58bdd45e5b3dbc09944bd
container: qdrvm/kagome-dev@sha256:2d70246c32418a3dd45c246d3f5c2dd99bdafde145b903271849affe476c4cfc
steps:
- uses: actions/checkout@dc323e67f16fb5f7663d20ff7941f27f5809e9b6
- uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed
Expand All @@ -252,7 +253,7 @@ jobs:
build-type: "Release"
name: "${{ matrix.options.name }}"
runs-on: [ self-hosted ]
container: qdrvm/kagome-dev@sha256:14d5aa92c971073e82ba9bbac9b615701e99c71f64e58bdd45e5b3dbc09944bd
container: qdrvm/kagome-dev@sha256:2d70246c32418a3dd45c246d3f5c2dd99bdafde145b903271849affe476c4cfc
steps:
- uses: actions/checkout@dc323e67f16fb5f7663d20ff7941f27f5809e9b6
- uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed
Expand Down
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ set(CMAKE_TOOLCHAIN_FILE
"${CMAKE_SOURCE_DIR}/cmake/toolchain/cxx20.cmake"
CACHE FILEPATH "Default toolchain")

if (NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()

set(HUNTER_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE})

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

add_compile_options(-gdwarf-4)
Expand Down Expand Up @@ -63,7 +69,7 @@ if(NOT($ENV{CI}) OR NOT($ENV{GITHUB_ACTIONS}))
endif()
option(EXTERNAL_PROJECT "Build external project" ${_EXTERNAL_PROJECT_DEFAULT})

set(WASM_COMPILER WAVM CACHE STRING "WebAssembly compiler built into Kagome: one of [WAVM, WasmEdge]")
set(WASM_COMPILER WasmEdge CACHE STRING "WebAssembly compiler built into Kagome: one of [WAVM, WasmEdge]")

if (NOT ${WASM_COMPILER} MATCHES "^(WAVM|WasmEdge)$")
fatal_error("WASM_COMPILER is set to ${WASM_COMPILER} but should be one of [WAVM, WasmEdge]")
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ debug_docker:
VERSION=0.0.1 BUILD_DIR=build BUILD_TYPE=Debug ./housekeeping/docker/kagome/build_and_push.sh

custom_docker:
VERSION=0.0.1 BUILD_TYPE=Custom BUILD_DIR=build ./housekeeping/docker/kagome/build_and_push.sh
VERSION=0.0.1 BUILD_TYPE=Custom ./housekeeping/docker/kagome/build_and_push.sh

clear:
rm -rf build

3 changes: 2 additions & 1 deletion cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ if ("${WASM_COMPILER}" STREQUAL "WasmEdge")

hunter_config(
WasmEdge
VERSION 0.13.3
URL https://github.com/Harrm/WasmEdge/archive/f9ef1de1679dd86c62c998a28fc8875e32c187f6.zip
SHA1 2bd770546623afb6083e67a3e6bad819f36dfd72
CMAKE_ARGS
WASMEDGE_BUILD_STATIC_LIB=ON
WASMEDGE_BUILD_SHARED_LIB=OFF
Expand Down
7 changes: 6 additions & 1 deletion cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ find_package(zstd CONFIG REQUIRED)

if ("${WASM_COMPILER}" STREQUAL "WasmEdge")
hunter_add_package(WasmEdge)
find_library(WASM_EDGE_LIBRARY NAMES libwasmedge.a REQUIRED PATHS "${WASMEDGE_ROOT}")
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
find_library(WASM_EDGE_LIBRARY NAMES libwasmedged.a REQUIRED PATHS "${WASMEDGE_ROOT}")
else()
find_library(WASM_EDGE_LIBRARY NAMES libwasmedge.a REQUIRED PATHS "${WASMEDGE_ROOT}")
endif()

add_library(WasmEdge::WasmEdge STATIC IMPORTED)
set_property(TARGET WasmEdge::WasmEdge PROPERTY IMPORTED_LOCATION "${WASM_EDGE_LIBRARY}")
target_link_libraries(WasmEdge::WasmEdge INTERFACE curses zstd::libzstd_static)
Expand Down
2 changes: 1 addition & 1 deletion cmake/install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function(kagome_install_setup)
get_filename_component(install_prefix ${relative_path} DIRECTORY)
install(DIRECTORY ${dir}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${install_prefix}
FILES_MATCHING PATTERN "*.hpp")
FILES_MATCHING PATTERN "*.hpp|*.h")
endforeach ()

install(
Expand Down
4 changes: 2 additions & 2 deletions core/api/service/child_state/impl/child_state_api_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "common/hexutil.hpp"
#include "common/monadic_utils.hpp"
#include "crypto/blake2/blake2b.h"
#include "storage/trie/serialization/polkadot_codec.hpp"

namespace kagome::api {
Expand Down Expand Up @@ -141,8 +142,7 @@ namespace kagome::api {
const std::optional<primitives::BlockHash> &block_hash_opt) const {
OUTCOME_TRY(value_opt, getStorage(child_storage_key, key, block_hash_opt));
if (value_opt.has_value()) {
storage::trie::PolkadotCodec codec;
auto hash = codec.hash256(value_opt.value());
common::Hash256 hash = crypto::blake2b<32>(value_opt.value());
return hash;
}
return std::nullopt;
Expand Down
2 changes: 1 addition & 1 deletion core/api/service/impl/api_service_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ namespace kagome::api {
bool ApiServiceImpl::prepare() {
for (const auto &listener : listeners_) {
auto on_new_session =
[wp = weak_from_this()](const sptr<Session> &session) mutable {
[wp{weak_from_this()}](const sptr<Session> &session) mutable {
auto self = wp.lock();
if (!self) {
return;
Expand Down
6 changes: 3 additions & 3 deletions core/api/transport/impl/ws/ws_listener_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ namespace kagome::api {
}

void WsListenerImpl::acceptOnce() {
auto get_id = [weak = weak_from_this()]() -> Session::SessionId {
auto get_id = [weak{weak_from_this()}]() -> Session::SessionId {
if (auto self = weak.lock()) {
return self->next_session_id_++;
}
return 0;
};
new_session_ = std::make_shared<SessionImpl>(
*context_, get_id, on_new_session_, allow_unsafe_, session_config_);
auto session_stopped_handler = [wp = weak_from_this()] {
auto session_stopped_handler = [wp{weak_from_this()}] {
if (auto self = wp.lock()) {
self->closed_session_->inc();
--self->active_connections_;
Expand All @@ -112,7 +112,7 @@ namespace kagome::api {
}
};

auto on_accept = [wp = weak_from_this(),
auto on_accept = [wp{weak_from_this()},
session_stopped_handler](boost::system::error_code ec) {
if (auto self = wp.lock()) {
if (not ec) {
Expand Down
1 change: 1 addition & 0 deletions core/application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ target_link_libraries(app_config
assets
chain_spec
build_version
wasm_compiler
)
kagome_install(app_config)

Expand Down
7 changes: 7 additions & 0 deletions core/application/app_configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ namespace kagome::application {
*/
virtual RuntimeExecutionMethod runtimeExecMethod() const = 0;

enum class RuntimeInterpreter {
WasmEdge,
Binaryen,
};

virtual RuntimeInterpreter runtimeInterpreter() const = 0;

/**
* A flag marking if we use and store precompiled WAVM runtimes.
* Significantly increases node restart speed. Especially useful when
Expand Down
10 changes: 5 additions & 5 deletions core/application/app_state_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ namespace kagome::application {
// bool, we want it to be a compile error instead of silently ignoring it
// because the concept is not satisfied.
template <typename T>
concept AppStateInjectable = requires(T& t) { t.inject(); };
concept AppStateInjectable = requires(T &t) { t.inject(); };
template <typename T>
concept AppStatePreparable = requires(T& t) { t.prepare(); };
concept AppStatePreparable = requires(T &t) { t.prepare(); };
template <typename T>
concept AppStateStartable = requires(T& t) { t.start(); };
concept AppStateStartable = requires(T &t) { t.start(); };
template <typename T>
concept AppStateStoppable = requires(T& t) { t.stop(); };
concept AppStateStoppable = requires(T &t) { t.stop(); };

// if an object is registered with AppStateManager but has no method
// that is called by AppStateManager, there's probably something wrong
template <typename T>
concept AppStateControllable = AppStatePreparable<T> || AppStateInjectable<T>
|| AppStateStoppable<T> || AppStateStartable<T>;

class AppStateManager : public std::enable_shared_from_this<AppStateManager> {
class AppStateManager {
public:
using OnInject = std::function<bool()>;
using OnPrepare = std::function<bool()>;
Expand Down
71 changes: 66 additions & 5 deletions core/application/impl/app_configuration_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ namespace {
const auto def_sync_method = kagome::application::SyncMethod::Full;
const auto def_runtime_exec_method =
kagome::application::AppConfiguration::RuntimeExecutionMethod::Interpret;
const auto def_runtime_interpreter =
kagome::application::AppConfiguration::RuntimeInterpreter::WasmEdge;
const auto def_use_wavm_cache_ = false;
const auto def_purge_wavm_cache_ = false;
const auto def_offchain_worker_mode =
Expand All @@ -101,6 +103,11 @@ namespace {
const uint32_t def_random_walk_interval = 15;
const auto def_full_sync = "Full";
const auto def_wasm_execution = "Interpreted";
#if KAGOME_WASM_COMPILER_WASM_EDGE == 1
const auto def_wasm_interpreter = "WasmEdge";
#else
const auto def_wasm_interpreter = "Binaryen";
#endif
const uint32_t def_db_cache_size = 1024;
const uint32_t def_parachain_runtime_instance_cache_size = 100;

Expand Down Expand Up @@ -161,6 +168,17 @@ namespace {
std::string execution_methods_str =
fmt::format("[{}]", fmt::join(execution_methods, ", "));

std::array<std::string_view, 1 + KAGOME_WASM_COMPILER_WASM_EDGE>
interpreters {
#if KAGOME_WASM_COMPILER_WASM_EDGE == 1
"WasmEdge",
#endif
"Binaryen"
};

std::string interpreters_str =
fmt::format("[{}]", fmt::join(interpreters, ", "));

std::optional<kagome::application::AppConfiguration::RuntimeExecutionMethod>
str_to_runtime_exec_method(std::string_view str) {
using REM = kagome::application::AppConfiguration::RuntimeExecutionMethod;
Expand All @@ -173,6 +191,18 @@ namespace {
return std::nullopt;
}

std::optional<kagome::application::AppConfiguration::RuntimeInterpreter>
str_to_runtime_interpreter(std::string_view str) {
using RI = kagome::application::AppConfiguration::RuntimeInterpreter;
if (str == "WasmEdge") {
return RI::WasmEdge;
}
if (str == "Binaryen") {
return RI::Binaryen;
}
return std::nullopt;
}

std::optional<kagome::application::AppConfiguration::OffchainWorkerMode>
str_to_offchain_worker_mode(std::string_view str) {
using Mode = kagome::application::AppConfiguration::OffchainWorkerMode;
Expand Down Expand Up @@ -228,8 +258,9 @@ namespace {

namespace kagome::application {

AppConfigurationImpl::AppConfigurationImpl(log::Logger logger)
: logger_(std::move(logger)),
AppConfigurationImpl::AppConfigurationImpl()
: logger_(kagome::log::createLogger("Configuration",
kagome::log::defaultGroupName)),
roles_(def_roles),
save_node_key_(false),
is_telemetry_enabled_(true),
Expand All @@ -251,15 +282,14 @@ namespace kagome::application {
random_walk_interval_(def_random_walk_interval),
sync_method_{def_sync_method},
runtime_exec_method_{def_runtime_exec_method},
runtime_interpreter_{def_runtime_interpreter},
use_wavm_cache_(def_use_wavm_cache_),
purge_wavm_cache_(def_purge_wavm_cache_),
offchain_worker_mode_{def_offchain_worker_mode},
enable_offchain_indexing_{def_enable_offchain_indexing},
recovery_state_{def_block_to_recover},
db_cache_size_{def_db_cache_size},
state_pruning_depth_{} {
SL_INFO(logger_, "Kagome started. Version: {} ", buildVersion());
}
state_pruning_depth_{} {}

fs::path AppConfigurationImpl::chainSpecPath() const {
return chain_spec_path_.native();
Expand Down Expand Up @@ -845,6 +875,8 @@ namespace kagome::application {
"choose the desired sync method (Full, Fast). Full is used by default.")
("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),
fmt::format("choose the desired wasm interpreter ({})", interpreters_str).c_str())
("unsafe-cached-wavm-runtime", "use WAVM runtime cache")
("purge-wavm-cache", "purge WAVM runtime cache")
("parachain-runtime-instance-cache-size",
Expand Down Expand Up @@ -1389,6 +1421,35 @@ namespace kagome::application {
return false;
}

// default interpreter
if (runtime_exec_method_ == RuntimeExecutionMethod::Interpret) {
#if KAGOME_WASM_COMPILER_WASM_EDGE == 1
runtime_interpreter_ = RuntimeInterpreter::WasmEdge;
#else
runtime_interpreter_ = RuntimeInterpreter::Binaryen;
#endif
}

if (auto val = find_argument<std::string>(vm, "wasm-interpreter");
val.has_value()) {
if (runtime_exec_method_ == RuntimeExecutionMethod::Compile) {
SL_ERROR(
logger_,
"--wasm-interpreter defined, but the execution mode is Compile");
return false;
}
if (auto interpreter = str_to_runtime_interpreter(*val);
interpreter.has_value()) {
runtime_interpreter_ = *interpreter;
} else {
SL_ERROR(logger_,
"Invalid wasm interpreter '{}', available options are: {}",
*val,
interpreters_str);
return false;
}
}

if (vm.count("unsafe-cached-wavm-runtime") > 0) {
use_wavm_cache_ = true;
}
Expand Down
Loading

0 comments on commit 360f9ea

Please sign in to comment.