Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Logic for the (Core) Fellowship #13503

Merged
merged 97 commits into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
e3a5bb2
More drafting
gavofyork Oct 7, 2022
3ff9ce8
Merge remote-tracking branch 'origin/master' into gav-paymaster
gavofyork Oct 7, 2022
07ab87a
Paymaster pallet
gavofyork Oct 11, 2022
88e11ce
Merge remote-tracking branch 'origin/master' into gav-paymaster
gavofyork Nov 30, 2022
8200850
Merge remote-tracking branch 'origin/master' into gav-paymaster
gavofyork Feb 12, 2023
958d34f
Fix build
gavofyork Feb 13, 2023
91cb1f5
More tests
gavofyork Feb 13, 2023
c53d372
Rename
gavofyork Feb 13, 2023
0806559
Rename
gavofyork Feb 13, 2023
5cadabf
Renaming
gavofyork Feb 13, 2023
712118b
Revert old changes
gavofyork Feb 13, 2023
07b785c
Multi-phase payouts to avoid bank-runs
gavofyork Feb 15, 2023
7fb95d0
Tests
gavofyork Feb 15, 2023
5c38814
Tests
gavofyork Feb 16, 2023
bfdf333
Allow payment to be targeted elsewhere
gavofyork Feb 16, 2023
807a3c9
Proper ssync payment failure handling
gavofyork Feb 16, 2023
cf1f365
Test for repayment
gavofyork Feb 22, 2023
d829078
Docs
gavofyork Feb 22, 2023
7162964
Impl RankedMembers for RankedCollective
gavofyork Feb 26, 2023
2e299f4
Implement Pay for Pot (i.e. basic account).
gavofyork Feb 26, 2023
5995eeb
Benchmarks
gavofyork Feb 26, 2023
c9c2ce8
Weights
gavofyork Feb 26, 2023
16bc55a
Introduce Salary benchmark into node
gavofyork Feb 26, 2023
2fc7fab
Fix warning
gavofyork Feb 26, 2023
575f426
Merge branch 'master' of https://github.com/paritytech/substrate into…
Feb 26, 2023
42a7927
".git/.scripts/commands/bench/bench.sh" pallet dev pallet_salary
Feb 26, 2023
7dc1529
Update primitives/arithmetic/src/traits.rs
gavofyork Feb 27, 2023
366267c
Update frame/salary/src/lib.rs
gavofyork Feb 27, 2023
26f1ab0
Update lib.rs
gavofyork Feb 27, 2023
872a047
Update frame/salary/src/lib.rs
gavofyork Feb 27, 2023
e2fd134
Docs
gavofyork Feb 27, 2023
8d8a5bf
Update frame/salary/src/lib.rs
gavofyork Feb 27, 2023
9849a65
Update frame/salary/src/lib.rs
gavofyork Feb 27, 2023
0b4aafa
Fix
gavofyork Feb 27, 2023
03199ae
Merge branch 'gav-paymaster' of github.com:paritytech/substrate into …
gavofyork Feb 27, 2023
a21b1bc
Fixes
gavofyork Feb 27, 2023
4c85f02
Fixes
gavofyork Feb 27, 2023
d5696c1
Move some salary traits stuff to a shared location
gavofyork Mar 1, 2023
199b1fe
Merge branch 'gav-paymaster' into gav-core-fellowship
gavofyork Mar 1, 2023
caaf99e
Initial draft
gavofyork Mar 1, 2023
3d70833
Comment out bits
gavofyork Mar 2, 2023
ddd4d3e
Fix
gavofyork Mar 2, 2023
26aa188
Merge branch 'gav-paymaster' into gav-core-fellowship
gavofyork Mar 2, 2023
3fcc590
First couple of tests
gavofyork Mar 2, 2023
f60ed83
One more test
gavofyork Mar 2, 2023
3704efe
Update frame/salary/src/lib.rs
gavofyork Mar 3, 2023
93a845d
Update frame/salary/src/lib.rs
gavofyork Mar 3, 2023
2ef3e14
Mul floor
gavofyork Mar 3, 2023
d992c0d
Tests
gavofyork Mar 3, 2023
e5c0733
Mul floor
gavofyork Mar 3, 2023
5d24050
Merge branch 'gav-paymaster' of github.com:paritytech/substrate into …
gavofyork Mar 3, 2023
b3d160e
Fix warnings
gavofyork Mar 3, 2023
b9623a4
Fix test
gavofyork Mar 3, 2023
b051049
Merge branch 'gav-paymaster' into gav-core-fellowship
gavofyork Mar 3, 2023
3580ea2
Tests
gavofyork Mar 3, 2023
31bf7b6
Last tests
gavofyork Mar 3, 2023
c08c010
Docs
gavofyork Mar 3, 2023
8782190
Merge branch 'gav-paymaster' into gav-core-fellowship
gavofyork Mar 3, 2023
a3f2026
Merge branch 'master' into gav-core-fellowship
gavofyork Mar 4, 2023
392c74d
Merge branch 'gav-core-fellowship' of github.com:paritytech/substrate…
gavofyork Mar 4, 2023
6c15f61
Fix warnings
gavofyork Mar 4, 2023
6fec0d2
Merge branch 'master' into gav-core-fellowship
gavofyork Mar 4, 2023
9d947a5
Benchmarks
gavofyork Mar 4, 2023
65f3570
Merge branch 'gav-core-fellowship' of github.com:paritytech/substrate…
gavofyork Mar 4, 2023
10e30b3
Weights
gavofyork Mar 4, 2023
bda6348
Integrate benchmark
gavofyork Mar 4, 2023
47ad52c
Fixes
gavofyork Mar 4, 2023
6752c18
Fix
gavofyork Mar 5, 2023
5b8e221
Merge branch 'master' of https://github.com/paritytech/substrate into…
Mar 5, 2023
3116351
".git/.scripts/commands/bench/bench.sh" pallet dev pallet_core_fellow…
Mar 5, 2023
032f7c1
Better process flow
gavofyork Mar 5, 2023
1f69d45
Fix benchmarks & tests
gavofyork Mar 5, 2023
b1868e0
Docs
gavofyork Mar 5, 2023
ec0f7db
Fixes
gavofyork Mar 5, 2023
59d70c9
Fixes
gavofyork Mar 5, 2023
cdb8022
docs
gavofyork Mar 5, 2023
308510a
".git/.scripts/commands/bench/bench.sh" pallet dev pallet_core_fellow…
Mar 5, 2023
8c60756
Docs and allow custom evidence size
gavofyork Mar 5, 2023
958edf6
Merge branch 'gav-core-fellowship' of github.com:paritytech/substrate…
gavofyork Mar 5, 2023
dd07d0c
".git/.scripts/commands/bench/bench.sh" pallet dev pallet_core_fellow…
Mar 5, 2023
8233b71
Update frame/core-fellowship/src/lib.rs
gavofyork Mar 6, 2023
1261201
Update frame/core-fellowship/src/tests.rs
gavofyork Mar 6, 2023
8e524e9
Update frame/core-fellowship/src/benchmarking.rs
gavofyork Mar 6, 2023
063f1d7
Update frame/core-fellowship/src/benchmarking.rs
gavofyork Mar 6, 2023
76e521b
Apply suggestions from code review
gavofyork Mar 6, 2023
a86c095
Rename
gavofyork Mar 6, 2023
c9de385
Update primitives/arithmetic/src/traits.rs
gavofyork Mar 7, 2023
8684952
Reduce magic numbers
gavofyork Mar 7, 2023
4fc96dd
Merge branch 'gav-core-fellowship' of github.com:paritytech/substrate…
gavofyork Mar 7, 2023
091c6af
Update frame/core-fellowship/src/lib.rs
gavofyork Mar 7, 2023
ecd0c46
Update frame/core-fellowship/src/lib.rs
gavofyork Mar 7, 2023
749f9ac
Benchmark result
gavofyork Mar 7, 2023
122df7c
Merge branch 'gav-core-fellowship' of github.com:paritytech/substrate…
gavofyork Mar 7, 2023
04da40e
Remove dependency
gavofyork Mar 8, 2023
ae5a5e2
set_params should pay
gavofyork Mar 8, 2023
554ac7d
induct should pay
gavofyork Mar 8, 2023
cc9f07c
Remove some other free calls
gavofyork Mar 8, 2023
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
20 changes: 20 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ members = [
"frame/contracts/proc-macro",
"frame/contracts/primitives",
"frame/conviction-voting",
"frame/core-fellowship",
"frame/democracy",
"frame/fast-unstake",
"frame/try-runtime",
Expand Down
4 changes: 4 additions & 0 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pallet-collective = { version = "4.0.0-dev", default-features = false, path = ".
pallet-contracts = { version = "4.0.0-dev", default-features = false, path = "../../../frame/contracts" }
pallet-contracts-primitives = { version = "7.0.0", default-features = false, path = "../../../frame/contracts/primitives/" }
pallet-conviction-voting = { version = "4.0.0-dev", default-features = false, path = "../../../frame/conviction-voting" }
pallet-core-fellowship = { version = "4.0.0-dev", default-features = false, path = "../../../frame/core-fellowship" }
pallet-democracy = { version = "4.0.0-dev", default-features = false, path = "../../../frame/democracy" }
pallet-election-provider-multi-phase = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-multi-phase" }
pallet-election-provider-support-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-support/benchmarking", optional = true }
Expand Down Expand Up @@ -148,6 +149,7 @@ std = [
"pallet-contracts/std",
"pallet-contracts-primitives/std",
"pallet-conviction-voting/std",
"pallet-core-fellowship/std",
"pallet-democracy/std",
"pallet-elections-phragmen/std",
"pallet-fast-unstake/std",
Expand Down Expand Up @@ -235,6 +237,7 @@ runtime-benchmarks = [
"pallet-collective/runtime-benchmarks",
"pallet-contracts/runtime-benchmarks",
"pallet-conviction-voting/runtime-benchmarks",
"pallet-core-fellowship/runtime-benchmarks",
"pallet-democracy/runtime-benchmarks",
"pallet-election-provider-multi-phase/runtime-benchmarks",
"pallet-election-provider-support-benchmarking/runtime-benchmarks",
Expand Down Expand Up @@ -294,6 +297,7 @@ try-runtime = [
"pallet-collective/try-runtime",
"pallet-contracts/try-runtime",
"pallet-conviction-voting/try-runtime",
"pallet-core-fellowship/try-runtime",
"pallet-democracy/try-runtime",
"pallet-election-provider-multi-phase/try-runtime",
"pallet-elections-phragmen/try-runtime",
Expand Down
14 changes: 14 additions & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,18 @@ impl pallet_salary::Config for Runtime {
type Budget = Budget;
}

impl pallet_core_fellowship::Config for Runtime {
type WeightInfo = ();
type RuntimeEvent = RuntimeEvent;
type Members = RankedCollective;
type Balance = Balance;
type ParamsOrigin = frame_system::EnsureRoot<AccountId>;
type InductOrigin = pallet_core_fellowship::EnsureInducted<Runtime, (), 1>;
type ApproveOrigin = frame_system::EnsureRootWithSuccess<AccountId, ConstU16<9>>;
type PromoteOrigin = frame_system::EnsureRootWithSuccess<AccountId, ConstU16<9>>;
type EvidenceSize = ConstU32<16_384>;
}

parameter_types! {
pub Features: PalletFeatures = PalletFeatures::all_enabled();
pub const MaxAttributesPerCall: u32 = 10;
Expand Down Expand Up @@ -1791,6 +1803,7 @@ construct_runtime!(
Uniques: pallet_uniques,
Nfts: pallet_nfts,
Salary: pallet_salary,
CoreFellowship: pallet_core_fellowship,
TransactionStorage: pallet_transaction_storage,
VoterList: pallet_bags_list::<Instance1>,
StateTrieMigration: pallet_state_trie_migration,
Expand Down Expand Up @@ -1887,6 +1900,7 @@ mod benches {
[pallet_collective, Council]
[pallet_conviction_voting, ConvictionVoting]
[pallet_contracts, Contracts]
[pallet_core_fellowship, CoreFellowship]
[pallet_democracy, Democracy]
[pallet_election_provider_multi_phase, ElectionProviderMultiPhase]
[pallet_election_provider_support_benchmarking, EPSBench::<Runtime>]
Expand Down
55 changes: 55 additions & 0 deletions frame/core-fellowship/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[package]
name = "pallet-core-fellowship"
version = "4.0.0-dev"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
license = "Apache-2.0"
homepage = "https://substrate.io"
repository = "https://github.com/paritytech/substrate/"
description = "Logic as per the description of The Fellowship for core Polkadot technology"
readme = "README.md"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
log = { version = "0.4.16", default-features = false }
scale-info = { version = "2.0.1", default-features = false, features = ["derive"] }
frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, path = "../benchmarking" }
frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }
sp-arithmetic = { version = "6.0.0", default-features = false, path = "../../primitives/arithmetic" }
sp-core = { version = "7.0.0", default-features = false, path = "../../primitives/core" }
sp-io = { version = "7.0.0", default-features = false, path = "../../primitives/io" }
sp-runtime = { version = "7.0.0", default-features = false, path = "../../primitives/runtime" }
sp-std = { version = "5.0.0", default-features = false, path = "../../primitives/std" }

[dev-dependencies]
pallet-ranked-collective = { version = "4.0.0-dev", default-features = false, path = "../ranked-collective" }
pallet-salary = { version = "4.0.0-dev", default-features = false, path = "../salary" }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"log/std",
"scale-info/std",
"sp-arithmetic/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"pallet-ranked-collective/runtime-benchmarks",
"pallet-salary/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
3 changes: 3 additions & 0 deletions frame/core-fellowship/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Core Fellowship

Logic specific to the core Polkadot Fellowship.
216 changes: 216 additions & 0 deletions frame/core-fellowship/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
// This file is part of Substrate.

// Copyright (C) 2020-2022 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Salary pallet benchmarking.

#![cfg(feature = "runtime-benchmarks")]

use super::*;
use crate::Pallet as CoreFellowship;

use frame_benchmarking::v2::*;
use frame_system::RawOrigin;
use sp_arithmetic::traits::Bounded;

const SEED: u32 = 0;
gavofyork marked this conversation as resolved.
Show resolved Hide resolved

type BenchResult = Result<(), BenchmarkError>;

#[instance_benchmarks]
mod benchmarks {
use super::*;

fn ensure_evidence<T: Config<I>, I: 'static>(who: &T::AccountId) -> BenchResult {
let evidence = BoundedVec::try_from(vec![0; Evidence::<T, I>::bound()]).unwrap();
let wish = Wish::Retention;
let origin = RawOrigin::Signed(who.clone()).into();
CoreFellowship::<T, I>::submit_evidence(origin, wish, evidence)?;
assert!(MemberEvidence::<T, I>::contains_key(who));
Ok(())
}

fn make_member<T: Config<I>, I: 'static>(rank: u16) -> Result<T::AccountId, BenchmarkError> {
let member = account("member", 0, SEED);
T::Members::induct(&member)?;
for _ in 0..rank {
T::Members::promote(&member)?;
}
CoreFellowship::<T, I>::import(RawOrigin::Signed(member.clone()).into())?;
Ok(member)
}

#[benchmark]
fn set_params() -> Result<(), BenchmarkError> {
let params = ParamsType {
active_salary: [100u32.into(); 9],
passive_salary: [10u32.into(); 9],
demotion_period: [100u32.into(); 9],
min_promotion_period: [100u32.into(); 9],
offboard_timeout: 1u32.into(),
};

#[extrinsic_call]
_(RawOrigin::Root, Box::new(params.clone()));

assert_eq!(Params::<T, I>::get(), params);
Ok(())
}

#[benchmark]
fn bump_offboard() -> Result<(), BenchmarkError> {
let member = make_member::<T, I>(0)?;

// Set it to the max value to ensure that any possible auto-demotion period has passed.
frame_system::Pallet::<T>::set_block_number(T::BlockNumber::max_value());
ensure_evidence::<T, I>(&member)?;
assert!(Member::<T, I>::contains_key(&member));

#[extrinsic_call]
CoreFellowship::<T, I>::bump(RawOrigin::Signed(member.clone()), member.clone());

assert!(!Member::<T, I>::contains_key(&member));
assert!(!MemberEvidence::<T, I>::contains_key(&member));
Ok(())
}

#[benchmark]
fn bump_demote() -> Result<(), BenchmarkError> {
let member = make_member::<T, I>(2)?;

// Set it to the max value to ensure that any possible auto-demotion period has passed.
frame_system::Pallet::<T>::set_block_number(T::BlockNumber::max_value());
ensure_evidence::<T, I>(&member)?;
assert!(Member::<T, I>::contains_key(&member));
assert_eq!(T::Members::rank_of(&member), Some(2));

#[extrinsic_call]
CoreFellowship::<T, I>::bump(RawOrigin::Signed(member.clone()), member.clone());

assert!(Member::<T, I>::contains_key(&member));
assert_eq!(T::Members::rank_of(&member), Some(1));
assert!(!MemberEvidence::<T, I>::contains_key(&member));
Ok(())
}

#[benchmark]
fn set_active() -> Result<(), BenchmarkError> {
let member = make_member::<T, I>(1)?;
assert!(Member::<T, I>::get(&member).unwrap().is_active);

#[extrinsic_call]
_(RawOrigin::Signed(member.clone()), false);

assert!(!Member::<T, I>::get(&member).unwrap().is_active);
Ok(())
}

#[benchmark]
fn induct() -> Result<(), BenchmarkError> {
let candidate: T::AccountId = account("candidate", 0, SEED);

#[extrinsic_call]
_(RawOrigin::Root, candidate.clone());

assert_eq!(T::Members::rank_of(&candidate), Some(0));
assert!(Member::<T, I>::contains_key(&candidate));
Ok(())
}

#[benchmark]
fn promote() -> Result<(), BenchmarkError> {
let member = make_member::<T, I>(1)?;
ensure_evidence::<T, I>(&member)?;

#[extrinsic_call]
_(RawOrigin::Root, member.clone(), 2u8.into());

assert_eq!(T::Members::rank_of(&member), Some(2));
assert!(!MemberEvidence::<T, I>::contains_key(&member));
Ok(())
}

#[benchmark]
fn offboard() -> Result<(), BenchmarkError> {
let member = make_member::<T, I>(0)?;
T::Members::demote(&member)?;
ensure_evidence::<T, I>(&member)?;

assert!(T::Members::rank_of(&member).is_none());
assert!(Member::<T, I>::contains_key(&member));
assert!(MemberEvidence::<T, I>::contains_key(&member));

#[extrinsic_call]
_(RawOrigin::Signed(member.clone()), member.clone());

assert!(!Member::<T, I>::contains_key(&member));
assert!(!MemberEvidence::<T, I>::contains_key(&member));
Ok(())
}

#[benchmark]
fn import() -> Result<(), BenchmarkError> {
let member = account("member", 0, SEED);
T::Members::induct(&member)?;
T::Members::promote(&member)?;

assert!(!Member::<T, I>::contains_key(&member));

#[extrinsic_call]
_(RawOrigin::Signed(member.clone()));

assert!(Member::<T, I>::contains_key(&member));
Ok(())
}

#[benchmark]
fn approve() -> Result<(), BenchmarkError> {
let member = make_member::<T, I>(1)?;
let then = frame_system::Pallet::<T>::block_number();
let now = then.saturating_plus_one();
frame_system::Pallet::<T>::set_block_number(now);
ensure_evidence::<T, I>(&member)?;

assert_eq!(Member::<T, I>::get(&member).unwrap().last_proof, then);

#[extrinsic_call]
_(RawOrigin::Root, member.clone(), 1u8.into());

assert_eq!(Member::<T, I>::get(&member).unwrap().last_proof, now);
assert!(!MemberEvidence::<T, I>::contains_key(&member));
Ok(())
}

#[benchmark]
fn submit_evidence() -> Result<(), BenchmarkError> {
let member = make_member::<T, I>(1)?;
let evidence = vec![0; Evidence::<T, I>::bound()].try_into().unwrap();

assert!(!MemberEvidence::<T, I>::contains_key(&member));

#[extrinsic_call]
_(RawOrigin::Signed(member.clone()), Wish::Retention, evidence);

assert!(MemberEvidence::<T, I>::contains_key(&member));
Ok(())
}

impl_benchmark_test_suite! {
CoreFellowship,
crate::tests::new_test_ext(),
crate::tests::Test,
}
}
Loading