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

Implements a variable deposit base calculation for EPM signed submissions #13983

Open
wants to merge 63 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
cda7c0e
Implements a variable deposit base calculation in EPM
gpestana Apr 23, 2023
cf5cd81
Implements geometric increase of base deposit based on the number of …
gpestana Apr 26, 2023
8b7e455
Finishes implementation and test
gpestana Apr 27, 2023
b9d90aa
More docs
gpestana Apr 27, 2023
95217b7
fixes docs
gpestana Apr 27, 2023
66a0bfb
Update frame/election-provider-multi-phase/src/signed.rs
gpestana May 4, 2023
a1636ca
Update bin/node/runtime/src/lib.rs
gpestana May 4, 2023
cb33150
Adds force_origin support (#13845)
gupnik Apr 24, 2023
0591d11
Vote locks for all reasons except RESERVE (#13914)
muharem Apr 24, 2023
1a14c52
[ci] Update buildah command and version (#13989)
alvicsam Apr 24, 2023
1c781d6
Bump enumflags2 from 0.7.5 to 0.7.7 (#13995)
dependabot[bot] Apr 24, 2023
e5a9709
frame-support-procedural: Fix detection of the tuples feature (#13996)
bkchr Apr 24, 2023
2d277ad
pallet-democracy: Do not request the proposal when scheduling (#13827)
bkchr Apr 25, 2023
db79585
[ci] Add message to cargo-deny (#14001)
alvicsam Apr 25, 2023
e34ab81
refactor(cli): Make some run params reusable (#13870)
yjhmelody Apr 25, 2023
c463fb0
contracts Add LOG_TARGET constant (#14002)
pgherveou Apr 25, 2023
316bced
frame-support: migrate some tests from `decl_*` macros to the new `pa…
koushiro Apr 25, 2023
4286a74
Removes ReportsByKindIndex (#13936)
gupnik Apr 25, 2023
f05447f
Allow missing docs for autogen weights. (#14011)
gilescope Apr 25, 2023
5ca19ef
[contracts] Port host functions to Weight V2 and storage deposit limi…
agryaznov Apr 26, 2023
7ddac2d
sp-core: remove useless bounded module (#13865)
koushiro Apr 26, 2023
4df1a87
fix a test (#14021)
agryaznov Apr 26, 2023
df3a709
Various minor fixes (#13945)
gavofyork Apr 26, 2023
941de8e
contracts Add storage_deposit test (#14003)
pgherveou Apr 27, 2023
76c802e
remote-externalities: batch insert key/values (#14004)
liamaharon Apr 27, 2023
9b487cd
collective pallet: sort genesis members and enforce max len constrain…
liamaharon Apr 27, 2023
db806ea
sc-network-sync: Improve error reporting (#14025)
bkchr Apr 27, 2023
5c320d3
contracts Fix store-call test path (#14028)
pgherveou Apr 27, 2023
49f69e4
chore(cli): make cli display docs correctly (#14017)
yjhmelody Apr 27, 2023
3b05747
improve staking interface methods (#14023)
kianenigma Apr 27, 2023
a5c6264
try-runtime-cli: improve ci stability (#14030)
liamaharon Apr 27, 2023
a6aa272
FRAME: inherited call weight syntax (#13932)
ggwpez Apr 27, 2023
07b1541
Implements `try_state` hook in elections and EPM pallets (#13979)
gpestana Apr 27, 2023
be73ca3
Bump wasmtime from 6.0.1 to 6.0.2 (#14037)
dependabot[bot] Apr 27, 2023
d20deb0
Improve contribution guidelines (#13902)
bkchr Apr 28, 2023
063b3b0
CI: Remove crate publish check (#14044)
ggwpez Apr 28, 2023
9ad2b40
fix(in_mem): fix the clone logic (#14038)
yjhmelody Apr 29, 2023
476ebd4
Contracts: runtime_call and storage_deposit (#13990)
pgherveou Apr 29, 2023
0e3c6b5
Fix bags-list tests execution (#14047)
bkchr May 1, 2023
513463b
CI: migrate to Google Cloud (#13994)
rcny May 2, 2023
f541d16
rpc: Use the blocks pinning API for chainHead methods (#13233)
lexnv May 2, 2023
2b3e750
contracts: Make Origin information available (#13708)
juangirini May 2, 2023
6ebcadd
Bump clap to 4.2.5 (#14061)
May 2, 2023
e296263
Manual seal delayed finalize (#13999)
shunsukew May 2, 2023
7eeb77d
Don't run `check-crates-publishing` job on prs (#14064)
May 3, 2023
dcaebbe
Only calculate tree route during finalization when there are multiple…
skunert May 3, 2023
4b7f99b
test-staking-e2e: Add to main `Cargo.toml`. (#14062)
bkchr May 3, 2023
89acf47
contracts: add events to ContractResult (#13807)
juangirini May 3, 2023
5f8f249
rpc server: break legacy CLI options and remove "backward compatible …
niklasad1 May 3, 2023
2668e9a
Makes DepositCalculator trait more generic
gpestana May 4, 2023
792ecc4
Merge branch 'master' into gpestana/epm_variable_deposit_base
gpestana May 4, 2023
1960329
Fixed runtime configs
gpestana May 4, 2023
afb016d
Merge remote-tracking branch 'origin/master' into gpestana/epm_variab…
May 4, 2023
1558456
Updates e2e integration tests mock
gpestana May 4, 2023
310a116
Merge remote-tracking branch 'origin/master' into gpestana/epm_variab…
May 17, 2023
0098612
Refactors the traits
gpestana May 17, 2023
99622a5
Update frame/election-provider-multi-phase/src/signed.rs
gpestana May 21, 2023
49e053b
Merge branch 'master' into gpestana/epm_variable_deposit_base
gpestana Jun 9, 2023
f053577
Nits and addresses review comments
gpestana Jun 9, 2023
f11d312
Merge branch 'master' into gpestana/epm_variable_deposit_base
gpestana Jun 9, 2023
856828e
".git/.scripts/commands/fmt/fmt.sh"
Jun 9, 2023
fe49a49
Parameterize GeometricProgression instead of using dedicated associat…
gpestana Jun 12, 2023
a51a3eb
Merge branch 'master' into gpestana/epm_variable_deposit_base
gpestana Aug 10, 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
Prev Previous commit
Next Next commit
Finishes implementation and test
  • Loading branch information
gpestana committed Apr 27, 2023
commit 8b7e4552c526a1786d97110f0a9bc67940d31a87
7 changes: 5 additions & 2 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use frame_system::{
};
pub use node_primitives::{AccountId, Signature};
use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Index, Moment};
use pallet_election_provider_multi_phase::SolutionAccuracyOf;
use pallet_election_provider_multi_phase::{GeometricDepositBase, SolutionAccuracyOf};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use pallet_nfts::PalletFeatures;
use pallet_nis::WithMaximumOf;
Expand Down Expand Up @@ -621,6 +621,7 @@ parameter_types! {
// signed config
pub const SignedRewardBase: Balance = 1 * DOLLARS;
pub const SignedDepositBase: Balance = 1 * DOLLARS;
gpestana marked this conversation as resolved.
Show resolved Hide resolved
pub const SignedDepositBaseIncreaseFactor: Percent = Percent::from_percent(10);
pub const SignedDepositByte: Balance = 1 * CENTS;

pub BetterUnsignedThreshold: Perbill = Perbill::from_rational(1u32, 10_000);
Expand Down Expand Up @@ -746,7 +747,9 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
type MinerConfig = Self;
type SignedMaxSubmissions = ConstU32<10>;
type SignedRewardBase = SignedRewardBase;
type SignedDepositBase = SignedDepositBase;
type SignedDepositBase = GeometricDepositBase<Runtime>;
kianenigma marked this conversation as resolved.
Show resolved Hide resolved
type SignedFixedDepositBase = SignedDepositBase;
type SignedDepositBaseIncreaseFactor = SignedDepositBaseIncreaseFactor;
type SignedDepositByte = SignedDepositByte;
type SignedMaxRefunds = ConstU32<3>;
type SignedDepositWeight = ();
Expand Down
17 changes: 8 additions & 9 deletions frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ use unsigned::VoterOf;
pub use weights::WeightInfo;

pub use signed::{
BalanceOf, NegativeImbalanceOf, PositiveImbalanceOf, SignedSubmission, SignedSubmissionOf,
SignedSubmissions, SubmissionIndicesOf,
BalanceOf, GeometricDepositBase, NegativeImbalanceOf, PositiveImbalanceOf, SignedSubmission,
SignedSubmissionOf, SignedSubmissions, SubmissionIndicesOf,
};
pub use unsigned::{Miner, MinerConfig};

Expand Down Expand Up @@ -650,13 +650,6 @@ pub mod pallet {
#[pallet::constant]
type SignedFixedDepositBase: Get<BalanceOf<Self>>;

/// Increase factor of the geometric increase of the base deposit.
///
/// If 0, then signed base deposit remains constans regardless of the submissions queue size
/// (and equal to `SignedFixedDepositBase`).
#[pallet::constant]
type SignedDepositBaseIncreaseFactor: Get<Percent>;

/// Per-byte deposit for a signed solution.
#[pallet::constant]
type SignedDepositByte: Get<BalanceOf<Self>>;
Expand Down Expand Up @@ -685,6 +678,12 @@ pub mod pallet {
/// Type that calculates the signed deposit base.
type SignedDepositBase: SignedDepositBase<BalanceOf<Self>>;
gpestana marked this conversation as resolved.
Show resolved Hide resolved

/// Increase factor of the geometric increase of the base deposit.
///
/// If 0, then signed base deposit remains constans regardless of the submissions queue size
/// (and equal to [`SignedFixedDepositBase`]).
type SignedDepositBaseIncreaseFactor: Get<Percent>;

/// Handler for the slashed deposits.
type SlashHandler: OnUnbalanced<NegativeImbalanceOf<Self>>;

Expand Down
6 changes: 4 additions & 2 deletions frame/election-provider-multi-phase/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// limitations under the License.

use super::*;
use crate::{self as multi_phase, unsigned::MinerConfig};
use crate::{self as multi_phase, signed::GeometricDepositBase, unsigned::MinerConfig};
use frame_election_provider_support::{
data_provider,
onchain::{self},
Expand Down Expand Up @@ -422,11 +422,13 @@ impl crate::Config for Runtime {
}

impl SignedDepositBase<BalanceOf<Runtime>> for Runtime {
type IncreaseFactor = SignedDepositBaseIncreaseFactor;

fn calculate(queue_len: usize) -> Balance {
if queue_len < QueueLenghtVariableDeposit::get() {
SignedFixedDepositBase::get()
} else {
<MultiPhase as SignedDepositBase<BalanceOf<Runtime>>>::calculate(queue_len)
GeometricDepositBase::<Runtime>::calculate(queue_len)
}
}
}
Expand Down
85 changes: 39 additions & 46 deletions frame/election-provider-multi-phase/src/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

//! The signed phase implementation.

use core::marker::PhantomData;

use crate::{
unsigned::MinerConfig, Config, ElectionCompute, Pallet, QueuedSolution, RawSolution,
ReadySolution, SignedSubmissionIndices, SignedSubmissionNextIndex, SignedSubmissionsMap,
Expand Down Expand Up @@ -349,17 +351,30 @@ impl<T: Config> SignedSubmissions<T> {
}
}

impl<T: Config> SignedDepositBase<BalanceOf<T>> for Pallet<T> {
/// Increase the base deposit as a geometric series // todo: finish
/// Type that can be used to calculate the deposit base for signed submissions.
///
/// The deposit base is calculated as a geometric progression based on the number of signed
/// submissions in the queue. The size of the queue represents the progression term.
pub struct GeometricDepositBase<T> {
_marker: PhantomData<T>,
}

impl<T: Config> SignedDepositBase<BalanceOf<T>> for GeometricDepositBase<T> {
/// Increase factor of the geometric progression, as a percentage.
///
/// The nth progression term will be `IncreaseFactor`% larger than the nth-1 term.
type IncreaseFactor = T::SignedDepositBaseIncreaseFactor;
gpestana marked this conversation as resolved.
Show resolved Hide resolved

/// Increase the base deposit as a geometric progression based on the number of signed
gpestana marked this conversation as resolved.
Show resolved Hide resolved
/// submissions.
///
/// base value * (1 + increase percentage)^number of iterations
/// The nth term is obtained by calculating `base * (1 + increase_factor)^nth`. Example: factor
/// 5, with initial deposit of 1000 and 10% of increase factor is 1000 * (1 + 1.1)^5.
gpestana marked this conversation as resolved.
Show resolved Hide resolved
fn calculate(queue_len: usize) -> BalanceOf<T> {
// increase_factor: (0.x + 1)
let increase_factor: FixedU128 =
<Percent as Into<FixedU128>>::into(T::SignedDepositBaseIncreaseFactor::get()) +
<Percent as Into<FixedU128>>::into(Self::IncreaseFactor::get()) +
sp_runtime::traits::One::one();

// fixed * (1 + percent_increase)^queue_len
increase_factor
.saturating_pow(queue_len)
.saturating_mul_int(T::SignedFixedDepositBase::get())
Expand Down Expand Up @@ -789,32 +804,32 @@ mod tests {
}

#[test]
fn geometric_deposit_base_works() {
fn geometric_deposit_queue_size_works() {
let constant = vec![1000; 10];
// geometric progression with 10% increase in each iteration for 10 terms.
let progression_10 = vec![1000, 1100, 1210, 1331, 1464, 1610, 1771, 1948, 2143, 2357];
let progression_40 = vec![1000, 1400, 1960, 2744, 3841, 5378, 7529, 10541, 14757, 20661];

let check_progressive_base_fee = |expected: &Vec<u64>| {
for s in 0..SignedMaxSubmissions::get() {
let account = 99 + s as u64;
Balances::make_free_balance_be(&account, 10000000);
let mut solution = raw_solution();
solution.score.minimal_stake -= s as u128;

assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(account), Box::new(solution)));
assert_eq!(balances(&account).1, expected[s as usize])
}
};

ExtBuilder::default()
.signed_max_submission(10)
.signed_base_deposit(1000, 0, Percent::from_percent(0))
.build_and_execute(|| {
roll_to_signed();
assert!(MultiPhase::current_phase().is_signed());

for s in 0..SignedMaxSubmissions::get() {
let account = 99 + s as u64;
Balances::make_free_balance_be(&account, 10000000);
let mut solution = raw_solution();
solution.score.minimal_stake -= s as u128;

assert_ok!(MultiPhase::submit(
RuntimeOrigin::signed(account),
Box::new(solution)
));

// if increase factor is 0, base deposit is constant with the number of
// submissions.
assert_eq!(balances(&account).1, SignedFixedDepositBase::get())
}
check_progressive_base_fee(&constant);
});

ExtBuilder::default()
Expand All @@ -824,18 +839,7 @@ mod tests {
roll_to_signed();
assert!(MultiPhase::current_phase().is_signed());

for s in 0..SignedMaxSubmissions::get() {
let account = 99 + s as u64;
Balances::make_free_balance_be(&account, 10000000);
let mut solution = raw_solution();
solution.score.minimal_stake -= s as u128;

assert_ok!(MultiPhase::submit(
RuntimeOrigin::signed(account),
Box::new(solution)
));
assert_eq!(balances(&account).1, progression_10[s as usize])
}
check_progressive_base_fee(&progression_10);
});

ExtBuilder::default()
Expand All @@ -845,18 +849,7 @@ mod tests {
roll_to_signed();
assert!(MultiPhase::current_phase().is_signed());

for s in 0..SignedMaxSubmissions::get() {
let account = 99 + s as u64;
Balances::make_free_balance_be(&account, 10000000);
let mut solution = raw_solution();
solution.score.minimal_stake -= s as u128;

assert_ok!(MultiPhase::submit(
RuntimeOrigin::signed(account),
Box::new(solution)
));
assert_eq!(balances(&account).1, progression_40[s as usize])
}
check_progressive_base_fee(&progression_40);
});
}

Expand Down
4 changes: 4 additions & 0 deletions frame/election-provider-support/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use codec::Encode;
use scale_info::TypeInfo;
use sp_arithmetic::traits::{Bounded, UniqueSaturatedInto};
use sp_npos_elections::{ElectionScore, Error, EvaluateSupport};
use sp_runtime::{traits::Get, Percent};
use sp_std::{fmt::Debug, prelude::*};

/// An opaque index-based, NPoS solution type.
Expand Down Expand Up @@ -126,6 +127,9 @@ where

/// A type that calculates the deposit base for signed election submissions.
pub trait SignedDepositBase<Balance> {
gpestana marked this conversation as resolved.
Show resolved Hide resolved
/// A percentage representing the increase factor of the base deposit, if any.
type IncreaseFactor: Get<Percent>;

/// Returns the value of the deposit base given a number of queued signed solutions.
fn calculate(queue_len: usize) -> Balance;
}
2 changes: 1 addition & 1 deletion frame/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
//! ```
//! use pallet_staking::{self as staking};
//!
//! #[frame_support::pallet]
//! #[frame_support::pallet(dev_mode)]
gpestana marked this conversation as resolved.
Show resolved Hide resolved
//! pub mod pallet {
//! use super::*;
//! use frame_support::pallet_prelude::*;
Expand Down