Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into ci/builds_testing
Browse files Browse the repository at this point in the history
  • Loading branch information
qdrvm-ci committed Apr 23, 2024
2 parents 8f0c27f + 4fc15ff commit e74ebbb
Show file tree
Hide file tree
Showing 20 changed files with 127 additions and 117 deletions.
2 changes: 1 addition & 1 deletion cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ hunter_config(

hunter_config(
libp2p
VERSION 0.1.19
VERSION 0.1.20
KEEP_PACKAGE_SOURCES
)

Expand Down
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.25.3-qdrvm7.zip
SHA1 be5869134ef7448fe2420d60dbb9706596b1b8bd
URL https://github.com/qdrvm/hunter/archive/refs/tags/v0.25.3-qdrvm8.zip
SHA1 dc0af42b358dc0bcab304a455e80681c12d52e0f
LOCAL
)
44 changes: 23 additions & 21 deletions core/consensus/grandpa/impl/grandpa_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<VotingRoundImpl>(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_);

Expand All @@ -206,7 +189,7 @@ namespace kagome::consensus::grandpa {
}

void GrandpaImpl::stop() {
fallback_timer_handle_.cancel();
fallback_timer_handle_.reset();
}

std::shared_ptr<VotingRound> GrandpaImpl::makeInitialRound(
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
});
Expand Down Expand Up @@ -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<VotingRoundImpl>(self->current_round_);
if (round) {
round->sendNeighborMessage();
}
self->setTimerFallback();
},
std::chrono::minutes(1));
}
} // namespace kagome::consensus::grandpa
2 changes: 2 additions & 0 deletions core/consensus/grandpa/impl/grandpa_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions core/consensus/grandpa/impl/voting_round_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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_) {
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
}
Expand Down
1 change: 0 additions & 1 deletion core/dispute_coordinator/impl/dispute_coordinator_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
38 changes: 20 additions & 18 deletions core/host_api/impl/crypto_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace kagome::host_api {
std::shared_ptr<const crypto::Ed25519Provider> ed25519_provider,
std::shared_ptr<const crypto::Secp256k1Provider> secp256k1_provider,
std::shared_ptr<const crypto::Hasher> hasher,
std::shared_ptr<crypto::KeyStore> key_store)
std::optional<std::shared_ptr<crypto::KeyStore>> key_store)
: memory_provider_(std::move(memory_provider)),
sr25519_provider_(std::move(sr25519_provider)),
ecdsa_provider_(std::move(ecdsa_provider)),
Expand All @@ -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 ----------------------
Expand Down Expand Up @@ -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());
Expand All @@ -208,10 +208,10 @@ namespace kagome::host_api {

outcome::result<crypto::Ed25519Keypair> 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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand All @@ -336,10 +337,10 @@ namespace kagome::host_api {
outcome::result<crypto::Sr25519Keypair> 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) {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -677,10 +679,10 @@ namespace kagome::host_api {
outcome::result<crypto::EcdsaKeypair> 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) {
Expand Down
5 changes: 3 additions & 2 deletions core/host_api/impl/crypto_extension.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace kagome::host_api {
std::shared_ptr<const crypto::Ed25519Provider> ed25519_provider,
std::shared_ptr<const crypto::Secp256k1Provider> secp256k1_provider,
std::shared_ptr<const crypto::Hasher> hasher,
std::shared_ptr<crypto::KeyStore> key_store);
std::optional<std::shared_ptr<crypto::KeyStore>> key_store);

void reset();

Expand Down Expand Up @@ -270,7 +270,8 @@ namespace kagome::host_api {
std::shared_ptr<const crypto::Ed25519Provider> ed25519_provider_;
std::shared_ptr<const crypto::Secp256k1Provider> secp256k1_provider_;
std::shared_ptr<const crypto::Hasher> hasher_;
std::shared_ptr<crypto::KeyStore> key_store_;
// not needed in PVF workers
std::optional<std::shared_ptr<crypto::KeyStore>> key_store_;
log::Logger logger_;
std::optional<runtime::WasmSize> batch_verify_;
};
Expand Down
6 changes: 4 additions & 2 deletions core/host_api/impl/host_api_factory_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<shared_ptr>
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<HostApi> HostApiFactoryImpl::make(
Expand Down
2 changes: 1 addition & 1 deletion core/host_api/impl/host_api_factory_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace kagome::host_api {
std::shared_ptr<crypto::Ed25519Provider> ed25519_provider_;
std::shared_ptr<crypto::Secp256k1Provider> secp256k1_provider_;
std::shared_ptr<crypto::Hasher> hasher_;
std::shared_ptr<crypto::KeyStore> key_store_;
std::optional<std::shared_ptr<crypto::KeyStore>> key_store_;
std::shared_ptr<offchain::OffchainPersistentStorage>
offchain_persistent_storage_;
std::shared_ptr<offchain::OffchainWorkerPool> offchain_worker_pool_;
Expand Down
2 changes: 1 addition & 1 deletion core/host_api/impl/host_api_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace kagome::host_api {
std::shared_ptr<const crypto::Ed25519Provider> ed25519_provider,
std::shared_ptr<const crypto::Secp256k1Provider> secp256k1_provider,
std::shared_ptr<const crypto::Hasher> hasher,
std::shared_ptr<crypto::KeyStore> key_store,
std::optional<std::shared_ptr<crypto::KeyStore>> key_store,
std::shared_ptr<offchain::OffchainPersistentStorage>
offchain_persistent_storage,
std::shared_ptr<offchain::OffchainWorkerPool> offchain_worker_pool)
Expand Down
2 changes: 1 addition & 1 deletion core/host_api/impl/host_api_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace kagome::host_api {
std::shared_ptr<const crypto::Ed25519Provider> ed25519_provider,
std::shared_ptr<const crypto::Secp256k1Provider> secp256k1_provider,
std::shared_ptr<const crypto::Hasher> hasher,
std::shared_ptr<crypto::KeyStore> key_store,
std::optional<std::shared_ptr<crypto::KeyStore>> key_store,
std::shared_ptr<offchain::OffchainPersistentStorage>
offchain_persistent_storage,
std::shared_ptr<offchain::OffchainWorkerPool> offchain_worker_pool);
Expand Down
2 changes: 1 addition & 1 deletion core/network/impl/peer_manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
13 changes: 10 additions & 3 deletions core/network/impl/reputation_repository_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
}
Expand Down Expand Up @@ -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
Loading

0 comments on commit e74ebbb

Please sign in to comment.