From 4d31f8159dd5af817997d3fb8c992e2ffbd7b355 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Tue, 8 Sep 2020 15:10:28 +0200 Subject: [PATCH] Remove Purchase Pallet from Polkadot + Westend (#1636) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove purchase pallet * Update runtime/common/src/purchase.rs Co-authored-by: Bastian Köcher * Actually check and fix compile * Add events to dummy * Fix kusama too * remove events where it did not exist historically Co-authored-by: Bastian Köcher --- polkadot/runtime/common/src/dummy.rs | 14 +- polkadot/runtime/common/src/purchase.rs | 50 +++++++ polkadot/runtime/kusama/src/lib.rs | 8 +- polkadot/runtime/polkadot/src/lib.rs | 166 ++---------------------- polkadot/runtime/westend/src/lib.rs | 67 +++------- 5 files changed, 101 insertions(+), 204 deletions(-) diff --git a/polkadot/runtime/common/src/dummy.rs b/polkadot/runtime/common/src/dummy.rs index 73f5392065..21908b0cb1 100644 --- a/polkadot/runtime/common/src/dummy.rs +++ b/polkadot/runtime/common/src/dummy.rs @@ -16,9 +16,11 @@ //! A dummy module for holding place of modules in a runtime. -use frame_support::{decl_module, decl_storage}; +use frame_support::{decl_module, decl_storage, decl_event}; -pub trait Trait: frame_system::Trait { } +pub trait Trait: frame_system::Trait { + type Event: Into<::Event>; +} decl_module! { pub struct Module, I: Instance = DefaultInstance> for enum Call where origin: T::Origin { @@ -28,3 +30,11 @@ decl_module! { decl_storage! { trait Store for Module, I: Instance = DefaultInstance> as Dummy { } } + +decl_event!{ + pub enum Event where + ::AccountId + { + Dummy(AccountId), + } +} diff --git a/polkadot/runtime/common/src/purchase.rs b/polkadot/runtime/common/src/purchase.rs index 8818649345..1944d29527 100644 --- a/polkadot/runtime/common/src/purchase.rs +++ b/polkadot/runtime/common/src/purchase.rs @@ -371,6 +371,20 @@ fn account_to_bytes(account: &AccountId) -> Result<[u8; 32], Dispatch Ok(bytes) } +/// WARNING: Executing this function will clear all storage used by this pallet. +/// Be sure this is what you want... +pub fn remove_pallet() -> frame_support::weights::Weight + where T: frame_system::Trait +{ + use frame_support::migration::remove_storage_prefix; + remove_storage_prefix(b"Purchase", b"Accounts", b""); + remove_storage_prefix(b"Purchase", b"PaymentAccount", b""); + remove_storage_prefix(b"Purchase", b"Statement", b""); + remove_storage_prefix(b"Purchase", b"UnlockBlock", b""); + + T::MaximumBlockWeight::get() +} + #[cfg(test)] mod tests { use super::*; @@ -1011,4 +1025,40 @@ mod tests { ), BalancesError::::InsufficientBalance); }); } + + #[test] + fn remove_pallet_works() { + new_test_ext().execute_with(|| { + let account_status = AccountStatus { + validity: AccountValidity::Completed, + free_balance: 1234, + locked_balance: 4321, + signature: b"my signature".to_vec(), + vat: Permill::from_percent(50), + }; + + // Add some storage. + Accounts::::insert(alice(), account_status.clone()); + Accounts::::insert(bob(), account_status); + PaymentAccount::::put(alice()); + Statement::put(b"hello, world!".to_vec()); + UnlockBlock::::put(4); + + // Verify storage exists. + assert_eq!(Accounts::::iter().count(), 2); + assert!(PaymentAccount::::exists()); + assert!(Statement::exists()); + assert!(UnlockBlock::::exists()); + + // Remove storage. + remove_pallet::(); + + // Verify storage is gone. + assert_eq!(Accounts::::iter().count(), 0); + assert!(!PaymentAccount::::exists()); + assert!(!Statement::exists()); + assert!(!UnlockBlock::::exists()); + + }); + } } diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index 9b5c68e65b..0200c9d1ff 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -761,7 +761,9 @@ parameter_types! { pub const MaxPending: u16 = 32; } -impl dummy::Trait for Runtime { } +impl dummy::Trait for Runtime { + type Event = Event; +} /// The type used to represent the kinds of proxying allowed. #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug)] @@ -915,8 +917,8 @@ construct_runtime! { // Old parachains stuff. All dummies to avoid messing up the transaction indices. DummyParachains: dummy::::{Module, Call}, DummyAttestations: dummy::::{Module, Call}, - DummySlots: dummy::::{Module, Call}, - DummyRegistrar: dummy::::{Module, Call}, + DummySlots: dummy::::{Module, Call, Event}, + DummyRegistrar: dummy::::{Module, Call, Event}, // Utility module. Utility: pallet_utility::{Module, Call, Event}, diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs index e53ef2f472..663e5354e3 100644 --- a/polkadot/runtime/polkadot/src/lib.rs +++ b/polkadot/runtime/polkadot/src/lib.rs @@ -50,11 +50,11 @@ use sp_version::NativeVersion; use sp_core::OpaqueMetadata; use sp_staking::SessionIndex; use frame_support::{ - parameter_types, ord_parameter_types, construct_runtime, debug, RuntimeDebug, + parameter_types, construct_runtime, debug, RuntimeDebug, traits::{KeyOwnerProofSystem, SplitTwoWays, Randomness, LockIdentifier, Filter}, weights::Weight, }; -use frame_system::{EnsureRoot, EnsureOneOf, EnsureSignedBy}; +use frame_system::{EnsureRoot, EnsureOneOf}; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo; @@ -109,7 +109,8 @@ impl Filter for BaseFilter { fn filter(call: &Call) -> bool { match call { // Parachains stuff - Call::DummyParachains(_) | Call::DummyAttestations(_) | Call::DummySlots(_) | Call::DummyRegistrar(_) => + Call::DummyParachains(_) | Call::DummyAttestations(_) | Call::DummySlots(_) | Call::DummyRegistrar(_) | + Call::DummyPurchase(_) => false, // These modules are all allowed to be called by transactions: @@ -121,9 +122,8 @@ impl Filter for BaseFilter { Call::Session(_) | Call::FinalityTracker(_) | Call::Grandpa(_) | Call::ImOnline(_) | Call::AuthorityDiscovery(_) | Call::Utility(_) | Call::Claims(_) | Call::Vesting(_) | - Call::Identity(_) | Call::Proxy(_) | Call::Multisig(_) | - Call::Purchase(_) => - true, + Call::Identity(_) | Call::Proxy(_) | Call::Multisig(_) + => true, } } } @@ -750,7 +750,9 @@ parameter_types! { pub const MaxPending: u16 = 32; } -impl dummy::Trait for Runtime { } +impl dummy::Trait for Runtime { + type Event = Event; +} /// The type used to represent the kinds of proxying allowed. #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug)] @@ -876,150 +878,10 @@ impl pallet_proxy::Trait for Runtime { pub struct CustomOnRuntimeUpgrade; impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { fn on_runtime_upgrade() -> frame_support::weights::Weight { - use frame_support::storage::{StorageMap, IterableStorageMap}; - use pallet_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::::iter() { - if let Direct { ref mut votes, .. } = voting { - if let Some((0, Standard { ref mut vote, .. })) = votes.first_mut() { - vote.conviction = Conviction::None - } - } - VotingOf::::insert(who, voting); - } - - ::MaximumBlockWeight::get() + purchase::remove_pallet::() } } -#[test] -fn test_rm_ref_0() { - use sp_runtime::AccountId32; - use frame_support::{traits::OnRuntimeUpgrade, storage::StorageMap}; - use pallet_democracy::{VotingOf, Vote, Voting::{Direct, Delegating}, AccountVote::{Standard, Split}}; - use pallet_democracy::Conviction::{Locked1x, Locked2x, Locked3x, None as NoConviction}; - let t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| { - let a = |i| AccountId32::from([i; 32]); - VotingOf::::insert(a(1), Direct { - votes: vec![(0, Standard { - vote: Vote { aye: true, conviction: Locked1x }, - balance: 1, - })], - delegations: Default::default(), - prior: Default::default(), - }); - VotingOf::::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::::insert(a(3), Direct { - votes: vec![(1, Standard { vote: Vote { aye: true, conviction: Locked3x }, balance: 3 })], - delegations: Default::default(), - prior: Default::default(), - }); - VotingOf::::insert(a(4), Direct { - votes: vec![], - delegations: Default::default(), - prior: Default::default(), - }); - VotingOf::::insert(a(5), Delegating { - balance: 5, - target: a(0), - conviction: Locked1x, - delegations: Default::default(), - prior: Default::default(), - }); - VotingOf::::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::::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::::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::::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::::get(a(4)), Direct { - votes: vec![], - delegations: Default::default(), - prior: Default::default(), - }); - assert_eq!(VotingOf::::get(a(5)), Delegating { - balance: 5, - target: a(0), - conviction: Locked1x, - delegations: Default::default(), - prior: Default::default(), - }); - assert_eq!(VotingOf::::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! { - pub const MaxStatementLength: usize = 1_000; - pub const UnlockedProportion: Permill = Permill::zero(); - pub const MaxUnlocked: Balance = 0; -} - -ord_parameter_types! { - pub const W3FValidity: AccountId = AccountId::from( - // 142wAF65SK7PxhyzzrWz5m5PXDtooehgePBd7rc2NWpfc8Wa - hex_literal::hex!("862e432e0cf75693899c62691ac0f48967f815add97ae85659dcde8332708551") - ); - pub const W3FConfiguration: AccountId = AccountId::from( - // 1KvKReVmUiTc2LW2a4qyHsaJJ9eE9LRsywZkMk5hyBeyHgw - hex_literal::hex!("0e6de68b13b82479fbe988ab9ecb16bad446b67b993cdd9198cd41c7c6259c49") - ); -} - -type ValidityOrigin = EnsureOneOf< - AccountId, - EnsureRoot, - EnsureSignedBy, ->; - -type ConfigurationOrigin = EnsureOneOf< - AccountId, - EnsureRoot, - EnsureSignedBy, ->; - -impl purchase::Trait for Runtime { - type Event = Event; - type Currency = Balances; - type VestingSchedule = Vesting; - type ValidityOrigin = ValidityOrigin; - type ConfigurationOrigin = ConfigurationOrigin; - type MaxStatementLength = MaxStatementLength; - type UnlockedProportion = UnlockedProportion; - type MaxUnlocked = MaxUnlocked; -} - construct_runtime! { pub enum Runtime where Block = Block, @@ -1061,8 +923,8 @@ construct_runtime! { // Old parachains stuff. All dummies to avoid messing up the transaction indices. DummyParachains: dummy::::{Module, Call}, DummyAttestations: dummy::::{Module, Call}, - DummySlots: dummy::::{Module, Call}, - DummyRegistrar: dummy::::{Module, Call}, + DummySlots: dummy::::{Module, Call, Event}, + DummyRegistrar: dummy::::{Module, Call, Event}, // Claims. Usable initially. Claims: claims::{Module, Call, Storage, Event, Config, ValidateUnsigned}, @@ -1071,8 +933,8 @@ construct_runtime! { // Cunning utilities. Usable initially. Utility: pallet_utility::{Module, Call, Event}, - // DOT Purchase module. Late addition; this is in place of Sudo. - Purchase: purchase::{Module, Call, Storage, Event}, + // Old spot for the purchase pallet. Can be replaced later by a new pallet. + DummyPurchase: dummy::::{Module, Call, Event}, // Identity. Late addition. Identity: pallet_identity::{Module, Call, Storage, Event}, diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 0581eb4ece..687324fa77 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -35,7 +35,7 @@ use runtime_common::{ }; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, - ApplyExtrinsicResult, KeyTypeId, Permill, Perbill, curve::PiecewiseLinear, + ApplyExtrinsicResult, KeyTypeId, Perbill, curve::PiecewiseLinear, transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority}, traits::{ BlakeTwo256, Block as BlockT, OpaqueKeys, ConvertInto, IdentityLookup, @@ -51,7 +51,7 @@ use sp_version::NativeVersion; use sp_core::OpaqueMetadata; use sp_staking::SessionIndex; use frame_support::{ - parameter_types, ord_parameter_types, construct_runtime, debug, RuntimeDebug, + parameter_types, construct_runtime, debug, RuntimeDebug, traits::{KeyOwnerProofSystem, Randomness, Filter, InstanceFilter}, weights::Weight, }; @@ -59,7 +59,7 @@ use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo; use pallet_session::historical as session_historical; -use frame_system::{EnsureRoot, EnsureSignedBy, EnsureOneOf}; +use frame_system::{EnsureRoot}; #[cfg(feature = "std")] pub use pallet_staking::StakerStatus; @@ -639,48 +639,10 @@ impl pallet_proxy::Trait for Runtime { type AnnouncementDepositFactor = AnnouncementDepositFactor; } -parameter_types! { - pub const MaxStatementLength: usize = 1_000; - pub const UnlockedProportion: Permill = Permill::zero(); - pub const MaxUnlocked: Balance = 0; -} - -ord_parameter_types! { - pub const PurchaseValidity: AccountId = AccountId::from( - // 5CqSB6zNHcp3mvTAyh5Vr2MbSdb7DgLi9yWoAppHRveGcYQh - hex_literal::hex!("221d409ba60508368d4448ccda40182aca2744bcdfa0881944c08108a9fd966d") - ); - pub const PurchaseConfiguration: AccountId = AccountId::from( - // 5FUP4BwQzi8F5WBTmaHsoobGbMSUTiX7Exwb7QzTjgNQypo1 - hex_literal::hex!("96c34c8c60b3690701176bdbc9b16aced2898d754385a84ee0cfe7fb015db800") - ); -} - -type ValidityOrigin = EnsureOneOf< - AccountId, - EnsureRoot, - EnsureSignedBy, ->; - -type ConfigurationOrigin = EnsureOneOf< - AccountId, - EnsureRoot, - EnsureSignedBy, ->; - -impl purchase::Trait for Runtime { +impl dummy::Trait for Runtime { type Event = Event; - type Currency = Balances; - type VestingSchedule = Vesting; - type ValidityOrigin = ValidityOrigin; - type ConfigurationOrigin = ConfigurationOrigin; - type MaxStatementLength = MaxStatementLength; - type UnlockedProportion = UnlockedProportion; - type MaxUnlocked = MaxUnlocked; } -impl dummy::Trait for Runtime { } - construct_runtime! { pub enum Runtime where Block = Block, @@ -713,7 +675,7 @@ construct_runtime! { // Old Parachains stuff. All dummies to avoid messing up the transaction indices. DummyParachains: dummy::::{Module, Call}, DummyAttestations: dummy::::{Module, Call}, - DummyRegistrar: dummy::::{Module, Call}, + DummyRegistrar: dummy::::{Module, Call, Event}, // Utility module. Utility: pallet_utility::{Module, Call, Event}, @@ -738,9 +700,6 @@ construct_runtime! { // Multisig module. Late addition. Multisig: pallet_multisig::{Module, Call, Storage, Event}, - - // Purchase module. Late addition. - Purchase: purchase::{Module, Call, Storage, Event}, } } @@ -769,10 +728,24 @@ pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; /// Executive: handles dispatch to the various modules. -pub type Executive = frame_executive::Executive, Runtime, AllModules>; +pub type Executive = frame_executive::Executive< + Runtime, + Block, + frame_system::ChainContext, + Runtime, + AllModules, + CustomOnRuntimeUpgrade, +>; /// The payload being signed in transactions. pub type SignedPayload = generic::SignedPayload; +pub struct CustomOnRuntimeUpgrade; +impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { + fn on_runtime_upgrade() -> frame_support::weights::Weight { + purchase::remove_pallet::() + } +} + #[cfg(not(feature = "disable-runtime-api"))] sp_api::impl_runtime_apis! { impl sp_api::Core for Runtime {