diff --git a/polkadot/Cargo.lock b/polkadot/Cargo.lock index 6ae438ece9063cb20e74f6bf7484e8345493820f..28532bb2625d9e2a4bf5e265a4d461a526593f0c 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 e0125209f2f0d6b01d73474224f9dfcc2a877f72..b7f45d5d2614cf3a4794284e51ccfa52f061d48d 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 25b39a0262973910c9b83d566201bb3e86bc39b2..48e5024e4ede189098e14d5fcb885111cca1e670 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 2847d1b1c71ca6d44250f7dd5b68b213af0e5cea..c2951cc8d5bc8af6b44fbbfc91347e6e4395db52 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 09d0112121d6bab36aa89f78202feef334c5af47..1917b203805f080711704b1cdeb9160a68546020 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 ab9b31e1512b7912ee202d9c6361e0cdaf9f6d32..2f702f37fd8161a9b416767ee87acf1207a62784 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 db5f99e714723d60653373bef8b3332e9fc9cbea..51b9de4728165bbfc4d70a4aeb195ef9fc93417a 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 b5397c46d2a2c4a6b6095f6c989a1dc0a20ac43f..239838c31a594173cfe21464235f133db27ef36c 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 b7676170b846b750ce4cddab4f1cdd3b4aded6d9..afd1110adc26cbbc81a0e6bdbb4b26063ee0e294 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 6d8f15e743c17807bc44d0266d6adcfa9ff6c779..372832c8312b4990cf94bb98e15d3251269088e0 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 1dd71cf3062daa6ae0d5caf8f818edae85904596..14acf0ecbaddff8ce30f450b94a350ff3b8fd7b9 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 96a15f68c587e812c13b0c195d94a2b27257fddb..3a8373f2e30ad44b65c430f2f88f363892098fba 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 58b300480f62a1f860455cf3a47faf6419949760..96da1db65cc71ad06afc62ac67536ab51513d2ce 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 5cf992c76f35ec81fc5d070bc3bf7378e856a74e..83ec53f44c92c58cf776395b8a9196a56566d58b 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 a8083a8a391d707a9796086c983dbc76251848a0..43526f13fdd09ecc124bc4e78bf36c76bd468ead 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 6eed529ab835ccfe8b369d8356996bf9a8f76c5d..df583ccbc91f83b925f0b720909823acf45f97ca 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 0af2fda617c7be0ffb82da09a5026153ec8d91f7..fc1c53ad2804afeb4d93d3eae877fc4991f692ef 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 56774d921bff01af7bf9e673c6501e6d2312ada9..c2a28975f1f0a757eca627bcf2357676f6ebc062 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 c2cd5518178b76d7670cd6f1c85f21dff90bcae2..0000000000000000000000000000000000000000 --- 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 9c62784bbd77af427dbc60465960fa1b550abd6f..201ba2debcb1b40803e0a8f405ecf5c69f7902e7 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 0305b48c3f8a24eb275d3edd77fe6ba72672ab06..78e74644af990d853a14522a5a16cdf1f51602b0 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 5764cbc96c1b1c9e54a965c37381be12a4c69653..1d97756952aa34556c129ae59cd6111d0d8ddc56 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 9ce1613401e17c355d58c1c044cc313b0c2a2012..13eeff889dcdee3343150cd706fb96e3006c8df8 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 870d8cb0b143c3d894238df358768f7aef52a982..9a5fd9d5726a1a4d98e05c32fe0d1131282931ad 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 aabf5286f5f01b300928ef729458c56ac69b9684..ea98e24dfcb5b478add70f162092335fd13aa705 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"