Skip to content
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

Add the multi-batching pallet #7

Merged
merged 24 commits into from
Apr 26, 2024
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Fix benchmarks
niksaak committed Apr 12, 2024
commit f10fa0e137e18f03fcda40075a97eeb42e30aebd
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ members = [
"primitives/xcm",
"runtime/mainnet",
"runtime/testnet",
"pallets/multibatching",
]
resolver = "2"

4 changes: 4 additions & 0 deletions pallets/multibatching/Cargo.toml
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ frame-system = { workspace = true }
account = { workspace = true, optional = true }
sp-core = { workspace = true, default-features = false, optional = true }
sp-io = { workspace = true, default-features = false, optional = true }
sp-std = { workspace = true, default-features = false, optional = true }

#hex = { workspace = true, default-features = false } # TODO: for debugging, delete this later

@@ -45,11 +46,14 @@ std = [
"scale-info/std",
"pallet-balances/std",
"account?/std",
"sp-io?/std",
"sp-std?/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"account",
"sp-core",
"sp-io",
"sp-std",
]
try-runtime = ["frame-support/try-runtime"]
26 changes: 17 additions & 9 deletions pallets/multibatching/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#![cfg(feature = "runtime-benchmarks")]
use super::*;
#[allow(unused_imports)]
use crate::Pallet as Multibatching;
use frame_benchmarking::v2::*;
use frame_support::{dispatch::RawOrigin, BoundedVec};
use sp_core::{ecdsa::Pair as EthereumPair, keccak_256, Pair};
use sp_core::ecdsa::Public;
use sp_io::{
crypto::{ecdsa_generate, ecdsa_sign_prehashed},
hashing::keccak_256,
};
use sp_std::vec::Vec;

#[benchmarks(
where
@@ -33,19 +39,18 @@ pub mod benchmarks {

let sender: AccountId20 = whitelisted_caller();

let mut signers =
Vec::<(EthereumPair, EthereumSigner, AccountId20)>::with_capacity(signer_count);
let mut signers = Vec::<(Public, EthereumSigner, AccountId20)>::with_capacity(signer_count);
for _ in 0..signer_count {
let pair: EthereumPair = EthereumPair::generate().0;
let signer: EthereumSigner = pair.public().into();
let public: Public = ecdsa_generate(0.into(), None);
let signer: EthereumSigner = public.into();
let account = signer.clone().into_account();
signers.push((pair, signer, account));
signers.push((public, signer, account));
}

let mut calls = BoundedVec::new();
let iter = (0..call_count).into_iter().zip(signers.iter().cycle());
for (_, (_, signer, _)) in iter {
let call = frame_system::Call::remark { remark: vec![] }.into();
let call = frame_system::Call::remark { remark: Default::default() }.into();
calls
.try_push(BatchedCall::<T> { from: signer.clone().into(), call })
.ok()
@@ -69,11 +74,14 @@ pub mod benchmarks {
//eprintln!("test hash: {}", hex::encode(hash));

let mut approvals = BoundedVec::new();
for (pair, _, account) in &signers {
for (public, _signer, account) in &signers {
approvals
.try_push(Approval::<T> {
from: EthereumSigner::from(account.0).into(),
signature: EthereumSignature::from(pair.sign_prehashed(&hash.into())).into(),
signature: EthereumSignature::from(
ecdsa_sign_prehashed(0.into(), public, &hash).unwrap(),
)
.into(),
})
.ok()
.expect("Benchmark config must match runtime config for BoundedVec size");