diff --git a/.githooks/pre-commit b/.githooks/pre-commit index cbbd8d56d6..3eb05ec9dd 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -14,7 +14,7 @@ fi # check clang-format binary CLANG_FORMAT_ENABLED=1 -CLANG_FORMAT=$(which clang-format-15) +CLANG_FORMAT=$(which clang-format-15 2>/dev/null) if [ -z "${CLANG_FORMAT}" ]; then CLANG_FORMAT=$(which clang-format) if [ -z "${CLANG_FORMAT}" ]; then diff --git a/CMakePresets.json b/CMakePresets.json index 5482b27820..70f93383f2 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -3,7 +3,7 @@ "configurePresets": [ { "name": "base", - "toolchainFile": "${sourceDir}/cmake/toolchain/clang-15_cxx20.cmake", + "toolchainFile": "${sourceDir}/cmake/toolchain/clang-16_cxx20.cmake", "generator": "Ninja", "hidden": true }, diff --git a/core/parachain/pvf/kagome_pvf_worker.cpp b/core/parachain/pvf/kagome_pvf_worker.cpp index c79d24c7a1..ebdd14c351 100644 --- a/core/parachain/pvf/kagome_pvf_worker.cpp +++ b/core/parachain/pvf/kagome_pvf_worker.cpp @@ -12,6 +12,7 @@ #include #include #include +#include "runtime/wabt/instrument.hpp" #ifdef __linux__ #include @@ -338,20 +339,21 @@ namespace kagome::parachain { #endif auto injector = pvf_worker_injector(input_config); OUTCOME_TRY(factory, createModuleFactory(injector, input_config.engine)); - std::shared_ptr instance; + std::shared_ptr module; while (true) { OUTCOME_TRY(input, decodeInput()); if (auto *code = std::get_if(&input)) { OUTCOME_TRY(path, chroot_path(*code)); - OUTCOME_TRY(module, factory->loadCompiled(path)); - BOOST_OUTCOME_TRY(instance, module->instantiate()); + BOOST_OUTCOME_TRY(module, factory->loadCompiled(path)); continue; } auto &input_args = std::get(input); - if (not instance) { + if (not module) { SL_ERROR(logger, "PvfWorkerInputCode expected"); return std::errc::invalid_argument; } + OUTCOME_TRY(instance, module->instantiate()); + OUTCOME_TRY(ctx, runtime::RuntimeContextFactory::stateless(instance)); OUTCOME_TRY( result, diff --git a/core/parachain/pvf/pool.cpp b/core/parachain/pvf/pool.cpp index 4e4fabbe88..3c4255523d 100644 --- a/core/parachain/pvf/pool.cpp +++ b/core/parachain/pvf/pool.cpp @@ -44,12 +44,12 @@ namespace kagome::parachain { PvfPool::PvfPool(const application::AppConfiguration &app_config, std::shared_ptr module_factory, - std::shared_ptr instrument) + std::shared_ptr instrument) : pool_{std::make_shared( - app_config, - std::move(module_factory), - std::move(instrument), - app_config.parachainRuntimeInstanceCacheSize())} {} + app_config, + std::move(module_factory), + std::move(instrument), + app_config.parachainRuntimeInstanceCacheSize())} {} outcome::result PvfPool::precompile( const Hash256 &code_hash, @@ -65,4 +65,17 @@ namespace kagome::parachain { }, config); } + + std::optional> PvfPool::getModule( + const Hash256 &code_hash, + const runtime::RuntimeContext::ContextParams &config) const { + return pool_->getModule(code_hash, config); + } + + std::filesystem::path PvfPool::getCachePath( + const common::Hash256 &code_hash, + const runtime::RuntimeContext::ContextParams &config) const { + return pool_->getCachePath(code_hash, config); + } + } // namespace kagome::parachain diff --git a/core/parachain/pvf/pool.hpp b/core/parachain/pvf/pool.hpp index f5b0e84090..ad3892dd71 100644 --- a/core/parachain/pvf/pool.hpp +++ b/core/parachain/pvf/pool.hpp @@ -6,8 +6,10 @@ #pragma once +#include #include +#include "common/optref.hpp" #include "runtime/runtime_context.hpp" namespace kagome::application { @@ -15,8 +17,9 @@ namespace kagome::application { } // namespace kagome::application namespace kagome::runtime { - class InstrumentWasm; + class WasmInstrumenter; class ModuleFactory; + class Module; class RuntimeInstancesPoolImpl; } // namespace kagome::runtime @@ -28,11 +31,15 @@ namespace kagome::parachain { public: PvfPool(const application::AppConfiguration &app_config, std::shared_ptr module_factory, - std::shared_ptr instrument); + std::shared_ptr instrument); - auto &pool() const { - return pool_; - } + std::optional> getModule( + const Hash256 &code_hash, + const runtime::RuntimeContext::ContextParams &config) const; + + std::filesystem::path getCachePath( + const common::Hash256 &code_hash, + const runtime::RuntimeContext::ContextParams &config) const; /** * Measures `kagome_parachain_candidate_validation_code_size` and diff --git a/core/parachain/pvf/pvf_impl.cpp b/core/parachain/pvf/pvf_impl.cpp index cb66268a22..1c97841086 100644 --- a/core/parachain/pvf/pvf_impl.cpp +++ b/core/parachain/pvf/pvf_impl.cpp @@ -12,6 +12,7 @@ #include "application/app_state_manager.hpp" #include "blockchain/block_tree.hpp" #include "common/visitor.hpp" +#include "log/profiling_logger.hpp" #include "metrics/histogram_timer.hpp" #include "parachain/pvf/module_precompiler.hpp" #include "parachain/pvf/pool.hpp" @@ -26,6 +27,7 @@ #include "runtime/module.hpp" #include "runtime/module_repository.hpp" #include "runtime/runtime_code_provider.hpp" +#include "runtime/runtime_context.hpp" #include "runtime/runtime_instances_pool.hpp" #include "scale/std_variant.hpp" @@ -44,7 +46,7 @@ OUTCOME_CPP_DEFINE_CATEGORY(kagome::parachain, PvfError, e) { using kagome::parachain::PvfError; switch (e) { case PvfError::PERSISTED_DATA_HASH: - return "Incorrect Perssted Data hash"; + return "Incorrect Persisted Data hash"; case PvfError::NO_CODE: return "No code"; case PvfError::NO_PERSISTED_DATA: @@ -63,6 +65,8 @@ OUTCOME_CPP_DEFINE_CATEGORY(kagome::parachain, PvfError, e) { return "Commitments hash mismatch"; case PvfError::OUTPUTS: return "ValidationResult is invalid"; + case PvfError::COMPILATION_ERROR: + return "PVF code failed to compile"; } return "unknown error (kagome::parachain::PvfError)"; } @@ -318,15 +322,27 @@ namespace kagome::parachain { constexpr auto name = "validate_block"; CB_TRYV(pvf_pool_->precompile(code_hash, code_zstd, executor_params)); if (not app_configuration_->usePvfSubprocess()) { - CB_TRY( - auto instance, - pvf_pool_->pool()->instantiateFromCode( - code_hash, [&] { return PvfError::NO_CODE; }, executor_params)); - CB_TRY(auto ctx, ctx_factory_->stateless(instance)); + // Reusing instances for PVF calls doesn't work, runtime calls start to + // crash on access out of memory bounds + KAGOME_PROFILE_START_L(log_, single_process_runtime_instantitation); + auto module_opt = pvf_pool_->getModule(code_hash, executor_params); + if (!module_opt) { + SL_ERROR(log_, + "Runtime module supposed to be precompiled for parachain ID " + "{}, but it's not. This indicates a bug.", + receipt.descriptor.para_id); + cb(PvfError::NO_CODE); + return; + } + auto &wasm_module = module_opt.value(); + CB_TRY(auto instance, wasm_module->instantiate()); + CB_TRY(auto ctx, runtime::RuntimeContextFactory::stateless(instance)); + KAGOME_PROFILE_END_L(log_, single_process_runtime_instantitation); + KAGOME_PROFILE_START_L(log_, single_process_runtime_call); return cb(executor_->call(ctx, name, params)); } workers_->execute({ - pvf_pool_->pool()->cachePath(code_hash, executor_params), + pvf_pool_->getCachePath(code_hash, executor_params), scale::encode(params).value(), [cb{std::move(cb)}](outcome::result r) { if (r.has_error()) { diff --git a/core/parachain/pvf/pvf_impl.hpp b/core/parachain/pvf/pvf_impl.hpp index 762c2eed42..dafc3cac40 100644 --- a/core/parachain/pvf/pvf_impl.hpp +++ b/core/parachain/pvf/pvf_impl.hpp @@ -13,6 +13,7 @@ #include "crypto/sr25519_provider.hpp" #include "log/logger.hpp" #include "runtime/runtime_api/parachain_host.hpp" +#include "runtime/wabt/instrument.hpp" namespace kagome { class PoolHandler; @@ -46,6 +47,7 @@ namespace kagome::parachain { OUTPUTS, PERSISTED_DATA_HASH, NO_CODE, + COMPILATION_ERROR }; } // namespace kagome::parachain diff --git a/core/parachain/pvf/workers.cpp b/core/parachain/pvf/workers.cpp index 7eee835996..27e55e64e3 100644 --- a/core/parachain/pvf/workers.cpp +++ b/core/parachain/pvf/workers.cpp @@ -145,7 +145,9 @@ namespace kagome::parachain { return job.cb(r.error()); } self->writeCode( - std::move(job), {std::move(process)}, std::move(used)); + std::move(job), + {.process = std::move(process), .code = std::nullopt}, + std::move(used)); }); return; } diff --git a/core/runtime/binaryen/instance_environment_factory.cpp b/core/runtime/binaryen/instance_environment_factory.cpp index cb3d84cf1e..454904729f 100644 --- a/core/runtime/binaryen/instance_environment_factory.cpp +++ b/core/runtime/binaryen/instance_environment_factory.cpp @@ -9,6 +9,7 @@ #include "host_api/host_api_factory.hpp" #include "runtime/binaryen/binaryen_memory_provider.hpp" #include "runtime/common/trie_storage_provider_impl.hpp" +#include "runtime/wabt/instrument.hpp" namespace kagome::runtime::binaryen { diff --git a/core/runtime/binaryen/memory_impl.hpp b/core/runtime/binaryen/memory_impl.hpp index 795cc36554..625a3964bd 100644 --- a/core/runtime/binaryen/memory_impl.hpp +++ b/core/runtime/binaryen/memory_impl.hpp @@ -9,7 +9,6 @@ #include #include -#include // for std::memset in gcc #include #include #include diff --git a/core/runtime/common/core_api_factory_impl.cpp b/core/runtime/common/core_api_factory_impl.cpp index fc8ff41f15..66439b7222 100644 --- a/core/runtime/common/core_api_factory_impl.cpp +++ b/core/runtime/common/core_api_factory_impl.cpp @@ -30,9 +30,8 @@ namespace kagome::runtime { CoreApiFactoryImpl::CoreApiFactoryImpl( std::shared_ptr hasher, - LazySPtr module_factory) - : hasher_{std::move(hasher)}, - module_factory_{std::move(module_factory)} {} + LazySPtr instance_pool) + : hasher_{std::move(hasher)}, instance_pool_{std::move(instance_pool)} {} outcome::result> CoreApiFactoryImpl::make( BufferView code_zstd, @@ -43,7 +42,7 @@ namespace kagome::runtime { if (version) { return std::make_unique(*version); } - if (not module_factory_.get()) { + if (not instance_pool_.get()) { return std::errc::not_supported; } MemoryLimits config; @@ -51,7 +50,7 @@ namespace kagome::runtime { heapAllocStrategyHeappagesDefault( *storage_provider->getCurrentBatch())); OUTCOME_TRY(instance, - module_factory_.get()->instantiateFromCode( + instance_pool_.get()->instantiateFromCode( code_hash, [&] { return std::make_shared(code); }, {config})); diff --git a/core/runtime/common/core_api_factory_impl.hpp b/core/runtime/common/core_api_factory_impl.hpp index 5d6462175a..e7c5c7df53 100644 --- a/core/runtime/common/core_api_factory_impl.hpp +++ b/core/runtime/common/core_api_factory_impl.hpp @@ -35,7 +35,7 @@ namespace kagome::runtime { public std::enable_shared_from_this { public: explicit CoreApiFactoryImpl(std::shared_ptr hasher, - LazySPtr module_factory); + LazySPtr instance_pool); outcome::result> make( BufferView code, @@ -43,7 +43,7 @@ namespace kagome::runtime { private: std::shared_ptr hasher_; - LazySPtr module_factory_; + LazySPtr instance_pool_; }; } // namespace kagome::runtime diff --git a/core/runtime/common/module_instance.cpp b/core/runtime/common/module_instance.cpp index c27bf25523..833ddc0638 100644 --- a/core/runtime/common/module_instance.cpp +++ b/core/runtime/common/module_instance.cpp @@ -61,9 +61,6 @@ namespace kagome::runtime { "__heap_base too low, allocations will overwrite wasm data segments"); } - auto memory_size = memory.memory()->size(); - memset(memory.view(0, memory_size).value().data(), 0, memory_size); - forDataSegment([&](auto offset, auto segment) { memory.storeBuffer(offset, segment); }); diff --git a/core/runtime/common/runtime_instances_pool.cpp b/core/runtime/common/runtime_instances_pool.cpp index 680cf37391..f7b7af9918 100644 --- a/core/runtime/common/runtime_instances_pool.cpp +++ b/core/runtime/common/runtime_instances_pool.cpp @@ -83,7 +83,7 @@ namespace kagome::runtime { RuntimeInstancesPoolImpl::RuntimeInstancesPoolImpl( const application::AppConfiguration &app_config, std::shared_ptr module_factory, - std::shared_ptr instrument, + std::shared_ptr instrument, size_t capacity) : cache_dir_{app_config.runtimeCacheDirPath()}, module_factory_{std::move(module_factory)}, @@ -98,14 +98,14 @@ namespace kagome::runtime { const GetCode &get_code, const RuntimeContext::ContextParams &config) { std::unique_lock lock{pools_mtx_}; - OUTCOME_TRY(module, getModule(lock, code_hash, get_code, config)); + OUTCOME_TRY(module, getPool(lock, code_hash, get_code, config)); OUTCOME_TRY(instance, module.get().instantiate(lock)); BOOST_ASSERT(shared_from_this()); return std::make_shared( weak_from_this(), code_hash, config, std::move(instance)); } - std::filesystem::path RuntimeInstancesPoolImpl::cachePath( + std::filesystem::path RuntimeInstancesPoolImpl::getCachePath( const CodeHash &code_hash, const RuntimeContext::ContextParams &config) const { std::string name; @@ -140,13 +140,25 @@ namespace kagome::runtime { const GetCode &get_code, const RuntimeContext::ContextParams &config) { std::unique_lock lock{pools_mtx_}; - OUTCOME_TRY(getModule(lock, code_hash, get_code, config)); + OUTCOME_TRY(getPool(lock, code_hash, get_code, config)); return outcome::success(); } + std::optional> + RuntimeInstancesPoolImpl::getModule( + const CodeHash &code_hash, const RuntimeContext::ContextParams &config) { + std::unique_lock lock{pools_mtx_}; + Key key{code_hash, config}; + auto pool_opt = pools_.get(key); + if (!pool_opt) { + return std::nullopt; + } + return pool_opt->get().module; + } + outcome::result< std::reference_wrapper> - RuntimeInstancesPoolImpl::getModule( + RuntimeInstancesPoolImpl::getPool( std::unique_lock &lock, const CodeHash &code_hash, const GetCode &get_code, @@ -186,7 +198,7 @@ namespace kagome::runtime { BOOST_ASSERT(is_inserted); BOOST_ASSERT(iter != compiling_modules_.end()); l.unlock(); - auto path = cachePath(code_hash, config); + auto path = getCachePath(code_hash, config); auto res = [&]() -> CompilationResult { std::error_code ec; if (not std::filesystem::exists(path, ec)) { diff --git a/core/runtime/common/runtime_instances_pool.hpp b/core/runtime/common/runtime_instances_pool.hpp index 293ea0b3ac..4987f446c1 100644 --- a/core/runtime/common/runtime_instances_pool.hpp +++ b/core/runtime/common/runtime_instances_pool.hpp @@ -6,6 +6,7 @@ #pragma once +#include "common/optref.hpp" #include "runtime/runtime_instances_pool.hpp" #include @@ -22,7 +23,7 @@ namespace kagome::application { } // namespace kagome::application namespace kagome::runtime { - class InstrumentWasm; + class WasmInstrumenter; /** * @brief Pool of runtime instances - per state. Encapsulates modules cache. @@ -34,7 +35,7 @@ namespace kagome::runtime { explicit RuntimeInstancesPoolImpl( const application::AppConfiguration &app_config, std::shared_ptr module_factory, - std::shared_ptr instrument, + std::shared_ptr instrument, size_t capacity = DEFAULT_MODULES_CACHE_SIZE); outcome::result> instantiateFromCode( @@ -53,7 +54,7 @@ namespace kagome::runtime { const RuntimeContext::ContextParams &config, std::shared_ptr &&instance); - std::filesystem::path cachePath( + std::filesystem::path getCachePath( const CodeHash &code_hash, const RuntimeContext::ContextParams &config) const; @@ -62,6 +63,9 @@ namespace kagome::runtime { const GetCode &get_code, const RuntimeContext::ContextParams &config); + std::optional> getModule( + const CodeHash &code_hash, const RuntimeContext::ContextParams &config); + private: using Key = std::tuple; struct InstancePool { @@ -72,7 +76,7 @@ namespace kagome::runtime { std::unique_lock &lock); }; - outcome::result> getModule( + outcome::result> getPool( std::unique_lock &lock, const CodeHash &code_hash, const GetCode &get_code, @@ -86,7 +90,7 @@ namespace kagome::runtime { std::filesystem::path cache_dir_; std::shared_ptr module_factory_; - std::shared_ptr instrument_; + std::shared_ptr instrument_; std::mutex pools_mtx_; Lru pools_; @@ -102,5 +106,5 @@ template <> struct boost::di::ctor_traits { BOOST_DI_INJECT_TRAITS(const kagome::application::AppConfiguration &, std::shared_ptr, - std::shared_ptr); + std::shared_ptr); }; diff --git a/core/runtime/module_repository.hpp b/core/runtime/module_repository.hpp index 31d97c441d..cdcd302f10 100644 --- a/core/runtime/module_repository.hpp +++ b/core/runtime/module_repository.hpp @@ -33,7 +33,8 @@ namespace kagome::runtime { /** * @brief Returns a module instance for runtime at the \arg block state, - * loading its code using the provided \arg code_provider + * loading its code using the provided \arg code_provider. The instance + * may be reused. * @param block info of the block at which the runtime code should be * extracted * @param state_hash of the block at which the runtime code should be diff --git a/core/runtime/runtime_instances_pool.hpp b/core/runtime/runtime_instances_pool.hpp index 0b5e24f75b..7f88abf369 100644 --- a/core/runtime/runtime_instances_pool.hpp +++ b/core/runtime/runtime_instances_pool.hpp @@ -6,6 +6,7 @@ #pragma once +#include "common/blob.hpp" #include "runtime/module_instance.hpp" #include "runtime/runtime_code_provider.hpp" #include "runtime/runtime_context.hpp" @@ -20,7 +21,7 @@ namespace kagome::runtime { public: static constexpr size_t DEFAULT_MODULES_CACHE_SIZE = 2; - using CodeHash = storage::trie::RootHash; + using CodeHash = common::Hash256; using GetCode = std::function; virtual ~RuntimeInstancesPool() = default; diff --git a/core/runtime/wabt/instrument.cpp b/core/runtime/wabt/instrument.cpp index f226185372..9a0986efa1 100644 --- a/core/runtime/wabt/instrument.cpp +++ b/core/runtime/wabt/instrument.cpp @@ -80,7 +80,7 @@ namespace kagome::runtime { return outcome::success(); } - WabtOutcome prepareBlobForCompilation( + WabtOutcome instrumentCodeForCompilation( common::BufferView code, const MemoryLimits &config) { OUTCOME_TRY(module, wabtDecode(code)); if (config.max_stack_values_num) { @@ -94,8 +94,8 @@ namespace kagome::runtime { return wabtEncode(module); } - WabtOutcome InstrumentWasm::instrument( + WabtOutcome WasmInstrumenter::instrument( common::BufferView code, const MemoryLimits &config) const { - return prepareBlobForCompilation(code, config); + return instrumentCodeForCompilation(code, config); } } // namespace kagome::runtime diff --git a/core/runtime/wabt/instrument.hpp b/core/runtime/wabt/instrument.hpp index eaf56c971d..250464e3b4 100644 --- a/core/runtime/wabt/instrument.hpp +++ b/core/runtime/wabt/instrument.hpp @@ -28,12 +28,12 @@ namespace kagome::runtime { * - set memory limit * https://github.com/paritytech/polkadot-sdk/blob/11831df8e709061e9c6b3292facb5d7d9709f151/substrate/client/executor/wasmtime/src/runtime.rs#L651 */ - WabtOutcome prepareBlobForCompilation( + WabtOutcome instrumentCodeForCompilation( common::BufferView code, const MemoryLimits &config); - class InstrumentWasm { + class WasmInstrumenter { public: - virtual ~InstrumentWasm() = default; + virtual ~WasmInstrumenter() = default; virtual WabtOutcome instrument( common::BufferView code, const MemoryLimits &config) const; diff --git a/core/runtime/wasm_edge/module_factory_impl.cpp b/core/runtime/wasm_edge/module_factory_impl.cpp index ca2efac3f8..770968a3c9 100644 --- a/core/runtime/wasm_edge/module_factory_impl.cpp +++ b/core/runtime/wasm_edge/module_factory_impl.cpp @@ -400,8 +400,11 @@ namespace kagome::runtime::wasm_edge { CompilationOutcome> ModuleFactoryImpl::loadCompiled( std::filesystem::path path_compiled) const { Buffer code; - if (not readFile(code, path_compiled)) { - return CompilationError{"read file failed"}; + if (auto res = readFile(code, path_compiled); !res) { + return CompilationError{ + fmt::format("Failed to read compiled wasm module from '{}': {}", + path_compiled, + res.error())}; } auto code_hash = hasher_->blake2b_256(code); OUTCOME_TRY(configure_ctx, configureCtx()); diff --git a/core/utils/read_file.hpp b/core/utils/read_file.hpp index 39be42faf6..816b308e33 100644 --- a/core/utils/read_file.hpp +++ b/core/utils/read_file.hpp @@ -8,6 +8,9 @@ #include #include +#include + +#include namespace kagome { @@ -25,19 +28,19 @@ namespace kagome { }; template - bool readFile(Out &out, const std::filesystem::path &path) { + outcome::result readFile(Out &out, const std::filesystem::path &path) { std::ifstream file{path, std::ios::binary | std::ios::ate}; if (not file.good()) { out.clear(); - return false; + return std::errc{errno}; } out.resize(file.tellg()); file.seekg(0); file.read(reinterpret_cast(out.data()), out.size()); if (not file.good()) { out.clear(); - return false; + return std::errc{errno}; } - return true; + return outcome::success(); } } // namespace kagome diff --git a/test/core/parachain/pvf_test.cpp b/test/core/parachain/pvf_test.cpp index a07818dc43..6230d553a0 100644 --- a/test/core/parachain/pvf_test.cpp +++ b/test/core/parachain/pvf_test.cpp @@ -6,6 +6,9 @@ #include +#include "gmock/gmock.h" +#include "mock/core/runtime/memory_provider_mock.hpp" +#include "mock/core/runtime/trie_storage_provider_mock.hpp" #include "parachain/pvf/pvf_impl.hpp" #include "crypto/hasher/hasher_impl.hpp" @@ -13,6 +16,7 @@ #include "mock/core/application/app_state_manager_mock.hpp" #include "mock/core/blockchain/block_tree_mock.hpp" #include "mock/core/crypto/sr25519_provider_mock.hpp" +#include "mock/core/host_api/host_api_mock.hpp" #include "mock/core/runtime/instrument_wasm.hpp" #include "mock/core/runtime/module_factory_mock.hpp" #include "mock/core/runtime/module_instance_mock.hpp" @@ -26,6 +30,7 @@ #include "parachain/pvf/pvf_worker_types.hpp" #include "parachain/types.hpp" #include "runtime/executor.hpp" +#include "runtime/instance_environment.hpp" #include "testutil/literals.hpp" #include "testutil/outcome.hpp" #include "testutil/prepare_loggers.hpp" @@ -44,11 +49,11 @@ using kagome::parachain::PvfImpl; using kagome::parachain::PvfPool; using kagome::parachain::PvfThreadPool; using kagome::parachain::ValidationResult; -using kagome::runtime::DontInstrumentWasm; using kagome::runtime::MemoryLimits; using kagome::runtime::ModuleFactoryMock; using kagome::runtime::ModuleInstanceMock; using kagome::runtime::ModuleMock; +using kagome::runtime::NoopWasmInstrumenter; namespace application = kagome::application; namespace crypto = kagome::crypto; namespace runtime = kagome::runtime; @@ -103,7 +108,7 @@ class PvfTest : public testing::Test { hasher_, std::make_shared(*app_config_, module_factory_, - std::make_shared()), + std::make_shared()), block_tree, sr25519_provider, parachain_api, @@ -150,7 +155,7 @@ class PvfTest : public testing::Test { scale::encode(Pvf::CandidateCommitments{}).value()); testing::MockFunction)> cb; EXPECT_CALL(cb, Call(_)).WillOnce([](outcome::result r) { - EXPECT_TRUE(r); + EXPECT_OUTCOME_TRUE_1(r); }); pvf_->pvfValidate(pvd, pov, receipt, code, cb.AsStdFunction()); io_->restart(); diff --git a/test/core/runtime/executor_test.cpp b/test/core/runtime/executor_test.cpp index 6022172295..4e74f3fd6e 100644 --- a/test/core/runtime/executor_test.cpp +++ b/test/core/runtime/executor_test.cpp @@ -131,7 +131,6 @@ class ExecutorTest : public testing::Test { .WillRepeatedly(testing::Return(42)); EXPECT_CALL(*module_repo_, getInstanceAt(blockchain_state, storage_state)) .WillRepeatedly(testing::Return(module_instance)); - if (type == CallType::Persistent) { return ctx_factory_->persistentAt(blockchain_state.hash); } else { diff --git a/test/core/runtime/instance_pool_test.cpp b/test/core/runtime/instance_pool_test.cpp index 4b9f5ddd4c..470c746ac4 100644 --- a/test/core/runtime/instance_pool_test.cpp +++ b/test/core/runtime/instance_pool_test.cpp @@ -23,10 +23,10 @@ using kagome::application::AppConfigurationMock; using kagome::common::Buffer; -using kagome::runtime::DontInstrumentWasm; using kagome::runtime::ModuleFactoryMock; using kagome::runtime::ModuleInstanceMock; using kagome::runtime::ModuleMock; +using kagome::runtime::NoopWasmInstrumenter; using kagome::runtime::RuntimeContext; using kagome::runtime::RuntimeInstancesPool; using kagome::runtime::RuntimeInstancesPoolImpl; @@ -61,7 +61,7 @@ TEST(InstancePoolTest, HeavilyMultithreadedCompilation) { auto pool = std::make_shared( app_config, module_factory, - std::make_shared(), + std::make_shared(), POOL_SIZE); EXPECT_CALL(*module_factory, compilerType()) diff --git a/test/core/runtime/runtime_test_base.hpp b/test/core/runtime/runtime_test_base.hpp index 24aa8eb421..a2429c6221 100644 --- a/test/core/runtime/runtime_test_base.hpp +++ b/test/core/runtime/runtime_test_base.hpp @@ -193,7 +193,7 @@ class RuntimeTestBaseImpl { instance_pool_ = std::make_shared( app_config_, module_factory, - std::make_shared()); + std::make_shared()); auto module_repo = std::make_shared(instance_pool_, hasher_, diff --git a/test/core/runtime/wavm/CMakeLists.txt b/test/core/runtime/wavm/CMakeLists.txt index 0d36515fb4..88ba02c971 100644 --- a/test/core/runtime/wavm/CMakeLists.txt +++ b/test/core/runtime/wavm/CMakeLists.txt @@ -43,21 +43,3 @@ target_link_libraries(core_integration_test filesystem logger_for_tests ) - -addtest(wavm_module_init_test - wavm_module_init_test.cpp -) -target_link_libraries(wavm_module_init_test - runtime_wavm - basic_code_provider - blockchain - hasher - core_api - host_api_factory - offchain_persistent_storage - offchain_worker_pool - runtime_properties_cache - logger_for_tests - module_repository - wavm_runtime_test -) diff --git a/test/core/runtime/wavm/wavm_module_init_test.cpp b/test/core/runtime/wavm/wavm_module_init_test.cpp deleted file mode 100644 index 4566440f2c..0000000000 --- a/test/core/runtime/wavm/wavm_module_init_test.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright Quadrivium LLC - * All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include "core/runtime/wavm/wavm_runtime_test.hpp" - -#include "core/runtime/wavm/runtime_paths.hpp" -#include "testutil/prepare_loggers.hpp" - -class WavmModuleInitTest : public ::testing::TestWithParam, - public WavmRuntimeTest { - public: - static void SetUpTestCase() { - testutil::prepareLoggers(); - } - - void SetUp() override { - SetUpImpl(); - } - - kagome::log::Logger log_ = kagome::log::createLogger("Test"); -}; - -TEST_P(WavmModuleInitTest, DISABLED_SingleModule) { - auto wasm = GetParam(); - SL_INFO(log_, "Trying {}", wasm); - auto code_provider = std::make_shared( - std::string(kBasePath) + std::string(wasm)); - EXPECT_OUTCOME_TRUE(code, code_provider->getCodeAt({})); - auto code_hash = hasher_->blake2b_256(*code); - auto instance = - instance_pool_->instantiateFromCode(code_hash, [&] { return code; }, {}) - .value(); - EXPECT_OUTCOME_TRUE( - runtime_context, - kagome::runtime::RuntimeContextFactory::stateless(instance)); - EXPECT_OUTCOME_TRUE(response, - runtime_context.module_instance->callExportFunction( - runtime_context, "Core_version", {})); - auto memory = runtime_context.module_instance->getEnvironment() - .memory_provider->getCurrentMemory(); - GTEST_ASSERT_TRUE(memory.has_value()); - EXPECT_OUTCOME_TRUE(cv, scale::decode(response)); - SL_INFO(log_, - "Module initialized - spec {}-{}, impl {}-{}", - cv.spec_name, - cv.spec_version, - cv.impl_name, - cv.impl_version); -} - -INSTANTIATE_TEST_SUITE_P(SingleModule, - WavmModuleInitTest, - testing::ValuesIn(kKusamaParachains)); diff --git a/test/core/runtime/wavm/wavm_runtime_test.hpp b/test/core/runtime/wavm/wavm_runtime_test.hpp index a81d415abe..3051e6caa4 100644 --- a/test/core/runtime/wavm/wavm_runtime_test.hpp +++ b/test/core/runtime/wavm/wavm_runtime_test.hpp @@ -6,6 +6,7 @@ #pragma once +#include #include "core/runtime/runtime_test_base.hpp" #include "crypto/hasher/hasher_impl.hpp" diff --git a/test/external-project-test/src/main.cpp b/test/external-project-test/src/main.cpp index a878dff140..4946f7c0dd 100644 --- a/test/external-project-test/src/main.cpp +++ b/test/external-project-test/src/main.cpp @@ -223,7 +223,7 @@ int main() { std::make_shared( app_config, module_factory, - std::make_shared()); + std::make_shared()); auto module_repo = std::make_shared( runtime_instances_pool, hasher, diff --git a/test/mock/core/runtime/instrument_wasm.hpp b/test/mock/core/runtime/instrument_wasm.hpp index cb297f39a4..f2f392c8cb 100644 --- a/test/mock/core/runtime/instrument_wasm.hpp +++ b/test/mock/core/runtime/instrument_wasm.hpp @@ -11,7 +11,7 @@ #include namespace kagome::runtime { - struct DontInstrumentWasm : InstrumentWasm { + struct NoopWasmInstrumenter : WasmInstrumenter { WabtOutcome instrument( common::BufferView code, const MemoryLimits &) const override { return common::Buffer{code};