Skip to content

Commit

Permalink
Feature: disabled validators (runtime API) (#2006)
Browse files Browse the repository at this point in the history
* feature: disabled validators

Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>

* fix: missed method doesn't cause error

Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>

* fix: broken mock object

Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>

---------

Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
  • Loading branch information
xDimon authored Mar 21, 2024
1 parent 982153e commit ffc47cf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/runtime/runtime_api/impl/parachain_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "runtime/runtime_api/impl/parachain_host.hpp"

#include "common/blob.hpp"
#include "runtime/common/runtime_execution_error.hpp"
#include "runtime/executor.hpp"
#include "runtime/runtime_api/impl/parachain_host_types_serde.hpp"
#include "scale/std_variant.hpp"
Expand Down Expand Up @@ -224,6 +225,7 @@ namespace kagome::runtime {
session_info_.erase(blocks);
dmq_contents_.erase(blocks);
inbound_hrmp_channels_contents_.erase(blocks);
disabled_validators_.erase(blocks);
}

outcome::result<std::optional<std::vector<ExecutorParam>>>
Expand Down Expand Up @@ -291,4 +293,16 @@ namespace kagome::runtime {
"ParachainHost_minimum_backing_votes");
}

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;
}

} // namespace kagome::runtime
4 changes: 4 additions & 0 deletions core/runtime/runtime_api/impl/parachain_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ namespace kagome::runtime {
outcome::result<uint32_t> minimum_backing_votes(
const primitives::BlockHash &block, SessionIndex index) override;

outcome::result<std::vector<ValidatorIndex>> disabled_validators(
const primitives::BlockHash &block) override;

private:
bool prepare();
void clearCaches(const std::vector<primitives::BlockHash> &blocks);
Expand Down Expand Up @@ -146,6 +149,7 @@ namespace kagome::runtime {
ParachainId,
std::map<ParachainId, std::vector<InboundHrmpMessage>>>
inbound_hrmp_channels_contents_{10};
RuntimeApiLruBlock<std::vector<ValidatorIndex>> disabled_validators_{10};
};

} // namespace kagome::runtime
4 changes: 4 additions & 0 deletions core/runtime/runtime_api/parachain_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ namespace kagome::runtime {

virtual outcome::result<uint32_t> minimum_backing_votes(
const primitives::BlockHash &block, SessionIndex index) = 0;

/// Returns a list of all disabled validators at the given block.
virtual outcome::result<std::vector<ValidatorIndex>> disabled_validators(
const primitives::BlockHash &block) = 0;
};

} // namespace kagome::runtime
5 changes: 5 additions & 0 deletions test/mock/core/runtime/parachain_host_mock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ namespace kagome::runtime {
minimum_backing_votes,
(const primitives::BlockHash &, SessionIndex),
(override));

MOCK_METHOD(outcome::result<std::vector<ValidatorIndex>>,
disabled_validators,
(const primitives::BlockHash &),
(override));
};

} // namespace kagome::runtime

0 comments on commit ffc47cf

Please sign in to comment.