Unverified Commit b481d6c0 authored by Gavin Wood's avatar Gavin Wood Committed by GitHub
Browse files

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
parent 1c606b1c
Pipeline #101169 passed with stages
in 25 minutes and 59 seconds
......@@ -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",
......
......@@ -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"
......
[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"
......
[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"
......
[package]
name = "polkadot-collator"
version = "0.8.17"
version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Collator node implementation"
edition = "2018"
......
[package]
name = "polkadot-erasure-coding"
version = "0.8.17"
version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
......
[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"
......
[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"
......
[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"
......
[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"
......
[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"
......
[package]
name = "polkadot-primitives"
version = "0.8.17"
version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
......
[package]
name = "polkadot-rpc"
version = "0.8.17"
version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
......
[package]
name = "polkadot-runtime-common"
version = "0.8.17"
version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
......
[package]
name = "kusama-runtime"
version = "0.8.17"
version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
build = "build.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,
......
[package]
name = "polkadot-runtime"
version = "0.8.17"
version = "0.8.18"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
build = "build.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>},
}
}
......
// 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() {