Skip to content

Commit

Permalink
Removes without_storage_info macro from pallets (#1122)
Browse files Browse the repository at this point in the history
* WIP: Removed macro, fixing max encoded len info missing

* wip: derive MaxEncodedLen

* feat: bound pool-system

* fix: make it compile for default features

* tests: fix

* tests: more minor fixes

* docs: improve comments

* docs: add upstream PR

* docs: improve for custom mel bound derivation

* docs: add missing max nav age comment

* fix: registry mock mel

* fix: final max encoded len for XcmDomain

Co-authored-by: Nuno Alexandre <hi@nunoalexandre.com>
Co-authored-by: William Freudenberger <w.freude@icloud.com>
  • Loading branch information
3 people authored Jan 12, 2023
1 parent d8a84f5 commit c73c7d0
Show file tree
Hide file tree
Showing 43 changed files with 664 additions and 371 deletions.
14 changes: 11 additions & 3 deletions libs/traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,16 @@ pub trait PoolNAV<PoolId, Amount> {

/// A trait that support pool inspection operations such as pool existence checks and pool admin of permission set.
pub trait PoolInspect<AccountId, CurrencyId> {
type PoolId: Parameter + Member + Debug + Copy + Default + TypeInfo + Encode + Decode;
type TrancheId: Parameter + Member + Debug + Copy + Default + TypeInfo;
type PoolId: Parameter
+ Member
+ Debug
+ Copy
+ Default
+ TypeInfo
+ Encode
+ Decode
+ MaxEncodedLen;
type TrancheId: Parameter + Member + Debug + Copy + Default + TypeInfo + MaxEncodedLen;
type Rate;
type Moment;

Expand Down Expand Up @@ -145,7 +153,7 @@ pub trait PoolMutate<AccountId, PoolId> {
type MaxTokenSymbolLength: Get<u32>;
type MaxTranches: Get<u32>;
type TrancheInput: Encode + Decode + Clone + TypeInfo + Debug + PartialEq;
type PoolChanges: Encode + Decode + Clone + TypeInfo + Debug + PartialEq;
type PoolChanges: Encode + Decode + Clone + TypeInfo + Debug + PartialEq + MaxEncodedLen;

fn create(
admin: AccountId,
Expand Down
4 changes: 2 additions & 2 deletions libs/types/src/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
// GNU General Public License for more details.

use cfg_primitives::Moment;
use codec::{Decode, Encode};
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::RuntimeDebug;
use scale_info::TypeInfo;

#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo)]
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct EpochState<EpochId> {
/// Current epoch that is ongoing.
pub current: EpochId,
Expand Down
4 changes: 2 additions & 2 deletions libs/types/src/fee_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

use codec::{Decode, Encode};
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::RuntimeDebug;
use scale_info::TypeInfo;
#[cfg(feature = "std")]
Expand All @@ -19,7 +19,7 @@ use sp_std::cmp::PartialEq;

/// Different fees keys available.
/// Each variant represents a balance previously determined and configured.
#[derive(Encode, Decode, Clone, Copy, PartialEq, RuntimeDebug, TypeInfo)]
#[derive(Encode, Decode, Clone, Copy, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub enum FeeKey {
/// Key to identify the balance reserved for the author.
Expand Down
3 changes: 2 additions & 1 deletion libs/types/src/fixed_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! Decimal Fixed Point implementations for Substrate runtime.
//! Copied over from sp_arithmetic

use codec::{CompactAs, Decode, Encode};
use codec::{CompactAs, Decode, Encode, MaxEncodedLen};
#[cfg(feature = "std")]
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use sp_arithmetic::{
Expand Down Expand Up @@ -430,6 +430,7 @@ pub trait FixedPointNumberExtension: FixedPointNumber {
PartialOrd,
Ord,
scale_info::TypeInfo,
MaxEncodedLen,
)]
pub struct Rate(u128);

Expand Down
2 changes: 1 addition & 1 deletion libs/types/src/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use sp_std::{
vec::Vec,
};

#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo)]
#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct FulfillmentWithPrice<BalanceRatio> {
pub of_amount: Perquintill,
pub price: BalanceRatio,
Expand Down
66 changes: 38 additions & 28 deletions libs/types/src/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
// GNU General Public License for more details.

use cfg_traits::Properties;
use codec::{Decode, Encode};
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{
sp_runtime::traits::Saturating,
traits::{Get, UnixTime},
BoundedVec,
};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_std::{
cmp::{Ord, PartialEq, PartialOrd},
marker::PhantomData,
vec::Vec,
};

/// PoolRole can hold any type of role specific functions a user can do on a given pool.
Expand Down Expand Up @@ -64,7 +64,7 @@ pub enum Role<TrancheId = [u8; 16], Moment = u64> {
PermissionedCurrencyRole(PermissionedCurrencyRole<Moment>),
}

#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, TypeInfo, Debug)]
#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, TypeInfo, Debug, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub enum PermissionScope<PoolId, CurrencyId> {
Pool(PoolId),
Expand All @@ -85,7 +85,7 @@ where

bitflags::bitflags! {
/// The current admin roles we support
#[derive(codec::Encode, codec::Decode, TypeInfo)]
#[derive(codec::Encode, codec::Decode, TypeInfo, MaxEncodedLen)]
pub struct PoolAdminRoles: u32 {
const POOL_ADMIN = 0b00000001;
const BORROWER = 0b00000010;
Expand All @@ -96,44 +96,44 @@ bitflags::bitflags! {
}

/// The current admin roles we support
#[derive(codec::Encode, codec::Decode, TypeInfo)]
#[derive(codec::Encode, codec::Decode, TypeInfo, MaxEncodedLen)]
pub struct CurrencyAdminRoles: u32 {
const PERMISSIONED_ASSET_MANAGER = 0b00000001;
const PERMISSIONED_ASSET_ISSUER = 0b00000010;
}
}

#[derive(Encode, Decode, TypeInfo, Debug, Clone, Eq, PartialEq)]
#[derive(Encode, Decode, TypeInfo, Debug, Clone, Eq, PartialEq, MaxEncodedLen)]
pub struct PermissionedCurrencyHolderInfo<Moment> {
permissioned_till: Moment,
}

#[derive(Encode, Decode, TypeInfo, Debug, Clone, Eq, PartialEq)]
#[derive(Encode, Decode, TypeInfo, Debug, Clone, Eq, PartialEq, MaxEncodedLen)]
pub struct TrancheInvestorInfo<TrancheId, Moment> {
tranche_id: TrancheId,
permissioned_till: Moment,
}

#[derive(Encode, Decode, TypeInfo, Debug, Clone, Eq, PartialEq)]
#[derive(Encode, Decode, TypeInfo, Debug, Clone, Eq, PartialEq, MaxEncodedLen)]
pub struct PermissionedCurrencyHolders<Now, MinDelay, Moment> {
info: Option<PermissionedCurrencyHolderInfo<Moment>>,
_phantom: PhantomData<(Now, MinDelay)>,
}

#[derive(Encode, Decode, TypeInfo, Debug, Clone, Eq, PartialEq)]
pub struct TrancheInvestors<Now, MinDelay, TrancheId, Moment> {
info: Vec<TrancheInvestorInfo<TrancheId, Moment>>,
#[derive(Encode, Decode, TypeInfo, Debug, Clone, Eq, PartialEq, MaxEncodedLen)]
pub struct TrancheInvestors<Now, MinDelay, TrancheId, Moment, MaxTranches: Get<u32>> {
info: BoundedVec<TrancheInvestorInfo<TrancheId, Moment>, MaxTranches>,
_phantom: PhantomData<(Now, MinDelay)>,
}

/// The structure that we store in the pallet-permissions storage
/// This here implements trait Properties.
#[derive(Encode, Decode, TypeInfo, Clone, Eq, PartialEq, Debug)]
pub struct PermissionRoles<Now, MinDelay, TrancheId, Moment = u64> {
#[derive(Encode, Decode, TypeInfo, Clone, Eq, PartialEq, Debug, MaxEncodedLen)]
pub struct PermissionRoles<Now, MinDelay, TrancheId, MaxTranches: Get<u32>, Moment = u64> {
pool_admin: PoolAdminRoles,
currency_admin: CurrencyAdminRoles,
permissioned_asset_holder: PermissionedCurrencyHolders<Now, MinDelay, Moment>,
tranche_investor: TrancheInvestors<Now, MinDelay, TrancheId, Moment>,
tranche_investor: TrancheInvestors<Now, MinDelay, TrancheId, Moment, MaxTranches>,
}

impl<Now, MinDelay, Moment> Default for PermissionedCurrencyHolders<Now, MinDelay, Moment>
Expand All @@ -150,36 +150,40 @@ where
}
}

impl<Now, MinDelay, TrancheId, Moment> Default
for TrancheInvestors<Now, MinDelay, TrancheId, Moment>
impl<Now, MinDelay, TrancheId, Moment, MaxTranches> Default
for TrancheInvestors<Now, MinDelay, TrancheId, Moment, MaxTranches>
where
Now: UnixTime,
MinDelay: Get<Moment>,
Moment: From<u64> + PartialEq + PartialOrd + Saturating + Ord,
TrancheId: PartialEq + PartialOrd,
MaxTranches: Get<u32>,
{
fn default() -> Self {
Self {
info: Vec::default(),
info: BoundedVec::default(),
_phantom: Default::default(),
}
}
}

impl<Now, MinDelay, TrancheId, Moment> Default for PermissionRoles<Now, MinDelay, TrancheId, Moment>
impl<Now, MinDelay, TrancheId, MaxTranches, Moment> Default
for PermissionRoles<Now, MinDelay, TrancheId, MaxTranches, Moment>
where
Now: UnixTime,
MinDelay: Get<Moment>,
Moment: From<u64> + PartialEq + PartialOrd + Saturating + Ord,
TrancheId: PartialEq + PartialOrd,
MaxTranches: Get<u32>,
{
fn default() -> Self {
Self {
pool_admin: PoolAdminRoles::empty(),
currency_admin: CurrencyAdminRoles::empty(),
permissioned_asset_holder:
PermissionedCurrencyHolders::<Now, MinDelay, Moment>::default(),
tranche_investor: TrancheInvestors::<Now, MinDelay, TrancheId, Moment>::default(),
tranche_investor:
TrancheInvestors::<Now, MinDelay, TrancheId, Moment, MaxTranches>::default(),
}
}
}
Expand All @@ -189,13 +193,14 @@ where
/// This UNION shall reflect that and explain to the reader why it is passed here.
pub const UNION: u64 = 0;

impl<Now, MinDelay, TrancheId, Moment> Properties
for PermissionRoles<Now, MinDelay, TrancheId, Moment>
impl<Now, MinDelay, TrancheId, MaxTranches, Moment> Properties
for PermissionRoles<Now, MinDelay, TrancheId, MaxTranches, Moment>
where
Now: UnixTime,
MinDelay: Get<Moment>,
Moment: From<u64> + PartialEq + PartialOrd + Saturating + Ord + Copy,
TrancheId: PartialEq + PartialOrd,
MaxTranches: Get<u32>,
{
type Error = ();
type Ok = ();
Expand Down Expand Up @@ -373,12 +378,14 @@ where
}
}

impl<Now, MinDelay, TrancheId, Moment> TrancheInvestors<Now, MinDelay, TrancheId, Moment>
impl<Now, MinDelay, TrancheId, Moment, MaxTranches>
TrancheInvestors<Now, MinDelay, TrancheId, Moment, MaxTranches>
where
Now: UnixTime,
MinDelay: Get<Moment>,
Moment: From<u64> + PartialEq + PartialOrd + Saturating + Ord + Copy,
TrancheId: PartialEq + PartialOrd,
MaxTranches: Get<u32>,
{
pub fn empty() -> Self {
Self::default()
Expand Down Expand Up @@ -435,10 +442,12 @@ where
Ok(self.info[index].permissioned_till = validity)
}
} else {
Ok(self.info.push(TrancheInvestorInfo {
tranche_id: tranche,
permissioned_till: validity,
}))
self.info
.try_push(TrancheInvestorInfo {
tranche_id: tranche,
permissioned_till: validity,
})
.map_err(|_| ())
}
}
}
Expand All @@ -454,6 +463,7 @@ mod tests {

parameter_types! {
pub const MinDelay: u64 = 4;
pub const MaxTranches: u32 = 5;
}

struct Now(core::time::Duration);
Expand Down Expand Up @@ -490,9 +500,9 @@ mod tests {

#[test]
fn permission_roles_work() {
assert!(PermissionRoles::<Now, MinDelay, TrancheId>::default().empty());
assert!(PermissionRoles::<Now, MinDelay, TrancheId, MaxTranches>::default().empty());

let mut roles = PermissionRoles::<Now, MinDelay, TrancheId>::default();
let mut roles = PermissionRoles::<Now, MinDelay, TrancheId, MaxTranches>::default();

// Updating works only when increasing permissions
assert!(roles
Expand Down
5 changes: 2 additions & 3 deletions pallets/anchors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#![allow(clippy::all)]

use cfg_traits::fees::{Fee, Fees};
use codec::{Decode, Encode};
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{
dispatch::{DispatchError, DispatchResult},
storage::child,
Expand Down Expand Up @@ -81,7 +81,7 @@ const ANCHOR_PREFIX: &[u8; 6] = b"anchor";
const EVICT_PRE_COMMIT_LIST_SIZE: u32 = 100;

/// The data structure for storing pre-committed anchors.
#[derive(Encode, Decode, Default, Clone, PartialEq, TypeInfo)]
#[derive(Encode, Decode, Default, Clone, PartialEq, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct PreCommitData<Hash, AccountId, BlockNumber, Balance> {
signing_root: Hash,
Expand Down Expand Up @@ -112,7 +112,6 @@ pub mod pallet {
// method.
#[pallet::pallet]
#[pallet::generate_store(pub (super) trait Store)]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);

#[pallet::config]
Expand Down
1 change: 0 additions & 1 deletion pallets/bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ pub mod pallet {
// for the pallet.
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);

// ------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion pallets/claims/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ pub mod pallet {
// for the pallet.
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);

// ------------------------------------------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions pallets/collator-allowlist/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ pub mod pallet {

#[pallet::pallet]
#[pallet::generate_store(pub (super) trait Store)]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);

#[pallet::config]
Expand All @@ -49,7 +48,7 @@ pub mod pallet {
type WeightInfo: WeightInfo;

/// The Validator Id type
type ValidatorId: Member + Parameter + MaybeSerializeDeserialize;
type ValidatorId: Member + Parameter + MaybeSerializeDeserialize + MaxEncodedLen;

/// Type representing the underlying validator registration center.
/// It offers us the API we need to check whether a collator
Expand Down
Loading

0 comments on commit c73c7d0

Please sign in to comment.