Skip to content

Commit afa5627

Browse files
authored
Select header that will be fully refunded in on-demand batch finality relay (paritytech#2729)
* select header that will be fully refunded for submission in on-demand **batch** finality relay * added the only possible test * spelling * nl * updated comment
1 parent 81e7947 commit afa5627

15 files changed

Lines changed: 222 additions & 115 deletions

File tree

bridges/bin/runtime-common/src/mock.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,8 @@ impl ChainWithGrandpa for BridgedUnderlyingChain {
376376
const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = "";
377377
const MAX_AUTHORITIES_COUNT: u32 = 16;
378378
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8;
379-
const MAX_HEADER_SIZE: u32 = 256;
380-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
381-
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
379+
const MAX_MANDATORY_HEADER_SIZE: u32 = 256;
380+
const AVERAGE_HEADER_SIZE: u32 = 64;
382381
}
383382

384383
impl Chain for BridgedUnderlyingParachain {

bridges/modules/grandpa/src/call_ext.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
1616

1717
use crate::{weights::WeightInfo, BridgedBlockNumber, BridgedHeader, Config, Error, Pallet};
18-
use bp_header_chain::{justification::GrandpaJustification, ChainWithGrandpa};
18+
use bp_header_chain::{
19+
justification::GrandpaJustification, max_expected_submit_finality_proof_arguments_size,
20+
ChainWithGrandpa, GrandpaConsensusLogReader,
21+
};
1922
use bp_runtime::{BlockNumberOf, OwnedBridgeModule};
2023
use codec::Encode;
2124
use frame_support::{dispatch::CallableCallFor, traits::IsSubType, weights::Weight};
@@ -169,28 +172,28 @@ pub(crate) fn submit_finality_proof_info_from_args<T: Config<I>, I: 'static>(
169172
Weight::zero()
170173
};
171174

175+
// check if the `finality_target` is a mandatory header. If so, we are ready to refund larger
176+
// size
177+
let is_mandatory_finality_target =
178+
GrandpaConsensusLogReader::<BridgedBlockNumber<T, I>>::find_scheduled_change(
179+
finality_target.digest(),
180+
)
181+
.is_some();
182+
172183
// we can estimate extra call size easily, without any additional significant overhead
173184
let actual_call_size: u32 = finality_target
174185
.encoded_size()
175186
.saturating_add(justification.encoded_size())
176187
.saturated_into();
177-
let max_expected_call_size = max_expected_call_size::<T, I>(required_precommits);
188+
let max_expected_call_size = max_expected_submit_finality_proof_arguments_size::<T::BridgedChain>(
189+
is_mandatory_finality_target,
190+
required_precommits,
191+
);
178192
let extra_size = actual_call_size.saturating_sub(max_expected_call_size);
179193

180194
SubmitFinalityProofInfo { block_number, extra_weight, extra_size }
181195
}
182196

183-
/// Returns maximal expected size of `submit_finality_proof` call arguments.
184-
fn max_expected_call_size<T: Config<I>, I: 'static>(required_precommits: u32) -> u32 {
185-
let max_expected_justification_size =
186-
GrandpaJustification::<BridgedHeader<T, I>>::max_reasonable_size::<T::BridgedChain>(
187-
required_precommits,
188-
);
189-
190-
// call arguments are header and justification
191-
T::BridgedChain::MAX_HEADER_SIZE.saturating_add(max_expected_justification_size)
192-
}
193-
194197
#[cfg(test)]
195198
mod tests {
196199
use crate::{

bridges/modules/grandpa/src/mock.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,8 @@ impl ChainWithGrandpa for TestBridgedChain {
8686
const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = "";
8787
const MAX_AUTHORITIES_COUNT: u32 = MAX_BRIDGED_AUTHORITIES;
8888
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8;
89-
const MAX_HEADER_SIZE: u32 = 256;
90-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
91-
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
89+
const MAX_MANDATORY_HEADER_SIZE: u32 = 256;
90+
const AVERAGE_HEADER_SIZE: u32 = 64;
9291
}
9392

9493
/// Return test externalities to use in tests.

bridges/modules/parachains/src/mock.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,8 @@ impl ChainWithGrandpa for TestBridgedChain {
252252
const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = "";
253253
const MAX_AUTHORITIES_COUNT: u32 = 16;
254254
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8;
255-
const MAX_HEADER_SIZE: u32 = 256;
256-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
257-
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
255+
const MAX_MANDATORY_HEADER_SIZE: u32 = 256;
256+
const AVERAGE_HEADER_SIZE: u32 = 64;
258257
}
259258

260259
#[derive(Debug)]
@@ -284,9 +283,8 @@ impl ChainWithGrandpa for OtherBridgedChain {
284283
const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = "";
285284
const MAX_AUTHORITIES_COUNT: u32 = 16;
286285
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8;
287-
const MAX_HEADER_SIZE: u32 = 256;
288-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
289-
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
286+
const MAX_MANDATORY_HEADER_SIZE: u32 = 256;
287+
const AVERAGE_HEADER_SIZE: u32 = 64;
290288
}
291289

292290
/// Return test externalities to use in tests.

bridges/primitives/chain-kusama/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ impl ChainWithGrandpa for Kusama {
5252
const MAX_AUTHORITIES_COUNT: u32 = MAX_AUTHORITIES_COUNT;
5353
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 =
5454
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
55-
const MAX_HEADER_SIZE: u32 = MAX_HEADER_SIZE;
56-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
57-
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = WORST_HEADER_SIZE_IN_JUSTIFICATION;
55+
const MAX_MANDATORY_HEADER_SIZE: u32 = MAX_MANDATORY_HEADER_SIZE;
56+
const AVERAGE_HEADER_SIZE: u32 = AVERAGE_HEADER_SIZE;
5857
}
5958

6059
// The SignedExtension used by Kusama.

bridges/primitives/chain-polkadot-bulletin/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ use sp_runtime::{traits::DispatchInfoOf, transaction_validity::TransactionValidi
4242
// This chain reuses most of Polkadot primitives.
4343
pub use bp_polkadot_core::{
4444
AccountAddress, AccountId, Balance, Block, BlockNumber, Hash, Hasher, Header, Nonce, Signature,
45-
SignedBlock, UncheckedExtrinsic, AVERAGE_HEADER_SIZE_IN_JUSTIFICATION,
46-
EXTRA_STORAGE_PROOF_SIZE, MAX_HEADER_SIZE, REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY,
47-
WORST_HEADER_SIZE_IN_JUSTIFICATION,
45+
SignedBlock, UncheckedExtrinsic, AVERAGE_HEADER_SIZE, EXTRA_STORAGE_PROOF_SIZE,
46+
MAX_MANDATORY_HEADER_SIZE, REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY,
4847
};
4948

5049
/// Maximal number of GRANDPA authorities at Polkadot Bulletin chain.
@@ -208,9 +207,8 @@ impl ChainWithGrandpa for PolkadotBulletin {
208207
const MAX_AUTHORITIES_COUNT: u32 = MAX_AUTHORITIES_COUNT;
209208
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 =
210209
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
211-
const MAX_HEADER_SIZE: u32 = MAX_HEADER_SIZE;
212-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
213-
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = WORST_HEADER_SIZE_IN_JUSTIFICATION;
210+
const MAX_MANDATORY_HEADER_SIZE: u32 = MAX_MANDATORY_HEADER_SIZE;
211+
const AVERAGE_HEADER_SIZE: u32 = AVERAGE_HEADER_SIZE;
214212
}
215213

216214
decl_bridge_finality_runtime_apis!(polkadot_bulletin, grandpa);

bridges/primitives/chain-polkadot/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ impl ChainWithGrandpa for Polkadot {
5252
const MAX_AUTHORITIES_COUNT: u32 = MAX_AUTHORITIES_COUNT;
5353
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 =
5454
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
55-
const MAX_HEADER_SIZE: u32 = MAX_HEADER_SIZE;
56-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
57-
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = WORST_HEADER_SIZE_IN_JUSTIFICATION;
55+
const MAX_MANDATORY_HEADER_SIZE: u32 = MAX_MANDATORY_HEADER_SIZE;
56+
const AVERAGE_HEADER_SIZE: u32 = AVERAGE_HEADER_SIZE;
5857
}
5958

6059
/// The SignedExtension used by Polkadot.

bridges/primitives/chain-rococo/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ impl ChainWithGrandpa for Rococo {
5252
const MAX_AUTHORITIES_COUNT: u32 = MAX_AUTHORITIES_COUNT;
5353
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 =
5454
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
55-
const MAX_HEADER_SIZE: u32 = MAX_HEADER_SIZE;
56-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
57-
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = WORST_HEADER_SIZE_IN_JUSTIFICATION;
55+
const MAX_MANDATORY_HEADER_SIZE: u32 = MAX_MANDATORY_HEADER_SIZE;
56+
const AVERAGE_HEADER_SIZE: u32 = AVERAGE_HEADER_SIZE;
5857
}
5958

6059
parameter_types! {

bridges/primitives/chain-westend/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ impl ChainWithGrandpa for Westend {
5252
const MAX_AUTHORITIES_COUNT: u32 = MAX_AUTHORITIES_COUNT;
5353
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 =
5454
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
55-
const MAX_HEADER_SIZE: u32 = MAX_HEADER_SIZE;
56-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
57-
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = WORST_HEADER_SIZE_IN_JUSTIFICATION;
55+
const MAX_MANDATORY_HEADER_SIZE: u32 = MAX_MANDATORY_HEADER_SIZE;
56+
const AVERAGE_HEADER_SIZE: u32 = AVERAGE_HEADER_SIZE;
5857
}
5958

6059
parameter_types! {

bridges/primitives/header-chain/src/justification/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ impl<H: HeaderT> GrandpaJustification<H> {
8282
.saturating_add(BlockNumberOf::<C>::max_encoded_len().saturated_into())
8383
.saturating_add(HashOf::<C>::max_encoded_len().saturated_into());
8484

85-
let max_expected_votes_ancestries_size = C::REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY
86-
.saturating_mul(C::AVERAGE_HEADER_SIZE_IN_JUSTIFICATION);
85+
let max_expected_votes_ancestries_size =
86+
C::REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY.saturating_mul(C::AVERAGE_HEADER_SIZE);
8787

8888
// justification is round number (u64=8b), a signed GRANDPA commit and the
8989
// `votes_ancestries` vector

0 commit comments

Comments
 (0)