Custom Codec Implenetation for NPoS Election (#6720)

* Fancy compact encode/decode impl for compact solution

* Make it optional

* Remove extra file

* Update primitives/npos-elections/compact/src/lib.rs

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

* Final fixes.

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
Kian Paimani
2020-08-11 12:33:30 +02:00
committed by GitHub
parent 253f906a4d
commit 1519da95d7
8 changed files with 533 additions and 624 deletions
+20 -21
View File
@@ -326,7 +326,7 @@ use frame_system::{
};
use sp_npos_elections::{
ExtendedBalance, Assignment, ElectionScore, ElectionResult as PrimitiveElectionResult,
build_support_map, evaluate_support, seq_phragmen, generate_compact_solution_type,
build_support_map, evaluate_support, seq_phragmen, generate_solution_type,
is_score_better, VotingLimit, SupportMap, VoteWeight,
};
@@ -368,7 +368,25 @@ pub type EraIndex = u32;
pub type RewardPoint = u32;
// Note: Maximum nomination limit is set here -- 16.
generate_compact_solution_type!(pub GenericCompactAssignments, 16);
generate_solution_type!(
#[compact]
pub struct CompactAssignments::<NominatorIndex, ValidatorIndex, OffchainAccuracy>(16)
);
/// Accuracy used for on-chain election.
pub type ChainAccuracy = Perbill;
/// Accuracy used for off-chain election. This better be small.
pub type OffchainAccuracy = PerU16;
/// The balance type of this module.
pub type BalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
type PositiveImbalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::PositiveImbalance;
type NegativeImbalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;
/// Information regarding the active era (era in used in session).
#[derive(Encode, Decode, RuntimeDebug)]
@@ -382,25 +400,6 @@ pub struct ActiveEraInfo {
start: Option<u64>,
}
/// Accuracy used for on-chain election.
pub type ChainAccuracy = Perbill;
/// Accuracy used for off-chain election. This better be small.
pub type OffchainAccuracy = PerU16;
/// The balance type of this module.
pub type BalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
/// The compact type for election solutions.
pub type CompactAssignments =
GenericCompactAssignments<NominatorIndex, ValidatorIndex, OffchainAccuracy>;
type PositiveImbalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::PositiveImbalance;
type NegativeImbalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;
/// Reward points of an era. Used to split era total payout between validators.
///
/// This points will be used to reward validators and their respective nominators.