Skip to content

Commit

Permalink
Benchmark Democracy Pallet (#5257)
Browse files Browse the repository at this point in the history
* Add origin bounds to benchmark macro.

* Add democracy benchmark.

* Fix tests

* Remove collective from frame/benchmarking, partially use EnsureOrigin.

* Remove collective stuff.

* Make previous benches compile again.

* Remove comments.

* Make prev bench to work again.

* Add remove votes.

* Add new proxy calls.

* Add runtime-benchmarks guard to EnsureOrigin and implementations.

* Refactor.

* Add missing import.

* Remove duplicated import

* Fix features.

* Add some missing features.

* Update frame/collective/Cargo.toml

Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Update frame/democracy/src/benchmarking.rs

Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Update frame/democracy/src/benchmarking.rs

Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Add referendums to state.

* populate vecs before call

* Update weight docs

* More fixes and weight docs

* More updates

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
  • Loading branch information
3 people authored Mar 26, 2020
1 parent a077211 commit 5a48cad
Show file tree
Hide file tree
Showing 17 changed files with 564 additions and 15 deletions.
1 change: 1 addition & 0 deletions substrate/Cargo.lock

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

6 changes: 5 additions & 1 deletion substrate/bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,20 @@ std = [
runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-elections-phragmen/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"pallet-session-benchmarking",
"pallet-staking/runtime-benchmarks",
"pallet-vesting/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-session-benchmarking",
"pallet-staking/runtime-benchmarks",
"pallet-society/runtime-benchmarks",
"pallet-im-online/runtime-benchmarks",
"pallet-democracy/runtime-benchmarks",
]
7 changes: 7 additions & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,13 @@ impl_runtime_apis! {
steps,
repeat,
),
b"pallet-democracy" | b"democracy" => Democracy::run_benchmark(
extrinsic,
lowest_range_values,
highest_range_values,
steps,
repeat,
),
b"pallet-collective" | b"collective" => Council::run_benchmark(
extrinsic,
lowest_range_values,
Expand Down
7 changes: 5 additions & 2 deletions substrate/frame/collective/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ std = [
"sp-std/std",
"serde",
"sp-io/std",
"frame-benchmarking/std",
"frame-support/std",
"sp-runtime/std",
"frame-system/std",
]
runtime-benchmarks = ["frame-benchmarking"]
runtime-benchmarks = [
"frame-benchmarking",
"sp-runtime/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
22 changes: 21 additions & 1 deletion substrate/frame/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ where
pub struct EnsureMember<AccountId, I=DefaultInstance>(sp_std::marker::PhantomData<(AccountId, I)>);
impl<
O: Into<Result<RawOrigin<AccountId, I>, O>> + From<RawOrigin<AccountId, I>>,
AccountId,
AccountId: Default,
I,
> EnsureOrigin<O> for EnsureMember<AccountId, I> {
type Success = AccountId;
Expand All @@ -444,6 +444,11 @@ impl<
r => Err(O::from(r)),
})
}

#[cfg(feature = "runtime-benchmarks")]
fn successful_origin() -> O {
O::from(RawOrigin::Member(Default::default()))
}
}

pub struct EnsureMembers<N: U32, AccountId, I=DefaultInstance>(sp_std::marker::PhantomData<(N, AccountId, I)>);
Expand All @@ -460,6 +465,11 @@ impl<
r => Err(O::from(r)),
})
}

#[cfg(feature = "runtime-benchmarks")]
fn successful_origin() -> O {
O::from(RawOrigin::Members(N::VALUE, N::VALUE))
}
}

pub struct EnsureProportionMoreThan<N: U32, D: U32, AccountId, I=DefaultInstance>(
Expand All @@ -479,6 +489,11 @@ impl<
r => Err(O::from(r)),
})
}

#[cfg(feature = "runtime-benchmarks")]
fn successful_origin() -> O {
O::from(RawOrigin::Members(1u32, 0u32))
}
}

pub struct EnsureProportionAtLeast<N: U32, D: U32, AccountId, I=DefaultInstance>(
Expand All @@ -498,6 +513,11 @@ impl<
r => Err(O::from(r)),
})
}

#[cfg(feature = "runtime-benchmarks")]
fn successful_origin() -> O {
O::from(RawOrigin::Members(0u32, 0u32))
}
}

#[cfg(test)]
Expand Down
7 changes: 7 additions & 0 deletions substrate/frame/democracy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ codec = { package = "parity-scale-codec", version = "1.2.0", default-features =
sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" }
sp-io = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/io" }
sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/runtime" }
frame-benchmarking = { version = "2.0.0-alpha.5", default-features = false, path = "../benchmarking", optional = true }
frame-support = { version = "2.0.0-alpha.5", default-features = false, path = "../support" }
frame-system = { version = "2.0.0-alpha.5", default-features = false, path = "../system" }

Expand All @@ -30,7 +31,13 @@ std = [
"codec/std",
"sp-std/std",
"sp-io/std",
"frame-benchmarking/std",
"frame-support/std",
"sp-runtime/std",
"frame-system/std",
]
runtime-benchmarks = [
"frame-benchmarking",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
Loading

0 comments on commit 5a48cad

Please sign in to comment.