Skip to content

Commit

Permalink
Collective: dynamic deposit based on number of proposals (#3151)
Browse files Browse the repository at this point in the history
Introduce a dynamic proposal deposit mechanism influenced by the total
number of active proposals, with the option to set the deposit to none.

The potential cost (e.g., balance hold) for proposal submission and
storage is determined by the implementation of the `Consideration`
trait. The footprint is defined as `proposal_count`, representing the
total number of active proposals in the system, excluding the one
currently being proposed. This cost may vary based on the proposal
count. The pallet also offers various types to define a cost strategy
based on the number of proposals.

Two new calls are introduced:
- kill(origin, proposal_hash): the cancellation of a proposal,
accompanied by the burning of the associated cost/consideration ticket.
- release_proposal_cost(origin, proposal_hash): the release of the cost
for a non-active proposal.

Additionally change: 
- benchmarks have been upgraded to benchmarks::v2 for collective pallet;
- `ensure_successful` function added to the `Consideration` under
`runtime-benchmarks` feature.

---------

Co-authored-by: command-bot <>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
3 people authored Sep 4, 2024
1 parent db41fab commit cc3b7bb
Show file tree
Hide file tree
Showing 13 changed files with 1,402 additions and 426 deletions.
2 changes: 2 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 @@ -552,6 +552,9 @@ impl pallet_collective::Config<AllianceCollective> for Runtime {
type SetMembersOrigin = EnsureRoot<AccountId>;
type WeightInfo = weights::pallet_collective::WeightInfo<Runtime>;
type MaxProposalWeight = MaxProposalWeight;
type DisapproveOrigin = EnsureRoot<Self::AccountId>;
type KillOrigin = EnsureRoot<Self::AccountId>;
type Consideration = ();
}

pub const MAX_FELLOWS: u32 = ALLIANCE_MAX_MEMBERS;
Expand Down

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions prdoc/pr_3151.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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: Dynamic deposit based on number of proposals

doc:
- audience:
- Runtime User
- Runtime Dev
description: |
Introduce a dynamic proposal deposit mechanism influenced by the total number of active
proposals, with the option to set the deposit to none.

The potential cost (e.g., balance hold) for proposal submission and storage is determined
by the implementation of the `Consideration` trait. The footprint is defined as `proposal_count`,
representing the total number of active proposals in the system, excluding the one currently
being proposed. This cost may vary based on the proposal count. The pallet also offers various
types to define a cost strategy based on the number of proposals.

Two new calls are introduced:
- kill(origin, proposal_hash): the cancellation of a proposal, accompanied by the burning
of the associated cost/consideration ticket.
- release_proposal_cost(origin, proposal_hash): the release of the cost for a non-active proposal.

New config parameters:
- DisapproveOrigin: origin from which a proposal in any status may be disapproved without
associated cost for a proposer;
- KillOrigin: Origin from which any malicious proposal may be killed with associated cost
for a proposer;
- Consideration: mechanism to assess the necessity of some cost for publishing and storing
a proposal. Set to unit type to have not submission cost;

Additionally change:
- benchmarks have been upgraded to benchmarks::v2 for collective pallet;
- `ensure_successful` function added to the `Consideration` under `runtime-benchmarks` feature.

crates:
- name: pallet-collective
bump: major
- name: collectives-westend-runtime
bump: major
- name: kitchensink-runtime
bump: major
- name: pallet-alliance
bump: patch
- name: pallet-balances
bump: patch
- name: pallet-utility
bump: patch
21 changes: 21 additions & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,9 @@ parameter_types! {
pub const CouncilMotionDuration: BlockNumber = 5 * DAYS;
pub const CouncilMaxProposals: u32 = 100;
pub const CouncilMaxMembers: u32 = 100;
pub const ProposalDepositOffset: Balance = ExistentialDeposit::get() + ExistentialDeposit::get();
pub const ProposalHoldReason: RuntimeHoldReason =
RuntimeHoldReason::Council(pallet_collective::HoldReason::ProposalSubmission);
}

type CouncilCollective = pallet_collective::Instance1;
Expand All @@ -1128,6 +1131,18 @@ impl pallet_collective::Config<CouncilCollective> for Runtime {
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = EnsureRoot<Self::AccountId>;
type MaxProposalWeight = MaxCollectivesProposalWeight;
type DisapproveOrigin = EnsureRoot<Self::AccountId>;
type KillOrigin = EnsureRoot<Self::AccountId>;
type Consideration = HoldConsideration<
AccountId,
Balances,
ProposalHoldReason,
pallet_collective::deposit::Delayed<
ConstU32<2>,
pallet_collective::deposit::Linear<ConstU32<2>, ProposalDepositOffset>,
>,
u32,
>;
}

parameter_types! {
Expand Down Expand Up @@ -1189,6 +1204,9 @@ impl pallet_collective::Config<TechnicalCollective> for Runtime {
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = EnsureRoot<Self::AccountId>;
type MaxProposalWeight = MaxCollectivesProposalWeight;
type DisapproveOrigin = EnsureRoot<Self::AccountId>;
type KillOrigin = EnsureRoot<Self::AccountId>;
type Consideration = ();
}

type EnsureRootOrHalfCouncil = EitherOfDiverse<
Expand Down Expand Up @@ -2027,6 +2045,9 @@ impl pallet_collective::Config<AllianceCollective> for Runtime {
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = EnsureRoot<Self::AccountId>;
type MaxProposalWeight = MaxCollectivesProposalWeight;
type DisapproveOrigin = EnsureRoot<Self::AccountId>;
type KillOrigin = EnsureRoot<Self::AccountId>;
type Consideration = ();
}

parameter_types! {
Expand Down
3 changes: 3 additions & 0 deletions substrate/frame/alliance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ impl pallet_collective::Config<AllianceCollective> for Test {
type WeightInfo = ();
type SetMembersOrigin = EnsureRoot<Self::AccountId>;
type MaxProposalWeight = MaxProposalWeight;
type DisapproveOrigin = EnsureRoot<Self::AccountId>;
type KillOrigin = EnsureRoot<Self::AccountId>;
type Consideration = ();
}

parameter_types! {
Expand Down
13 changes: 6 additions & 7 deletions substrate/frame/balances/src/tests/fungible_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,9 @@ fn freeze_consideration_works() {
let who = 4;
// freeze amount taken somewhere outside of our (Consideration) scope.
let extend_freeze = 15;
let zero_ticket = Consideration::new(&who, Footprint::from_parts(0, 0)).unwrap();
assert!(zero_ticket.is_none());

let ticket = Consideration::new(&who, Footprint::from_parts(0, 0)).unwrap();
assert!(ticket.is_none());
assert_eq!(Balances::balance_frozen(&TestId::Foo, &who), 0);

let ticket = Consideration::new(&who, Footprint::from_parts(10, 1)).unwrap();
Expand All @@ -536,7 +537,6 @@ fn freeze_consideration_works() {

let ticket = ticket.update(&who, Footprint::from_parts(0, 0)).unwrap();
assert!(ticket.is_none());
assert_eq!(ticket, zero_ticket);
assert_eq!(Balances::balance_frozen(&TestId::Foo, &who), 0 + extend_freeze);

let ticket = Consideration::new(&who, Footprint::from_parts(10, 1)).unwrap();
Expand Down Expand Up @@ -565,11 +565,11 @@ fn hold_consideration_works() {
// hold amount taken somewhere outside of our (Consideration) scope.
let extend_hold = 15;

let zero_ticket = Consideration::new(&who, Footprint::from_parts(0, 0)).unwrap();
assert!(zero_ticket.is_none());
let ticket = Consideration::new(&who, Footprint::from_parts(0, 0)).unwrap();
assert!(ticket.is_none());
assert_eq!(Balances::balance_on_hold(&TestId::Foo, &who), 0);

let ticket = Consideration::new(&who, Footprint::from_parts(10, 1)).unwrap();
let ticket = ticket.update(&who, Footprint::from_parts(10, 1)).unwrap();
assert_eq!(Balances::balance_on_hold(&TestId::Foo, &who), 10);

let ticket = ticket.update(&who, Footprint::from_parts(4, 1)).unwrap();
Expand All @@ -583,7 +583,6 @@ fn hold_consideration_works() {

let ticket = ticket.update(&who, Footprint::from_parts(0, 0)).unwrap();
assert!(ticket.is_none());
assert_eq!(ticket, zero_ticket);
assert_eq!(Balances::balance_on_hold(&TestId::Foo, &who), 0 + extend_hold);

let ticket = Consideration::new(&who, Footprint::from_parts(10, 1)).unwrap();
Expand Down
9 changes: 8 additions & 1 deletion substrate/frame/collective/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { features = ["derive"], workspace = true }
docify = { workspace = true }
log = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-support = { features = ["experimental"], workspace = true }
frame-system = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }

[dev-dependencies]
pallet-balances = { workspace = true, default-features = false }

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

0 comments on commit cc3b7bb

Please sign in to comment.