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 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2954f6a
frame-tips
bennethxyz Nov 18, 2024
fc2bb13
less imports adopts prelude prevelance
bennethxyz Dec 5, 2024
eefba0a
Merge branch 'master' into frame-tips
bennethxyz Dec 5, 2024
e9faacd
nit: remove comments
bennethxyz Dec 5, 2024
7a30bf4
nit: same as before
bennethxyz Dec 5, 2024
68cb91e
Merge branch 'master' into frame-tips
re-gius Dec 9, 2024
205ee2a
remove prdoc
bennethxyz Dec 12, 2024
9020dc3
mainly prelude
bennethxyz Dec 30, 2024
64018ee
nit migration prelude
bennethxyz Dec 30, 2024
17ebc08
tryruntime unreserve deposit migration
bennethxyz Dec 30, 2024
5b528c3
nit
bennethxyz Dec 30, 2024
aae9812
comment nit
bennethxyz Dec 30, 2024
6ed7aa0
account mod before utility arrangement nit
bennethxyz Dec 30, 2024
a210e1b
TypedGet in scope
bennethxyz Dec 30, 2024
be9e0dc
not utility, not currency
bennethxyz Jan 4, 2025
e3cefc5
Merge branch 'master' into frame-tips
bennethxyz Jan 4, 2025
84ada28
cargo fmt
bennethxyz Jan 4, 2025
b50c842
nit
bennethxyz Jan 13, 2025
36d5cf0
Merge branch 'master' into frame-tips
bennethxyz Jan 13, 2025
195b4d9
nit
bennethxyz Jan 13, 2025
dc092a0
cargo +nightly fmt
bennethxyz Jan 14, 2025
d6c9f17
Merge branch 'master' into frame-tips
bennethxyz Jan 14, 2025
056dfae
Merge branch 'master' into frame-tips
bennethxyz Jan 19, 2025
d348e3b
remove experimental
bennethxyz Jan 19, 2025
71df9ae
Merge branch 'master' into frame-tips
bennethxyz Jan 20, 2025
b0f087f
nit
bennethxyz Jan 20, 2025
19d2d2e
Merge branch 'master' into frame-tips
bennethxyz Jan 20, 2025
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.

30 changes: 23 additions & 7 deletions substrate/frame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,13 @@ 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, EitherOf, EstimateNextSessionRotation, Everything, InsideBoth,
InstanceFilter, IsSubType, MapSuccess, NoOpPoll, OnRuntimeUpgrade, OneSessionHandler,
RankedMembers, RankedMembersSwapHandler, VariantCount, VariantCountOf,
},
};

/// Pallet prelude of `frame-system`.
Expand Down Expand Up @@ -242,7 +245,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 @@ -355,6 +359,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 @@ -371,6 +380,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 @@ -561,9 +576,10 @@ pub mod hashing {
/// This is already part of the [`prelude`].
pub mod account {
pub use frame_support::traits::{
AsEnsureOriginWithArg, ChangeMembers, EitherOfDiverse, InitializeMembers,
AsEnsureOriginWithArg, ChangeMembers, ContainsLengthBound, EitherOfDiverse,
InitializeMembers, NeverEnsureOrigin, SortedMembers,
};
pub use sp_runtime::traits::{IdentifyAccount, IdentityLookup};
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,
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 @@ -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 }
frame = { workspace = true, features = ["runtime"] }
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 }

[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))]
Copy link
Contributor

Choose a reason for hiding this comment

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

curious why is this changed?

Copy link
Author

Choose a reason for hiding this comment

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

mainly because of this

error[E0433]: failed to resolve: could not find `try_runtime` in `frame`
   --> /polkadot-sdk/substrate/frame/tips/src/lib.rs:640:45
    |
640 |     pub fn do_try_state() -> Result<(), frame::try_runtime::TryRuntimeError> {
    |                                                ^^^^^^^^^^^ could not find `try_runtime` in `frame`
    |
note: found an item that was configured out
   --> /polkadot-sdk/substrate/frame/src/lib.rs:254:9
    |
254 | pub mod try_runtime {
    |         ^^^^^^^^^^^
note: the item is gated here
   --> /polkadot-sdk/substrate/frame/src/lib.rs:253:1
    |
253 | #[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