Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into fix/precheck
Browse files Browse the repository at this point in the history
  • Loading branch information
turuslan committed Dec 11, 2023
2 parents e25529d + 8c40662 commit 0a3fb9d
Show file tree
Hide file tree
Showing 276 changed files with 4,371 additions and 2,636 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: install
run: ./housekeeping/macos/dependency.sh
- name: build
run: ./housekeeping/make_build.sh -DCLEAR_OBJS=ON -DCOVERAGE=OFF -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/cxx20.cmake
run: ./housekeeping/make_build.sh -DCLEAR_OBJS=ON -DCOVERAGE=OFF -DWASM_COMPILER=WasmEdge -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/cxx20.cmake
env:
CI:

Expand Down
18 changes: 14 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ 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]")

if (NOT ${WASM_COMPILER} MATCHES "^(WAVM|WasmEdge)$")
fatal_error("WASM_COMPILER is set to ${WASM_COMPILER} but should be one of [WAVM, WasmEdge]")
endif()

# sanitizers will be enabled only for Kagome, and will be disabled for dependencies
option(ASAN "Enable address sanitizer" OFF)
option(LSAN "Enable leak sanitizer" OFF)
Expand All @@ -80,6 +86,8 @@ if("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(AppleClang|Clang|GNU)$")
# cmake-format: off

# enable those flags
add_flag(-fdiagnostics-show-template-tree)

add_flag(-Wall)
add_flag(-Wextra)
add_flag(-Woverloaded-virtual) # warn if you overload (not override) a virtual function
Expand Down Expand Up @@ -108,7 +116,8 @@ if("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(AppleClang|Clang|GNU)$")
add_flag(-Werror=unused-lambda-capture) # error if lambda capture is unused
add_flag(-Werror=return-type) # warning: control reaches end of non-void function [-Wreturn-type]
add_flag(-Werror=sign-compare) # warn the user if they compare a signed and unsigned numbers
add_flag(-Werror=reorder) # field '$1' will be initialized after field '$2'
# breaks soralog headers
# add_flag(-Werror=reorder) # field '$1' will be initialized after field '$2'
add_flag(-Werror=mismatched-tags) # warning: class '$1' was previously declared as struct
add_flag(-Werror=switch) # unhandled values in a switch statement
# cmake-format: on
Expand All @@ -124,9 +133,9 @@ if("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(AppleClang|Clang|GNU)$")
# cmake-format: on
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# using Visual Studio C++
# TODO(warchant): add flags
# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md#msvc

fatal_error("MSVC is not supported")
endif()

print("C flags: ${CMAKE_C_FLAGS}")
Expand Down Expand Up @@ -186,7 +195,8 @@ kagome_install_setup(
core/storage
core/subscription
core/telemetry
core/utils)
core/utils
)

include(CMakePackageConfigHelpers)

Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,15 @@ More details of KAGOME development can be found within the [supported features](

#### Prerequisites

For now, please refer to the [Dockerfile](housekeeping/docker/kagome-dev/minideb.Dockerfile) to get a picture of what you need for a local build-environment.

If you are using a Debian Linux system, the following command allows you to build KAGOME:

```sh
git clone https://github.com/soramitsu/kagome
git clone https://github.com/qdrvm/kagome
cd kagome
sudo chmod +x scripts/init.sh scripts/build.sh

make build
sudo ./scripts/init.sh
./scripts/build.sh
```

You will get KAGOME binary in the `build/node/` folder
Expand Down
61 changes: 43 additions & 18 deletions cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,44 @@ hunter_config(
CMAKE_ARGS WITH_GFLAGS=OFF
)

hunter_config(
wavm
VERSION 1.0.14
KEEP_PACKAGE_SOURCES
)
if ("${WASM_COMPILER}" STREQUAL "WasmEdge")
hunter_config(
LLVM
VERSION 16.0.1
CMAKE_ARGS LLVM_ENABLE_PROJECTS=compiler-rt
)

hunter_config(
LLVM
VERSION 12.0.1-p4
CMAKE_ARGS
hunter_config(
WasmEdge
URL https://github.com/harrm/WasmEdge/archive/8a52b27e2592fc9934b6132e80f69ae6d6925997.zip
SHA1 fbdd08bd648faffa7d140387eb98b437d0f6d5ea
KEEP_PACKAGE_SOURCES
)
endif ()

if ("${WASM_COMPILER}" STREQUAL "WAVM")
hunter_config(
LLVM
VERSION 12.0.1-p4
CMAKE_ARGS
LLVM_ENABLE_PROJECTS=ir
KEEP_PACKAGE_SOURCES
)
KEEP_PACKAGE_SOURCES
)

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(WAVM_CXX_FLAGS -Wno-redundant-move;-Wno-dangling-reference;-Wno-error=extra;)
else ()
set(WAVM_CXX_FLAGS -Wno-redundant-move)
endif ()

hunter_config(
wavm
VERSION 1.0.14
CMAKE_ARGS
WAVM_CXX_FLAGS=${WAVM_CXX_FLAGS}
KEEP_PACKAGE_SOURCES
)
endif ()

hunter_config(
scale
Expand All @@ -71,10 +96,10 @@ hunter_config(
)

# Fix for Apple clang (or clang from brew) of versions 15 and higher
if(APPLE AND (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL "15.0.0")
hunter_config(
binaryen
URL https://github.com/qdrvm/binaryen/archive/0744f64a584cae5b9255b1c2f0a4e0b5e06d7038.zip
SHA1 f953c5f38a0417e494901e15ab6f5d8267388d18
)
endif()
if (APPLE AND (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL "15.0.0")
hunter_config(
binaryen
URL https://github.com/qdrvm/binaryen/archive/0744f64a584cae5b9255b1c2f0a4e0b5e06d7038.zip
SHA1 f953c5f38a0417e494901e15ab6f5d8267388d18
)
endif ()
4 changes: 2 additions & 2 deletions cmake/Hunter/hunter-gate-url.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
HunterGate(
URL https://github.com/qdrvm/hunter/archive/refs/tags/v0.23.257-qdrvm11.tar.gz
SHA1 b2a69ae501bdc99006fb86e55930640004468556
URL "https://github.com/qdrvm/hunter/archive/refs/tags/v0.23.257-qdrvm14.tar.gz"
SHA1 "1d488224f6a06971a5b4166283bde16d1aa56458"
LOCAL
)
3 changes: 3 additions & 0 deletions cmake/clang-format.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ if(NOT CLANG_FORMAT_BIN)
OUTPUT_VARIABLE DEFAULT_CLANG_FORMAT_VERSION
)
math(EXPR DEFAULT_CLANG_FORMAT_VERSION "0 + 0${DEFAULT_CLANG_FORMAT_VERSION}")
if (${DEFAULT_CLANG_FORMAT_VERSION} GREATER ${RECOMMENDED_CLANG_FORMAT_VERSION})
return()
endif()
# Try to find newest version
foreach(CLANG_FORMAT_VERSION RANGE ${RECOMMENDED_CLANG_FORMAT_VERSION} ${DEFAULT_CLANG_FORMAT_VERSION} -1)
find_program(CLANG_FORMAT_BIN_ NAMES clang-format-${CLANG_FORMAT_VERSION})
Expand Down
27 changes: 17 additions & 10 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# https://docs.hunter.sh/en/latest/packages/

if (TESTING)
# https://docs.hunter.sh/en/latest/packages/pkg/GTest.html
hunter_add_package(GTest)
find_package(GTest CONFIG REQUIRED)
endif()
# https://docs.hunter.sh/en/latest/packages/pkg/GTest.html
hunter_add_package(GTest)
find_package(GTest CONFIG REQUIRED)
endif ()

if (BACKWARD)
hunter_add_package(backward-cpp)
find_package(Backward)
endif()
hunter_add_package(backward-cpp)
find_package(Backward)
endif ()

# https://docs.hunter.sh/en/latest/packages/pkg/Boost.html
hunter_add_package(Boost COMPONENTS random filesystem program_options date_time)
Expand Down Expand Up @@ -71,9 +71,16 @@ find_package(libsecp256k1 CONFIG REQUIRED)
hunter_add_package(scale)
find_package(scale CONFIG REQUIRED)

hunter_add_package(wavm)
find_package(LLVM CONFIG REQUIRED)
find_package(WAVM CONFIG REQUIRED)
if ("${WASM_COMPILER}" STREQUAL "WAVM")
hunter_add_package(wavm)
find_package(LLVM CONFIG REQUIRED)
find_package(WAVM CONFIG REQUIRED)
endif ()

if ("${WASM_COMPILER}" STREQUAL "WasmEdge")
hunter_add_package(WasmEdge)
find_library(WASM_EDGE_LIBRARY NAMES wasmedge REQUIRED PATHS "${WASMEDGE_ROOT}")
endif ()

hunter_add_package(zstd)
find_package(zstd CONFIG REQUIRED)
Expand Down
2 changes: 1 addition & 1 deletion cmake/install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ endfunction()
### workaround for imported libraries
function(kagome_install_mini target)
install(TARGETS ${target} EXPORT kagomeTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/kagome
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/kagome
)
endfunction()

Expand Down
6 changes: 6 additions & 0 deletions cmake/kagomeConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ if (KAGOME_ENABLE_WAVM)
find_dependency(WAVM REQUIRED)
endif()

option(KAGOME_ENABLE_WASMEDGE "Include WasmEdge webassembly executor dependency" OFF)
if (KAGOME_ENABLE_WASMEDGE)
find_dependency(LLVM REQUIRED)
find_dependency(WasmEdge REQUIRED)
endif()

option(KAGOME_ENABLE_BINARYEN "Include Binaryen webassembly executor dependency" ON)
if (KAGOME_ENABLE_BINARYEN)
find_dependency(binaryen REQUIRED)
Expand Down
34 changes: 34 additions & 0 deletions cmake/toolchain/compiler/gcc-13.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-13)
find_program(CMAKE_CXX_COMPILER g++-13)

if(NOT CMAKE_C_COMPILER)
fatal_error("gcc-13 not found")
endif()

if(NOT CMAKE_CXX_COMPILER)
fatal_error("g++-13 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-13_cxx20.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include(${CMAKE_CURRENT_LIST_DIR}/compiler/gcc-13.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cxx20.cmake)
3 changes: 2 additions & 1 deletion core/api/service/state/impl/state_api_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ namespace kagome::api {
const std::optional<primitives::BlockHash> &opt_at) const {
auto at =
opt_at.has_value() ? opt_at.value() : block_tree_->bestBlock().hash;
return executor_->callAt(at, method, data);
OUTCOME_TRY(ctx, executor_->ctx().ephemeralAt(at));
return ctx.module_instance->callExportFunction(ctx, method, data);
}

outcome::result<std::vector<common::Buffer>> StateApiImpl::getKeysPaged(
Expand Down
8 changes: 7 additions & 1 deletion core/application/app_configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ namespace kagome::application {
*/
virtual SyncMethod syncMethod() const = 0;

enum class RuntimeExecutionMethod { Compile, Interpret };
enum class RuntimeExecutionMethod {
Compile,
Interpret,
};

/**
* @return enum constant of the chosen runtime backend
*/
Expand All @@ -234,6 +238,8 @@ namespace kagome::application {
virtual bool purgeWavmCache() const = 0;

virtual uint32_t parachainRuntimeInstanceCacheSize() const = 0;
virtual uint32_t parachainPrecompilationThreadNum() const = 0;
virtual bool shouldPrecompileParachainModules() const = 0;

enum class OffchainWorkerMode { WhenValidating, Always, Never };
/**
Expand Down
51 changes: 25 additions & 26 deletions core/application/app_state_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@

namespace kagome::application {

// concepts that check if an object has a method that is called by app state
// manager. Deliberately avoid checking that the method returns bool,
// because if there's a method with an appropriate name, and it doesn't return
// 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(); };
template <typename T>
concept AppStatePreparable = requires(T& t) { t.prepare(); };
template <typename T>
concept AppStateStartable = requires(T& t) { t.start(); };
template <typename T>
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> {
public:
using OnInject = std::function<bool()>;
Expand Down Expand Up @@ -55,45 +75,24 @@ namespace kagome::application {
*/
virtual void atShutdown(OnShutdown &&cb) = 0;

private:
template <typename C, typename = int>
struct HasMethodInject : std::false_type {};
template <typename C>
struct HasMethodInject<C, decltype(&C::inject, 0)> : std::true_type {};

template <typename C, typename = int>
struct HasMethodPrepare : std::false_type {};
template <typename C>
struct HasMethodPrepare<C, decltype(&C::prepare, 0)> : std::true_type {};

template <typename C, typename = int>
struct HasMethodStart : std::false_type {};
template <typename C>
struct HasMethodStart<C, decltype(&C::start, 0)> : std::true_type {};

template <typename C, typename = int>
struct HasMethodStop : std::false_type {};
template <typename C>
struct HasMethodStop<C, decltype(&C::stop, 0)> : std::true_type {};

public:
/**
* @brief Registration special methods (if any) of object as handlers
* for stages of application life-cycle
* @param entity is registered entity
*/
template <typename Controlled>
template <AppStateControllable Controlled>
void takeControl(Controlled &entity) {
if constexpr (HasMethodInject<Controlled>::value) {
if constexpr (AppStateInjectable<Controlled>) {
atInject([&entity]() -> bool { return entity.inject(); });
}
if constexpr (HasMethodPrepare<Controlled>::value) {
if constexpr (AppStatePreparable<Controlled>) {
atPrepare([&entity]() -> bool { return entity.prepare(); });
}
if constexpr (HasMethodStart<Controlled>::value) {
if constexpr (AppStateStartable<Controlled>) {
atLaunch([&entity]() -> bool { return entity.start(); });
}
if constexpr (HasMethodStop<Controlled>::value) {
if constexpr (AppStateStoppable<Controlled>) {
atShutdown([&entity]() -> void { return entity.stop(); });
}
}
Expand Down
Loading

0 comments on commit 0a3fb9d

Please sign in to comment.