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

feat(pallet): Get rid of without_storage_info, use Bounded structs #3777

Closed
wants to merge 5 commits into from
Closed
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
1 change: 0 additions & 1 deletion pallets/gas/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ pub mod pallet {

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);

// Gas pallet error.
Expand Down
14 changes: 11 additions & 3 deletions pallets/gear-builtin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ use gear_core::{
use impl_trait_for_tuples::impl_for_tuples;
use pallet_gear::{BuiltinCache, BuiltinDispatcher, BuiltinDispatcherFactory, HandleFn};
use parity_scale_codec::{Decode, Encode};
use sp_runtime::BoundedBTreeSet;
use sp_std::prelude::*;

pub use pallet::*;
Expand Down Expand Up @@ -153,21 +154,23 @@ pub mod pallet {

// This pallet doesn't define a storage version because it doesn't use any storage
#[pallet::pallet]
#[pallet::without_storage_info]
pub struct Pallet<T>(PhantomData<T>);

#[pallet::config]
pub trait Config: frame_system::Config {
/// The builtin actor type.
type Builtins: BuiltinCollection<BuiltinActorError>;

/// This is enforced in the code; the quick cache size can not exceed this limit.
type MaxQuickCache: Get<u32>;

/// Weight cost incurred by builtin actors calls.
type WeightInfo: WeightInfo;
}

#[pallet::storage]
#[pallet::getter(fn quick_cache)]
pub type QuickCache<T: Config> = StorageValue<_, BTreeSet<ProgramId>>;
pub type QuickCache<T: Config> = StorageValue<_, BoundedBTreeSet<ProgramId, T::MaxQuickCache>>;

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
Expand Down Expand Up @@ -202,7 +205,12 @@ impl<T: Config> BuiltinCache for Pallet<T> {
// Populate the cache at the first call
let registry = BuiltinRegistry::<T>::new();
QuickCache::<T>::mutate(|keys| {
*keys = Some(registry.registry.keys().cloned().collect())
let set: BoundedBTreeSet<ProgramId, T::MaxQuickCache> =
BoundedBTreeSet::<ProgramId, T::MaxQuickCache>::try_from(
registry.registry.keys().cloned().collect::<BTreeSet<_>>(),
)
.expect("Filtered accounts vec too big");
*keys = Some(set)
});
}
Self::quick_cache()
Expand Down
1 change: 0 additions & 1 deletion pallets/payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,5 @@ pub mod pallet {
}

#[pallet::pallet]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);
}
18 changes: 9 additions & 9 deletions pallets/staking-rewards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use parity_scale_codec::{Decode, Encode};
pub use scale_info::TypeInfo;
use sp_runtime::{
traits::{AccountIdConversion, Saturating, StaticLookup, UniqueSaturatedInto},
PerThing, Perquintill,
BoundedBTreeSet, PerThing, Perquintill,
};
use sp_std::{collections::btree_set::BTreeSet, vec::Vec};

Expand Down Expand Up @@ -115,7 +115,6 @@ pub mod pallet {

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
#[pallet::without_storage_info]
pub struct Pallet<T>(PhantomData<T>);

#[pallet::config]
Expand Down Expand Up @@ -155,6 +154,9 @@ pub mod pallet {
#[pallet::constant]
type Falloff: Get<Perquintill>;

/// This is enforced in the code; the filtered accounts size can not exceed this limit.
type MaxFilteredAccounts: Get<u32>;

/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
}
Expand All @@ -181,7 +183,8 @@ pub mod pallet {
/// During the 1st year the non-stakeable amount is accounted for as a fixed fraction of TTS.
#[pallet::storage]
#[pallet::getter(fn filtered_accounts)]
pub type FilteredAccounts<T: Config> = StorageValue<_, BTreeSet<T::AccountId>, ValueQuery>;
pub type FilteredAccounts<T: Config> =
StorageValue<_, BoundedBTreeSet<T::AccountId, T::MaxFilteredAccounts>, ValueQuery>;

#[pallet::genesis_config]
#[derive(frame_support::DefaultNoBound)]
Expand Down Expand Up @@ -216,12 +219,9 @@ pub mod pallet {
TargetInflation::<T>::put(self.target_inflation);
IdealStakingRatio::<T>::put(self.ideal_stake);
NonStakeableShare::<T>::put(self.non_stakeable);
FilteredAccounts::<T>::put(
self.filtered_accounts
.iter()
.cloned()
.collect::<BTreeSet<_>>(),
);
let bounded_accounts =
BoundedBTreeSet::<T::AccountId, T::MaxFilteredAccounts>::try_from(self.filtered_accounts.iter().cloned().collect::<BTreeSet<_>>()).expect("Filtered accounts vec too big");
FilteredAccounts::<T>::put(bounded_accounts);
}
}

Expand Down
2 changes: 2 additions & 0 deletions runtime/vara/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ impl pallet_gear_staking_rewards::Config for Runtime {
type MinInflation = MinInflation;
type MaxROI = MaxROI;
type Falloff = Falloff;
type MaxFilteredAccounts = ConstU32<500>;
type WeightInfo = pallet_gear_staking_rewards::weights::SubstrateWeight<Runtime>;
}

Expand Down Expand Up @@ -1063,6 +1064,7 @@ parameter_types! {

impl pallet_gear_builtin::Config for Runtime {
type Builtins = BuiltinActors;
type MaxQuickCache = ConstU32<100>;
type WeightInfo = pallet_gear_builtin::weights::SubstrateWeight<Runtime>;
}

Expand Down
Loading