From 3f57b1c6e867a3bfddd8b344727fbb46c6d53696 Mon Sep 17 00:00:00 2001 From: Gavin Wood <gavin@parity.io> Date: Tue, 21 Jul 2020 12:19:23 +0200 Subject: [PATCH] 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 --- polkadot/Cargo.lock | 40 +-- polkadot/Cargo.toml | 2 +- polkadot/availability-store/Cargo.toml | 2 +- polkadot/cli/Cargo.toml | 2 +- polkadot/collator/Cargo.toml | 2 +- polkadot/erasure-coding/Cargo.toml | 2 +- polkadot/network/Cargo.toml | 2 +- polkadot/network/test/Cargo.toml | 2 +- polkadot/parachain/Cargo.toml | 2 +- .../test-parachains/adder/Cargo.toml | 2 +- .../parachain/test-parachains/halt/Cargo.toml | 2 +- polkadot/primitives/Cargo.toml | 2 +- polkadot/rpc/Cargo.toml | 2 +- polkadot/runtime/common/Cargo.toml | 2 +- polkadot/runtime/kusama/Cargo.toml | 2 +- polkadot/runtime/kusama/src/lib.rs | 2 +- polkadot/runtime/polkadot/Cargo.toml | 2 +- polkadot/runtime/polkadot/src/lib.rs | 148 ++++++++--- polkadot/runtime/polkadot/src/poll.rs | 233 ------------------ polkadot/runtime/test-runtime/Cargo.toml | 2 +- polkadot/runtime/westend/Cargo.toml | 2 +- polkadot/runtime/westend/src/lib.rs | 2 +- polkadot/service/Cargo.toml | 2 +- polkadot/statement-table/Cargo.toml | 2 +- polkadot/validation/Cargo.toml | 2 +- 25 files changed, 152 insertions(+), 313 deletions(-) delete mode 100644 polkadot/runtime/polkadot/src/poll.rs diff --git a/polkadot/Cargo.lock b/polkadot/Cargo.lock index 6ae438ece90..28532bb2625 100644 --- a/polkadot/Cargo.lock +++ b/polkadot/Cargo.lock @@ -2433,7 +2433,7 @@ dependencies = [ [[package]] name = "kusama-runtime" -version = "0.8.17" +version = "0.8.18" dependencies = [ "bitvec", "frame-benchmarking", @@ -4313,7 +4313,7 @@ checksum = "feb3b2b1033b8a60b4da6ee470325f887758c95d5320f52f9ce0df055a55940e" [[package]] name = "polkadot" -version = "0.8.17" +version = "0.8.18" dependencies = [ "assert_cmd", "futures 0.3.5", @@ -4327,7 +4327,7 @@ dependencies = [ [[package]] name = "polkadot-availability-store" -version = "0.8.17" +version = "0.8.18" dependencies = [ "derive_more 0.99.9", "exit-future", @@ -4353,7 +4353,7 @@ dependencies = [ [[package]] name = "polkadot-cli" -version = "0.8.17" +version = "0.8.18" dependencies = [ "frame-benchmarking-cli", "futures 0.3.5", @@ -4378,7 +4378,7 @@ dependencies = [ [[package]] name = "polkadot-collator" -version = "0.8.17" +version = "0.8.18" dependencies = [ "futures 0.3.5", "futures-timer 2.0.2", @@ -4416,7 +4416,7 @@ dependencies = [ [[package]] name = "polkadot-erasure-coding" -version = "0.8.17" +version = "0.8.18" dependencies = [ "derive_more 0.15.0", "parity-scale-codec", @@ -4428,7 +4428,7 @@ dependencies = [ [[package]] name = "polkadot-network" -version = "0.8.17" +version = "0.8.18" dependencies = [ "arrayvec 0.4.12", "bytes 0.5.5", @@ -4476,7 +4476,7 @@ dependencies = [ [[package]] name = "polkadot-network-test" -version = "0.8.17" +version = "0.8.18" dependencies = [ "futures 0.3.5", "log 0.4.8", @@ -4596,7 +4596,7 @@ dependencies = [ [[package]] name = "polkadot-parachain" -version = "0.8.17" +version = "0.8.18" dependencies = [ "derive_more 0.99.9", "log 0.4.8", @@ -4634,7 +4634,7 @@ dependencies = [ [[package]] name = "polkadot-primitives" -version = "0.8.17" +version = "0.8.18" dependencies = [ "bitvec", "frame-system", @@ -4658,7 +4658,7 @@ dependencies = [ [[package]] name = "polkadot-rpc" -version = "0.8.17" +version = "0.8.18" dependencies = [ "jsonrpc-core", "pallet-transaction-payment-rpc", @@ -4684,7 +4684,7 @@ dependencies = [ [[package]] name = "polkadot-runtime" -version = "0.8.17" +version = "0.8.18" dependencies = [ "bitvec", "frame-benchmarking", @@ -4758,7 +4758,7 @@ dependencies = [ [[package]] name = "polkadot-runtime-common" -version = "0.8.17" +version = "0.8.18" dependencies = [ "bitvec", "frame-benchmarking", @@ -4846,7 +4846,7 @@ dependencies = [ [[package]] name = "polkadot-service" -version = "0.8.17" +version = "0.8.18" dependencies = [ "env_logger", "frame-benchmarking", @@ -4989,7 +4989,7 @@ dependencies = [ [[package]] name = "polkadot-statement-table" -version = "0.8.17" +version = "0.8.18" dependencies = [ "parity-scale-codec", "polkadot-primitives", @@ -4998,7 +4998,7 @@ dependencies = [ [[package]] name = "polkadot-test-runtime" -version = "0.8.17" +version = "0.8.18" dependencies = [ "bitvec", "frame-executive", @@ -5129,7 +5129,7 @@ dependencies = [ [[package]] name = "polkadot-validation" -version = "0.8.17" +version = "0.8.18" dependencies = [ "ansi_term 0.12.1", "bitvec", @@ -8363,7 +8363,7 @@ dependencies = [ [[package]] name = "test-parachain-adder" -version = "0.8.17" +version = "0.8.18" dependencies = [ "dlmalloc", "parity-scale-codec", @@ -8404,7 +8404,7 @@ dependencies = [ [[package]] name = "test-parachain-halt" -version = "0.8.17" +version = "0.8.18" dependencies = [ "substrate-wasm-builder-runner 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -9343,7 +9343,7 @@ dependencies = [ [[package]] name = "westend-runtime" -version = "0.8.17" +version = "0.8.18" dependencies = [ "bitvec", "frame-benchmarking", diff --git a/polkadot/Cargo.toml b/polkadot/Cargo.toml index e0125209f2f..b7f45d5d261 100644 --- a/polkadot/Cargo.toml +++ b/polkadot/Cargo.toml @@ -4,7 +4,7 @@ path = "src/main.rs" [package] name = "polkadot" -version = "0.8.17" +version = "0.8.18" authors = ["Parity Technologies <admin@parity.io>"] edition = "2018" diff --git a/polkadot/availability-store/Cargo.toml b/polkadot/availability-store/Cargo.toml index 25b39a02629..48e5024e4ed 100644 --- a/polkadot/availability-store/Cargo.toml +++ b/polkadot/availability-store/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "polkadot-availability-store" description = "Persistent database for parachain data" -version = "0.8.17" +version = "0.8.18" authors = ["Parity Technologies <admin@parity.io>"] edition = "2018" diff --git a/polkadot/cli/Cargo.toml b/polkadot/cli/Cargo.toml index 2847d1b1c71..c2951cc8d5b 100644 --- a/polkadot/cli/Cargo.toml +++ b/polkadot/cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "polkadot-cli" -version = "0.8.17" +version = "0.8.18" authors = ["Parity Technologies <admin@parity.io>"] description = "Polkadot Relay-chain Client Node" edition = "2018" diff --git a/polkadot/collator/Cargo.toml b/polkadot/collator/Cargo.toml index 09d0112121d..1917b203805 100644 --- a/polkadot/collator/Cargo.toml +++ b/polkadot/collator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "polkadot-collator" -version = "0.8.17" +version = "0.8.18" authors = ["Parity Technologies <admin@parity.io>"] description = "Collator node implementation" edition = "2018" diff --git a/polkadot/erasure-coding/Cargo.toml b/polkadot/erasure-coding/Cargo.toml index ab9b31e1512..2f702f37fd8 100644 --- a/polkadot/erasure-coding/Cargo.toml +++ b/polkadot/erasure-coding/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "polkadot-erasure-coding" -version = "0.8.17" +version = "0.8.18" authors = ["Parity Technologies <admin@parity.io>"] edition = "2018" diff --git a/polkadot/network/Cargo.toml b/polkadot/network/Cargo.toml index db5f99e7147..51b9de47281 100644 --- a/polkadot/network/Cargo.toml +++ b/polkadot/network/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "polkadot-network" -version = "0.8.17" +version = "0.8.18" authors = ["Parity Technologies <admin@parity.io>"] description = "Polkadot-specific networking protocol" edition = "2018" diff --git a/polkadot/network/test/Cargo.toml b/polkadot/network/test/Cargo.toml index b5397c46d2a..239838c31a5 100644 --- a/polkadot/network/test/Cargo.toml +++ b/polkadot/network/test/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "polkadot-network-test" -version = "0.8.17" +version = "0.8.18" license = "GPL-3.0" authors = ["Parity Technologies <admin@parity.io>"] edition = "2018" diff --git a/polkadot/parachain/Cargo.toml b/polkadot/parachain/Cargo.toml index b7676170b84..afd1110adc2 100644 --- a/polkadot/parachain/Cargo.toml +++ b/polkadot/parachain/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "polkadot-parachain" -version = "0.8.17" +version = "0.8.18" authors = ["Parity Technologies <admin@parity.io>"] description = "Types and utilities for creating and working with parachains" edition = "2018" diff --git a/polkadot/parachain/test-parachains/adder/Cargo.toml b/polkadot/parachain/test-parachains/adder/Cargo.toml index 6d8f15e743c..372832c8312 100644 --- a/polkadot/parachain/test-parachains/adder/Cargo.toml +++ b/polkadot/parachain/test-parachains/adder/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "test-parachain-adder" -version = "0.8.17" +version = "0.8.18" authors = ["Parity Technologies <admin@parity.io>"] description = "Test parachain which adds to a number as its state transition" edition = "2018" diff --git a/polkadot/parachain/test-parachains/halt/Cargo.toml b/polkadot/parachain/test-parachains/halt/Cargo.toml index 1dd71cf3062..14acf0ecbad 100644 --- a/polkadot/parachain/test-parachains/halt/Cargo.toml +++ b/polkadot/parachain/test-parachains/halt/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "test-parachain-halt" -version = "0.8.17" +version = "0.8.18" authors = ["Parity Technologies <admin@parity.io>"] description = "Test parachain which executes forever" edition = "2018" diff --git a/polkadot/primitives/Cargo.toml b/polkadot/primitives/Cargo.toml index 96a15f68c58..3a8373f2e30 100644 --- a/polkadot/primitives/Cargo.toml +++ b/polkadot/primitives/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "polkadot-primitives" -version = "0.8.17" +version = "0.8.18" authors = ["Parity Technologies <admin@parity.io>"] edition = "2018" diff --git a/polkadot/rpc/Cargo.toml b/polkadot/rpc/Cargo.toml index 58b300480f6..96da1db65cc 100644 --- a/polkadot/rpc/Cargo.toml +++ b/polkadot/rpc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "polkadot-rpc" -version = "0.8.17" +version = "0.8.18" authors = ["Parity Technologies <admin@parity.io>"] edition = "2018" diff --git a/polkadot/runtime/common/Cargo.toml b/polkadot/runtime/common/Cargo.toml index 5cf992c76f3..83ec53f44c9 100644 --- a/polkadot/runtime/common/Cargo.toml +++ b/polkadot/runtime/common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "polkadot-runtime-common" -version = "0.8.17" +version = "0.8.18" authors = ["Parity Technologies <admin@parity.io>"] edition = "2018" diff --git a/polkadot/runtime/kusama/Cargo.toml b/polkadot/runtime/kusama/Cargo.toml index a8083a8a391..43526f13fdd 100644 --- a/polkadot/runtime/kusama/Cargo.toml +++ b/polkadot/runtime/kusama/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kusama-runtime" -version = "0.8.17" +version = "0.8.18" authors = ["Parity Technologies <admin@parity.io>"] edition = "2018" build = "build.rs" diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index 6eed529ab83..df583ccbc91 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -87,7 +87,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("kusama"), impl_name: create_runtime_str!("parity-kusama"), authoring_version: 2, - spec_version: 2017, + spec_version: 2018, impl_version: 0, #[cfg(not(feature = "disable-runtime-api"))] apis: RUNTIME_API_VERSIONS, diff --git a/polkadot/runtime/polkadot/Cargo.toml b/polkadot/runtime/polkadot/Cargo.toml index 0af2fda617c..fc1c53ad280 100644 --- a/polkadot/runtime/polkadot/Cargo.toml +++ b/polkadot/runtime/polkadot/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "polkadot-runtime" -version = "0.8.17" +version = "0.8.18" authors = ["Parity Technologies <admin@parity.io>"] edition = "2018" build = "build.rs" diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs index 56774d921bf..c2a28975f1f 100644 --- a/polkadot/runtime/polkadot/src/lib.rs +++ b/polkadot/runtime/polkadot/src/lib.rs @@ -36,18 +36,12 @@ use primitives::v0::{ AccountId, AccountIndex, Balance, BlockNumber, Hash, Nonce, Signature, Moment, ActiveParas, AbridgedCandidateReceipt, SigningContext, }; -use sp_runtime::{ - create_runtime_str, generic, impl_opaque_keys, ModuleId, - ApplyExtrinsicResult, KeyTypeId, Percent, Permill, Perbill, - transaction_validity::{ - TransactionValidity, TransactionSource, TransactionPriority, - }, - curve::PiecewiseLinear, - traits::{ - BlakeTwo256, Block as BlockT, OpaqueKeys, ConvertInto, IdentityLookup, - Extrinsic as ExtrinsicT, SaturatedConversion, Verify, - }, -}; +use sp_runtime::{create_runtime_str, generic, impl_opaque_keys, ModuleId, ApplyExtrinsicResult, KeyTypeId, Percent, Permill, Perbill, transaction_validity::{ + TransactionValidity, TransactionSource, TransactionPriority, +}, curve::PiecewiseLinear, traits::{ + BlakeTwo256, Block as BlockT, OpaqueKeys, ConvertInto, IdentityLookup, + Extrinsic as ExtrinsicT, SaturatedConversion, Verify, +}}; #[cfg(feature = "runtime-benchmarks")] use sp_runtime::RuntimeString; use version::RuntimeVersion; @@ -79,7 +73,6 @@ pub use parachains::Call as ParachainsCall; /// Constant values used within the runtime. pub mod constants; -pub mod poll; use constants::{time::*, currency::*, fee::*}; use frame_support::traits::InstanceFilter; @@ -99,7 +92,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, #[cfg(feature = "disable-runtime-api")] apis: version::create_apis_vec![[]], - transaction_version: 3, + transaction_version: 4, }; /// Native version. @@ -118,22 +111,19 @@ impl Filter<Call> for BaseFilter { Call::Parachains(parachains::Call::set_heads(..)) => true, // Parachains stuff - 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(..)) => + Call::Parachains(_) | Call::Attestations(_) | Call::Slots(_) | Call::Registrar(_) => false, // These modules are all allowed to be called by transactions: Call::Democracy(_) | Call::Council(_) | Call::TechnicalCommittee(_) | Call::TechnicalMembership(_) | Call::Treasury(_) | Call::ElectionsPhragmen(_) | Call::System(_) | Call::Scheduler(_) | Call::Indices(_) | - Call::Babe(_) | Call::Timestamp(_) | + Call::Babe(_) | Call::Timestamp(_) | Call::Balances(_) | Call::Authorship(_) | Call::Staking(_) | Call::Offences(_) | Call::Session(_) | Call::FinalityTracker(_) | Call::Grandpa(_) | Call::ImOnline(_) | Call::AuthorityDiscovery(_) | Call::Utility(_) | Call::Claims(_) | Call::Vesting(_) | - Call::Identity(_) | Call::Proxy(_) | Call::Multisig(_) | Call::Poll(_) | + Call::Identity(_) | Call::Proxy(_) | Call::Multisig(_) | Call::Purchase(_) => true, } @@ -486,8 +476,8 @@ impl collective::Trait<CouncilCollective> for Runtime { parameter_types! { pub const CandidacyBond: Balance = 100 * DOLLARS; pub const VotingBond: Balance = 5 * DOLLARS; - /// Daily council elections initially, later weekly and monthly. - pub const TermDuration: BlockNumber = 1 * DAYS; + /// Weekly council elections; scaling up to monthly eventually. + pub const TermDuration: BlockNumber = 7 * DAYS; /// 13 members initially, to be increased to 23 eventually. pub const DesiredMembers: u32 = 13; pub const DesiredRunnersUp: u32 = 20; @@ -908,7 +898,6 @@ impl InstanceFilter<Call> for ProxyType { ProxyType::Governance => matches!(c, Call::Democracy(..) | Call::Council(..) | Call::TechnicalCommittee(..) | Call::ElectionsPhragmen(..) | Call::Treasury(..) | Call::Utility(..) - | Call::Poll(..) ), ProxyType::Staking => matches!(c, Call::Staking(..) | Call::Utility(utility::Call::batch(..)) | Call::Utility(..) @@ -944,22 +933,108 @@ impl proxy::Trait for Runtime { pub struct CustomOnRuntimeUpgrade; impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { fn on_runtime_upgrade() -> frame_support::weights::Weight { - if scheduler::Module::<Runtime>::migrate_v1_to_t2() { - <Runtime as system::Trait>::MaximumBlockWeight::get() - } else { - <Runtime as system::Trait>::DbWeight::get().reads(1) + use frame_support::storage::{StorageMap, IterableStorageMap}; + use democracy::{VotingOf, Conviction, Voting::Direct, AccountVote::Standard}; + // Cancel convictions for Referendum Zero (for removing Sudo - this is something we would + // 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); } - } -} -parameter_types! { - pub const PollEnd: BlockNumber = 888_888; + <Runtime as system::Trait>::MaximumBlockWeight::get() + } } -impl poll::Trait for Runtime { - type Event = Event; - type Currency = Balances; - type End = PollEnd; +#[test] +fn test_rm_ref_0() { + use sp_runtime::AccountId32; + use frame_support::{traits::OnRuntimeUpgrade, storage::StorageMap}; + use democracy::{VotingOf, Vote, Voting::{Direct, Delegating}, AccountVote::{Standard, Split}}; + use democracy::Conviction::{Locked1x, Locked2x, Locked3x, None as NoConviction}; + let t = system::GenesisConfig::default().build_storage::<Runtime>().unwrap(); + 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! { @@ -1067,9 +1142,6 @@ construct_runtime! { // Multisig dispatch. Late addition. Multisig: multisig::{Module, Call, Storage, Event<T>}, - - // Poll module. - Poll: poll::{Module, Call, Storage, Event<T>}, } } diff --git a/polkadot/runtime/polkadot/src/poll.rs b/polkadot/runtime/polkadot/src/poll.rs deleted file mode 100644 index c2cd5518178..00000000000 --- a/polkadot/runtime/polkadot/src/poll.rs +++ /dev/null @@ -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); - }); - } -} diff --git a/polkadot/runtime/test-runtime/Cargo.toml b/polkadot/runtime/test-runtime/Cargo.toml index 9c62784bbd7..201ba2debcb 100644 --- a/polkadot/runtime/test-runtime/Cargo.toml +++ b/polkadot/runtime/test-runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "polkadot-test-runtime" -version = "0.8.17" +version = "0.8.18" authors = ["Parity Technologies <admin@parity.io>"] edition = "2018" build = "build.rs" diff --git a/polkadot/runtime/westend/Cargo.toml b/polkadot/runtime/westend/Cargo.toml index 0305b48c3f8..78e74644af9 100644 --- a/polkadot/runtime/westend/Cargo.toml +++ b/polkadot/runtime/westend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "westend-runtime" -version = "0.8.17" +version = "0.8.18" authors = ["Parity Technologies <admin@parity.io>"] edition = "2018" build = "build.rs" diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 5764cbc96c1..1d97756952a 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -83,7 +83,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("westend"), impl_name: create_runtime_str!("parity-westend"), authoring_version: 2, - spec_version: 37, + spec_version: 38, impl_version: 0, #[cfg(not(feature = "disable-runtime-api"))] apis: RUNTIME_API_VERSIONS, diff --git a/polkadot/service/Cargo.toml b/polkadot/service/Cargo.toml index 9ce1613401e..13eeff889dc 100644 --- a/polkadot/service/Cargo.toml +++ b/polkadot/service/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "polkadot-service" -version = "0.8.17" +version = "0.8.18" authors = ["Parity Technologies <admin@parity.io>"] edition = "2018" diff --git a/polkadot/statement-table/Cargo.toml b/polkadot/statement-table/Cargo.toml index 870d8cb0b14..9a5fd9d5726 100644 --- a/polkadot/statement-table/Cargo.toml +++ b/polkadot/statement-table/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "polkadot-statement-table" -version = "0.8.17" +version = "0.8.18" authors = ["Parity Technologies <admin@parity.io>"] edition = "2018" diff --git a/polkadot/validation/Cargo.toml b/polkadot/validation/Cargo.toml index aabf5286f5f..ea98e24dfcb 100644 --- a/polkadot/validation/Cargo.toml +++ b/polkadot/validation/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "polkadot-validation" -version = "0.8.17" +version = "0.8.18" authors = ["Parity Technologies <admin@parity.io>"] edition = "2018" -- GitLab