Skip to content

Commit

Permalink
port FinalityApi::free_headers_interval from paritytech/parity-bridge…
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik committed Apr 16, 2024
1 parent 7aba809 commit 21962bd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
12 changes: 12 additions & 0 deletions bridges/primitives/runtime/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ macro_rules! decl_bridge_finality_runtime_apis {
pub const [<BEST_FINALIZED_ $chain:upper _HEADER_METHOD>]: &str =
stringify!([<$chain:camel FinalityApi_best_finalized>]);

/// Name of the `<ThisChain>FinalityApi::free_headers_interval` runtime method.
pub const [<FREE_HEADERS_INTERVAL_FOR_ $chain:upper _METHOD>]: &str =
stringify!([<$chain:camel FinalityApi_free_headers_interval>]);


$(
/// Name of the `<ThisChain>FinalityApi::accepted_<consensus>_finality_proofs`
/// runtime method.
Expand All @@ -330,6 +335,13 @@ macro_rules! decl_bridge_finality_runtime_apis {
/// Returns number and hash of the best finalized header known to the bridge module.
fn best_finalized() -> Option<bp_runtime::HeaderId<Hash, BlockNumber>>;

/// Returns free headers interval, if it is configured in the runtime.
/// The caller expects that if his transaction improves best known header
/// at least by the free_headers_interval`, it will be fee-free.
///
/// See [`pallet_bridge_grandpa::Config::FreeHeadersInterval`] for details.
fn free_headers_interval() -> Option<BlockNumber>;

$(
/// Returns the justifications accepted in the current block.
fn [<synced_headers_ $consensus:lower _info>](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ use frame_support::{
dispatch::DispatchClass,
genesis_builder_helper::{build_state, get_preset},
parameter_types,
traits::{ConstBool, ConstU32, ConstU64, ConstU8, TransformOrigin},
traits::{ConstBool, ConstU32, ConstU64, ConstU8, Get, TransformOrigin},
weights::{ConstantMultiplier, Weight},
PalletId,
};
Expand Down Expand Up @@ -962,6 +962,11 @@ impl_runtime_apis! {
fn best_finalized() -> Option<HeaderId<bp_westend::Hash, bp_westend::BlockNumber>> {
BridgeWestendGrandpa::best_finalized()
}
fn free_headers_interval() -> Option<bp_westend::BlockNumber> {
<Runtime as pallet_bridge_grandpa::Config<
bridge_common_config::BridgeGrandpaWestendInstance
>>::FreeHeadersInterval::get()
}
fn synced_headers_grandpa_info(
) -> Vec<bp_header_chain::StoredHeaderGrandpaInfo<bp_westend::Header>> {
BridgeWestendGrandpa::synced_headers_grandpa_info()
Expand All @@ -974,6 +979,10 @@ impl_runtime_apis! {
bp_bridge_hub_westend::BridgeHubWestend
>().unwrap_or(None)
}
fn free_headers_interval() -> Option<bp_bridge_hub_westend::BlockNumber> {
// "free interval" is not currently used for parachains
None
}
}

// This is exposed by BridgeHubRococo
Expand Down Expand Up @@ -1008,6 +1017,12 @@ impl_runtime_apis! {
BridgePolkadotBulletinGrandpa::best_finalized()
}

fn free_headers_interval() -> Option<bp_polkadot_bulletin::BlockNumber> {
<Runtime as pallet_bridge_grandpa::Config<
bridge_common_config::BridgeGrandpaRococoBulletinInstance
>>::FreeHeadersInterval::get()
}

fn synced_headers_grandpa_info(
) -> Vec<bp_header_chain::StoredHeaderGrandpaInfo<bp_polkadot_bulletin::Header>> {
BridgePolkadotBulletinGrandpa::synced_headers_grandpa_info()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ use frame_support::{
dispatch::DispatchClass,
genesis_builder_helper::{build_state, get_preset},
parameter_types,
traits::{ConstBool, ConstU32, ConstU64, ConstU8, TransformOrigin},
traits::{ConstBool, ConstU32, ConstU64, ConstU8, Get, TransformOrigin},
weights::{ConstantMultiplier, Weight},
PalletId,
};
Expand Down Expand Up @@ -711,6 +711,11 @@ impl_runtime_apis! {
fn best_finalized() -> Option<HeaderId<bp_rococo::Hash, bp_rococo::BlockNumber>> {
BridgeRococoGrandpa::best_finalized()
}
fn free_headers_interval() -> Option<bp_rococo::BlockNumber> {
<Runtime as pallet_bridge_grandpa::Config<
bridge_to_rococo_config::BridgeGrandpaRococoInstance
>>::FreeHeadersInterval::get()
}
fn synced_headers_grandpa_info(
) -> Vec<bp_header_chain::StoredHeaderGrandpaInfo<bp_rococo::Header>> {
BridgeRococoGrandpa::synced_headers_grandpa_info()
Expand All @@ -723,6 +728,10 @@ impl_runtime_apis! {
bp_bridge_hub_rococo::BridgeHubRococo
>().unwrap_or(None)
}
fn free_headers_interval() -> Option<bp_bridge_hub_rococo::BlockNumber> {
// "free interval" is not currently used for parachains
None
}
}

impl bp_bridge_hub_rococo::FromBridgeHubRococoInboundLaneApi<Block> for Runtime {
Expand Down

0 comments on commit 21962bd

Please sign in to comment.