Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
173 commits
Select commit Hold shift + click to select a range
021f712
Update contract weights (#12192)
athei Sep 7, 2022
5e2ffeb
Move Get and bounded types to sp-core (#12203)
KiChjang Sep 7, 2022
c0e1cdb
Add `--header` to `benchmark overhead + storage` (#12204)
ggwpez Sep 7, 2022
2619394
Remove Ord impl for Weights V2 and add comparison fns (#12183)
KiChjang Sep 8, 2022
8075aa4
pallet-identity: Be more paranoid ;) (#12170)
bkchr Sep 8, 2022
e202092
Upgrade wasmtime to 0.40.0 (#12096)
bkchr Sep 8, 2022
0478535
Use parameter_types instead of thread_local for test-setup (#12036)
tifecool Sep 8, 2022
cd66db5
Fully remove `rusty-cachier` from the `node-bench-regression-guard` j…
rcny Sep 8, 2022
b8c3d8c
Upgrade wasm crate dependencies (#12173)
athei Sep 8, 2022
f9fdee1
Removing without_storage_info from scored-pool pallet. (#11996)
hbulgarini Sep 8, 2022
c8bfc91
Update ss58-registry (#12220)
MOZGIII Sep 8, 2022
5a48536
Add missing metadata specs to crate manifests (#12221)
Sep 8, 2022
51f60d0
construct_runtime: Fix generation of types behind features (#12229)
bkchr Sep 10, 2022
7de3d78
Remove native call (#12201)
bkchr Sep 12, 2022
d5de897
Fuzz testing for nomination pools (#12002)
kianenigma Sep 12, 2022
c997a62
Add `ConstFeeMultiplier` to the transaction payment pallet (#12222)
mrshiposha Sep 12, 2022
7cb78ff
Don't run `cargo-check-benches` for `master` based downstream staging…
rcny Sep 12, 2022
dd1f1b5
Expose some of the staking miner types over metadata (#12245)
kianenigma Sep 12, 2022
f1c60e5
extract some grandpa types to Primitives crate (#12208)
yjhmelody Sep 12, 2022
5527263
BREAKING: Rename Call & Event (#11981)
Szegoo Sep 12, 2022
379813c
Update README (#12247)
nuke-web3 Sep 13, 2022
5daa20c
Add inspect trait for asset roles (#11738)
girazoki Sep 13, 2022
c1103fd
Move bitswap to its own crate (#12242)
altonen Sep 13, 2022
9df9448
benches: disable caching per default (#12232)
ggwpez Sep 13, 2022
bb7fb64
Make `BasePath::new_temp_dir` return the same path for the program li…
bkchr Sep 13, 2022
3449fb0
Remove CanAuthorWith trait (#12213)
michalkucharczyk Sep 13, 2022
23bb5a6
Create sp-weights crate to store weight primitives (#12219)
KiChjang Sep 13, 2022
b5e2542
fix sp-weight std (#12265)
shawntabrizi Sep 14, 2022
7c2c0c1
Improve base weights consistency and make sure they're never zero (#1…
koute Sep 14, 2022
dc22e48
Fix Rust features (#11976)
ggwpez Sep 14, 2022
1dcb9ce
Clean up the logging output (#12253)
bkchr Sep 14, 2022
fd54957
Bump wasm-instrument (#12234)
athei Sep 15, 2022
3bef1ba
Include Bitswap into request response protocols (#12262)
altonen Sep 15, 2022
12b5b5a
Use `--locked` for Cargo in CI everywhere (#12270)
rcny Sep 15, 2022
8bd5510
Replace 'blake2-rfc' with rust-crypto 'blake2' crate (#12266)
davxy Sep 15, 2022
21adbaf
Expose tracks as a constant. (#12273)
gavofyork Sep 15, 2022
d65f4bb
client/beefy: fix voter initialization (#12274)
acatangiu Sep 16, 2022
7202ca6
Fix warp sync (#12281)
arkpar Sep 16, 2022
4d04aba
Add special tag to exclude runtime storage items from benchmarking (#…
sam0x17 Sep 16, 2022
03eb807
[Feature] Part 1: add TargetList for validator ranking (#12034)
ruseinov Sep 18, 2022
91b97b0
[Fix] Benchmark issue in staking (#12290)
ruseinov Sep 18, 2022
ee3c159
support upgrade hooks to directly pass data (#12185)
NingLin-P Sep 19, 2022
b541b2d
contracts: Use `WeakBoundedVec` for instrumented code (#12186)
athei Sep 19, 2022
c24431e
Fix CI (#12297)
ggwpez Sep 19, 2022
df3722c
Fix `cargo-check-benches` job (#12301)
rcny Sep 20, 2022
625de4f
[ci] Revert cancel-pipeline job (#12309)
alvicsam Sep 20, 2022
e7c515d
Proper naming wrt expectations (#12311)
sandreim Sep 20, 2022
97ad64b
Import target block body during warp sync (#12300)
dmitry-markin Sep 20, 2022
de5a7f6
rpc: Implement `chainSpec` RPC API (#12261)
lexnv Sep 20, 2022
006dbc0
Use temporary db for benchmarking (#12254)
michalkucharczyk Sep 20, 2022
a47f200
BREAKING: Rename Origin (#12258)
Szegoo Sep 20, 2022
409167e
Use `array-bytes` for All Array/Bytes/Hex Operations (#12190)
aurexav Sep 21, 2022
4e53bdc
Bound staking storage items (#12230)
Ank4n Sep 21, 2022
9df7ac8
Introduce 'intermediate_insert' method to hide implementation details…
davxy Sep 21, 2022
ae4ba19
Bump `wasmtime` to 1.0.0 (#12317)
koute Sep 21, 2022
be97615
Format templates and fix `--steps` default value (#12286)
ggwpez Sep 21, 2022
493b58b
Make automatic storage deposits resistant against changing deposit pr…
athei Sep 21, 2022
1253de6
pallet-utility: Disallow none origin (#12321)
bkchr Sep 22, 2022
cc4d5cc
Migrate remaining old decl_* macros to the new pallet attribute macro…
koushiro Sep 22, 2022
1f720c1
Rename anonymous to pure proxy (#12283)
shawntabrizi Sep 22, 2022
bffd6a3
Fast Unstake Pallet (#12129)
kianenigma Sep 23, 2022
397da27
bench: Use `_` instead of `::` in auto-generated file names (#12332)
ggwpez Sep 23, 2022
8161ee1
[Feature] Sequential migration execution for try-runtime (#12319)
ruseinov Sep 23, 2022
b34936a
[Fix] parameter_types! dead code errors (#12340)
ruseinov Sep 23, 2022
ffcd523
Independence of Slot-based algorithms from system Timestamp (#12224)
davxy Sep 23, 2022
fb77921
Const impls of base arithmetics for `Weights` with `u64` (#12322)
mustermeiszer Sep 24, 2022
9476d21
Add base-weight to `System::Extrinsic*` events (#12329)
ggwpez Sep 24, 2022
d0214e7
re add the migration checks for staking (#12330)
Ank4n Sep 24, 2022
4219b3a
Allow specifying immediate finalize for `manual-seal` (#12106)
cmichi Sep 25, 2022
badc92a
Removed OuterCall alias & doc fixes (#12349)
Szegoo Sep 25, 2022
fbd7e5a
[Enhancement] Remove optional Pool subscription from fast-unstake (#1…
ruseinov Sep 26, 2022
a0ec652
Remove discarded blocks and states from database by default (#11983)
hzy1919 Sep 26, 2022
0dbeaa0
re-export weight file for fast-unstsake pallet (#12352)
kianenigma Sep 26, 2022
f360c87
Move transactions protocol to its own crate (#12264)
altonen Sep 26, 2022
519fbaa
export more types from fast-untsake 🤦‍♂️ (#12353)
kianenigma Sep 27, 2022
1763ff2
Fix compilation on 1.66 nightly (#12363)
bkchr Sep 27, 2022
edca891
Relax Slots-based engines from Epochs (#12360)
davxy Sep 27, 2022
2a6c314
Pallet staking events to named enum (#12342)
Szegoo Sep 27, 2022
74daaf1
[fix] Bound staking ledger correctly with MaxUnlockingChunks from con…
Ank4n Sep 27, 2022
94b9646
[Feature] Add deposit to fast-unstake (#12366)
ruseinov Sep 27, 2022
2ee4cb4
Add missing CountedStorageMap in pallet::storage error info (#12356)
liuchengxu Sep 27, 2022
17c07af
Add storage size component to weights (#12277)
KiChjang Sep 28, 2022
01a905e
pallet-utility: Only disallow the `None` origin (#12351)
bkchr Sep 28, 2022
1b1a5e1
Fix staking migration (#12373)
ggwpez Sep 28, 2022
0ec4373
Support running the pallet benchmarks analysis without running the be…
koute Sep 28, 2022
d66adfa
fix: typo in AllPalletsWithSystem deprecated msg (#12379)
Sep 28, 2022
96de768
New Pallet: Root offences (#11943)
Szegoo Sep 28, 2022
e7f994d
bounding staking: `BoundedElectionProvider` trait (#12362)
Ank4n Sep 28, 2022
427fd09
BEEFY: impl TypeInfo for SignedCommitment (#12382)
serban300 Sep 29, 2022
61b9a4d
Properly set the max proof size weight on defaults and tests (#12383)
KiChjang Sep 29, 2022
c2026ca
Carry over where clauses defined in Config to Call and Hook (#12388)
KiChjang Sep 30, 2022
dbb72f3
unsafe_pruning flag removed (#12385)
michalkucharczyk Sep 30, 2022
952030c
pallet-mmr: generate historical proofs (#12324)
serban300 Sep 30, 2022
37664fe
Remove contracts RPCs (#12358)
athei Oct 2, 2022
9472af8
Beefy on-demand justifications as a custom RequestResponse protocol (…
acatangiu Oct 3, 2022
2579550
Fix `Weight::is_zero` (#12396)
ggwpez Oct 3, 2022
1b23ec9
Remove unnecessary Clone trait bounds on CountedStorageMap (#12402)
KiChjang Oct 3, 2022
6d7f76b
docs/CODEOWNERS: add @acatangiu as MMR owner (#12406)
acatangiu Oct 4, 2022
594d71a
Add @koute to `docs/CODEOWNERS` and update stale paths (#12408)
koute Oct 4, 2022
e77cbe3
BEEFY: Simplify hashing for pallet-beefy-mmr (#12393)
serban300 Oct 4, 2022
0051950
client/beefy: small code improvements (#12414)
acatangiu Oct 4, 2022
07e5ec5
[Fix] Rename VoterBagsList -> VoterList to match pdot (#12416)
ruseinov Oct 4, 2022
d11dd02
Use saturating add for alliance::disband witness data (#12418)
muharem Oct 4, 2022
91d072d
Bump prost to 0.11+ (#12419)
chevdor Oct 4, 2022
241b0d0
Improved election pallet testing (#12327)
Szegoo Oct 4, 2022
7a8de49
Adapt `pallet-contracts` to WeightV2 (#12421)
athei Oct 5, 2022
2cd4088
MMR: impl `TypeInfo` for some structures (#12423)
serban300 Oct 5, 2022
4cd3248
Don't send back empty proofs if light request fails (#12372)
tomaka Oct 5, 2022
87224cf
Implement `Clone` and `Default` for `Config` (#12397)
s0me0ne-unkn0wn Oct 5, 2022
eefba93
Bound uses of `Call` (#11649)
gavofyork Oct 5, 2022
fc67cbb
update kvdb & co (#12312)
ordian Oct 5, 2022
f447bee
Use `Option<Weight>` for contract dry-runs (#12429)
athei Oct 6, 2022
3cb5a40
Add pluggable BEEFY payload constructors (#12428)
acatangiu Oct 6, 2022
a84def9
Maximum value for `MultiplierUpdate` (#12282)
Szegoo Oct 6, 2022
f77f788
macro stubs for all pallet:: macros to improve documentation visibili…
sam0x17 Oct 6, 2022
4a5a9de
Upgrade pin-project (#12426)
bkchr Oct 7, 2022
a8e951d
Extend the lower bounds of some of the benchmarks to also include `0`…
koute Oct 7, 2022
1a5cdc8
BEEFY: Define a `BeefyVerify` trait for signatures (#12299)
serban300 Oct 7, 2022
b7c0562
fix comment math (#12452)
nuke-web3 Oct 8, 2022
460fff9
Remove "to_block" field from BlockRequests (#12447)
tomaka Oct 8, 2022
73c4f94
Vesting pallet - make WithdrawReasons configurable (#12109)
Lezek123 Oct 9, 2022
0c1ccda
Move block announcement protocol config out of `Protocol` (#12441)
altonen Oct 10, 2022
df81976
Dont ignore errors in pallet benchmarking (#12449)
ggwpez Oct 10, 2022
9672c36
Update UI tests for Rust 1.64 (#12440)
rcny Oct 10, 2022
488fc24
rpc: Implement `transaction` RPC API (#12328)
lexnv Oct 11, 2022
60be7b8
Remove the unused light client requests (#12470)
tomaka Oct 11, 2022
6072b90
Fix flaky service test (#12472)
altonen Oct 11, 2022
1bf2e6d
Rename `from_components` to `from_parts` (#12473)
KiChjang Oct 11, 2022
ccc8f6c
Avoid Unstable Sort (#12455)
shawntabrizi Oct 11, 2022
94b731c
Finalized block event triggers tx maintanance (#12305)
michalkucharczyk Oct 11, 2022
88db102
tx-pool: failing tests fixed (#12481)
michalkucharczyk Oct 12, 2022
06a9f0a
Clarify the "direction" field of block requests (#12438)
tomaka Oct 12, 2022
f8a0b7a
BlockId::Number refactor: trivial changes to BlockId::Hash (#12471)
michalkucharczyk Oct 12, 2022
b324e51
Dont use benchmark range on constant functions (#12456)
shawntabrizi Oct 12, 2022
94941a8
Punish peers for duplicate GRANDPA neighbor messages (#12462)
dmitry-markin Oct 13, 2022
983b6b0
Introduce mockable `ChainSync` object for testing (#12480)
altonen Oct 13, 2022
1f39c90
pallet-mmr: RPC API and Runtime API work with block numbers (#12345)
Szegoo Oct 13, 2022
fd00b14
Enable the `wasmtime`-based WASM executor by default (#12486)
koute Oct 13, 2022
6e04e48
Trivial BlockId::Number => Hash (#12490)
michalkucharczyk Oct 13, 2022
f313987
BlockId removal: refactor: Backend::state_at (#12488)
michalkucharczyk Oct 14, 2022
0ee0327
Try-runtime CLI fix weight parsing (#12491)
ggwpez Oct 14, 2022
6f453b5
Export fn code_hash (#12479)
kvinwang Oct 17, 2022
30a7a5b
Introduce `ChainSyncInterface` (#12489)
altonen Oct 17, 2022
951f075
sp-api: Remove invalid unsafe trait bounds (#12502)
bkchr Oct 17, 2022
273e264
pallet-mmr: fix offchain db for sync from zero (#12498)
acatangiu Oct 17, 2022
acacb53
Fix: typo (#12505)
omahs Oct 17, 2022
444cf9d
Upgrade libp2p to 0.49.0 (#12256)
dmitry-markin Oct 17, 2022
ed2466e
Execute try-state at end of each test to ensure pallet data integrity…
Ank4n Oct 17, 2022
e8a4408
Bump clap to 4.0.x and adjust to best practices (#12381)
skunert Oct 18, 2022
b9a555d
implement storage decode length for BTreeSet (#12503)
dharjeezy Oct 18, 2022
415648d
Decrease default --out-peers from 25 to 15 (#12434)
tomaka Oct 18, 2022
4c45673
Prepare for latest clippy (nightly 09-10-2022) (#12466)
bkchr Oct 18, 2022
281bcd4
derive Serialize/Deserialize for BeefyAuthoritySet (#12516)
serban300 Oct 18, 2022
e34b840
BlockId removal: refactor: StorageProvider (#12510)
michalkucharczyk Oct 18, 2022
487ac5c
Use `ArgAction::Set` for enable-offchain-indexing flag (#12521)
skunert Oct 18, 2022
49734dd
frame/utils: introduce `substrate-rpc-client` crate for RPC utils (#1…
niklasad1 Oct 18, 2022
399ab89
Force base weights to be the minimum only when the intercept is negat…
koute Oct 20, 2022
7a4e516
Update `pallet-multisig` benches (#12558)
ggwpez Oct 26, 2022
7eab46f
resolve conflicts version 31
devdanco Nov 14, 2022
6304e5a
Update TargetedFeeAdjustment struct
devdanco Nov 18, 2022
1dfd9b4
Merge branch 'mangata-dev' into mangata-dev-v0.9.31
devdanco Nov 28, 2022
c2f6367
add feature to crate
devdanco Nov 28, 2022
1f23be6
update orml version in test
devdanco Nov 28, 2022
f61d829
remove unnecessary try-runtime feature
devdanco Nov 30, 2022
3696593
feat: resolve confclits and fix fmt
devdanco Dec 12, 2022
b31aa9d
fix: benchmarking types
devdanco Dec 13, 2022
7b6b521
Merge branch 'mangata-dev' into mangata-dev-v0.9.31
devdanco Dec 20, 2022
c5a1bbe
feat: resolve conflicts after storage queue
devdanco Dec 21, 2022
34c492c
fix: tests
devdanco Dec 21, 2022
a73d548
Added pre and post upgrade hooks for try0runtime and remove pallet-tr…
Dec 23, 2022
f84f481
Minor try-runtime bug
Dec 23, 2022
61bcb2e
fix: inject inherets
devdanco Dec 30, 2022
3d36c5e
update reference
devdanco Dec 31, 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
bounding staking: BoundedElectionProvider trait (paritytech#12362)
* add a bounded election provider trait

* extract common trait election provider base

* fmt

* only bound the outer support vector

* fix tests

* docs

* fix rust docs

* fmt

* fix rustdocs

* docs

* improve docs

* small doc change
  • Loading branch information
Ank4n authored Sep 28, 2022
commit e7f994d1e797420f252dd24714b029071ccbc46c
16 changes: 10 additions & 6 deletions frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@

use codec::{Decode, Encode};
use frame_election_provider_support::{
ElectionDataProvider, ElectionProvider, InstantElectionProvider, NposSolution,
ElectionDataProvider, ElectionProvider, ElectionProviderBase, InstantElectionProvider,
NposSolution,
};
use frame_support::{
dispatch::DispatchClass,
Expand Down Expand Up @@ -289,7 +290,7 @@ pub type SolutionTargetIndexOf<T> = <SolutionOf<T> as NposSolution>::TargetIndex
pub type SolutionAccuracyOf<T> =
<SolutionOf<<T as crate::Config>::MinerConfig> as NposSolution>::Accuracy;
/// The fallback election type.
pub type FallbackErrorOf<T> = <<T as crate::Config>::Fallback as ElectionProvider>::Error;
pub type FallbackErrorOf<T> = <<T as crate::Config>::Fallback as ElectionProviderBase>::Error;

/// Configuration for the benchmarks of the pallet.
pub trait BenchmarkingConfig {
Expand All @@ -312,7 +313,7 @@ pub trait BenchmarkingConfig {
/// A fallback implementation that transitions the pallet to the emergency phase.
pub struct NoFallback<T>(sp_std::marker::PhantomData<T>);

impl<T: Config> ElectionProvider for NoFallback<T> {
impl<T: Config> ElectionProviderBase for NoFallback<T> {
type AccountId = T::AccountId;
type BlockNumber = T::BlockNumber;
type DataProvider = T::DataProvider;
Expand All @@ -321,7 +322,9 @@ impl<T: Config> ElectionProvider for NoFallback<T> {
fn ongoing() -> bool {
false
}
}

impl<T: Config> ElectionProvider for NoFallback<T> {
fn elect() -> Result<Supports<T::AccountId>, Self::Error> {
// Do nothing, this will enable the emergency phase.
Err("NoFallback.")
Expand Down Expand Up @@ -1563,7 +1566,7 @@ impl<T: Config> Pallet<T> {
<QueuedSolution<T>>::take()
.ok_or(ElectionError::<T>::NothingQueued)
.or_else(|_| {
T::Fallback::elect()
<T::Fallback as ElectionProvider>::elect()
.map(|supports| ReadySolution {
supports,
score: Default::default(),
Expand Down Expand Up @@ -1598,7 +1601,7 @@ impl<T: Config> Pallet<T> {
}
}

impl<T: Config> ElectionProvider for Pallet<T> {
impl<T: Config> ElectionProviderBase for Pallet<T> {
type AccountId = T::AccountId;
type BlockNumber = T::BlockNumber;
type Error = ElectionError<T>;
Expand All @@ -1610,7 +1613,9 @@ impl<T: Config> ElectionProvider for Pallet<T> {
_ => true,
}
}
}

impl<T: Config> ElectionProvider for Pallet<T> {
fn elect() -> Result<Supports<T::AccountId>, Self::Error> {
match Self::do_elect() {
Ok(supports) => {
Expand All @@ -1627,7 +1632,6 @@ impl<T: Config> ElectionProvider for Pallet<T> {
}
}
}

/// convert a DispatchError to a custom InvalidTransaction with the inner code being the error
/// number.
pub fn dispatch_error_to_invalid(error: DispatchError) -> InvalidTransaction {
Expand Down
5 changes: 3 additions & 2 deletions frame/election-provider-multi-phase/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ impl onchain::Config for OnChainSeqPhragmen {
}

pub struct MockFallback;
impl ElectionProvider for MockFallback {
impl ElectionProviderBase for MockFallback {
type AccountId = AccountId;
type BlockNumber = u64;
type Error = &'static str;
Expand All @@ -306,7 +306,8 @@ impl ElectionProvider for MockFallback {
fn ongoing() -> bool {
false
}

}
impl ElectionProvider for MockFallback {
fn elect() -> Result<Supports<AccountId>, Self::Error> {
Self::elect_with_bounds(Bounded::max_value(), Bounded::max_value())
}
Expand Down
83 changes: 55 additions & 28 deletions frame/election-provider-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
//! This crate provides two traits that could interact to enable extensible election functionality
//! within FRAME pallets.
//!
//! Something that will provide the functionality of election will implement [`ElectionProvider`],
//! whilst needing an associated [`ElectionProvider::DataProvider`], which needs to be fulfilled by
//! an entity implementing [`ElectionDataProvider`]. Most often, *the data provider is* the receiver
//! of the election, resulting in a diagram as below:
//! Something that will provide the functionality of election will implement
//! [`ElectionProvider`] and its parent-trait [`ElectionProviderBase`], whilst needing an
//! associated [`ElectionProviderBase::DataProvider`], which needs to be
//! fulfilled by an entity implementing [`ElectionDataProvider`]. Most often, *the data provider is*
//! the receiver of the election, resulting in a diagram as below:
//!
//! ```ignore
//! ElectionDataProvider
Expand Down Expand Up @@ -131,12 +132,16 @@
//! type DataProvider: ElectionDataProvider<AccountId=AccountId, BlockNumber = BlockNumber>;
//! }
//!
//! impl<T: Config> ElectionProvider for GenericElectionProvider<T> {
//! impl<T: Config> ElectionProviderBase for GenericElectionProvider<T> {
//! type AccountId = AccountId;
//! type BlockNumber = BlockNumber;
//! type Error = &'static str;
//! type DataProvider = T::DataProvider;
//! fn ongoing() -> bool { false }
//!
//! }
//!
//! impl<T: Config> ElectionProvider for GenericElectionProvider<T> {
//! fn elect() -> Result<Supports<AccountId>, Self::Error> {
//! Self::DataProvider::electable_targets(None)
//! .map_err(|_| "failed to elect")
Expand Down Expand Up @@ -177,8 +182,8 @@ pub use frame_support::{traits::Get, weights::Weight, BoundedVec, RuntimeDebug};
/// Re-export some type as they are used in the interface.
pub use sp_arithmetic::PerThing;
pub use sp_npos_elections::{
Assignment, BalancingConfig, ElectionResult, Error, ExtendedBalance, IdentifierT, PerThing128,
Support, Supports, VoteWeight,
Assignment, BalancingConfig, BoundedSupports, ElectionResult, Error, ExtendedBalance,
IdentifierT, PerThing128, Support, Supports, VoteWeight,
};
pub use traits::NposSolution;

Expand Down Expand Up @@ -349,12 +354,12 @@ pub trait ElectionDataProvider {
fn clear() {}
}

/// Something that can compute the result of an election and pass it back to the caller.
/// Base trait for [`ElectionProvider`] and [`BoundedElectionProvider`]. It is
/// meant to be used only with an extension trait that adds an election
/// functionality.
///
/// This trait only provides an interface to _request_ an election, i.e.
/// [`ElectionProvider::elect`]. That data required for the election need to be passed to the
/// implemented of this trait through [`ElectionProvider::DataProvider`].
pub trait ElectionProvider {
/// Data can be bounded or unbounded and is fetched from [`Self::DataProvider`].
pub trait ElectionProviderBase {
/// The account identifier type.
type AccountId;

Expand All @@ -372,24 +377,39 @@ pub trait ElectionProvider {

/// Indicate if this election provider is currently ongoing an asynchronous election or not.
fn ongoing() -> bool;
}

/// Elect a new set of winners, without specifying any bounds on the amount of data fetched from
/// [`Self::DataProvider`]. An implementation could nonetheless impose its own custom limits.
///
/// The result is returned in a target major format, namely as *vector of supports*.
///
/// This should be implemented as a self-weighing function. The implementor should register its
/// appropriate weight at the end of execution with the system pallet directly.
/// Elect a new set of winners, bounded by `MaxWinners`.
///
/// Returns a result in bounded, target major format, namely as
/// *BoundedVec<(AccountId, Vec<Support>), MaxWinners>*.
pub trait BoundedElectionProvider: ElectionProviderBase {
/// The upper bound on election winners.
type MaxWinners: Get<u32>;
/// Performs the election. This should be implemented as a self-weighing function. The
/// implementor should register its appropriate weight at the end of execution with the
/// system pallet directly.
fn elect() -> Result<BoundedSupports<Self::AccountId, Self::MaxWinners>, Self::Error>;
}

/// Same a [`BoundedElectionProvider`], but no bounds are imposed on the number
/// of winners.
///
/// The result is returned in a target major format, namely as
///*Vec<(AccountId, Vec<Support>)>*.
pub trait ElectionProvider: ElectionProviderBase {
/// Performs the election. This should be implemented as a self-weighing
/// function, similar to [`BoundedElectionProvider::elect()`].
fn elect() -> Result<Supports<Self::AccountId>, Self::Error>;
}

/// A sub-trait of the [`ElectionProvider`] for cases where we need to be sure an election needs to
/// happen instantly, not asynchronously.
/// A sub-trait of the [`ElectionProvider`] for cases where we need to be sure
/// an election needs to happen instantly, not asynchronously.
///
/// The same `DataProvider` is assumed to be used.
///
/// Consequently, allows for control over the amount of data that is being fetched from the
/// [`ElectionProvider::DataProvider`].
/// Consequently, allows for control over the amount of data that is being
/// fetched from the [`ElectionProviderBase::DataProvider`].
pub trait InstantElectionProvider: ElectionProvider {
/// Elect a new set of winners, but unlike [`ElectionProvider::elect`] which cannot enforce
/// bounds, this trait method can enforce bounds on the amount of data provided by the
Expand All @@ -410,7 +430,7 @@ pub trait InstantElectionProvider: ElectionProvider {
pub struct NoElection<X>(sp_std::marker::PhantomData<X>);

#[cfg(feature = "std")]
impl<AccountId, BlockNumber, DataProvider> ElectionProvider
impl<AccountId, BlockNumber, DataProvider> ElectionProviderBase
for NoElection<(AccountId, BlockNumber, DataProvider)>
where
DataProvider: ElectionDataProvider<AccountId = AccountId, BlockNumber = BlockNumber>,
Expand All @@ -420,15 +440,22 @@ where
type Error = &'static str;
type DataProvider = DataProvider;

fn elect() -> Result<Supports<AccountId>, Self::Error> {
Err("<NoElection as ElectionProvider> cannot do anything.")
}

fn ongoing() -> bool {
false
}
}

#[cfg(feature = "std")]
impl<AccountId, BlockNumber, DataProvider> ElectionProvider
for NoElection<(AccountId, BlockNumber, DataProvider)>
where
DataProvider: ElectionDataProvider<AccountId = AccountId, BlockNumber = BlockNumber>,
{
fn elect() -> Result<Supports<AccountId>, Self::Error> {
Err("<NoElection as ElectionProvider> cannot do anything.")
}
}

/// A utility trait for something to implement `ElectionDataProvider` in a sensible way.
///
/// This is generic over `AccountId` and it can represent a validator, a nominator, or any other
Expand Down
27 changes: 16 additions & 11 deletions frame/election-provider-support/src/onchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
//! careful when using it onchain.

use crate::{
Debug, ElectionDataProvider, ElectionProvider, InstantElectionProvider, NposSolver, WeightInfo,
Debug, ElectionDataProvider, ElectionProvider, ElectionProviderBase, InstantElectionProvider,
NposSolver, WeightInfo,
};
use frame_support::{dispatch::DispatchClass, traits::Get};
use sp_npos_elections::*;
Expand Down Expand Up @@ -133,15 +134,6 @@ fn elect_with<T: Config>(
}

impl<T: Config> ElectionProvider for UnboundedExecution<T> {
type AccountId = <T::System as frame_system::Config>::AccountId;
type BlockNumber = <T::System as frame_system::Config>::BlockNumber;
type Error = Error;
type DataProvider = T::DataProvider;

fn ongoing() -> bool {
false
}

fn elect() -> Result<Supports<Self::AccountId>, Self::Error> {
// This should not be called if not in `std` mode (and therefore neither in genesis nor in
// testing)
Expand All @@ -156,6 +148,17 @@ impl<T: Config> ElectionProvider for UnboundedExecution<T> {
}
}

impl<T: Config> ElectionProviderBase for UnboundedExecution<T> {
type AccountId = <T::System as frame_system::Config>::AccountId;
type BlockNumber = <T::System as frame_system::Config>::BlockNumber;
type Error = Error;
type DataProvider = T::DataProvider;

fn ongoing() -> bool {
false
}
}

impl<T: Config> InstantElectionProvider for UnboundedExecution<T> {
fn elect_with_bounds(
max_voters: usize,
Expand All @@ -165,7 +168,7 @@ impl<T: Config> InstantElectionProvider for UnboundedExecution<T> {
}
}

impl<T: BoundedConfig> ElectionProvider for BoundedExecution<T> {
impl<T: BoundedConfig> ElectionProviderBase for BoundedExecution<T> {
type AccountId = <T::System as frame_system::Config>::AccountId;
type BlockNumber = <T::System as frame_system::Config>::BlockNumber;
type Error = Error;
Expand All @@ -174,7 +177,9 @@ impl<T: BoundedConfig> ElectionProvider for BoundedExecution<T> {
fn ongoing() -> bool {
false
}
}

impl<T: BoundedConfig> ElectionProvider for BoundedExecution<T> {
fn elect() -> Result<Supports<Self::AccountId>, Self::Error> {
elect_with::<T>(Some(T::VotersBound::get() as usize), Some(T::TargetsBound::get() as usize))
}
Expand Down
5 changes: 3 additions & 2 deletions frame/fast-unstake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ macro_rules! log {
pub mod pallet {
use super::*;
use crate::types::*;
use frame_election_provider_support::ElectionProvider;
use frame_election_provider_support::ElectionProviderBase;
use frame_support::{
pallet_prelude::*,
traits::{Defensive, ReservableCurrency},
Expand Down Expand Up @@ -330,7 +330,8 @@ pub mod pallet {
}
}

if <T as pallet_staking::Config>::ElectionProvider::ongoing() {
if <<T as pallet_staking::Config>::ElectionProvider as ElectionProviderBase>::ongoing()
{
// NOTE: we assume `ongoing` does not consume any weight.
// there is an ongoing election -- we better not do anything. Imagine someone is not
// exposed anywhere in the last era, and the snapshot for the election is already
Expand Down
4 changes: 3 additions & 1 deletion frame/fast-unstake/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ parameter_types! {
}

pub struct MockElection;
impl frame_election_provider_support::ElectionProvider for MockElection {
impl frame_election_provider_support::ElectionProviderBase for MockElection {
type AccountId = AccountId;
type BlockNumber = BlockNumber;
type DataProvider = Staking;
Expand All @@ -113,7 +113,9 @@ impl frame_election_provider_support::ElectionProvider for MockElection {
fn ongoing() -> bool {
Ongoing::get()
}
}

impl frame_election_provider_support::ElectionProvider for MockElection {
fn elect() -> Result<frame_election_provider_support::Supports<AccountId>, Self::Error> {
Err(())
}
Expand Down
14 changes: 9 additions & 5 deletions primitives/npos-elections/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,16 @@

#![cfg_attr(not(feature = "std"), no_std)]

use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_arithmetic::{traits::Zero, Normalizable, PerThing, Rational128, ThresholdOrd};
use sp_core::RuntimeDebug;
use sp_core::{bounded::BoundedVec, RuntimeDebug};
use sp_std::{
cell::RefCell, cmp::Ordering, collections::btree_map::BTreeMap, prelude::*, rc::Rc, vec,
};

use codec::{Decode, Encode, MaxEncodedLen};
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};

#[cfg(test)]
mod mock;
#[cfg(test)]
Expand Down Expand Up @@ -451,6 +450,11 @@ impl<AccountId> Default for Support<AccountId> {
/// The main advantage of this is that it is encodable.
pub type Supports<A> = Vec<(A, Support<A>)>;

/// Same as `Supports` bounded by `MaxWinners`.
///
/// To note, the inner `Support` is still unbounded.
pub type BoundedSupports<A, MaxWinners> = BoundedVec<(A, Support<A>), MaxWinners>;

/// Linkage from a winner to their [`Support`].
///
/// This is more helpful than a normal [`Supports`] as it allows faster error checking.
Expand Down