Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Rename all the election operations (#6245)
Browse files Browse the repository at this point in the history
* Rename and move sp-phragmen

* More renames for equalise

* Update main module doc

* Fix line width

* Line width
  • Loading branch information
kianenigma authored Jun 5, 2020
1 parent 606b4fa commit 252b146
Show file tree
Hide file tree
Showing 35 changed files with 284 additions and 310 deletions.
2 changes: 1 addition & 1 deletion .maintain/rename-crates-for-2.0.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ TO_RENAME=(
"substrate-keyring sp-keyring"
"substrate-offchain-primitives sp-offchain"
"substrate-panic-handler sp-panic-handler"
"substrate-phragmen sp-phragmen"
"substrate-phragmen sp-npos-elections"
"substrate-rpc-primitives sp-rpc"
"substrate-runtime-interface sp-runtime-interface"
"substrate-runtime-interface-proc-macro sp-runtime-interface-proc-macro"
Expand Down
54 changes: 27 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ members = [
"primitives/keyring",
"primitives/offchain",
"primitives/panic-handler",
"primitives/phragmen",
"primitives/phragmen/fuzzer",
"primitives/phragmen/compact",
"primitives/npos-elections",
"primitives/npos-elections/fuzzer",
"primitives/npos-elections/compact",
"primitives/rpc",
"primitives/runtime-interface",
"primitives/runtime-interface/proc-macro",
Expand Down
4 changes: 2 additions & 2 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ parameter_types! {
pub const ElectionsPhragmenModuleId: LockIdentifier = *b"phrelect";
}

// Make sure that there are no more than `MAX_MEMBERS` members elected via phragmen.
// Make sure that there are no more than `MAX_MEMBERS` members elected via elections-phragmen.
const_assert!(DesiredMembers::get() <= pallet_collective::MAX_MEMBERS);

impl pallet_elections_phragmen::Trait for Runtime {
Expand Down Expand Up @@ -580,7 +580,7 @@ impl pallet_sudo::Trait for Runtime {
parameter_types! {
pub const SessionDuration: BlockNumber = EPOCH_DURATION_IN_SLOTS as _;
pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value();
/// We prioritize im-online heartbeats over phragmen solution submission.
/// We prioritize im-online heartbeats over election solution submission.
pub const StakingUnsignedPriority: TransactionPriority = TransactionPriority::max_value() / 2;
}

Expand Down
2 changes: 1 addition & 1 deletion docs/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
/frame/staking/ @kianenigma
/frame/elections/ @kianenigma
/frame/elections-phragmen/ @kianenigma
/primitives/phragmen/ @kianenigma
/primitives/npos-elections/ @kianenigma

# Fixed point arithmetic
/primitives/sp-arithmetic/ @kianenigma
Expand Down
6 changes: 3 additions & 3 deletions frame/elections-phragmen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0"
homepage = "https://substrate.dev"
repository = "https:/paritytech/substrate/"
description = "FRAME election pallet for PHRAGMEN"
description = "FRAME pallet based on seq-Phragmén election method."

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
Expand All @@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.101", optional = true }
sp-runtime = { version = "2.0.0-rc2", default-features = false, path = "../../primitives/runtime" }
sp-phragmen = { version = "2.0.0-rc2", default-features = false, path = "../../primitives/phragmen" }
sp-npos-elections = { version = "2.0.0-rc2", default-features = false, path = "../../primitives/npos-elections" }
frame-support = { version = "2.0.0-rc2", default-features = false, path = "../support" }
frame-system = { version = "2.0.0-rc2", default-features = false, path = "../system" }
sp-std = { version = "2.0.0-rc2", default-features = false, path = "../../primitives/std" }
Expand All @@ -35,7 +35,7 @@ std = [
"codec/std",
"frame-support/std",
"sp-runtime/std",
"sp-phragmen/std",
"sp-npos-elections/std",
"frame-system/std",
"sp-std/std",
]
Expand Down
18 changes: 7 additions & 11 deletions frame/elections-phragmen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! # Phragmen Election Module.
//! # Phragmén Election Module.
//!
//! An election module based on sequential phragmen.
//!
Expand Down Expand Up @@ -100,7 +100,7 @@ use frame_support::{
ContainsLengthBound,
}
};
use sp_phragmen::{build_support_map, ExtendedBalance, VoteWeight, PhragmenResult};
use sp_npos_elections::{build_support_map, ExtendedBalance, VoteWeight, ElectionResult};
use frame_system::{self as system, ensure_signed, ensure_root};

mod benchmarking;
Expand Down Expand Up @@ -245,7 +245,6 @@ decl_storage! {
}

decl_error! {
/// Error for the elections-phragmen module.
pub enum Error for Module<T: Trait> {
/// Cannot vote when no candidates or members exist.
UnableToVote,
Expand Down Expand Up @@ -610,7 +609,7 @@ decl_module! {
/// the outgoing member is slashed.
///
/// If a runner-up is available, then the best runner-up will be removed and replaces the
/// outgoing member. Otherwise, a new phragmen round is started.
/// outgoing member. Otherwise, a new phragmen election is started.
///
/// Note that this does not affect the designated block number of the next election.
///
Expand Down Expand Up @@ -840,13 +839,10 @@ impl<T: Trait> Module<T> {

/// Run the phragmen election with all required side processes and state updates.
///
/// Calls the appropriate `ChangeMembers` function variant internally.
/// Calls the appropriate [`ChangeMembers`] function variant internally.
///
/// # <weight>
/// #### State
/// Reads: O(C + V*E) where C = candidates, V voters and E votes per voter exits.
/// Writes: O(M + R) with M desired members and R runners_up.
/// # </weight>
fn do_phragmen() {
let desired_seats = Self::desired_members() as usize;
let desired_runners_up = Self::desired_runners_up() as usize;
Expand Down Expand Up @@ -876,14 +872,14 @@ impl<T: Trait> Module<T> {
let voters_and_votes = Voting::<T>::iter()
.map(|(voter, (stake, targets))| { (voter, to_votes(stake), targets) })
.collect::<Vec<_>>();
let maybe_phragmen_result = sp_phragmen::elect::<T::AccountId, Perbill>(
let maybe_phragmen_result = sp_npos_elections::seq_phragmen::<T::AccountId, Perbill>(
num_to_elect,
0,
candidates,
voters_and_votes.clone(),
);

if let Some(PhragmenResult { winners, assignments }) = maybe_phragmen_result {
if let Some(ElectionResult { winners, assignments }) = maybe_phragmen_result {
let old_members_ids = <Members<T>>::take().into_iter()
.map(|(m, _)| m)
.collect::<Vec<T::AccountId>>();
Expand All @@ -907,7 +903,7 @@ impl<T: Trait> Module<T> {
// exposed candidates, cleaning any previous members, and so on. For now, in favour of
// readability and veracity, we keep it simple.

let staked_assignments = sp_phragmen::assignment_ratio_to_staked(
let staked_assignments = sp_npos_elections::assignment_ratio_to_staked(
assignments,
stake_of,
);
Expand Down
4 changes: 2 additions & 2 deletions frame/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static_assertions = "1.1.0"
serde = { version = "1.0.101", optional = true }
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] }
sp-std = { version = "2.0.0-rc2", default-features = false, path = "../../primitives/std" }
sp-phragmen = { version = "2.0.0-rc2", default-features = false, path = "../../primitives/phragmen" }
sp-npos-elections = { version = "2.0.0-rc2", default-features = false, path = "../../primitives/npos-elections" }
sp-io ={ version = "2.0.0-rc2", default-features = false, path = "../../primitives/io" }
sp-runtime = { version = "2.0.0-rc2", default-features = false, path = "../../primitives/runtime" }
sp-staking = { version = "2.0.0-rc2", default-features = false, path = "../../primitives/staking" }
Expand Down Expand Up @@ -49,7 +49,7 @@ std = [
"serde",
"codec/std",
"sp-std/std",
"sp-phragmen/std",
"sp-npos-elections/std",
"sp-io/std",
"frame-support/std",
"sp-runtime/std",
Expand Down
10 changes: 5 additions & 5 deletions frame/staking/fuzzer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frame/staking/fuzzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ frame-support = { version = "2.0.0-rc2", path = "../../support" }
sp-std = { version = "2.0.0-rc2", path = "../../../primitives/std" }
sp-io ={ version = "2.0.0-rc2", path = "../../../primitives/io" }
sp-core = { version = "2.0.0-rc2", path = "../../../primitives/core" }
sp-phragmen = { version = "2.0.0-rc2", path = "../../../primitives/phragmen" }
sp-npos-elections = { version = "2.0.0-rc2", path = "../../../primitives/npos-elections" }
sp-runtime = { version = "2.0.0-rc2", path = "../../../primitives/runtime" }

[[bin]]
Expand Down
2 changes: 1 addition & 1 deletion frame/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ benchmarks! {
let caller: T::AccountId = account("caller", n, SEED);
let era = <Staking<T>>::current_era().unwrap_or(0);

// submit a seq-phragmen with all the good stuff on chain
// submit a seq-phragmen with all the good stuff on chain.
{
let (winners, compact, score, size) = get_seq_phragmen_solution::<T>(true);
assert!(
Expand Down
Loading

0 comments on commit 252b146

Please sign in to comment.