babe, grandpa: waive fees on valid equivocation report (#6981)

* babe: waive fees on report_equivocation

* grandpa: waive fees on report_equivocation

* babe: add test for fee waiving on valid equivocation report

* grandpa: add test for fee waiving on valid equivocation report

* grandpa: remove stray comment
This commit is contained in:
André Silva
2020-09-08 11:05:36 +01:00
committed by GitHub
parent 7c7ad18d4e
commit 2a7a539e82
4 changed files with 147 additions and 19 deletions
+59
View File
@@ -21,6 +21,7 @@ use super::{Call, *};
use frame_support::{
assert_err, assert_ok,
traits::{Currency, OnFinalize},
weights::{GetDispatchInfo, Pays},
};
use mock::*;
use pallet_session::ShouldEndSession;
@@ -608,3 +609,61 @@ fn report_equivocation_has_valid_weight() {
.all(|w| w[0] < w[1])
);
}
#[test]
fn valid_equivocation_reports_dont_pay_fees() {
let (pairs, mut ext) = new_test_ext_with_pairs(3);
ext.execute_with(|| {
start_era(1);
let offending_authority_pair = &pairs[0];
// generate an equivocation proof.
let equivocation_proof =
generate_equivocation_proof(0, &offending_authority_pair, CurrentSlot::get());
// create the key ownership proof.
let key_owner_proof = Historical::prove((
sp_consensus_babe::KEY_TYPE,
&offending_authority_pair.public(),
))
.unwrap();
// check the dispatch info for the call.
let info = Call::<Test>::report_equivocation_unsigned(
equivocation_proof.clone(),
key_owner_proof.clone(),
)
.get_dispatch_info();
// it should have non-zero weight and the fee has to be paid.
assert!(info.weight > 0);
assert_eq!(info.pays_fee, Pays::Yes);
// report the equivocation.
let post_info = Babe::report_equivocation_unsigned(
Origin::none(),
equivocation_proof.clone(),
key_owner_proof.clone(),
)
.unwrap();
// the original weight should be kept, but given that the report
// is valid the fee is waived.
assert!(post_info.actual_weight.is_none());
assert_eq!(post_info.pays_fee, Pays::No);
// report the equivocation again which is invalid now since it is
// duplicate.
let post_info =
Babe::report_equivocation_unsigned(Origin::none(), equivocation_proof, key_owner_proof)
.err()
.unwrap()
.post_info;
// the fee is not waived and the original weight is kept.
assert!(post_info.actual_weight.is_none());
assert_eq!(post_info.pays_fee, Pays::Yes);
})
}