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

Migrate pallet-message-queue to use umbrella crate #7212

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
10 changes: 1 addition & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 4 additions & 24 deletions substrate/frame/message-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,32 @@ workspace = true

[dependencies]
codec = { features = ["derive"], workspace = true }
frame = { workspace = true, features = ["runtime"]}
environmental = { workspace = true }
log = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
serde = { optional = true, features = ["derive"], workspace = true, default-features = true }

sp-arithmetic = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-weights = { workspace = true }

frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }

[dev-dependencies]
rand = { workspace = true, default-features = true }
rand_distr = { workspace = true }
sp-crypto-hashing = { workspace = true, default-features = true }
sp-tracing = { workspace = true, default-features = true }

[features]
default = ["std"]
std = [
"codec/std",
"frame/std",
"environmental/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"log/std",
"scale-info/std",
"sp-arithmetic/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-tracing/std",
"sp-weights/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"frame/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
"frame/try-runtime",
]
5 changes: 1 addition & 4 deletions substrate/frame/message-queue/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@

use super::{mock_helpers::*, Pallet as MessageQueue, *};

use frame_benchmarking::v2::*;
use frame_support::traits::Get;
use frame_system::RawOrigin;
use sp_io::hashing::blake2_256;
use frame::benchmarking::prelude::*;

#[benchmarks(
where
Expand Down
6 changes: 3 additions & 3 deletions substrate/frame/message-queue/src/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ use crate::{
};

use crate as pallet_message_queue;
use frame_support::{derive_impl, parameter_types};
use frame::testing_prelude::*;
use rand::{rngs::StdRng, Rng, SeedableRng};
use rand_distr::Pareto;
use std::collections::{BTreeMap, BTreeSet};

type Block = frame_system::mocking::MockBlock<Test>;
type Block = MockBlock<Test>;

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand Down
32 changes: 10 additions & 22 deletions substrate/frame/message-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,28 +208,16 @@
use alloc::{vec, vec::Vec};
use codec::{Codec, Decode, Encode, MaxEncodedLen};
use core::{fmt::Debug, ops::Deref};
use frame_support::{
defensive,
pallet_prelude::*,
traits::{
Defensive, DefensiveSaturating, DefensiveTruncateFrom, EnqueueMessage,
ExecuteOverweightError, Footprint, ProcessMessage, ProcessMessageError, QueueFootprint,
QueuePausedQuery, ServiceQueues,
},
BoundedSlice, CloneNoBound, DefaultNoBound,
};
use frame_system::pallet_prelude::*;

use frame::{prelude::*, runtime::prelude::WeightMeter};
pub use pallet::*;
use scale_info::TypeInfo;
use sp_arithmetic::traits::{BaseArithmetic, Unsigned};
use sp_core::{defer, H256};
use sp_runtime::{
traits::{One, Zero},
SaturatedConversion, Saturating, TransactionOutcome,
};
use sp_weights::WeightMeter;

pub use weights::WeightInfo;

#[cfg(feature = "try-runtime")]
use frame::try_runtime::TryRuntimeError;

/// Type for identifying a page.
type PageIndex = u32;

Expand Down Expand Up @@ -462,7 +450,7 @@
fn on_queue_changed(_: Id, _: QueueFootprint) {}
}

#[frame_support::pallet]
#[frame::pallet]
pub mod pallet {
use super::*;

Expand Down Expand Up @@ -1348,7 +1336,7 @@
/// * `first` <= `last`
/// * Every page can be decoded into peek_* functions
#[cfg(any(test, feature = "try-runtime", feature = "std"))]
pub fn do_try_state() -> Result<(), sp_runtime::TryRuntimeError> {
pub fn do_try_state() -> Result<(), frame::try_runtime::TryRuntimeError> {

Check failure on line 1339 in substrate/frame/message-queue/src/lib.rs

View workflow job for this annotation

GitHub Actions / cargo-check-all-crate-macos

failed to resolve: could not find `try_runtime` in `frame`
Nathy-bajo marked this conversation as resolved.
Show resolved Hide resolved
Nathy-bajo marked this conversation as resolved.
Show resolved Hide resolved
// Checking memory corruption for BookStateFor
ensure!(
BookStateFor::<T>::iter_keys().count() == BookStateFor::<T>::iter_values().count(),
Expand Down Expand Up @@ -1500,7 +1488,7 @@
meter: &mut WeightMeter,
overweight_limit: Weight,
) -> MessageExecutionStatus {
let mut id = sp_io::hashing::blake2_256(message);
let mut id = blake2_256(message);
use ProcessMessageError::*;
let prev_consumed = meter.consumed();

Expand Down Expand Up @@ -1626,7 +1614,7 @@
let hold = token::with(|t| t.take()).ok_or(()).defensive()?.ok_or(())?;

// Put the token back when we're done.
defer! {
frame::deps::sp_core::defer! {
token::with(|t| {
*t = Some(hold);
});
Expand Down
12 changes: 6 additions & 6 deletions substrate/frame/message-queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ use super::*;

use crate as pallet_message_queue;
use alloc::collections::btree_map::BTreeMap;
use frame_support::{derive_impl, parameter_types};
use sp_runtime::BuildStorage;
use frame::testing_prelude::*;

type Block = frame_system::mocking::MockBlock<Test>;

frame_support::construct_runtime!(
type Block = MockBlock<Test>;

construct_runtime!(
pub enum Test
{
System: frame_system,
Expand Down Expand Up @@ -298,7 +298,7 @@ impl QueuePausedQuery<MessageOrigin> for MockedQueuePauser {
/// Create new test externalities.
///
/// Is generic since it is used by the unit test, integration tests and benchmarks.
pub fn new_test_ext<T: Config>() -> sp_io::TestExternalities
pub fn new_test_ext<T: Config>() -> TestState
where
frame_system::pallet_prelude::BlockNumberFor<T>: From<u32>,
{
Expand All @@ -307,7 +307,7 @@ where
QueueChanges::take();
NumMessagesErrored::take();
let t = frame_system::GenesisConfig::<T>::default().build_storage().unwrap();
let mut ext = sp_io::TestExternalities::new(t);
let mut ext = TestState::new(t);
ext.execute_with(|| frame_system::Pallet::<T>::set_block_number(1.into()));
ext
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/message-queue/src/mock_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

use crate::*;
use alloc::vec::Vec;
use frame_support::traits::Defensive;
use frame::testing_prelude::*;

/// Converts `Self` into a `Weight` by using `Self` for all components.
pub trait IntoWeight {
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/message-queue/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

use crate::{mock::*, *};

use frame_support::{assert_noop, assert_ok, assert_storage_noop, StorageNoopGuard};
use rand::{rngs::StdRng, Rng, SeedableRng};
use sp_crypto_hashing::blake2_256;
use frame::testing_prelude::*;
use frame::deps::sp_io;

#[test]
fn mocked_weight_works() {
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/message-queue/src/weights.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 18 additions & 9 deletions substrate/frame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,19 @@ 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::{
defensive, defensive_assert,
traits::{
Contains, Defensive, DefensiveSaturating, DefensiveTruncateFrom, EitherOf,
EnqueueMessage, EstimateNextSessionRotation, ExecuteOverweightError, Footprint, Get,
IsSubType, MapSuccess, NoOpPoll, OnRuntimeUpgrade, OneSessionHandler, ProcessMessage,
ProcessMessageError, QueueFootprint, QueuePausedQuery, RankedMembers,
RankedMembersSwapHandler, ServiceQueues,
},
};

pub use frame_support::storage::TransactionOutcome;

/// Pallet prelude of `frame-system`.
#[doc(no_inline)]
pub use frame_system::pallet_prelude::*;
Expand All @@ -233,7 +240,8 @@ pub mod prelude {
#[doc(no_inline)]
pub use sp_runtime::traits::{
BlockNumberProvider, Bounded, Convert, DispatchInfoOf, Dispatchable, ReduceBy,
ReplaceWithDefault, SaturatedConversion, Saturating, StaticLookup, TrailingZeroInput,
ReplaceWithDefault, SaturatedConversion, Saturating, StaticLookup,
TrailingZeroInput,
};

/// Bounded storage related types.
Expand Down Expand Up @@ -326,7 +334,7 @@ pub mod testing_prelude {
/// Other helper macros from `frame_support` that help with asserting in tests.
pub use frame_support::{
assert_err, assert_err_ignore_postinfo, assert_error_encoded_size, assert_noop, assert_ok,
assert_storage_noop, ensure, hypothetically, storage_alias,
assert_storage_noop, ensure, hypothetically, storage_alias, StorageNoopGuard,
};

pub use frame_system::{self, mocking::*, RunToBlockHooks};
Expand Down Expand Up @@ -385,7 +393,7 @@ pub mod runtime {
};

/// Used for simple fee calculation.
pub use frame_support::weights::{self, FixedFee, NoFee};
pub use frame_support::weights::{self, FixedFee, NoFee, WeightMeter};

/// Primary types used to parameterize `EnsureOrigin` and `EnsureRootWithArg`.
pub use frame_system::{
Expand Down Expand Up @@ -535,6 +543,7 @@ pub mod traits {
/// This is already part of the [`prelude`].
pub mod arithmetic {
pub use sp_arithmetic::{traits::*, *};
pub use sp_runtime::traits::{Zero, One};
}

/// All derive macros used in frame.
Expand All @@ -544,8 +553,8 @@ pub mod derive {
pub use codec::{Decode, Encode};
pub use core::fmt::Debug;
pub use frame_support::{
CloneNoBound, DebugNoBound, DefaultNoBound, EqNoBound, OrdNoBound, PartialEqNoBound,
PartialOrdNoBound, RuntimeDebugNoBound,
BoundedSlice, CloneNoBound, DebugNoBound, DefaultNoBound, EqNoBound, OrdNoBound,
PartialEqNoBound, PartialOrdNoBound, RuntimeDebugNoBound,
};
pub use scale_info::TypeInfo;
pub use sp_runtime::RuntimeDebug;
Expand Down
Loading