mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 09:21:05 +00:00
Split SolutionImprovementThresholds into two types (#11221)
* Splitting `SolutionImprovementThreshold` in 2 One for Signed phase and one for Unsigned phase. * Adding some tests * Fixes after code review. - Removing `GetDefault`. - Shorter naming. - More explicit test.
This commit is contained in:
@@ -291,7 +291,7 @@ impl<T: Config> SignedSubmissions<T> {
|
||||
None => return InsertResult::NotInserted,
|
||||
Some((score, _)) => *score,
|
||||
};
|
||||
let threshold = T::SolutionImprovementThreshold::get();
|
||||
let threshold = T::BetterSignedThreshold::get();
|
||||
|
||||
// if we haven't improved on the weakest score, don't change anything.
|
||||
if !insert_score.strict_threshold_better(weakest_score, threshold) {
|
||||
@@ -499,7 +499,7 @@ mod tests {
|
||||
balances, raw_solution, roll_to, ExtBuilder, MultiPhase, Origin, Runtime,
|
||||
SignedMaxSubmissions, SignedMaxWeight,
|
||||
},
|
||||
Error, Phase,
|
||||
Error, Perbill, Phase,
|
||||
};
|
||||
use frame_support::{assert_noop, assert_ok, assert_storage_noop};
|
||||
|
||||
@@ -632,6 +632,54 @@ mod tests {
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_submit_worse_with_full_queue_depends_on_threshold() {
|
||||
ExtBuilder::default()
|
||||
.signed_max_submission(1)
|
||||
.better_signed_threshold(Perbill::from_percent(20))
|
||||
.build_and_execute(|| {
|
||||
roll_to(15);
|
||||
assert!(MultiPhase::current_phase().is_signed());
|
||||
|
||||
let mut solution = RawSolution {
|
||||
score: ElectionScore {
|
||||
minimal_stake: 5u128,
|
||||
sum_stake: 0u128,
|
||||
sum_stake_squared: 10u128,
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(99), Box::new(solution)));
|
||||
|
||||
// This is 10% better, so does not meet the 20% threshold and is therefore rejected.
|
||||
solution = RawSolution {
|
||||
score: ElectionScore {
|
||||
minimal_stake: 5u128,
|
||||
sum_stake: 0u128,
|
||||
sum_stake_squared: 9u128,
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert_noop!(
|
||||
MultiPhase::submit(Origin::signed(99), Box::new(solution)),
|
||||
Error::<Runtime>::SignedQueueFull,
|
||||
);
|
||||
|
||||
// This is however 30% better and should therefore be accepted.
|
||||
solution = RawSolution {
|
||||
score: ElectionScore {
|
||||
minimal_stake: 5u128,
|
||||
sum_stake: 0u128,
|
||||
sum_stake_squared: 7u128,
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert_ok!(MultiPhase::submit(Origin::signed(99), Box::new(solution)));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn weakest_is_removed_if_better_provided() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
|
||||
Reference in New Issue
Block a user