This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
forked from paritytech/polkadot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Benchmarks for incentivized channel & constant time
verify
(parityt…
…ech#328) * Benchmarks for incentivized channel * Make Verifier::verify constant time * Add WeightInfo trait, generate weights * Merge and update benchmarks
- Loading branch information
Showing
20 changed files
with
443 additions
and
80 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 172 additions & 0 deletions
172
parachain/pallets/incentivized-channel/src/inbound/benchmarking.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
//! IncentivizedInboundChannel pallet benchmarking | ||
|
||
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use super::*; | ||
|
||
use frame_system::{RawOrigin, self, EventRecord}; | ||
use frame_benchmarking::{benchmarks, whitelisted_caller, impl_benchmark_test_suite}; | ||
use hex_literal::hex; | ||
use sp_std::convert::TryInto; | ||
|
||
use artemis_core::{ChannelId, Message, MessageId, Proof}; | ||
use artemis_ethereum::{Log, Header}; | ||
|
||
#[allow(unused_imports)] | ||
use crate::inbound::Module as IncentivizedInboundChannel; | ||
|
||
fn assert_last_event<T: Config>(system_event: <T as frame_system::Config>::Event) { | ||
let events = frame_system::Pallet::<T>::events(); | ||
// compare to the last event record | ||
let EventRecord { event, .. } = &events[events.len() - 1]; | ||
assert_eq!(event, &system_event); | ||
} | ||
|
||
// This collection of benchmarks should include a benchmark for each | ||
// call dispatched by the channel, i.e. each "app" pallet function | ||
// that can be invoked by MessageDispatch. The most expensive call | ||
// should be used in the `submit` benchmark. | ||
// | ||
// We rely on configuration via chain spec of the app pallets because | ||
// we don't have access to their storage here. | ||
benchmarks! { | ||
// Benchmark `submit` extrinsic under worst case conditions: | ||
// * `submit` dispatches the DotApp::unlock call | ||
// * `unlock` call successfully unlocks DOT | ||
submit { | ||
let caller: T::AccountId = whitelisted_caller(); | ||
let (header, message) = dot_unlock_data(); | ||
let envelope: envelope::Envelope<T> = rlp::decode::<Log>(&message.data) | ||
.map(|log| log.try_into().unwrap()) | ||
.unwrap(); | ||
Nonce::put(envelope.nonce - 1); | ||
SourceChannel::put(envelope.channel); | ||
|
||
T::Verifier::initialize_storage( | ||
vec![header], | ||
0.into(), | ||
0, // forces all headers to be finalized | ||
)?; | ||
|
||
}: _(RawOrigin::Signed(caller.clone()), message) | ||
verify { | ||
assert_eq!(envelope.nonce, Nonce::get()); | ||
|
||
let message_id = MessageId::new(ChannelId::Incentivized, envelope.nonce); | ||
if let Some(event) = T::MessageDispatch::successful_dispatch_event(message_id) { | ||
assert_last_event::<T>(event); | ||
} | ||
} | ||
|
||
#[extra] | ||
submit_eth_mint { | ||
let caller: T::AccountId = whitelisted_caller(); | ||
let (header, message) = eth_mint_data(); | ||
let envelope: envelope::Envelope<T> = rlp::decode::<Log>(&message.data) | ||
.map(|log| log.try_into().unwrap()) | ||
.unwrap(); | ||
Nonce::put(envelope.nonce - 1); | ||
SourceChannel::put(envelope.channel); | ||
|
||
T::Verifier::initialize_storage( | ||
vec![header], | ||
0.into(), | ||
0, // forces all headers to be finalized | ||
)?; | ||
|
||
}: submit(RawOrigin::Signed(caller.clone()), message) | ||
verify { | ||
assert_eq!(envelope.nonce, Nonce::get()); | ||
|
||
let message_id = MessageId::new(ChannelId::Incentivized, envelope.nonce); | ||
if let Some(event) = T::MessageDispatch::successful_dispatch_event(message_id) { | ||
assert_last_event::<T>(event); | ||
} | ||
} | ||
|
||
// TODO: add back ECR20 mint benchmark | ||
} | ||
|
||
// ETH mint | ||
// Channel = 0xeda338e4dc46038493b885327842fd3e301cab39 | ||
// Nonce = 2 | ||
// Source = 0x774667629726ec1fabebcec0d9139bd1c8f72a23 | ||
fn eth_mint_data() -> (Header, Message) { | ||
( | ||
Header { | ||
parent_hash: hex!("3f136282153539e5b4006c05d0c6ab033786d5793c7cc3b784ca3b274918181e").into(), | ||
timestamp: 1618295862u64.into(), | ||
number: 3584u64.into(), | ||
author: hex!("0000000000000000000000000000000000000000").into(), | ||
transactions_root: hex!("84ed6b4ad707994d7095eff6f5458d2c6e351fcab00669b084705229faa63840").into(), | ||
ommers_hash: hex!("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347").into(), | ||
extra_data: hex!("").into(), | ||
state_root: hex!("ab5ce23d0914c05c74504cb797349fa8fca1b9b286f2f1ab11f0adb7f8c2d12c").into(), | ||
receipts_root: hex!("ac1dbc12173e495453bf5277fb1cc507a092218adcb795e7743308615ed62c89").into(), | ||
logs_bloom: (&hex!("00000000000040000000000000000200000000000000400010000000010080000000000000000000000000001000000010000000000000000000000000000080000000000000000400000008000000000000000000008000000000000000000000000000020000000000000000000800000001000400000000000010000000000000020000000000000000000400000000000000000000000000040000000000000000000004000000000000000000000220000000000001000000000200080000000002000000000000000000000000000000000000000000000000000020402000000000000000000000000000000000000000000000000000000000000000")).into(), | ||
gas_used: 97210u64.into(), | ||
gas_limit: 6721975u64.into(), | ||
difficulty: 0u64.into(), | ||
seal: vec![ | ||
hex!("a00000000000000000000000000000000000000000000000000000000000000000").to_vec(), | ||
hex!("880000000000000000").to_vec(), | ||
], | ||
}, | ||
Message { | ||
data: hex!("f9013a94eda338e4dc46038493b885327842fd3e301cab39e1a05e9ae1d7c484f74d554a503aa825e823725531d97e784dd9b1aacdb58d1f7076b90100000000000000000000000000774667629726ec1fabebcec0d9139bd1c8f72a2300000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000570c0189b4ab1ef20763630df9743acf155865600daff200d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d0000c16ff2862300000000000000000000000000000000000000000000000000000000000000000000").to_vec(), | ||
proof: Proof { | ||
block_hash: hex!("fbd6740f975d184468373c65c1278051403867361c03ab8c245c5ff42e53c9e2").into(), | ||
tx_index: 0, | ||
data: ( | ||
vec![hex!("ac1dbc12173e495453bf5277fb1cc507a092218adcb795e7743308615ed62c89").to_vec()], | ||
vec![hex!("f904a8822080b904a2f9049f0183017bbab9010000000000000040000000000000000200000000000000400010000000010080000000000000000000000000001000000010000000000000000000000000000080000000000000000400000008000000000000000000008000000000000000000000000000020000000000000000000800000001000400000000000010000000000000020000000000000000000400000000000000000000000000040000000000000000000004000000000000000000000220000000000001000000000200080000000002000000000000000000000000000000000000000000000000000020402000000000000000000000000000000000000000000000000000000000000000f90394f89994774667629726ec1fabebcec0d9139bd1c8f72a23e1a0caae0f5e72020d428da73a237d1f9bf162e158dda6d4908769b8b60c095b01f4b86000000000000000000000000089b4ab1ef20763630df9743acf155865600daff2d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d000000000000000000000000000000000000000000000000002386f26fc10000f9011c94672a95c8928c8450b594186cf7954ec269626a2df863a0a78a9be3a7b862d26933ad85fb11d80ef66b8f972d7cbba06621d583943a4098a0000000000000000000000000b1185ede04202fe62d38f5db72f71e38ff3e8305a000000000000000000000000089b4ab1ef20763630df9743acf155865600daff2b8a00000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f89b94672a95c8928c8450b594186cf7954ec269626a2df863a0ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa000000000000000000000000089b4ab1ef20763630df9743acf155865600daff2a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000de0b6b3a7640000f9013a94eda338e4dc46038493b885327842fd3e301cab39e1a05e9ae1d7c484f74d554a503aa825e823725531d97e784dd9b1aacdb58d1f7076b90100000000000000000000000000774667629726ec1fabebcec0d9139bd1c8f72a2300000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000570c0189b4ab1ef20763630df9743acf155865600daff200d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d0000c16ff2862300000000000000000000000000000000000000000000000000000000000000000000").to_vec()], | ||
), | ||
}, | ||
}, | ||
) | ||
} | ||
|
||
// DOT unlock | ||
// Channel = 0xeda338e4dc46038493b885327842fd3e301cab39 | ||
// Nonce = 1 | ||
// Source = 0xb1185ede04202fe62d38f5db72f71e38ff3e8305 | ||
fn dot_unlock_data() -> (Header, Message) { | ||
( | ||
Header { | ||
parent_hash: hex!("6e54738f4e58949361383e11d06cfe5b72c87410881230fae3289f1de8487927").into(), | ||
timestamp: 1618291501u64.into(), | ||
number: 2496u64.into(), | ||
author: hex!("0000000000000000000000000000000000000000").into(), | ||
transactions_root: hex!("9c53bbde6f3dfe2afd272cfd64a8639db23588d3ec63406b5225b38fa79a0490").into(), | ||
ommers_hash: hex!("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347").into(), | ||
extra_data: hex!("").into(), | ||
state_root: hex!("b262afa00f5d920137d59f2061cb2075a9cece1d53775ba6f1b38f88423f6ff7").into(), | ||
receipts_root: hex!("f19e53a299860306c5ad8201b28f78d505ea4a46f08739f2f58def37652cd386").into(), | ||
logs_bloom: (&hex!("00000000000040000000000000000200000000000000000010000000000080000000000000000000000000001000000010000000000000000000000000000000000000000000000400000008000000000000000000008000000000000000000000000000020000000000000000000800000001000400000000000010000000000000020000000000000000000400000000000000000000000000040000000000000000000004000000000000000000000200000000000001000000000200000000000002000000000000000000000000000000000000000000000000000020400000000000000000000000000000000000000000000000000000000000000000")).into(), | ||
gas_used: 107966u64.into(), | ||
gas_limit: 6721975u64.into(), | ||
difficulty: 0u64.into(), | ||
seal: vec![ | ||
hex!("a00000000000000000000000000000000000000000000000000000000000000000").to_vec(), | ||
hex!("880000000000000000").to_vec(), | ||
], | ||
}, | ||
Message { | ||
data: hex!("f9013a94eda338e4dc46038493b885327842fd3e301cab39e1a05e9ae1d7c484f74d554a503aa825e823725531d97e784dd9b1aacdb58d1f7076b90100000000000000000000000000b1185ede04202fe62d38f5db72f71e38ff3e830500000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000570e0189b4ab1ef20763630df9743acf155865600daff200d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d000064a7b3b6e00d000000000000000000000000000000000000000000000000000000000000000000").to_vec(), | ||
proof: Proof { | ||
block_hash: hex!("2e2ac53ae0dcd35d23e004d105f21a07cfb841ee7f86b5edd957067684d61f85").into(), | ||
tx_index: 0, | ||
data: ( | ||
vec![hex!("f19e53a299860306c5ad8201b28f78d505ea4a46f08739f2f58def37652cd386").to_vec()], | ||
vec![hex!("f905e9822080b905e3f905e0018301a5beb9010000000000000040000000000000000200000000000000000010000000000080000000000000000000000000001000000010000000000000000000000000000000000000000000000400000008000000000000000000008000000000000000000000000000020000000000000000000800000001000400000000000010000000000000020000000000000000000400000000000000000000000000040000000000000000000004000000000000000000000200000000000001000000000200000000000002000000000000000000000000000000000000000000000000000020400000000000000000000000000000000000000000000000000000000000000000f904d5f9013c94672a95c8928c8450b594186cf7954ec269626a2df863a0a78a9be3a7b862d26933ad85fb11d80ef66b8f972d7cbba06621d583943a4098a0000000000000000000000000b1185ede04202fe62d38f5db72f71e38ff3e8305a000000000000000000000000089b4ab1ef20763630df9743acf155865600daff2b8c00000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000020d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d0000000000000000000000000000000000000000000000000000000000000000f89b94672a95c8928c8450b594186cf7954ec269626a2df863a0ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa000000000000000000000000089b4ab1ef20763630df9743acf155865600daff2a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000de0b6b3a7640000f9011c94672a95c8928c8450b594186cf7954ec269626a2df863a0a78a9be3a7b862d26933ad85fb11d80ef66b8f972d7cbba06621d583943a4098a0000000000000000000000000b1185ede04202fe62d38f5db72f71e38ff3e8305a000000000000000000000000089b4ab1ef20763630df9743acf155865600daff2b8a00000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f89b94672a95c8928c8450b594186cf7954ec269626a2df863a0ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa000000000000000000000000089b4ab1ef20763630df9743acf155865600daff2a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000de0b6b3a7640000f9013a94eda338e4dc46038493b885327842fd3e301cab39e1a05e9ae1d7c484f74d554a503aa825e823725531d97e784dd9b1aacdb58d1f7076b90100000000000000000000000000b1185ede04202fe62d38f5db72f71e38ff3e830500000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000570e0189b4ab1ef20763630df9743acf155865600daff200d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d000064a7b3b6e00d000000000000000000000000000000000000000000000000000000000000000000").to_vec()], | ||
), | ||
}, | ||
}, | ||
) | ||
} | ||
|
||
impl_benchmark_test_suite!( | ||
IncentivizedInboundChannel, | ||
crate::inbound::test::new_tester(Default::default()), | ||
crate::inbound::test::Test, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.