Skip to content

Commit

Permalink
Only store header state root (pallet-bridge-parachains) (paritytech#1701
Browse files Browse the repository at this point in the history
)

* store block number ++ state root in parachains pallet

* fixed parachains finality APIs

* (test commit)

* removed test code

* deduplicated code a bit

* removed commented code

* spelling

* Update modules/parachains/src/lib.rs

Co-authored-by: Adrian Catangiu <[email protected]>

* Update modules/parachains/src/lib.rs

Co-authored-by: Adrian Catangiu <[email protected]>

* Update modules/parachains/src/mock.rs

Co-authored-by: Adrian Catangiu <[email protected]>

* added comment

Co-authored-by: Adrian Catangiu <[email protected]>
  • Loading branch information
2 people authored and serban300 committed Apr 9, 2024
1 parent c87965d commit 9e2e3c5
Show file tree
Hide file tree
Showing 22 changed files with 448 additions and 178 deletions.
2 changes: 2 additions & 0 deletions bridges/bin/millau/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ scale-info = { version = "2.1.1", default-features = false, features = ["derive"

bp-messages = { path = "../../../primitives/messages", default-features = false }
bp-millau = { path = "../../../primitives/chain-millau", default-features = false }
bp-parachains = { path = "../../../primitives/parachains", default-features = false }
bp-polkadot-core = { path = "../../../primitives/polkadot-core", default-features = false }
bp-relayers = { path = "../../../primitives/relayers", default-features = false }
bp-rialto = { path = "../../../primitives/chain-rialto", default-features = false }
Expand Down Expand Up @@ -84,6 +85,7 @@ std = [
"beefy-primitives/std",
"bp-messages/std",
"bp-millau/std",
"bp-parachains/std",
"bp-polkadot-core/std",
"bp-relayers/std",
"bp-rialto/std",
Expand Down
34 changes: 13 additions & 21 deletions bridges/bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ pub mod rialto_parachain_messages;
pub mod xcm_config;

use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion, ValidatorSet};
use bp_runtime::{HeaderId, HeaderIdProvider};
use codec::Decode;
use bp_parachains::SingleParaStoredHeaderDataBuilder;
use bp_runtime::HeaderId;
use pallet_grandpa::{
fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList,
};
Expand Down Expand Up @@ -522,8 +522,8 @@ parameter_types! {
pub const RialtoParachainId: u32 = bp_rialto_parachain::RIALTO_PARACHAIN_ID;
pub const RialtoParasPalletName: &'static str = bp_rialto::PARAS_PALLET_NAME;
pub const WestendParasPalletName: &'static str = bp_westend::PARAS_PALLET_NAME;
pub const MaxRialtoParaHeadSize: u32 = bp_rialto::MAX_NESTED_PARACHAIN_HEAD_SIZE;
pub const MaxWestendParaHeadSize: u32 = bp_westend::MAX_NESTED_PARACHAIN_HEAD_SIZE;
pub const MaxRialtoParaHeadDataSize: u32 = bp_rialto::MAX_NESTED_PARACHAIN_HEAD_DATA_SIZE;
pub const MaxWestendParaHeadDataSize: u32 = bp_westend::MAX_NESTED_PARACHAIN_HEAD_DATA_SIZE;
}

/// Instance of the with-Rialto parachains pallet.
Expand All @@ -534,9 +534,10 @@ impl pallet_bridge_parachains::Config<WithRialtoParachainsInstance> for Runtime
type WeightInfo = pallet_bridge_parachains::weights::BridgeWeight<Runtime>;
type BridgesGrandpaPalletInstance = RialtoGrandpaInstance;
type ParasPalletName = RialtoParasPalletName;
type TrackedParachains = frame_support::traits::Everything;
type ParaStoredHeaderDataBuilder =
SingleParaStoredHeaderDataBuilder<bp_rialto_parachain::RialtoParachain>;
type HeadsToKeep = HeadersToKeep;
type MaxParaHeadSize = MaxRialtoParaHeadSize;
type MaxParaHeadDataSize = MaxRialtoParaHeadDataSize;
}

/// Instance of the with-Westend parachains pallet.
Expand All @@ -547,9 +548,9 @@ impl pallet_bridge_parachains::Config<WithWestendParachainsInstance> for Runtime
type WeightInfo = pallet_bridge_parachains::weights::BridgeWeight<Runtime>;
type BridgesGrandpaPalletInstance = WestendGrandpaInstance;
type ParasPalletName = WestendParasPalletName;
type TrackedParachains = frame_support::traits::Everything;
type ParaStoredHeaderDataBuilder = SingleParaStoredHeaderDataBuilder<bp_westend::Westmint>;
type HeadsToKeep = HeadersToKeep;
type MaxParaHeadSize = MaxWestendParaHeadSize;
type MaxParaHeadDataSize = MaxWestendParaHeadDataSize;
}

impl pallet_utility::Config for Runtime {
Expand Down Expand Up @@ -902,28 +903,19 @@ impl_runtime_apis! {

impl bp_westend::WestmintFinalityApi<Block> for Runtime {
fn best_finalized() -> Option<HeaderId<bp_westend::Hash, bp_westend::BlockNumber>> {
// the parachains finality pallet is never decoding parachain heads, so it is
// only done in the integration code
use bp_westend::WESTMINT_PARACHAIN_ID;
let encoded_head = pallet_bridge_parachains::Pallet::<
pallet_bridge_parachains::Pallet::<
Runtime,
WithWestendParachainsInstance,
>::best_parachain_head(WESTMINT_PARACHAIN_ID.into())?;
let head = bp_westend::Header::decode(&mut &encoded_head.0[..]).ok()?;
Some(head.id())
>::best_parachain_head_id::<bp_westend::Westmint>().unwrap_or(None)
}
}

impl bp_rialto_parachain::RialtoParachainFinalityApi<Block> for Runtime {
fn best_finalized() -> Option<HeaderId<bp_rialto::Hash, bp_rialto::BlockNumber>> {
// the parachains finality pallet is never decoding parachain heads, so it is
// only done in the integration code
let encoded_head = pallet_bridge_parachains::Pallet::<
pallet_bridge_parachains::Pallet::<
Runtime,
WithRialtoParachainsInstance,
>::best_parachain_head(bp_rialto_parachain::RIALTO_PARACHAIN_ID.into())?;
let head = bp_rialto_parachain::Header::decode(&mut &encoded_head.0[..]).ok()?;
Some(head.id())
>::best_parachain_head_id::<bp_rialto_parachain::RialtoParachain>().unwrap_or(None)
}
}

Expand Down
1 change: 1 addition & 0 deletions bridges/modules/parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master",
[dev-dependencies]
bp-header-chain = { path = "../../primitives/header-chain" }
bp-test-utils = { path = "../../primitives/test-utils" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" }

[features]
Expand Down
Loading

0 comments on commit 9e2e3c5

Please sign in to comment.