-
Notifications
You must be signed in to change notification settings - Fork 85
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: benchmark foreign investments worst case #1565
Conversation
…o bench/foreign-investments
@@ -152,7 +152,7 @@ pub mod pallet { | |||
|
|||
/// Type for price ratio for cost of incoming currency relative to | |||
/// outgoing | |||
type Rate: Parameter | |||
type BalanceRatio: Parameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for feature creeping. This change does not have any functional impact as it's just renaming.
@@ -0,0 +1,78 @@ | |||
|
|||
//! Autogenerated weights for `pallet_liquidity_pools` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: Committed solely for demonstration purpose, will be removed before merging!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love how clean are you getting this given that is quite difficult benchmark. 💯
libs/traits/src/benchmarking.rs
Outdated
/// Returns | ||
/// * The substrate investor address | ||
/// * The investment id | ||
/// * The pool currency id | ||
/// * The foreign currency id | ||
/// * A trading account which can bidirectionally fulfill swap orders for | ||
/// the (foreign, pool) currency pair | ||
fn bench_prepare_foreign_investments_setup() -> ( | ||
Self::AccountId, | ||
Self::InvestmentId, | ||
Self::CurrencyId, | ||
Self::CurrencyId, | ||
Self::AccountId, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a plain struct along with this trait can avoid errors when reading from these values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
) { | ||
let pool_id = Default::default(); | ||
let pool_admin: T::AccountId = frame_benchmarking::account("pool_admin", 0, 0); | ||
<T::PoolInspect as PoolBenchmarkHelper>::bench_create_pool(pool_id, &pool_admin); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment: I really like how the bench_*
methods are called inside bench_*
methods, leaving a clean API to use from the benchmark side with 0 knowledge about what's happening under the hood. i.e. the pool_id
used is totally transparent here ❤️
let pool_account = PoolLocator { pool_id }.into_account_truncating(); | ||
frame_support::assert_ok!(T::Tokens::mint_into( | ||
POOL_CURRENCY, | ||
&pool_account, | ||
POOL_ACCOUNT_BALANCE.into() | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, why is this minting now needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was taken from the integration tests when I was debugging BalanceTooLow
errors. So it might not be necessary but I believe it still is.
When we process a redemption of tranche tokens, the pool account needs to have native balance which is exchanged for these tranche tokens.
In contrast, we don't need to fund the pool account with tranche tokens as these are minted when processing an investment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
… bench/foreign-investments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Description
ForeignInvestmentBenchmarkHelper
which provides the setup required for benchmarking the heaviest foreign investment callbenchmarking
mod topallet-liquidity-pools
which benches an incomingCollectRedeem
message by executinghandle_collect_redemption
InboundQueue
since this complicates the investor setup: Right now, theinvestor
account is created during the pool creation ofpool_system::PoolBenchmarkHelper
and thus just some Substrate account id. However, for theInboundQueue
it would have to be aAccountConverter<Runtime, LocationToAccountId>::convert((sender_domain, investor_bytes))
.pallet_foreign_investments::<T>::Config::Rate
toBalanceRatio
TODO
LiquidityPools
to the runtimes' benchmark listhandle_collect_redemption
) and extrinsics by their corresponding benchmarkspallet-liquidity-pools
benchmarks cannot be unit tested, because the existing mock is insufficient. If running unit tests is desired, I propose to enable this in a subsequent PR.Justification about heaviest FI call
pallet-foreign-investments
, the heaviest action (measured by amount of reads and writes) is collecting a redemption when there exists anInvestmentState
which swaps fromforeign
topool
pool
toforeign
emerges which needs to be resolved inhandle_concurrent_swap_orders
by comparing with the existing swap from the investmentAbout the weight
For presentation purposes, I temporarily added the generated weight file. This must be removed before merging as otherwise executing benchmarks for
pallet-liquidity-pools
would remove all hardcoded values.When looking at the results of executing the benchmark on my local machine, the total weight is ~55% of the current hardcoded one. The PoV size is ~80% of the hardcoded one. For details, see the WIP Weights Sheet. I suppose the locally generated weights are close enough to our benchmark runner, since the results are similar.
Checklist: