mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 17:01:09 +00:00
Remove sp-runtime dependency from sp-phragmen (#5786)
* Remove sp-runtime dependency from sp-phragmen * Use regular derive(Debug) instead of RuntimeDebug
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
//! Helper methods for phragmen.
|
||||
|
||||
use crate::{Assignment, ExtendedBalance, VoteWeight, IdentifierT, StakedAssignment, WithApprovalOf};
|
||||
use sp_runtime::PerThing;
|
||||
use sp_arithmetic::PerThing;
|
||||
use sp_std::prelude::*;
|
||||
|
||||
/// Converts a vector of ratio assignments into ones with absolute budget value.
|
||||
@@ -57,7 +57,7 @@ pub fn to_without_backing<A: IdentifierT>(winners: Vec<WithApprovalOf<A>>) -> Ve
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use sp_runtime::Perbill;
|
||||
use sp_arithmetic::Perbill;
|
||||
|
||||
#[test]
|
||||
fn into_staked_works() {
|
||||
|
||||
@@ -34,8 +34,11 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use sp_std::{prelude::*, collections::btree_map::BTreeMap, fmt::Debug, cmp::Ordering, convert::TryFrom};
|
||||
use sp_runtime::{helpers_128bit::multiply_by_rational, PerThing, Rational128, RuntimeDebug, SaturatedConversion};
|
||||
use sp_runtime::traits::{Zero, Member, Saturating, Bounded};
|
||||
use sp_arithmetic::{
|
||||
PerThing, Rational128,
|
||||
helpers_128bit::multiply_by_rational,
|
||||
traits::{Zero, Saturating, Bounded, SaturatedConversion},
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
mod mock;
|
||||
@@ -60,7 +63,7 @@ pub use helpers::*;
|
||||
#[doc(hidden)]
|
||||
pub use codec;
|
||||
#[doc(hidden)]
|
||||
pub use sp_runtime;
|
||||
pub use sp_arithmetic;
|
||||
|
||||
// re-export the compact solution type.
|
||||
pub use sp_phragmen_compact::generate_compact_solution_type;
|
||||
@@ -107,7 +110,7 @@ pub type WithApprovalOf<A> = (A, ExtendedBalance);
|
||||
const DEN: u128 = u128::max_value();
|
||||
|
||||
/// A candidate entity for phragmen election.
|
||||
#[derive(Clone, Default, RuntimeDebug)]
|
||||
#[derive(Clone, Default, Debug)]
|
||||
struct Candidate<AccountId> {
|
||||
/// Identifier.
|
||||
who: AccountId,
|
||||
@@ -120,7 +123,7 @@ struct Candidate<AccountId> {
|
||||
}
|
||||
|
||||
/// A voter entity.
|
||||
#[derive(Clone, Default, RuntimeDebug)]
|
||||
#[derive(Clone, Default, Debug)]
|
||||
struct Voter<AccountId> {
|
||||
/// Identifier.
|
||||
who: AccountId,
|
||||
@@ -133,7 +136,7 @@ struct Voter<AccountId> {
|
||||
}
|
||||
|
||||
/// A candidate being backed by a voter.
|
||||
#[derive(Clone, Default, RuntimeDebug)]
|
||||
#[derive(Clone, Default, Debug)]
|
||||
struct Edge<AccountId> {
|
||||
/// Identifier.
|
||||
who: AccountId,
|
||||
@@ -144,7 +147,7 @@ struct Edge<AccountId> {
|
||||
}
|
||||
|
||||
/// Final result of the phragmen election.
|
||||
#[derive(RuntimeDebug)]
|
||||
#[derive(Debug)]
|
||||
pub struct PhragmenResult<AccountId, T: PerThing> {
|
||||
/// Just winners zipped with their approval stake. Note that the approval stake is merely the
|
||||
/// sub of their received stake and could be used for very basic sorting and approval voting.
|
||||
@@ -155,7 +158,7 @@ pub struct PhragmenResult<AccountId, T: PerThing> {
|
||||
}
|
||||
|
||||
/// A voter's stake assignment among a set of targets, represented as ratios.
|
||||
#[derive(RuntimeDebug, Clone, Default)]
|
||||
#[derive(Debug, Clone, Default)]
|
||||
#[cfg_attr(feature = "std", derive(PartialEq, Eq, Encode, Decode))]
|
||||
pub struct Assignment<AccountId, T: PerThing> {
|
||||
/// Voter's identifier.
|
||||
@@ -223,7 +226,7 @@ where
|
||||
|
||||
/// A voter's stake assignment among a set of targets, represented as absolute values in the scale
|
||||
/// of [`ExtendedBalance`].
|
||||
#[derive(RuntimeDebug, Clone, Default)]
|
||||
#[derive(Debug, Clone, Default)]
|
||||
#[cfg_attr(feature = "std", derive(PartialEq, Eq, Encode, Decode))]
|
||||
pub struct StakedAssignment<AccountId> {
|
||||
/// Voter's identifier
|
||||
@@ -301,7 +304,7 @@ impl<AccountId> StakedAssignment<AccountId> {
|
||||
///
|
||||
/// This, at the current version, resembles the `Exposure` defined in the Staking pallet, yet
|
||||
/// they do not necessarily have to be the same.
|
||||
#[derive(Default, RuntimeDebug)]
|
||||
#[derive(Default, Debug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Eq, PartialEq))]
|
||||
pub struct Support<AccountId> {
|
||||
/// Total support.
|
||||
@@ -334,7 +337,7 @@ pub fn elect<AccountId, R>(
|
||||
initial_candidates: Vec<AccountId>,
|
||||
initial_voters: Vec<(AccountId, VoteWeight, Vec<AccountId>)>,
|
||||
) -> Option<PhragmenResult<AccountId, R>> where
|
||||
AccountId: Default + Ord + Member,
|
||||
AccountId: Default + Ord + Clone,
|
||||
R: PerThing,
|
||||
{
|
||||
// return structures
|
||||
@@ -561,7 +564,7 @@ pub fn build_support_map<AccountId>(
|
||||
winners: &[AccountId],
|
||||
assignments: &[StakedAssignment<AccountId>],
|
||||
) -> (SupportMap<AccountId>, u32) where
|
||||
AccountId: Default + Ord + Member,
|
||||
AccountId: Default + Ord + Clone,
|
||||
{
|
||||
let mut errors = 0;
|
||||
// Initialize the support of each candidate.
|
||||
|
||||
@@ -19,11 +19,9 @@
|
||||
#![cfg(test)]
|
||||
|
||||
use crate::{elect, PhragmenResult, Assignment, VoteWeight, ExtendedBalance};
|
||||
use sp_runtime::{
|
||||
assert_eq_error_rate, PerThing,
|
||||
traits::{Member, SaturatedConversion, Zero, One}
|
||||
};
|
||||
use sp_arithmetic::{PerThing, traits::{SaturatedConversion, Zero, One}};
|
||||
use sp_std::collections::btree_map::BTreeMap;
|
||||
use sp_runtime::assert_eq_error_rate;
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub(crate) struct _Candidate<A> {
|
||||
@@ -77,7 +75,7 @@ pub(crate) fn elect_float<A, FS>(
|
||||
initial_voters: Vec<(A, Vec<A>)>,
|
||||
stake_of: FS,
|
||||
) -> Option<_PhragmenResult<A>> where
|
||||
A: Default + Ord + Member + Copy,
|
||||
A: Default + Ord + Copy,
|
||||
for<'r> FS: Fn(&'r A) -> VoteWeight,
|
||||
{
|
||||
let mut elected_candidates: Vec<(A, ExtendedBalance)>;
|
||||
|
||||
@@ -16,11 +16,10 @@
|
||||
|
||||
//! (very) Basic implementation of a graph node used in the reduce algorithm.
|
||||
|
||||
use sp_runtime::RuntimeDebug;
|
||||
use sp_std::{cell::RefCell, fmt, prelude::*, rc::Rc};
|
||||
|
||||
/// The role that a node can accept.
|
||||
#[derive(PartialEq, Eq, Ord, PartialOrd, Clone, RuntimeDebug)]
|
||||
#[derive(PartialEq, Eq, Ord, PartialOrd, Clone, Debug)]
|
||||
pub(crate) enum NodeRole {
|
||||
/// A voter. This is synonym to a nominator in a staking context.
|
||||
Voter,
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
|
||||
use crate::node::{Node, NodeId, NodeRef, NodeRole};
|
||||
use crate::{ExtendedBalance, IdentifierT, StakedAssignment};
|
||||
use sp_runtime::traits::{Bounded, Zero};
|
||||
use sp_arithmetic::traits::{Bounded, Zero};
|
||||
use sp_std::{
|
||||
collections::btree_map::{BTreeMap, Entry::*},
|
||||
prelude::*,
|
||||
|
||||
@@ -24,7 +24,7 @@ use crate::{
|
||||
Support, StakedAssignment, Assignment, PhragmenResult, ExtendedBalance,
|
||||
};
|
||||
use substrate_test_utils::assert_eq_uvec;
|
||||
use sp_runtime::{Perbill, Permill, Percent, PerU16};
|
||||
use sp_arithmetic::{Perbill, Permill, Percent, PerU16};
|
||||
|
||||
#[test]
|
||||
fn float_phragmen_poc_works() {
|
||||
@@ -648,7 +648,7 @@ mod compact {
|
||||
// these need to come from the same dev-dependency `sp-phragmen`, not from the crate.
|
||||
use sp_phragmen::{Assignment, StakedAssignment, Error as PhragmenError, ExtendedBalance};
|
||||
use sp_std::{convert::{TryInto, TryFrom}, fmt::Debug};
|
||||
use sp_runtime::Percent;
|
||||
use sp_arithmetic::Percent;
|
||||
|
||||
type Accuracy = Percent;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user