Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Feature/update to polkadot v0 8 30 #141

Merged
merged 141 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
beff566
Add some debug_asserts for #8171 (#8181)
tomaka Feb 24, 2021
1c34ccf
Display nicer inspect results. (#8198)
tomusdrw Feb 24, 2021
7a6d60d
Move proof generation to the type system level (#8185)
bkchr Feb 24, 2021
5d72a5a
grandpa: rewrite warp sync proof generation (#8148)
andresilva Feb 25, 2021
4b5b9bd
Add ss58 prefix for HydraDX (#8058)
jak-pan Feb 25, 2021
1febf99
allow to write pre and post runtime upgrade in pallet macro (#8194)
gui1117 Feb 25, 2021
df6a400
Add an is_finished boolean to the grandpa warp sync response (#8203)
expenses Feb 25, 2021
74d5612
Fix networking debug_asserts (#8200)
tomaka Feb 25, 2021
6fae4a1
pallet macro broke `benchmarks_instance`, fix by introducing `benchm…
gui1117 Feb 25, 2021
f6de92e
Frame Benchmarking v3.1.0 released (#8206)
gnunicorn Feb 25, 2021
debec91
contracts: Release as v3.0.0 and add reserved field to `ContractInfoO…
athei Feb 25, 2021
ec498bb
chore: fix typos for contract (#8178)
yjhmelody Feb 26, 2021
ad626b0
Fix transactions not being propagated to authorities (#8212)
tomaka Feb 26, 2021
28107d4
Better identifier and logging for runtime upgrades (#8123)
kianenigma Feb 26, 2021
a6ff3d3
Fix ignored error in benchmark tests (#8214)
gui1117 Feb 26, 2021
88ba0e6
Gilts Pallet (#8139)
gavofyork Feb 27, 2021
2dd569a
emit event on remark (#8120)
xlc Feb 28, 2021
e84d2ae
grandpa: maintain invariants when evaluating aggregated voting rules …
andresilva Feb 28, 2021
dd29596
Init `RuntimeLogger` automatically for each runtime api call (#8128)
bkchr Mar 1, 2021
7bd6b86
babe: make plan_config_change callable (#8233)
andresilva Mar 1, 2021
172c7f8
Fix state mismatch in case of bad handshake (#8230)
tomaka Mar 1, 2021
f5d2faf
contracts: Use unstable sort for topics (#8232)
athei Mar 2, 2021
44ad00d
Make Benchmark Output Analysis Function Configurable (#8228)
shawntabrizi Mar 2, 2021
308eb4c
Add benchmark to node-template pallet-template (#8239)
shawntabrizi Mar 2, 2021
0a85d36
make use of matches (#8211)
gui1117 Mar 2, 2021
73942bc
Add some migration helper to help migrating pallet changing pallet pr…
gui1117 Mar 2, 2021
b203f79
Move AuRa digest from client to primitives (#8245)
bkchr Mar 3, 2021
5f05683
Make `ExecuteBlock::execute_block` return the final block header (#8244)
bkchr Mar 3, 2021
8fc92d1
Allow pallet::call to return `DispatchResult` (#8241)
gui1117 Mar 3, 2021
e5e8197
Add migration logs to pallet v2 (#8243)
kianenigma Mar 3, 2021
dc5d587
Do not return the `Header` from `execute_block` (#8256)
bkchr Mar 3, 2021
e2d74ac
Self-sufficient account ref-counting (#8221)
gavofyork Mar 3, 2021
a8c2bc6
update nb-connect pin-project-lite rand_core (#8249)
gui1117 Mar 4, 2021
fc2d2d3
babe: introduce a request-answering mechanic (#7833)
rphmeier Mar 4, 2021
3233d29
Fix warnings related to panic and assert (#8272)
bkchr Mar 5, 2021
adca498
Fix doc build with --all-features (#8277)
gui1117 Mar 5, 2021
79ddc79
AuRa improvements (#8255)
bkchr Mar 5, 2021
af998b2
Do not use `Option` to wrap `GenesisConfig` fields (#8275)
bkchr Mar 6, 2021
a958512
refactor(remote ext): use jsonrpsee (#8105)
niklasad1 Mar 6, 2021
88014d5
pallet_macro: Generate default documentation for well known types (#8…
athei Mar 8, 2021
ac1f7ff
Clippy arithmetic new (#8282)
honeywest Mar 8, 2021
641aa72
Assets: Remove zombies, introduce approvals (#8220)
gavofyork Mar 9, 2021
e68ff13
Introduce IgnoredIssuance into Gilts (#8299)
gavofyork Mar 9, 2021
a38c948
update jsonrpsee to fix a `allow(dead_code)` (#8302)
niklasad1 Mar 9, 2021
7e5c307
Decrease the peer reputation on invalid block requests (#8260)
bkchr Mar 9, 2021
773c0b4
Simplify the code a little bit (#8295)
liuchengxu Mar 9, 2021
a94749c
Fix typo in generated docs. (#8300)
athei Mar 9, 2021
8fca15b
Introduce new concept of "slot portion for proposing" (#8280)
bkchr Mar 9, 2021
b6c2c5d
Update to latest proc-macro-crate version (#8294)
bkchr Mar 9, 2021
2461349
Return babe configuration information in the babe api epoch functions…
expenses Mar 10, 2021
ef50a44
CI: return docs jobs (#8307)
TriplEight Mar 10, 2021
3adefdc
Custom RPC for Merkle Mountain Range pallet (#8137)
tomusdrw Mar 10, 2021
b24c43a
more clear randomness API for BABE (#8180)
rphmeier Mar 10, 2021
fcab5a3
Implement PJR checker (#8160)
coriolinus Mar 11, 2021
6f12d79
Fix doc build (#8322)
adoerr Mar 11, 2021
6ac86d5
Rework telemetry to replace the use of tracing with an object we pass…
cecton Mar 11, 2021
dedbdc4
Bump tracing from 0.1.22 to 0.1.25 (#8263)
dependabot[bot] Mar 11, 2021
0a61b0a
Remove legacy network protocol (#8296)
tomaka Mar 11, 2021
aae1861
pallet-staking: add RewardDestination::None for explictly not receivi…
sorpaas Mar 11, 2021
6b50787
Add on_idle hook (#8209)
JesseAbram Mar 11, 2021
8b3e5bc
Fix #8306 (#8330)
tomaka Mar 11, 2021
1e045f2
Convert timestamp to unit type wrapper (#8333)
bkchr Mar 11, 2021
97ecd62
Do not ban peers for sending multiple valid requests (#8325)
bkchr Mar 12, 2021
101b347
contracts: Expose rent parameter to contracts (#8231)
athei Mar 12, 2021
da7ca4d
im-online: use EstimateNextSessionRotation to get better estimates of…
andresilva Mar 12, 2021
3ba5808
remove whitespaces. (#8341)
kianenigma Mar 12, 2021
18ab090
Derive common classes for `IfDisconnected`. (#8346)
eskimor Mar 12, 2021
52c2189
Remove useless sr-api (#8335)
koushiro Mar 15, 2021
a107e1f
Don't log to debug for every failed extrinsic. (#8355)
kianenigma Mar 15, 2021
fdac8be
Add more relaxed pallet-name parsing (#8353)
hirschenberger Mar 15, 2021
3541769
Don't log so many stkaing events on genesis block (#8339)
kianenigma Mar 15, 2021
9618c5f
Support pallet::storage conditional compilation (#8324)
shaunxw Mar 16, 2021
c939ceb
NPoS Challenge Mode (#8236)
coriolinus Mar 16, 2021
8a4aeba
Audit fixes for election/staking decoupling part 2 (#8167)
kianenigma Mar 16, 2021
39b3131
staking: Flexible generation of reward curve and associated tweaks (#…
gavofyork Mar 16, 2021
c532e0b
alerting-rules: ContinuousTaskEnded alert should not drop all unspeci…
gabreal Mar 16, 2021
ea50800
Document a pub item (#8374)
gavofyork Mar 16, 2021
b8ee107
Update diener to enable polkadot companions that use new crates (#8371)
bkchr Mar 16, 2021
24df4c5
Release missing 3.0 crates: pallet-node-authorization sc-finality-gra…
gnunicorn Mar 16, 2021
056d63f
Update ss58-registry.json (#8351)
akru Mar 16, 2021
7eafd1f
[CI] Require D*-audit labels for any runtime changes (#8345)
s3krit Mar 16, 2021
66098c2
Fix CI benchmark check (#8380)
bkchr Mar 16, 2021
3f434df
CI: run cargo deny nightly (#8376)
TriplEight Mar 16, 2021
319d244
Improve complexity of CompactAssignments::unique_targets (#8314)
coriolinus Mar 17, 2021
cb033a4
Migrate pallet-proxy to pallet attribute macro (#8365)
emostov Mar 17, 2021
abd39a8
Migrate node authorization pallet to FRAME v2 (#8337)
kaichaosun Mar 17, 2021
3a12b0e
fix check-labels.yml (#8387)
s3krit Mar 17, 2021
de96cf8
add D1-trivial label (#8388)
s3krit Mar 17, 2021
ce0b69a
Migrate pallet-babe to pallet attribute macro. (#8310)
shaunxw Mar 17, 2021
211be1d
Storing multiple Justifications per block (#7640)
octol Mar 17, 2021
a0161f3
Aura and Slots refactoring (#8386)
bkchr Mar 17, 2021
46ea7e7
Fast CompactAssignment search (#8385)
coriolinus Mar 18, 2021
cc24950
Replace 'Module' with 'Pallet' in construct_runtime macro (#8372)
shaunxw Mar 18, 2021
c2cffa1
Improve logging in network gossip (#8389)
bkchr Mar 18, 2021
462384b
Storage chains: indexing, renewals and reference counting (#8265)
arkpar Mar 18, 2021
f8a58bd
doc(frame): [nitpicks] (#8396)
sacha-l Mar 18, 2021
4365fa6
Better description for assert in frame-session genesis (#8399)
bkchr Mar 18, 2021
b066782
Compute yearly inflation on-chain allowing to change x_ideal accordin…
gui1117 Mar 19, 2021
bb8ab89
Make work for no_std (#8402)
gavofyork Mar 19, 2021
283bb60
Decouple Staking and Election - Part 2.1: Unleash Multi Phase (#8113)
kianenigma Mar 20, 2021
c731027
Implement PartialEq for DispatchError. (#8407)
shaunxw Mar 21, 2021
f6e265d
Use the log crate to output contract generated messages. (#8403)
athei Mar 21, 2021
6e42b4b
Rename GenericProto to Notifications (#8415)
tomaka Mar 22, 2021
97da79e
CI: address the bug with .env (#8404)
TriplEight Mar 22, 2021
3472a65
CI: fix env file location (#8417)
TriplEight Mar 22, 2021
83942f5
Optimize the peerset a bit (#8416)
tomaka Mar 22, 2021
067f185
Refactor NotifsHandler::poll (#8422)
tomaka Mar 23, 2021
7821936
contracts: Update deduct block when a contract is excempted (#8418)
athei Mar 23, 2021
fcf950c
Fix CI for new labels (#8432)
gavofyork Mar 23, 2021
307a3b6
Fungibles trait and impl for Assets pallet (#8425)
gavofyork Mar 23, 2021
f2e8da0
Improve remote-externalities (#8397)
hardliner66 Mar 23, 2021
36d77bc
Expose block number in seal_random (#8329)
athei Mar 23, 2021
87cdfd3
Add tracing logic in pallet macro for hooks and dispatchables (#8305)
gui1117 Mar 23, 2021
4df3c9a
improve doc (#8437)
gui1117 Mar 23, 2021
30ad918
contracts: Reduce the API surface (#8359)
athei Mar 24, 2021
4d4e1a2
grandpa: speed up tests (#8439)
andresilva Mar 24, 2021
069917b
remove outdated comment (#8442)
gui1117 Mar 24, 2021
189d079
test runner (#7665)
Mar 24, 2021
91f4559
Migrate pallet-utility to pallet attribute macro. (#8326)
shaunxw Mar 24, 2021
3a3e9ea
update README.adoc (#8412)
Mar 24, 2021
f02dcaa
Make candidate intake in society configurable (#8445)
kianenigma Mar 24, 2021
b6e8438
Migrate pallet-vesting to pallet attribute macro. (#8440)
shaunxw Mar 24, 2021
6792846
Check `unreserve` and `transfer` returnvalues in debug code (#8398)
hirschenberger Mar 24, 2021
67695c8
Update to libp2p-0.36 (#8420)
romanb Mar 24, 2021
3efe87d
Use Debug for genesis mismatch message (#8449)
tomaka Mar 24, 2021
2f69b2d
Make the number of nominations configurable (#8368)
kianenigma Mar 25, 2021
3655f9b
client: fix justifications migration (#8489)
andresilva Mar 30, 2021
5b7145a
Merge remote-tracking branch 'upstream/polkadot-v0.8.30' into feature…
MRamanenkau Sep 12, 2022
b780e19
Add release notes
MRamanenkau Sep 12, 2022
9bec8d9
Merge clean up
MRamanenkau Sep 12, 2022
78b0167
Remove mmr-pallet from rpc
MRamanenkau Sep 12, 2022
e01a533
Make tests compile
MRamanenkau Sep 13, 2022
d815531
Merge branch 'feature/update-to-polkadot-v0-8-29' into feature/update…
MRamanenkau Sep 13, 2022
bd03bfb
Remame Module to Pallet
MRamanenkau Sep 13, 2022
26e95be
Temperary disable should_submit_signed_transaction_on_chain test
MRamanenkau Sep 13, 2022
6ef0991
Fix should_submit_signed_transaction_on_chain
MRamanenkau Sep 13, 2022
ec6350c
Update ddc-pallet
MRamanenkau Sep 14, 2022
9454cc5
Align rustc to Polkadot for wasm runtime
MRamanenkau Sep 14, 2022
9ff7363
Remove pallet-gilt from runtime
MRamanenkau Sep 14, 2022
ac570e4
Code review
MRamanenkau Sep 16, 2022
908016d
Add storage migrations
MRamanenkau Nov 22, 2022
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
Make the number of nominations configurable (paritytech#8368)
* Base features and traits.

* pallet and unsigned phase

* Undo bad formattings.

* some formatting cleanup.

* Small self-cleanup.

* Make it all build

* self-review

* Some doc tests.

* Some changes from other PR

* Fix session test

* Update Cargo.lock

* Update frame/election-provider-multi-phase/src/lib.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Some review comments

* Rename + make encode/decode

* Do an assert as well, just in case.

* Fix build

* Update frame/election-provider-multi-phase/src/unsigned.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Las comment

* fix staking fuzzer.

* cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_election_provider_multi_phase --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/election-provider-multi-phase/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* Add one last layer of feasibility check as well.

* Last fixes to benchmarks

* Some more docs.

* cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_election_provider_multi_phase --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/election-provider-multi-phase/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_election_provider_multi_phase --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/election-provider-multi-phase/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* Some nits

* It all works

* Some self cleanup

* Update frame/staking/src/lib.rs

Co-authored-by: Peter Goodspeed-Niklaus <coriolinus@users.noreply.github.com>

* remove most todos.

* Round of self-review.

* Fix migration

* clean macro

* Revert wrong merge

* Make the number of nominations configurable

* Self reivew

* renmae.

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
Co-authored-by: Parity Benchmarking Bot <admin@parity.io>
Co-authored-by: Peter Goodspeed-Niklaus <coriolinus@users.noreply.github.com>
  • Loading branch information
5 people authored Mar 25, 2021
commit 2f69b2d417cbee2c343e0bb6af20fc89e4dea213
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ sp-keyring = { version = "3.0.0", optional = true, path = "../../../primitives/k
sp-session = { version = "3.0.0", default-features = false, path = "../../../primitives/session" }
sp-transaction-pool = { version = "3.0.0", default-features = false, path = "../../../primitives/transaction-pool" }
sp-version = { version = "3.0.0", default-features = false, path = "../../../primitives/version" }
sp-npos-elections = { version = "3.0.0", default-features = false, path = "../../../primitives/npos-elections" }

# frame dependencies
frame-executive = { version = "3.0.0", default-features = false, path = "../../../frame/executive" }
Expand Down Expand Up @@ -159,6 +160,7 @@ std = [
"pallet-vesting/std",
"log/std",
"frame-try-runtime/std",
"sp-npos-elections/std",
]
runtime-benchmarks = [
"frame-benchmarking",
Expand Down
10 changes: 9 additions & 1 deletion bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ parameter_types! {
}

impl pallet_staking::Config for Runtime {
const MAX_NOMINATIONS: u32 =
<NposCompactSolution16 as sp_npos_elections::CompactSolution>::LIMIT as u32;
type Currency = Balances;
type UnixTime = Timestamp;
type CurrencyToVote = U128CurrencyToVote;
Expand Down Expand Up @@ -515,6 +517,12 @@ parameter_types! {
.saturating_sub(BlockExecutionWeight::get());
}

sp_npos_elections::generate_solution_type!(
#[compact]
pub struct NposCompactSolution16::<u32, u16, sp_runtime::PerU16>(16)
// -------------------- ^^ <NominatorIndex, ValidatorIndex, Accuracy>
);

impl pallet_election_provider_multi_phase::Config for Runtime {
type Event = Event;
type Currency = Balances;
Expand All @@ -526,7 +534,7 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
type MinerTxPriority = MultiPhaseUnsignedPriority;
type DataProvider = Staking;
type OnChainAccuracy = Perbill;
type CompactSolution = pallet_staking::CompactAssignments;
type CompactSolution = NposCompactSolution16;
type Fallback = Fallback;
type WeightInfo = pallet_election_provider_multi_phase::weights::SubstrateWeight<Runtime>;
type BenchmarkingConfig = ();
Expand Down
1 change: 1 addition & 0 deletions frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ impl onchain::Config for Test {
}

impl pallet_staking::Config for Test {
const MAX_NOMINATIONS: u32 = 16;
type RewardRemainder = ();
type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote;
type Event = Event;
Expand Down
10 changes: 10 additions & 0 deletions frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,16 @@ pub mod pallet {
let _: UpperOf<CompactAccuracyOf<T>> = maximum_chain_accuracy
.iter()
.fold(Zero::zero(), |acc, x| acc.checked_add(x).unwrap());

// We only accept data provider who's maximum votes per voter matches our
// `T::CompactSolution`'s `LIMIT`.
//
// NOTE that this pallet does not really need to enforce this in runtime. The compact
// solution cannot represent any voters more than `LIMIT` anyhow.
assert_eq!(
<T::DataProvider as ElectionDataProvider<T::AccountId, T::BlockNumber>>::MAXIMUM_VOTES_PER_VOTER,
<CompactOf<T> as CompactSolution>::LIMIT as u32,
);
}
}

Expand Down
1 change: 1 addition & 0 deletions frame/election-provider-multi-phase/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ pub struct ExtBuilder {}

pub struct StakingMock;
impl ElectionDataProvider<AccountId, u64> for StakingMock {
const MAXIMUM_VOTES_PER_VOTER: u32 = <TestCompact as CompactSolution>::LIMIT as u32;
fn targets(maybe_max_len: Option<usize>) -> data_provider::Result<(Vec<AccountId>, Weight)> {
let targets = Targets::get();

Expand Down
5 changes: 5 additions & 0 deletions frame/election-provider-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
//! pub struct Module<T: Config>(std::marker::PhantomData<T>);
//!
//! impl<T: Config> ElectionDataProvider<AccountId, BlockNumber> for Module<T> {
//! const MAXIMUM_VOTES_PER_VOTER: u32 = 1;
//! fn desired_targets() -> data_provider::Result<(u32, Weight)> {
//! Ok((1, 0))
//! }
Expand Down Expand Up @@ -180,6 +181,9 @@ pub mod data_provider {

/// Something that can provide the data to an [`ElectionProvider`].
pub trait ElectionDataProvider<AccountId, BlockNumber> {
/// Maximum number of votes per voter that this data provider is providing.
const MAXIMUM_VOTES_PER_VOTER: u32;

/// All possible targets for the election, i.e. the candidates.
///
/// If `maybe_max_len` is `Some(v)` then the resulting vector MUST NOT be longer than `v` items
Expand Down Expand Up @@ -226,6 +230,7 @@ pub trait ElectionDataProvider<AccountId, BlockNumber> {

#[cfg(feature = "std")]
impl<AccountId, BlockNumber> ElectionDataProvider<AccountId, BlockNumber> for () {
const MAXIMUM_VOTES_PER_VOTER: u32 = 0;
fn targets(_maybe_max_len: Option<usize>) -> data_provider::Result<(Vec<AccountId>, Weight)> {
Ok(Default::default())
}
Expand Down
1 change: 1 addition & 0 deletions frame/election-provider-support/src/onchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ mod tests {
pub struct DataProvider;

impl ElectionDataProvider<AccountId, BlockNumber> for DataProvider {
const MAXIMUM_VOTES_PER_VOTER: u32 = 2;
fn voters(
_: Option<usize>,
) -> data_provider::Result<(Vec<(AccountId, VoteWeight, Vec<AccountId>)>, Weight)> {
Expand Down
1 change: 1 addition & 0 deletions frame/grandpa/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ impl onchain::Config for Test {
}

impl pallet_staking::Config for Test {
const MAX_NOMINATIONS: u32 = 16;
type RewardRemainder = ();
type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote;
type Event = Event;
Expand Down
15 changes: 9 additions & 6 deletions frame/offences/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ use frame_system::{RawOrigin, Pallet as System, Config as SystemConfig};
use frame_benchmarking::{benchmarks, account, impl_benchmark_test_suite};
use frame_support::traits::{Currency, OnInitialize, ValidatorSet, ValidatorSetWithIdentification};

use sp_runtime::{Perbill, traits::{Convert, StaticLookup, Saturating, UniqueSaturatedInto}};
use sp_runtime::{
Perbill,
traits::{Convert, StaticLookup, Saturating, UniqueSaturatedInto},
};
use sp_staking::offence::{ReportOffence, Offence, OffenceDetails};

use pallet_balances::Config as BalancesConfig;
Expand All @@ -39,8 +42,8 @@ use pallet_offences::{Config as OffencesConfig, Module as Offences};
use pallet_session::historical::{Config as HistoricalConfig, IdentificationTuple};
use pallet_session::{Config as SessionConfig, SessionManager};
use pallet_staking::{
Module as Staking, Config as StakingConfig, RewardDestination, ValidatorPrefs,
Exposure, IndividualExposure, MAX_NOMINATIONS, Event as StakingEvent
Module as Staking, Config as StakingConfig, RewardDestination, ValidatorPrefs, Exposure,
IndividualExposure, Event as StakingEvent,
};

const SEED: u32 = 0;
Expand Down Expand Up @@ -236,7 +239,7 @@ benchmarks! {
let r in 1 .. MAX_REPORTERS;
// we skip 1 offender, because in such case there is no slashing
let o in 2 .. MAX_OFFENDERS;
let n in 0 .. MAX_NOMINATORS.min(MAX_NOMINATIONS as u32);
let n in 0 .. MAX_NOMINATORS.min(<T as pallet_staking::Config>::MAX_NOMINATIONS);

// Make r reporters
let mut reporters = vec![];
Expand Down Expand Up @@ -310,7 +313,7 @@ benchmarks! {
}

report_offence_grandpa {
let n in 0 .. MAX_NOMINATORS.min(MAX_NOMINATIONS as u32);
let n in 0 .. MAX_NOMINATORS.min(<T as pallet_staking::Config>::MAX_NOMINATIONS);

// for grandpa equivocation reports the number of reporters
// and offenders is always 1
Expand Down Expand Up @@ -346,7 +349,7 @@ benchmarks! {
}

report_offence_babe {
let n in 0 .. MAX_NOMINATORS.min(MAX_NOMINATIONS as u32);
let n in 0 .. MAX_NOMINATORS.min(<T as pallet_staking::Config>::MAX_NOMINATIONS);

// for babe equivocation reports the number of reporters
// and offenders is always 1
Expand Down
1 change: 1 addition & 0 deletions frame/offences/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ impl onchain::Config for Test {
}

impl pallet_staking::Config for Test {
const MAX_NOMINATIONS: u32 = 16;
type Currency = Balances;
type UnixTime = pallet_timestamp::Pallet<Self>;
type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote;
Expand Down
10 changes: 5 additions & 5 deletions frame/session/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use frame_system::RawOrigin;
use pallet_session::{historical::Module as Historical, Module as Session, *};
use pallet_staking::{
benchmarking::create_validator_with_nominators, testing_utils::create_validators,
MAX_NOMINATIONS, RewardDestination,
RewardDestination,
};
use sp_runtime::traits::{One, StaticLookup};

Expand All @@ -52,10 +52,10 @@ impl<T: Config> OnInitialize<T::BlockNumber> for Pallet<T> {

benchmarks! {
set_keys {
let n = MAX_NOMINATIONS as u32;
let n = <T as pallet_staking::Config>::MAX_NOMINATIONS;
let (v_stash, _) = create_validator_with_nominators::<T>(
n,
MAX_NOMINATIONS as u32,
<T as pallet_staking::Config>::MAX_NOMINATIONS,
false,
RewardDestination::Staked,
)?;
Expand All @@ -68,10 +68,10 @@ benchmarks! {
}: _(RawOrigin::Signed(v_controller), keys, proof)

purge_keys {
let n = MAX_NOMINATIONS as u32;
let n = <T as pallet_staking::Config>::MAX_NOMINATIONS;
let (v_stash, _) = create_validator_with_nominators::<T>(
n,
MAX_NOMINATIONS as u32,
<T as pallet_staking::Config>::MAX_NOMINATIONS,
false,
RewardDestination::Staked
)?;
Expand Down
1 change: 1 addition & 0 deletions frame/session/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ impl onchain::Config for Test {
}

impl pallet_staking::Config for Test {
const MAX_NOMINATIONS: u32 = 16;
type Currency = Balances;
type UnixTime = pallet_timestamp::Pallet<Self>;
type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote;
Expand Down
2 changes: 0 additions & 2 deletions frame/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ static_assertions = "1.1.0"
serde = { version = "1.0.101", optional = true }
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
sp-std = { version = "3.0.0", default-features = false, path = "../../primitives/std" }
sp-npos-elections = { version = "3.0.0", default-features = false, path = "../../primitives/npos-elections" }
sp-io ={ version = "3.0.0", default-features = false, path = "../../primitives/io" }
sp-runtime = { version = "3.0.0", default-features = false, path = "../../primitives/runtime" }
sp-staking = { version = "3.0.0", default-features = false, path = "../../primitives/staking" }
Expand Down Expand Up @@ -54,7 +53,6 @@ std = [
"serde",
"codec/std",
"sp-std/std",
"sp-npos-elections/std",
"sp-io/std",
"frame-support/std",
"sp-runtime/std",
Expand Down
53 changes: 39 additions & 14 deletions frame/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,20 @@ benchmarks! {
kick {
// scenario: we want to kick `k` nominators from nominating us (we are a validator).
// we'll assume that `k` is under 128 for the purposes of determining the slope.
// each nominator should have `MAX_NOMINATIONS` validators nominated, and our validator
// each nominator should have `T::MAX_NOMINATIONS` validators nominated, and our validator
// should be somewhere in there.
let k in 1 .. 128;

// these are the other validators; there are `MAX_NOMINATIONS - 1` of them, so there are a
// total of `MAX_NOMINATIONS` validators in the system.
let rest_of_validators = create_validators::<T>(MAX_NOMINATIONS as u32 - 1, 100)?;
// these are the other validators; there are `T::MAX_NOMINATIONS - 1` of them, so
// there are a total of `T::MAX_NOMINATIONS` validators in the system.
let rest_of_validators = create_validators::<T>(T::MAX_NOMINATIONS - 1, 100)?;

// this is the validator that will be kicking.
let (stash, controller) = create_stash_controller::<T>(MAX_NOMINATIONS as u32 - 1, 100, Default::default())?;
let (stash, controller) = create_stash_controller::<T>(
T::MAX_NOMINATIONS - 1,
100,
Default::default(),
)?;
let stash_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(stash.clone());

// they start validating.
Expand All @@ -224,7 +228,11 @@ benchmarks! {
let mut nominator_stashes = Vec::with_capacity(k as usize);
for i in 0 .. k {
// create a nominator stash.
let (n_stash, n_controller) = create_stash_controller::<T>(MAX_NOMINATIONS as u32 + i, 100, Default::default())?;
let (n_stash, n_controller) = create_stash_controller::<T>(
T::MAX_NOMINATIONS + i,
100,
Default::default(),
)?;

// bake the nominations; we first clone them from the rest of the validators.
let mut nominations = rest_of_validators.clone();
Expand Down Expand Up @@ -256,9 +264,9 @@ benchmarks! {
}
}

// Worst case scenario, MAX_NOMINATIONS
// Worst case scenario, T::MAX_NOMINATIONS
nominate {
let n in 1 .. MAX_NOMINATIONS as u32;
let n in 1 .. T::MAX_NOMINATIONS;
let (stash, controller) = create_stash_controller::<T>(n + 1, 100, Default::default())?;
let validators = create_validators::<T>(n, 100)?;
whitelist_account!(controller);
Expand Down Expand Up @@ -467,7 +475,13 @@ benchmarks! {
let v in 1 .. 10;
let n in 1 .. 100;

create_validators_with_nominators_for_era::<T>(v, n, MAX_NOMINATIONS, false, None)?;
create_validators_with_nominators_for_era::<T>(
v,
n,
<T as Config>::MAX_NOMINATIONS as usize,
false,
None,
)?;
let session_index = SessionIndex::one();
}: {
let validators = Staking::<T>::new_era(session_index).ok_or("`new_era` failed")?;
Expand All @@ -478,7 +492,13 @@ benchmarks! {
payout_all {
let v in 1 .. 10;
let n in 1 .. 100;
create_validators_with_nominators_for_era::<T>(v, n, MAX_NOMINATIONS, false, None)?;
create_validators_with_nominators_for_era::<T>(
v,
n,
<T as Config>::MAX_NOMINATIONS as usize,
false,
None,
)?;
// Start a new Era
let new_validators = Staking::<T>::new_era(SessionIndex::one()).unwrap();
assert!(new_validators.len() == v as usize);
Expand Down Expand Up @@ -548,7 +568,7 @@ benchmarks! {
// total number of slashing spans. Assigned to validators randomly.
let s in 1 .. 20;

let validators = create_validators_with_nominators_for_era::<T>(v, n, MAX_NOMINATIONS, false, None)?
let validators = create_validators_with_nominators_for_era::<T>(v, n, T::MAX_NOMINATIONS as usize, false, None)?
.into_iter()
.map(|v| T::Lookup::lookup(v).unwrap())
.collect::<Vec<_>>();
Expand All @@ -567,7 +587,7 @@ benchmarks! {
// number of nominator intention.
let n = 500;

let _ = create_validators_with_nominators_for_era::<T>(v, n, MAX_NOMINATIONS, false, None)?;
let _ = create_validators_with_nominators_for_era::<T>(v, n, T::MAX_NOMINATIONS as usize, false, None)?;
}: {
let targets = <Staking<T>>::get_npos_targets();
assert_eq!(targets.len() as u32, v);
Expand All @@ -586,8 +606,13 @@ mod tests {
let v = 10;
let n = 100;

create_validators_with_nominators_for_era::<Test>(v, n, MAX_NOMINATIONS, false, None)
.unwrap();
create_validators_with_nominators_for_era::<Test>(
v,
n,
<Test as Config>::MAX_NOMINATIONS as usize,
false,
None,
).unwrap();

let count_validators = Validators::<Test>::iter().count();
let count_nominators = Nominators::<Test>::iter().count();
Expand Down
Loading