From c4f7ecfdf3ff9ea80ea159fb80b05af530e27f72 Mon Sep 17 00:00:00 2001 From: Nathy-bajo Date: Sun, 26 Jan 2025 22:00:34 +0100 Subject: [PATCH 1/2] migrate pallet-beefy and pallet-beefy-mmr to use umbrella crate --- Cargo.lock | 16 +----- substrate/frame/Cargo.toml | 1 - substrate/frame/beefy-mmr/Cargo.toml | 28 ++------- substrate/frame/beefy-mmr/src/benchmarking.rs | 5 +- substrate/frame/beefy-mmr/src/lib.rs | 20 ++----- substrate/frame/beefy-mmr/src/mock.rs | 22 ++----- substrate/frame/beefy-mmr/src/tests.rs | 8 +-- substrate/frame/beefy-mmr/src/weights.rs | 2 +- substrate/frame/beefy/Cargo.toml | 23 ++------ substrate/frame/beefy/src/default_weights.rs | 5 +- substrate/frame/beefy/src/equivocation.rs | 13 +---- substrate/frame/beefy/src/lib.rs | 32 ++++------- substrate/frame/beefy/src/mock.rs | 20 +------ substrate/frame/beefy/src/tests.rs | 22 +++---- substrate/frame/src/lib.rs | 57 ++++++++++++++----- 15 files changed, 96 insertions(+), 178 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e4bd817300f0..bffeaf5fea0a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12475,8 +12475,6 @@ name = "pallet-beefy" version = "28.0.0" dependencies = [ "frame-election-provider-support 28.0.0", - "frame-support 28.0.0", - "frame-system 28.0.0", "log", "pallet-authorship 28.0.0", "pallet-balances 28.0.0", @@ -12486,13 +12484,10 @@ dependencies = [ "pallet-staking-reward-curve", "pallet-timestamp 27.0.0", "parity-scale-codec", + "polkadot-sdk-frame 0.1.0", "scale-info", "serde", "sp-consensus-beefy 13.0.0", - "sp-core 28.0.0", - "sp-io 30.0.0", - "sp-runtime 31.0.1", - "sp-session 27.0.0", "sp-staking 26.0.0", "sp-state-machine 0.35.0", ] @@ -12523,22 +12518,15 @@ version = "28.0.0" dependencies = [ "array-bytes", "binary-merkle-tree 13.0.0", - "frame-benchmarking 28.0.0", - "frame-support 28.0.0", - "frame-system 28.0.0", "log", "pallet-beefy 28.0.0", "pallet-mmr 27.0.0", "pallet-session 28.0.0", "parity-scale-codec", + "polkadot-sdk-frame 0.1.0", "scale-info", "serde", - "sp-api 26.0.0", "sp-consensus-beefy 13.0.0", - "sp-core 28.0.0", - "sp-io 30.0.0", - "sp-runtime 31.0.1", - "sp-staking 26.0.0", "sp-state-machine 0.35.0", ] diff --git a/substrate/frame/Cargo.toml b/substrate/frame/Cargo.toml index 8fc0d8468430..6c5724472a76 100644 --- a/substrate/frame/Cargo.toml +++ b/substrate/frame/Cargo.toml @@ -48,7 +48,6 @@ sp-session = { optional = true, workspace = true } sp-storage = { optional = true, workspace = true } sp-transaction-pool = { optional = true, workspace = true } sp-version = { optional = true, workspace = true } - frame-executive = { optional = true, workspace = true } frame-system-rpc-runtime-api = { optional = true, workspace = true } diff --git a/substrate/frame/beefy-mmr/Cargo.toml b/substrate/frame/beefy-mmr/Cargo.toml index 54343bb9ce51..156c74e328e7 100644 --- a/substrate/frame/beefy-mmr/Cargo.toml +++ b/substrate/frame/beefy-mmr/Cargo.toml @@ -15,25 +15,18 @@ workspace = true array-bytes = { optional = true, workspace = true, default-features = true } binary-merkle-tree = { workspace = true } codec = { features = ["derive"], workspace = true } -frame-benchmarking = { optional = true, workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } +frame = { workspace = true, features = ["runtime"] } log = { workspace = true } pallet-beefy = { workspace = true } pallet-mmr = { workspace = true } pallet-session = { workspace = true } scale-info = { features = ["derive"], workspace = true } serde = { optional = true, workspace = true, default-features = true } -sp-api = { workspace = true } sp-consensus-beefy = { workspace = true } -sp-core = { workspace = true } -sp-io = { workspace = true } -sp-runtime = { workspace = true } sp-state-machine = { workspace = true } [dev-dependencies] array-bytes = { workspace = true, default-features = true } -sp-staking = { workspace = true, default-features = true } [features] default = ["std"] @@ -41,36 +34,23 @@ std = [ "array-bytes", "binary-merkle-tree/std", "codec/std", - "frame-benchmarking/std", - "frame-support/std", - "frame-system/std", + "frame/std", "log/std", "pallet-beefy/std", "pallet-mmr/std", "pallet-session/std", "scale-info/std", "serde", - "sp-api/std", "sp-consensus-beefy/std", - "sp-core/std", - "sp-io/std", - "sp-runtime/std", - "sp-staking/std", "sp-state-machine/std", ] try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", "pallet-beefy/try-runtime", + "frame/try-runtime", "pallet-mmr/try-runtime", "pallet-session/try-runtime", - "sp-runtime/try-runtime", ] runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", "pallet-mmr/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", - "sp-staking/runtime-benchmarks", + "frame/runtime-benchmarks", ] diff --git a/substrate/frame/beefy-mmr/src/benchmarking.rs b/substrate/frame/beefy-mmr/src/benchmarking.rs index 4fddd1bccf11..c5dd5ff10a7a 100644 --- a/substrate/frame/beefy-mmr/src/benchmarking.rs +++ b/substrate/frame/beefy-mmr/src/benchmarking.rs @@ -22,12 +22,9 @@ use super::*; use crate::Pallet as BeefyMmr; use codec::Encode; -use frame_benchmarking::v2::*; -use frame_support::traits::Hooks; -use frame_system::{Config as SystemConfig, Pallet as System}; +use frame::benchmarking::prelude::Pallet as System; use pallet_mmr::{Nodes, Pallet as Mmr}; use sp_consensus_beefy::Payload; -use sp_runtime::traits::One; pub trait Config: pallet_mmr::Config + crate::Config diff --git a/substrate/frame/beefy-mmr/src/lib.rs b/substrate/frame/beefy-mmr/src/lib.rs index c7fcdeff8799..64a9c6287ace 100644 --- a/substrate/frame/beefy-mmr/src/lib.rs +++ b/substrate/frame/beefy-mmr/src/lib.rs @@ -35,12 +35,6 @@ extern crate alloc; -use sp_runtime::{ - generic::OpaqueDigestItemId, - traits::{Convert, Header, Member}, - SaturatedConversion, -}; - use alloc::vec::Vec; use codec::Decode; use pallet_mmr::{primitives::AncestryProof, LeafDataProvider, NodesUtils, ParentNumberAndHash}; @@ -51,8 +45,7 @@ use sp_consensus_beefy::{ ValidatorSet as BeefyValidatorSet, }; -use frame_support::{crypto::ecdsa::ECDSAExt, pallet_prelude::Weight, traits::Get}; -use frame_system::pallet_prelude::{BlockNumberFor, HeaderFor}; +use frame::{prelude::*, runtime::apis::decl_runtime_apis}; pub use pallet::*; pub use weights::WeightInfo; @@ -73,7 +66,7 @@ where T: pallet_beefy::Config, { fn on_new_root(root: &sp_consensus_beefy::MmrRootHash) { - let digest = sp_runtime::generic::DigestItem::Consensus( + let digest = DigestItem::Consensus( sp_consensus_beefy::BEEFY_ENGINE_ID, codec::Encode::encode(&sp_consensus_beefy::ConsensusLog::< ::BeefyId, @@ -87,7 +80,7 @@ where pub struct BeefyEcdsaToEthereum; impl Convert> for BeefyEcdsaToEthereum { fn convert(beefy_id: sp_consensus_beefy::ecdsa_crypto::AuthorityId) -> Vec { - sp_core::ecdsa::Public::from(beefy_id) + Public::from(beefy_id) .to_eth_address() .map(|v| v.to_vec()) .map_err(|_| { @@ -97,14 +90,13 @@ impl Convert> for BeefyEc } } -type MerkleRootOf = <::Hashing as sp_runtime::traits::Hash>::Output; +type MerkleRootOf = <::Hashing as Hash>::Output; -#[frame_support::pallet] +#[frame::pallet] pub mod pallet { #![allow(missing_docs)] use super::*; - use frame_support::pallet_prelude::*; /// BEEFY-MMR pallet. #[pallet::pallet] @@ -377,7 +369,7 @@ impl Pallet { } } -sp_api::decl_runtime_apis! { +decl_runtime_apis! { /// API useful for BEEFY light clients. pub trait BeefyMmrApi where diff --git a/substrate/frame/beefy-mmr/src/mock.rs b/substrate/frame/beefy-mmr/src/mock.rs index 6756c618d706..0c750d8cfb43 100644 --- a/substrate/frame/beefy-mmr/src/mock.rs +++ b/substrate/frame/beefy-mmr/src/mock.rs @@ -18,18 +18,9 @@ use std::vec; use codec::Encode; -use frame_support::{ - construct_runtime, derive_impl, parameter_types, - traits::{ConstU32, ConstU64}, -}; + use sp_consensus_beefy::mmr::MmrLeafVersion; -use sp_io::TestExternalities; -use sp_runtime::{ - app_crypto::ecdsa::Public, - impl_opaque_keys, - traits::{ConvertInto, Keccak256, OpaqueKeys}, - BuildStorage, -}; + use sp_state_machine::BasicExternalities; use crate as pallet_beefy_mmr; @@ -37,7 +28,6 @@ use crate as pallet_beefy_mmr; pub use sp_consensus_beefy::{ ecdsa_crypto::AuthorityId as BeefyId, mmr::BeefyDataProvider, ConsensusLog, BEEFY_ENGINE_ID, }; -use sp_core::offchain::{testing::TestOffchainExt, OffchainDbExt, OffchainWorkerExt}; impl_opaque_keys! { pub struct MockSessionKeys { @@ -45,7 +35,7 @@ impl_opaque_keys! { } } -type Block = frame_system::mocking::MockBlock; +type Block = MockBlock; construct_runtime!( pub enum Test @@ -170,11 +160,11 @@ pub fn mock_authorities(vec: Vec) -> Vec<(u64, BeefyId)> { vec.into_iter().map(|id| ((id as u64), mock_beefy_id(id))).collect() } -pub fn new_test_ext(ids: Vec) -> TestExternalities { +pub fn new_test_ext(ids: Vec) -> TestState { new_test_ext_raw_authorities(mock_authorities(ids)) } -pub fn new_test_ext_raw_authorities(authorities: Vec<(u64, BeefyId)>) -> TestExternalities { +pub fn new_test_ext_raw_authorities(authorities: Vec<(u64, BeefyId)>) -> TestState { let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); let session_keys: Vec<_> = authorities @@ -193,7 +183,7 @@ pub fn new_test_ext_raw_authorities(authorities: Vec<(u64, BeefyId)>) -> TestExt .assimilate_storage(&mut t) .unwrap(); - let mut ext: TestExternalities = t.into(); + let mut ext: TestState = t.into(); let (offchain, _offchain_state) = TestOffchainExt::with_offchain_db(ext.offchain_db()); ext.register_extension(OffchainDbExt::new(offchain.clone())); ext.register_extension(OffchainWorkerExt::new(offchain)); diff --git a/substrate/frame/beefy-mmr/src/tests.rs b/substrate/frame/beefy-mmr/src/tests.rs index 297fb28647ac..7d09b07ffce7 100644 --- a/substrate/frame/beefy-mmr/src/tests.rs +++ b/substrate/frame/beefy-mmr/src/tests.rs @@ -24,11 +24,7 @@ use sp_consensus_beefy::{ AncestryHelper, Commitment, Payload, ValidatorSet, }; -use sp_core::H256; -use sp_io::TestExternalities; -use sp_runtime::{traits::Keccak256, DigestItem}; - -use frame_support::traits::OnInitialize; +use frame::traits::OnInitialize; use crate::mock::*; @@ -43,7 +39,7 @@ pub fn beefy_log(log: ConsensusLog) -> DigestItem { DigestItem::Consensus(BEEFY_ENGINE_ID, log.encode()) } -fn read_mmr_leaf(ext: &mut TestExternalities, key: Vec) -> MmrLeaf { +fn read_mmr_leaf(ext: &mut TestState, key: Vec) -> MmrLeaf { type Node = pallet_mmr::primitives::DataOrHash; ext.persist_offchain_overlay(); let offchain_db = ext.offchain_db(); diff --git a/substrate/frame/beefy-mmr/src/weights.rs b/substrate/frame/beefy-mmr/src/weights.rs index 5f7f7055311c..3bffc1ebb726 100644 --- a/substrate/frame/beefy-mmr/src/weights.rs +++ b/substrate/frame/beefy-mmr/src/weights.rs @@ -46,7 +46,7 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use frame::weights_prelude::*; use core::marker::PhantomData; /// Weight functions needed for `pallet_beefy_mmr`. diff --git a/substrate/frame/beefy/Cargo.toml b/substrate/frame/beefy/Cargo.toml index b8e952dfbd66..4f8258bd26ed 100644 --- a/substrate/frame/beefy/Cargo.toml +++ b/substrate/frame/beefy/Cargo.toml @@ -13,17 +13,14 @@ workspace = true [dependencies] codec = { features = ["derive"], workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } +frame = { workspace = true, features = ["runtime"] } log = { workspace = true } pallet-authorship = { workspace = true } pallet-session = { workspace = true } scale-info = { features = ["derive", "serde"], workspace = true } serde = { optional = true, workspace = true, default-features = true } sp-consensus-beefy = { features = ["serde"], workspace = true } -sp-runtime = { features = ["serde"], workspace = true } -sp-session = { workspace = true } -sp-staking = { features = ["serde"], workspace = true } +sp-staking = { optional = true, workspace = true } [dev-dependencies] frame-election-provider-support = { workspace = true, default-features = true } @@ -32,18 +29,14 @@ pallet-offences = { workspace = true, default-features = true } pallet-staking = { workspace = true, default-features = true } pallet-staking-reward-curve = { workspace = true, default-features = true } pallet-timestamp = { workspace = true, default-features = true } -sp-core = { workspace = true, default-features = true } -sp-io = { workspace = true, default-features = true } -sp-staking = { workspace = true, default-features = true } sp-state-machine = { workspace = true } [features] default = ["std"] std = [ "codec/std", + "frame/std", "frame-election-provider-support/std", - "frame-support/std", - "frame-system/std", "log/std", "pallet-authorship/std", "pallet-balances/std", @@ -54,22 +47,16 @@ std = [ "scale-info/std", "serde/std", "sp-consensus-beefy/std", - "sp-core/std", - "sp-io/std", - "sp-runtime/std", - "sp-session/std", - "sp-staking/std", "sp-state-machine/std", + "sp-staking/std", ] try-runtime = [ "frame-election-provider-support/try-runtime", - "frame-support/try-runtime", - "frame-system/try-runtime", + "frame/try-runtime", "pallet-authorship/try-runtime", "pallet-balances/try-runtime", "pallet-offences/try-runtime", "pallet-session/try-runtime", "pallet-staking/try-runtime", "pallet-timestamp/try-runtime", - "sp-runtime/try-runtime", ] diff --git a/substrate/frame/beefy/src/default_weights.rs b/substrate/frame/beefy/src/default_weights.rs index 6b83015459d6..e18c2a8503d1 100644 --- a/substrate/frame/beefy/src/default_weights.rs +++ b/substrate/frame/beefy/src/default_weights.rs @@ -18,10 +18,7 @@ //! Default weights for the BEEFY Pallet //! This file was not auto-generated. -use frame_support::weights::{ - constants::{RocksDbWeight as DbWeight, WEIGHT_REF_TIME_PER_MICROS, WEIGHT_REF_TIME_PER_NANOS}, - Weight, -}; +use frame::weights_prelude::*; impl crate::WeightInfo for () { fn report_voting_equivocation( diff --git a/substrate/frame/beefy/src/equivocation.rs b/substrate/frame/beefy/src/equivocation.rs index 294d64427ef8..9e1b793f1243 100644 --- a/substrate/frame/beefy/src/equivocation.rs +++ b/substrate/frame/beefy/src/equivocation.rs @@ -36,21 +36,14 @@ use alloc::{vec, vec::Vec}; use codec::{self as codec, Decode, Encode}; -use frame_support::traits::{Get, KeyOwnerProofSystem}; -use frame_system::pallet_prelude::{BlockNumberFor, HeaderFor}; use log::{error, info}; use sp_consensus_beefy::{ check_commitment_signature, AncestryHelper, DoubleVotingProof, ForkVotingProof, FutureBlockVotingProof, ValidatorSetId, KEY_TYPE as BEEFY_KEY_TYPE, }; -use sp_runtime::{ - transaction_validity::{ - InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity, - TransactionValidityError, ValidTransaction, - }, - DispatchError, KeyTypeId, Perbill, RuntimeAppPublic, -}; -use sp_session::{GetSessionNumber, GetValidatorCount}; + +use frame::testing_prelude::*; +use frame::deps::sp_session::{GetSessionNumber, GetValidatorCount}; use sp_staking::{ offence::{Kind, Offence, OffenceReportSystem, ReportOffence}, SessionIndex, diff --git a/substrate/frame/beefy/src/lib.rs b/substrate/frame/beefy/src/lib.rs index e57fc0e21bc1..cf5abdc304ba 100644 --- a/substrate/frame/beefy/src/lib.rs +++ b/substrate/frame/beefy/src/lib.rs @@ -30,29 +30,18 @@ use alloc::{boxed::Box, vec::Vec}; use codec::{Encode, MaxEncodedLen}; use log; -use frame_support::{ - dispatch::{DispatchResultWithPostInfo, Pays}, - pallet_prelude::*, - traits::{Get, OneSessionHandler}, - weights::{constants::RocksDbWeight as DbWeight, Weight}, - BoundedSlice, BoundedVec, Parameter, -}; -use frame_system::{ - ensure_none, ensure_signed, - pallet_prelude::{BlockNumberFor, HeaderFor, OriginFor}, -}; +use frame::weights_prelude::DbWeight; +use sp_staking::{offence::OffenceReportSystem, SessionIndex}; + use sp_consensus_beefy::{ AncestryHelper, AncestryHelperWeightInfo, AuthorityIndex, BeefyAuthorityId, ConsensusLog, DoubleVotingProof, ForkVotingProof, FutureBlockVotingProof, OnNewValidatorSet, ValidatorSet, BEEFY_ENGINE_ID, GENESIS_AUTHORITY_SET_ID, }; -use sp_runtime::{ - generic::DigestItem, - traits::{IsMember, Member, One}, - RuntimeAppPublic, -}; -use sp_session::{GetSessionNumber, GetValidatorCount}; -use sp_staking::{offence::OffenceReportSystem, SessionIndex}; + +use frame::deps::sp_session::{GetSessionNumber, GetValidatorCount}; + +use frame::runtime::prelude::*; use crate::equivocation::EquivocationEvidenceFor; pub use crate::equivocation::{EquivocationOffence, EquivocationReportSystem, TimeSlot}; @@ -60,10 +49,9 @@ pub use pallet::*; const LOG_TARGET: &str = "runtime::beefy"; -#[frame_support::pallet] +#[frame::pallet] pub mod pallet { use super::*; - use frame_system::{ensure_root, pallet_prelude::BlockNumberFor}; #[pallet::config] pub trait Config: frame_system::Config { @@ -71,7 +59,7 @@ pub mod pallet { type BeefyId: Member + Parameter // todo: use custom signature hashing type instead of hardcoded `Keccak256` - + BeefyAuthorityId + + BeefyAuthorityId + MaybeSerializeDeserialize + MaxEncodedLen; @@ -656,7 +644,7 @@ impl Pallet { } } -impl sp_runtime::BoundToRuntimeAppPublic for Pallet { +impl BoundToRuntimeAppPublic for Pallet { type Public = T::BeefyId; } diff --git a/substrate/frame/beefy/src/mock.rs b/substrate/frame/beefy/src/mock.rs index fc731e3bc50e..1ecdbbe7532d 100644 --- a/substrate/frame/beefy/src/mock.rs +++ b/substrate/frame/beefy/src/mock.rs @@ -23,22 +23,8 @@ use frame_election_provider_support::{ bounds::{ElectionBounds, ElectionBoundsBuilder}, onchain, SequentialPhragmen, Weight, }; -use frame_support::{ - construct_runtime, derive_impl, parameter_types, - traits::{ConstU32, ConstU64, KeyOwnerProofSystem, OnFinalize, OnInitialize}, -}; -use frame_system::pallet_prelude::HeaderFor; + use pallet_session::historical as pallet_session_historical; -use sp_core::{crypto::KeyTypeId, ConstU128}; -use sp_runtime::{ - app_crypto::ecdsa::Public, - curve::PiecewiseLinear, - impl_opaque_keys, - testing::TestXt, - traits::{Header as HeaderT, OpaqueKeys}, - BuildStorage, Perbill, -}; -use sp_staking::{EraIndex, SessionIndex}; use sp_state_machine::BasicExternalities; use crate as pallet_beefy; @@ -52,7 +38,7 @@ impl_opaque_keys! { } } -type Block = frame_system::mocking::MockBlock; +type Block = MockBlock; construct_runtime!( pub enum Test @@ -276,7 +262,7 @@ impl ExtBuilder { self } - pub fn build(self) -> sp_io::TestExternalities { + pub fn build(self) -> TestState { let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); let balances: Vec<_> = diff --git a/substrate/frame/beefy/src/tests.rs b/substrate/frame/beefy/src/tests.rs index 1bd0a72b25ec..38b87371075a 100644 --- a/substrate/frame/beefy/src/tests.rs +++ b/substrate/frame/beefy/src/tests.rs @@ -18,11 +18,7 @@ use codec::Encode; use std::vec; -use frame_support::{ - assert_err, assert_ok, - dispatch::{DispatchResultWithPostInfo, Pays}, - traits::{Currency, KeyOwnerProofSystem, OnInitialize}, -}; + use sp_consensus_beefy::{ check_double_voting_proof, ecdsa_crypto, known_payloads::MMR_ROOT_ID, @@ -32,8 +28,7 @@ use sp_consensus_beefy::{ }, Payload, ValidatorSet, ValidatorSetId, KEY_TYPE as BEEFY_KEY_TYPE, }; -use sp_runtime::DigestItem; -use sp_session::MembershipProof; +// use sp_session::MembershipProof; use crate::{self as beefy, mock::*, Call, Config, Error, WeightInfoExt}; @@ -218,7 +213,6 @@ pub fn test_authorities() -> Vec { #[test] fn should_sign_and_verify() { - use sp_runtime::traits::Keccak256; let set_id = 3; let payload1 = Payload::from_single_entry(MMR_ROOT_ID, vec![42]); @@ -672,7 +666,7 @@ fn report_double_voting_invalid_equivocation_proof() { #[test] fn report_double_voting_validate_unsigned_prevents_duplicates() { - use sp_runtime::transaction_validity::{ + transaction_validity::{ InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity, ValidTransaction, }; @@ -708,7 +702,7 @@ fn report_double_voting_validate_unsigned_prevents_duplicates() { // only local/inblock reports are allowed assert_eq!( - ::validate_unsigned( + ::validate_unsigned( TransactionSource::External, &call, ), @@ -719,7 +713,7 @@ fn report_double_voting_validate_unsigned_prevents_duplicates() { let tx_tag = (equivocation_key, set_id, 3u64); assert_eq!( - ::validate_unsigned( + ::validate_unsigned( TransactionSource::Local, &call, ), @@ -733,7 +727,7 @@ fn report_double_voting_validate_unsigned_prevents_duplicates() { ); // the pre dispatch checks should also pass - assert_ok!(::pre_dispatch(&call)); + assert_ok!(::pre_dispatch(&call)); // we submit the report Beefy::report_double_voting_unsigned( @@ -746,7 +740,7 @@ fn report_double_voting_validate_unsigned_prevents_duplicates() { // the report should now be considered stale and the transaction is invalid // the check for staleness should be done on both `validate_unsigned` and on `pre_dispatch` assert_err!( - ::validate_unsigned( + ::validate_unsigned( TransactionSource::Local, &call, ), @@ -754,7 +748,7 @@ fn report_double_voting_validate_unsigned_prevents_duplicates() { ); assert_err!( - ::pre_dispatch(&call), + ::pre_dispatch(&call), InvalidTransaction::Stale, ); }); diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index 1c4b2ed5b821..d8c06abe6efc 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -201,11 +201,17 @@ pub mod prelude { /// Dispatch types from `frame-support`, other fundamental traits #[doc(no_inline)] - pub use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo}; - pub use frame_support::traits::{ - Contains, EitherOf, EstimateNextSessionRotation, Everything, IsSubType, MapSuccess, - NoOpPoll, OnRuntimeUpgrade, OneSessionHandler, RankedMembers, RankedMembersSwapHandler, - VariantCount, VariantCountOf, + pub use frame_support::dispatch::{ + DispatchResultWithPostInfo, GetDispatchInfo, Pays, PostDispatchInfo, + }; + pub use frame_support::{ + traits::{ + Contains, Currency, EitherOf, EstimateNextSessionRotation, Everything, Get, Hooks, + IsSubType, KeyOwnerProofSystem, MapSuccess, NoOpPoll, OnFinalize, OnInitialize, + OnRuntimeUpgrade, OneSessionHandler, RankedMembers, RankedMembersSwapHandler, + VariantCount, VariantCountOf, + }, + Parameter, }; /// Pallet prelude of `frame-system`. @@ -231,9 +237,14 @@ pub mod prelude { /// Runtime traits #[doc(no_inline)] - pub use sp_runtime::traits::{ - BlockNumberProvider, Bounded, Convert, DispatchInfoOf, Dispatchable, ReduceBy, - ReplaceWithDefault, SaturatedConversion, Saturating, StaticLookup, TrailingZeroInput, + pub use sp_runtime::{ + generic::{DigestItem, OpaqueDigestItemId}, + traits::{ + BlockNumberProvider, Bounded, Convert, DispatchInfoOf, Dispatchable, Header, IsMember, + Member, ReduceBy, ReplaceWithDefault, SaturatedConversion, Saturating, StaticLookup, + TrailingZeroInput, ValidateUnsigned, + }, + KeyTypeId, Perbill, }; /// Bounded storage related types. @@ -242,7 +253,8 @@ pub mod prelude { /// Other error/result types for runtime #[doc(no_inline)] pub use sp_runtime::{ - BoundToRuntimeAppPublic, DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError, + BoundToRuntimeAppPublic, DispatchErrorWithPostInfo, DispatchResultWithInfo, + RuntimeAppPublic, TokenError, }; } @@ -297,7 +309,10 @@ pub mod weights_prelude { pub use frame_support::{ traits::Get, weights::{ - constants::{ParityDbWeight, RocksDbWeight}, + constants::{ + ParityDbWeight, RocksDbWeight, RocksDbWeight as DbWeight, + WEIGHT_REF_TIME_PER_MICROS, WEIGHT_REF_TIME_PER_NANOS, + }, Weight, }, }; @@ -403,17 +418,27 @@ pub mod runtime { pub use sp_version::NativeVersion; /// Macro to implement runtime APIs. - pub use sp_api::impl_runtime_apis; + pub use sp_api::{decl_runtime_apis, impl_runtime_apis}; // Types often used in the runtime APIs. - pub use sp_core::OpaqueMetadata; + pub use sp_core::{ + offchain::{testing::TestOffchainExt, OffchainDbExt, OffchainWorkerExt}, + OpaqueMetadata, + }; + pub use sp_genesis_builder::{ PresetId, Result as GenesisBuilderResult, DEV_RUNTIME_PRESET, LOCAL_TESTNET_RUNTIME_PRESET, }; pub use sp_inherents::{CheckInherentsResult, InherentData}; pub use sp_keyring::Sr25519Keyring; - pub use sp_runtime::{ApplyExtrinsicResult, ExtrinsicInclusionMode}; + pub use sp_runtime::{ + transaction_validity::{ + InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity, + TransactionValidityError, ValidTransaction, + }, + ApplyExtrinsicResult, ExtrinsicInclusionMode, + }; } /// Types and traits for runtimes that implement runtime APIs. @@ -535,6 +560,7 @@ pub mod traits { /// This is already part of the [`prelude`]. pub mod arithmetic { pub use sp_arithmetic::{traits::*, *}; + pub use sp_runtime::traits::One; } /// All derive macros used in frame. @@ -556,6 +582,10 @@ pub mod hashing { pub use sp_runtime::traits::{BlakeTwo256, Hash, Keccak256}; } +pub use sp_runtime::{ + app_crypto::ecdsa::Public, curve::PiecewiseLinear, impl_opaque_keys, testing::TestXt, +}; + /// All account management related traits. /// /// This is already part of the [`prelude`]. @@ -583,6 +613,7 @@ pub mod deps { pub use sp_core; pub use sp_io; pub use sp_runtime; + pub use sp_session; pub use codec; pub use scale_info; From e609042148a992f1a9c6f78352b8554b996225cf Mon Sep 17 00:00:00 2001 From: Nathy-bajo Date: Tue, 28 Jan 2025 21:17:36 +0100 Subject: [PATCH 2/2] more changes --- Cargo.lock | 2 +- substrate/frame/Cargo.toml | 2 ++ substrate/frame/beefy-mmr/src/lib.rs | 2 +- substrate/frame/beefy/Cargo.toml | 2 -- substrate/frame/beefy/src/equivocation.rs | 2 +- substrate/frame/beefy/src/lib.rs | 2 +- substrate/frame/beefy/src/tests.rs | 1 + substrate/frame/src/lib.rs | 4 +++- 8 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c58e8dbe6069..eb570aa35d03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12468,7 +12468,6 @@ dependencies = [ "scale-info", "serde", "sp-consensus-beefy 13.0.0", - "sp-staking 26.0.0", "sp-state-machine 0.35.0", ] @@ -19411,6 +19410,7 @@ dependencies = [ "sp-offchain 26.0.0", "sp-runtime 31.0.1", "sp-session 27.0.0", + "sp-staking 26.0.0", "sp-storage 19.0.0", "sp-transaction-pool 26.0.0", "sp-version 29.0.0", diff --git a/substrate/frame/Cargo.toml b/substrate/frame/Cargo.toml index 6c5724472a76..fb45acd04ed1 100644 --- a/substrate/frame/Cargo.toml +++ b/substrate/frame/Cargo.toml @@ -48,6 +48,7 @@ sp-session = { optional = true, workspace = true } sp-storage = { optional = true, workspace = true } sp-transaction-pool = { optional = true, workspace = true } sp-version = { optional = true, workspace = true } +sp-staking = { optional = true, workspace = true } frame-executive = { optional = true, workspace = true } frame-system-rpc-runtime-api = { optional = true, workspace = true } @@ -110,6 +111,7 @@ std = [ "sp-storage/std", "sp-transaction-pool?/std", "sp-version?/std", + "sp-staking/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/substrate/frame/beefy-mmr/src/lib.rs b/substrate/frame/beefy-mmr/src/lib.rs index 64a9c6287ace..f48d4623faeb 100644 --- a/substrate/frame/beefy-mmr/src/lib.rs +++ b/substrate/frame/beefy-mmr/src/lib.rs @@ -80,7 +80,7 @@ where pub struct BeefyEcdsaToEthereum; impl Convert> for BeefyEcdsaToEthereum { fn convert(beefy_id: sp_consensus_beefy::ecdsa_crypto::AuthorityId) -> Vec { - Public::from(beefy_id) + frame::deps::sp_core::ecdsa::Public::from(beefy_id) .to_eth_address() .map(|v| v.to_vec()) .map_err(|_| { diff --git a/substrate/frame/beefy/Cargo.toml b/substrate/frame/beefy/Cargo.toml index 4f8258bd26ed..083956180e8a 100644 --- a/substrate/frame/beefy/Cargo.toml +++ b/substrate/frame/beefy/Cargo.toml @@ -20,7 +20,6 @@ pallet-session = { workspace = true } scale-info = { features = ["derive", "serde"], workspace = true } serde = { optional = true, workspace = true, default-features = true } sp-consensus-beefy = { features = ["serde"], workspace = true } -sp-staking = { optional = true, workspace = true } [dev-dependencies] frame-election-provider-support = { workspace = true, default-features = true } @@ -48,7 +47,6 @@ std = [ "serde/std", "sp-consensus-beefy/std", "sp-state-machine/std", - "sp-staking/std", ] try-runtime = [ "frame-election-provider-support/try-runtime", diff --git a/substrate/frame/beefy/src/equivocation.rs b/substrate/frame/beefy/src/equivocation.rs index 9e1b793f1243..2bdf8d53c6eb 100644 --- a/substrate/frame/beefy/src/equivocation.rs +++ b/substrate/frame/beefy/src/equivocation.rs @@ -44,7 +44,7 @@ use sp_consensus_beefy::{ use frame::testing_prelude::*; use frame::deps::sp_session::{GetSessionNumber, GetValidatorCount}; -use sp_staking::{ +use frame::deps::sp_staking::{ offence::{Kind, Offence, OffenceReportSystem, ReportOffence}, SessionIndex, }; diff --git a/substrate/frame/beefy/src/lib.rs b/substrate/frame/beefy/src/lib.rs index cf5abdc304ba..be4cb7cfae58 100644 --- a/substrate/frame/beefy/src/lib.rs +++ b/substrate/frame/beefy/src/lib.rs @@ -31,7 +31,7 @@ use codec::{Encode, MaxEncodedLen}; use log; use frame::weights_prelude::DbWeight; -use sp_staking::{offence::OffenceReportSystem, SessionIndex}; +use frame::deps::sp_staking::{offence::OffenceReportSystem, SessionIndex}; use sp_consensus_beefy::{ AncestryHelper, AncestryHelperWeightInfo, AuthorityIndex, BeefyAuthorityId, ConsensusLog, diff --git a/substrate/frame/beefy/src/tests.rs b/substrate/frame/beefy/src/tests.rs index 38b87371075a..e8fb76638b63 100644 --- a/substrate/frame/beefy/src/tests.rs +++ b/substrate/frame/beefy/src/tests.rs @@ -30,6 +30,7 @@ use sp_consensus_beefy::{ }; // use sp_session::MembershipProof; + use crate::{self as beefy, mock::*, Call, Config, Error, WeightInfoExt}; fn init_block(block: u64) { diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index d8c06abe6efc..9892432eee0a 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -422,7 +422,7 @@ pub mod runtime { // Types often used in the runtime APIs. pub use sp_core::{ - offchain::{testing::TestOffchainExt, OffchainDbExt, OffchainWorkerExt}, + offchain::testing, OpaqueMetadata, }; @@ -580,6 +580,7 @@ pub mod derive { pub mod hashing { pub use sp_core::{hashing::*, H160, H256, H512, U256, U512}; pub use sp_runtime::traits::{BlakeTwo256, Hash, Keccak256}; + pub use frame_support::crypto::ecdsa::ECDSAExt; } pub use sp_runtime::{ @@ -614,6 +615,7 @@ pub mod deps { pub use sp_io; pub use sp_runtime; pub use sp_session; + pub use sp_staking; pub use codec; pub use scale_info;