Skip to content

Commit 83f3973

Browse files
committed
Select header that will be fully refunded in on-demand batch finality relay (#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 7a364bb commit 83f3973

File tree

17 files changed

+228
-121
lines changed

17 files changed

+228
-121
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/grandpa/src/call_ext.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
use crate::{weights::WeightInfo, BridgedBlockNumber, BridgedHeader, Config, Error, Pallet};
1818
use bp_header_chain::{
19-
justification::GrandpaJustification, ChainWithGrandpa, SubmitFinalityProofInfo,
19+
justification::GrandpaJustification, max_expected_submit_finality_proof_arguments_size,
20+
ChainWithGrandpa, GrandpaConsensusLogReader, SubmitFinalityProofInfo,
2021
};
2122
use bp_runtime::{BlockNumberOf, OwnedBridgeModule};
2223
use codec::Encode;
@@ -145,28 +146,28 @@ pub(crate) fn submit_finality_proof_info_from_args<T: Config<I>, I: 'static>(
145146
Weight::zero()
146147
};
147148

149+
// check if the `finality_target` is a mandatory header. If so, we are ready to refund larger
150+
// size
151+
let is_mandatory_finality_target =
152+
GrandpaConsensusLogReader::<BridgedBlockNumber<T, I>>::find_scheduled_change(
153+
finality_target.digest(),
154+
)
155+
.is_some();
156+
148157
// we can estimate extra call size easily, without any additional significant overhead
149158
let actual_call_size: u32 = finality_target
150159
.encoded_size()
151160
.saturating_add(justification.encoded_size())
152161
.saturated_into();
153-
let max_expected_call_size = max_expected_call_size::<T, I>(required_precommits);
162+
let max_expected_call_size = max_expected_submit_finality_proof_arguments_size::<T::BridgedChain>(
163+
is_mandatory_finality_target,
164+
required_precommits,
165+
);
154166
let extra_size = actual_call_size.saturating_sub(max_expected_call_size);
155167

156168
SubmitFinalityProofInfo { block_number, extra_weight, extra_size }
157169
}
158170

159-
/// Returns maximal expected size of `submit_finality_proof` call arguments.
160-
fn max_expected_call_size<T: Config<I>, I: 'static>(required_precommits: u32) -> u32 {
161-
let max_expected_justification_size =
162-
GrandpaJustification::<BridgedHeader<T, I>>::max_reasonable_size::<T::BridgedChain>(
163-
required_precommits,
164-
);
165-
166-
// call arguments are header and justification
167-
T::BridgedChain::MAX_HEADER_SIZE.saturating_add(max_expected_justification_size)
168-
}
169-
170171
#[cfg(test)]
171172
mod tests {
172173
use crate::{

modules/grandpa/src/mock.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ impl ChainWithGrandpa for TestBridgedChain {
9191
const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = "";
9292
const MAX_AUTHORITIES_COUNT: u32 = MAX_BRIDGED_AUTHORITIES;
9393
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8;
94-
const MAX_HEADER_SIZE: u32 = 256;
95-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
96-
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
94+
const MAX_MANDATORY_HEADER_SIZE: u32 = 256;
95+
const AVERAGE_HEADER_SIZE: u32 = 64;
9796
}
9897

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

modules/messages/src/tests/mock.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,8 @@ impl ChainWithGrandpa for BridgedChain {
134134
const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = "WithBridgedChainBridgeGrandpa";
135135
const MAX_AUTHORITIES_COUNT: u32 = 16;
136136
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 4;
137-
const MAX_HEADER_SIZE: u32 = 4096;
138-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 4096;
139-
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 8192;
137+
const AVERAGE_HEADER_SIZE: u32 = 4096;
138+
const MAX_MANDATORY_HEADER_SIZE: u32 = 8192;
140139
}
141140

142141
impl ChainWithMessages for BridgedChain {

modules/parachains/src/mock.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,8 @@ impl ChainWithGrandpa for TestBridgedChain {
272272
const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = "";
273273
const MAX_AUTHORITIES_COUNT: u32 = 16;
274274
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8;
275-
const MAX_HEADER_SIZE: u32 = 256;
276-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
277-
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
275+
const MAX_MANDATORY_HEADER_SIZE: u32 = 256;
276+
const AVERAGE_HEADER_SIZE: u32 = 64;
278277
}
279278

280279
#[derive(Debug)]
@@ -308,9 +307,8 @@ impl ChainWithGrandpa for OtherBridgedChain {
308307
const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = "";
309308
const MAX_AUTHORITIES_COUNT: u32 = 16;
310309
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8;
311-
const MAX_HEADER_SIZE: u32 = 256;
312-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
313-
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
310+
const MAX_MANDATORY_HEADER_SIZE: u32 = 256;
311+
const AVERAGE_HEADER_SIZE: u32 = 64;
314312
}
315313

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

modules/relayers/src/mock.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,8 @@ impl ChainWithGrandpa for BridgedUnderlyingChain {
146146
const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = "";
147147
const MAX_AUTHORITIES_COUNT: u32 = 16;
148148
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8;
149-
const MAX_HEADER_SIZE: u32 = 256;
150-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
151-
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 128;
149+
const AVERAGE_HEADER_SIZE: u32 = 64;
150+
const MAX_MANDATORY_HEADER_SIZE: u32 = 128;
152151
}
153152

154153
impl ChainWithMessages for BridgedUnderlyingChain {

primitives/chain-kusama/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ impl ChainWithGrandpa for Kusama {
5858
const MAX_AUTHORITIES_COUNT: u32 = MAX_AUTHORITIES_COUNT;
5959
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 =
6060
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
61-
const MAX_HEADER_SIZE: u32 = MAX_HEADER_SIZE;
62-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
63-
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = WORST_HEADER_SIZE_IN_JUSTIFICATION;
61+
const MAX_MANDATORY_HEADER_SIZE: u32 = MAX_MANDATORY_HEADER_SIZE;
62+
const AVERAGE_HEADER_SIZE: u32 = AVERAGE_HEADER_SIZE;
6463
}
6564

6665
// The SignedExtension used by Kusama.

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

+4-6
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ use sp_runtime::{
4444
// This chain reuses most of Polkadot primitives.
4545
pub use bp_polkadot_core::{
4646
AccountAddress, AccountId, Balance, Block, BlockNumber, Hash, Hasher, Header, Nonce, Signature,
47-
SignedBlock, UncheckedExtrinsic, AVERAGE_HEADER_SIZE_IN_JUSTIFICATION,
48-
EXTRA_STORAGE_PROOF_SIZE, MAX_HEADER_SIZE, REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY,
49-
WORST_HEADER_SIZE_IN_JUSTIFICATION,
47+
SignedBlock, UncheckedExtrinsic, AVERAGE_HEADER_SIZE, EXTRA_STORAGE_PROOF_SIZE,
48+
MAX_MANDATORY_HEADER_SIZE, REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY,
5049
};
5150

5251
/// Maximal number of GRANDPA authorities at Polkadot Bulletin chain.
@@ -214,9 +213,8 @@ impl ChainWithGrandpa for PolkadotBulletin {
214213
const MAX_AUTHORITIES_COUNT: u32 = MAX_AUTHORITIES_COUNT;
215214
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 =
216215
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
217-
const MAX_HEADER_SIZE: u32 = MAX_HEADER_SIZE;
218-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
219-
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = WORST_HEADER_SIZE_IN_JUSTIFICATION;
216+
const MAX_MANDATORY_HEADER_SIZE: u32 = MAX_MANDATORY_HEADER_SIZE;
217+
const AVERAGE_HEADER_SIZE: u32 = AVERAGE_HEADER_SIZE;
220218
}
221219

222220
impl ChainWithMessages for PolkadotBulletin {

primitives/chain-polkadot/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ impl ChainWithGrandpa for Polkadot {
6060
const MAX_AUTHORITIES_COUNT: u32 = MAX_AUTHORITIES_COUNT;
6161
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 =
6262
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
63-
const MAX_HEADER_SIZE: u32 = MAX_HEADER_SIZE;
64-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
65-
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = WORST_HEADER_SIZE_IN_JUSTIFICATION;
63+
const MAX_MANDATORY_HEADER_SIZE: u32 = MAX_MANDATORY_HEADER_SIZE;
64+
const AVERAGE_HEADER_SIZE: u32 = AVERAGE_HEADER_SIZE;
6665
}
6766

6867
/// The SignedExtension used by Polkadot.

primitives/chain-rococo/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ impl ChainWithGrandpa for Rococo {
5858
const MAX_AUTHORITIES_COUNT: u32 = MAX_AUTHORITIES_COUNT;
5959
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 =
6060
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
61-
const MAX_HEADER_SIZE: u32 = MAX_HEADER_SIZE;
62-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
63-
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = WORST_HEADER_SIZE_IN_JUSTIFICATION;
61+
const MAX_MANDATORY_HEADER_SIZE: u32 = MAX_MANDATORY_HEADER_SIZE;
62+
const AVERAGE_HEADER_SIZE: u32 = AVERAGE_HEADER_SIZE;
6463
}
6564

6665
// The SignedExtension used by Rococo.

primitives/chain-westend/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ impl ChainWithGrandpa for Westend {
5858
const MAX_AUTHORITIES_COUNT: u32 = MAX_AUTHORITIES_COUNT;
5959
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 =
6060
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
61-
const MAX_HEADER_SIZE: u32 = MAX_HEADER_SIZE;
62-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
63-
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = WORST_HEADER_SIZE_IN_JUSTIFICATION;
61+
const MAX_MANDATORY_HEADER_SIZE: u32 = MAX_MANDATORY_HEADER_SIZE;
62+
const AVERAGE_HEADER_SIZE: u32 = AVERAGE_HEADER_SIZE;
6463
}
6564

6665
// The SignedExtension used by Westend.

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

+2-2
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

primitives/header-chain/src/lib.rs

+83-30
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use crate::justification::{
2424
GrandpaJustification, JustificationVerificationContext, JustificationVerificationError,
2525
};
2626
use bp_runtime::{
27-
BasicOperatingMode, Chain, HashOf, HasherOf, StorageProofError, UnderlyingChainProvider,
28-
UnverifiedStorageProof, VerifiedStorageProof,
27+
BasicOperatingMode, Chain, HashOf, HasherOf, HeaderOf, StorageProofError,
28+
UnderlyingChainProvider, UnverifiedStorageProof, VerifiedStorageProof,
2929
};
3030
use codec::{Codec, Decode, Encode, EncodeLike, MaxEncodedLen};
3131
use core::{clone::Clone, cmp::Eq, default::Default, fmt::Debug};
@@ -270,36 +270,28 @@ pub trait ChainWithGrandpa: Chain {
270270
/// to submitter.
271271
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32;
272272

273-
/// Maximal size of the chain header. The header may be the header that enacts new GRANDPA
274-
/// authorities set (so it has large digest inside).
273+
/// Maximal size of the mandatory chain header. Mandatory header is the header that enacts new
274+
/// GRANDPA authorities set (so it has large digest inside).
275275
///
276276
/// This isn't a strict limit. The relay may submit larger headers and the pallet will accept
277277
/// the call. The limit is only used to compute maximal refund amount and doing calls which
278278
/// exceed the limit, may be costly to submitter.
279-
const MAX_HEADER_SIZE: u32;
279+
const MAX_MANDATORY_HEADER_SIZE: u32;
280280

281-
/// Average size of the chain header from justification ancestry. We don't expect to see there
282-
/// headers that change GRANDPA authorities set (GRANDPA will probably be able to finalize at
283-
/// least one additional header per session on non test chains), so this is average size of
284-
/// headers that aren't changing the set.
281+
/// Average size of the chain header. We don't expect to see there headers that change GRANDPA
282+
/// authorities set (GRANDPA will probably be able to finalize at least one additional header
283+
/// per session on non test chains), so this is average size of headers that aren't changing the
284+
/// set.
285285
///
286-
/// This isn't a strict limit. The relay may submit justifications with larger headers in its
287-
/// ancestry and the pallet will accept the call. The limit is only used to compute fee, paid
288-
/// by the user at the sending chain. It covers most of cases, but if the actual header,
289-
/// submitted with the messages transaction will be larger than the
290-
/// `AVERAGE_HEADER_SIZE_IN_JUSTIFICATION`, the difference (`WORST_HEADER_SIZE_IN_JUSTIFICATION`
291-
/// - `AVERAGE_HEADER_SIZE_IN_JUSTIFICATION`) must be covered by the sending chain.
292-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32;
293-
294-
/// Worst-case size of the chain header from justification ancestry. We don't expect to see
295-
/// there headers that change GRANDPA authorities set (GRANDPA will probably be able to finalize
296-
/// at least one additional header per session on non test chains), so this is the worst-case
297-
/// size of headers that aren't changing the set.
286+
/// This isn't a strict limit. The relay may submit justifications with larger headers and the
287+
/// pallet will accept the call. However, if the total size of all `submit_finality_proof`
288+
/// arguments exceeds the maximal size, computed using this average size, relayer will only get
289+
/// partial refund.
298290
///
299-
/// This isn't a strict limit. The relay may submit justifications with larger headers in its
300-
/// ancestry and the pallet will accept the call. The limit is only used to compute maximal
301-
/// refund amount and doing calls which exceed the limit, may be costly to submitter.
302-
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32;
291+
/// We expect some headers on production chains that are above this size. But they are rare and
292+
/// if rellayer cares about its profitability, we expect it'll select other headers for
293+
/// submission.
294+
const AVERAGE_HEADER_SIZE: u32;
303295
}
304296

305297
impl<T> ChainWithGrandpa for T
@@ -312,9 +304,70 @@ where
312304
const MAX_AUTHORITIES_COUNT: u32 = <T::Chain as ChainWithGrandpa>::MAX_AUTHORITIES_COUNT;
313305
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 =
314306
<T::Chain as ChainWithGrandpa>::REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
315-
const MAX_HEADER_SIZE: u32 = <T::Chain as ChainWithGrandpa>::MAX_HEADER_SIZE;
316-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 =
317-
<T::Chain as ChainWithGrandpa>::AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
318-
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 =
319-
<T::Chain as ChainWithGrandpa>::WORST_HEADER_SIZE_IN_JUSTIFICATION;
307+
const MAX_MANDATORY_HEADER_SIZE: u32 =
308+
<T::Chain as ChainWithGrandpa>::MAX_MANDATORY_HEADER_SIZE;
309+
const AVERAGE_HEADER_SIZE: u32 = <T::Chain as ChainWithGrandpa>::AVERAGE_HEADER_SIZE;
310+
}
311+
312+
/// Returns maximal expected size of `submit_finality_proof` call arguments.
313+
pub fn max_expected_submit_finality_proof_arguments_size<C: ChainWithGrandpa>(
314+
is_mandatory_finality_target: bool,
315+
precommits: u32,
316+
) -> u32 {
317+
let max_expected_justification_size =
318+
GrandpaJustification::<HeaderOf<C>>::max_reasonable_size::<C>(precommits);
319+
320+
// call arguments are header and justification
321+
let max_expected_finality_target_size = if is_mandatory_finality_target {
322+
C::MAX_MANDATORY_HEADER_SIZE
323+
} else {
324+
C::AVERAGE_HEADER_SIZE
325+
};
326+
max_expected_finality_target_size.saturating_add(max_expected_justification_size)
327+
}
328+
329+
#[cfg(test)]
330+
mod tests {
331+
use super::*;
332+
use bp_runtime::ChainId;
333+
use frame_support::weights::Weight;
334+
use sp_runtime::{testing::H256, traits::BlakeTwo256, MultiSignature, StateVersion};
335+
336+
struct TestChain;
337+
338+
impl Chain for TestChain {
339+
const ID: ChainId = *b"test";
340+
const STATE_VERSION: StateVersion = StateVersion::V1;
341+
type BlockNumber = u32;
342+
type Hash = H256;
343+
type Hasher = BlakeTwo256;
344+
type Header = sp_runtime::generic::Header<u32, BlakeTwo256>;
345+
type AccountId = u64;
346+
type Balance = u64;
347+
type Nonce = u64;
348+
type Signature = MultiSignature;
349+
350+
fn max_extrinsic_size() -> u32 {
351+
0
352+
}
353+
fn max_extrinsic_weight() -> Weight {
354+
Weight::zero()
355+
}
356+
}
357+
358+
impl ChainWithGrandpa for TestChain {
359+
const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = "Test";
360+
const MAX_AUTHORITIES_COUNT: u32 = 128;
361+
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 2;
362+
const MAX_MANDATORY_HEADER_SIZE: u32 = 100_000;
363+
const AVERAGE_HEADER_SIZE: u32 = 1_024;
364+
}
365+
366+
#[test]
367+
fn max_expected_submit_finality_proof_arguments_size_respects_mandatory_argument() {
368+
assert!(
369+
max_expected_submit_finality_proof_arguments_size::<TestChain>(true, 100) >
370+
max_expected_submit_finality_proof_arguments_size::<TestChain>(false, 100),
371+
);
372+
}
320373
}

primitives/polkadot-core/src/lib.rs

+7-18
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub const MAX_AUTHORITIES_COUNT: u32 = 1_256;
6767
///
6868
/// See [`bp-header-chain::ChainWithGrandpa`] for more details.
6969
///
70-
/// This value comes from recent (February, 2023) Kusama and Polkadot headers. There are no
70+
/// This value comes from recent (December, 2023) Kusama and Polkadot headers. There are no
7171
/// justifications with any additional headers in votes ancestry, so reasonable headers may
7272
/// be set to zero. But we assume that there may be small GRANDPA lags, so we're leaving some
7373
/// reserve here.
@@ -78,28 +78,17 @@ pub const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 2;
7878
///
7979
/// See [`bp-header-chain::ChainWithGrandpa`] for more details.
8080
///
81-
/// This value comes from recent (February, 2023) Kusama headers. Average is `336` there, but let's
82-
/// have some reserve and make it 1024.
83-
pub const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 1024;
84-
85-
/// Worst-case header size in `votes_ancestries` field of justification on Polkadot-like
86-
/// chains.
87-
///
88-
/// See [`bp-header-chain::ChainWithGrandpa`] for more details.
89-
///
90-
/// This value comes from recent (February, 2023) Kusama headers. Average is `336` there, but some
91-
/// non-mandatory headers has size `40kb` (they contain the BABE epoch descriptor with all
92-
/// authorities - just like our mandatory header). Since we assume `2` headers in justification
93-
/// votes ancestry, let's set average header to `40kb / 2`.
94-
pub const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 20 * 1024;
81+
/// This value comes from recent (December, 2023) Kusama headers. Most of headers are `327` bytes
82+
/// there, but let's have some reserve and make it 1024.
83+
pub const AVERAGE_HEADER_SIZE: u32 = 1024;
9584

9685
/// Approximate maximal header size on Polkadot-like chains.
9786
///
9887
/// See [`bp-header-chain::ChainWithGrandpa`] for more details.
9988
///
100-
/// This value comes from recent (February, 2023) Kusama headers. Maximal header is a mandatory
101-
/// header. In its SCALE-encoded form it is `80348` bytes. Let's have some reserve here.
102-
pub const MAX_HEADER_SIZE: u32 = 90_000;
89+
/// This value comes from recent (December, 2023) Kusama headers. Maximal header is a mandatory
90+
/// header. In its SCALE-encoded form it is `113407` bytes. Let's have some reserve here.
91+
pub const MAX_MANDATORY_HEADER_SIZE: u32 = 120 * 1024;
10392

10493
/// Number of extra bytes (excluding size of storage value itself) of storage proof, built at
10594
/// Polkadot-like chain. This mostly depends on number of entries in the storage trie.

relays/bin-substrate/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ anyhow = "1.0"
1010
async-std = "1.9.0"
1111
async-trait = "0.1"
1212
codec = { package = "parity-scale-codec", version = "3.1.5" }
13+
env_logger = "0.10"
1314
futures = "0.3.29"
1415
hex = "0.4"
1516
log = "0.4.20"

0 commit comments

Comments
 (0)