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-tips to umbrella crate #6532

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
8 changes: 1 addition & 7 deletions Cargo.lock

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

52 changes: 50 additions & 2 deletions substrate/frame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,34 @@ pub mod prelude {
/// All hashing related things
pub use super::hashing::*;

/// All arithmetic types used for safe math.
pub use super::arithmetic::*;

/// All account related things.
pub use super::account::*;

/// Runtime traits
#[doc(no_inline)]
pub use sp_runtime::traits::{
BlockNumberProvider, Bounded, DispatchInfoOf, Dispatchable, SaturatedConversion,
Saturating, StaticLookup, TrailingZeroInput,
};

/// Currency related traits.
bennethxyz marked this conversation as resolved.
Show resolved Hide resolved
pub use frame_support::traits::{
tokens::{PayFromAccount, UnityAssetBalanceConversion},
BalanceStatus::{self, Reserved},
Currency,
ExistenceRequirement::KeepAlive,
LockableCurrency, OnUnbalanced, ReservableCurrency,
};

/// Other error/result types for runtime
#[doc(no_inline)]
pub use sp_runtime::{DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError};
pub use sp_runtime::{
DispatchError::{self, BadOrigin},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DispatchError::{self, BadOrigin},
DispatchError,

DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError,
};
}

#[cfg(any(feature = "try-runtime", test))]
Expand Down Expand Up @@ -308,7 +326,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, storage_alias,
assert_storage_noop, ensure, storage_alias,
};

pub use frame_system::{self, mocking::*};
Expand All @@ -334,6 +352,11 @@ pub mod runtime {
pub mod prelude {
pub use crate::prelude::*;

/// All things runtime metadata.
pub use frame_support::traits::{
CallMetadata, GetCallMetadata, PalletInfoAccess, STORAGE_VERSION_STORAGE_KEY_POSTFIX,
};

/// All of the types related to the FRAME runtime executive.
pub use frame_executive::*;

Expand All @@ -350,6 +373,12 @@ pub mod runtime {
/// Macro to easily derive the `Config` trait of various pallet for `Runtime`.
pub use frame_support::derive_impl;

/// sovereign account ID for a pallet.
pub use frame_support::PalletId;

/// Runtime storage traits amd types.
pub use frame_support::storage::{migration::*, KeyPrefixIterator, StoragePrefixedMap};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub use frame_support::storage::{migration::*, KeyPrefixIterator, StoragePrefixedMap};
pub use frame_support::storage::{KeyPrefixIterator, StoragePrefixedMap};

I don't see why migration items should be in this prelude


/// Macros to easily impl traits such as `Get` for types.
// TODO: using linking in the Get in the line above triggers an ICE :/
pub use frame_support::{ord_parameter_types, parameter_types};
Expand Down Expand Up @@ -532,6 +561,25 @@ pub mod hashing {
pub use sp_runtime::traits::{BlakeTwo256, Hash, Keccak256};
}

/// All account management related traits.
///
/// This is already part of the [`prelude`].
pub mod account {
pub use frame_support::traits::{
ChangeMembers, ContainsLengthBound, EitherOfDiverse, InitializeMembers, NeverEnsureOrigin,
SortedMembers,
};
pub use sp_runtime::traits::{AccountIdConversion, IdentifyAccount, IdentityLookup};
}

/// Utility traits not tied to any direct operation(i.e. currency, account management e.t.c.) in the
/// runtime.
pub mod utility {
pub use frame_support::traits::{
Everything, InsideBoth, InstanceFilter, VariantCount, VariantCountOf,
};
}

/// Access to all of the dependencies of this crate. In case the prelude re-exports are not enough,
/// this module can be used.
///
Expand Down
25 changes: 4 additions & 21 deletions substrate/frame/tips/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,30 @@ codec = { features = ["derive"], workspace = true }
log = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
serde = { features = ["derive"], optional = true, workspace = true, default-features = true }
frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"] }
pallet-treasury = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }

[dev-dependencies]
pallet-balances = { workspace = true, default-features = true }
sp-storage = { workspace = true, default-features = true }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"frame/std",
"log/std",
"pallet-balances/std",
"pallet-treasury/std",
"scale-info/std",
"serde",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-storage/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"frame/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame/try-runtime",
"pallet-balances/try-runtime",
"pallet-treasury/try-runtime",
"sp-runtime/try-runtime",
]
20 changes: 7 additions & 13 deletions substrate/frame/tips/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@

#![cfg(feature = "runtime-benchmarks")]

use frame_benchmarking::v1::{
account, benchmarks_instance_pallet, whitelisted_caller, BenchmarkError,
};
use frame_support::ensure;
use frame_system::RawOrigin;
use sp_runtime::traits::Saturating;

use super::*;
use crate::Pallet as TipsMod;
use frame::benchmarking::prelude::*;

const SEED: u32 = 0;

Expand Down Expand Up @@ -78,7 +72,7 @@ fn create_tips<T: Config<I>, I: 'static>(
}
Tips::<T, I>::mutate(hash, |maybe_tip| {
if let Some(open_tip) = maybe_tip {
open_tip.closes = Some(frame_system::pallet_prelude::BlockNumberFor::<T>::zero());
open_tip.closes = Some(BlockNumberFor::<T>::zero());
}
});
Ok(())
Expand All @@ -97,7 +91,7 @@ benchmarks_instance_pallet! {
let awesome_person_lookup = T::Lookup::unlookup(awesome_person);
// Whitelist caller account from further DB operations.
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller);
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
add_to_whitelist(caller_key.into());
}: _(RawOrigin::Signed(caller), reason, awesome_person_lookup)

retract_tip {
Expand All @@ -113,7 +107,7 @@ benchmarks_instance_pallet! {
let hash = T::Hashing::hash_of(&(&reason_hash, &awesome_person));
// Whitelist caller account from further DB operations.
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller);
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
add_to_whitelist(caller_key.into());
}: _(RawOrigin::Signed(caller), hash)

tip_new {
Expand All @@ -124,7 +118,7 @@ benchmarks_instance_pallet! {
let beneficiary_lookup = T::Lookup::unlookup(beneficiary);
// Whitelist caller account from further DB operations.
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller);
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
add_to_whitelist(caller_key.into());
}: _(RawOrigin::Signed(caller), reason, beneficiary_lookup, value)

tip {
Expand All @@ -145,7 +139,7 @@ benchmarks_instance_pallet! {
let caller = account("member", t - 1, SEED);
// Whitelist caller account from further DB operations.
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller);
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
add_to_whitelist(caller_key.into());
}: _(RawOrigin::Signed(caller), hash, value)

close_tip {
Expand Down Expand Up @@ -175,7 +169,7 @@ benchmarks_instance_pallet! {
let caller = account("caller", t, SEED);
// Whitelist caller account from further DB operations.
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller);
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
add_to_whitelist(caller_key.into());
}: _(RawOrigin::Signed(caller), hash)

slash_tip {
Expand Down
30 changes: 6 additions & 24 deletions substrate/frame/tips/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,16 @@ pub mod migrations;
pub mod weights;

extern crate alloc;

use sp_runtime::{
traits::{AccountIdConversion, BadOrigin, Hash, StaticLookup, TrailingZeroInput, Zero},
Percent, RuntimeDebug,
};

use alloc::{vec, vec::Vec};
use codec::{Decode, Encode};
use frame_support::{
ensure,
traits::{
ContainsLengthBound, Currency, EnsureOrigin, ExistenceRequirement::KeepAlive, Get,
OnUnbalanced, ReservableCurrency, SortedMembers,
},
Parameter,
};
use frame_system::pallet_prelude::BlockNumberFor;

#[cfg(any(feature = "try-runtime", test))]
use sp_runtime::TryRuntimeError;
use frame::prelude::*;

pub use pallet::*;
pub use weights::WeightInfo;

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

const LOG_TARGET: &str = "runtime::tips";

pub type BalanceOf<T, I = ()> = pallet_treasury::BalanceOf<T, I>;
Expand Down Expand Up @@ -118,11 +104,9 @@ pub struct OpenTip<
finders_fee: bool,
}

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

/// The in-code storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(4);
Expand Down Expand Up @@ -617,12 +601,10 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
tips: Vec<(AccountId, Balance)>,
}

use frame_support::{migration::storage_key_iter, Twox64Concat};

let zero_account = T::AccountId::decode(&mut TrailingZeroInput::new(&[][..]))
.expect("infinite input; qed");

for (hash, old_tip) in storage_key_iter::<
for (hash, old_tip) in storage::migration::storage_key_iter::<
T::Hash,
OldOpenTip<T::AccountId, BalanceOf<T, I>, BlockNumberFor<T>, T::Hash>,
Twox64Concat,
Expand Down
Loading
Loading