Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed without_storage_info from pallet-collective #1445

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ where
}

fn proposal_of(proposal_hash: HashOf<T>) -> Option<ProposalOf<T, I>> {
pallet_collective::ProposalOf::<T, I>::get(proposal_hash)
pallet_collective::Pallet::<T, I>::proposal_of(&proposal_hash)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ impl pallet_collective::Config<AllianceCollective> for Runtime {
type SetMembersOrigin = EnsureRoot<AccountId>;
type WeightInfo = weights::pallet_collective::WeightInfo<Runtime>;
type MaxProposalWeight = MaxProposalWeight;
type Preimages = Preimage;
}

pub const MAX_FELLOWS: u32 = ALLIANCE_MAX_MEMBERS;
Expand Down Expand Up @@ -725,6 +726,8 @@ type Migrations = (
cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4<Runtime>,
// permanent
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
// unreleased
pallet_collective::migrations::v5::MigrateToV5<Runtime, AllianceCollective>,
);

/// Executive: handles dispatch to the various modules.
Expand Down
19 changes: 19 additions & 0 deletions prdoc/pr_1445.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: removed `without_storage_info` from `pallet-collective`

doc:
- audience: Runtime Dev
description: |
1. Voting storage is now a CountedStorageMap
2. Members storage is now bounded, avoiding runtime checks
muraca marked this conversation as resolved.
Show resolved Hide resolved
3. Proposal storage has been removed, to check if a proposal exists `Voting::<T, I>::contains_key(&hash)` should be used instead
4. Pallet Preimage has been introduced as a dependency for Collective to store proposal preimages
5. ProposalOf storage has been removed in favour of Preimage, while the function `Collective::proposal_of` was introduced facilitate proposal retrieval and decoding


crates:
- name: pallet-collective
- name: collectives-westend-runtime
- name: kitchensink-runtime
6 changes: 3 additions & 3 deletions substrate/bin/node/runtime/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ use pallet_identity::legacy::IdentityField;
use sp_std::prelude::*;

use crate::{
AccountId, AllianceCollective, AllianceMotion, Assets, Authorship, Balances, Hash,
NegativeImbalance, Runtime, RuntimeCall,
AccountId, AllianceMotion, Assets, Authorship, Balances, Hash, NegativeImbalance, Runtime,
RuntimeCall,
};

pub struct Author;
Expand Down Expand Up @@ -107,7 +107,7 @@ impl ProposalProvider<AccountId, Hash, RuntimeCall> for AllianceProposalProvider
}

fn proposal_of(proposal_hash: Hash) -> Option<RuntimeCall> {
pallet_collective::ProposalOf::<Runtime, AllianceCollective>::get(proposal_hash)
AllianceMotion::proposal_of(&proposal_hash)
}
}

Expand Down
6 changes: 6 additions & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,7 @@ impl pallet_collective::Config<CouncilCollective> for Runtime {
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = EnsureRoot<Self::AccountId>;
type MaxProposalWeight = MaxCollectivesProposalWeight;
type Preimages = Preimage;
}

parameter_types! {
Expand Down Expand Up @@ -1179,6 +1180,7 @@ impl pallet_collective::Config<TechnicalCollective> for Runtime {
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = EnsureRoot<Self::AccountId>;
type MaxProposalWeight = MaxCollectivesProposalWeight;
type Preimages = Preimage;
}

type EnsureRootOrHalfCouncil = EitherOfDiverse<
Expand Down Expand Up @@ -1941,6 +1943,7 @@ impl pallet_collective::Config<AllianceCollective> for Runtime {
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = EnsureRoot<Self::AccountId>;
type MaxProposalWeight = MaxCollectivesProposalWeight;
type Preimages = Preimage;
}

parameter_types! {
Expand Down Expand Up @@ -2497,6 +2500,9 @@ type Migrations = (
pallet_alliance::migration::Migration<Runtime>,
pallet_contracts::Migration<Runtime>,
pallet_identity::migration::versioned::V0ToV1<Runtime, IDENTITY_MIGRATION_KEY_LIMIT>,
pallet_collective::migrations::v5::MigrateToV5<Runtime, CouncilCollective>,
pallet_collective::migrations::v5::MigrateToV5<Runtime, TechnicalCollective>,
pallet_collective::migrations::v5::MigrateToV5<Runtime, AllianceCollective>,
);

type EventRecord = frame_system::EventRecord<
Expand Down
4 changes: 4 additions & 0 deletions substrate/frame/alliance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ array-bytes = "6.1"
sp-crypto-hashing = { path = "../../primitives/crypto/hashing", default-features = false }
pallet-balances = { path = "../balances" }
pallet-collective = { path = "../collective" }
pallet-preimage = { path = "../preimage" }

[features]
default = ["std"]
Expand All @@ -52,6 +53,7 @@ std = [
"pallet-balances/std",
"pallet-collective?/std",
"pallet-identity/std",
"pallet-preimage/std",
"scale-info/std",
"sp-core/std",
"sp-crypto-hashing?/std",
Expand All @@ -67,6 +69,7 @@ runtime-benchmarks = [
"pallet-balances/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"sp-crypto-hashing",
"sp-runtime/runtime-benchmarks",
]
Expand All @@ -76,5 +79,6 @@ try-runtime = [
"pallet-balances/try-runtime",
"pallet-collective?/try-runtime",
"pallet-identity/try-runtime",
"pallet-preimage/try-runtime",
"sp-runtime/try-runtime",
]
12 changes: 11 additions & 1 deletion substrate/frame/alliance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ impl pallet_collective::Config<AllianceCollective> for Test {
type WeightInfo = ();
type SetMembersOrigin = EnsureRoot<Self::AccountId>;
type MaxProposalWeight = MaxProposalWeight;
type Preimages = Preimage;
}

impl pallet_preimage::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type Currency = ();
type ManagerOrigin = EnsureRoot<Self::AccountId>;
type Consideration = ();
}

parameter_types! {
Expand Down Expand Up @@ -208,7 +217,7 @@ impl ProposalProvider<AccountId, H256, RuntimeCall> for AllianceProposalProvider
}

fn proposal_of(proposal_hash: H256) -> Option<RuntimeCall> {
pallet_collective::ProposalOf::<Test, Instance1>::get(proposal_hash)
AllianceMotion::proposal_of(&proposal_hash)
}
}

Expand Down Expand Up @@ -255,6 +264,7 @@ frame_support::construct_runtime!(
Identity: pallet_identity,
AllianceMotion: pallet_collective::<Instance1>,
Alliance: pallet_alliance,
Preimage: pallet_preimage,
}
);

Expand Down
43 changes: 24 additions & 19 deletions substrate/frame/alliance/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ fn assert_powerless(user: RuntimeOrigin, user_is_member: bool) {
);
}

fn record(event: RuntimeEvent) -> EventRecord<RuntimeEvent, H256> {
EventRecord::<RuntimeEvent, H256> { phase: Phase::Initialization, event, topics: vec![] }
}

#[test]
fn init_members_works() {
new_test_ext().execute_with(|| {
Expand Down Expand Up @@ -187,21 +191,16 @@ fn propose_works() {
Box::new(proposal.clone()),
proposal_len
));
assert_eq!(*pallet_collective::Proposals::<Test, Instance1>::get(), vec![hash]);
assert_eq!(pallet_collective::ProposalOf::<Test, Instance1>::get(&hash), Some(proposal));
assert_eq!(
System::events(),
vec![EventRecord {
phase: Phase::Initialization,
event: mock::RuntimeEvent::AllianceMotion(AllianceMotionEvent::Proposed {
account: 1,
proposal_index: 0,
proposal_hash: hash,
threshold: 3,
}),
topics: vec![],
}]
);
assert!(pallet_collective::Voting::<Test, Instance1>::contains_key(hash));
assert_eq!(AllianceMotion::proposal_of(&hash), Some(proposal));
System::assert_has_event(mock::RuntimeEvent::AllianceMotion(
AllianceMotionEvent::Proposed {
account: 1,
proposal_index: 0,
proposal_hash: hash,
threshold: 3,
},
));
});
}

Expand All @@ -217,9 +216,12 @@ fn vote_works() {
));
assert_ok!(Alliance::vote(RuntimeOrigin::signed(2), hash, 0, true));

let record = |event| EventRecord { phase: Phase::Initialization, event, topics: vec![] };
assert_eq!(
System::events(),
System::events()
.iter()
.filter(|e| matches!(e.event, RuntimeEvent::AllianceMotion(_)))
.cloned()
.collect::<Vec<_>>(),
vec![
record(mock::RuntimeEvent::AllianceMotion(AllianceMotionEvent::Proposed {
account: 1,
Expand Down Expand Up @@ -261,9 +263,12 @@ fn close_works() {
proposal_len
));

let record = |event| EventRecord { phase: Phase::Initialization, event, topics: vec![] };
assert_eq!(
System::events(),
System::events()
.iter()
.filter(|e| matches!(e.event, RuntimeEvent::AllianceMotion(_)))
.cloned()
.collect::<Vec<_>>(),
vec![
record(mock::RuntimeEvent::AllianceMotion(AllianceMotionEvent::Proposed {
account: 1,
Expand Down
6 changes: 6 additions & 0 deletions substrate/frame/collective/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ sp-io = { path = "../../primitives/io", default-features = false }
sp-runtime = { path = "../../primitives/runtime", default-features = false }
sp-std = { path = "../../primitives/std", default-features = false }

[dev-dependencies]
pallet-preimage = { path = "../preimage" }

[features]
default = ["std"]
std = [
Expand All @@ -35,6 +38,7 @@ std = [
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-preimage/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
Expand All @@ -45,10 +49,12 @@ runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-preimage/try-runtime",
"sp-runtime/try-runtime",
]
Loading
Loading