Skip to content

Commit 021cb98

Browse files
Add lock_instruction common benchmark
1 parent 674d950 commit 021cb98

File tree

3 files changed

+125
-3
lines changed

3 files changed

+125
-3
lines changed

pallets/settlement/src/benchmarking.rs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1515

1616
pub use frame_benchmarking::{account, benchmarks};
17+
use frame_support::storage::with_transaction as frame_support_with_transaction;
1718
use frame_support::traits::{Get, TryCollect};
1819
use frame_system::RawOrigin;
1920
use scale_info::prelude::format;
@@ -29,7 +30,7 @@ use polymesh_primitives::checked_inc::CheckedInc;
2930
use polymesh_primitives::constants::currency::ONE_UNIT;
3031
use polymesh_primitives::constants::ENSURED_MAX_LEN;
3132
use polymesh_primitives::settlement::ReceiptMetadata;
32-
use polymesh_primitives::{IdentityId, Memo, NFTId, NFTs, PortfolioId, Ticker};
33+
use polymesh_primitives::{IdentityId, Memo, NFTId, NFTs, PortfolioId, Ticker, WeightMeter};
3334

3435
use crate::*;
3536

@@ -875,4 +876,47 @@ benchmarks! {
875876
InstructionStatuses::<T>::insert(inst_id, InstructionStatus::Rejected(System::<T>::block_number()));
876877
}
877878

879+
lock_instruction_common {
880+
let f in 1..T::MaxNumberOfFungibleAssets::get();
881+
let n in 0..T::MaxNumberOfNFTs::get();
882+
let o in 0..T::MaxNumberOfOffChainAssets::get();
883+
884+
let m = T::MaxInstructionMediators::get();
885+
886+
let alice = UserBuilder::<T>::default().generate_did().build("Alice");
887+
let bob = UserBuilder::<T>::default().generate_did().build("Bob");
888+
let settlement_type = SettlementType::SettleAfterLock;
889+
let venue_id = create_venue_::<T>(alice.did(), vec![alice.account(), bob.account()]);
890+
891+
let inst_id = InstructionId(1);
892+
let parameters = setup_execute_instruction::<T>(&alice, &bob, settlement_type, venue_id, f, n, o, m, true, true);
893+
}: {
894+
let caller_did =
895+
pallet_identity::Pallet::<T>::ensure_perms(parameters.asset_mediators[0].clone().origin.into()).unwrap();
896+
Pallet::<T>::ensure_mediator(&inst_id, &caller_did).unwrap();
897+
898+
let _ = InstructionDetails::<T>::get(&inst_id);
899+
let inst_memo = InstructionMemos::<T>::get(&inst_id);
900+
901+
let inst_legs: Vec<_> = InstructionLegs::<T>::iter_prefix(&inst_id).collect();
902+
let _ = AssetCount::from_legs(&inst_legs);
903+
904+
frame_support_with_transaction(|| {
905+
Pallet::<T>::release_locks(&inst_id, &inst_legs).unwrap();
906+
Pallet::<T>::transfer_assets(
907+
inst_id,
908+
&inst_legs,
909+
inst_memo,
910+
caller_did,
911+
&mut WeightMeter::max_limit_no_minimum()
912+
)
913+
.unwrap();
914+
TransactionOutcome::Rollback(Ok::<(), DispatchError>(()))
915+
})
916+
.unwrap();
917+
918+
InstructionStatuses::<T>::insert(inst_id, InstructionStatus::LockedForExecution);
919+
LockedTimestamp::<T>::insert(inst_id, pallet_timestamp::Pallet::<T>::get());
920+
}
921+
878922
}

pallets/settlement/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3148,6 +3148,15 @@ impl<T: Config> Pallet<T> {
31483148
inst_legs.sort_by_key(|leg| leg.0);
31493149
let inst_asset_count = AssetCount::from_legs(&inst_legs);
31503150

3151+
Self::check_accrue(
3152+
weight_meter,
3153+
<T as Config>::WeightInfo::lock_instruction_common(
3154+
inst_asset_count.fungible(),
3155+
inst_asset_count.non_fungible(),
3156+
inst_asset_count.off_chain(),
3157+
),
3158+
)?;
3159+
31513160
Self::validate_execute_instruction_pre_conditions(
31523161
&inst_id,
31533162
&inst_legs,

pallets/weights/src/pallet_settlement.rs

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,76 @@ impl pallet_settlement::WeightInfo for SubstrateWeight {
11191119
.saturating_add(DbWeight::get().writes((1_u64).saturating_mul(f.into())))
11201120
.saturating_add(DbWeight::get().writes((1_u64).saturating_mul(n.into())))
11211121
}
1122-
fn lock_instruction_common(_f: u32, _n: u32, _o: u32) -> Weight {
1123-
Weight::zero()
1122+
// Storage: Identity KeyRecords (r:1 w:0)
1123+
// Proof: Identity KeyRecords (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen)
1124+
// Storage: Settlement InstructionMediatorsAffirmations (r:1 w:0)
1125+
// Proof: Settlement InstructionMediatorsAffirmations (max_values: None, max_size: Some(58), added: 2533, mode: MaxEncodedLen)
1126+
// Storage: Settlement InstructionDetails (r:1 w:0)
1127+
// Proof: Settlement InstructionDetails (max_values: None, max_size: Some(65), added: 2540, mode: MaxEncodedLen)
1128+
// Storage: Settlement InstructionMemos (r:1 w:0)
1129+
// Proof: Settlement InstructionMemos (max_values: None, max_size: Some(48), added: 2523, mode: MaxEncodedLen)
1130+
// Storage: Settlement InstructionLegs (r:121 w:0)
1131+
// Proof Skipped: Settlement InstructionLegs (max_values: None, max_size: None, mode: Measured)
1132+
// Storage: Settlement InstructionLegStatus (r:120 w:0)
1133+
// Proof: Settlement InstructionLegStatus (max_values: None, max_size: Some(73), added: 2548, mode: MaxEncodedLen)
1134+
// Storage: Portfolio PortfolioLockedNFT (r:100 w:0)
1135+
// Proof: Portfolio PortfolioLockedNFT (max_values: None, max_size: Some(90), added: 2565, mode: MaxEncodedLen)
1136+
// Storage: Portfolio PortfolioLockedAssets (r:10 w:0)
1137+
// Proof: Portfolio PortfolioLockedAssets (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen)
1138+
// Storage: Nft CollectionAsset (r:100 w:0)
1139+
// Proof: Nft CollectionAsset (max_values: None, max_size: Some(40), added: 2515, mode: MaxEncodedLen)
1140+
// Storage: Nft NumberOfNFTs (r:200 w:0)
1141+
// Proof: Nft NumberOfNFTs (max_values: None, max_size: Some(72), added: 2547, mode: MaxEncodedLen)
1142+
// Storage: Portfolio PortfolioNFT (r:100 w:0)
1143+
// Proof: Portfolio PortfolioNFT (max_values: None, max_size: Some(90), added: 2565, mode: MaxEncodedLen)
1144+
// Storage: Asset Frozen (r:110 w:0)
1145+
// Proof: Asset Frozen (max_values: None, max_size: Some(33), added: 2508, mode: MaxEncodedLen)
1146+
// Storage: Timestamp Now (r:1 w:0)
1147+
// Proof: Timestamp Now (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen)
1148+
// Storage: CddServiceProviders ActiveMembers (r:1 w:0)
1149+
// Proof Skipped: CddServiceProviders ActiveMembers (max_values: Some(1), max_size: None, mode: Measured)
1150+
// Storage: Identity Claims (r:4 w:0)
1151+
// Proof Skipped: Identity Claims (max_values: None, max_size: None, mode: Measured)
1152+
// Storage: ComplianceManager AssetCompliances (r:110 w:0)
1153+
// Proof Skipped: ComplianceManager AssetCompliances (max_values: None, max_size: None, mode: Measured)
1154+
// Storage: Asset Assets (r:10 w:0)
1155+
// Proof Skipped: Asset Assets (max_values: None, max_size: None, mode: Measured)
1156+
// Storage: Asset BalanceOf (r:20 w:0)
1157+
// Proof: Asset BalanceOf (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen)
1158+
// Storage: Portfolio Portfolios (r:20 w:0)
1159+
// Proof Skipped: Portfolio Portfolios (max_values: None, max_size: None, mode: Measured)
1160+
// Storage: Portfolio PortfolioAssetBalances (r:20 w:0)
1161+
// Proof: Portfolio PortfolioAssetBalances (max_values: None, max_size: Some(97), added: 2572, mode: MaxEncodedLen)
1162+
// Storage: Statistics AssetTransferCompliances (r:10 w:0)
1163+
// Proof: Statistics AssetTransferCompliances (max_values: None, max_size: Some(246), added: 2721, mode: MaxEncodedLen)
1164+
// Storage: Checkpoint CachedNextCheckpoints (r:10 w:0)
1165+
// Proof Skipped: Checkpoint CachedNextCheckpoints (max_values: None, max_size: None, mode: Measured)
1166+
// Storage: Checkpoint CheckpointIdSequence (r:10 w:0)
1167+
// Proof: Checkpoint CheckpointIdSequence (max_values: None, max_size: Some(40), added: 2515, mode: MaxEncodedLen)
1168+
// Storage: Portfolio PortfolioAssetCount (r:10 w:0)
1169+
// Proof: Portfolio PortfolioAssetCount (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen)
1170+
// Storage: Statistics ActiveAssetStats (r:10 w:0)
1171+
// Proof: Statistics ActiveAssetStats (max_values: None, max_size: Some(423), added: 2898, mode: MaxEncodedLen)
1172+
// Storage: Settlement InstructionStatuses (r:0 w:1)
1173+
// Proof: Settlement InstructionStatuses (max_values: None, max_size: Some(21), added: 2496, mode: MaxEncodedLen)
1174+
// Storage: Settlement LockedTimestamp (r:0 w:1)
1175+
// Proof: Settlement LockedTimestamp (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen)
1176+
/// The range of component `f` is `[1, 10]`.
1177+
/// The range of component `n` is `[0, 100]`.
1178+
/// The range of component `o` is `[0, 10]`.
1179+
fn lock_instruction_common(f: u32, n: u32, o: u32) -> Weight {
1180+
// Minimum execution time: 1_808_704 nanoseconds.
1181+
Weight::from_ref_time(56_320_006)
1182+
// Standard Error: 1_710_336
1183+
.saturating_add(Weight::from_ref_time(151_928_134).saturating_mul(f.into()))
1184+
// Standard Error: 158_210
1185+
.saturating_add(Weight::from_ref_time(126_987_606).saturating_mul(n.into()))
1186+
// Standard Error: 1_549_300
1187+
.saturating_add(Weight::from_ref_time(10_140_105).saturating_mul(o.into()))
1188+
.saturating_add(DbWeight::get().reads(11))
1189+
.saturating_add(DbWeight::get().reads((17_u64).saturating_mul(f.into())))
1190+
.saturating_add(DbWeight::get().reads((9_u64).saturating_mul(n.into())))
1191+
.saturating_add(DbWeight::get().reads((2_u64).saturating_mul(o.into())))
1192+
.saturating_add(DbWeight::get().writes(2))
11241193
}
11251194
}

0 commit comments

Comments
 (0)