-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Staking: Introduce MaxBackersPerWinner
#11935
Conversation
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@@ -658,6 +659,10 @@ impl onchain::Config for OnChainSeqPhragmen { | |||
>; | |||
type DataProvider = <Runtime as pallet_election_provider_multi_phase::Config>::DataProvider; | |||
type WeightInfo = frame_election_provider_support::weights::SubstrateWeight<Runtime>; | |||
|
|||
// TODO no idea what to use here | |||
type MaxBackersPerWinner = ConstU32<{ u32::MAX }>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be 1024 or something a few orders larger than MaxNominatorRewardedPerValidator
.
/// The final supports of the solution. | ||
/// | ||
/// This is target-major vector, storing each winners, total backing, and each individual | ||
/// backer. | ||
pub supports: Supports<A>, | ||
pub supports: BoundedSupports<AccountId, MaxBackersPerWinner>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally move structs to be <T: Config>
once they need more than one generic from T
, just a suggestion.
/// Try to convert the supports of a solution into a [`ReadySolution`]. | ||
/// | ||
/// Errors if any of the supports has more than [`MaxBackersPerWinner`] backers. | ||
impl<AccountId: PartialEq, MaxBackersPerWinner: Get<u32>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this, I would implement just impl TryFrom<Supports<AccountId>> for BoundedSupports<..>
in election-provider-support/src
.
The other two elements of the tuple seems very out of context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, IIRC a lot of such conversions need to re-allocate in safe rust but with unsafe we can circumvent it.
let solution: ReadySolution<_, _> = | ||
(supports, Default::default(), ElectionCompute::Emergency) | ||
.try_into() | ||
.map_err(|_| Error::<T>::TooManyBackersPerWinner)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let solution: ReadySolution<_, _> = | |
(supports, Default::default(), ElectionCompute::Emergency) | |
.try_into() | |
.map_err(|_| Error::<T>::TooManyBackersPerWinner)?; | |
ReadySolution { | |
supports: supports.into_iter().map(|s| s.try_into()).collect::<Result<Vec<_>, _>>().map_err(|_| Error::<T>::TooManyBackersPerWinner)?, | |
score: Default::default(), | |
ElectionCompute::Emergency, | |
}; |
Supplement of https://github.com/paritytech/substrate/pull/11935/files#r933816968
pub voters: BoundedVec<(AccountId, ExtendedBalance), Bound>, | ||
} | ||
|
||
pub type BoundedSupportOf<E> = BoundedSupport< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub type BoundedSupportOf<E> = BoundedSupport< | |
/// Same as [`BoundedSupport`], parameterized by something that implements [`ElectionProvider`] | |
pub type BoundedSupportOf<E> = BoundedSupport< |
<E as ElectionProvider>::MaxBackersPerWinner, | ||
>; | ||
|
||
pub type BoundedSupports<AccountId, MaxBackersPerWinner> = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub type BoundedSupports<AccountId, MaxBackersPerWinner> = | |
/// Bounded counter-part of [`sp_npos_elections::Supports`]. | |
pub type BoundedSupports<AccountId, MaxBackersPerWinner> = |
pub type BoundedSupports<AccountId, MaxBackersPerWinner> = | ||
Vec<(AccountId, BoundedSupport<AccountId, MaxBackersPerWinner>)>; | ||
|
||
/// Convenience to create a [`BoundedSupport`] from a [`ElectionProvider`]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Convenience to create a [`BoundedSupport`] from a [`ElectionProvider`]. | |
/// Convenience to create a [`BoundedSupports`] from a [`ElectionProvider`]. |
I am very open to the idea of not relying on this damn 's' to distinguish Support and Supports. Suggestions?
This part of this work is quite nasty, deals with a lot of legacy code that I have admittedly not had the time to really re-think since years ago, so I decided to take a stab at it. Feel free to cherry pick this commit if it makes sense, else try your approach if you have one. only checked things compile, without any test. PS. this is the same as what I meant by
So these two TODOs are practically the same. |
cc @Ank4n |
Let's close this for now, and revisit later. |
Draft for @kianenigma
This is a preparation for bounding the Staking, eg #11585
Helps with paritytech/polkadot-sdk#473
Changes:
MaxBackersPerWinner
andBounder
BoundedSupports
inReadySolution
to make it a bit more bounded. TheBoundedSupports
is still an unbound vector though and would otherwise require a secondGet<u32>
bound.TruncateIntoBoundedSupports
elect_with_bounds
returns bounded supports.set_emergency_election_result
errors when the input is too long.Open:
score
function to not consumeself
unsigned.rs
trim_assignment_backers
as well."