diff --git a/cmake/Hunter/config.cmake b/cmake/Hunter/config.cmake index 47ac26a223..7f023aa566 100644 --- a/cmake/Hunter/config.cmake +++ b/cmake/Hunter/config.cmake @@ -40,7 +40,7 @@ hunter_config( hunter_config( libp2p - VERSION 0.1.19 + VERSION 0.1.20 KEEP_PACKAGE_SOURCES ) diff --git a/cmake/Hunter/hunter-gate-url.cmake b/cmake/Hunter/hunter-gate-url.cmake index c92ff5b0b7..002c72603d 100644 --- a/cmake/Hunter/hunter-gate-url.cmake +++ b/cmake/Hunter/hunter-gate-url.cmake @@ -1,5 +1,5 @@ HunterGate( - URL https://github.com/qdrvm/hunter/archive/refs/tags/v0.25.3-qdrvm7.zip - SHA1 be5869134ef7448fe2420d60dbb9706596b1b8bd + URL https://github.com/qdrvm/hunter/archive/refs/tags/v0.25.3-qdrvm8.zip + SHA1 dc0af42b358dc0bcab304a455e80681c12d52e0f LOCAL ) diff --git a/core/consensus/grandpa/impl/grandpa_impl.cpp b/core/consensus/grandpa/impl/grandpa_impl.cpp index af2a577b83..924f79eade 100644 --- a/core/consensus/grandpa/impl/grandpa_impl.cpp +++ b/core/consensus/grandpa/impl/grandpa_impl.cpp @@ -175,24 +175,7 @@ namespace kagome::consensus::grandpa { } // Timer to send neighbor message if round does not change long time (1 min) - fallback_timer_handle_ = scheduler_->scheduleWithHandle( - [wp{weak_from_this()}] { - auto self = wp.lock(); - if (not self) { - return; - } - BOOST_ASSERT_MSG(self->current_round_, - "Current round must be defiled anytime after start"); - auto round = - std::dynamic_pointer_cast(self->current_round_); - if (round) { - round->sendNeighborMessage(); - } - - std::ignore = - self->fallback_timer_handle_.reschedule(std::chrono::minutes(1)); - }, - std::chrono::minutes(1)); + setTimerFallback(); tryExecuteNextRound(current_round_); @@ -206,7 +189,7 @@ namespace kagome::consensus::grandpa { } void GrandpaImpl::stop() { - fallback_timer_handle_.cancel(); + fallback_timer_handle_.reset(); } std::shared_ptr GrandpaImpl::makeInitialRound( @@ -387,7 +370,7 @@ namespace kagome::consensus::grandpa { BOOST_ASSERT(res.value() != nullptr); current_round_ = std::move(res.value()); - std::ignore = fallback_timer_handle_.reschedule(std::chrono::minutes(1)); + setTimerFallback(); // Truncate chain of rounds size_t i = 0; @@ -743,7 +726,7 @@ namespace kagome::consensus::grandpa { ::libp2p::common::FinalAction cleanup([&] { if (need_cleanup_when_exiting_scope) { - catchup_request_timer_handle_.cancel(); + catchup_request_timer_handle_.reset(); pending_catchup_request_.reset(); } }); @@ -1472,4 +1455,23 @@ namespace kagome::consensus::grandpa { } update.update(); } + + void GrandpaImpl::setTimerFallback() { + fallback_timer_handle_ = scheduler_->scheduleWithHandle( + [weak_self{weak_from_this()}] { + auto self = weak_self.lock(); + if (not self) { + return; + } + BOOST_ASSERT_MSG(self->current_round_, + "Current round must be defiled anytime after start"); + auto round = + std::dynamic_pointer_cast(self->current_round_); + if (round) { + round->sendNeighborMessage(); + } + self->setTimerFallback(); + }, + std::chrono::minutes(1)); + } } // namespace kagome::consensus::grandpa diff --git a/core/consensus/grandpa/impl/grandpa_impl.hpp b/core/consensus/grandpa/impl/grandpa_impl.hpp index 707bce114b..7f3632209d 100644 --- a/core/consensus/grandpa/impl/grandpa_impl.hpp +++ b/core/consensus/grandpa/impl/grandpa_impl.hpp @@ -322,6 +322,8 @@ namespace kagome::consensus::grandpa { void saveCachedVotes(); void applyCachedVotes(VotingRound &round); + void setTimerFallback(); + log::Logger logger_ = log::createLogger("Grandpa", "grandpa"); const size_t kVotesCacheSize = 5; diff --git a/core/consensus/grandpa/impl/voting_round_impl.cpp b/core/consensus/grandpa/impl/voting_round_impl.cpp index fe808fae71..a5c7de22cb 100644 --- a/core/consensus/grandpa/impl/voting_round_impl.cpp +++ b/core/consensus/grandpa/impl/voting_round_impl.cpp @@ -288,7 +288,7 @@ namespace kagome::consensus::grandpa { } BOOST_ASSERT(stage_ == Stage::PREVOTE_RUNS); - stage_timer_handle_.cancel(); + stage_timer_handle_.reset(); on_complete_handler_ = nullptr; stage_ = Stage::END_PREVOTE; @@ -356,7 +356,7 @@ namespace kagome::consensus::grandpa { BOOST_ASSERT(stage_ == Stage::PRECOMMIT_RUNS || stage_ == Stage::PRECOMMIT_WAITS_FOR_PREVOTES); - stage_timer_handle_.cancel(); + stage_timer_handle_.reset(); // https://github.com/paritytech/finality-grandpa/blob/8c45a664c05657f0c71057158d3ba555ba7d20de/src/voter/voting_round.rs#L630-L633 if (not prevote_ghost_) { @@ -438,7 +438,7 @@ namespace kagome::consensus::grandpa { } BOOST_ASSERT(stage_ == Stage::WAITING_RUNS); - stage_timer_handle_.cancel(); + stage_timer_handle_.reset(); on_complete_handler_ = nullptr; // Final attempt to finalize round what should be success @@ -452,8 +452,8 @@ namespace kagome::consensus::grandpa { if (stage_ != Stage::COMPLETED) { SL_DEBUG(logger_, "Round #{}: End round", round_number_); on_complete_handler_ = nullptr; - stage_timer_handle_.cancel(); - pending_timer_handle_.cancel(); + stage_timer_handle_.reset(); + pending_timer_handle_.reset(); stage_ = Stage::COMPLETED; } } diff --git a/core/dispute_coordinator/impl/dispute_coordinator_impl.cpp b/core/dispute_coordinator/impl/dispute_coordinator_impl.cpp index 7487f625be..4d46b77d19 100644 --- a/core/dispute_coordinator/impl/dispute_coordinator_impl.cpp +++ b/core/dispute_coordinator/impl/dispute_coordinator_impl.cpp @@ -2152,7 +2152,6 @@ namespace kagome::dispute { void DisputeCoordinatorImpl::process_portion_incoming_disputes() { if (rate_limit_timer_) { - rate_limit_timer_->cancel(); rate_limit_timer_.reset(); } diff --git a/core/host_api/impl/crypto_extension.cpp b/core/host_api/impl/crypto_extension.cpp index f167998707..7f37693a2b 100644 --- a/core/host_api/impl/crypto_extension.cpp +++ b/core/host_api/impl/crypto_extension.cpp @@ -65,7 +65,7 @@ namespace kagome::host_api { std::shared_ptr ed25519_provider, std::shared_ptr secp256k1_provider, std::shared_ptr hasher, - std::shared_ptr key_store) + std::optional> key_store) : memory_provider_(std::move(memory_provider)), sr25519_provider_(std::move(sr25519_provider)), ecdsa_provider_(std::move(ecdsa_provider)), @@ -81,7 +81,7 @@ namespace kagome::host_api { BOOST_ASSERT(secp256k1_provider_ != nullptr); BOOST_ASSERT(hasher_ != nullptr); BOOST_ASSERT(logger_ != nullptr); - BOOST_ASSERT(key_store_ != nullptr); + BOOST_ASSERT(key_store_ == std::nullopt || *key_store_ != nullptr); } // ---------------------- hashing ---------------------- @@ -182,7 +182,7 @@ namespace kagome::host_api { crypto::KeyType key_type = loadKeyType(key_type_ptr); checkIfKeyIsSupported(key_type, logger_); - auto public_keys = key_store_->ed25519().getPublicKeys(key_type); + auto public_keys = key_store_.value()->ed25519().getPublicKeys(key_type); if (not public_keys) { throw_with_error( logger_, "error loading public keys: {}", public_keys.error()); @@ -208,10 +208,10 @@ namespace kagome::host_api { outcome::result kp_res = [&] { if (seed_opt.has_value()) { - return key_store_->ed25519().generateKeypair(key_type, - seed_opt.value()); + return key_store_.value()->ed25519().generateKeypair(key_type, + seed_opt.value()); } else { - return key_store_->ed25519().generateKeypairOnDisk(key_type); + return key_store_.value()->ed25519().generateKeypairOnDisk(key_type); } }(); if (!kp_res) { @@ -241,7 +241,8 @@ namespace kagome::host_api { if (!pk) { BOOST_UNREACHABLE_RETURN({}); } - auto key_pair_opt = key_store_->ed25519().findKeypair(key_type, pk.value()); + auto key_pair_opt = + key_store_.value()->ed25519().findKeypair(key_type, pk.value()); if (!key_pair_opt) { logger_->error("failed to find required key"); auto error_result = scale::encode(ResultType(std::nullopt)).value(); @@ -309,7 +310,7 @@ namespace kagome::host_api { crypto::KeyType key_type = loadKeyType(key_type_ptr); checkIfKeyIsSupported(key_type, logger_); - auto public_keys = key_store_->sr25519().getPublicKeys(key_type); + auto public_keys = key_store_.value()->sr25519().getPublicKeys(key_type); if (not public_keys) { throw_with_error( logger_, "error loading public keys: {}", public_keys.error()); @@ -336,10 +337,10 @@ namespace kagome::host_api { outcome::result kp_res = [&]() { auto bip39_seed = seed_res.value(); if (bip39_seed.has_value()) { - return key_store_->sr25519().generateKeypair(key_type, - bip39_seed.value()); + return key_store_.value()->sr25519().generateKeypair( + key_type, bip39_seed.value()); } else { - return key_store_->sr25519().generateKeypairOnDisk(key_type); + return key_store_.value()->sr25519().generateKeypairOnDisk(key_type); } }(); if (!kp_res) { @@ -376,7 +377,8 @@ namespace kagome::host_api { // error is not possible, since we loaded correct number of bytes BOOST_UNREACHABLE_RETURN({}); } - auto key_pair = key_store_->sr25519().findKeypair(key_type, pk.value()); + auto key_pair = + key_store_.value()->sr25519().findKeypair(key_type, pk.value()); if (!key_pair) { logger_->error( "failed to find required key: {} {}", key_type, pk.value()); @@ -581,7 +583,7 @@ namespace kagome::host_api { crypto::KeyType key_type = loadKeyType(key_type_ptr); checkIfKeyIsSupported(key_type, logger_); - auto public_keys = key_store_->ecdsa().getPublicKeys(key_type); + auto public_keys = key_store_.value()->ecdsa().getPublicKeys(key_type); if (not public_keys) { throw_with_error( logger_, "error loading public keys: {}", public_keys.error()); @@ -608,7 +610,7 @@ namespace kagome::host_api { crypto::EcdsaPublicKey pk; std::copy(public_buffer.begin(), public_buffer.end(), pk.begin()); - auto key_pair = key_store_->ecdsa().findKeypair(key_type, pk); + auto key_pair = key_store_.value()->ecdsa().findKeypair(key_type, pk); if (!key_pair) { logger_->error("failed to find required key"); auto error_result = scale::encode(ResultType(std::nullopt)).value(); @@ -641,7 +643,7 @@ namespace kagome::host_api { crypto::EcdsaPublicKey pk; std::copy(public_buffer.begin(), public_buffer.end(), pk.begin()); - auto key_pair = key_store_->ecdsa().findKeypair(key_type, pk); + auto key_pair = key_store_.value()->ecdsa().findKeypair(key_type, pk); if (!key_pair) { logger_->error("failed to find required key"); auto error_result = scale::encode(ResultType(std::nullopt)).value(); @@ -677,10 +679,10 @@ namespace kagome::host_api { outcome::result kp_res = [&]() { auto bip39_seed = seed_res.value(); if (bip39_seed.has_value()) { - return key_store_->ecdsa().generateKeypair(key_type, - bip39_seed.value()); + return key_store_.value()->ecdsa().generateKeypair(key_type, + bip39_seed.value()); } else { - return key_store_->ecdsa().generateKeypairOnDisk(key_type); + return key_store_.value()->ecdsa().generateKeypairOnDisk(key_type); } }(); if (!kp_res) { diff --git a/core/host_api/impl/crypto_extension.hpp b/core/host_api/impl/crypto_extension.hpp index 620026eb09..4c6989390d 100644 --- a/core/host_api/impl/crypto_extension.hpp +++ b/core/host_api/impl/crypto_extension.hpp @@ -41,7 +41,7 @@ namespace kagome::host_api { std::shared_ptr ed25519_provider, std::shared_ptr secp256k1_provider, std::shared_ptr hasher, - std::shared_ptr key_store); + std::optional> key_store); void reset(); @@ -270,7 +270,8 @@ namespace kagome::host_api { std::shared_ptr ed25519_provider_; std::shared_ptr secp256k1_provider_; std::shared_ptr hasher_; - std::shared_ptr key_store_; + // not needed in PVF workers + std::optional> key_store_; log::Logger logger_; std::optional batch_verify_; }; diff --git a/core/host_api/impl/host_api_factory_impl.cpp b/core/host_api/impl/host_api_factory_impl.cpp index 77c7ef81e9..473bb74c38 100644 --- a/core/host_api/impl/host_api_factory_impl.cpp +++ b/core/host_api/impl/host_api_factory_impl.cpp @@ -27,14 +27,16 @@ namespace kagome::host_api { ed25519_provider_(std::move(ed25519_provider)), secp256k1_provider_(std::move(secp256k1_provider)), hasher_(std::move(hasher)), - key_store_(std::move(key_store)), + // we do this instead of passing key_store as an optional right away + // because boost.di doesn't like optional + key_store_(key_store ? std::optional(key_store) : std::nullopt), offchain_persistent_storage_(std::move(offchain_persistent_storage)), offchain_worker_pool_(std::move(offchain_worker_pool)) { BOOST_ASSERT(sr25519_provider_ != nullptr); BOOST_ASSERT(ed25519_provider_ != nullptr); BOOST_ASSERT(secp256k1_provider_ != nullptr); BOOST_ASSERT(hasher_ != nullptr); - BOOST_ASSERT(key_store_ != nullptr); + BOOST_ASSERT(key_store_ == std::nullopt || *key_store_ != nullptr); } std::unique_ptr HostApiFactoryImpl::make( diff --git a/core/host_api/impl/host_api_factory_impl.hpp b/core/host_api/impl/host_api_factory_impl.hpp index d5f7a5e580..71e8f85bc8 100644 --- a/core/host_api/impl/host_api_factory_impl.hpp +++ b/core/host_api/impl/host_api_factory_impl.hpp @@ -52,7 +52,7 @@ namespace kagome::host_api { std::shared_ptr ed25519_provider_; std::shared_ptr secp256k1_provider_; std::shared_ptr hasher_; - std::shared_ptr key_store_; + std::optional> key_store_; std::shared_ptr offchain_persistent_storage_; std::shared_ptr offchain_worker_pool_; diff --git a/core/host_api/impl/host_api_impl.cpp b/core/host_api/impl/host_api_impl.cpp index 0d64240e4d..dc20c453ca 100644 --- a/core/host_api/impl/host_api_impl.cpp +++ b/core/host_api/impl/host_api_impl.cpp @@ -29,7 +29,7 @@ namespace kagome::host_api { std::shared_ptr ed25519_provider, std::shared_ptr secp256k1_provider, std::shared_ptr hasher, - std::shared_ptr key_store, + std::optional> key_store, std::shared_ptr offchain_persistent_storage, std::shared_ptr offchain_worker_pool) diff --git a/core/host_api/impl/host_api_impl.hpp b/core/host_api/impl/host_api_impl.hpp index 018a8a285a..367b0b534f 100644 --- a/core/host_api/impl/host_api_impl.hpp +++ b/core/host_api/impl/host_api_impl.hpp @@ -43,7 +43,7 @@ namespace kagome::host_api { std::shared_ptr ed25519_provider, std::shared_ptr secp256k1_provider, std::shared_ptr hasher, - std::shared_ptr key_store, + std::optional> key_store, std::shared_ptr offchain_persistent_storage, std::shared_ptr offchain_worker_pool); diff --git a/core/network/impl/peer_manager_impl.cpp b/core/network/impl/peer_manager_impl.cpp index 8f40e3ac62..0b4cce42bc 100644 --- a/core/network/impl/peer_manager_impl.cpp +++ b/core/network/impl/peer_manager_impl.cpp @@ -308,7 +308,7 @@ namespace kagome::network { + app_config_.outPeers(); const auto peer_ttl = app_config_.peeringConfig().peerTtl; - align_timer_.cancel(); + align_timer_.reset(); clearClosedPingingConnections(); diff --git a/core/network/impl/reputation_repository_impl.cpp b/core/network/impl/reputation_repository_impl.cpp index 0deddf0896..8f5f847c17 100644 --- a/core/network/impl/reputation_repository_impl.cpp +++ b/core/network/impl/reputation_repository_impl.cpp @@ -29,8 +29,7 @@ namespace kagome::network { void ReputationRepositoryImpl::start() { main_thread_->execute([weak{weak_from_this()}] { if (auto self = weak.lock()) { - self->tick_handler_ = - self->scheduler_->scheduleWithHandle([self] { self->tick(); }, 1s); + self->tick(); } }); } @@ -137,7 +136,15 @@ namespace kagome::network { reputation_table_.erase(cit); } } - std::ignore = tick_handler_.reschedule(1s); + tick_handler_ = scheduler_->scheduleWithHandle( + [weak_self{weak_from_this()}] { + auto self = weak_self.lock(); + if (not self) { + return; + } + self->tick(); + }, + 1s); } } // namespace kagome::network diff --git a/core/telemetry/impl/service_impl.cpp b/core/telemetry/impl/service_impl.cpp index 4f7333a639..ba28d1302a 100644 --- a/core/telemetry/impl/service_impl.cpp +++ b/core/telemetry/impl/service_impl.cpp @@ -110,8 +110,8 @@ namespace kagome::telemetry { void TelemetryServiceImpl::stop() { shutdown_requested_ = true; - frequent_timer_.cancel(); - delayed_timer_.cancel(); + frequent_timer_.reset(); + delayed_timer_.reset(); for (auto &connection : connections_) { connection->shutdown(); } @@ -180,7 +180,7 @@ namespace kagome::telemetry { } void TelemetryServiceImpl::frequentNotificationsRoutine() { - frequent_timer_.cancel(); + frequent_timer_.reset(); if (shutdown_requested_) { return; } @@ -216,7 +216,7 @@ namespace kagome::telemetry { } void TelemetryServiceImpl::delayedNotificationsRoutine() { - delayed_timer_.cancel(); + delayed_timer_.reset(); if (shutdown_requested_) { return; } diff --git a/test/core/consensus/beefy_test.cpp b/test/core/consensus/beefy_test.cpp index 5c43561a14..9c0d83721a 100644 --- a/test/core/consensus/beefy_test.cpp +++ b/test/core/consensus/beefy_test.cpp @@ -71,9 +71,6 @@ using testing::_; using testing::Return; struct Timer : libp2p::basic::Scheduler { - void pulse(std::chrono::milliseconds current_clock) noexcept override { - abort(); - } std::chrono::milliseconds now() const noexcept override { abort(); } @@ -83,14 +80,6 @@ struct Timer : libp2p::basic::Scheduler { cb_.emplace(std::move(cb)); return Handle{}; } - void cancel(Handle::Ticket ticket) noexcept override { - abort(); - } - outcome::result reschedule( - Handle::Ticket ticket, - std::chrono::milliseconds delay_from_now) noexcept override { - abort(); - } void call() { if (cb_) { diff --git a/test/core/consensus/grandpa/voting_round/voting_round_test.cpp b/test/core/consensus/grandpa/voting_round/voting_round_test.cpp index c5f923166e..a6648755d0 100644 --- a/test/core/consensus/grandpa/voting_round/voting_round_test.cpp +++ b/test/core/consensus/grandpa/voting_round/voting_round_test.cpp @@ -147,8 +147,8 @@ class VotingRoundTest : public testing::Test, vote_graph_ = std::make_shared(base, config.voters, env_); scheduler_ = std::make_shared(); - EXPECT_CALL(*scheduler_, scheduleImplMockCall(_, _, _)).Times(AnyNumber()); - EXPECT_CALL(*scheduler_, nowMockCall()).Times(AnyNumber()); + EXPECT_CALL(*scheduler_, scheduleImpl(_, _, _)).Times(AnyNumber()); + EXPECT_CALL(*scheduler_, now()).Times(AnyNumber()); previous_round_ = std::make_shared(); ON_CALL(*previous_round_, lastFinalizedBlock()) diff --git a/test/core/consensus/timeline/timeline_test.cpp b/test/core/consensus/timeline/timeline_test.cpp index 7a17778813..43f3cfd8b2 100644 --- a/test/core/consensus/timeline/timeline_test.cpp +++ b/test/core/consensus/timeline/timeline_test.cpp @@ -259,7 +259,7 @@ TEST_F(TimelineTest, SingleValidator) { .WillRepeatedly(Return(ValidatorStatus::SingleValidator)); EXPECT_CALL(*production_consensus, processSlot(_, best_block)).Times(0); // - start to wait for end of current slot - EXPECT_CALL(*scheduler, scheduleImplMockCall(_, _, false)) + EXPECT_CALL(*scheduler, scheduleImpl(_, _, false)) .WillOnce(WithArg<0>(Invoke([&](auto cb) { on_run_slot = std::move(cb); return SchedulerMock::Handle{}; @@ -285,7 +285,7 @@ TEST_F(TimelineTest, SingleValidator) { EXPECT_CALL(*production_consensus, processSlot(current_slot, best_block)) .WillOnce(Return(outcome::success())); // - start to wait for end of current slot - EXPECT_CALL(*scheduler, scheduleImplMockCall(_, _, false)) + EXPECT_CALL(*scheduler, scheduleImpl(_, _, false)) .WillOnce(WithArg<0>( Invoke([&](auto cb) { return SchedulerMock::Handle{}; }))); @@ -324,7 +324,7 @@ TEST_F(TimelineTest, Validator) { // - don't process slot, because node is not synchronized EXPECT_CALL(*production_consensus, processSlot(_, best_block)).Times(0); // - don't wait time to run slot, because node is not synchronized - EXPECT_CALL(*scheduler, scheduleImplMockCall(_, _, _)).Times(0); + EXPECT_CALL(*scheduler, scheduleImpl(_, _, _)).Times(0); timeline->start(); @@ -349,7 +349,7 @@ TEST_F(TimelineTest, Validator) { // - process slot won't start, because slot is not changed EXPECT_CALL(*production_consensus, processSlot(_, _)).Times(0); // - start to wait for end of current slot - EXPECT_CALL(*scheduler, scheduleImplMockCall(_, _, false)) + EXPECT_CALL(*scheduler, scheduleImpl(_, _, false)) .WillOnce(WithArg<0>(Invoke([&](auto cb) { on_run_slot_2 = std::move(cb); return SchedulerMock::Handle{}; @@ -380,7 +380,7 @@ TEST_F(TimelineTest, Validator) { EXPECT_CALL(*production_consensus, processSlot(current_slot, best_block)) .WillOnce(Return(SlotLeadershipError::NO_SLOT_LEADER)); // - start to wait for end of current slot - EXPECT_CALL(*scheduler, scheduleImplMockCall(_, _, false)) + EXPECT_CALL(*scheduler, scheduleImpl(_, _, false)) .WillOnce(WithArg<0>(Invoke([&](auto cb) { on_run_slot_3 = std::move(cb); return SchedulerMock::Handle{}; @@ -406,7 +406,7 @@ TEST_F(TimelineTest, Validator) { EXPECT_CALL(*production_consensus, processSlot(current_slot, best_block)) .WillOnce(Return(outcome::success())); // - start to wait for end of current slot - EXPECT_CALL(*scheduler, scheduleImplMockCall(_, _, false)) + EXPECT_CALL(*scheduler, scheduleImpl(_, _, false)) .WillOnce(WithArg<0>(Invoke([&](auto cb) { on_run_slot_3 = std::move(cb); return SchedulerMock::Handle{}; diff --git a/test/core/network/synchronizer_test.cpp b/test/core/network/synchronizer_test.cpp index 47621a1c06..0d4b44428f 100644 --- a/test/core/network/synchronizer_test.cpp +++ b/test/core/network/synchronizer_test.cpp @@ -80,7 +80,7 @@ class SynchronizerTest EXPECT_CALL(*router, getSyncProtocol()) .WillRepeatedly(Return(sync_protocol)); - EXPECT_CALL(*scheduler, scheduleImplMockCall(_, _, _)).Times(AnyNumber()); + EXPECT_CALL(*scheduler, scheduleImpl(_, _, _)).Times(AnyNumber()); EXPECT_CALL(app_config, syncMethod()) .WillOnce(Return(application::SyncMethod::Full)); diff --git a/test/core/runtime/wavm/wavm_module_init_test.cpp b/test/core/runtime/wavm/wavm_module_init_test.cpp index ed6773d752..53232982b8 100644 --- a/test/core/runtime/wavm/wavm_module_init_test.cpp +++ b/test/core/runtime/wavm/wavm_module_init_test.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include #include #include @@ -12,20 +13,20 @@ #include "blockchain/impl/block_header_repository_impl.hpp" //header_repo #include "crypto/bip39/impl/bip39_provider_impl.hpp" //bip39_provider -#include "crypto/crypto_store/crypto_store_impl.hpp" //crypto_store #include "crypto/ecdsa/ecdsa_provider_impl.hpp" //ecdsa_provider #include "crypto/ed25519/ed25519_provider_impl.hpp" //ed25519_provider #include "crypto/hasher/hasher_impl.hpp" //hasher +#include "crypto/key_store/key_store_impl.hpp" //crypto_store #include "crypto/pbkdf2/impl/pbkdf2_provider_impl.hpp" //pbkdf2_provider #include "crypto/secp256k1/secp256k1_provider_impl.hpp" //secp256k1_provider #include "crypto/sr25519/sr25519_provider_impl.hpp" //sr25519_provider #include "host_api/impl/host_api_factory_impl.hpp" // host_api_factory +#include "mock/core/application/app_state_manager_mock.hpp" #include "offchain/impl/offchain_persistent_storage.hpp" //offchain_persistent_store #include "offchain/impl/offchain_worker_pool_impl.hpp" //offchain_worker_pool #include "runtime/common/runtime_properties_cache_impl.hpp" // cache #include "runtime/executor.hpp" #include "runtime/memory_provider.hpp" -#include "runtime/module.hpp" // smc #include "runtime/runtime_context.hpp" #include "runtime/wavm/compartment_wrapper.hpp" // compartment #include "runtime/wavm/instance_environment_factory.hpp" // instance_env_factory @@ -53,6 +54,9 @@ class WavmModuleInitTest : public ::testing::TestWithParam { } void SetUp() override { + std::filesystem::path base_path{std::filesystem::temp_directory_path() + / "wasm_module_init_test"}; + auto compartment = std::make_shared( "WAVM Compartment"); @@ -79,39 +83,42 @@ class WavmModuleInitTest : public ::testing::TestWithParam { std::make_shared( compartment, module_params->intrinsicMemoryType); - auto hasher = std::make_shared(); - auto sr25519_provider = - std::make_shared(); - auto ecdsa_provider = - std::make_shared(hasher); - auto ed25519_provider = - std::make_shared(hasher); - auto secp256k1_provider = - std::make_shared(); - auto pbkdf2_provider = - std::make_shared(); - auto bip39_provider = std::make_shared( - pbkdf2_provider, hasher); - auto ecdsa_suite = - std::make_shared(ecdsa_provider); - auto ed_suite = - std::make_shared(ed25519_provider); - auto sr_suite = - std::make_shared(sr25519_provider); - std::shared_ptr key_fs = - kagome::crypto::KeyFileStorage::createAt( - "/tmp/kagome_vawm_tmp_key_storage") - .value(); + using namespace kagome::crypto; + auto hasher = std::make_shared(); auto csprng = std::make_shared(); - auto crypto_store = std::make_shared( - ecdsa_suite, ed_suite, sr_suite, bip39_provider, csprng, key_fs); + auto ecdsa_provider = std::make_shared(hasher); + auto ed25519_provider = std::make_shared(hasher); + auto sr25519_provider = std::make_shared(); + + auto secp256k1_provider = std::make_shared(); + auto pbkdf2_provider = std::make_shared(); + auto bip39_provider = + std::make_shared(std::move(pbkdf2_provider), hasher); + std::shared_ptr key_file_storage = + kagome::crypto::KeyFileStorage::createAt(base_path).value(); + KeyStore::Config config{base_path}; + auto key_store = std::make_shared( + std::make_unique>( + std::move(sr25519_provider), + bip39_provider, + csprng, + key_file_storage), + std::make_unique>( + ed25519_provider, bip39_provider, csprng, key_file_storage), + std::make_unique>( + std::move(ecdsa_provider), + bip39_provider, + csprng, + key_file_storage), + ed25519_provider, + std::make_shared(), + config); rocksdb::Options db_options{}; db_options.create_if_missing = true; std::shared_ptr database = - kagome::storage::RocksDb::create("/tmp/kagome_tmp_db", db_options) - .value(); + kagome::storage::RocksDb::create(base_path / "db", db_options).value(); auto header_repo = std::make_shared( @@ -130,7 +137,7 @@ class WavmModuleInitTest : public ::testing::TestWithParam { ed25519_provider, secp256k1_provider, hasher, - crypto_store, + key_store, offchain_persistent_storage, offchain_worker_pool); @@ -145,7 +152,6 @@ class WavmModuleInitTest : public ::testing::TestWithParam { trie_storage, serializer, intrinsic_module, - smc, std::nullopt, hasher); @@ -164,9 +170,9 @@ TEST_P(WavmModuleInitTest, DISABLED_SingleModule) { auto code_provider = std::make_shared( std::string(kBasePath) + std::string(wasm)); EXPECT_OUTCOME_TRUE(code, code_provider->getCodeAt({})); - EXPECT_OUTCOME_TRUE( - runtime_context, - kagome::runtime::RuntimeContextFactory::fromCode(*module_factory_, code)); + EXPECT_OUTCOME_TRUE(runtime_context, + kagome::runtime::RuntimeContextFactory::fromCode( + *module_factory_, *code, {})); EXPECT_OUTCOME_TRUE(response, runtime_context.module_instance->callExportFunction( runtime_context, "Core_version", {}));