Skip to content

Commit ce701dd

Browse files
authored
separate constants for average and worst case relay headers (#2728)
* separate constants for average and worst case relay headers * fix compilation
1 parent 09215c5 commit ce701dd

File tree

10 files changed

+37
-3
lines changed

10 files changed

+37
-3
lines changed

bin/runtime-common/src/mock.rs

+1
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ impl ChainWithGrandpa for BridgedUnderlyingChain {
378378
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8;
379379
const MAX_HEADER_SIZE: u32 = 256;
380380
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
381+
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
381382
}
382383

383384
impl Chain for BridgedUnderlyingParachain {

modules/grandpa/src/mock.rs

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ impl ChainWithGrandpa for TestBridgedChain {
8888
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8;
8989
const MAX_HEADER_SIZE: u32 = 256;
9090
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
91+
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
9192
}
9293

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

modules/parachains/src/mock.rs

+2
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ impl ChainWithGrandpa for TestBridgedChain {
254254
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8;
255255
const MAX_HEADER_SIZE: u32 = 256;
256256
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
257+
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
257258
}
258259

259260
#[derive(Debug)]
@@ -285,6 +286,7 @@ impl ChainWithGrandpa for OtherBridgedChain {
285286
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8;
286287
const MAX_HEADER_SIZE: u32 = 256;
287288
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
289+
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
288290
}
289291

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

primitives/chain-kusama/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ impl ChainWithGrandpa for Kusama {
5454
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
5555
const MAX_HEADER_SIZE: u32 = MAX_HEADER_SIZE;
5656
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;
5758
}
5859

5960
// The SignedExtension used by Kusama.

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

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub use bp_polkadot_core::{
4444
AccountAddress, AccountId, Balance, Block, BlockNumber, Hash, Hasher, Header, Nonce, Signature,
4545
SignedBlock, UncheckedExtrinsic, AVERAGE_HEADER_SIZE_IN_JUSTIFICATION,
4646
EXTRA_STORAGE_PROOF_SIZE, MAX_HEADER_SIZE, REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY,
47+
WORST_HEADER_SIZE_IN_JUSTIFICATION,
4748
};
4849

4950
/// Maximal number of GRANDPA authorities at Polkadot Bulletin chain.
@@ -209,6 +210,7 @@ impl ChainWithGrandpa for PolkadotBulletin {
209210
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
210211
const MAX_HEADER_SIZE: u32 = MAX_HEADER_SIZE;
211212
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;
212214
}
213215

214216
decl_bridge_finality_runtime_apis!(polkadot_bulletin, grandpa);

primitives/chain-polkadot/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ impl ChainWithGrandpa for Polkadot {
5454
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
5555
const MAX_HEADER_SIZE: u32 = MAX_HEADER_SIZE;
5656
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;
5758
}
5859

5960
/// The SignedExtension used by Polkadot.

primitives/chain-rococo/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ impl ChainWithGrandpa for Rococo {
5454
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
5555
const MAX_HEADER_SIZE: u32 = MAX_HEADER_SIZE;
5656
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;
5758
}
5859

5960
parameter_types! {

primitives/chain-westend/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ impl ChainWithGrandpa for Westend {
5454
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
5555
const MAX_HEADER_SIZE: u32 = MAX_HEADER_SIZE;
5656
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;
5758
}
5859

5960
parameter_types! {

primitives/header-chain/src/lib.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,22 @@ pub trait ChainWithGrandpa: Chain {
280280
/// headers that aren't changing the set.
281281
///
282282
/// This isn't a strict limit. The relay may submit justifications with larger headers in its
283+
/// ancestry and the pallet will accept the call. The limit is only used to compute fee, paid
284+
/// by the user at the sending chain. It covers most of cases, but if the actual header,
285+
/// submitted with the messages transaction will be larger than the
286+
/// `AVERAGE_HEADER_SIZE_IN_JUSTIFICATION`, the difference (`WORST_HEADER_SIZE_IN_JUSTIFICATION`
287+
/// - `AVERAGE_HEADER_SIZE_IN_JUSTIFICATION`) must be covered by the sending chain.
288+
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32;
289+
290+
/// Worst-case size of the chain header from justification ancestry. We don't expect to see
291+
/// there headers that change GRANDPA authorities set (GRANDPA will probably be able to finalize
292+
/// at least one additional header per session on non test chains), so this is the worst-case
293+
/// size of headers that aren't changing the set.
294+
///
295+
/// This isn't a strict limit. The relay may submit justifications with larger headers in its
283296
/// ancestry and the pallet will accept the call. The limit is only used to compute maximal
284297
/// refund amount and doing calls which exceed the limit, may be costly to submitter.
285-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32;
298+
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32;
286299
}
287300

288301
impl<T> ChainWithGrandpa for T
@@ -298,4 +311,6 @@ where
298311
const MAX_HEADER_SIZE: u32 = <T::Chain as ChainWithGrandpa>::MAX_HEADER_SIZE;
299312
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 =
300313
<T::Chain as ChainWithGrandpa>::AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
314+
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 =
315+
<T::Chain as ChainWithGrandpa>::WORST_HEADER_SIZE_IN_JUSTIFICATION;
301316
}

primitives/polkadot-core/src/lib.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,16 @@ pub const MAX_AUTHORITIES_COUNT: u32 = 1_256;
7070
/// reserve here.
7171
pub const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 2;
7272

73-
/// Approximate average header size in `votes_ancestries` field of justification on Polkadot-like
73+
/// Average header size in `votes_ancestries` field of justification on Polkadot-like
74+
/// chains.
75+
///
76+
/// See [`bp-header-chain::ChainWithGrandpa`] for more details.
77+
///
78+
/// This value comes from recent (February, 2023) Kusama headers. Average is `336` there, but let's
79+
/// have some reserve and make it 1024.
80+
pub const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 1024;
81+
82+
/// Worst-case header size in `votes_ancestries` field of justification on Polkadot-like
7483
/// chains.
7584
///
7685
/// See [`bp-header-chain::ChainWithGrandpa`] for more details.
@@ -79,7 +88,7 @@ pub const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 2;
7988
/// non-mandatory headers has size `40kb` (they contain the BABE epoch descriptor with all
8089
/// authorities - just like our mandatory header). Since we assume `2` headers in justification
8190
/// votes ancestry, let's set average header to `40kb / 2`.
82-
pub const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 20 * 1024;
91+
pub const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 20 * 1024;
8392

8493
/// Approximate maximal header size on Polkadot-like chains.
8594
///

0 commit comments

Comments
 (0)