Weight+size limits for bridge GRANDPA pallet calls (#1882)

* weight+size limits for bridge GRANDPA pallet calls

* continue

* fixed all tests

* some changes to refund computations

* post_dispatch_refunds_relayer_in_all_finality_batch_with_extra_weight

* - dup code

* do not return Pays::No if call is above weight/size limits

* relayer_pays_tx_fee_when_submitting_huge_mandatory_header and relayer_pays_tx_fee_when_submitting_justification_with_long_ancestry_votes

* clippy

* fmt

* clippy

* small change in docs

* fixed GRANDPA-limits constants for Polkadot-like chains

* clippy

* clippy + spelling

* Update primitives/polkadot-core/src/lib.rs

Co-authored-by: Adrian Catangiu <adrian@parity.io>

* Update bin/runtime-common/src/refund_relayer_extension.rs

Co-authored-by: Adrian Catangiu <adrian@parity.io>

* reverted unnecessary change

* GrandpaJustification::max_reasonable_size

---------

Co-authored-by: Adrian Catangiu <adrian@parity.io>
This commit is contained in:
Svyatoslav Nikolsky
2023-02-22 09:51:11 +03:00
committed by Bastian Köcher
parent 1aa6da448f
commit 498a3e83d0
10 changed files with 643 additions and 195 deletions
@@ -16,14 +16,16 @@
//! Tests for Grandpa Justification code.
use bp_header_chain::justification::{optimize_justification, verify_justification, Error};
use bp_header_chain::justification::{
optimize_justification, required_justification_precommits, verify_justification, Error,
};
use bp_test_utils::*;
type TestHeader = sp_runtime::testing::Header;
#[test]
fn valid_justification_accepted() {
let authorities = vec![(ALICE, 1), (BOB, 1), (CHARLIE, 1), (DAVE, 1)];
let authorities = vec![(ALICE, 1), (BOB, 1), (CHARLIE, 1)];
let params = JustificationGeneratorParams {
header: test_header(1),
round: TEST_GRANDPA_ROUND,
@@ -54,7 +56,7 @@ fn valid_justification_accepted_with_single_fork() {
header: test_header(1),
round: TEST_GRANDPA_ROUND,
set_id: TEST_GRANDPA_SET_ID,
authorities: vec![(ALICE, 1), (BOB, 1), (CHARLIE, 1), (DAVE, 1), (EVE, 1)],
authorities: vec![(ALICE, 1), (BOB, 1), (CHARLIE, 1)],
ancestors: 5,
forks: 1,
};
@@ -76,15 +78,16 @@ fn valid_justification_accepted_with_arbitrary_number_of_authorities() {
use sp_finality_grandpa::AuthorityId;
let n = 15;
let required_signatures = required_justification_precommits(n as _);
let authorities = accounts(n).iter().map(|k| (*k, 1)).collect::<Vec<_>>();
let params = JustificationGeneratorParams {
header: test_header(1),
round: TEST_GRANDPA_ROUND,
set_id: TEST_GRANDPA_SET_ID,
authorities: authorities.clone(),
authorities: authorities.clone().into_iter().take(required_signatures as _).collect(),
ancestors: n.into(),
forks: n.into(),
forks: required_signatures,
};
let authorities = authorities