Skip to content

Commit

Permalink
only store header state root (pallet-bridge-grandpa) (paritytech#1699)
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik authored and serban300 committed Apr 9, 2024
1 parent 2fbb086 commit 8d0f43b
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 193 deletions.
11 changes: 2 additions & 9 deletions bridges/bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,8 @@ parameter_types! {
}

parameter_types! {
/// Maximal size of SCALE-encoded Rialto header.
pub const MaxRialtoHeaderSize: u32 = bp_rialto::MAX_HEADER_SIZE;

/// Maximal number of authorities at Westend.
pub const MaxAuthoritiesAtWestend: u32 = bp_westend::MAX_AUTHORITIES_COUNT;
/// Maximal size of SCALE-encoded Westend header.
pub const MaxWestendHeaderSize: u32 = bp_westend::MAX_HEADER_SIZE;
}

pub type RialtoGrandpaInstance = ();
Expand All @@ -432,7 +427,6 @@ impl pallet_bridge_grandpa::Config for Runtime {
type MaxRequests = ConstU32<50>;
type HeadersToKeep = HeadersToKeep;
type MaxBridgedAuthorities = MaxAuthoritiesAtRialto;
type MaxBridgedHeaderSize = MaxRialtoHeaderSize;

type WeightInfo = pallet_bridge_grandpa::weights::BridgeWeight<Runtime>;
}
Expand All @@ -443,7 +437,6 @@ impl pallet_bridge_grandpa::Config<WestendGrandpaInstance> for Runtime {
type MaxRequests = ConstU32<50>;
type HeadersToKeep = HeadersToKeep;
type MaxBridgedAuthorities = MaxAuthoritiesAtWestend;
type MaxBridgedHeaderSize = MaxWestendHeaderSize;

type WeightInfo = pallet_bridge_grandpa::weights::BridgeWeight<Runtime>;
}
Expand Down Expand Up @@ -871,13 +864,13 @@ impl_runtime_apis! {

impl bp_rialto::RialtoFinalityApi<Block> for Runtime {
fn best_finalized() -> Option<HeaderId<bp_rialto::Hash, bp_rialto::BlockNumber>> {
BridgeRialtoGrandpa::best_finalized().map(|header| header.id())
BridgeRialtoGrandpa::best_finalized()
}
}

impl bp_westend::WestendFinalityApi<Block> for Runtime {
fn best_finalized() -> Option<HeaderId<bp_westend::Hash, bp_westend::BlockNumber>> {
BridgeWestendGrandpa::best_finalized().map(|header| header.id())
BridgeWestendGrandpa::best_finalized()
}
}

Expand Down
7 changes: 2 additions & 5 deletions bridges/bin/rialto-parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

// A few exports that help ease life for downstream crates.
use bp_runtime::{HeaderId, HeaderIdProvider};
use bp_runtime::HeaderId;
pub use frame_support::{
construct_runtime,
dispatch::DispatchClass,
Expand Down Expand Up @@ -525,8 +525,6 @@ parameter_types! {

/// Maximal number of authorities at Millau.
pub const MaxAuthoritiesAtMillau: u32 = bp_millau::MAX_AUTHORITIES_COUNT;
/// Maximal size of SCALE-encoded Millau header.
pub const MaxMillauHeaderSize: u32 = bp_millau::MAX_HEADER_SIZE;
}

pub type MillauGrandpaInstance = ();
Expand All @@ -539,7 +537,6 @@ impl pallet_bridge_grandpa::Config for Runtime {
type MaxRequests = ConstU32<50>;
type HeadersToKeep = HeadersToKeep;
type MaxBridgedAuthorities = MaxAuthoritiesAtMillau;
type MaxBridgedHeaderSize = MaxMillauHeaderSize;
type WeightInfo = pallet_bridge_grandpa::weights::BridgeWeight<Runtime>;
}

Expand Down Expand Up @@ -728,7 +725,7 @@ impl_runtime_apis! {

impl bp_millau::MillauFinalityApi<Block> for Runtime {
fn best_finalized() -> Option<HeaderId<bp_millau::Hash, bp_millau::BlockNumber>> {
BridgeMillauGrandpa::best_finalized().map(|header| header.id())
BridgeMillauGrandpa::best_finalized()
}
}

Expand Down
7 changes: 2 additions & 5 deletions bridges/bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub mod parachains;
pub mod xcm_config;

use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion, ValidatorSet};
use bp_runtime::{HeaderId, HeaderIdProvider};
use bp_runtime::HeaderId;
use pallet_grandpa::{
fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList,
};
Expand Down Expand Up @@ -410,8 +410,6 @@ parameter_types! {

/// Maximal number of authorities at Millau.
pub const MaxAuthoritiesAtMillau: u32 = bp_millau::MAX_AUTHORITIES_COUNT;
/// Maximal size of SCALE-encoded Millau header.
pub const MaxMillauHeaderSize: u32 = bp_millau::MAX_HEADER_SIZE;
}

pub type MillauGrandpaInstance = ();
Expand All @@ -424,7 +422,6 @@ impl pallet_bridge_grandpa::Config for Runtime {
type MaxRequests = ConstU32<50>;
type HeadersToKeep = HeadersToKeep;
type MaxBridgedAuthorities = MaxAuthoritiesAtMillau;
type MaxBridgedHeaderSize = MaxMillauHeaderSize;
type WeightInfo = pallet_bridge_grandpa::weights::BridgeWeight<Runtime>;
}

Expand Down Expand Up @@ -721,7 +718,7 @@ impl_runtime_apis! {

impl bp_millau::MillauFinalityApi<Block> for Runtime {
fn best_finalized() -> Option<HeaderId<bp_millau::Hash, bp_millau::BlockNumber>> {
BridgeMillauGrandpa::best_finalized().map(|header| header.id())
BridgeMillauGrandpa::best_finalized()
}
}

Expand Down
9 changes: 4 additions & 5 deletions bridges/bin/runtime-common/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,6 @@ mod tests {
use crate::messages_generation::{
encode_all_messages, encode_lane_data, prepare_messages_storage_proof,
};
use bp_runtime::HeaderOf;
use codec::{Decode, Encode};
use frame_support::weights::Weight;
use sp_core::H256;
Expand Down Expand Up @@ -881,17 +880,17 @@ mod tests {
struct BridgedHeaderChain;

impl HeaderChain<BridgedUnderlyingChain> for BridgedHeaderChain {
fn finalized_header(
fn finalized_header_state_root(
_hash: HashOf<BridgedChain>,
) -> Option<HeaderOf<BridgedUnderlyingChain>> {
TEST_BRIDGED_HEADER.with(|h| h.borrow().clone())
) -> Option<HashOf<BridgedChain>> {
TEST_BRIDGED_HEADER.with(|h| h.borrow().clone()).map(|h| *h.state_root())
}
}

struct ThisHeaderChain;

impl HeaderChain<ThisUnderlyingChain> for ThisHeaderChain {
fn finalized_header(_hash: HashOf<ThisChain>) -> Option<HeaderOf<ThisUnderlyingChain>> {
fn finalized_header_state_root(_hash: HashOf<ThisChain>) -> Option<HashOf<ThisChain>> {
unreachable!()
}
}
Expand Down
5 changes: 3 additions & 2 deletions bridges/modules/grandpa/src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<

let best_finalized = crate::BestFinalized::<T, I>::get();
let best_finalized_number = match best_finalized {
Some((best_finalized_number, _)) => best_finalized_number,
Some(best_finalized_id) => best_finalized_id.number(),
None => return InvalidTransaction::Call.into(),
};

Expand All @@ -66,6 +66,7 @@ mod tests {
mock::{run_test, test_header, RuntimeCall, TestNumber, TestRuntime},
BestFinalized,
};
use bp_runtime::HeaderId;
use bp_test_utils::make_default_justification;

fn validate_block_submit(num: TestNumber) -> bool {
Expand All @@ -81,7 +82,7 @@ mod tests {

fn sync_to_header_10() {
let header10_hash = sp_core::H256::default();
BestFinalized::<TestRuntime, ()>::put((10, header10_hash));
BestFinalized::<TestRuntime, ()>::put(HeaderId(10, header10_hash));
}

#[test]
Expand Down
Loading

0 comments on commit 8d0f43b

Please sign in to comment.