Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hardcoded override to ElectionScore #455

Merged
merged 3 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
6 changes: 6 additions & 0 deletions codegen/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ impl RuntimeGenerator {
"frame_support::traits::misc::WrapperKeepOpaque",
parse_quote!(::subxt::WrapperKeepOpaque),
),
// We override this because it's used as a key in a BTreeMap, and so we
// need to implement some extra derives for it for that to compile.
(
"sp_npos_elections::ElectionScore",
parse_quote!(::subxt::ElectionScore),
),
]
.iter()
.map(|(path, substitute): &(&str, syn::TypePath)| {
Expand Down
19 changes: 19 additions & 0 deletions subxt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,22 @@ impl<T> PhantomDataSendSync<T> {

unsafe impl<T> Send for PhantomDataSendSync<T> {}
unsafe impl<T> Sync for PhantomDataSendSync<T> {}

/// [`ElectionScore`] overrides any generated instance of `sp_npos_elections::ElectionScore` found
/// in the metadata, so that we can add some extra derives required for it to be used as the key
/// in a [`std::collections::BTreeMap`].
#[derive(Encode, Decode, Debug, PartialOrd, Ord, PartialEq, Eq)]
pub struct ElectionScore {
/// The minimal winner, in terms of total backing stake.
///
/// This parameter should be maximized.
pub minimal_stake: u128,
/// The sum of the total backing of all winners.
///
/// This parameter should maximized
pub sum_stake: u128,
/// The sum squared of the total backing of all winners, aka. the variance.
///
/// Ths parameter should be minimized.
pub sum_stake_squared: u128,
}