Nonlinear locking and cleanups (#2733)

* Nonlinear locking and cleanups

* Bump runtime version

* Minor cleanup

* Fix tests

* Fix council tests

* Fix flaw in turnout counting

* fix: lock_voting_should_work_with_delegation test

* chore: fix comment refering to unexisting function
This commit is contained in:
Gavin Wood
2019-06-03 16:47:48 +02:00
committed by GitHub
parent 7885068fac
commit b88c46bfd1
7 changed files with 696 additions and 415 deletions
+2 -14
View File
@@ -119,13 +119,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
stakers: initial_authorities.iter().map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)).collect(),
invulnerables: initial_authorities.iter().map(|x| x.1.clone()).collect(),
}),
democracy: Some(DemocracyConfig {
launch_period: 10 * MINUTES, // 1 day per public referendum
voting_period: 10 * MINUTES, // 3 days to discuss & vote on an active referendum
minimum_deposit: 50 * DOLLARS, // 12000 as the minimum deposit for a referendum
public_delay: 10 * MINUTES,
max_lock_periods: 6,
}),
democracy: Some(DemocracyConfig::default()),
council_seats: Some(CouncilSeatsConfig {
active_council: vec![],
candidacy_bond: 10 * DOLLARS,
@@ -303,13 +297,7 @@ pub fn testnet_genesis(
stakers: initial_authorities.iter().map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)).collect(),
invulnerables: initial_authorities.iter().map(|x| x.1.clone()).collect(),
}),
democracy: Some(DemocracyConfig {
launch_period: 9,
voting_period: 18,
minimum_deposit: 10,
public_delay: 0,
max_lock_periods: 6,
}),
democracy: Some(DemocracyConfig::default()),
council_seats: Some(CouncilSeatsConfig {
active_council: endowed_accounts.iter()
.filter(|&endowed| initial_authorities.iter().find(|&(_, controller, _)| controller == endowed).is_none())
+2 -2
View File
@@ -38,13 +38,13 @@ mod tests {
NativeOrEncoded};
use node_primitives::{Hash, BlockNumber, AccountId};
use runtime_primitives::traits::{Header as HeaderT, Hash as HashT, Digest, DigestItem};
use runtime_primitives::{generic::{self, Era}, ApplyOutcome, ApplyError, ApplyResult, Perbill};
use runtime_primitives::{generic::Era, ApplyOutcome, ApplyError, ApplyResult, Perbill};
use {balances, indices, session, system, staking, consensus, timestamp, treasury, contract};
use contract::ContractAddressFor;
use system::{EventRecord, Phase};
use node_runtime::{Header, Block, UncheckedExtrinsic, CheckedExtrinsic, Call, Runtime, Balances,
BuildStorage, GenesisConfig, BalancesConfig, SessionConfig, StakingConfig, System,
SystemConfig, GrandpaConfig, IndicesConfig, Event, Log};
SystemConfig, GrandpaConfig, IndicesConfig, Event};
use wabt;
use primitives::map;
+16 -3
View File
@@ -21,7 +21,7 @@
#![recursion_limit="256"]
use rstd::prelude::*;
use support::construct_runtime;
use support::{construct_runtime, parameter_types};
use substrate_primitives::u32_trait::{_2, _4};
use node_primitives::{
AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, AuthorityId, Signature, AuthoritySignature
@@ -58,7 +58,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("node"),
impl_name: create_runtime_str!("substrate-node"),
authoring_version: 10,
spec_version: 89,
spec_version: 90,
impl_version: 90,
apis: RUNTIME_API_VERSIONS,
};
@@ -150,10 +150,23 @@ impl staking::Trait for Runtime {
type Reward = ();
}
const MINUTES: BlockNumber = 6;
const BUCKS: Balance = 1_000_000_000_000;
parameter_types! {
pub const LaunchPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
pub const VotingPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
pub const MinimumDeposit: Balance = 100 * BUCKS;
pub const EnactmentPeriod: BlockNumber = 30 * 24 * 60 * MINUTES;
}
impl democracy::Trait for Runtime {
type Currency = Balances;
type Proposal = Call;
type Event = Event;
type Currency = Balances;
type EnactmentPeriod = EnactmentPeriod;
type LaunchPeriod = LaunchPeriod;
type VotingPeriod = VotingPeriod;
type MinimumDeposit = MinimumDeposit;
}
impl council::Trait for Runtime {
+13 -9
View File
@@ -29,7 +29,7 @@ mod tests {
// These re-exports are here for a reason, edit with care
pub use super::*;
pub use runtime_io::with_externalities;
use srml_support::{impl_outer_origin, impl_outer_event, impl_outer_dispatch};
use srml_support::{impl_outer_origin, impl_outer_event, impl_outer_dispatch, parameter_types};
pub use substrate_primitives::H256;
pub use primitives::BuildStorage;
pub use primitives::traits::{BlakeTwo256, IdentityLookup};
@@ -81,10 +81,20 @@ mod tests {
type TransferPayment = ();
type DustRemoval = ();
}
parameter_types! {
pub const LaunchPeriod: u64 = 1;
pub const VotingPeriod: u64 = 3;
pub const MinimumDeposit: u64 = 1;
pub const EnactmentPeriod: u64 = 0;
}
impl democracy::Trait for Test {
type Currency = balances::Module<Self>;
type Proposal = Call;
type Event = Event;
type Currency = balances::Module<Self>;
type EnactmentPeriod = EnactmentPeriod;
type LaunchPeriod = LaunchPeriod;
type VotingPeriod = VotingPeriod;
type MinimumDeposit = MinimumDeposit;
}
impl seats::Trait for Test {
type Event = Event;
@@ -111,13 +121,7 @@ mod tests {
creation_fee: 0,
vesting: vec![],
}.build_storage().unwrap().0);
t.extend(democracy::GenesisConfig::<Test>{
launch_period: 1,
voting_period: 3,
minimum_deposit: 1,
public_delay: 0,
max_lock_periods: 6,
}.build_storage().unwrap().0);
t.extend(democracy::GenesisConfig::<Test>::default().build_storage().unwrap().0);
t.extend(seats::GenesisConfig::<Test> {
candidacy_bond: 9,
voter_bond: 3,
File diff suppressed because it is too large Load Diff
+33
View File
@@ -65,6 +65,39 @@ pub use self::dispatch::{Parameter, Dispatchable, Callable, IsSubType};
pub use self::double_map::StorageDoubleMapWithHasher;
pub use runtime_io::{print, storage_root};
/// Macro for easily creating a new implementation of the `Get` trait. Use similarly to
/// how you would declare a `const`:
///
/// ```no_compile
/// parameter_types! {
/// pub const Argument: u64 = 42;
/// }
/// trait Config {
/// type Parameter: Get<u64>;
/// }
/// struct Runtime;
/// impl Config for Runtime {
/// type Parameter = Argument;
/// }
/// ```
#[macro_export]
macro_rules! parameter_types {
(pub const $name:ident: $type:ty = $value:expr; $( $rest:tt )*) => (
pub struct $name;
$crate::parameter_types!{IMPL $name , $type , $value}
$crate::parameter_types!{ $( $rest )* }
);
(const $name:ident: $type:ty = $value:expr; $( $rest:tt )*) => (
struct $name;
$crate::parameter_types!{IMPL $name , $type , $value}
$crate::parameter_types!{ $( $rest )* }
);
() => ();
(IMPL $name:ident , $type:ty , $value:expr) => {
impl $crate::traits::Get<$type> for $name { fn get() -> $type { $value } }
}
}
#[doc(inline)]
pub use srml_support_procedural::decl_storage;
+3 -34
View File
@@ -14,7 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
//! Traits for SRML
//! Traits for SRML.
//!
//! NOTE: If you're looking for `parameter_types`, it has moved in to the top-level module.
use crate::rstd::result;
use crate::codec::{Codec, Encode, Decode};
@@ -28,39 +30,6 @@ pub trait Get<T> {
fn get() -> T;
}
/// Macro for easily creating a new implementation of the `Get` trait. Use similarly to
/// how you would declare a `const`:
///
/// ```no_compile
/// parameter_types! {
/// pub const Argument: u64 = 42;
/// }
/// trait Config {
/// type Parameter: Get<u64>;
/// }
/// struct Runtime;
/// impl Config for Runtime {
/// type Parameter = Argument;
/// }
/// ```
#[macro_export]
macro_rules! parameter_types {
(pub const $name:ident: $type:ty = $value:expr; $( $rest:tt )*) => (
pub struct $name;
$crate::parameter_types!{IMPL $name , $type , $value}
$crate::parameter_types!{ $( $rest )* }
);
(const $name:ident: $type:ty = $value:expr; $( $rest:tt )*) => (
struct $name;
$crate::parameter_types!{IMPL $name , $type , $value}
$crate::parameter_types!{ $( $rest )* }
);
() => ();
(IMPL $name:ident , $type:ty , $value:expr) => {
impl $crate::traits::Get<$type> for $name { fn get() -> $type { $value } }
}
}
/// The account with the given id was killed.
pub trait OnFreeBalanceZero<AccountId> {
/// The account was the given id was killed.