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 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

35 changes: 31 additions & 4 deletions substrate/frame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,9 @@ pub mod prelude {
pub use frame_support::{
defensive, defensive_assert,
traits::{
Contains, EitherOf, EstimateNextSessionRotation, IsSubType, MapSuccess, NoOpPoll,
OnRuntimeUpgrade, OneSessionHandler, RankedMembers, RankedMembersSwapHandler,
Contains, EitherOf, EstimateNextSessionRotation, Everything, InsideBoth,
InstanceFilter, IsSubType, MapSuccess, NoOpPoll, OnRuntimeUpgrade, OneSessionHandler,
RankedMembers, RankedMembersSwapHandler, VariantCount, VariantCountOf,
},
};

Expand All @@ -226,6 +227,9 @@ pub mod prelude {
/// All hashing related things
pub use super::hashing::*;

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

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

Expand All @@ -238,7 +242,8 @@ pub mod prelude {
/// Other error/result types for runtime
#[doc(no_inline)]
pub use sp_runtime::{
BoundToRuntimeAppPublic, DispatchErrorWithPostInfo, DispatchResultWithInfo, TokenError,
BoundToRuntimeAppPublic, DispatchError, DispatchErrorWithPostInfo, DispatchResultWithInfo,
TokenError,
};
}

Expand Down Expand Up @@ -322,7 +327,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, hypothetically, storage_alias,
assert_storage_noop, ensure, hypothetically, storage_alias,
};

pub use frame_system::{self, mocking::*};
Expand Down Expand Up @@ -351,6 +356,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 @@ -367,6 +377,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 and types.
pub use frame_support::storage::{KeyPrefixIterator, StoragePrefixedMap};

/// 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 @@ -552,6 +568,17 @@ 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};
}

/// 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
27 changes: 5 additions & 22 deletions substrate/frame/tips/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,33 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { features = ["derive"], workspace = true }
frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
log = { workspace = true }
pallet-treasury = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
serde = { features = ["derive"], optional = true, workspace = true, default-features = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"] }
pallet-treasury = { 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
31 changes: 8 additions & 23 deletions substrate/frame/tips/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,15 @@ 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::{
prelude::{DispatchError::BadOrigin, *},
traits::{Currency, ExistenceRequirement::KeepAlive, OnUnbalanced, ReservableCurrency},
};
use frame_system::pallet_prelude::BlockNumberFor;

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

pub use pallet::*;
pub use weights::WeightInfo;
Expand Down Expand Up @@ -118,11 +107,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 +604,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 Expand Up @@ -654,7 +639,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// 1. The number of entries in `Tips` should be equal to `Reasons`.
/// 2. Reasons exists for each Tip[`OpenTip.reason`].
/// 3. If `OpenTip.finders_fee` is true, then OpenTip.deposit should be greater than zero.
#[cfg(any(feature = "try-runtime", test))]
#[cfg(feature = "try-runtime")]
pub fn do_try_state() -> Result<(), TryRuntimeError> {
let reasons = Reasons::<T, I>::iter_keys().collect::<Vec<_>>();
let tips = Tips::<T, I>::iter_keys().collect::<Vec<_>>();
Expand Down
Loading
Loading