Configurable call fee refund for signed submissions (#11002)

* Refund call fee for all non-invalid signed submissions

* Clean up

* Fix benchmarks

* Remove reward from struct

* WIP SignedMaxRefunds

* Apply suggestions from code review

* Add test for ejected call_fee refunds

* Add test for number of calls refunded

* Account for read op in mutate

* Apply suggestions from code review

* Add to node runtime

* Don't refund ejected solutions

* Update frame/election-provider-multi-phase/src/lib.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Inegrity test SignedMaxRefunds

* Use reward handle to refund call fee

* Fix node runtime build

* Drain in order of submission

* Update frame/election-provider-multi-phase/src/signed.rs

* save

* Update frame/election-provider-multi-phase/src/signed.rs

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>

* Update frame/election-provider-multi-phase/src/signed.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Zeke Mostov
2022-04-20 13:56:07 -07:00
committed by GitHub
parent a8ab0c048a
commit 79c632abdd
5 changed files with 133 additions and 35 deletions
@@ -242,7 +242,7 @@ use frame_support::{
use frame_system::{ensure_none, offchain::SendTransactionTypes};
use scale_info::TypeInfo;
use sp_arithmetic::{
traits::{Bounded, CheckedAdd, Saturating, Zero},
traits::{Bounded, CheckedAdd, Zero},
UpperOf,
};
use sp_npos_elections::{
@@ -628,6 +628,10 @@ pub mod pallet {
#[pallet::constant]
type SignedMaxWeight: Get<Weight>;
/// The maximum amount of unchecked solutions to refund the call fee for.
#[pallet::constant]
type SignedMaxRefunds: Get<u32>;
/// Base reward for a signed solution
#[pallet::constant]
type SignedRewardBase: Get<BalanceOf<Self>>;
@@ -848,6 +852,11 @@ pub mod pallet {
<T::DataProvider as ElectionDataProvider>::MaxVotesPerVoter::get(),
<SolutionOf<T> as NposSolution>::LIMIT as u32,
);
// While it won't cause any failures, setting `SignedMaxRefunds` gt
// `SignedMaxSubmissions` is a red flag that the developer does not understand how to
// configure this pallet.
assert!(T::SignedMaxSubmissions::get() >= T::SignedMaxRefunds::get());
}
}
@@ -988,14 +997,17 @@ pub mod pallet {
// create the submission
let deposit = Self::deposit_for(&raw_solution, size);
let reward = {
let call_fee = {
let call = Call::submit { raw_solution: raw_solution.clone() };
let call_fee = T::EstimateCallFee::estimate_call_fee(&call, None.into());
T::SignedRewardBase::get().saturating_add(call_fee)
T::EstimateCallFee::estimate_call_fee(&call, None.into())
};
let submission =
SignedSubmission { who: who.clone(), deposit, raw_solution: *raw_solution, reward };
let submission = SignedSubmission {
who: who.clone(),
deposit,
raw_solution: *raw_solution,
call_fee,
};
// insert the submission if the queue has space or it's better than the weakest
// eject the weakest if the queue was full