Skip to content

Commit

Permalink
Add bridge_parachains pallet (#122)
Browse files Browse the repository at this point in the history
* Update Grandpa Name

* Add bridge parachain pallet

* Correct bridge message verify

* type HeadersToKeep

* Fix CI

* Fix CI
  • Loading branch information
jiguantong authored Dec 12, 2022
1 parent f2ce40c commit 5b19e28
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 46 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions node/src/chain_spec/crab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ pub fn genesis_config() -> ChainSpec {
base_fee: Default::default(),

// S2S stuff.
bridge_darwinia_grandpa: Default::default(),
bridge_polkadot_grandpa: Default::default(),
bridge_polkadot_parachain: Default::default(),
bridge_darwinia_messages: Default::default(),
darwinia_fee_market: Default::default(),
}
Expand Down Expand Up @@ -232,7 +233,12 @@ fn testnet_genesis(
transaction_payment: Default::default(),
assets: AssetsConfig {
assets: vec![(AssetIds::CKton as _, array_bytes::hex_n_into_unchecked(ALITH), true, 1)],
metadata: vec![(AssetIds::CKton as _, b"Crab Commitment Token".to_vec(), b"CKTON".to_vec(), 18)],
metadata: vec![(
AssetIds::CKton as _,
b"Crab Commitment Token".to_vec(),
b"CKTON".to_vec(),
18,
)],
..Default::default()
},

Expand Down Expand Up @@ -320,7 +326,8 @@ fn testnet_genesis(
base_fee: Default::default(),

// S2S stuff.
bridge_darwinia_grandpa: Default::default(),
bridge_polkadot_grandpa: Default::default(),
bridge_polkadot_parachain: Default::default(),
bridge_darwinia_messages: Default::default(),
darwinia_fee_market: Default::default(),
}
Expand Down
13 changes: 10 additions & 3 deletions node/src/chain_spec/darwinia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ pub fn genesis_config() -> ChainSpec {
base_fee: Default::default(),

// S2S stuff.
bridge_crab_grandpa: Default::default(),
bridge_kusama_grandpa: Default::default(),
bridge_kusama_parachain: Default::default(),
bridge_crab_messages: Default::default(),
crab_fee_market: Default::default(),
}
Expand Down Expand Up @@ -232,7 +233,12 @@ fn testnet_genesis(
transaction_payment: Default::default(),
assets: AssetsConfig {
assets: vec![(AssetIds::Kton as _, array_bytes::hex_n_into_unchecked(ALITH), true, 1)],
metadata: vec![(AssetIds::Kton as _, b"Darwinia Commitment Token".to_vec(), b"KTON".to_vec(), 18)],
metadata: vec![(
AssetIds::Kton as _,
b"Darwinia Commitment Token".to_vec(),
b"KTON".to_vec(),
18,
)],
..Default::default()
},

Expand Down Expand Up @@ -320,7 +326,8 @@ fn testnet_genesis(
base_fee: Default::default(),

// S2S stuff.
bridge_crab_grandpa: Default::default(),
bridge_kusama_grandpa: Default::default(),
bridge_kusama_parachain: Default::default(),
bridge_crab_messages: Default::default(),
crab_fee_market: Default::default(),
}
Expand Down
21 changes: 12 additions & 9 deletions runtime/crab/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ darwinia-staking = { default-features = false, path = "../../pa
dc-primitives = { default-features = false, path = "../../core/primitives" }

# darwinia-messages-substrate
bp-message-dispatch = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
bp-messages = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
bp-polkadot-core = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
bp-runtime = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
bridge-runtime-common = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
pallet-bridge-dispatch = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
pallet-bridge-grandpa = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
pallet-bridge-messages = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
pallet-fee-market = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
bp-message-dispatch = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
bp-messages = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
bp-polkadot-core = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
bp-runtime = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
bridge-runtime-common = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
pallet-bridge-dispatch = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
pallet-bridge-grandpa = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
pallet-bridge-messages = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
pallet-bridge-parachains = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
pallet-fee-market = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }

# frontier
fp-rpc = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" }
Expand Down Expand Up @@ -168,6 +169,7 @@ std = [
"pallet-bridge-dispatch/std",
"pallet-bridge-grandpa/std",
"pallet-bridge-messages/std",
"pallet-bridge-parachains/std",
"pallet-fee-market/std",

# frontier
Expand Down Expand Up @@ -256,6 +258,7 @@ runtime-benchmarks = [
"bridge-runtime-common/runtime-benchmarks",
"pallet-bridge-grandpa/runtime-benchmarks",
"pallet-bridge-messages/runtime-benchmarks",
"pallet-bridge-parachains/runtime-benchmarks",
"pallet-fee-market/runtime-benchmarks",

# frontier
Expand Down
18 changes: 11 additions & 7 deletions runtime/crab/src/bridges_message/darwinia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use sp_runtime::{FixedPointNumber, FixedU128};
// darwinia
use crate::*;
use bp_messages::{source_chain::*, target_chain::*, *};
use bp_polkadot_core::parachains::ParaId;
use bp_runtime::*;
use bridge_runtime_common::{
lanes::*,
Expand Down Expand Up @@ -155,11 +156,12 @@ impl TargetHeaderChain<ToDarwiniaMessagePayload, <Self as ChainWithMessages>::Ac
fn verify_messages_delivery_proof(
proof: Self::MessagesDeliveryProof,
) -> Result<(LaneId, InboundLaneData<bp_darwinia::AccountId>), Self::Error> {
source::verify_messages_delivery_proof::<
source::verify_messages_delivery_proof_from_parachain::<
WithDarwiniaMessageBridge,
bp_darwinia::Header,
Runtime,
WithDarwiniaGrandpa,
>(proof)
WithPolkadotParachainsInstance,
>(ParaId(2046), proof)
}
}
impl SourceHeaderChain<<Self as ChainWithMessages>::Balance> for Darwinia {
Expand All @@ -170,9 +172,11 @@ impl SourceHeaderChain<<Self as ChainWithMessages>::Balance> for Darwinia {
proof: Self::MessagesProof,
messages_count: u32,
) -> Result<ProvedMessages<Message<<Self as ChainWithMessages>::Balance>>, Self::Error> {
target::verify_messages_proof::<WithDarwiniaMessageBridge, Runtime, WithDarwiniaGrandpa>(
proof,
messages_count,
)
target::verify_messages_proof_from_parachain::<
WithDarwiniaMessageBridge,
bp_darwinia::Header,
Runtime,
WithPolkadotParachainsInstance,
>(ParaId(2046), proof, messages_count)
}
}
3 changes: 2 additions & 1 deletion runtime/crab/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ frame_support::construct_runtime! {
MessageTransact: darwinia_message_transact = 39,

// S2S stuff.
BridgeDarwiniaGrandpa: pallet_bridge_grandpa::<Instance1> = 35,
BridgePolkadotGrandpa: pallet_bridge_grandpa::<Instance1> = 35,
BridgePolkadotParachain: pallet_bridge_parachains::<Instance1> = 42,
BridgeDarwiniaMessages: pallet_bridge_messages::<Instance1> = 36,
BridgeDarwiniaDispatch: pallet_bridge_dispatch::<Instance1> = 37,
DarwiniaFeeMarket: pallet_fee_market::<Instance1> = 38
Expand Down
8 changes: 5 additions & 3 deletions runtime/crab/src/pallets/bridge_grandpa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pub use pallet_bridge_grandpa::Instance1 as WithDarwiniaGrandpa;
pub use pallet_bridge_grandpa::Instance1 as WithPolkadotGrandpa;

// darwinia
use crate::*;

impl pallet_bridge_grandpa::Config<WithDarwiniaGrandpa> for Runtime {
pub type PolkadotHeadersToKeep = ConstU32<500>;

impl pallet_bridge_grandpa::Config<WithPolkadotGrandpa> for Runtime {
type BridgedChain = bp_darwinia::DarwiniaLike;
type HeadersToKeep = ConstU32<500>;
type HeadersToKeep = PolkadotHeadersToKeep;
type MaxBridgedAuthorities = ();
type MaxBridgedHeaderSize = ();
type MaxRequests = ConstU32<50>;
Expand Down
36 changes: 36 additions & 0 deletions runtime/crab/src/pallets/bridge_parachains.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// This file is part of Darwinia.
//
// Copyright (C) 2018-2022 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Darwinia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pub use pallet_bridge_parachains::Instance1 as WithPolkadotParachainsInstance;

// darwinia
use crate::*;

frame_support::parameter_types! {
pub const ParasPalletName: &'static str = bp_polkadot_core::parachains::PARAS_PALLET_NAME;
}

impl pallet_bridge_parachains::Config<WithPolkadotParachainsInstance> for Runtime {
type BridgesGrandpaPalletInstance = WithPolkadotGrandpa;
type HeadsToKeep = PolkadotHeadersToKeep;
type MaxParaHeadSize = ConstU32<1024>;
type ParasPalletName = ParasPalletName;
type RuntimeEvent = RuntimeEvent;
type TrackedParachains = frame_support::traits::Everything;
type WeightInfo = ();
}
3 changes: 3 additions & 0 deletions runtime/crab/src/pallets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,8 @@ pub use bridge_grandpa::*;
mod bridge_messages;
pub use bridge_messages::*;

mod bridge_parachains;
pub use bridge_parachains::*;

mod fee_market;
pub use fee_market::*;
21 changes: 12 additions & 9 deletions runtime/darwinia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ darwinia-staking = { default-features = false, path = "../../pa
dc-primitives = { default-features = false, path = "../../core/primitives" }

# darwinia-messages-substrate
bp-message-dispatch = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
bp-messages = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
bp-polkadot-core = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
bp-runtime = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
bridge-runtime-common = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
pallet-bridge-dispatch = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
pallet-bridge-grandpa = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
pallet-bridge-messages = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
pallet-fee-market = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
bp-message-dispatch = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
bp-messages = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
bp-polkadot-core = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
bp-runtime = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
bridge-runtime-common = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
pallet-bridge-dispatch = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
pallet-bridge-grandpa = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
pallet-bridge-messages = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
pallet-bridge-parachains = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
pallet-fee-market = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }

# frontier
fp-rpc = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" }
Expand Down Expand Up @@ -168,6 +169,7 @@ std = [
"pallet-bridge-dispatch/std",
"pallet-bridge-grandpa/std",
"pallet-bridge-messages/std",
"pallet-bridge-parachains/std",
"pallet-fee-market/std",

# frontier
Expand Down Expand Up @@ -256,6 +258,7 @@ runtime-benchmarks = [
"bridge-runtime-common/runtime-benchmarks",
"pallet-bridge-grandpa/runtime-benchmarks",
"pallet-bridge-messages/runtime-benchmarks",
"pallet-bridge-parachains/runtime-benchmarks",
"pallet-fee-market/runtime-benchmarks",

# frontier
Expand Down
20 changes: 13 additions & 7 deletions runtime/darwinia/src/bridges_message/crab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use sp_runtime::{FixedPointNumber, FixedU128};
// darwinia
use crate::*;
use bp_messages::{source_chain::*, target_chain::*, *};
use bp_polkadot_core::parachains::ParaId;
use bp_runtime::*;
use bridge_runtime_common::{
lanes::*,
Expand Down Expand Up @@ -149,9 +150,12 @@ impl TargetHeaderChain<ToCrabMessagePayload, <Self as ChainWithMessages>::Accoun
fn verify_messages_delivery_proof(
proof: Self::MessagesDeliveryProof,
) -> Result<(LaneId, InboundLaneData<bp_crab::AccountId>), Self::Error> {
source::verify_messages_delivery_proof::<WithCrabMessageBridge, Runtime, WithCrabGrandpa>(
proof,
)
source::verify_messages_delivery_proof_from_parachain::<
WithCrabMessageBridge,
bp_crab::Header,
Runtime,
WithKusamaParachainsInstance,
>(ParaId(2105), proof)
}
}
impl SourceHeaderChain<<Self as ChainWithMessages>::Balance> for Crab {
Expand All @@ -162,9 +166,11 @@ impl SourceHeaderChain<<Self as ChainWithMessages>::Balance> for Crab {
proof: Self::MessagesProof,
messages_count: u32,
) -> Result<ProvedMessages<Message<<Self as ChainWithMessages>::Balance>>, Self::Error> {
target::verify_messages_proof::<WithCrabMessageBridge, Runtime, WithCrabGrandpa>(
proof,
messages_count,
)
target::verify_messages_proof_from_parachain::<
WithCrabMessageBridge,
bp_crab::Header,
Runtime,
WithKusamaParachainsInstance,
>(ParaId(2105), proof, messages_count)
}
}
3 changes: 2 additions & 1 deletion runtime/darwinia/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ frame_support::construct_runtime! {
MessageTransact: darwinia_message_transact = 39,

// S2S stuff.
BridgeCrabGrandpa: pallet_bridge_grandpa::<Instance1> = 35,
BridgeKusamaGrandpa: pallet_bridge_grandpa::<Instance1> = 35,
BridgeKusamaParachain: pallet_bridge_parachains::<Instance1> = 42,
BridgeCrabMessages: pallet_bridge_messages::<Instance1> = 36,
BridgeCrabDispatch: pallet_bridge_dispatch::<Instance1> = 37,
CrabFeeMarket: pallet_fee_market::<Instance1> = 38
Expand Down
8 changes: 5 additions & 3 deletions runtime/darwinia/src/pallets/bridge_grandpa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pub use pallet_bridge_grandpa::Instance1 as WithCrabGrandpa;
pub use pallet_bridge_grandpa::Instance1 as WithKusamaGrandpa;

// darwinia
use crate::*;

impl pallet_bridge_grandpa::Config<WithCrabGrandpa> for Runtime {
pub type KusamaHeadersToKeep = ConstU32<500>;

impl pallet_bridge_grandpa::Config<WithKusamaGrandpa> for Runtime {
type BridgedChain = bp_crab::DarwiniaLike;
type HeadersToKeep = ConstU32<500>;
type HeadersToKeep = KusamaHeadersToKeep;
type MaxBridgedAuthorities = ();
type MaxBridgedHeaderSize = ();
type MaxRequests = ConstU32<50>;
Expand Down
36 changes: 36 additions & 0 deletions runtime/darwinia/src/pallets/bridge_parachains.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// This file is part of Darwinia.
//
// Copyright (C) 2018-2022 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Darwinia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

pub use pallet_bridge_parachains::Instance1 as WithKusamaParachainsInstance;

// darwinia
use crate::*;

frame_support::parameter_types! {
pub const ParasPalletName: &'static str = bp_polkadot_core::parachains::PARAS_PALLET_NAME;
}

impl pallet_bridge_parachains::Config<WithKusamaParachainsInstance> for Runtime {
type BridgesGrandpaPalletInstance = WithKusamaGrandpa;
type HeadsToKeep = KusamaHeadersToKeep;
type MaxParaHeadSize = ConstU32<1024>;
type ParasPalletName = ParasPalletName;
type RuntimeEvent = RuntimeEvent;
type TrackedParachains = frame_support::traits::Everything;
type WeightInfo = ();
}
Loading

0 comments on commit 5b19e28

Please sign in to comment.