Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Companion for substrate #13121 - BEEFY Equivocations support #6593

20 changes: 19 additions & 1 deletion runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use runtime_parachains::{
};

use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use beefy_primitives::crypto::AuthorityId as BeefyId;
use beefy_primitives::crypto::{AuthorityId as BeefyId, Signature as BeefySignature};
use frame_election_provider_support::{
generate_solution_type, onchain, NposSolution, SequentialPhragmen,
};
Expand Down Expand Up @@ -1746,6 +1746,24 @@ sp_api::impl_runtime_apis! {
// dummy implementation due to lack of BEEFY pallet.
None
}

fn submit_report_equivocation_unsigned_extrinsic(
_equivocation_proof: beefy_primitives::EquivocationProof<
BlockNumber,
BeefyId,
BeefySignature,
>,
_key_owner_proof: beefy_primitives::OpaqueKeyOwnershipProof,
) -> Option<()> {
None
}

fn generate_key_ownership_proof(
_set_id: beefy_primitives::ValidatorSetId,
_authority_id: BeefyId,
) -> Option<beefy_primitives::OpaqueKeyOwnershipProof> {
None
}
}

impl mmr::MmrApi<Block, Hash, BlockNumber> for Runtime {
Expand Down
20 changes: 19 additions & 1 deletion runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use runtime_parachains::{
};

use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use beefy_primitives::crypto::AuthorityId as BeefyId;
use beefy_primitives::crypto::{AuthorityId as BeefyId, Signature as BeefySignature};
use frame_election_provider_support::{generate_solution_type, onchain, SequentialPhragmen};
use frame_support::{
construct_runtime, parameter_types,
Expand Down Expand Up @@ -1863,6 +1863,24 @@ sp_api::impl_runtime_apis! {
// dummy implementation due to lack of BEEFY pallet.
None
}

fn submit_report_equivocation_unsigned_extrinsic(
_equivocation_proof: beefy_primitives::EquivocationProof<
BlockNumber,
BeefyId,
BeefySignature,
>,
_key_owner_proof: beefy_primitives::OpaqueKeyOwnershipProof,
) -> Option<()> {
None
}

fn generate_key_ownership_proof(
_set_id: beefy_primitives::ValidatorSetId,
_authority_id: BeefyId,
) -> Option<beefy_primitives::OpaqueKeyOwnershipProof> {
None
}
}

impl mmr::MmrApi<Block, Hash, BlockNumber> for Runtime {
Expand Down
45 changes: 43 additions & 2 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use runtime_parachains::{

use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use beefy_primitives::{
crypto::AuthorityId as BeefyId,
crypto::{AuthorityId as BeefyId, Signature as BeefySignature},
mmr::{BeefyDataProvider, MmrLeafVersion},
};

Expand Down Expand Up @@ -1242,8 +1242,22 @@ impl pallet_nis::Config for Runtime {

impl pallet_beefy::Config for Runtime {
type BeefyId = BeefyId;
type KeyOwnerProofSystem = Historical;
type KeyOwnerProof =
<Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, BeefyId)>>::Proof;
type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
BeefyId,
)>>::IdentificationTuple;
type HandleEquivocation = pallet_beefy::EquivocationHandler<
BlockNumber,
Self::KeyOwnerIdentification,
Offences,
ReportLongevity,
>;
type MaxAuthorities = MaxAuthorities;
type OnNewValidatorSet = MmrLeaf;
type WeightInfo = ();
}

type MmrHash = <Keccak256 as sp_runtime::traits::Hash>::Output;
Expand Down Expand Up @@ -1436,7 +1450,7 @@ construct_runtime! {
// Rococo specific pallets (not included in Kusama). Start indices at 240
//
// BEEFY Bridges support.
Beefy: pallet_beefy::{Pallet, Storage, Config<T>} = 240,
Beefy: pallet_beefy::{Pallet, Call, Storage, Config<T>, ValidateUnsigned} = 240,
MmrLeaf: pallet_beefy_mmr::{Pallet, Storage} = 242,

ParasSudoWrapper: paras_sudo_wrapper::{Pallet, Call} = 250,
Expand Down Expand Up @@ -1757,6 +1771,33 @@ sp_api::impl_runtime_apis! {
fn validator_set() -> Option<beefy_primitives::ValidatorSet<BeefyId>> {
Beefy::validator_set()
}

fn submit_report_equivocation_unsigned_extrinsic(
equivocation_proof: beefy_primitives::EquivocationProof<
BlockNumber,
BeefyId,
BeefySignature,
>,
key_owner_proof: beefy_primitives::OpaqueKeyOwnershipProof,
) -> Option<()> {
let key_owner_proof = key_owner_proof.decode()?;

Beefy::submit_unsigned_equivocation_report(
equivocation_proof,
key_owner_proof,
)
}

fn generate_key_ownership_proof(
_set_id: beefy_primitives::ValidatorSetId,
authority_id: BeefyId,
) -> Option<beefy_primitives::OpaqueKeyOwnershipProof> {
use parity_scale_codec::Encode;

Historical::prove((beefy_primitives::KEY_TYPE, authority_id))
.map(|p| p.encode())
.map(beefy_primitives::OpaqueKeyOwnershipProof::new)
}
}

impl mmr::MmrApi<Block, Hash, BlockNumber> for Runtime {
Expand Down
20 changes: 19 additions & 1 deletion runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use polkadot_runtime_parachains::{
};

use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use beefy_primitives::crypto::AuthorityId as BeefyId;
use beefy_primitives::crypto::{AuthorityId as BeefyId, Signature as BeefySignature};
use frame_election_provider_support::{onchain, SequentialPhragmen};
use frame_support::{
construct_runtime, parameter_types,
Expand Down Expand Up @@ -904,6 +904,24 @@ sp_api::impl_runtime_apis! {
// dummy implementation due to lack of BEEFY pallet.
None
}

fn submit_report_equivocation_unsigned_extrinsic(
_equivocation_proof: beefy_primitives::EquivocationProof<
BlockNumber,
BeefyId,
BeefySignature,
>,
_key_owner_proof: beefy_primitives::OpaqueKeyOwnershipProof,
) -> Option<()> {
None
}

fn generate_key_ownership_proof(
_set_id: beefy_primitives::ValidatorSetId,
_authority_id: BeefyId,
) -> Option<beefy_primitives::OpaqueKeyOwnershipProof> {
None
}
}

impl mmr::MmrApi<Block, Hash, BlockNumber> for Runtime {
Expand Down
20 changes: 19 additions & 1 deletion runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#![recursion_limit = "256"]

use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use beefy_primitives::crypto::AuthorityId as BeefyId;
use beefy_primitives::crypto::{AuthorityId as BeefyId, Signature as BeefySignature};
use frame_election_provider_support::{onchain, SequentialPhragmen};
use frame_support::{
construct_runtime, parameter_types,
Expand Down Expand Up @@ -1489,6 +1489,24 @@ sp_api::impl_runtime_apis! {
// dummy implementation due to lack of BEEFY pallet.
None
}

fn submit_report_equivocation_unsigned_extrinsic(
_equivocation_proof: beefy_primitives::EquivocationProof<
BlockNumber,
BeefyId,
BeefySignature,
>,
_key_owner_proof: beefy_primitives::OpaqueKeyOwnershipProof,
) -> Option<()> {
None
}

fn generate_key_ownership_proof(
_set_id: beefy_primitives::ValidatorSetId,
_authority_id: BeefyId,
) -> Option<beefy_primitives::OpaqueKeyOwnershipProof> {
None
}
}

impl mmr::MmrApi<Block, Hash, BlockNumber> for Runtime {
Expand Down