Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into refactor/notifications
Browse files Browse the repository at this point in the history
Signed-off-by: turuslan <[email protected]>

# Conflicts:
#	core/parachain/validator/impl/parachain_processor.cpp
#	core/parachain/validator/parachain_processor.hpp
  • Loading branch information
turuslan committed Nov 14, 2024
2 parents 15fb5c0 + f42743c commit 192b29d
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 148 deletions.
10 changes: 2 additions & 8 deletions core/consensus/babe/impl/babe_block_validator_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,8 @@ namespace kagome::consensus::babe {
// If we were synchronized,
// we have available runtime to check disabled validators
if (was_synchronized_) {
std::vector<AuthorityIndex> disabled_validators;
if (auto res = babe_api_->disabled_validators(block_header.parent_hash);
res.has_error()) {
SL_CRITICAL(log_,
"Can't obtain disabled validators list for block {}",
block_header.blockInfo());
}

OUTCOME_TRY(disabled_validators,
babe_api_->disabled_validators(block_header.parent_hash));
if (std::ranges::binary_search(disabled_validators,
babe_header.authority_index)) {
SL_VERBOSE(log_,
Expand Down
2 changes: 0 additions & 2 deletions core/parachain/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ namespace kagome::parachain {
/// Signature with which parachain validators sign blocks.
using ValidatorSignature = Signature;

constexpr uint32_t CLAIM_QUEUE_RUNTIME_REQUIREMENT = 11;

template <typename D>
struct Indexed {
using Type = std::decay_t<D>;
Expand Down
14 changes: 0 additions & 14 deletions core/parachain/validator/impl/parachain_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,20 +416,6 @@ namespace kagome::parachain {
return outcome::success();
}

outcome::result<std::optional<runtime::ClaimQueueSnapshot>>
ParachainProcessorImpl::fetch_claim_queue(const RelayHash &relay_parent) {
OUTCOME_TRY(version, parachain_host_->runtime_api_version(relay_parent));
if (version < CLAIM_QUEUE_RUNTIME_REQUIREMENT) {
SL_TRACE(logger_, "Runtime doesn't support `request_claim_queue`");
return std::nullopt;
}

OUTCOME_TRY(claims, parachain_host_->claim_queue(relay_parent));
return runtime::ClaimQueueSnapshot{
.claimes = std::move(claims),
};
}

outcome::result<consensus::Randomness>
ParachainProcessorImpl::getBabeRandomness(const RelayHash &relay_parent) {
OUTCOME_TRY(block_header, block_tree_->getBlockHeader(relay_parent));
Expand Down
2 changes: 0 additions & 2 deletions core/parachain/validator/parachain_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,6 @@ namespace kagome::parachain {

outcome::result<consensus::Randomness> getBabeRandomness(
const RelayHash &relay_parent);
outcome::result<std::optional<runtime::ClaimQueueSnapshot>>
fetch_claim_queue(const RelayHash &relay_parent);

/**
* @brief Inserts an advertisement into the peer's data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,25 +281,11 @@ namespace kagome::parachain {
return std::nullopt;
}

outcome::result<std::optional<runtime::ClaimQueueSnapshot>>
ProspectiveParachains::fetch_claim_queue(const RelayHash &relay_parent) {
OUTCOME_TRY(version, parachain_host_->runtime_api_version(relay_parent));
if (version < CLAIM_QUEUE_RUNTIME_REQUIREMENT) {
SL_TRACE(logger, "Runtime doesn't support `request_claim_queue`");
return std::nullopt;
}

OUTCOME_TRY(claims, parachain_host_->claim_queue(relay_parent));
return runtime::ClaimQueueSnapshot{
.claimes = std::move(claims),
};
}

outcome::result<std::unordered_set<ParachainId>>
ProspectiveParachains::fetchUpcomingParas(
const RelayHash &relay_parent,
std::unordered_set<CandidateHash> &pending_availability) {
OUTCOME_TRY(claim, fetch_claim_queue(relay_parent));
OUTCOME_TRY(claim, parachain_host_->claim_queue(relay_parent));
if (claim) {
std::unordered_set<ParachainId> result;
for (const auto &[_, paras] : claim->claimes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ namespace kagome::parachain {
const RelayHash &relay_parent,
std::unordered_set<CandidateHash> &pending_availability);

outcome::result<std::optional<runtime::ClaimQueueSnapshot>>
fetch_claim_queue(const RelayHash &relay_parent);

outcome::result<std::vector<fragment::BlockInfoProspectiveParachains>>
fetchAncestry(const RelayHash &relay_hash, size_t ancestors);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,11 @@ namespace kagome::parachain::statement_distribution {
std::move(authority_lookup)));
});
if (per_session_state.has_error()) {
SL_WARN(logger,
"Create session data failed. (error={})",
per_session_state.error());
if (per_session_state.error() != Error::NOT_A_VALIDATOR) {
SL_WARN(logger,
"Create session data failed. (error={})",
per_session_state.error());
}
continue;
}

Expand All @@ -424,14 +426,7 @@ namespace kagome::parachain::statement_distribution {
OUTCOME_TRY(groups, parachain_host->validator_groups(new_relay_parent));
const auto &[_, group_rotation_info] = groups;

auto maybe_claim_queue =
[&]() -> std::optional<runtime::ClaimQueueSnapshot> {
auto r = fetch_claim_queue(new_relay_parent);
if (r.has_value()) {
return r.value();
}
return std::nullopt;
}();
OUTCOME_TRY(maybe_claim_queue, parachain_host->claim_queue(relay_parent));

auto local_validator = [&]() -> std::optional<LocalValidatorState> {
if (!per_session_state.value()->value().v_index) {
Expand Down Expand Up @@ -576,22 +571,6 @@ namespace kagome::parachain::statement_distribution {
return groups_per_para;
}

outcome::result<std::optional<runtime::ClaimQueueSnapshot>>
StatementDistribution::fetch_claim_queue(const RelayHash &relay_parent) {
// constexpr uint32_t CLAIM_QUEUE_RUNTIME_REQUIREMENT = 11;
// OUTCOME_TRY(version,
// parachain_host->runtime_api_version(relay_parent)); if (version <
// CLAIM_QUEUE_RUNTIME_REQUIREMENT) {
// SL_TRACE(logger, "Runtime doesn't support `request_claim_queue`");
// return std::nullopt;
// }

OUTCOME_TRY(claims, parachain_host->claim_queue(relay_parent));
return runtime::ClaimQueueSnapshot{
.claimes = std::move(claims),
};
}

bool StatementDistribution::can_disconnect(const libp2p::PeerId &peer) const {
auto audi = query_audi->get(peer);
if (not audi) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,6 @@ namespace kagome::parachain::statement_distribution {
outcome::result<std::optional<ValidatorSigner>> is_parachain_validator(
const primitives::BlockHash &relay_parent) const;

outcome::result<std::optional<runtime::ClaimQueueSnapshot>>
fetch_claim_queue(const RelayHash &relay_parent);

std::unordered_map<ParachainId, std::vector<GroupIndex>>
determine_groups_per_para(
const std::vector<runtime::CoreState> &availability_cores,
Expand Down
10 changes: 3 additions & 7 deletions core/runtime/runtime_api/impl/babe_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "runtime/common/runtime_execution_error.hpp"
#include "runtime/executor.hpp"
#include "runtime/runtime_api/impl/if_export.hpp"

namespace kagome::runtime {

Expand Down Expand Up @@ -56,12 +57,7 @@ namespace kagome::runtime {
outcome::result<std::vector<consensus::AuthorityIndex>>
BabeApiImpl::disabled_validators(const primitives::BlockHash &block) {
OUTCOME_TRY(ctx, executor_->ctx().ephemeralAt(block));
auto res = executor_->call<std::vector<consensus::AuthorityIndex>>(
ctx, "ParachainHost_disabled_validators");
if (res.has_error()
and res.error() == RuntimeExecutionError::EXPORT_FUNCTION_NOT_FOUND) {
return std::vector<consensus::AuthorityIndex>{};
}
return res;
return ifExportVec(executor_->call<std::vector<consensus::AuthorityIndex>>(
ctx, "ParachainHost_disabled_validators"));
}
} // namespace kagome::runtime
15 changes: 6 additions & 9 deletions core/runtime/runtime_api/impl/beefy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "runtime/common/runtime_execution_error.hpp"
#include "runtime/executor.hpp"
#include "runtime/runtime_api/impl/if_export.hpp"

namespace kagome::runtime {
BeefyApiImpl::BeefyApiImpl(std::shared_ptr<Executor> executor)
Expand All @@ -18,15 +19,11 @@ namespace kagome::runtime {
outcome::result<std::optional<primitives::BlockNumber>> BeefyApiImpl::genesis(
const primitives::BlockHash &block) {
OUTCOME_TRY(ctx, executor_->ctx().ephemeralAt(block));
auto r = executor_->call<std::optional<primitives::BlockNumber>>(
ctx, "BeefyApi_beefy_genesis");
if (r) {
return r.value();
}
if (r.error() == RuntimeExecutionError::EXPORT_FUNCTION_NOT_FOUND) {
return std::nullopt;
}
return r.error();
OUTCOME_TRY(
r,
ifExport(executor_->call<std::optional<primitives::BlockNumber>>(
ctx, "BeefyApi_beefy_genesis")));
return r.value_or(std::nullopt);
}

outcome::result<std::optional<consensus::beefy::ValidatorSet>>
Expand Down
37 changes: 37 additions & 0 deletions core/runtime/runtime_api/impl/if_export.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <optional>
#include <vector>

#include "runtime/common/runtime_execution_error.hpp"

namespace kagome::runtime {
template <typename T>
outcome::result<std::optional<T>> ifExport(outcome::result<T> &&r) {
if (r) {
return std::move(r.value());
}
if (r.error() == RuntimeExecutionError::EXPORT_FUNCTION_NOT_FOUND) {
return std::nullopt;
}
return r.error();
}

template <typename T>
outcome::result<std::vector<T>> ifExportVec(
outcome::result<std::vector<T>> &&r) {
if (r) {
return std::move(r.value());
}
if (r.error() == RuntimeExecutionError::EXPORT_FUNCTION_NOT_FOUND) {
return std::vector<T>{};
}
return r.error();
}
} // namespace kagome::runtime
31 changes: 8 additions & 23 deletions core/runtime/runtime_api/impl/parachain_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "common/blob.hpp"
#include "runtime/common/runtime_execution_error.hpp"
#include "runtime/executor.hpp"
#include "runtime/runtime_api/impl/if_export.hpp"
#include "runtime/runtime_api/impl/parachain_host_types_serde.hpp"
#include "scale/std_variant.hpp"

Expand Down Expand Up @@ -270,17 +271,11 @@ namespace kagome::runtime {
ctx, "ParachainHost_para_backing_state", id);
}

outcome::result<std::map<CoreIndex, std::vector<ParachainId>>>
ParachainHostImpl::claim_queue(const primitives::BlockHash &block) {
OUTCOME_TRY(ctx, executor_->ctx().ephemeralAt(block));
return executor_->call<std::map<CoreIndex, std::vector<ParachainId>>>(
ctx, "ParachainHost_claim_queue");
}

outcome::result<uint32_t> ParachainHostImpl::runtime_api_version(
ParachainHost::ClaimQueueResult ParachainHostImpl::claim_queue(
const primitives::BlockHash &block) {
OUTCOME_TRY(ctx, executor_->ctx().ephemeralAt(block));
return executor_->call<uint32_t>(ctx, "ParachainHost_runtime_api_version");
return ifExport(
executor_->call<ClaimQueueSnapshot>(ctx, "ParachainHost_claim_queue"));
}

outcome::result<parachain::fragment::AsyncBackingParams>
Expand All @@ -301,26 +296,16 @@ namespace kagome::runtime {
outcome::result<std::vector<ValidatorIndex>>
ParachainHostImpl::disabled_validators(const primitives::BlockHash &block) {
OUTCOME_TRY(ctx, executor_->ctx().ephemeralAt(block));
auto res = executor_->call<std::vector<ValidatorIndex>>(
ctx, "ParachainHost_disabled_validators");
if (res.has_error()
and res.error() == RuntimeExecutionError::EXPORT_FUNCTION_NOT_FOUND) {
return outcome::success(std::vector<ValidatorIndex>{});
}
return res;
return ifExportVec(executor_->call<std::vector<ValidatorIndex>>(
ctx, "ParachainHost_disabled_validators"));
}

outcome::result<std::optional<ParachainHost::NodeFeatures>>
ParachainHostImpl::node_features(const primitives::BlockHash &block,
SessionIndex index) {
OUTCOME_TRY(ctx, executor_->ctx().ephemeralAt(block));
auto res = executor_->call<ParachainHost::NodeFeatures>(
ctx, "ParachainHost_node_features");
if (res.has_error()
and res.error() == RuntimeExecutionError::EXPORT_FUNCTION_NOT_FOUND) {
return outcome::success(std::nullopt);
}
return res.value();
return ifExport(executor_->call<ParachainHost::NodeFeatures>(
ctx, "ParachainHost_node_features"));
}

} // namespace kagome::runtime
6 changes: 1 addition & 5 deletions core/runtime/runtime_api/impl/parachain_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,7 @@ namespace kagome::runtime {
outcome::result<std::optional<NodeFeatures>> node_features(
const primitives::BlockHash &block, SessionIndex index) override;

outcome::result<std::map<CoreIndex, std::vector<ParachainId>>> claim_queue(
const primitives::BlockHash &block) override;

outcome::result<uint32_t> runtime_api_version(
const primitives::BlockHash &block) override;
ClaimQueueResult claim_queue(const primitives::BlockHash &block) override;

private:
bool prepare();
Expand Down
6 changes: 2 additions & 4 deletions core/runtime/runtime_api/parachain_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,8 @@ namespace kagome::runtime {
virtual outcome::result<std::optional<NodeFeatures>> node_features(
const primitives::BlockHash &block, SessionIndex index) = 0;

virtual outcome::result<std::map<CoreIndex, std::vector<ParachainId>>>
claim_queue(const primitives::BlockHash &block) = 0;

virtual outcome::result<uint32_t> runtime_api_version(
using ClaimQueueResult = outcome::result<std::optional<ClaimQueueSnapshot>>;
virtual ClaimQueueResult claim_queue(
const primitives::BlockHash &block) = 0;
};

Expand Down
Loading

0 comments on commit 192b29d

Please sign in to comment.