Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
16ad36c
initial stuff
shawntabrizi Sep 27, 2021
cbd0dc8
Merge branch 'master' into shawntabrizi-xcm-generic-benchmarks
shawntabrizi Oct 4, 2021
82caeec
quick fixes
shawntabrizi Oct 4, 2021
e3a0f4a
move to individual tests
shawntabrizi Oct 4, 2021
f5b3269
dont need these
shawntabrizi Oct 4, 2021
29bfa5d
Update benchmarking.rs
shawntabrizi Oct 4, 2021
ec573a0
add to westend
shawntabrizi Oct 4, 2021
e3a7c02
Merge branch 'master' into shawntabrizi-xcm-generic-benchmarks
shawntabrizi Nov 11, 2021
77b1fbd
make benchmarks execute
shawntabrizi Nov 12, 2021
470ce15
fix compile
shawntabrizi Nov 14, 2021
82149ac
add post_execute
shawntabrizi Nov 15, 2021
b817e7c
ClaimAsset benchmark working
shawntabrizi Nov 15, 2021
3d9f774
subscribe and unsubscribe benchmarks
shawntabrizi Nov 15, 2021
e85c556
benchmark for initiate reserve withdraw
shawntabrizi Nov 15, 2021
e64c9ae
Merge branch 'master' into shawntabrizi-xcm-generic-benchmarks
shawntabrizi Nov 15, 2021
3aa3b3c
cargo run --quiet --release --features=runtime-benchmarks -- benchmar…
Nov 15, 2021
30c13a2
fix spell check
shawntabrizi Nov 15, 2021
270c283
Merge branch 'master' into shawntabrizi-xcm-generic-benchmarks
shawntabrizi Nov 15, 2021
041b3f4
Merge branch 'master' into shawntabrizi-xcm-generic-benchmarks
shawntabrizi Nov 15, 2021
cd190e2
cargo run --quiet --release --features=runtime-benchmarks -- benchmar…
Nov 15, 2021
2ee0d81
update worst case for query_holding
shawntabrizi Nov 16, 2021
02248db
Merge branch 'master' of https://github.com/paritytech/polkadot into …
Nov 16, 2021
a9a3b29
cargo run --quiet --release --features=runtime-benchmarks -- benchmar…
Nov 16, 2021
f51acc3
move verification logic below
shawntabrizi Nov 16, 2021
1e80cfe
introduce worst case holding to initiate reserve withdraw
shawntabrizi Nov 16, 2021
9178fbe
cargo run --quiet --release --features=runtime-benchmarks -- benchmar…
Nov 16, 2021
d8da46b
Merge branch 'master' into shawntabrizi-xcm-generic-benchmarks
shawntabrizi Nov 24, 2021
978b015
Merge branch 'master' into shawntabrizi-xcm-generic-benchmarks
shawntabrizi Nov 30, 2021
23602ca
feedback
shawntabrizi Nov 30, 2021
21fde67
Merge branch 'master' into shawntabrizi-xcm-generic-benchmarks
shawntabrizi Nov 30, 2021
2779039
cargo run --quiet --release --features=runtime-benchmarks -- benchmar…
Nov 30, 2021
98964be
Revert "cargo run --quiet --release --features=runtime-benchmarks -- …
shawntabrizi Nov 30, 2021
4939b63
fix benchmark template
shawntabrizi Nov 30, 2021
be2036d
cargo run --quiet --release --features=runtime-benchmarks -- benchmar…
Nov 30, 2021
4efd026
use response::version
shawntabrizi Dec 1, 2021
6c0ceed
Merge branch 'master' of https://github.com/paritytech/polkadot into …
Dec 1, 2021
77b183f
cargo run --quiet --release --features=runtime-benchmarks -- benchmar…
Dec 1, 2021
d783d40
refactor worst case holding
shawntabrizi Dec 1, 2021
2a9582b
Merge branch 'shawntabrizi-xcm-generic-benchmarks' of https://github.…
shawntabrizi Dec 1, 2021
6512a26
cargo run --quiet --release --features=runtime-benchmarks -- benchmar…
Dec 1, 2021
df66c1f
fmt
shawntabrizi Dec 1, 2021
fc51779
Merge branch 'shawntabrizi-xcm-generic-benchmarks' of https://github.…
shawntabrizi Dec 1, 2021
cd0f4b8
one more todo needs to be labeled
shawntabrizi Dec 1, 2021
b7e3ced
change option to result with benchmark error
shawntabrizi Dec 1, 2021
3c4dcb4
fmt and fix import
shawntabrizi Dec 1, 2021
a9ea6c1
Merge branch 'master' into shawntabrizi-xcm-generic-benchmarks
shawntabrizi Dec 1, 2021
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
Next Next commit
initial stuff
  • Loading branch information
shawntabrizi committed Sep 27, 2021
commit 16ad36c0c3e89b8579e76b0244eb23ff79f93daa
272 changes: 272 additions & 0 deletions xcm/pallet-xcm-benchmarks/src/generic/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
// Copyright 2021 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use super::*;
use crate::{new_executor, worst_case_holding, XcmCallOf};
use codec::Encode;
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, BenchmarkError};
use frame_support::dispatch::GetDispatchInfo;
use sp_std::vec;
use xcm::{latest::prelude::*, DoubleEncoded};

const MAX_ASSETS: u32 = 100;

benchmarks! {
query_holding {
let holding = worst_case_holding();

let mut executor = new_executor::<T>(Default::default());
executor.holding = holding;

let instruction = Instruction::<XcmCallOf<T>>::QueryHolding {
query_id: Default::default(),
dest: T::valid_destination()?,
assets: Wild(WildMultiAsset::All), // TODO is worst case filter?
max_response_weight: u64::MAX,
};

let xcm = Xcm(vec![instruction]);

} : {
executor.execute(xcm)?;
} verify {
// The assert above is enough to validate this is completed.
// todo maybe XCM sender peek
}

// This benchmark does not use any additional orders or instructions. This should be managed
// by the `deep` and `shallow` implementation.
buy_execution {
let holding = worst_case_holding();

let mut executor = new_executor::<T>(Default::default());
executor.holding = holding;

let fee_asset = Concrete(Here.into());

let instruction = Instruction::<XcmCallOf<T>>::BuyExecution {
fees: (fee_asset, 100_000_000).into(), // should be something inside of holding
weight_limit: WeightLimit::Unlimited,
};

let xcm = Xcm(vec![instruction]);
} : {
executor.execute(xcm)?;
} verify {

}

// Worst case scenario for this benchmark is a large number of assets to
// filter through the reserve.
reserve_asset_deposited {
let mut executor = new_executor::<T>(Default::default());
// TODO real max assets
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO
I assume you have an issue tracking this?

let assets = (0..MAX_ASSETS).map(|i| MultiAsset {
id: Abstract(i.encode()),
fun: Fungible(i as u128),

}).collect::<Vec<_>>();
let multiassets: MultiAssets = assets.into();

let instruction = Instruction::ReserveAssetDeposited(multiassets.clone());
let xcm = Xcm(vec![instruction]);
}: {
executor.execute(xcm)?;
} verify {
assert_eq!(executor.holding, multiassets.into());
}

query_response {
let mut executor = new_executor::<T>(Default::default());
let (query_id, response) = T::worst_case_response();
let max_weight = u64::MAX;
let instruction = Instruction::QueryResponse { query_id, response, max_weight };
let xcm = Xcm(vec![instruction]);
}: {
executor.execute(xcm)?;
} verify {
// The assert above is enough to show this XCM succeeded
}

// We don't care about the call itself, since that is accounted for in the weight parameter
// and included in the final weight calculation. So this is just the overhead of submitting
// a noop call.
transact {
let mut executor = new_executor::<T>(Default::default());
let noop_call: <T as Config>::Call = frame_system::Call::remark_with_event {
remark: Default::default()
}.into();
let double_encoded_noop_call: DoubleEncoded<_> = noop_call.encode().into();

let instruction = Instruction::Transact {
origin_type: OriginKind::SovereignAccount,
require_weight_at_most: noop_call.get_dispatch_info().weight,
call: double_encoded_noop_call,
};
let xcm = Xcm(vec![instruction]);

let num_events = frame_system::Pallet::<T>::events().len();
}: {
executor.execute(xcm)?;
} verify {
// TODO make better assertion?
let num_events2 = frame_system::Pallet::<T>::events().len();
assert_eq!(num_events + 1, num_events2);
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO
seems hacky to verify successful execution this way, but I also don't have a better idea 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah the better idea i had was an extrinsic which modifies storage, but System::set_storage is a root function, and then we wouldn't always be able to pass the origin test.

}

// hrmp_new_channel_open_request {
// let mut executor = new_executor::<T>(Default::default());
// let instruction = Instruction::HrmpNewChannelOpenRequest {
// sender: 1,
// max_message_size: 100,
// max_capacity: 100
// };

// let xcm = Xcm(vec![instruction]);
// }: {
// executor.execute(xcm)?;
// } verify {
// // TODO: query pallet
// }

// hrmp_channel_accepted {
// let mut executor = new_executor::<T>(Default::default());
// // TODO open channel request first.

// let instruction = Instruction::HrmpChannelAccepted {
// recipient: 1,
// };
// let xcm = Xcm(vec![instruction]);
// }: {
// executor.execute(xcm)?;
// } verify {
// // TODO: query pallet
// }

// hrmp_channel_closing {
// let (sender_account, sender_location) = account_and_location::<T>(1);
// // TODO open channel first.

// let instruction = Instruction::HrmpChannelClosing {
// initiator: 1,
// sender: 1,
// recipient: 2,
// };
// let xcm = Xcm(vec![instruction]);
// }: {
// execute_xcm_override_error::<T>(sender_location, Default::default(), xcm)?;
// } verify {
// // TODO: query pallet
// }

refund_surplus {
let mut executor = new_executor::<T>(Default::default());
executor.total_surplus = 1337;
executor.total_refunded = 0;

let instruction = Instruction::<XcmCallOf<T>>::RefundSurplus;
let xcm = Xcm(vec![instruction]);
} : {
let result = executor.execute(xcm)?;
} verify {
assert_eq!(executor.total_surplus, 1337);
assert_eq!(executor.total_refunded, 1337);
}

set_error_handler {
let mut executor = new_executor::<T>(Default::default());
let instruction = Instruction::<XcmCallOf<T>>::SetErrorHandler(Xcm(vec![]));
let xcm = Xcm(vec![instruction]);
} : {
executor.execute(xcm)?;
} verify {
assert_eq!(executor.error_handler, Xcm(vec![]));
}

set_appendix {

} : {

} verify {}

clear_error {
let mut executor = new_executor::<T>(Default::default());
executor.error = Some((5u32, XcmError::Undefined));
let instruction = Instruction::<XcmCallOf<T>>::ClearError;
let xcm = Xcm(vec![instruction]);
} : {
executor.execute(xcm)?;
} verify {
assert!(executor.error.is_none())
}

descend_origin {
let mut executor = new_executor::<T>(Default::default());
let who = X2(OnlyChild, OnlyChild);
let instruction = Instruction::DescendOrigin(who.clone());
let xcm = Xcm(vec![instruction]);
} : {
executor.execute(xcm)?;
} verify {
assert_eq!(
executor.origin,
Some(MultiLocation {
parents: 0,
interior: who,
}),
);
}

clear_origin {
let mut executor = new_executor::<T>(Default::default());
let instruction = Instruction::ClearOrigin;
let xcm = Xcm(vec![instruction]);
} : {
executor.execute(xcm)?;
} verify {
assert_eq!(executor.origin, None);
Copy link
Contributor

Choose a reason for hiding this comment

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

what is this value before the benchmark?

}

claim_asset {

} : {} verify {}

trap {
let mut executor = new_executor::<T>(Default::default());
let instruction = Instruction::Trap(10);
let xcm = Xcm(vec![instruction]);
} : {
match executor.execute(xcm) {
Err(error) if error.xcm_error == XcmError::Trap(10) => {
// This is the success condition
},
_ => return Err(BenchmarkError::Stop("xcm trap did not return the expected error"))
};
} verify {
// Verification is done above.
}

subscribe_version {} : {} verify {}

unsubscribe_version {} : {} verify {}

}

impl_benchmark_test_suite!(
Pallet,
crate::generic::mock::new_test_ext(),
crate::generic::mock::Test
);
Loading