Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix some side issues.
  • Loading branch information
kianenigma committed Mar 14, 2019
commit 5567859b677636dcab85b758ef5c3555f4c00b8d
16 changes: 1 addition & 15 deletions node/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,13 +445,7 @@ mod tests {
]
);

// let mut digest = generic::Digest::<Log>::default();
// digest.push(Log::from(::grandpa::RawLog::AuthoritiesChangeSignal(0, vec![
// (Keyring::Charlie.to_raw_public().into(), 1),
// (Keyring::Bob.to_raw_public().into(), 1),
// (Keyring::Alice.to_raw_public().into(), 1),
// ])));
let digest = generic::Digest::<Log>::default(); // TODO test this
let digest = generic::Digest::<Log>::default();
assert_eq!(Header::decode(&mut &block2.0[..]).unwrap().digest, digest);

(block1, block2)
Expand Down Expand Up @@ -584,14 +578,6 @@ mod tests {
phase: Phase::Finalization,
event: Event::session(session::RawEvent::NewSession(1))
},
// EventRecord { // TODO: this might be wrong.
// phase: Phase::Finalization,
// event: Event::grandpa(::grandpa::RawEvent::NewAuthorities(vec![
// (Keyring::Charlie.to_raw_public().into(), 1),
// (Keyring::Bob.to_raw_public().into(), 1),
// (Keyring::Alice.to_raw_public().into(), 1),
// ])),
// },
EventRecord {
phase: Phase::Finalization,
event: Event::treasury(treasury::RawEvent::Spending(0))
Expand Down
2 changes: 1 addition & 1 deletion srml/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ impl<T: Trait> Module<T> {

/// Select a new validator set from the assembled stakers and their role preferences.
///
/// @returns the new SlotStake value.
/// returns the new SlotStake value.
fn select_validators() -> BalanceOf<T> {
// Map of (would-be) validator account to amount of stake backing it.

Expand Down
34 changes: 15 additions & 19 deletions srml/staking/src/phragmen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,25 @@ pub struct Vote<AccountId, Balance: HasCompact> {
///
/// Reference implementation: https://github.com/w3f/consensus
///
/// @returns a vector of elected candidates
/// returns a vector of elected candidates
pub fn elect<T: Trait + 'static, FR, FN, FV, FS>(
get_rounds: FR,
get_validators: FV,
get_nominators: FN,
stash_of: FS,
minimum_validator_count: usize,
) -> Vec<Candidate<T::AccountId, BalanceOf<T>>> where
FR: Fn() -> usize,
FV: Fn() -> Box<dyn Iterator<
Item =(T::AccountId, ValidatorPrefs<BalanceOf<T>>)
>>,
FN: Fn() -> Box<dyn Iterator<
Item =(T::AccountId, Vec<T::AccountId>)
>>,
FS: Fn(T::AccountId) -> BalanceOf<T>,
) -> Vec<Candidate<T::AccountId, BalanceOf<T>>> where
FR: Fn() -> usize,
FV: Fn() -> Box<dyn Iterator<
Item =(T::AccountId, ValidatorPrefs<BalanceOf<T>>)
>>,
FN: Fn() -> Box<dyn Iterator<
Item =(T::AccountId, Vec<T::AccountId>)
>>,
FS: Fn(T::AccountId) -> BalanceOf<T>,
{
let rounds = get_rounds();
let mut elected_candidates = vec![];
let mut elected_candidates;

// 1- Pre-process candidates and place them in a container
let mut candidates = get_validators().map(|(who, _)| {
Expand Down Expand Up @@ -130,6 +130,7 @@ pub fn elect<T: Trait + 'static, FR, FN, FV, FS>(

// 4- If we have more candidates then needed, run Phragmén.
if candidates.len() > rounds {
elected_candidates = Vec::with_capacity(rounds);
// Main election loop
for _round in 0..rounds {
// Loop 1: initialize score
Expand Down Expand Up @@ -177,23 +178,18 @@ pub fn elect<T: Trait + 'static, FR, FN, FV, FS>(
}

elected_candidates.push(winner);

} // end of all rounds

// 4.1- Update backing stake of candidates and nominators
for n in &mut nominations {
for v in &mut n.nominees {
// if the target of this vote is among the winners, otherwise let go.
if let Some(c) = elected_candidates.iter_mut().find(|c| c.who == v.who) {
v.backing_stake = <BalanceOf<T> as As<u64>>::sa(
n.stake.as_()
* *v.load
/ *n.load
);
v.backing_stake = <BalanceOf<T> as As<u64>>::sa(n.stake.as_() * *v.load / *n.load);
c.exposure.total += v.backing_stake;
// Update IndividualExposure of those who nominated and their vote won
c.exposure.others.push(
IndividualExposure {who: n.who.clone(), value: v.backing_stake }
IndividualExposure { who: n.who.clone(), value: v.backing_stake }
);
}
}
Expand All @@ -208,7 +204,7 @@ pub fn elect<T: Trait + 'static, FR, FN, FV, FS>(
if let Some(c) = elected_candidates.iter_mut().find(|c| c.who == v.who) {
c.exposure.total += n.stake;
c.exposure.others.push(
IndividualExposure {who: n.who.clone(), value: n.stake }
IndividualExposure { who: n.who.clone(), value: n.stake }
);
}
}
Expand Down