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

feat: add tips pallet #352

Merged
merged 9 commits into from
Apr 19, 2022
Merged
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.

1 change: 1 addition & 0 deletions nodes/parachain/src/chain_spec/peregrine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ fn testnet_genesis(
phantom: Default::default(),
},
treasury: Default::default(),
tips_membership: Default::default(),
technical_membership: Default::default(),
democracy: Default::default(),
parachain_staking: ParachainStakingConfig {
Expand Down
1 change: 1 addition & 0 deletions nodes/parachain/src/chain_spec/spiritnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ fn testnet_genesis(
},
treasury: Default::default(),
technical_membership: Default::default(),
tips_membership: Default::default(),
democracy: Default::default(),
}
}
2 changes: 2 additions & 0 deletions runtimes/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ frame-support = {git = "https://github.com/paritytech/substrate", default-featur
frame-system = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.17"}
pallet-authorship = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.17"}
pallet-balances = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.17"}
pallet-membership = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.17"}
pallet-transaction-payment = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.17"}
sp-consensus-aura = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.17"}
sp-core = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.17"}
Expand All @@ -43,6 +44,7 @@ std = [
"frame-system/std",
"pallet-transaction-payment/std",
"pallet-balances/std",
"pallet-membership/std",
"pallet-authorship/std",
"scale-info/std",
"serde",
Expand Down
13 changes: 12 additions & 1 deletion runtimes/common/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use frame_support::{
parameter_types,
weights::{constants::WEIGHT_PER_SECOND, Weight},
};
use sp_runtime::{Perbill, Perquintill};
use sp_runtime::{Perbill, Percent, Perquintill};

use parachain_staking::InflationInfo;

Expand Down Expand Up @@ -408,6 +408,17 @@ pub mod preimage {
}
}

pub mod tips {
use super::*;

parameter_types! {
pub const MaximumReasonLength: u32 = 16384;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is naively taken from Kusama configuration, I could not find any information where this value comes from unfortunately.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we were told once that there is a threshold up to which a storage entry size doesn't influence the weights. If this threshold is passed, the storage needs to be taken into account when doing benchmarks. Maybe the value is related to that?

pub const TipCountdown: BlockNumber = DAYS;
pub const TipFindersFee: Percent = Percent::from_percent(20);
pub const TipReportDepositBase: Balance = deposit(1, 1);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Polkadot, this is set to 1 Dollar. However, I wanted to align with our other deposits.

}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
41 changes: 39 additions & 2 deletions runtimes/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ pub use sp_consensus_aura::sr25519::AuthorityId;
pub use opaque::*;

pub use frame_support::weights::constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
use frame_support::{parameter_types, traits::Currency, weights::DispatchClass};
use frame_support::{
parameter_types,
traits::{Contains, ContainsLengthBound, Currency, Get, SortedMembers},
weights::DispatchClass,
};
use frame_system::limits;
use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment};
use sp_runtime::{
generic,
traits::{IdentifyAccount, Verify},
FixedPointNumber, MultiSignature, Perquintill,
FixedPointNumber, MultiSignature, Perquintill, SaturatedConversion,
};
use sp_std::marker::PhantomData;

pub mod authorization;
pub mod constants;
Expand Down Expand Up @@ -153,3 +158,35 @@ pub type FeeSplit<R, B1, B2> = SplitFeesByRatio<R, FeeSplitRatio, B1, B2>;
/// https://w3f-research.readthedocs.io/en/latest/polkadot/Token%20Economics.html#-2.-slow-adjusting-mechanism
pub type SlowAdjustingFeeUpdate<R> =
TargetedFeeAdjustment<R, TargetBlockFullness, AdjustmentVariable, MinimumMultiplier>;

pub struct Tippers<R, I>(PhantomData<R>, PhantomData<I>);
impl<R, I: 'static> ContainsLengthBound for Tippers<R, I>
where
R: pallet_membership::Config<I>,
{
fn max_len() -> usize {
<R as pallet_membership::Config<I>>::MaxMembers::get().saturated_into()
}

fn min_len() -> usize {
0
}
}

impl<R, I: 'static> SortedMembers<R::AccountId> for Tippers<R, I>
where
R: pallet_membership::Config<I>,
pallet_membership::Pallet<R, I>: SortedMembers<R::AccountId> + Contains<R::AccountId>,
{
fn sorted_members() -> sp_std::vec::Vec<R::AccountId> {
pallet_membership::Pallet::<R, I>::sorted_members()
}

#[cfg(feature = "runtime-benchmarks")]
fn add(who: &R::AccountId) {
pallet_membership::Members::<R, I>::mutate(|members| match members.binary_search_by(|m| m.cmp(who)) {
Ok(_) => (),
Err(pos) => members.insert(pos, who.clone()),
})
}
}
4 changes: 4 additions & 0 deletions runtimes/peregrine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pallet-scheduler = {git = "https://github.com/paritytech/substrate", default-fea
pallet-session = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.17"}
pallet-sudo = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.17"}
pallet-timestamp = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.17"}
pallet-tips = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.17"}
pallet-transaction-payment = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.17"}
pallet-treasury = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.17"}
pallet-utility = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.17"}
Expand Down Expand Up @@ -122,6 +123,7 @@ runtime-benchmarks = [
"pallet-preimage/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-tips/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"pallet-vesting/runtime-benchmarks",
"pallet-web3-names/runtime-benchmarks",
Expand Down Expand Up @@ -166,6 +168,7 @@ std = [
"pallet-session/std",
"pallet-sudo/std",
"pallet-timestamp/std",
"pallet-tips/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
"pallet-treasury/std",
Expand Down Expand Up @@ -220,6 +223,7 @@ try-runtime = [
"pallet-session/try-runtime",
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-tips/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-treasury/try-runtime",
"pallet-web3-names/try-runtime",
Expand Down
38 changes: 36 additions & 2 deletions runtimes/peregrine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,8 @@ impl pallet_collective::Config<TechnicalCollective> for Runtime {
type WeightInfo = weights::pallet_collective::WeightInfo<Runtime>;
}

impl pallet_membership::Config for Runtime {
type TechnicalMembershipProvider = pallet_membership::Instance1;
impl pallet_membership::Config<TechnicalMembershipProvider> for Runtime {
type Event = Event;
type AddOrigin = MoreThanHalfCouncil;
type RemoveOrigin = MoreThanHalfCouncil;
Expand All @@ -475,6 +476,31 @@ impl pallet_membership::Config for Runtime {
type WeightInfo = weights::pallet_membership::WeightInfo<Runtime>;
}

type TipsMembershipProvider = pallet_membership::Instance2;
impl pallet_membership::Config<TipsMembershipProvider> for Runtime {
type Event = Event;
type AddOrigin = MoreThanHalfCouncil;
type RemoveOrigin = MoreThanHalfCouncil;
type SwapOrigin = MoreThanHalfCouncil;
type ResetOrigin = MoreThanHalfCouncil;
type PrimeOrigin = MoreThanHalfCouncil;
type MembershipInitialized = ();
type MembershipChanged = ();
Comment on lines +487 to +488
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two receivers can be kept empty for Tippers IMO as we don't need to handle membership change anywhere else in contrast to the Technical Committee which also needs to apply it to the collective pallet.

type MaxMembers = constants::governance::TechnicalMaxMembers;
type WeightInfo = weights::pallet_membership::WeightInfo<Runtime>;
}

impl pallet_tips::Config for Runtime {
type MaximumReasonLength = constants::tips::MaximumReasonLength;
type DataDepositPerByte = constants::ByteDeposit;
type Tippers = runtime_common::Tippers<Runtime, TipsMembershipProvider>;
type TipCountdown = constants::tips::TipCountdown;
type TipFindersFee = constants::tips::TipFindersFee;
type TipReportDepositBase = constants::tips::TipReportDepositBase;
type Event = Event;
type WeightInfo = weights::pallet_tips::WeightInfo<Runtime>;
}

impl attestation::Config for Runtime {
type EnsureOrigin = did::EnsureDidOrigin<DidIdentifier, AccountId>;
type OriginSuccess = did::DidRawOrigin<AccountId, DidIdentifier>;
Expand Down Expand Up @@ -700,6 +726,7 @@ impl InstanceFilter<Call> for ProxyType {
| Call::System(..)
| Call::TechnicalCommittee(..)
| Call::TechnicalMembership(..)
| Call::TipsMembership(..)
| Call::Timestamp(..)
| Call::Treasury(..)
| Call::Utility(..)
Expand Down Expand Up @@ -780,6 +807,7 @@ impl InstanceFilter<Call> for ProxyType {
| Call::Democracy(..)
| Call::TechnicalCommittee(..)
| Call::TechnicalMembership(..)
| Call::TipsMembership(..)
| Call::Treasury(..) | Call::Utility(..)
),
ProxyType::ParachainStaking => {
Expand Down Expand Up @@ -850,7 +878,7 @@ construct_runtime! {
Council: pallet_collective::<Instance1> = 31,
TechnicalCommittee: pallet_collective::<Instance2> = 32,
// placeholder: parachain council election = 33,
TechnicalMembership: pallet_membership = 34,
TechnicalMembership: pallet_membership::<Instance1> = 34,
Treasury: pallet_treasury = 35,

// Utility module.
Expand All @@ -868,6 +896,10 @@ construct_runtime! {
// Preimage registrar
Preimage: pallet_preimage::{Pallet, Call, Storage, Event<T>} = 44,

// Tips module to reward contributions to the ecosystem with small amount of KILTs.
TipsMembership: pallet_membership::<Instance2> = 45,
Tips: pallet_tips::{Pallet, Call, Storage, Event<T>} = 46,

// KILT Pallets. Start indices 60 to leave room
KiltLaunch: kilt_launch = 60,
Ctype: ctype = 61,
Expand Down Expand Up @@ -1098,6 +1130,7 @@ impl_runtime_apis! {
list_benchmark!(list, extra, pallet_preimage, Preimage);
list_benchmark!(list, extra, pallet_scheduler, Scheduler);
list_benchmark!(list, extra, pallet_timestamp, Timestamp);
list_benchmark!(list, extra, pallet_tips, Tips);
list_benchmark!(list, extra, pallet_treasury, Treasury);
list_benchmark!(list, extra, pallet_utility, Utility);
list_benchmark!(list, extra, pallet_vesting, Vesting);
Expand Down Expand Up @@ -1166,6 +1199,7 @@ impl_runtime_apis! {
add_benchmark!(params, batches, pallet_session, SessionBench::<Runtime>);
add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
add_benchmark!(params, batches, pallet_timestamp, Timestamp);
add_benchmark!(params, batches, pallet_tips, Tips);
add_benchmark!(params, batches, pallet_treasury, Treasury);
add_benchmark!(params, batches, pallet_utility, Utility);
add_benchmark!(params, batches, pallet_vesting, Vesting);
Expand Down
1 change: 1 addition & 0 deletions runtimes/peregrine/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub mod pallet_proxy;
pub mod pallet_scheduler;
pub mod pallet_session;
pub mod pallet_timestamp;
pub mod pallet_tips;
pub mod pallet_treasury;
pub mod pallet_utility;
pub mod pallet_vesting;
Expand Down
107 changes: 107 additions & 0 deletions runtimes/peregrine/src/weights/pallet_tips.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// KILT Blockchain – https://botlabs.org
// Copyright (C) 2019-2022 BOTLabs GmbH

// The KILT Blockchain 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.

// The KILT Blockchain 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 this program. If not, see <https://www.gnu.org/licenses/>.

// If you feel like getting in touch with us, you can do so at info@botlabs.org

//! Autogenerated weights for pallet_tips
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-04-07, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024

// Executed Command:
// target/release/kilt-parachain
// benchmark
// --chain=dev
// --steps=50
// --repeat=20
// --pallet=pallet-tips
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --heap-pages=4096
// --output=./runtimes/peregrine/src/weights/pallet_tips.rs
// --template=.maintain/runtime-weight-template.hbs

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(clippy::unnecessary_cast)]

use frame_support::{traits::Get, weights::Weight};
use sp_std::marker::PhantomData;

/// Weight functions for `pallet_tips`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_tips::WeightInfo for WeightInfo<T> {
// Storage: Tips Reasons (r:1 w:1)
// Storage: Tips Tips (r:1 w:1)
fn report_awesome(r: u32, ) -> Weight {
(40_320_000 as Weight)
// Standard Error: 0
.saturating_add((2_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: Tips Tips (r:1 w:1)
// Storage: Tips Reasons (r:0 w:1)
fn retract_tip() -> Weight {
(36_908_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: TipsMembership Members (r:1 w:0)
// Storage: Tips Reasons (r:1 w:1)
// Storage: Tips Tips (r:0 w:1)
fn tip_new(r: u32, t: u32, ) -> Weight {
(26_418_000 as Weight)
// Standard Error: 0
.saturating_add((2_000 as Weight).saturating_mul(r as Weight))
// Standard Error: 0
.saturating_add((102_000 as Weight).saturating_mul(t as Weight))
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: TipsMembership Members (r:1 w:0)
// Storage: Tips Tips (r:1 w:1)
fn tip(t: u32, ) -> Weight {
(15_519_000 as Weight)
// Standard Error: 0
.saturating_add((457_000 as Weight).saturating_mul(t as Weight))
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Tips Tips (r:1 w:1)
// Storage: TipsMembership Members (r:1 w:0)
// Storage: System Account (r:2 w:2)
// Storage: Tips Reasons (r:0 w:1)
fn close_tip(t: u32, ) -> Weight {
(64_426_000 as Weight)
// Standard Error: 0
.saturating_add((300_000 as Weight).saturating_mul(t as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
// Storage: Tips Tips (r:1 w:1)
// Storage: Tips Reasons (r:0 w:1)
fn slash_tip(t: u32, ) -> Weight {
(22_294_000 as Weight)
// Standard Error: 0
.saturating_add((6_000 as Weight).saturating_mul(t as Weight))
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
}
Loading