Skip to content

Commit a11d77d

Browse files
svyatonikacatangiu
andauthored
Only store header state root (pallet-bridge-parachains) (paritytech#1701)
* 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 <adrian@parity.io> * Update modules/parachains/src/lib.rs Co-authored-by: Adrian Catangiu <adrian@parity.io> * Update modules/parachains/src/mock.rs Co-authored-by: Adrian Catangiu <adrian@parity.io> * added comment Co-authored-by: Adrian Catangiu <adrian@parity.io>
1 parent cc77fb1 commit a11d77d

File tree

22 files changed

+448
-178
lines changed

22 files changed

+448
-178
lines changed

bridges/bin/millau/runtime/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ scale-info = { version = "2.1.1", default-features = false, features = ["derive"
1616

1717
bp-messages = { path = "../../../primitives/messages", default-features = false }
1818
bp-millau = { path = "../../../primitives/chain-millau", default-features = false }
19+
bp-parachains = { path = "../../../primitives/parachains", default-features = false }
1920
bp-polkadot-core = { path = "../../../primitives/polkadot-core", default-features = false }
2021
bp-relayers = { path = "../../../primitives/relayers", default-features = false }
2122
bp-rialto = { path = "../../../primitives/chain-rialto", default-features = false }
@@ -84,6 +85,7 @@ std = [
8485
"beefy-primitives/std",
8586
"bp-messages/std",
8687
"bp-millau/std",
88+
"bp-parachains/std",
8789
"bp-polkadot-core/std",
8890
"bp-relayers/std",
8991
"bp-rialto/std",

bridges/bin/millau/runtime/src/lib.rs

+13-21
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ pub mod rialto_parachain_messages;
3333
pub mod xcm_config;
3434

3535
use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion, ValidatorSet};
36-
use bp_runtime::{HeaderId, HeaderIdProvider};
37-
use codec::Decode;
36+
use bp_parachains::SingleParaStoredHeaderDataBuilder;
37+
use bp_runtime::HeaderId;
3838
use pallet_grandpa::{
3939
fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList,
4040
};
@@ -522,8 +522,8 @@ parameter_types! {
522522
pub const RialtoParachainId: u32 = bp_rialto_parachain::RIALTO_PARACHAIN_ID;
523523
pub const RialtoParasPalletName: &'static str = bp_rialto::PARAS_PALLET_NAME;
524524
pub const WestendParasPalletName: &'static str = bp_westend::PARAS_PALLET_NAME;
525-
pub const MaxRialtoParaHeadSize: u32 = bp_rialto::MAX_NESTED_PARACHAIN_HEAD_SIZE;
526-
pub const MaxWestendParaHeadSize: u32 = bp_westend::MAX_NESTED_PARACHAIN_HEAD_SIZE;
525+
pub const MaxRialtoParaHeadDataSize: u32 = bp_rialto::MAX_NESTED_PARACHAIN_HEAD_DATA_SIZE;
526+
pub const MaxWestendParaHeadDataSize: u32 = bp_westend::MAX_NESTED_PARACHAIN_HEAD_DATA_SIZE;
527527
}
528528

529529
/// Instance of the with-Rialto parachains pallet.
@@ -534,9 +534,10 @@ impl pallet_bridge_parachains::Config<WithRialtoParachainsInstance> for Runtime
534534
type WeightInfo = pallet_bridge_parachains::weights::BridgeWeight<Runtime>;
535535
type BridgesGrandpaPalletInstance = RialtoGrandpaInstance;
536536
type ParasPalletName = RialtoParasPalletName;
537-
type TrackedParachains = frame_support::traits::Everything;
537+
type ParaStoredHeaderDataBuilder =
538+
SingleParaStoredHeaderDataBuilder<bp_rialto_parachain::RialtoParachain>;
538539
type HeadsToKeep = HeadersToKeep;
539-
type MaxParaHeadSize = MaxRialtoParaHeadSize;
540+
type MaxParaHeadDataSize = MaxRialtoParaHeadDataSize;
540541
}
541542

542543
/// Instance of the with-Westend parachains pallet.
@@ -547,9 +548,9 @@ impl pallet_bridge_parachains::Config<WithWestendParachainsInstance> for Runtime
547548
type WeightInfo = pallet_bridge_parachains::weights::BridgeWeight<Runtime>;
548549
type BridgesGrandpaPalletInstance = WestendGrandpaInstance;
549550
type ParasPalletName = WestendParasPalletName;
550-
type TrackedParachains = frame_support::traits::Everything;
551+
type ParaStoredHeaderDataBuilder = SingleParaStoredHeaderDataBuilder<bp_westend::Westmint>;
551552
type HeadsToKeep = HeadersToKeep;
552-
type MaxParaHeadSize = MaxWestendParaHeadSize;
553+
type MaxParaHeadDataSize = MaxWestendParaHeadDataSize;
553554
}
554555

555556
impl pallet_utility::Config for Runtime {
@@ -902,28 +903,19 @@ impl_runtime_apis! {
902903

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

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

bridges/modules/parachains/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master",
3030
[dev-dependencies]
3131
bp-header-chain = { path = "../../primitives/header-chain" }
3232
bp-test-utils = { path = "../../primitives/test-utils" }
33+
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
3334
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" }
3435

3536
[features]

0 commit comments

Comments
 (0)