mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-24 20:35:41 +00:00
Fix phragmen election to wasm (#3898)
* Fix phragmen-election compile to wasm * Fix chain_spec stuff * Fix panic with no term duration
This commit is contained in:
Generated
+1
-1
@@ -2484,7 +2484,7 @@ dependencies = [
|
|||||||
"srml-contracts 2.0.0",
|
"srml-contracts 2.0.0",
|
||||||
"srml-contracts-rpc-runtime-api 2.0.0",
|
"srml-contracts-rpc-runtime-api 2.0.0",
|
||||||
"srml-democracy 2.0.0",
|
"srml-democracy 2.0.0",
|
||||||
"srml-elections 2.0.0",
|
"srml-elections-phragmen 2.0.0",
|
||||||
"srml-executive 2.0.0",
|
"srml-executive 2.0.0",
|
||||||
"srml-finality-tracker 2.0.0",
|
"srml-finality-tracker 2.0.0",
|
||||||
"srml-grandpa 2.0.0",
|
"srml-grandpa 2.0.0",
|
||||||
|
|||||||
@@ -235,11 +235,11 @@ pub fn testnet_genesis(
|
|||||||
members: vec![],
|
members: vec![],
|
||||||
phantom: Default::default(),
|
phantom: Default::default(),
|
||||||
}),
|
}),
|
||||||
elections: Some(ElectionsConfig {
|
elections_phragmen: Some(ElectionsConfig {
|
||||||
members: vec![],
|
members: endowed_accounts.iter().take(2).cloned().collect(),
|
||||||
presentation_duration: 1 * DAYS,
|
|
||||||
term_duration: 28 * DAYS,
|
term_duration: 28 * DAYS,
|
||||||
desired_seats: 0,
|
desired_members: 4,
|
||||||
|
desired_runners_up: 1,
|
||||||
}),
|
}),
|
||||||
contracts: Some(ContractsConfig {
|
contracts: Some(ContractsConfig {
|
||||||
current_schedule: contracts::Schedule {
|
current_schedule: contracts::Schedule {
|
||||||
|
|||||||
@@ -60,9 +60,6 @@ pub type DigestItem = generic::DigestItem<Hash>;
|
|||||||
/// Header type.
|
/// Header type.
|
||||||
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||||
/// Block type.
|
/// Block type.
|
||||||
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
|
pub type Block = generic::Block<Header, OpaqueExtrinsic>;
|
||||||
/// Block ID.
|
/// Block ID.
|
||||||
pub type BlockId = generic::BlockId<Block>;
|
pub type BlockId = generic::BlockId<Block>;
|
||||||
|
|
||||||
/// Opaque, encoded, unchecked extrinsic.
|
|
||||||
pub type UncheckedExtrinsic = OpaqueExtrinsic;
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ collective = { package = "srml-collective", path = "../../srml/collective", defa
|
|||||||
contracts = { package = "srml-contracts", path = "../../srml/contracts", default-features = false }
|
contracts = { package = "srml-contracts", path = "../../srml/contracts", default-features = false }
|
||||||
contracts-rpc-runtime-api = { package = "srml-contracts-rpc-runtime-api", path = "../../srml/contracts/rpc/runtime-api/", default-features = false }
|
contracts-rpc-runtime-api = { package = "srml-contracts-rpc-runtime-api", path = "../../srml/contracts/rpc/runtime-api/", default-features = false }
|
||||||
democracy = { package = "srml-democracy", path = "../../srml/democracy", default-features = false }
|
democracy = { package = "srml-democracy", path = "../../srml/democracy", default-features = false }
|
||||||
elections = { package = "srml-elections", path = "../../srml/elections", default-features = false }
|
elections-phragmen = { package = "srml-elections-phragmen", path = "../../srml/elections-phragmen", default-features = false }
|
||||||
executive = { package = "srml-executive", path = "../../srml/executive", default-features = false }
|
executive = { package = "srml-executive", path = "../../srml/executive", default-features = false }
|
||||||
finality-tracker = { package = "srml-finality-tracker", path = "../../srml/finality-tracker", default-features = false }
|
finality-tracker = { package = "srml-finality-tracker", path = "../../srml/finality-tracker", default-features = false }
|
||||||
grandpa = { package = "srml-grandpa", path = "../../srml/grandpa", default-features = false }
|
grandpa = { package = "srml-grandpa", path = "../../srml/grandpa", default-features = false }
|
||||||
@@ -72,7 +72,7 @@ std = [
|
|||||||
"contracts/std",
|
"contracts/std",
|
||||||
"contracts-rpc-runtime-api/std",
|
"contracts-rpc-runtime-api/std",
|
||||||
"democracy/std",
|
"democracy/std",
|
||||||
"elections/std",
|
"elections-phragmen/std",
|
||||||
"executive/std",
|
"executive/std",
|
||||||
"finality-tracker/std",
|
"finality-tracker/std",
|
||||||
"grandpa/std",
|
"grandpa/std",
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ use sr_primitives::traits::{
|
|||||||
self, BlakeTwo256, Block as BlockT, NumberFor, StaticLookup, SaturatedConversion,
|
self, BlakeTwo256, Block as BlockT, NumberFor, StaticLookup, SaturatedConversion,
|
||||||
};
|
};
|
||||||
use version::RuntimeVersion;
|
use version::RuntimeVersion;
|
||||||
use elections::VoteIndex;
|
|
||||||
#[cfg(any(feature = "std", test))]
|
#[cfg(any(feature = "std", test))]
|
||||||
use version::NativeVersion;
|
use version::NativeVersion;
|
||||||
use primitives::OpaqueMetadata;
|
use primitives::OpaqueMetadata;
|
||||||
@@ -84,8 +83,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
|||||||
// and set impl_version to equal spec_version. If only runtime
|
// and set impl_version to equal spec_version. If only runtime
|
||||||
// implementation changes and behavior does not, then leave spec_version as
|
// implementation changes and behavior does not, then leave spec_version as
|
||||||
// is and increment impl_version.
|
// is and increment impl_version.
|
||||||
spec_version: 181,
|
spec_version: 182,
|
||||||
impl_version: 183,
|
impl_version: 182,
|
||||||
apis: RUNTIME_API_VERSIONS,
|
apis: RUNTIME_API_VERSIONS,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -324,33 +323,18 @@ impl collective::Trait<CouncilCollective> for Runtime {
|
|||||||
parameter_types! {
|
parameter_types! {
|
||||||
pub const CandidacyBond: Balance = 10 * DOLLARS;
|
pub const CandidacyBond: Balance = 10 * DOLLARS;
|
||||||
pub const VotingBond: Balance = 1 * DOLLARS;
|
pub const VotingBond: Balance = 1 * DOLLARS;
|
||||||
pub const VotingFee: Balance = 2 * DOLLARS;
|
|
||||||
pub const MinimumVotingLock: Balance = 1 * DOLLARS;
|
|
||||||
pub const PresentSlashPerVoter: Balance = 1 * CENTS;
|
|
||||||
pub const CarryCount: u32 = 6;
|
|
||||||
// one additional vote should go by before an inactive voter can be reaped.
|
|
||||||
pub const InactiveGracePeriod: VoteIndex = 1;
|
|
||||||
pub const ElectionsVotingPeriod: BlockNumber = 2 * DAYS;
|
|
||||||
pub const DecayRatio: u32 = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl elections::Trait for Runtime {
|
impl elections_phragmen::Trait for Runtime {
|
||||||
type Event = Event;
|
type Event = Event;
|
||||||
type Currency = Balances;
|
type Currency = Balances;
|
||||||
type BadPresentation = ();
|
type CurrencyToVote = CurrencyToVoteHandler;
|
||||||
type BadReaper = ();
|
|
||||||
type BadVoterIndex = ();
|
|
||||||
type LoserCandidate = ();
|
|
||||||
type ChangeMembers = Council;
|
|
||||||
type CandidacyBond = CandidacyBond;
|
type CandidacyBond = CandidacyBond;
|
||||||
type VotingBond = VotingBond;
|
type VotingBond = VotingBond;
|
||||||
type VotingFee = VotingFee;
|
type LoserCandidate = ();
|
||||||
type MinimumVotingLock = MinimumVotingLock;
|
type BadReport = ();
|
||||||
type PresentSlashPerVoter = PresentSlashPerVoter;
|
type KickedMember = ();
|
||||||
type CarryCount = CarryCount;
|
type ChangeMembers = Council;
|
||||||
type InactiveGracePeriod = InactiveGracePeriod;
|
|
||||||
type VotingPeriod = ElectionsVotingPeriod;
|
|
||||||
type DecayRatio = DecayRatio;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type TechnicalCollective = collective::Instance2;
|
type TechnicalCollective = collective::Instance2;
|
||||||
@@ -518,7 +502,7 @@ construct_runtime!(
|
|||||||
Democracy: democracy::{Module, Call, Storage, Config, Event<T>},
|
Democracy: democracy::{Module, Call, Storage, Config, Event<T>},
|
||||||
Council: collective::<Instance1>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
|
Council: collective::<Instance1>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
|
||||||
TechnicalCommittee: collective::<Instance2>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
|
TechnicalCommittee: collective::<Instance2>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
|
||||||
Elections: elections::{Module, Call, Storage, Event<T>, Config<T>},
|
Elections: elections_phragmen::{Module, Call, Storage, Event<T>, Config<T>},
|
||||||
TechnicalMembership: membership::<Instance1>::{Module, Call, Storage, Event<T>, Config<T>},
|
TechnicalMembership: membership::<Instance1>::{Module, Call, Storage, Event<T>, Config<T>},
|
||||||
FinalityTracker: finality_tracker::{Module, Call, Inherent},
|
FinalityTracker: finality_tracker::{Module, Call, Inherent},
|
||||||
Grandpa: grandpa::{Module, Call, Storage, Config, Event},
|
Grandpa: grandpa::{Module, Call, Storage, Config, Event},
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ pub fn config(support_changes_trie: bool, code: Option<&[u8]>) -> GenesisConfig
|
|||||||
collective_Instance1: Some(Default::default()),
|
collective_Instance1: Some(Default::default()),
|
||||||
collective_Instance2: Some(Default::default()),
|
collective_Instance2: Some(Default::default()),
|
||||||
membership_Instance1: Some(Default::default()),
|
membership_Instance1: Some(Default::default()),
|
||||||
elections: Some(Default::default()),
|
elections_phragmen: Some(Default::default()),
|
||||||
sudo: Some(Default::default()),
|
sudo: Some(Default::default()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,6 +76,7 @@
|
|||||||
|
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
|
||||||
|
use rstd::prelude::*;
|
||||||
use sr_primitives::{print, traits::{Zero, StaticLookup, Bounded, Convert}};
|
use sr_primitives::{print, traits::{Zero, StaticLookup, Bounded, Convert}};
|
||||||
use sr_primitives::weights::SimpleDispatchInfo;
|
use sr_primitives::weights::SimpleDispatchInfo;
|
||||||
use srml_support::{
|
use srml_support::{
|
||||||
@@ -136,7 +137,8 @@ decl_storage! {
|
|||||||
/// Number of runners_up to keep.
|
/// Number of runners_up to keep.
|
||||||
pub DesiredRunnersUp get(fn desired_runners_up) config(): u32;
|
pub DesiredRunnersUp get(fn desired_runners_up) config(): u32;
|
||||||
/// How long each seat is kept. This defines the next block number at which an election
|
/// How long each seat is kept. This defines the next block number at which an election
|
||||||
/// round will happen.
|
/// round will happen. If set to zero, no elections are ever triggered and the module will
|
||||||
|
/// be in passive mode. In that case only a member set defined in at genesis can exist.
|
||||||
pub TermDuration get(fn term_duration) config(): T::BlockNumber;
|
pub TermDuration get(fn term_duration) config(): T::BlockNumber;
|
||||||
|
|
||||||
// ---- State
|
// ---- State
|
||||||
@@ -470,8 +472,10 @@ impl<T: Trait> Module<T> {
|
|||||||
/// Runs phragmen election and cleans all the previous candidate state. The voter state is NOT
|
/// Runs phragmen election and cleans all the previous candidate state. The voter state is NOT
|
||||||
/// cleaned and voters must themselves submit a transaction to retract.
|
/// cleaned and voters must themselves submit a transaction to retract.
|
||||||
fn end_block(block_number: T::BlockNumber) -> dispatch::Result {
|
fn end_block(block_number: T::BlockNumber) -> dispatch::Result {
|
||||||
if (block_number % Self::term_duration()).is_zero() {
|
if !Self::term_duration().is_zero() {
|
||||||
Self::do_phragmen();
|
if (block_number % Self::term_duration()).is_zero() {
|
||||||
|
Self::do_phragmen();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -701,7 +705,9 @@ mod tests {
|
|||||||
pub struct ExtBuilder {
|
pub struct ExtBuilder {
|
||||||
balance_factor: u64,
|
balance_factor: u64,
|
||||||
voter_bond: u64,
|
voter_bond: u64,
|
||||||
|
term_duration: u64,
|
||||||
desired_runners_up: u32,
|
desired_runners_up: u32,
|
||||||
|
members: Vec<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ExtBuilder {
|
impl Default for ExtBuilder {
|
||||||
@@ -710,6 +716,8 @@ mod tests {
|
|||||||
balance_factor: 1,
|
balance_factor: 1,
|
||||||
voter_bond: 2,
|
voter_bond: 2,
|
||||||
desired_runners_up: 0,
|
desired_runners_up: 0,
|
||||||
|
term_duration: 5,
|
||||||
|
members: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -723,6 +731,14 @@ mod tests {
|
|||||||
self.desired_runners_up = count;
|
self.desired_runners_up = count;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
pub fn term_duration(mut self, duration: u64) -> Self {
|
||||||
|
self.term_duration = duration;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
pub fn members(mut self, members: Vec<u64>) -> Self {
|
||||||
|
self.members = members;
|
||||||
|
self
|
||||||
|
}
|
||||||
pub fn build(self) -> runtime_io::TestExternalities {
|
pub fn build(self) -> runtime_io::TestExternalities {
|
||||||
VOTING_BOND.with(|v| *v.borrow_mut() = self.voter_bond);
|
VOTING_BOND.with(|v| *v.borrow_mut() = self.voter_bond);
|
||||||
GenesisConfig {
|
GenesisConfig {
|
||||||
@@ -738,10 +754,10 @@ mod tests {
|
|||||||
vesting: vec![],
|
vesting: vec![],
|
||||||
}),
|
}),
|
||||||
elections: Some(elections::GenesisConfig::<Test>{
|
elections: Some(elections::GenesisConfig::<Test>{
|
||||||
members: vec![],
|
members: self.members,
|
||||||
desired_members: 2,
|
desired_members: 2,
|
||||||
desired_runners_up: self.desired_runners_up,
|
desired_runners_up: self.desired_runners_up,
|
||||||
term_duration: 5,
|
term_duration: self.term_duration,
|
||||||
}),
|
}),
|
||||||
}.build_storage().unwrap().into()
|
}.build_storage().unwrap().into()
|
||||||
}
|
}
|
||||||
@@ -781,6 +797,33 @@ mod tests {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn passive_module_should_work() {
|
||||||
|
ExtBuilder::default()
|
||||||
|
.term_duration(0)
|
||||||
|
.members(vec![1, 2, 3])
|
||||||
|
.build()
|
||||||
|
.execute_with(||
|
||||||
|
{
|
||||||
|
System::set_block_number(1);
|
||||||
|
assert_eq!(Elections::term_duration(), 0);
|
||||||
|
assert_eq!(Elections::desired_members(), 2);
|
||||||
|
assert_eq!(Elections::election_rounds(), 0);
|
||||||
|
|
||||||
|
assert_eq!(Elections::members(), vec![1, 2, 3]);
|
||||||
|
assert_eq!(Elections::runners_up(), vec![]);
|
||||||
|
|
||||||
|
assert_eq!(Elections::candidates(), vec![]);
|
||||||
|
assert_eq!(all_voters(), vec![]);
|
||||||
|
|
||||||
|
System::set_block_number(5);
|
||||||
|
assert_ok!(Elections::end_block(System::block_number()));
|
||||||
|
|
||||||
|
assert_eq!(Elections::members(), vec![1, 2, 3]);
|
||||||
|
assert_eq!(Elections::runners_up(), vec![]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn simple_candidate_submission_should_work() {
|
fn simple_candidate_submission_should_work() {
|
||||||
ExtBuilder::default().build().execute_with(|| {
|
ExtBuilder::default().build().execute_with(|| {
|
||||||
|
|||||||
Reference in New Issue
Block a user