Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
a3095a7
Add missing pallets to centrifuge - loans not yet
mustermeiszer Mar 7, 2023
d459aca
Clean up feature list Centrifuge
mustermeiszer Mar 7, 2023
8a24359
Add most pallets, not loans yet
mustermeiszer Mar 7, 2023
4247dbd
Add Keystore and Uniques to Centrifuge runtime
Mar 8, 2023
a4cbc68
TMP add pallet-loans
Mar 8, 2023
a1495f6
Use per-pallet weights for unbenched pallets
Mar 9, 2023
04ffb9c
Add missing imports
Mar 9, 2023
75d6db7
EnsureRoot<AccountId>
Mar 9, 2023
5bb2fc6
Add remaining impls
Mar 9, 2023
e19a8b7
Restore Encode/Decode impls for MaxTranches
Mar 9, 2023
1c63eb7
Add serde for conditional {De}serialize impls
Mar 9, 2023
eecb743
Add uniques/keystores to benchmarks
Mar 9, 2023
1a9554f
Add interest_accrual to centrifuge genesis
Mar 9, 2023
6aea06e
Fix PoolCreateOrigin for benchmarks
Mar 9, 2023
1740bdf
Actually run all the benches
Mar 9, 2023
efe18cd
Enable Pools RPC endpoints on centrifuge chain
Mar 9, 2023
eb7232c
Adapt paramets from Jeroen suggestion
mustermeiszer Mar 9, 2023
e7282e1
fix: issuance issues for creating blocking redeem order
mustermeiszer Mar 15, 2023
888eadf
change: Remove check in guard, updates note submission, not schedule
mustermeiszer Mar 15, 2023
ba53154
change: Remove impossible to fulfill check
mustermeiszer Mar 15, 2023
7f6eb4a
feat: Add correct check if epoch was closed in between
mustermeiszer Mar 15, 2023
0011592
fix: runtime settings altair, centrifuge for pool params
mustermeiszer Mar 15, 2023
d5ba981
fix: registry-benchmarks
mustermeiszer Mar 15, 2023
e4d94e3
fix: uniques naming, feature guard for PoolUpdateGuard
mustermeiszer Mar 15, 2023
8c89a16
fix taplo & nix
lemunozm Mar 17, 2023
4b709a8
Merge remote-tracking branch 'origin/main' into feature/add-pools-to-…
Mar 21, 2023
6f94c50
Adding filter for restricted tokens
mustermeiszer Mar 22, 2023
c8382d2
feat: new weights for centrifuge runtime
mustermeiszer Mar 22, 2023
fca17d1
feat: use newly benched weights
mustermeiszer Mar 22, 2023
1e97c28
feat: adapt parameters
mustermeiszer Mar 22, 2023
ff17c8d
fix: adapt uniques parameters according to review
mustermeiszer Mar 23, 2023
d38790e
Add loans to centrifuge runtime (#1254)
lemunozm Mar 23, 2023
474d917
Merge remote-tracking branch 'origin/main' into feature/add-pools-to-…
mustermeiszer Mar 23, 2023
40245fd
inter: clion deletes this files content, need to regenerate anyways
mustermeiszer Mar 23, 2023
cf1b465
fix: rm warn, check orml-asset-regsitry weights
mustermeiszer Mar 23, 2023
71160aa
fix: collator-selection benchmarks
mustermeiszer Mar 23, 2023
ece6a56
fix: xcmp queue benches to centrifuge
mustermeiszer Mar 23, 2023
f2c6a44
feat: intermediate change spec name for upgrade on charcoal
mustermeiszer Mar 23, 2023
654b5ab
fix: failing collator-allowlist test with benchmark fix
mustermeiszer Mar 23, 2023
274bb56
feat: update nix hash
mustermeiszer Mar 23, 2023
e2b4b3a
fiy: clippy lint, allow for readabulity
mustermeiszer Mar 24, 2023
81bee18
fix: xclippy allow not working, using suggestion
mustermeiszer Mar 24, 2023
8c01c9f
fix: clippy development runtime
mustermeiszer Mar 24, 2023
c6f313c
feat: adapt weight to high fix
mustermeiszer Mar 24, 2023
319b4a9
feat: update weights centrifuge
mustermeiszer Mar 28, 2023
351abec
feat: Update weights altair
mustermeiszer Mar 28, 2023
093c9c4
fix: use weights, adapt comments
mustermeiszer Mar 28, 2023
5b54934
fix: only signed origin in registry benches
mustermeiszer Mar 28, 2023
a10d79d
Merge remote-tracking branch 'origin/main' into feature/add-pools-to-…
mustermeiszer Mar 28, 2023
a862e54
feat: Pump version number Centrifuge
mustermeiszer Mar 28, 2023
94a38f4
Update Cargo.toml centrifuge
mustermeiszer Mar 28, 2023
5663eb6
fix: remarks from review
wischli Mar 28, 2023
ff1f281
chore: bump nix
wischli Mar 28, 2023
c02892f
fix: enable phrag elec benches in cfg runtime
wischli Mar 28, 2023
d761ad4
fix: remove old migrations, default to V2 interest accrual
mustermeiszer Apr 4, 2023
02d3334
fix: typos, use dummy weight phragmen, prepare for bench
mustermeiszer Apr 4, 2023
b75e69c
Merge remote-tracking branch 'origin/main' into feature/add-pools-to-…
mustermeiszer Apr 4, 2023
2b66f18
fix: adapt nix hash
mustermeiszer Apr 4, 2023
4915a47
chore: update weights centrifuge
mustermeiszer Apr 4, 2023
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
11 changes: 10 additions & 1 deletion 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-BBuNvCWqMQDNDeDNCr/C4CvJay/2sPGAZQefaKg0EFg=";
cargoSha256 = "sha256-B44+vaseMmcmEAn0qhGime0a1geVofH0Qtbd9Epo5KI=";

nativeBuildInputs = with pkgs; [ clang git-mock pkg-config ];
buildInputs = with pkgs; [ openssl ] ++ (
Expand Down
18 changes: 18 additions & 0 deletions pallets/collator-allowlist/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,24 @@ impl<T: Config> ValidatorRegistration<T::ValidatorId> for Pallet<T> {
/// True iff
/// - the validator id is present in the allowlist and
/// - the validator id is registered in the underlying validator registration center
#[cfg(not(test))]
fn is_registered(id: &T::ValidatorId) -> bool {
let contains_key = if cfg!(feature = "runtime-benchmarks") {
Comment thread
mustermeiszer marked this conversation as resolved.
// NOTE: We want to return true but count the storage hit
// during benchmarks here.
let _ = <Allowlist<T>>::contains_key(id);
true
} else {
<Allowlist<T>>::contains_key(id)
};

contains_key && T::ValidatorRegistration::is_registered(id)
}

// NOTE: Running test with `feature = "runtime-benchmarks"` breaks the test
// with the above solution for fixing `pallet-collator-selection` benchmarks
// hence, we have a "non-benchmarking implementation" here
#[cfg(test)]
fn is_registered(id: &T::ValidatorId) -> bool {
<Allowlist<T>>::contains_key(id) && T::ValidatorRegistration::is_registered(id)
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/interest-accrual/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub enum Release {

impl Default for Release {
fn default() -> Self {
Self::V0
Self::V2
}
}

Expand Down
17 changes: 17 additions & 0 deletions pallets/interest-accrual/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,23 @@ pub mod v2 {
}
}

pub mod centrifuge {
use super::*;

pub struct SetStorageVersionToV2<T>(sp_std::marker::PhantomData<T>);

impl<T: Config> OnRuntimeUpgrade for SetStorageVersionToV2<T> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In theory we could change Release::default() to be V2 now, and the unpopulated storage key would be V2 on Centrifuge without us needing to run a migration

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed and defaulted to V2.

fn on_runtime_upgrade() -> Weight {
if StorageVersion::<T>::get() != Release::V2 {
StorageVersion::<T>::set(Release::V2);
T::DbWeight::get().reads_writes(1, 1)
} else {
T::DbWeight::get().reads(1)
}
}
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
12 changes: 6 additions & 6 deletions pallets/investments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ pub mod pallet {
/// amount is less than the current order, the balance
/// will be transferred from the pool to the calling
/// account.
#[pallet::weight(80_000_000)]
#[pallet::weight(5_000_000_000)]
pub fn update_invest_order(
origin: OriginFor<T>,
investment_id: T::InvestmentId,
Expand All @@ -478,7 +478,7 @@ pub mod pallet {
/// amount is less than the current order, the balance
/// will be transferred from the pool to the calling
/// account.
#[pallet::weight(80_000_000)]
#[pallet::weight(5_000_000_000)]
pub fn update_redeem_order(
origin: OriginFor<T>,
investment_id: T::InvestmentId,
Expand All @@ -492,7 +492,7 @@ pub mod pallet {
/// Collect the results of a users invest orders for the given investment.
/// If any amounts are not fulfilled they are directly appended to the next active
/// order for this investment.
#[pallet::weight(80_000_000)]
#[pallet::weight(5_000_000_000)]
pub fn collect_investments(
origin: OriginFor<T>,
investment_id: T::InvestmentId,
Expand All @@ -505,7 +505,7 @@ pub mod pallet {
/// Collect the results of a users redeem orders for the given investment.
/// If any amounts are not fulfilled they are directly appended to the next active
/// order for this investment.
#[pallet::weight(80_000_000)]
#[pallet::weight(5_000_000_000)]
pub fn collect_redemptions(
origin: OriginFor<T>,
investment_id: T::InvestmentId,
Expand All @@ -518,7 +518,7 @@ pub mod pallet {
/// Collect the results of another users invest orders for the given investment.
/// If any amounts are not fulfilled they are directly appended to the next active
/// order for this investment.
#[pallet::weight(80_000_000)]
#[pallet::weight(5_000_000_000)]
pub fn collect_investments_for(
origin: OriginFor<T>,
who: T::AccountId,
Expand All @@ -532,7 +532,7 @@ pub mod pallet {
/// Collect the results of another users redeem orders for the given investment.
/// If any amounts are not fulfilled they are directly appended to the next active
/// order for this investment.
#[pallet::weight(80_000_000)]
#[pallet::weight(5_000_000_000)]
pub fn collect_redemptions_for(
origin: OriginFor<T>,
who: T::AccountId,
Expand Down
1 change: 0 additions & 1 deletion pallets/loans/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ impl pallet_permissions::Config for Runtime {
type AdminOrigin = EnsureSignedBy<One, u64>;
type Editors = Everything;
type MaxRolesPerScope = MaxRoles;
type MaxTranches = MaxTranches;
type Role = Role;
type RuntimeEvent = RuntimeEvent;
type Scope = PermissionScope<u64, CurrencyId>;
Expand Down
5 changes: 1 addition & 4 deletions pallets/loans/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ use frame_support::{
use frame_system::RawOrigin;
#[cfg(feature = "runtime-benchmarks")]
use pallet_pool_system::tranches::TrancheLoc;
use pallet_pool_system::{
tranches::{TrancheInput, TrancheMetadata, TrancheType},
Pallet as PoolPallet, Pool as PoolStorage,
};
use pallet_pool_system::tranches::{TrancheInput, TrancheMetadata, TrancheType};
use sp_runtime::{
traits::{AccountIdConversion, Zero},
Perquintill,
Expand Down
4 changes: 0 additions & 4 deletions pallets/permissions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ pub mod pallet {
#[pallet::constant]
type MaxRolesPerScope: Get<u32>;

/// The maximum number of tranches.
#[pallet::constant]
type MaxTranches: Get<u32>;

type WeightInfo: WeightInfo;
}

Expand Down
1 change: 0 additions & 1 deletion pallets/permissions/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ impl pallet_permissions::Config for Runtime {
type AdminOrigin = AdminOrigin;
type Editors = Editors;
type MaxRolesPerScope = MaxRoles;
type MaxTranches = MaxTranches;
type Role = Role;
type RuntimeEvent = RuntimeEvent;
type Scope = Scope;
Expand Down
2 changes: 2 additions & 0 deletions pallets/pool-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pallet-pool-system = { path = "../pool-system", default-features = false }
# Benchmarking dependencies - optional
frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.32" }
pallet-investments = { path = "../investments", default-features = false, optional = true }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.32" }

cfg-primitives = { path = "../../libs/primitives", default-features = false }
cfg-traits = { path = "../../libs/traits", default-features = false }
Expand Down Expand Up @@ -58,6 +59,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"orml-asset-registry/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
]
std = [
"codec/std",
Expand Down
56 changes: 17 additions & 39 deletions pallets/pool-registry/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// GNU General Public License for more details.

//! Module provides benchmarking for Loan Pallet
use cfg_primitives::PoolEpochId;
use cfg_primitives::{Moment, PoolEpochId};
use cfg_traits::{InvestmentAccountant, InvestmentProperties, TrancheCurrency as _};
use cfg_types::tokens::{CurrencyId, TrancheCurrency};
use frame_benchmarking::benchmarks;
Expand Down Expand Up @@ -45,7 +45,6 @@ const SECS_PER_DAY: u64 = 24 * SECS_PER_HOUR;
const SECS_PER_YEAR: u64 = 365 * SECS_PER_DAY;

const TRANCHE: TrancheIndex = 0;

const POOL: u64 = 0;

benchmarks! {
Expand All @@ -64,6 +63,7 @@ benchmarks! {
MaxTokenNameLength = <T as Config>::MaxTokenNameLength,
MaxTokenSymbolLength = <T as Config>::MaxTokenSymbolLength,
MaxTranches = <T as Config>::MaxTranches>,
T: pallet_timestamp::Config<Moment = Moment>,
<T as pallet_investments::Config>::Tokens: Inspect<T::AccountId, AssetId = CurrencyId, Balance = u128>,
<<T as pallet_investments::Config>::Accountant as InvestmentAccountant<T::AccountId>>::InvestmentInfo:
InvestmentProperties<T::AccountId, Currency = CurrencyId>,
Expand All @@ -88,7 +88,11 @@ benchmarks! {
let n in 1..<T as pallet_pool_system::Config>::MaxTranches::get();
let caller: <T as frame_system::Config>::AccountId = create_admin::<T>(0);
let tranches = build_bench_input_tranches::<T>(n);
let origin = RawOrigin::Signed(caller.clone());
let origin = if let Ok(_) = <T as Config>::PoolCreateOrigin::try_origin(RawOrigin::Signed(caller.clone()).into()) {
RawOrigin::Signed(caller.clone())
} else {
RawOrigin::Root
};
prepare_asset_registry::<T>();
}: register(origin, caller, POOL, tranches.clone(), CurrencyId::AUSD, MAX_RESERVE, None)
verify {
Expand All @@ -102,36 +106,34 @@ benchmarks! {
}

update_no_execution {
// Execution of updates is blocked as no epoch has passed
// since we submitted the update
let admin: <T as frame_system::Config>::AccountId = create_admin::<T>(0);
let n in 1..<T as pallet_pool_system::Config>::MaxTranches::get();
let tranches = build_update_tranches::<T>(n);
prepare_asset_registry::<T>();
create_pool::<T>(n, admin.clone())?;

let pool = get_pool::<T>();
let default_min_epoch_time = pool.parameters.min_epoch_time;
let default_max_nav_age = pool.parameters.max_nav_age;

// Submit redemption order so the update isn't executed
let amount = MAX_RESERVE / 2;
let investor = create_investor::<T>(0, TRANCHE)?;
let investor = create_investor::<T>(0, TRANCHE, Some(amount))?;
let locator = get_tranche_id::<T>(TRANCHE);
pallet_investments::Pallet::<T>::update_redeem_order(RawOrigin::Signed(investor.clone()).into(), TrancheCurrency::generate(POOL, locator), amount)?;


let changes = PoolChanges {
tranches: Change::NoChange,
min_epoch_time: Change::NewValue(SECS_PER_DAY),
max_nav_age: Change::NewValue(SECS_PER_HOUR),
tranche_metadata: Change::NoChange,
};

update_pool::<T>(changes.clone())?;
}: update(RawOrigin::Signed(admin), POOL, changes.clone())
verify {
// Should be the old values
let pool = get_pool::<T>();
assert_eq!(pool.parameters.min_epoch_time, default_min_epoch_time);
assert_eq!(pool.parameters.max_nav_age, default_max_nav_age);
assert_eq!(pool.parameters.min_epoch_time, T::DefaultMinEpochTime::get());
assert_eq!(pool.parameters.max_nav_age, T::DefaultMaxNAVAge::get());

let actual_update = get_scheduled_update::<T>();
assert_eq!(actual_update.changes, changes);
Expand All @@ -145,12 +147,11 @@ benchmarks! {
create_pool::<T>(n, admin.clone())?;

let changes = PoolChanges {
tranches: Change::NewValue(build_update_tranches::<T>(n)),
tranches: Change::NewValue(tranches.clone()),
min_epoch_time: Change::NewValue(SECS_PER_DAY),
max_nav_age: Change::NewValue(SECS_PER_HOUR),
tranche_metadata: Change::NewValue(build_update_tranche_metadata::<T>()),
};
update_pool::<T>(changes.clone())?;
}: update(RawOrigin::Signed(admin), POOL, changes)
verify {
// No redemption order was submitted and the MinUpdateDelay is 0 for benchmarks,
Expand Down Expand Up @@ -179,7 +180,7 @@ benchmarks! {
};

// Invest so we can redeem later
let investor = create_investor::<T>(0, TRANCHE)?;
let investor = create_investor::<T>(0, TRANCHE, Some(1))?;
let locator = get_tranche_id::<T>(TRANCHE);
// Submit redemption order so the update isn't immediately executed
pallet_investments::Pallet::<T>::update_redeem_order(RawOrigin::Signed(investor.clone()).into(), TrancheCurrency::generate(POOL, locator), 1)?;
Expand Down Expand Up @@ -225,39 +226,16 @@ fn build_update_tranche_metadata<T: Config>(

fn build_update_tranches<T: Config>(
num_tranches: u32,
) -> BoundedVec<TrancheUpdate<T::InterestRate>, T::MaxTranches> {
let mut tranches = build_bench_update_tranches::<T>(num_tranches);

for tranche in &mut tranches {
tranche.tranche_type = match tranche.tranche_type {
TrancheType::Residual => TrancheType::Residual,
TrancheType::NonResidual {
interest_rate_per_sec,
min_risk_buffer,
} => {
let min_risk_buffer = Perquintill::from_parts(min_risk_buffer.deconstruct() * 2);
TrancheType::NonResidual {
interest_rate_per_sec,
min_risk_buffer,
}
}
}
}
tranches
}

fn build_bench_update_tranches<T: Config>(
num_tranches: u32,
) -> BoundedVec<TrancheUpdate<T::InterestRate>, T::MaxTranches> {
let senior_interest_rate = T::InterestRate::saturating_from_rational(5, 100)
/ T::InterestRate::saturating_from_integer(SECS_PER_YEAR);
let mut tranches: Vec<_> = (1..num_tranches)
.map(|tranche_id| TrancheUpdate {
tranche_type: TrancheType::NonResidual {
interest_rate_per_sec: senior_interest_rate
/ T::InterestRate::saturating_from_integer(tranche_id)
/ T::InterestRate::saturating_from_integer(tranche_id * 2)
+ One::one(),
min_risk_buffer: Perquintill::from_percent(tranche_id.into()),
min_risk_buffer: Perquintill::from_percent((tranche_id * 2).into()),
},
seniority: None,
})
Expand Down
4 changes: 0 additions & 4 deletions pallets/pool-registry/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,6 @@ impl PoolUpdateGuard for UpdateGuard {
update: &Self::ScheduledUpdateDetails,
now: Self::Moment,
) -> bool {
if now < update.scheduled_time {
return false;
}

// The epoch in which the redemptions were fulfilled,
// should have closed after the scheduled time already,
// to ensure that investors had the `MinUpdateDelay`
Expand Down
Loading