This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Logic for the (Core) Fellowship (#13503)
* More drafting * Paymaster pallet * Fix build * More tests * Rename * Rename * Renaming * Revert old changes * Multi-phase payouts to avoid bank-runs * Tests * Tests * Allow payment to be targeted elsewhere * Proper ssync payment failure handling * Test for repayment * Docs * Impl RankedMembers for RankedCollective * Implement Pay for Pot (i.e. basic account). * Benchmarks * Weights * Introduce Salary benchmark into node * Fix warning * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_salary * Update primitives/arithmetic/src/traits.rs Co-authored-by: Jegor Sidorenko <[email protected]> * Update frame/salary/src/lib.rs Co-authored-by: Jegor Sidorenko <[email protected]> * Update lib.rs * Update frame/salary/src/lib.rs Co-authored-by: joe petrowski <[email protected]> * Docs * Update frame/salary/src/lib.rs Co-authored-by: joe petrowski <[email protected]> * Update frame/salary/src/lib.rs Co-authored-by: joe petrowski <[email protected]> * Fix * Fixes * Fixes * Move some salary traits stuff to a shared location * Initial draft * Comment out bits * Fix * First couple of tests * One more test * Update frame/salary/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <[email protected]> * Update frame/salary/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <[email protected]> * Mul floor * Tests * Mul floor * Fix warnings * Fix test * Tests * Last tests * Docs * Fix warnings * Benchmarks * Weights * Integrate benchmark * Fixes * Fix * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_core_fellowship * Better process flow * Fix benchmarks & tests * Docs * Fixes * Fixes * docs * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_core_fellowship * Docs and allow custom evidence size * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_core_fellowship * Update frame/core-fellowship/src/lib.rs Co-authored-by: Kian Paimani <[email protected]> * Update frame/core-fellowship/src/tests.rs Co-authored-by: Kian Paimani <[email protected]> * Update frame/core-fellowship/src/benchmarking.rs * Update frame/core-fellowship/src/benchmarking.rs * Apply suggestions from code review * Rename * Update primitives/arithmetic/src/traits.rs Co-authored-by: joe petrowski <[email protected]> * Reduce magic numbers * Update frame/core-fellowship/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <[email protected]> * Update frame/core-fellowship/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <[email protected]> * Benchmark result * Remove dependency * set_params should pay * induct should pay * Remove some other free calls --------- Co-authored-by: command-bot <> Co-authored-by: Jegor Sidorenko <[email protected]> Co-authored-by: joe petrowski <[email protected]> Co-authored-by: Oliver Tale-Yazdi <[email protected]> Co-authored-by: Kian Paimani <[email protected]>
- Loading branch information
1 parent
8f9b074
commit 9d34fb0
Showing
14 changed files
with
1,716 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Core Fellowship | ||
|
||
Logic specific to the core Polkadot Fellowship. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
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, | ||
} | ||
} |
Oops, something went wrong.