Move BEEFY code to consensus (#13484)

* Move beefy primitives to consensus dir
* Move beefy gadget to client consensus folder
* Rename beefy crates
This commit is contained in:
Davide Galassi
2023-02-28 15:56:22 +01:00
committed by GitHub
parent 1eb0cd31b9
commit 1ef9c473e7
47 changed files with 260 additions and 262 deletions
+2 -2
View File
@@ -15,12 +15,12 @@ log = { version = "0.4.17", default-features = false }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
serde = { version = "1.0.136", optional = true }
binary-merkle-tree = { version = "4.0.0-dev", default-features = false, path = "../../utils/binary-merkle-tree" }
beefy-primitives = { version = "4.0.0-dev", default-features = false, path = "../../primitives/beefy", package = "sp-beefy" }
frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }
pallet-beefy = { version = "4.0.0-dev", default-features = false, path = "../beefy" }
pallet-mmr = { version = "4.0.0-dev", default-features = false, path = "../merkle-mountain-range" }
pallet-session = { version = "4.0.0-dev", default-features = false, path = "../session" }
sp-consensus-beefy = { version = "4.0.0-dev", default-features = false, path = "../../primitives/consensus/beefy" }
sp-core = { version = "7.0.0", default-features = false, path = "../../primitives/core" }
sp-io = { version = "7.0.0", default-features = false, path = "../../primitives/io" }
sp-runtime = { version = "7.0.0", default-features = false, path = "../../primitives/runtime" }
@@ -36,7 +36,6 @@ default = ["std"]
std = [
"array-bytes",
"binary-merkle-tree/std",
"beefy-primitives/std",
"codec/std",
"frame-support/std",
"frame-system/std",
@@ -46,6 +45,7 @@ std = [
"pallet-session/std",
"scale-info/std",
"serde",
"sp-consensus-beefy/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
+9 -9
View File
@@ -36,11 +36,11 @@
use sp_runtime::traits::{Convert, Member};
use sp_std::prelude::*;
use beefy_primitives::{
use pallet_mmr::{LeafDataProvider, ParentNumberAndHash};
use sp_consensus_beefy::{
mmr::{BeefyAuthoritySet, BeefyDataProvider, BeefyNextAuthoritySet, MmrLeaf, MmrLeafVersion},
ValidatorSet as BeefyValidatorSet,
};
use pallet_mmr::{LeafDataProvider, ParentNumberAndHash};
use frame_support::{crypto::ecdsa::ECDSAExt, traits::Get};
@@ -54,15 +54,15 @@ mod tests;
/// A BEEFY consensus digest item with MMR root hash.
pub struct DepositBeefyDigest<T>(sp_std::marker::PhantomData<T>);
impl<T> pallet_mmr::primitives::OnNewRoot<beefy_primitives::MmrRootHash> for DepositBeefyDigest<T>
impl<T> pallet_mmr::primitives::OnNewRoot<sp_consensus_beefy::MmrRootHash> for DepositBeefyDigest<T>
where
T: pallet_mmr::Config<Hash = beefy_primitives::MmrRootHash>,
T: pallet_mmr::Config<Hash = sp_consensus_beefy::MmrRootHash>,
T: pallet_beefy::Config,
{
fn on_new_root(root: &<T as pallet_mmr::Config>::Hash) {
let digest = sp_runtime::generic::DigestItem::Consensus(
beefy_primitives::BEEFY_ENGINE_ID,
codec::Encode::encode(&beefy_primitives::ConsensusLog::<
sp_consensus_beefy::BEEFY_ENGINE_ID,
codec::Encode::encode(&sp_consensus_beefy::ConsensusLog::<
<T as pallet_beefy::Config>::BeefyId,
>::MmrRoot(*root)),
);
@@ -72,8 +72,8 @@ where
/// Convert BEEFY secp256k1 public keys into Ethereum addresses
pub struct BeefyEcdsaToEthereum;
impl Convert<beefy_primitives::crypto::AuthorityId, Vec<u8>> for BeefyEcdsaToEthereum {
fn convert(beefy_id: beefy_primitives::crypto::AuthorityId) -> Vec<u8> {
impl Convert<sp_consensus_beefy::crypto::AuthorityId, Vec<u8>> for BeefyEcdsaToEthereum {
fn convert(beefy_id: sp_consensus_beefy::crypto::AuthorityId) -> Vec<u8> {
sp_core::ecdsa::Public::from(beefy_id)
.to_eth_address()
.map(|v| v.to_vec())
@@ -156,7 +156,7 @@ impl<T: Config> LeafDataProvider for Pallet<T> {
}
}
impl<T> beefy_primitives::OnNewValidatorSet<<T as pallet_beefy::Config>::BeefyId> for Pallet<T>
impl<T> sp_consensus_beefy::OnNewValidatorSet<<T as pallet_beefy::Config>::BeefyId> for Pallet<T>
where
T: pallet::Config,
{
+3 -3
View File
@@ -17,7 +17,6 @@
use std::vec;
use beefy_primitives::mmr::MmrLeafVersion;
use codec::Encode;
use frame_support::{
construct_runtime, parameter_types,
@@ -25,6 +24,7 @@ use frame_support::{
traits::{ConstU16, ConstU32, ConstU64, GenesisBuild, KeyOwnerProofSystem},
BasicExternalities,
};
use sp_consensus_beefy::mmr::MmrLeafVersion;
use sp_core::{crypto::KeyTypeId, Hasher, H256};
use sp_runtime::{
app_crypto::ecdsa::Public,
@@ -35,7 +35,7 @@ use sp_runtime::{
use crate as pallet_beefy_mmr;
pub use beefy_primitives::{
pub use sp_consensus_beefy::{
crypto::AuthorityId as BeefyId, mmr::BeefyDataProvider, ConsensusLog, BEEFY_ENGINE_ID,
};
@@ -101,7 +101,7 @@ impl pallet_session::Config for Test {
type WeightInfo = ();
}
pub type MmrLeaf = beefy_primitives::mmr::MmrLeaf<
pub type MmrLeaf = sp_consensus_beefy::mmr::MmrLeaf<
<Test as frame_system::Config>::BlockNumber,
<Test as frame_system::Config>::Hash,
<Test as pallet_mmr::Config>::Hash,
+2 -2
View File
@@ -17,11 +17,11 @@
use std::vec;
use beefy_primitives::{
use codec::{Decode, Encode};
use sp_consensus_beefy::{
mmr::{BeefyNextAuthoritySet, MmrLeafVersion},
ValidatorSet,
};
use codec::{Decode, Encode};
use sp_core::H256;
use sp_io::TestExternalities;
+2 -2
View File
@@ -12,11 +12,11 @@ homepage = "https://substrate.io"
codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive"] }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
serde = { version = "1.0.136", optional = true }
beefy-primitives = { version = "4.0.0-dev", default-features = false, path = "../../primitives/beefy", package = "sp-beefy" }
frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }
pallet-authorship = { version = "4.0.0-dev", default-features = false, path = "../authorship" }
pallet-session = { version = "4.0.0-dev", default-features = false, path = "../session" }
sp-consensus-beefy = { version = "4.0.0-dev", default-features = false, path = "../../primitives/consensus/beefy" }
sp-runtime = { version = "7.0.0", default-features = false, path = "../../primitives/runtime" }
sp-session = { version = "4.0.0-dev", default-features = false, path = "../../primitives/session" }
sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" }
@@ -36,7 +36,6 @@ sp-staking = { version = "4.0.0-dev", path = "../../primitives/staking" }
[features]
default = ["std"]
std = [
"beefy-primitives/std",
"codec/std",
"frame-support/std",
"frame-system/std",
@@ -44,6 +43,7 @@ std = [
"pallet-session/std",
"scale-info/std",
"serde",
"sp-consensus-beefy/std",
"sp-runtime/std",
"sp-session/std",
"sp-staking/std",
+2 -2
View File
@@ -36,13 +36,13 @@
use sp_std::prelude::*;
use beefy_primitives::{EquivocationProof, ValidatorSetId};
use codec::{self as codec, Decode, Encode};
use frame_support::{
log,
traits::{Get, KeyOwnerProofSystem},
};
use frame_system::pallet_prelude::BlockNumberFor;
use sp_consensus_beefy::{EquivocationProof, ValidatorSetId};
use sp_runtime::{
transaction_validity::{
InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity,
@@ -271,7 +271,7 @@ fn is_known_offence<T: Config>(
) -> Result<(), TransactionValidityError> {
// check the membership proof to extract the offender's id,
// equivocation validity will be fully checked during the call.
let key = (beefy_primitives::KEY_TYPE, equivocation_proof.offender_id().clone());
let key = (sp_consensus_beefy::KEY_TYPE, equivocation_proof.offender_id().clone());
let offender = T::KeyOwnerProofSystem::check_proof(key, key_owner_proof.clone())
.ok_or(InvalidTransaction::BadProof)?;
+6 -6
View File
@@ -40,7 +40,7 @@ use sp_session::{GetSessionNumber, GetValidatorCount};
use sp_staking::SessionIndex;
use sp_std::prelude::*;
use beefy_primitives::{
use sp_consensus_beefy::{
AuthorityIndex, BeefyAuthorityId, ConsensusLog, EquivocationProof, OnNewValidatorSet,
ValidatorSet, BEEFY_ENGINE_ID, GENESIS_AUTHORITY_SET_ID,
};
@@ -135,7 +135,7 @@ pub mod pallet {
#[pallet::storage]
#[pallet::getter(fn validator_set_id)]
pub(super) type ValidatorSetId<T: Config> =
StorageValue<_, beefy_primitives::ValidatorSetId, ValueQuery>;
StorageValue<_, sp_consensus_beefy::ValidatorSetId, ValueQuery>;
/// Authorities set scheduled to be used with the next session
#[pallet::storage]
@@ -156,7 +156,7 @@ pub mod pallet {
#[pallet::storage]
#[pallet::getter(fn session_for_set)]
pub(super) type SetIdSession<T: Config> =
StorageMap<_, Twox64Concat, beefy_primitives::ValidatorSetId, SessionIndex>;
StorageMap<_, Twox64Concat, sp_consensus_beefy::ValidatorSetId, SessionIndex>;
/// Block number where BEEFY consensus is enabled/started.
/// If changing this, make sure `Self::ValidatorSetId` is also reset to
@@ -280,7 +280,7 @@ impl<T: Config> Pallet<T> {
/// Return the current active BEEFY validator set.
pub fn validator_set() -> Option<ValidatorSet<T::BeefyId>> {
let validators: BoundedVec<T::BeefyId, T::MaxAuthorities> = Self::authorities();
let id: beefy_primitives::ValidatorSetId = Self::validator_set_id();
let id: sp_consensus_beefy::ValidatorSetId = Self::validator_set_id();
ValidatorSet::<T::BeefyId>::new(validators, id)
}
@@ -390,13 +390,13 @@ impl<T: Config> Pallet<T> {
// validate the key ownership proof extracting the id of the offender.
let offender = T::KeyOwnerProofSystem::check_proof(
(beefy_primitives::KEY_TYPE, offender_id),
(sp_consensus_beefy::KEY_TYPE, offender_id),
key_owner_proof,
)
.ok_or(Error::<T>::InvalidKeyOwnershipProof)?;
// validate equivocation proof (check votes are different and signatures are valid).
if !beefy_primitives::check_equivocation_proof(&equivocation_proof) {
if !sp_consensus_beefy::check_equivocation_proof(&equivocation_proof) {
return Err(Error::<T>::InvalidEquivocationProof.into())
}
+1 -1
View File
@@ -40,7 +40,7 @@ use sp_staking::{EraIndex, SessionIndex};
use crate as pallet_beefy;
pub use beefy_primitives::{
pub use sp_consensus_beefy::{
crypto::{AuthorityId as BeefyId, AuthoritySignature as BeefySignature},
ConsensusLog, EquivocationProof, BEEFY_ENGINE_ID,
};
+10 -10
View File
@@ -17,11 +17,11 @@
use std::vec;
use beefy_primitives::{
use codec::Encode;
use sp_consensus_beefy::{
check_equivocation_proof, generate_equivocation_proof, known_payloads::MMR_ROOT_ID,
Keyring as BeefyKeyring, Payload, ValidatorSet,
};
use codec::Encode;
use sp_runtime::DigestItem;
@@ -298,7 +298,7 @@ fn report_equivocation_current_set_works() {
// create the key ownership proof
let key_owner_proof =
Historical::prove((beefy_primitives::KEY_TYPE, &equivocation_key)).unwrap();
Historical::prove((sp_consensus_beefy::KEY_TYPE, &equivocation_key)).unwrap();
// report the equivocation and the tx should be dispatched successfully
assert_ok!(Beefy::report_equivocation_unsigned(
@@ -355,7 +355,7 @@ fn report_equivocation_old_set_works() {
// create the key ownership proof in the "old" set
let key_owner_proof =
Historical::prove((beefy_primitives::KEY_TYPE, &equivocation_key)).unwrap();
Historical::prove((sp_consensus_beefy::KEY_TYPE, &equivocation_key)).unwrap();
start_era(2);
@@ -437,7 +437,7 @@ fn report_equivocation_invalid_set_id() {
let equivocation_keyring = BeefyKeyring::from_public(equivocation_key).unwrap();
let key_owner_proof =
Historical::prove((beefy_primitives::KEY_TYPE, &equivocation_key)).unwrap();
Historical::prove((sp_consensus_beefy::KEY_TYPE, &equivocation_key)).unwrap();
let payload1 = Payload::from_single_entry(MMR_ROOT_ID, vec![42]);
let payload2 = Payload::from_single_entry(MMR_ROOT_ID, vec![128]);
@@ -476,7 +476,7 @@ fn report_equivocation_invalid_session() {
// generate a key ownership proof at current era set id
let key_owner_proof =
Historical::prove((beefy_primitives::KEY_TYPE, &equivocation_key)).unwrap();
Historical::prove((sp_consensus_beefy::KEY_TYPE, &equivocation_key)).unwrap();
start_era(2);
@@ -520,7 +520,7 @@ fn report_equivocation_invalid_key_owner_proof() {
// generate a key ownership proof for the authority at index 1
let invalid_key_owner_proof =
Historical::prove((beefy_primitives::KEY_TYPE, &invalid_owner_key)).unwrap();
Historical::prove((sp_consensus_beefy::KEY_TYPE, &invalid_owner_key)).unwrap();
let equivocation_authority_index = 0;
let equivocation_key = &authorities[equivocation_authority_index];
@@ -569,7 +569,7 @@ fn report_equivocation_invalid_equivocation_proof() {
// generate a key ownership proof at set id in era 1
let key_owner_proof =
Historical::prove((beefy_primitives::KEY_TYPE, &equivocation_key)).unwrap();
Historical::prove((sp_consensus_beefy::KEY_TYPE, &equivocation_key)).unwrap();
let assert_invalid_equivocation_proof = |equivocation_proof| {
assert_err!(
@@ -650,7 +650,7 @@ fn report_equivocation_validate_unsigned_prevents_duplicates() {
);
let key_owner_proof =
Historical::prove((beefy_primitives::KEY_TYPE, &equivocation_key)).unwrap();
Historical::prove((sp_consensus_beefy::KEY_TYPE, &equivocation_key)).unwrap();
let call = Call::report_equivocation_unsigned {
equivocation_proof: Box::new(equivocation_proof.clone()),
@@ -756,7 +756,7 @@ fn valid_equivocation_reports_dont_pay_fees() {
// create the key ownership proof.
let key_owner_proof =
Historical::prove((beefy_primitives::KEY_TYPE, &equivocation_key)).unwrap();
Historical::prove((sp_consensus_beefy::KEY_TYPE, &equivocation_key)).unwrap();
// check the dispatch info for the call.
let info = Call::<Test>::report_equivocation_unsigned {