Skip to content

Commit

Permalink
separate constants for average and worst case relay headers (#2728)
Browse files Browse the repository at this point in the history
* separate constants for average and worst case relay headers

* fix compilation
  • Loading branch information
svyatonik committed Dec 8, 2023
1 parent 2d22e14 commit 7a364bb
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions modules/grandpa/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl ChainWithGrandpa for TestBridgedChain {
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8;
const MAX_HEADER_SIZE: u32 = 256;
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
}

/// Return test externalities to use in tests.
Expand Down
1 change: 1 addition & 0 deletions modules/messages/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ impl ChainWithGrandpa for BridgedChain {
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 4;
const MAX_HEADER_SIZE: u32 = 4096;
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 4096;
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 8192;
}

impl ChainWithMessages for BridgedChain {
Expand Down
2 changes: 2 additions & 0 deletions modules/parachains/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ impl ChainWithGrandpa for TestBridgedChain {
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8;
const MAX_HEADER_SIZE: u32 = 256;
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
}

#[derive(Debug)]
Expand Down Expand Up @@ -309,6 +310,7 @@ impl ChainWithGrandpa for OtherBridgedChain {
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8;
const MAX_HEADER_SIZE: u32 = 256;
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
}

/// Return test externalities to use in tests.
Expand Down
1 change: 1 addition & 0 deletions modules/relayers/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ impl ChainWithGrandpa for BridgedUnderlyingChain {
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8;
const MAX_HEADER_SIZE: u32 = 256;
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 128;
}

impl ChainWithMessages for BridgedUnderlyingChain {
Expand Down
1 change: 1 addition & 0 deletions primitives/chain-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl ChainWithGrandpa for Kusama {
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
const MAX_HEADER_SIZE: u32 = MAX_HEADER_SIZE;
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = WORST_HEADER_SIZE_IN_JUSTIFICATION;
}

// The SignedExtension used by Kusama.
Expand Down
2 changes: 2 additions & 0 deletions primitives/chain-polkadot-bulletin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub use bp_polkadot_core::{
AccountAddress, AccountId, Balance, Block, BlockNumber, Hash, Hasher, Header, Nonce, Signature,
SignedBlock, UncheckedExtrinsic, AVERAGE_HEADER_SIZE_IN_JUSTIFICATION,
EXTRA_STORAGE_PROOF_SIZE, MAX_HEADER_SIZE, REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY,
WORST_HEADER_SIZE_IN_JUSTIFICATION,
};

/// Maximal number of GRANDPA authorities at Polkadot Bulletin chain.
Expand Down Expand Up @@ -215,6 +216,7 @@ impl ChainWithGrandpa for PolkadotBulletin {
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
const MAX_HEADER_SIZE: u32 = MAX_HEADER_SIZE;
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = WORST_HEADER_SIZE_IN_JUSTIFICATION;
}

impl ChainWithMessages for PolkadotBulletin {
Expand Down
1 change: 1 addition & 0 deletions primitives/chain-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl ChainWithGrandpa for Polkadot {
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
const MAX_HEADER_SIZE: u32 = MAX_HEADER_SIZE;
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = WORST_HEADER_SIZE_IN_JUSTIFICATION;
}

/// The SignedExtension used by Polkadot.
Expand Down
1 change: 1 addition & 0 deletions primitives/chain-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl ChainWithGrandpa for Rococo {
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
const MAX_HEADER_SIZE: u32 = MAX_HEADER_SIZE;
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = WORST_HEADER_SIZE_IN_JUSTIFICATION;
}

// The SignedExtension used by Rococo.
Expand Down
1 change: 1 addition & 0 deletions primitives/chain-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl ChainWithGrandpa for Westend {
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
const MAX_HEADER_SIZE: u32 = MAX_HEADER_SIZE;
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = WORST_HEADER_SIZE_IN_JUSTIFICATION;
}

// The SignedExtension used by Westend.
Expand Down
17 changes: 16 additions & 1 deletion primitives/header-chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,22 @@ pub trait ChainWithGrandpa: Chain {
/// headers that aren't changing the set.
///
/// This isn't a strict limit. The relay may submit justifications with larger headers in its
/// ancestry and the pallet will accept the call. The limit is only used to compute fee, paid
/// by the user at the sending chain. It covers most of cases, but if the actual header,
/// submitted with the messages transaction will be larger than the
/// `AVERAGE_HEADER_SIZE_IN_JUSTIFICATION`, the difference (`WORST_HEADER_SIZE_IN_JUSTIFICATION`
/// - `AVERAGE_HEADER_SIZE_IN_JUSTIFICATION`) must be covered by the sending chain.
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32;

/// Worst-case size of the chain header from justification ancestry. We don't expect to see
/// there headers that change GRANDPA authorities set (GRANDPA will probably be able to finalize
/// at least one additional header per session on non test chains), so this is the worst-case
/// size of headers that aren't changing the set.
///
/// This isn't a strict limit. The relay may submit justifications with larger headers in its
/// ancestry and the pallet will accept the call. The limit is only used to compute maximal
/// refund amount and doing calls which exceed the limit, may be costly to submitter.
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32;
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32;
}

impl<T> ChainWithGrandpa for T
Expand All @@ -302,4 +315,6 @@ where
const MAX_HEADER_SIZE: u32 = <T::Chain as ChainWithGrandpa>::MAX_HEADER_SIZE;
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 =
<T::Chain as ChainWithGrandpa>::AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 =
<T::Chain as ChainWithGrandpa>::WORST_HEADER_SIZE_IN_JUSTIFICATION;
}
13 changes: 11 additions & 2 deletions primitives/polkadot-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,16 @@ pub const MAX_AUTHORITIES_COUNT: u32 = 1_256;
/// reserve here.
pub const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 2;

/// Approximate average header size in `votes_ancestries` field of justification on Polkadot-like
/// Average header size in `votes_ancestries` field of justification on Polkadot-like
/// chains.
///
/// See [`bp-header-chain::ChainWithGrandpa`] for more details.
///
/// This value comes from recent (February, 2023) Kusama headers. Average is `336` there, but let's
/// have some reserve and make it 1024.
pub const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 1024;

/// Worst-case header size in `votes_ancestries` field of justification on Polkadot-like
/// chains.
///
/// See [`bp-header-chain::ChainWithGrandpa`] for more details.
Expand All @@ -82,7 +91,7 @@ pub const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 2;
/// non-mandatory headers has size `40kb` (they contain the BABE epoch descriptor with all
/// authorities - just like our mandatory header). Since we assume `2` headers in justification
/// votes ancestry, let's set average header to `40kb / 2`.
pub const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 20 * 1024;
pub const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 20 * 1024;

/// Approximate maximal header size on Polkadot-like chains.
///
Expand Down

0 comments on commit 7a364bb

Please sign in to comment.