Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beefy report double voting #2169

Merged
merged 8 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/consensus/beefy/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,10 @@ namespace kagome::consensus::beefy {
using BeefyJustification = boost::variant<Unused<0>, SignedCommitment>;

using BeefyGossipMessage = boost::variant<VoteMessage, BeefyJustification>;

struct DoubleVotingProof {
SCALE_TIE(2);

VoteMessage first, second;
};
} // namespace kagome::consensus::beefy
13 changes: 13 additions & 0 deletions core/primitives/opaque_key_ownership_proof.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include "common/buffer.hpp"

namespace kagome::primitives {
using OpaqueKeyOwnershipProof = Buffer;
} // namespace kagome::primitives
19 changes: 19 additions & 0 deletions core/runtime/runtime_api/beefy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#pragma once

#include "consensus/beefy/types.hpp"
#include "primitives/opaque_key_ownership_proof.hpp"

namespace kagome::runtime {
class BeefyApi {
Expand All @@ -24,5 +25,23 @@ namespace kagome::runtime {
*/
virtual outcome::result<std::optional<consensus::beefy::ValidatorSet>>
validatorSet(const primitives::BlockHash &block) = 0;

/**
* Report equivocation.
*/
virtual outcome::result<void>
submit_report_double_voting_unsigned_extrinsic(
const primitives::BlockHash &block,
const consensus::beefy::DoubleVotingProof &equivocation_proof,
const primitives::OpaqueKeyOwnershipProof &key_owner_proof) const = 0;

/**
* Generate key ownership proof.
*/
virtual outcome::result<std::optional<primitives::OpaqueKeyOwnershipProof>>
generate_key_ownership_proof(
const primitives::BlockHash &block,
consensus::beefy::AuthoritySetId set_id,
const crypto::EcdsaPublicKey &authority_id) const = 0;
};
} // namespace kagome::runtime
23 changes: 23 additions & 0 deletions core/runtime/runtime_api/impl/beefy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,27 @@ namespace kagome::runtime {
return executor_->call<std::optional<consensus::beefy::ValidatorSet>>(
ctx, "BeefyApi_validator_set");
}

outcome::result<void>
BeefyApiImpl::submit_report_double_voting_unsigned_extrinsic(
const primitives::BlockHash &block,
const consensus::beefy::DoubleVotingProof &equivocation_proof,
const primitives::OpaqueKeyOwnershipProof &key_owner_proof) const {
OUTCOME_TRY(ctx, executor_->ctx().ephemeralAt(block));
return executor_->call<void>(
ctx,
"BeefyApi_submit_report_double_voting_unsigned_extrinsic",
equivocation_proof,
key_owner_proof);
}

outcome::result<std::optional<primitives::OpaqueKeyOwnershipProof>>
BeefyApiImpl::generate_key_ownership_proof(
const primitives::BlockHash &block,
consensus::beefy::AuthoritySetId set_id,
const crypto::EcdsaPublicKey &authority_id) const {
OUTCOME_TRY(ctx, executor_->ctx().ephemeralAt(block));
return executor_->call<std::optional<primitives::OpaqueKeyOwnershipProof>>(
ctx, "BeefyApi_generate_key_ownership_proof", set_id, authority_id);
}
} // namespace kagome::runtime
10 changes: 10 additions & 0 deletions core/runtime/runtime_api/impl/beefy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ namespace kagome::runtime {
const primitives::BlockHash &block) override;
outcome::result<std::optional<consensus::beefy::ValidatorSet>> validatorSet(
const primitives::BlockHash &block) override;
outcome::result<void> submit_report_double_voting_unsigned_extrinsic(
const primitives::BlockHash &block,
const consensus::beefy::DoubleVotingProof &equivocation_proof,
const primitives::OpaqueKeyOwnershipProof &key_owner_proof)
const override;
outcome::result<std::optional<primitives::OpaqueKeyOwnershipProof>>
generate_key_ownership_proof(
const primitives::BlockHash &block,
consensus::beefy::AuthoritySetId set_id,
const crypto::EcdsaPublicKey &authority_id) const override;

private:
std::shared_ptr<Executor> executor_;
Expand Down
15 changes: 15 additions & 0 deletions test/mock/core/runtime/beefy_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,20 @@ namespace kagome::runtime {
validatorSet,
(const primitives::BlockHash &),
(override));

MOCK_METHOD(outcome::result<void>,
submit_report_double_voting_unsigned_extrinsic,
(const primitives::BlockHash &,
const consensus::beefy::DoubleVotingProof &,
const primitives::OpaqueKeyOwnershipProof &),
(const, override));

MOCK_METHOD(
outcome::result<std::optional<primitives::OpaqueKeyOwnershipProof>>,
generate_key_ownership_proof,
(const primitives::BlockHash &,
consensus::beefy::AuthoritySetId,
const crypto::EcdsaPublicKey &),
(const, override));
};
} // namespace kagome::runtime
Loading