Enable transfers (#1443)

* Enable transfers

Also quash any conviction from Referendum Zero; Sudo was always
going to have been removed so lock-voting doesn't make sense in
this case.

* Add test for migration; remove superfluous comment.

* Fixes

* Bump

* Weekly elections
This commit is contained in:
Gavin Wood
2020-07-21 12:19:23 +02:00
committed by GitHub
parent 69da327677
commit 3f57b1c6e8
25 changed files with 152 additions and 313 deletions
+20 -20
View File
@@ -2433,7 +2433,7 @@ dependencies = [
[[package]] [[package]]
name = "kusama-runtime" name = "kusama-runtime"
version = "0.8.17" version = "0.8.18"
dependencies = [ dependencies = [
"bitvec", "bitvec",
"frame-benchmarking", "frame-benchmarking",
@@ -4313,7 +4313,7 @@ checksum = "feb3b2b1033b8a60b4da6ee470325f887758c95d5320f52f9ce0df055a55940e"
[[package]] [[package]]
name = "polkadot" name = "polkadot"
version = "0.8.17" version = "0.8.18"
dependencies = [ dependencies = [
"assert_cmd", "assert_cmd",
"futures 0.3.5", "futures 0.3.5",
@@ -4327,7 +4327,7 @@ dependencies = [
[[package]] [[package]]
name = "polkadot-availability-store" name = "polkadot-availability-store"
version = "0.8.17" version = "0.8.18"
dependencies = [ dependencies = [
"derive_more 0.99.9", "derive_more 0.99.9",
"exit-future", "exit-future",
@@ -4353,7 +4353,7 @@ dependencies = [
[[package]] [[package]]
name = "polkadot-cli" name = "polkadot-cli"
version = "0.8.17" version = "0.8.18"
dependencies = [ dependencies = [
"frame-benchmarking-cli", "frame-benchmarking-cli",
"futures 0.3.5", "futures 0.3.5",
@@ -4378,7 +4378,7 @@ dependencies = [
[[package]] [[package]]
name = "polkadot-collator" name = "polkadot-collator"
version = "0.8.17" version = "0.8.18"
dependencies = [ dependencies = [
"futures 0.3.5", "futures 0.3.5",
"futures-timer 2.0.2", "futures-timer 2.0.2",
@@ -4416,7 +4416,7 @@ dependencies = [
[[package]] [[package]]
name = "polkadot-erasure-coding" name = "polkadot-erasure-coding"
version = "0.8.17" version = "0.8.18"
dependencies = [ dependencies = [
"derive_more 0.15.0", "derive_more 0.15.0",
"parity-scale-codec", "parity-scale-codec",
@@ -4428,7 +4428,7 @@ dependencies = [
[[package]] [[package]]
name = "polkadot-network" name = "polkadot-network"
version = "0.8.17" version = "0.8.18"
dependencies = [ dependencies = [
"arrayvec 0.4.12", "arrayvec 0.4.12",
"bytes 0.5.5", "bytes 0.5.5",
@@ -4476,7 +4476,7 @@ dependencies = [
[[package]] [[package]]
name = "polkadot-network-test" name = "polkadot-network-test"
version = "0.8.17" version = "0.8.18"
dependencies = [ dependencies = [
"futures 0.3.5", "futures 0.3.5",
"log 0.4.8", "log 0.4.8",
@@ -4596,7 +4596,7 @@ dependencies = [
[[package]] [[package]]
name = "polkadot-parachain" name = "polkadot-parachain"
version = "0.8.17" version = "0.8.18"
dependencies = [ dependencies = [
"derive_more 0.99.9", "derive_more 0.99.9",
"log 0.4.8", "log 0.4.8",
@@ -4634,7 +4634,7 @@ dependencies = [
[[package]] [[package]]
name = "polkadot-primitives" name = "polkadot-primitives"
version = "0.8.17" version = "0.8.18"
dependencies = [ dependencies = [
"bitvec", "bitvec",
"frame-system", "frame-system",
@@ -4658,7 +4658,7 @@ dependencies = [
[[package]] [[package]]
name = "polkadot-rpc" name = "polkadot-rpc"
version = "0.8.17" version = "0.8.18"
dependencies = [ dependencies = [
"jsonrpc-core", "jsonrpc-core",
"pallet-transaction-payment-rpc", "pallet-transaction-payment-rpc",
@@ -4684,7 +4684,7 @@ dependencies = [
[[package]] [[package]]
name = "polkadot-runtime" name = "polkadot-runtime"
version = "0.8.17" version = "0.8.18"
dependencies = [ dependencies = [
"bitvec", "bitvec",
"frame-benchmarking", "frame-benchmarking",
@@ -4758,7 +4758,7 @@ dependencies = [
[[package]] [[package]]
name = "polkadot-runtime-common" name = "polkadot-runtime-common"
version = "0.8.17" version = "0.8.18"
dependencies = [ dependencies = [
"bitvec", "bitvec",
"frame-benchmarking", "frame-benchmarking",
@@ -4846,7 +4846,7 @@ dependencies = [
[[package]] [[package]]
name = "polkadot-service" name = "polkadot-service"
version = "0.8.17" version = "0.8.18"
dependencies = [ dependencies = [
"env_logger", "env_logger",
"frame-benchmarking", "frame-benchmarking",
@@ -4989,7 +4989,7 @@ dependencies = [
[[package]] [[package]]
name = "polkadot-statement-table" name = "polkadot-statement-table"
version = "0.8.17" version = "0.8.18"
dependencies = [ dependencies = [
"parity-scale-codec", "parity-scale-codec",
"polkadot-primitives", "polkadot-primitives",
@@ -4998,7 +4998,7 @@ dependencies = [
[[package]] [[package]]
name = "polkadot-test-runtime" name = "polkadot-test-runtime"
version = "0.8.17" version = "0.8.18"
dependencies = [ dependencies = [
"bitvec", "bitvec",
"frame-executive", "frame-executive",
@@ -5129,7 +5129,7 @@ dependencies = [
[[package]] [[package]]
name = "polkadot-validation" name = "polkadot-validation"
version = "0.8.17" version = "0.8.18"
dependencies = [ dependencies = [
"ansi_term 0.12.1", "ansi_term 0.12.1",
"bitvec", "bitvec",
@@ -8363,7 +8363,7 @@ dependencies = [
[[package]] [[package]]
name = "test-parachain-adder" name = "test-parachain-adder"
version = "0.8.17" version = "0.8.18"
dependencies = [ dependencies = [
"dlmalloc", "dlmalloc",
"parity-scale-codec", "parity-scale-codec",
@@ -8404,7 +8404,7 @@ dependencies = [
[[package]] [[package]]
name = "test-parachain-halt" name = "test-parachain-halt"
version = "0.8.17" version = "0.8.18"
dependencies = [ dependencies = [
"substrate-wasm-builder-runner 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-wasm-builder-runner 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@@ -9343,7 +9343,7 @@ dependencies = [
[[package]] [[package]]
name = "westend-runtime" name = "westend-runtime"
version = "0.8.17" version = "0.8.18"
dependencies = [ dependencies = [
"bitvec", "bitvec",
"frame-benchmarking", "frame-benchmarking",
+1 -1
View File
@@ -4,7 +4,7 @@ path = "src/main.rs"
[package] [package]
name = "polkadot" name = "polkadot"
version = "0.8.17" version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018" edition = "2018"
+1 -1
View File
@@ -1,7 +1,7 @@
[package] [package]
name = "polkadot-availability-store" name = "polkadot-availability-store"
description = "Persistent database for parachain data" description = "Persistent database for parachain data"
version = "0.8.17" version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018" edition = "2018"
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "polkadot-cli" name = "polkadot-cli"
version = "0.8.17" version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
description = "Polkadot Relay-chain Client Node" description = "Polkadot Relay-chain Client Node"
edition = "2018" edition = "2018"
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "polkadot-collator" name = "polkadot-collator"
version = "0.8.17" version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
description = "Collator node implementation" description = "Collator node implementation"
edition = "2018" edition = "2018"
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "polkadot-erasure-coding" name = "polkadot-erasure-coding"
version = "0.8.17" version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018" edition = "2018"
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "polkadot-network" name = "polkadot-network"
version = "0.8.17" version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
description = "Polkadot-specific networking protocol" description = "Polkadot-specific networking protocol"
edition = "2018" edition = "2018"
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "polkadot-network-test" name = "polkadot-network-test"
version = "0.8.17" version = "0.8.18"
license = "GPL-3.0" license = "GPL-3.0"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018" edition = "2018"
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "polkadot-parachain" name = "polkadot-parachain"
version = "0.8.17" version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
description = "Types and utilities for creating and working with parachains" description = "Types and utilities for creating and working with parachains"
edition = "2018" edition = "2018"
@@ -1,6 +1,6 @@
[package] [package]
name = "test-parachain-adder" name = "test-parachain-adder"
version = "0.8.17" version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
description = "Test parachain which adds to a number as its state transition" description = "Test parachain which adds to a number as its state transition"
edition = "2018" edition = "2018"
@@ -1,6 +1,6 @@
[package] [package]
name = "test-parachain-halt" name = "test-parachain-halt"
version = "0.8.17" version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
description = "Test parachain which executes forever" description = "Test parachain which executes forever"
edition = "2018" edition = "2018"
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "polkadot-primitives" name = "polkadot-primitives"
version = "0.8.17" version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018" edition = "2018"
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "polkadot-rpc" name = "polkadot-rpc"
version = "0.8.17" version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018" edition = "2018"
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "polkadot-runtime-common" name = "polkadot-runtime-common"
version = "0.8.17" version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018" edition = "2018"
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "kusama-runtime" name = "kusama-runtime"
version = "0.8.17" version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018" edition = "2018"
build = "build.rs" build = "build.rs"
+1 -1
View File
@@ -87,7 +87,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("kusama"), spec_name: create_runtime_str!("kusama"),
impl_name: create_runtime_str!("parity-kusama"), impl_name: create_runtime_str!("parity-kusama"),
authoring_version: 2, authoring_version: 2,
spec_version: 2017, spec_version: 2018,
impl_version: 0, impl_version: 0,
#[cfg(not(feature = "disable-runtime-api"))] #[cfg(not(feature = "disable-runtime-api"))]
apis: RUNTIME_API_VERSIONS, apis: RUNTIME_API_VERSIONS,
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "polkadot-runtime" name = "polkadot-runtime"
version = "0.8.17" version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018" edition = "2018"
build = "build.rs" build = "build.rs"
+110 -38
View File
@@ -36,18 +36,12 @@ use primitives::v0::{
AccountId, AccountIndex, Balance, BlockNumber, Hash, Nonce, Signature, Moment, AccountId, AccountIndex, Balance, BlockNumber, Hash, Nonce, Signature, Moment,
ActiveParas, AbridgedCandidateReceipt, SigningContext, ActiveParas, AbridgedCandidateReceipt, SigningContext,
}; };
use sp_runtime::{ use sp_runtime::{create_runtime_str, generic, impl_opaque_keys, ModuleId, ApplyExtrinsicResult, KeyTypeId, Percent, Permill, Perbill, transaction_validity::{
create_runtime_str, generic, impl_opaque_keys, ModuleId, TransactionValidity, TransactionSource, TransactionPriority,
ApplyExtrinsicResult, KeyTypeId, Percent, Permill, Perbill, }, curve::PiecewiseLinear, traits::{
transaction_validity::{ BlakeTwo256, Block as BlockT, OpaqueKeys, ConvertInto, IdentityLookup,
TransactionValidity, TransactionSource, TransactionPriority, Extrinsic as ExtrinsicT, SaturatedConversion, Verify,
}, }};
curve::PiecewiseLinear,
traits::{
BlakeTwo256, Block as BlockT, OpaqueKeys, ConvertInto, IdentityLookup,
Extrinsic as ExtrinsicT, SaturatedConversion, Verify,
},
};
#[cfg(feature = "runtime-benchmarks")] #[cfg(feature = "runtime-benchmarks")]
use sp_runtime::RuntimeString; use sp_runtime::RuntimeString;
use version::RuntimeVersion; use version::RuntimeVersion;
@@ -79,7 +73,6 @@ pub use parachains::Call as ParachainsCall;
/// Constant values used within the runtime. /// Constant values used within the runtime.
pub mod constants; pub mod constants;
pub mod poll;
use constants::{time::*, currency::*, fee::*}; use constants::{time::*, currency::*, fee::*};
use frame_support::traits::InstanceFilter; use frame_support::traits::InstanceFilter;
@@ -99,7 +92,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS, apis: RUNTIME_API_VERSIONS,
#[cfg(feature = "disable-runtime-api")] #[cfg(feature = "disable-runtime-api")]
apis: version::create_apis_vec![[]], apis: version::create_apis_vec![[]],
transaction_version: 3, transaction_version: 4,
}; };
/// Native version. /// Native version.
@@ -118,22 +111,19 @@ impl Filter<Call> for BaseFilter {
Call::Parachains(parachains::Call::set_heads(..)) => true, Call::Parachains(parachains::Call::set_heads(..)) => true,
// Parachains stuff // Parachains stuff
Call::Parachains(_) | Call::Attestations(_) | Call::Slots(_) | Call::Registrar(_) | Call::Parachains(_) | Call::Attestations(_) | Call::Slots(_) | Call::Registrar(_) =>
// Balances and Vesting's transfer (which can be used to transfer)
Call::Balances(_) | Call::Vesting(vesting::Call::vested_transfer(..)) |
Call::Indices(indices::Call::transfer(..)) =>
false, false,
// These modules are all allowed to be called by transactions: // These modules are all allowed to be called by transactions:
Call::Democracy(_) | Call::Council(_) | Call::TechnicalCommittee(_) | Call::Democracy(_) | Call::Council(_) | Call::TechnicalCommittee(_) |
Call::TechnicalMembership(_) | Call::Treasury(_) | Call::ElectionsPhragmen(_) | Call::TechnicalMembership(_) | Call::Treasury(_) | Call::ElectionsPhragmen(_) |
Call::System(_) | Call::Scheduler(_) | Call::Indices(_) | Call::System(_) | Call::Scheduler(_) | Call::Indices(_) |
Call::Babe(_) | Call::Timestamp(_) | Call::Babe(_) | Call::Timestamp(_) | Call::Balances(_) |
Call::Authorship(_) | Call::Staking(_) | Call::Offences(_) | Call::Authorship(_) | Call::Staking(_) | Call::Offences(_) |
Call::Session(_) | Call::FinalityTracker(_) | Call::Grandpa(_) | Call::ImOnline(_) | Call::Session(_) | Call::FinalityTracker(_) | Call::Grandpa(_) | Call::ImOnline(_) |
Call::AuthorityDiscovery(_) | Call::AuthorityDiscovery(_) |
Call::Utility(_) | Call::Claims(_) | Call::Vesting(_) | Call::Utility(_) | Call::Claims(_) | Call::Vesting(_) |
Call::Identity(_) | Call::Proxy(_) | Call::Multisig(_) | Call::Poll(_) | Call::Identity(_) | Call::Proxy(_) | Call::Multisig(_) |
Call::Purchase(_) => Call::Purchase(_) =>
true, true,
} }
@@ -486,8 +476,8 @@ impl collective::Trait<CouncilCollective> for Runtime {
parameter_types! { parameter_types! {
pub const CandidacyBond: Balance = 100 * DOLLARS; pub const CandidacyBond: Balance = 100 * DOLLARS;
pub const VotingBond: Balance = 5 * DOLLARS; pub const VotingBond: Balance = 5 * DOLLARS;
/// Daily council elections initially, later weekly and monthly. /// Weekly council elections; scaling up to monthly eventually.
pub const TermDuration: BlockNumber = 1 * DAYS; pub const TermDuration: BlockNumber = 7 * DAYS;
/// 13 members initially, to be increased to 23 eventually. /// 13 members initially, to be increased to 23 eventually.
pub const DesiredMembers: u32 = 13; pub const DesiredMembers: u32 = 13;
pub const DesiredRunnersUp: u32 = 20; pub const DesiredRunnersUp: u32 = 20;
@@ -908,7 +898,6 @@ impl InstanceFilter<Call> for ProxyType {
ProxyType::Governance => matches!(c, ProxyType::Governance => matches!(c,
Call::Democracy(..) | Call::Council(..) | Call::TechnicalCommittee(..) Call::Democracy(..) | Call::Council(..) | Call::TechnicalCommittee(..)
| Call::ElectionsPhragmen(..) | Call::Treasury(..) | Call::Utility(..) | Call::ElectionsPhragmen(..) | Call::Treasury(..) | Call::Utility(..)
| Call::Poll(..)
), ),
ProxyType::Staking => matches!(c, ProxyType::Staking => matches!(c,
Call::Staking(..) | Call::Utility(utility::Call::batch(..)) | Call::Utility(..) Call::Staking(..) | Call::Utility(utility::Call::batch(..)) | Call::Utility(..)
@@ -944,22 +933,108 @@ impl proxy::Trait for Runtime {
pub struct CustomOnRuntimeUpgrade; pub struct CustomOnRuntimeUpgrade;
impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
fn on_runtime_upgrade() -> frame_support::weights::Weight { fn on_runtime_upgrade() -> frame_support::weights::Weight {
if scheduler::Module::<Runtime>::migrate_v1_to_t2() { use frame_support::storage::{StorageMap, IterableStorageMap};
<Runtime as system::Trait>::MaximumBlockWeight::get() use democracy::{VotingOf, Conviction, Voting::Direct, AccountVote::Standard};
} else { // Cancel convictions for Referendum Zero (for removing Sudo - this is something we would
<Runtime as system::Trait>::DbWeight::get().reads(1) // have done anyway).
for (who, mut voting) in VotingOf::<Runtime>::iter() {
if let Direct { ref mut votes, .. } = voting {
if let Some((0, Standard { ref mut vote, .. })) = votes.first_mut() {
vote.conviction = Conviction::None
}
}
VotingOf::<Runtime>::insert(who, voting);
} }
<Runtime as system::Trait>::MaximumBlockWeight::get()
} }
} }
parameter_types! { #[test]
pub const PollEnd: BlockNumber = 888_888; fn test_rm_ref_0() {
} use sp_runtime::AccountId32;
use frame_support::{traits::OnRuntimeUpgrade, storage::StorageMap};
impl poll::Trait for Runtime { use democracy::{VotingOf, Vote, Voting::{Direct, Delegating}, AccountVote::{Standard, Split}};
type Event = Event; use democracy::Conviction::{Locked1x, Locked2x, Locked3x, None as NoConviction};
type Currency = Balances; let t = system::GenesisConfig::default().build_storage::<Runtime>().unwrap();
type End = PollEnd; let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| {
let a = |i| AccountId32::from([i; 32]);
VotingOf::<Runtime>::insert(a(1), Direct {
votes: vec![(0, Standard {
vote: Vote { aye: true, conviction: Locked1x },
balance: 1,
})],
delegations: Default::default(),
prior: Default::default(),
});
VotingOf::<Runtime>::insert(a(2), Direct {
votes: vec![
(0, Standard { vote: Vote { aye: true, conviction: Locked2x }, balance: 2 }),
(1, Standard { vote: Vote { aye: true, conviction: Locked2x }, balance: 2 })
],
delegations: Default::default(),
prior: Default::default(),
});
VotingOf::<Runtime>::insert(a(3), Direct {
votes: vec![(1, Standard { vote: Vote { aye: true, conviction: Locked3x }, balance: 3 })],
delegations: Default::default(),
prior: Default::default(),
});
VotingOf::<Runtime>::insert(a(4), Direct {
votes: vec![],
delegations: Default::default(),
prior: Default::default(),
});
VotingOf::<Runtime>::insert(a(5), Delegating {
balance: 5,
target: a(0),
conviction: Locked1x,
delegations: Default::default(),
prior: Default::default(),
});
VotingOf::<Runtime>::insert(a(6), Direct {
votes: vec![(0, Split { aye: 6, nay: 6 }), (1, Split { aye: 6, nay: 6 })],
delegations: Default::default(),
prior: Default::default(),
});
CustomOnRuntimeUpgrade::on_runtime_upgrade();
assert_eq!(VotingOf::<Runtime>::get(a(1)), Direct {
votes: vec![(0, Standard { vote: Vote { aye: true, conviction: NoConviction }, balance: 1, })],
delegations: Default::default(),
prior: Default::default(),
});
assert_eq!(VotingOf::<Runtime>::get(a(2)), Direct {
votes: vec![
(0, Standard { vote: Vote { aye: true, conviction: NoConviction }, balance: 2, }),
(1, Standard { vote: Vote { aye: true, conviction: Locked2x }, balance: 2, })
],
delegations: Default::default(),
prior: Default::default(),
});
assert_eq!(VotingOf::<Runtime>::get(a(3)), Direct {
votes: vec![(1, Standard { vote: Vote { aye: true, conviction: Locked3x }, balance: 3, })],
delegations: Default::default(),
prior: Default::default(),
});
assert_eq!(VotingOf::<Runtime>::get(a(4)), Direct {
votes: vec![],
delegations: Default::default(),
prior: Default::default(),
});
assert_eq!(VotingOf::<Runtime>::get(a(5)), Delegating {
balance: 5,
target: a(0),
conviction: Locked1x,
delegations: Default::default(),
prior: Default::default(),
});
assert_eq!(VotingOf::<Runtime>::get(a(6)), Direct {
votes: vec![(0, Split { aye: 6, nay: 6 }), (1, Split { aye: 6, nay: 6 })],
delegations: Default::default(),
prior: Default::default(),
});
});
} }
parameter_types! { parameter_types! {
@@ -1067,9 +1142,6 @@ construct_runtime! {
// Multisig dispatch. Late addition. // Multisig dispatch. Late addition.
Multisig: multisig::{Module, Call, Storage, Event<T>}, Multisig: multisig::{Module, Call, Storage, Event<T>},
// Poll module.
Poll: poll::{Module, Call, Storage, Event<T>},
} }
} }
-233
View File
@@ -1,233 +0,0 @@
// Copyright 2020 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//! # Simple polling module
//!
//! Note: This implementation assumes that all accounts are locked, and thus that no account balance
//! may ever reduce.
use frame_support::{
decl_module, decl_storage, decl_event, decl_error, ensure, traits::{Currency, Get},
};
use system::{self as frame_system, ensure_signed};
use sp_runtime::traits::Saturating;
pub type BalanceOf<T> =
<<T as Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::Balance;
pub trait Trait: system::Trait {
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
/// The currency type used.
type Currency: Currency<Self::AccountId>;
/// The block number only before which voting is possible.
type End: Get<Self::BlockNumber>;
}
/// The options someone has approved.
pub type Approvals = [bool; 4];
decl_storage! {
trait Store for Module<T: Trait> as Poll {
/// Votes, so far.
pub VoteOf: map hasher(twox_64_concat) T::AccountId => (Approvals, BalanceOf<T>);
/// The total balances voting for each option.
pub Totals: [BalanceOf<T>; 4];
}
}
decl_event! {
pub enum Event<T> where
<T as system::Trait>::AccountId,
Balance = BalanceOf<T>,
{
Voted(AccountId, Balance, Approvals),
}
}
decl_error! {
pub enum Error for Module<T: Trait> {
/// Vote attempted after the end of voting.
TooLate,
}
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
type Error = Error<T>;
fn deposit_event() = default;
/// The End config param.
const End: T::BlockNumber = T::End::get();
/// Cast a vote on the poll.
#[weight = 100_000_000]
fn vote(origin, approvals: Approvals) {
let who = ensure_signed(origin)?;
ensure!(system::Module::<T>::block_number() < T::End::get(), Error::<T>::TooLate);
let balance = T::Currency::total_balance(&who);
Totals::<T>::mutate(|ref mut totals| {
VoteOf::<T>::mutate(&who, |(ref mut who_approvals, ref mut who_balance)| {
for i in 0..approvals.len() {
if who_approvals[i] {
totals[i] = totals[i].saturating_sub(*who_balance);
}
if approvals[i] {
totals[i] = totals[i].saturating_add(balance);
}
}
*who_approvals = approvals;
*who_balance = balance;
});
});
Self::deposit_event(RawEvent::Voted(who, balance, approvals));
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use frame_support::{assert_ok, assert_noop, impl_outer_origin, parameter_types, weights::Weight};
use sp_core::H256;
use sp_runtime::{Perbill, testing::Header, traits::{BlakeTwo256, IdentityLookup}};
impl_outer_origin! {
pub enum Origin for Test where system = frame_system {}
}
// For testing the pallet, we construct most of a mock runtime. This means
// first constructing a configuration type (`Test`) which `impl`s each of the
// configuration traits of pallets we want to use.
#[derive(Clone, Eq, PartialEq)]
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Call = ();
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = MaximumBlockWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type ModuleToIndex = ();
type AccountData = balances::AccountData<u64>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
}
impl balances::Trait for Test {
type Balance = u64;
type Event = ();
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
}
parameter_types! {
pub const End: u64 = 1;
}
impl Trait for Test {
type Event = ();
type Currency = Balances;
type End = End;
}
type System = system::Module<Test>;
type Balances = balances::Module<Test>;
type Poll = Module<Test>;
// This function basically just builds a genesis storage key/value store according to
// our desired mockup.
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
// We use default for brevity, but you can configure as desired if needed.
balances::GenesisConfig::<Test> {
balances: vec![
(1, 10),
(2, 20),
(3, 30),
(4, 40),
],
}.assimilate_storage(&mut t).unwrap();
t.into()
}
#[test]
fn basic_setup_works() {
new_test_ext().execute_with(|| {
assert_eq!(System::block_number(), 0);
});
}
#[test]
fn totaling_works() {
new_test_ext().execute_with(|| {
assert_ok!(Poll::vote(Origin::signed(1), [true, true, false, false]));
assert_ok!(Poll::vote(Origin::signed(2), [false, true, true, false]));
assert_ok!(Poll::vote(Origin::signed(3), [false, false, true, true]));
assert_ok!(Poll::vote(Origin::signed(4), [true, false, false, true]));
assert_eq!(Totals::<Test>::get(), [50, 30, 50, 70]);
});
}
#[test]
fn revoting_works() {
new_test_ext().execute_with(|| {
assert_ok!(Poll::vote(Origin::signed(1), [true, false, false, false]));
assert_eq!(Totals::<Test>::get(), [10, 0, 0, 0]);
assert_ok!(Poll::vote(Origin::signed(1), [false, true, false, false]));
assert_eq!(Totals::<Test>::get(), [0, 10, 0, 0]);
assert_ok!(Poll::vote(Origin::signed(1), [false, false, true, true]));
assert_eq!(Totals::<Test>::get(), [0, 0, 10, 10]);
});
}
#[test]
fn vote_end_works() {
new_test_ext().execute_with(|| {
assert_ok!(Poll::vote(Origin::signed(1), [true, false, false, false]));
assert_eq!(Totals::<Test>::get(), [10, 0, 0, 0]);
system::Module::<Test>::set_block_number(1);
assert_noop!(Poll::vote(Origin::signed(1), [false, true, false, false]), Error::<Test>::TooLate);
});
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "polkadot-test-runtime" name = "polkadot-test-runtime"
version = "0.8.17" version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018" edition = "2018"
build = "build.rs" build = "build.rs"
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "westend-runtime" name = "westend-runtime"
version = "0.8.17" version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018" edition = "2018"
build = "build.rs" build = "build.rs"
+1 -1
View File
@@ -83,7 +83,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("westend"), spec_name: create_runtime_str!("westend"),
impl_name: create_runtime_str!("parity-westend"), impl_name: create_runtime_str!("parity-westend"),
authoring_version: 2, authoring_version: 2,
spec_version: 37, spec_version: 38,
impl_version: 0, impl_version: 0,
#[cfg(not(feature = "disable-runtime-api"))] #[cfg(not(feature = "disable-runtime-api"))]
apis: RUNTIME_API_VERSIONS, apis: RUNTIME_API_VERSIONS,
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "polkadot-service" name = "polkadot-service"
version = "0.8.17" version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018" edition = "2018"
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "polkadot-statement-table" name = "polkadot-statement-table"
version = "0.8.17" version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018" edition = "2018"
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "polkadot-validation" name = "polkadot-validation"
version = "0.8.17" version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018" edition = "2018"