Skip to content

Commit

Permalink
EquivocationProof -> DoubleVotingProof
Browse files Browse the repository at this point in the history
  • Loading branch information
serban300 committed Apr 29, 2024
1 parent a2c97d9 commit 113658d
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion polkadot/node/service/src/fake_runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ sp_api::impl_runtime_apis! {
}

fn submit_report_equivocation_unsigned_extrinsic(
_: beefy_primitives::EquivocationProof<
_: beefy_primitives::DoubleVotingProof<
BlockNumber,
BeefyId,
BeefySignature,
Expand Down
2 changes: 1 addition & 1 deletion polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,7 @@ sp_api::impl_runtime_apis! {
}

fn submit_report_equivocation_unsigned_extrinsic(
equivocation_proof: beefy_primitives::EquivocationProof<
equivocation_proof: beefy_primitives::DoubleVotingProof<
BlockNumber,
BeefyId,
BeefySignature,
Expand Down
2 changes: 1 addition & 1 deletion polkadot/runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ sp_api::impl_runtime_apis! {
}

fn submit_report_equivocation_unsigned_extrinsic(
_equivocation_proof: beefy_primitives::EquivocationProof<
_equivocation_proof: beefy_primitives::DoubleVotingProof<
BlockNumber,
BeefyId,
BeefySignature,
Expand Down
2 changes: 1 addition & 1 deletion polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1966,7 +1966,7 @@ sp_api::impl_runtime_apis! {
}

fn submit_report_equivocation_unsigned_extrinsic(
equivocation_proof: beefy_primitives::EquivocationProof<
equivocation_proof: beefy_primitives::DoubleVotingProof<
BlockNumber,
BeefyId,
BeefySignature,
Expand Down
2 changes: 1 addition & 1 deletion substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3053,7 +3053,7 @@ impl_runtime_apis! {
}

fn submit_report_equivocation_unsigned_extrinsic(
equivocation_proof: sp_consensus_beefy::EquivocationProof<
equivocation_proof: sp_consensus_beefy::DoubleVotingProof<
BlockNumber,
BeefyId,
BeefySignature,
Expand Down
6 changes: 3 additions & 3 deletions substrate/client/consensus/beefy/src/fisherman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use sp_blockchain::HeaderBackend;
use sp_consensus_beefy::{
check_equivocation_proof,
ecdsa_crypto::{AuthorityId, Signature},
BeefyApi, BeefySignatureHasher, EquivocationProof, OpaqueKeyOwnershipProof, ValidatorSetId,
BeefyApi, BeefySignatureHasher, DoubleVotingProof, OpaqueKeyOwnershipProof, ValidatorSetId,
};
use sp_runtime::{
generic::BlockId,
Expand Down Expand Up @@ -117,9 +117,9 @@ where
/// extrinsic to report the equivocation. In particular, the session membership
/// proof must be generated at the block at which the given set was active which
/// isn't necessarily the best block if there are pending authority set changes.
pub fn report_equivocation(
pub fn report_double_voting(
&self,
proof: EquivocationProof<NumberFor<B>, AuthorityId, Signature>,
proof: DoubleVotingProof<NumberFor<B>, AuthorityId, Signature>,
active_rounds: &Rounds<B>,
) -> Result<(), Error> {
let (validators, validator_set_id) =
Expand Down
10 changes: 5 additions & 5 deletions substrate/client/consensus/beefy/src/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use codec::{Decode, Encode};
use log::{debug, info};
use sp_consensus_beefy::{
ecdsa_crypto::{AuthorityId, Signature},
Commitment, EquivocationProof, SignedCommitment, ValidatorSet, ValidatorSetId, VoteMessage,
Commitment, DoubleVotingProof, SignedCommitment, ValidatorSet, ValidatorSetId, VoteMessage,
};
use sp_runtime::traits::{Block, NumberFor};
use std::collections::BTreeMap;
Expand Down Expand Up @@ -61,7 +61,7 @@ pub fn threshold(authorities: usize) -> usize {
pub enum VoteImportResult<B: Block> {
Ok,
RoundConcluded(SignedCommitment<NumberFor<B>, Signature>),
Equivocation(EquivocationProof<NumberFor<B>, AuthorityId, Signature>),
DoubleVoting(DoubleVotingProof<NumberFor<B>, AuthorityId, Signature>),
Invalid,
Stale,
}
Expand Down Expand Up @@ -153,7 +153,7 @@ where
target: LOG_TARGET,
"🥩 detected equivocated vote: 1st: {:?}, 2nd: {:?}", previous_vote, vote
);
return VoteImportResult::Equivocation(EquivocationProof {
return VoteImportResult::DoubleVoting(DoubleVotingProof {
first: previous_vote.clone(),
second: vote,
})
Expand Down Expand Up @@ -207,7 +207,7 @@ mod tests {
use sc_network_test::Block;

use sp_consensus_beefy::{
known_payloads::MMR_ROOT_ID, test_utils::Keyring, Commitment, EquivocationProof, Payload,
known_payloads::MMR_ROOT_ID, test_utils::Keyring, Commitment, DoubleVotingProof, Payload,
SignedCommitment, ValidatorSet, VoteMessage,
};

Expand Down Expand Up @@ -494,7 +494,7 @@ mod tests {
let mut alice_vote2 = alice_vote1.clone();
alice_vote2.commitment = commitment2;

let expected_result = VoteImportResult::Equivocation(EquivocationProof {
let expected_result = VoteImportResult::DoubleVoting(DoubleVotingProof {
first: alice_vote1.clone(),
second: alice_vote2.clone(),
});
Expand Down
6 changes: 3 additions & 3 deletions substrate/client/consensus/beefy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use sp_consensus_beefy::{
known_payloads,
mmr::{find_mmr_root_digest, MmrRootProvider},
test_utils::Keyring as BeefyKeyring,
BeefyApi, Commitment, ConsensusLog, EquivocationProof, MmrRootHash, OpaqueKeyOwnershipProof,
BeefyApi, Commitment, ConsensusLog, DoubleVotingProof, MmrRootHash, OpaqueKeyOwnershipProof,
Payload, SignedCommitment, ValidatorSet, ValidatorSetId, VersionedFinalityProof, VoteMessage,
BEEFY_ENGINE_ID,
};
Expand Down Expand Up @@ -259,7 +259,7 @@ pub(crate) struct TestApi {
pub validator_set: Option<BeefyValidatorSet>,
pub mmr_root_hash: MmrRootHash,
pub reported_equivocations:
Option<Arc<Mutex<Vec<EquivocationProof<NumberFor<Block>, AuthorityId, Signature>>>>>,
Option<Arc<Mutex<Vec<DoubleVotingProof<NumberFor<Block>, AuthorityId, Signature>>>>>,
}

impl TestApi {
Expand Down Expand Up @@ -313,7 +313,7 @@ sp_api::mock_impl_runtime_apis! {
}

fn submit_report_equivocation_unsigned_extrinsic(
proof: EquivocationProof<NumberFor<Block>, AuthorityId, Signature>,
proof: DoubleVotingProof<NumberFor<Block>, AuthorityId, Signature>,
_dummy: OpaqueKeyOwnershipProof,
) -> Option<()> {
if let Some(equivocations_buf) = self.inner.reported_equivocations.as_ref() {
Expand Down
20 changes: 10 additions & 10 deletions substrate/client/consensus/beefy/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use sp_arithmetic::traits::{AtLeast32Bit, Saturating};
use sp_consensus::SyncOracle;
use sp_consensus_beefy::{
ecdsa_crypto::{AuthorityId, Signature},
BeefyApi, Commitment, EquivocationProof, PayloadProvider, ValidatorSet, VersionedFinalityProof,
BeefyApi, Commitment, DoubleVotingProof, PayloadProvider, ValidatorSet, VersionedFinalityProof,
VoteMessage, BEEFY_ENGINE_ID,
};
use sp_runtime::{
Expand Down Expand Up @@ -591,9 +591,9 @@ where
}
metric_inc!(self.metrics, beefy_good_votes_processed);
},
VoteImportResult::Equivocation(proof) => {
VoteImportResult::DoubleVoting(proof) => {
metric_inc!(self.metrics, beefy_equivocation_votes);
self.report_equivocation(proof)?;
self.report_double_voting(proof)?;
},
VoteImportResult::Invalid => metric_inc!(self.metrics, beefy_invalid_votes),
VoteImportResult::Stale => metric_inc!(self.metrics, beefy_stale_votes),
Expand Down Expand Up @@ -943,12 +943,12 @@ where
}

/// Report the given equivocation to the BEEFY runtime module.
fn report_equivocation(
fn report_double_voting(
&self,
proof: EquivocationProof<NumberFor<B>, AuthorityId, Signature>,
proof: DoubleVotingProof<NumberFor<B>, AuthorityId, Signature>,
) -> Result<(), Error> {
let rounds = self.persisted_state.voting_oracle.active_rounds()?;
self.fisherman.report_equivocation(proof, rounds)
self.fisherman.report_double_voting(proof, rounds)
}
}

Expand Down Expand Up @@ -1561,7 +1561,7 @@ pub(crate) mod tests {
);
{
// expect voter (Alice) to successfully report it
assert_eq!(worker.report_equivocation(good_proof.clone()), Ok(()));
assert_eq!(worker.report_double_voting(good_proof.clone()), Ok(()));
// verify Alice reports Bob equivocation to runtime
let reported = api_alice.reported_equivocations.as_ref().unwrap().lock();
assert_eq!(reported.len(), 1);
Expand All @@ -1573,7 +1573,7 @@ pub(crate) mod tests {
let mut bad_proof = good_proof.clone();
bad_proof.first.id = Keyring::Charlie.public();
// bad proofs are simply ignored
assert_eq!(worker.report_equivocation(bad_proof), Ok(()));
assert_eq!(worker.report_double_voting(bad_proof), Ok(()));
// verify nothing reported to runtime
assert!(api_alice.reported_equivocations.as_ref().unwrap().lock().is_empty());

Expand All @@ -1582,7 +1582,7 @@ pub(crate) mod tests {
old_proof.first.commitment.validator_set_id = 0;
old_proof.second.commitment.validator_set_id = 0;
// old proofs are simply ignored
assert_eq!(worker.report_equivocation(old_proof), Ok(()));
assert_eq!(worker.report_double_voting(old_proof), Ok(()));
// verify nothing reported to runtime
assert!(api_alice.reported_equivocations.as_ref().unwrap().lock().is_empty());

Expand All @@ -1592,7 +1592,7 @@ pub(crate) mod tests {
(block_num, payload2.clone(), set_id, &Keyring::Alice),
);
// equivocations done by 'self' are simply ignored (not reported)
assert_eq!(worker.report_equivocation(self_proof), Ok(()));
assert_eq!(worker.report_double_voting(self_proof), Ok(()));
// verify nothing reported to runtime
assert!(api_alice.reported_equivocations.as_ref().unwrap().lock().is_empty());
}
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/beefy/src/equivocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use codec::{self as codec, Decode, Encode};
use frame_support::traits::{Get, KeyOwnerProofSystem};
use frame_system::pallet_prelude::BlockNumberFor;
use log::{error, info};
use sp_consensus_beefy::{EquivocationProof, ValidatorSetId, KEY_TYPE as BEEFY_KEY_TYPE};
use sp_consensus_beefy::{DoubleVotingProof, ValidatorSetId, KEY_TYPE as BEEFY_KEY_TYPE};
use sp_runtime::{
transaction_validity::{
InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity,
Expand Down Expand Up @@ -123,7 +123,7 @@ pub struct EquivocationReportSystem<T, R, P, L>(sp_std::marker::PhantomData<(T,

/// Equivocation evidence convenience alias.
pub type EquivocationEvidenceFor<T> = (
EquivocationProof<
DoubleVotingProof<
BlockNumberFor<T>,
<T as Config>::BeefyId,
<<T as Config>::BeefyId as RuntimeAppPublic>::Signature,
Expand Down
8 changes: 4 additions & 4 deletions substrate/frame/beefy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use sp_staking::{offence::OffenceReportSystem, SessionIndex};
use sp_std::prelude::*;

use sp_consensus_beefy::{
AuthorityIndex, BeefyAuthorityId, ConsensusLog, EquivocationProof, OnNewValidatorSet,
AuthorityIndex, BeefyAuthorityId, ConsensusLog, DoubleVotingProof, OnNewValidatorSet,
ValidatorSet, BEEFY_ENGINE_ID, GENESIS_AUTHORITY_SET_ID,
};

Expand Down Expand Up @@ -210,7 +210,7 @@ pub mod pallet {
pub fn report_equivocation(
origin: OriginFor<T>,
equivocation_proof: Box<
EquivocationProof<
DoubleVotingProof<
BlockNumberFor<T>,
T::BeefyId,
<T::BeefyId as RuntimeAppPublic>::Signature,
Expand Down Expand Up @@ -245,7 +245,7 @@ pub mod pallet {
pub fn report_equivocation_unsigned(
origin: OriginFor<T>,
equivocation_proof: Box<
EquivocationProof<
DoubleVotingProof<
BlockNumberFor<T>,
T::BeefyId,
<T::BeefyId as RuntimeAppPublic>::Signature,
Expand Down Expand Up @@ -368,7 +368,7 @@ impl<T: Config> Pallet<T> {
/// an unsigned extrinsic with a call to `report_equivocation_unsigned` and
/// will push the transaction to the pool. Only useful in an offchain context.
pub fn submit_unsigned_equivocation_report(
equivocation_proof: EquivocationProof<
equivocation_proof: DoubleVotingProof<
BlockNumberFor<T>,
T::BeefyId,
<T::BeefyId as RuntimeAppPublic>::Signature,
Expand Down
8 changes: 4 additions & 4 deletions substrate/primitives/consensus/beefy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,14 @@ pub struct VoteMessage<Number, Id, Signature> {
/// BEEFY happens when a voter votes on the same round/block for different payloads.
/// Proving is achieved by collecting the signed commitments of conflicting votes.
#[derive(Clone, Debug, Decode, Encode, PartialEq, TypeInfo)]
pub struct EquivocationProof<Number, Id, Signature> {
pub struct DoubleVotingProof<Number, Id, Signature> {
/// The first vote in the equivocation.
pub first: VoteMessage<Number, Id, Signature>,
/// The second vote in the equivocation.
pub second: VoteMessage<Number, Id, Signature>,
}

impl<Number, Id, Signature> EquivocationProof<Number, Id, Signature> {
impl<Number, Id, Signature> DoubleVotingProof<Number, Id, Signature> {
/// Returns the authority id of the equivocator.
pub fn offender_id(&self) -> &Id {
&self.first.id
Expand Down Expand Up @@ -347,7 +347,7 @@ where
/// Verifies the equivocation proof by making sure that both votes target
/// different blocks and that its signatures are valid.
pub fn check_equivocation_proof<Number, Id, MsgHash>(
report: &EquivocationProof<Number, Id, <Id as RuntimeAppPublic>::Signature>,
report: &DoubleVotingProof<Number, Id, <Id as RuntimeAppPublic>::Signature>,
) -> bool
where
Id: BeefyAuthorityId<MsgHash> + PartialEq,
Expand Down Expand Up @@ -437,7 +437,7 @@ sp_api::decl_runtime_apis! {
/// hardcoded to return `None`). Only useful in an offchain context.
fn submit_report_equivocation_unsigned_extrinsic(
equivocation_proof:
EquivocationProof<NumberFor<Block>, AuthorityId, <AuthorityId as RuntimeAppPublic>::Signature>,
DoubleVotingProof<NumberFor<Block>, AuthorityId, <AuthorityId as RuntimeAppPublic>::Signature>,
key_owner_proof: OpaqueKeyOwnershipProof,
) -> Option<()>;

Expand Down
6 changes: 3 additions & 3 deletions substrate/primitives/consensus/beefy/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#[cfg(feature = "bls-experimental")]
use crate::ecdsa_bls_crypto;
use crate::{
ecdsa_crypto, AuthorityIdBound, BeefySignatureHasher, Commitment, EquivocationProof, Payload,
ecdsa_crypto, AuthorityIdBound, BeefySignatureHasher, Commitment, DoubleVotingProof, Payload,
ValidatorSetId, VoteMessage,
};
use sp_application_crypto::{AppCrypto, AppPair, RuntimeAppPublic, Wraps};
Expand Down Expand Up @@ -140,7 +140,7 @@ impl From<Keyring<ecdsa_crypto::AuthorityId>> for ecdsa_crypto::Public {
pub fn generate_equivocation_proof(
vote1: (u64, Payload, ValidatorSetId, &Keyring<ecdsa_crypto::AuthorityId>),
vote2: (u64, Payload, ValidatorSetId, &Keyring<ecdsa_crypto::AuthorityId>),
) -> EquivocationProof<u64, ecdsa_crypto::Public, ecdsa_crypto::Signature> {
) -> DoubleVotingProof<u64, ecdsa_crypto::Public, ecdsa_crypto::Signature> {
let signed_vote = |block_number: u64,
payload: Payload,
validator_set_id: ValidatorSetId,
Expand All @@ -151,5 +151,5 @@ pub fn generate_equivocation_proof(
};
let first = signed_vote(vote1.0, vote1.1, vote1.2, vote1.3);
let second = signed_vote(vote2.0, vote2.1, vote2.2, vote2.3);
EquivocationProof { first, second }
DoubleVotingProof { first, second }
}

0 comments on commit 113658d

Please sign in to comment.