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

Remove duplicate metadata from pool-system #1285

Merged
merged 8 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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: 1 addition & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
};

# This is a hash of all the Cargo dependencies, for reproducibility.
cargoSha256 = "sha256-B44+vaseMmcmEAn0qhGime0a1geVofH0Qtbd9Epo5KI=";
cargoSha256 = "sha256-V+ST911USf0FCpVxpJEwRrbwXjvLDQ0aHtNoIokH1M4=";

nativeBuildInputs = with pkgs; [ clang git-mock pkg-config ];
buildInputs = with pkgs; [ openssl ] ++ (
Expand Down
1 change: 0 additions & 1 deletion libs/traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ pub trait PoolMutate<AccountId, PoolId> {
tranche_inputs: Vec<Self::TrancheInput>,
currency: Self::CurrencyId,
max_reserve: Self::Balance,
metadata: Option<Vec<u8>>,
) -> DispatchResult;

fn update(pool_id: PoolId, changes: Self::PoolChanges) -> Result<UpdateState, DispatchError>;
Expand Down
6 changes: 0 additions & 6 deletions pallets/loans/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,6 @@ parameter_types! {
pub const MinEpochTimeUpperBound: u64 = u64::MAX; // disable bound
pub const MaxNAVAgeUpperBound: u64 = u64::MAX; // disable bound

// Pool metadata limit
#[derive(scale_info::TypeInfo, Eq, PartialEq, Debug, Clone, Copy )]
pub const MaxSizeMetadata: u32 = 100;

#[derive(scale_info::TypeInfo, Eq, PartialEq, Debug, Clone, Copy )]
pub const MaxTokenNameLength: u32 = 128;

Expand Down Expand Up @@ -222,7 +218,6 @@ impl pallet_pool_system::Config for Runtime {
type EpochId = PoolEpochId;
type Investments = OrderManager;
type MaxNAVAgeUpperBound = MaxNAVAgeUpperBound;
type MaxSizeMetadata = MaxSizeMetadata;
type MaxTokenNameLength = MaxTokenNameLength;
type MaxTokenSymbolLength = MaxTokenSymbolLength;
type MaxTranches = MaxTranches;
Expand Down Expand Up @@ -258,7 +253,6 @@ impl PoolUpdateGuard for UpdateGuard {
u32,
Balance,
Rate,
MaxSizeMetadata,
TrancheWeight,
TrancheId,
PoolId,
Expand Down
1 change: 0 additions & 1 deletion pallets/loans/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ pub(crate) fn create<T, OM: Investment<T::AccountId>>(
],
currency_id.into(),
(100_000 * CURRENCY).into(),
None
));

let account: <T as frame_system::Config>::AccountId =
Expand Down
5 changes: 2 additions & 3 deletions pallets/pool-registry/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ benchmarks! {
assert_eq!(pool.reserve.total, Zero::zero());
assert_eq!(pool.parameters.min_epoch_time, T::DefaultMinEpochTime::get());
assert_eq!(pool.parameters.max_nav_age, T::DefaultMaxNAVAge::get());
assert_eq!(pool.metadata, None);
}

update_no_execution {
Expand Down Expand Up @@ -198,14 +197,14 @@ benchmarks! {
}

set_metadata {
let n in 0..<T as pallet_pool_system::Config>::MaxSizeMetadata::get();
let n in 0..<T as Config>::MaxSizeMetadata::get();
let caller: <T as frame_system::Config>::AccountId = create_admin::<T>(0);
prepare_asset_registry::<T>();
create_pool::<T>(2, caller.clone())?;
let metadata = vec![0u8; n as usize];
}: set_metadata(RawOrigin::Signed(caller), POOL, metadata.clone())
verify {
let metadata: BoundedVec<u8, <T as pallet_pool_system::Config>::MaxSizeMetadata> = metadata.try_into().unwrap();
let metadata: BoundedVec<u8, <T as Config>::MaxSizeMetadata> = metadata.try_into().unwrap();
assert_eq!(get_pool_metadata::<T>().metadata, metadata);
}
}
Expand Down
1 change: 0 additions & 1 deletion pallets/pool-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ pub mod pallet {
tranche_inputs,
currency,
max_reserve,
metadata,
)
.map(|_| Self::deposit_event(Event::Registered { pool_id }))
}
Expand Down
5 changes: 1 addition & 4 deletions pallets/pool-registry/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ impl pallet_pool_system::Config for Test {
type EpochId = PoolEpochId;
type Investments = Investments;
type MaxNAVAgeUpperBound = MaxNAVAgeUpperBound;
type MaxSizeMetadata = MaxSizeMetadata;
type MaxTokenNameLength = MaxTokenNameLength;
type MaxTokenSymbolLength = MaxTokenSymbolLength;
type MaxTranches = MaxTranches;
Expand Down Expand Up @@ -221,7 +220,6 @@ impl<
tranche_inputs: Vec<Self::TrancheInput>,
_currency: <T as pallet_pool_registry::Config>::CurrencyId,
_max_reserve: <T as pallet_pool_registry::Config>::Balance,
_metadata: Option<Vec<u8>>,
) -> DispatchResult {
create_pool::<T>(tranche_inputs.len() as u32, admin)?;
Ok(())
Expand Down Expand Up @@ -347,7 +345,6 @@ impl PoolUpdateGuard for UpdateGuard {
u32,
Balance,
Rate,
MaxSizeMetadata,
TrancheWeight,
TrancheId,
u64,
Expand All @@ -358,7 +355,7 @@ impl PoolUpdateGuard for UpdateGuard {

fn released(
pool: &Self::PoolDetails,
update: &Self::ScheduledUpdateDetails,
_update: &Self::ScheduledUpdateDetails,
now: Self::Moment,
) -> bool {
// The epoch in which the redemptions were fulfilled,
Expand Down
1 change: 1 addition & 0 deletions pallets/pool-system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"], default-features = false }
lazy_static = { version = "1.4.0", optional = true, default-features = false }
log = { version = "0.4.0", default-features = false }
rev_slice = { version = "0.1.5", default-features = false }
scale-info = { version = "2.3.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.119" }
Expand Down
1 change: 0 additions & 1 deletion pallets/pool-system/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ pub fn create_pool<T: Config<PoolId = u64, Balance = u128, CurrencyId = Currency
tranches,
CurrencyId::AUSD,
MAX_RESERVE,
None,
)
}

Expand Down
14 changes: 0 additions & 14 deletions pallets/pool-system/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ impl<T: Config> PoolMutate<T::AccountId, T::PoolId> for Pallet<T> {
tranche_inputs: Vec<TrancheInput<T::Rate, T::MaxTokenNameLength, T::MaxTokenSymbolLength>>,
currency: T::CurrencyId,
max_reserve: T::Balance,
metadata: Option<Vec<u8>>,
) -> DispatchResult {
// A single pool ID can only be used by one owner.
ensure!(!Pool::<T>::contains_key(pool_id), Error::<T>::PoolInUse);
Expand Down Expand Up @@ -137,17 +136,6 @@ impl<T: Config> PoolMutate<T::AccountId, T::PoolId> for Pallet<T> {
now,
)?;

let checked_metadata: Option<BoundedVec<u8, T::MaxSizeMetadata>> = match metadata {
Some(metadata_value) => {
let checked: BoundedVec<u8, T::MaxSizeMetadata> = metadata_value
.try_into()
.map_err(|_| Error::<T>::BadMetadata)?;

Some(checked)
}
None => None,
};

for (tranche, tranche_input) in tranches.tranches.iter().zip(&tranche_inputs) {
let token_name: BoundedVec<u8, T::MaxTokenNameLength> =
tranche_input.metadata.token_name.clone();
Expand Down Expand Up @@ -192,7 +180,6 @@ impl<T: Config> PoolMutate<T::AccountId, T::PoolId> for Pallet<T> {
available: Zero::zero(),
total: Zero::zero(),
},
metadata: checked_metadata,
};

Pool::<T>::insert(pool_id, pool_details.clone());
Expand Down Expand Up @@ -454,7 +441,6 @@ mod benchmarks_utils {
],
CurrencyId::AUSD,
FUNDS.into(),
None,
)
.unwrap();

Expand Down
40 changes: 27 additions & 13 deletions pallets/pool-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ use cfg_types::{
orders::SummarizedOrders,
permissions::{PermissionScope, PoolRole, Role},
};
use codec::HasCompact;
use codec::{Decode, Encode, HasCompact, MaxEncodedLen};
use frame_support::{
dispatch::DispatchResult,
pallet_prelude::*,
ensure,
traits::{
fungibles::{Inspect, Mutate, Transfer},
ReservableCurrency, UnixTime,
},
transactional, BoundedVec,
transactional, BoundedVec, RuntimeDebug,
};
use frame_system::pallet_prelude::*;
pub use impls::*;
Expand All @@ -51,9 +51,10 @@ pub use solution::*;
use sp_arithmetic::traits::BaseArithmetic;
use sp_runtime::{
traits::{
AccountIdConversion, AtLeast32BitUnsigned, CheckedAdd, CheckedSub, One, Saturating, Zero,
AccountIdConversion, AtLeast32BitUnsigned, CheckedAdd, CheckedSub, Get, One, Saturating,
Zero,
},
FixedPointNumber, FixedPointOperand, Perquintill, TokenError,
DispatchError, FixedPointNumber, FixedPointOperand, Perquintill, TokenError,
};
use sp_std::{cmp::Ordering, vec::Vec};
use tranches::{
Expand All @@ -66,6 +67,7 @@ pub use weights::*;
pub mod benchmarking;
mod impls;

pub mod migrations;
#[cfg(test)]
mod mock;
pub mod pool_types;
Expand Down Expand Up @@ -121,7 +123,6 @@ pub type PoolDetailsOf<T> = PoolDetails<
<T as Config>::EpochId,
<T as Config>::Balance,
<T as Config>::Rate,
<T as Config>::MaxSizeMetadata,
<T as Config>::TrancheWeight,
<T as Config>::TrancheId,
<T as Config>::PoolId,
Expand Down Expand Up @@ -166,14 +167,29 @@ pub type PoolEssenceOf<T> = PoolEssence<
<T as Config>::MaxTokenSymbolLength,
>;

#[derive(Encode, Decode, TypeInfo, PartialEq, Eq, MaxEncodedLen, RuntimeDebug)]
#[repr(u32)]
pub enum Release {
V0,
V1,
}

impl Default for Release {
fn default() -> Self {
Self::V0
}
}
Comment on lines +172 to +181
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use the new versioning that is automatically supported for pallets. Cc @wischli for how this works ^^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding of that is that its based around the crate's version number. We... don't really use/maintain those right now. I agree we should move to the new versioning, though.

My thought was that we'll need to figure out some sort of versioning / release-stream system anyway once pools are on cent-chain (because we won't want new features to land simultaneously on altair & cfg). We should roll pallet versioning into that, and then we can switch to the new pallet version storage. WDYT? (again /cc @wischli )

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it is a basic u16 value.


#[frame_support::pallet]
pub mod pallet {
use cfg_traits::{OrderManager, PoolUpdateGuard, TrancheCurrency as TrancheCurrencyT};
use cfg_types::{
orders::{FulfillmentWithPrice, TotalOrder},
tokens::CustomMetadata,
};
use frame_support::{sp_runtime::traits::Convert, traits::Contains, PalletId};
use frame_support::{
pallet_prelude::*, sp_runtime::traits::Convert, traits::Contains, PalletId,
};
use sp_runtime::{traits::BadOrigin, ArithmeticError};

use super::*;
Expand Down Expand Up @@ -319,10 +335,6 @@ pub mod pallet {
#[pallet::constant]
type MinUpdateDelay: Get<u64>;

/// Max size of Metadata
#[pallet::constant]
type MaxSizeMetadata: Get<u32> + Copy + Member + scale_info::TypeInfo;

/// Max length for a tranche token name
#[pallet::constant]
type MaxTokenNameLength: Get<u32> + Copy + Member + scale_info::TypeInfo;
Expand Down Expand Up @@ -373,6 +385,10 @@ pub mod pallet {
#[pallet::getter(fn pool_deposits)]
pub type PoolDeposit<T: Config> = StorageMap<_, Blake2_128Concat, T::PoolId, PoolDepositOf<T>>;

#[pallet::storage]
#[pallet::getter(fn storage_version)]
pub type StorageVersion<T: Config> = StorageValue<_, Release, ValueQuery>;

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
Expand Down Expand Up @@ -455,8 +471,6 @@ pub mod pallet {
/// Pre-requirements for a TrancheUpdate are not met
/// for example: Tranche changed but not its metadata or vice versa
InvalidTrancheUpdate,
/// Invalid metadata passed
BadMetadata,
/// No metada for the given currency found
MetadataForCurrencyNotFound,
/// The given tranche token name exceeds the length limit
Expand Down
Loading