Skip to content

Commit 33c4b3b

Browse files
author
talentdev219
committed
allocations optim (#626)
1 parent a681f42 commit 33c4b3b

File tree

16 files changed

+318
-621
lines changed

16 files changed

+318
-621
lines changed

Cargo.lock

-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/src/chain_spec.rs

+19-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
/*
2-
* This file is part of the Nodle Chain distributed at https://github.com/NodleCode/chain
3-
* Copyright (C) 2020-2022 Nodle International
4-
*
5-
* This program is free software: you can redistribute it and/or modify
6-
* it under the terms of the GNU General Public License as published by
7-
* the Free Software Foundation, either version 3 of the License, or
8-
* (at your option) any later version.
9-
*
10-
* This program is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU General Public License
16-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17-
*/
2+
* This file is part of the Nodle Chain distributed at https://github.com/NodleCode/chain
3+
* Copyright (C) 2020-2022 Nodle International
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
// clippy complains about ChainSpecGroup which we cannot modify
1820
#![allow(clippy::derive_partial_eq_without_eq)]
1921

2022
use cumulus_primitives_core::ParaId;
@@ -40,7 +42,7 @@ pub fn get_public_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pa
4042
}
4143

4244
/// The extensions for the [`ChainSpec`].
43-
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
45+
#[derive(Debug, Clone, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
4446
#[serde(rename_all = "camelCase")]
4547
pub struct Extensions {
4648
/// The relay chain of the Parachain.

pallets/allocations/Cargo.toml

+10-12
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ std = [
1616
"sp-io/std",
1717
"sp-runtime/std",
1818
"sp-std/std",
19-
"pallet-emergency-shutdown/std",
2019
]
2120
runtime-benchmarks = [
2221
"frame-benchmarking",
@@ -25,18 +24,17 @@ runtime-benchmarks = [
2524
]
2625

2726
[dependencies]
28-
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
27+
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive",] }
2928
serde = { version = "1.0.136", optional = true, features = ["derive"] }
30-
scale-info = { version = "2.0.1", default-features = false, features = ["derive"] }
31-
frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.20" }
32-
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.20" }
33-
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.20" }
34-
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.20" }
35-
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.20" }
36-
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.20" }
37-
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.20" }
38-
pallet-emergency-shutdown = { default-features = false, path = "../emergency-shutdown" }
29+
scale-info = { version = "2.0.1", default-features = false, features = [ "derive",] }
30+
frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.20" }
31+
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.20" }
32+
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.20" }
33+
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.20" }
34+
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.20" }
35+
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.20" }
36+
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.20" }
3937
support = { path = "../../support" }
4038

4139
[dev-dependencies]
42-
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.20" }
40+
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.20" }

pallets/allocations/src/benchmarking.rs

+24-14
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,56 @@
1717
*/
1818

1919
#![cfg(feature = "runtime-benchmarks")]
20-
#![allow(unused)]
2120

2221
//! Amendments pallet benchmarks
2322
2423
use super::*;
25-
2624
use crate::Pallet as Allocations;
27-
use frame_benchmarking::impl_benchmark_test_suite;
2825
use frame_benchmarking::{account, benchmarks};
26+
use frame_support::BoundedVec;
2927
use frame_system::RawOrigin;
3028
use sp_std::prelude::*;
3129

32-
const MAX_BYTES: u32 = 1_024;
3330
const SEED: u32 = 0;
3431

3532
pub struct BenchmarkConfig<T: Config> {
3633
grantee: T::AccountId,
3734
oracle: T::AccountId,
3835
}
3936

40-
fn make_benchmark_config<T: Config>(u: u32) -> BenchmarkConfig<T> {
41-
let grantee = account("grantee", u, SEED);
42-
let oracle = account("oracle", u, SEED);
37+
fn make_benchmark_config<T: Config>() -> BenchmarkConfig<T> {
38+
let grantee = account("grantee", 0, SEED);
39+
let oracle = account("oracle", 0, SEED);
4340

44-
let deposit_applying = T::ExistentialDeposit::get();
41+
BenchmarkConfig { grantee, oracle }
42+
}
4543

46-
T::Currency::make_free_balance_be(&grantee, deposit_applying);
47-
T::Currency::make_free_balance_be(&oracle, deposit_applying);
44+
type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
45+
fn make_batch<T: Config>(b: u32) -> BoundedVec<(T::AccountId, BalanceOf<T>), T::MaxAllocs> {
46+
let mut ret = BoundedVec::with_bounded_capacity(b as usize);
4847

49-
BenchmarkConfig { grantee, oracle }
48+
for i in 0..b {
49+
let account = account("grantee", i, SEED);
50+
let _ = ret.try_push((account, T::ExistentialDeposit::get() * 10u32.into()));
51+
}
52+
ret
5053
}
5154

5255
benchmarks! {
5356
allocate {
54-
let b in 1 .. MAX_BYTES;
57+
let config = make_benchmark_config::<T>();
58+
59+
Pallet::<T>::initialize_members(&[config.oracle.clone()]);
60+
}: _(RawOrigin::Signed(config.oracle.clone()), config.grantee.clone(), T::ExistentialDeposit::get() * 10u32.into(), vec![])
61+
62+
batch {
63+
let b in 1..T::MaxAllocs::get();
5564

56-
let config = make_benchmark_config::<T>(0);
65+
let config = make_benchmark_config::<T>();
66+
let batch_arg = make_batch::<T>(b);
5767

5868
Pallet::<T>::initialize_members(&[config.oracle.clone()]);
59-
}: _(RawOrigin::Signed(config.oracle.clone()), config.grantee.clone(), 40000u32.into(), vec![1; b as usize])
69+
}: _(RawOrigin::Signed(config.oracle.clone()), batch_arg)
6070

6171
impl_benchmark_test_suite!(
6272
Allocations,

0 commit comments

Comments
 (0)