diff --git a/Cargo.lock b/Cargo.lock
index f81586b72..c6892f3f6 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -15,7 +15,7 @@ dependencies = [
[[package]]
name = "account"
version = "0.1.1"
-source = "git+https://github.com/darwinia-network/moonbeam?branch=polkadot-v0.9.30#38c37cc41b9a97482292717aec58b305d5f627f4"
+source = "git+https://github.com/darwinia-network/moonbeam?branch=polkadot-v0.9.30#9d31c6120bb0f317053da9cac7fe7cd2a44f844c"
dependencies = [
"blake2-rfc",
"hex",
@@ -737,10 +737,27 @@ dependencies = [
"thiserror",
]
+[[package]]
+name = "bp-darwinia-core"
+version = "0.1.0"
+source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#eb71a8eea2679c8fe6cd04c7c98421a631f63838"
+dependencies = [
+ "account",
+ "bp-messages",
+ "bp-runtime",
+ "frame-support",
+ "frame-system",
+ "parity-scale-codec",
+ "scale-info",
+ "sp-core",
+ "sp-runtime",
+ "sp-std",
+]
+
[[package]]
name = "bp-header-chain"
version = "0.1.0"
-source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#9f1f451245784a0d2f4c943610c838bb1b7c8ac0"
+source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#eb71a8eea2679c8fe6cd04c7c98421a631f63838"
dependencies = [
"bp-runtime",
"finality-grandpa",
@@ -757,7 +774,7 @@ dependencies = [
[[package]]
name = "bp-message-dispatch"
version = "0.1.0"
-source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#9f1f451245784a0d2f4c943610c838bb1b7c8ac0"
+source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#eb71a8eea2679c8fe6cd04c7c98421a631f63838"
dependencies = [
"bp-runtime",
"frame-support",
@@ -770,7 +787,7 @@ dependencies = [
[[package]]
name = "bp-messages"
version = "0.1.0"
-source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#9f1f451245784a0d2f4c943610c838bb1b7c8ac0"
+source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#eb71a8eea2679c8fe6cd04c7c98421a631f63838"
dependencies = [
"bitvec",
"bp-runtime",
@@ -787,7 +804,7 @@ dependencies = [
[[package]]
name = "bp-parachains"
version = "0.1.0"
-source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#9f1f451245784a0d2f4c943610c838bb1b7c8ac0"
+source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#eb71a8eea2679c8fe6cd04c7c98421a631f63838"
dependencies = [
"bp-polkadot-core",
"bp-runtime",
@@ -800,7 +817,7 @@ dependencies = [
[[package]]
name = "bp-polkadot-core"
version = "0.1.0"
-source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#9f1f451245784a0d2f4c943610c838bb1b7c8ac0"
+source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#eb71a8eea2679c8fe6cd04c7c98421a631f63838"
dependencies = [
"bp-messages",
"bp-runtime",
@@ -820,7 +837,7 @@ dependencies = [
[[package]]
name = "bp-runtime"
version = "0.1.0"
-source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#9f1f451245784a0d2f4c943610c838bb1b7c8ac0"
+source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#eb71a8eea2679c8fe6cd04c7c98421a631f63838"
dependencies = [
"frame-support",
"frame-system",
@@ -841,7 +858,7 @@ dependencies = [
[[package]]
name = "bp-test-utils"
version = "0.1.0"
-source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#9f1f451245784a0d2f4c943610c838bb1b7c8ac0"
+source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#eb71a8eea2679c8fe6cd04c7c98421a631f63838"
dependencies = [
"bp-header-chain",
"ed25519-dalek",
@@ -856,7 +873,7 @@ dependencies = [
[[package]]
name = "bridge-runtime-common"
version = "0.1.0"
-source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#9f1f451245784a0d2f4c943610c838bb1b7c8ac0"
+source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#eb71a8eea2679c8fe6cd04c7c98421a631f63838"
dependencies = [
"bp-message-dispatch",
"bp-messages",
@@ -2271,6 +2288,7 @@ dependencies = [
name = "darwinia-common-runtime"
version = "6.0.0"
dependencies = [
+ "bp-darwinia-core",
"dc-primitives",
"frame-support",
"frame-system",
@@ -6228,7 +6246,7 @@ dependencies = [
[[package]]
name = "pallet-bridge-dispatch"
version = "0.1.0"
-source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#9f1f451245784a0d2f4c943610c838bb1b7c8ac0"
+source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#eb71a8eea2679c8fe6cd04c7c98421a631f63838"
dependencies = [
"bp-message-dispatch",
"bp-runtime",
@@ -6244,7 +6262,7 @@ dependencies = [
[[package]]
name = "pallet-bridge-grandpa"
version = "0.1.0"
-source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#9f1f451245784a0d2f4c943610c838bb1b7c8ac0"
+source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#eb71a8eea2679c8fe6cd04c7c98421a631f63838"
dependencies = [
"bp-header-chain",
"bp-runtime",
@@ -6266,7 +6284,7 @@ dependencies = [
[[package]]
name = "pallet-bridge-messages"
version = "0.1.0"
-source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#9f1f451245784a0d2f4c943610c838bb1b7c8ac0"
+source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#eb71a8eea2679c8fe6cd04c7c98421a631f63838"
dependencies = [
"bitvec",
"bp-message-dispatch",
@@ -6287,7 +6305,7 @@ dependencies = [
[[package]]
name = "pallet-bridge-parachains"
version = "0.1.0"
-source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#9f1f451245784a0d2f4c943610c838bb1b7c8ac0"
+source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#eb71a8eea2679c8fe6cd04c7c98421a631f63838"
dependencies = [
"bp-parachains",
"bp-polkadot-core",
@@ -6554,7 +6572,7 @@ dependencies = [
[[package]]
name = "pallet-fee-market"
version = "0.1.0"
-source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#9f1f451245784a0d2f4c943610c838bb1b7c8ac0"
+source = "git+https://github.com/darwinia-network/darwinia-messages-substrate?branch=polkadot-v0.9.30#eb71a8eea2679c8fe6cd04c7c98421a631f63838"
dependencies = [
"bp-messages",
"bp-runtime",
@@ -8731,7 +8749,7 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "precompile-utils"
version = "0.1.0"
-source = "git+https://github.com/darwinia-network/moonbeam?branch=polkadot-v0.9.30#38c37cc41b9a97482292717aec58b305d5f627f4"
+source = "git+https://github.com/darwinia-network/moonbeam?branch=polkadot-v0.9.30#9d31c6120bb0f317053da9cac7fe7cd2a44f844c"
dependencies = [
"affix",
"evm",
@@ -8757,7 +8775,7 @@ dependencies = [
[[package]]
name = "precompile-utils-macro"
version = "0.1.0"
-source = "git+https://github.com/darwinia-network/moonbeam?branch=polkadot-v0.9.30#38c37cc41b9a97482292717aec58b305d5f627f4"
+source = "git+https://github.com/darwinia-network/moonbeam?branch=polkadot-v0.9.30#9d31c6120bb0f317053da9cac7fe7cd2a44f844c"
dependencies = [
"case",
"num_enum",
@@ -13580,7 +13598,7 @@ dependencies = [
[[package]]
name = "xcm-primitives"
version = "0.1.0"
-source = "git+https://github.com/darwinia-network/moonbeam?branch=polkadot-v0.9.30#38c37cc41b9a97482292717aec58b305d5f627f4"
+source = "git+https://github.com/darwinia-network/moonbeam?branch=polkadot-v0.9.30#9d31c6120bb0f317053da9cac7fe7cd2a44f844c"
dependencies = [
"ethereum",
"ethereum-types",
diff --git a/node/src/chain_spec/crab.rs b/node/src/chain_spec/crab.rs
index a0f08efd9..534e7d155 100644
--- a/node/src/chain_spec/crab.rs
+++ b/node/src/chain_spec/crab.rs
@@ -218,6 +218,11 @@ pub fn config() -> ChainSpec {
ethereum: Default::default(),
evm: Default::default(),
base_fee: Default::default(),
+
+ // S2S stuff
+ bridge_darwinia_grandpa: Default::default(),
+ bridge_darwinia_messages: Default::default(),
+ darwinia_fee_market: Default::default(),
}
},
// Bootnodes
@@ -339,6 +344,11 @@ fn testnet_genesis(
},
},
base_fee: Default::default(),
+
+ // S2S stuff
+ bridge_darwinia_grandpa: Default::default(),
+ bridge_darwinia_messages: Default::default(),
+ darwinia_fee_market: Default::default(),
}
}
diff --git a/node/src/chain_spec/darwinia.rs b/node/src/chain_spec/darwinia.rs
index deac4ea87..b8c78bb91 100644
--- a/node/src/chain_spec/darwinia.rs
+++ b/node/src/chain_spec/darwinia.rs
@@ -218,6 +218,11 @@ pub fn config() -> ChainSpec {
ethereum: Default::default(),
evm: Default::default(),
base_fee: Default::default(),
+
+ // S2S stuff
+ bridge_crab_grandpa: Default::default(),
+ bridge_crab_messages: Default::default(),
+ crab_fee_market: Default::default(),
}
},
// Bootnodes
@@ -343,6 +348,11 @@ fn testnet_genesis(
},
},
base_fee: Default::default(),
+
+ // S2S stuff
+ bridge_crab_grandpa: Default::default(),
+ bridge_crab_messages: Default::default(),
+ crab_fee_market: Default::default(),
}
}
diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml
index 3f22addc0..eded93bf3 100644
--- a/runtime/common/Cargo.toml
+++ b/runtime/common/Cargo.toml
@@ -13,6 +13,9 @@ version = "6.0.0"
# darwinia
dc-primitives = { default-features = false, path = "../../core/primitives" }
+# darwinia-messages-substrate
+bp-darwinia-core = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" }
+
# polkadot
xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.30" }
xcm-executor = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.30" }
diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs
index 1b95b603d..7b0c65c68 100644
--- a/runtime/common/src/lib.rs
+++ b/runtime/common/src/lib.rs
@@ -20,3 +20,7 @@
pub mod gov_origin;
pub mod xcm_barrier;
+
+pub use bp_darwinia_core as bp_crab;
+pub use bp_darwinia_core as bp_darwinia;
+pub use bp_darwinia_core as bp_pangolin;
diff --git a/runtime/crab/src/bridges_message/darwinia.rs b/runtime/crab/src/bridges_message/darwinia.rs
new file mode 100644
index 000000000..e9883b2e4
--- /dev/null
+++ b/runtime/crab/src/bridges_message/darwinia.rs
@@ -0,0 +1,178 @@
+// 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 .
+
+// crates.io
+use codec::{Decode, Encode};
+use scale_info::TypeInfo;
+// paritytech
+use frame_support::{weights::Weight, RuntimeDebug};
+use sp_runtime::{FixedPointNumber, FixedU128};
+// darwinia
+use crate::*;
+use bp_messages::{source_chain::*, target_chain::*, *};
+use bp_runtime::*;
+use bridge_runtime_common::{
+ lanes::*,
+ messages::{source::*, target::*, *},
+};
+use darwinia_common_runtime::*;
+
+/// Message delivery proof for Crab -> Darwinia messages.
+pub type ToDarwiniaMessagesDeliveryProof = FromBridgedChainMessagesDeliveryProof;
+/// Message proof for Darwinia -> Crab messages.
+pub type FromDarwiniaMessagesProof = FromBridgedChainMessagesProof;
+
+/// Message payload for Crab -> Darwinia messages.
+pub type ToDarwiniaMessagePayload = FromThisChainMessagePayload;
+/// Message payload for Darwinia -> Crab messages.
+pub type FromDarwiniaMessagePayload = FromBridgedChainMessagePayload;
+
+/// Message verifier for Crab -> Darwinia messages.
+pub type ToDarwiniaMessageVerifier =
+ FromThisChainMessageVerifier;
+
+/// Encoded Darwinia Call as it comes from Darwinia.
+pub type FromDarwiniaEncodedCall = FromBridgedChainEncodedMessageCall;
+
+/// Call-dispatch based message dispatch for Darwinia -> Crab messages.
+pub type FromDarwiniaMessageDispatch = FromBridgedChainMessageDispatch<
+ WithDarwiniaMessageBridge,
+ Runtime,
+ Balances,
+ WithDarwiniaDispatch,
+>;
+
+pub const INITIAL_DARWINIA_TO_CRAB_CONVERSION_RATE: FixedU128 =
+ FixedU128::from_inner(FixedU128::DIV);
+
+frame_support::parameter_types! {
+ /// Crab to Darwinia conversion rate. Initially we treate both tokens as equal.
+ pub storage DarwiniaToCrabConversionRate: FixedU128 = INITIAL_DARWINIA_TO_CRAB_CONVERSION_RATE;
+}
+
+#[derive(Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo)]
+pub enum CrabToDarwiniaParameter {
+ /// The conversion formula we use is: `DarwiniaTokens = CrabTokens *
+ /// conversion_rate`.
+ DarwiniaToCrabConversionRate(FixedU128),
+}
+impl Parameter for CrabToDarwiniaParameter {
+ fn save(&self) {
+ match *self {
+ CrabToDarwiniaParameter::DarwiniaToCrabConversionRate(ref conversion_rate) =>
+ DarwiniaToCrabConversionRate::set(conversion_rate),
+ }
+ }
+}
+
+pub type ToDarwiniaMaximalOutboundPayloadSize =
+ bridge_runtime_common::messages::source::FromThisChainMaximalOutboundPayloadSize<
+ WithDarwiniaMessageBridge,
+ >;
+
+/// Darwinia <-> Crab message bridge.
+#[derive(Clone, Copy, RuntimeDebug)]
+pub struct WithDarwiniaMessageBridge;
+impl MessageBridge for WithDarwiniaMessageBridge {
+ type BridgedChain = Darwinia;
+ type ThisChain = Crab;
+
+ const BRIDGED_CHAIN_ID: bp_runtime::ChainId = DARWINIA_CHAIN_ID;
+ const BRIDGED_MESSAGES_PALLET_NAME: &'static str =
+ bridge_runtime_common::pallets::WITH_CRAB_MESSAGES_PALLET_NAME;
+ const RELAYER_FEE_PERCENT: u32 = 10;
+ const THIS_CHAIN_ID: bp_runtime::ChainId = CRAB_CHAIN_ID;
+}
+
+#[derive(Clone, Copy, RuntimeDebug)]
+pub struct Crab;
+impl ChainWithMessages for Crab {
+ type AccountId = bp_crab::AccountId;
+ type Balance = bp_crab::Balance;
+ type Hash = bp_crab::Hash;
+ type Signature = bp_crab::Signature;
+ type Signer = bp_crab::AccountPublic;
+}
+impl ThisChainWithMessages for Crab {
+ type RuntimeCall = RuntimeCall;
+ type RuntimeOrigin = RuntimeOrigin;
+
+ fn is_message_accepted(_send_origin: &Self::RuntimeOrigin, lane: &LaneId) -> bool {
+ *lane == DARWINIA_CRAB_LANE
+ }
+
+ fn maximal_pending_messages_at_outbound_lane() -> MessageNonce {
+ MessageNonce::MAX
+ }
+}
+
+#[derive(Clone, Copy, RuntimeDebug)]
+pub struct Darwinia;
+impl ChainWithMessages for Darwinia {
+ type AccountId = bp_darwinia::AccountId;
+ type Balance = bp_darwinia::Balance;
+ type Hash = bp_darwinia::Hash;
+ type Signature = bp_darwinia::Signature;
+ type Signer = bp_darwinia::AccountPublic;
+}
+impl BridgedChainWithMessages for Darwinia {
+ fn maximal_extrinsic_size() -> u32 {
+ bp_darwinia::DarwiniaLike::max_extrinsic_size()
+ }
+
+ fn verify_dispatch_weight(_message_payload: &[u8], payload_weight: &Weight) -> bool {
+ let upper_limit = target::maximal_incoming_message_dispatch_weight(
+ bp_darwinia::DarwiniaLike::max_extrinsic_weight(),
+ );
+ payload_weight.all_lte(upper_limit)
+ }
+}
+impl TargetHeaderChain::AccountId>
+ for Darwinia
+{
+ type Error = &'static str;
+ type MessagesDeliveryProof = ToDarwiniaMessagesDeliveryProof;
+
+ fn verify_message(payload: &ToDarwiniaMessagePayload) -> Result<(), Self::Error> {
+ source::verify_chain_message::(payload)
+ }
+
+ fn verify_messages_delivery_proof(
+ proof: Self::MessagesDeliveryProof,
+ ) -> Result<(LaneId, InboundLaneData), Self::Error> {
+ source::verify_messages_delivery_proof::<
+ WithDarwiniaMessageBridge,
+ Runtime,
+ WithDarwiniaGrandpa,
+ >(proof)
+ }
+}
+impl SourceHeaderChain<::Balance> for Darwinia {
+ type Error = &'static str;
+ type MessagesProof = FromDarwiniaMessagesProof;
+
+ fn verify_messages_proof(
+ proof: Self::MessagesProof,
+ messages_count: u32,
+ ) -> Result::Balance>>, Self::Error> {
+ target::verify_messages_proof::(
+ proof,
+ messages_count,
+ )
+ }
+}
diff --git a/runtime/crab/src/bridges_message/mod.rs b/runtime/crab/src/bridges_message/mod.rs
new file mode 100644
index 000000000..f3c0116ff
--- /dev/null
+++ b/runtime/crab/src/bridges_message/mod.rs
@@ -0,0 +1,20 @@
+// 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 .
+
+pub mod darwinia;
+pub use darwinia as bm_darwinia;
diff --git a/runtime/crab/src/lib.rs b/runtime/crab/src/lib.rs
index 138b77e77..93d3c69fa 100644
--- a/runtime/crab/src/lib.rs
+++ b/runtime/crab/src/lib.rs
@@ -27,8 +27,12 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
mod pallets;
pub use pallets::*;
+mod bridges_message;
+pub use bridges_message::*;
+
mod weights;
+pub use darwinia_common_runtime::*;
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
// cumulus
@@ -309,6 +313,12 @@ frame_support::construct_runtime! {
Ethereum: pallet_ethereum = 31,
Evm: pallet_evm = 32,
BaseFee: pallet_base_fee = 33,
+
+ // S2S stuff
+ BridgeDarwiniaGrandpa: pallet_bridge_grandpa:: = 35,
+ BridgeDarwiniaMessages: pallet_bridge_messages:: = 36,
+ BridgeDarwiniaDispatch: pallet_bridge_dispatch:: = 37,
+ DarwiniaFeeMarket: pallet_fee_market:: = 38
}
}
diff --git a/runtime/crab/src/pallets/bridge_dispatch.rs b/runtime/crab/src/pallets/bridge_dispatch.rs
new file mode 100644
index 000000000..d5a919a78
--- /dev/null
+++ b/runtime/crab/src/pallets/bridge_dispatch.rs
@@ -0,0 +1,45 @@
+// 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 .
+
+pub use pallet_bridge_dispatch::Instance1 as WithDarwiniaDispatch;
+
+// darwinia
+use crate::*;
+use bp_message_dispatch::{Everything, IntoDispatchOrigin as IntoDispatchOriginT};
+use bp_messages::{LaneId, MessageNonce};
+use pallet_bridge_dispatch::Config;
+
+pub struct IntoDispatchOrigin;
+impl IntoDispatchOriginT for IntoDispatchOrigin {
+ fn into_dispatch_origin(id: &bp_crab::AccountId, _: &RuntimeCall) -> RuntimeOrigin {
+ frame_system::RawOrigin::Signed(id.clone()).into()
+ }
+}
+
+impl Config for Runtime {
+ type AccountIdConverter = bp_crab::AccountIdConverter;
+ type BridgeMessageId = (LaneId, MessageNonce);
+ type CallValidator = Everything;
+ type EncodedCall = bm_darwinia::FromDarwiniaEncodedCall;
+ type IntoDispatchOrigin = IntoDispatchOrigin;
+ type RuntimeCall = RuntimeCall;
+ type RuntimeEvent = RuntimeEvent;
+ type SourceChainAccountId = bp_darwinia::AccountId;
+ type TargetChainAccountPublic = bp_crab::AccountPublic;
+ type TargetChainSignature = bp_crab::Signature;
+}
diff --git a/runtime/crab/src/pallets/bridge_grandpa.rs b/runtime/crab/src/pallets/bridge_grandpa.rs
new file mode 100644
index 000000000..3ce65f20b
--- /dev/null
+++ b/runtime/crab/src/pallets/bridge_grandpa.rs
@@ -0,0 +1,41 @@
+// 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 .
+
+pub use pallet_bridge_grandpa::Instance1 as WithDarwiniaGrandpa;
+
+// darwinia
+use crate::*;
+use pallet_bridge_grandpa::Config;
+
+frame_support::parameter_types! {
+ // This is a pretty unscientific cap.
+ //
+ // Note that once this is hit the pallet will essentially throttle incoming requests down to one
+ // call per block.
+ pub const MaxRequests: u32 = 50;
+ pub const DarwiniaHeadersToKeep: u32 = 500;
+}
+
+impl Config for Runtime {
+ type BridgedChain = bp_darwinia::DarwiniaLike;
+ type HeadersToKeep = DarwiniaHeadersToKeep;
+ type MaxBridgedAuthorities = ();
+ type MaxBridgedHeaderSize = ();
+ type MaxRequests = MaxRequests;
+ type WeightInfo = ();
+}
diff --git a/runtime/crab/src/pallets/bridge_messages.rs b/runtime/crab/src/pallets/bridge_messages.rs
new file mode 100644
index 000000000..bd260b878
--- /dev/null
+++ b/runtime/crab/src/pallets/bridge_messages.rs
@@ -0,0 +1,73 @@
+// 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 .
+
+use pallet_bridge_messages::Instance1 as WithDarwiniaMessages;
+
+// darwinia
+use crate::{bm_darwinia::ToDarwiniaMaximalOutboundPayloadSize, *};
+use bp_messages::{source_chain::SenderOrigin, MessageNonce};
+use bp_runtime::{ChainId, DARWINIA_CHAIN_ID};
+use pallet_bridge_messages::Config;
+use pallet_fee_market::s2s::{
+ FeeMarketMessageAcceptedHandler, FeeMarketMessageConfirmedHandler, FeeMarketPayment,
+};
+
+impl SenderOrigin for RuntimeOrigin {
+ fn linked_account(&self) -> Option {
+ match self.caller {
+ OriginCaller::system(frame_system::RawOrigin::Signed(ref submitter)) =>
+ Some(submitter.clone()),
+ _ => None,
+ }
+ }
+}
+
+frame_support::parameter_types! {
+ pub const MaxMessagesToPruneAtOnce: MessageNonce = 8;
+ pub const BridgedChainId: ChainId = DARWINIA_CHAIN_ID;
+ pub const MaxUnconfirmedMessagesAtInboundLane: MessageNonce =
+ bp_darwinia::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
+ pub const MaxUnrewardedRelayerEntriesAtInboundLane: MessageNonce =
+ bp_darwinia::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX;
+ pub RootAccountForPayments: Option = None;
+}
+
+impl Config for Runtime {
+ type AccountIdConverter = bp_crab::AccountIdConverter;
+ type BridgedChainId = BridgedChainId;
+ type InboundMessageFee = bp_darwinia::Balance;
+ type InboundPayload = bm_darwinia::FromDarwiniaMessagePayload;
+ type InboundRelayer = bp_darwinia::AccountId;
+ type LaneMessageVerifier = bm_darwinia::ToDarwiniaMessageVerifier;
+ type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce;
+ type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane;
+ type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane;
+ type MaximalOutboundPayloadSize = ToDarwiniaMaximalOutboundPayloadSize;
+ type MessageDeliveryAndDispatchPayment =
+ FeeMarketPayment;
+ type MessageDispatch = bm_darwinia::FromDarwiniaMessageDispatch;
+ type OnDeliveryConfirmed = FeeMarketMessageConfirmedHandler;
+ type OnMessageAccepted = FeeMarketMessageAcceptedHandler;
+ type OutboundMessageFee = bp_crab::Balance;
+ type OutboundPayload = bm_darwinia::ToDarwiniaMessagePayload;
+ type Parameter = bm_darwinia::CrabToDarwiniaParameter;
+ type RuntimeEvent = RuntimeEvent;
+ type SourceHeaderChain = bm_darwinia::Darwinia;
+ type TargetHeaderChain = bm_darwinia::Darwinia;
+ type WeightInfo = ();
+}
diff --git a/runtime/crab/src/pallets/fee_market.rs b/runtime/crab/src/pallets/fee_market.rs
new file mode 100644
index 000000000..a9d93df1b
--- /dev/null
+++ b/runtime/crab/src/pallets/fee_market.rs
@@ -0,0 +1,70 @@
+// 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 .
+
+pub use pallet_fee_market::Instance1 as WithDarwiniaFeeMarket;
+
+// --- core ---
+use core::cmp;
+// --- substrate ---
+use frame_support::{traits::LockIdentifier, PalletId};
+use sp_runtime::{traits::UniqueSaturatedInto, Permill};
+// --- darwinia ---
+use crate::*;
+use pallet_fee_market::{BalanceOf, Config, Slasher};
+
+pub struct FeeMarketSlasher;
+impl, I: 'static> Slasher for FeeMarketSlasher {
+ fn calc_amount(locked_collateral: BalanceOf, timeout: T::BlockNumber) -> BalanceOf {
+ let slash_each_block = 2 * UNIT;
+ let slash_value = UniqueSaturatedInto::::unique_saturated_into(timeout)
+ .saturating_mul(UniqueSaturatedInto::::unique_saturated_into(slash_each_block))
+ .unique_saturated_into();
+
+ cmp::min(locked_collateral, slash_value)
+ }
+}
+
+frame_support::parameter_types! {
+ pub const TreasuryPalletId: PalletId = PalletId(*b"da/trsry");
+ pub const FeeMarketLockId: LockIdentifier = *b"da/feecr";
+
+ pub const MinimumRelayFee: Balance = 15 * UNIT;
+ pub const CollateralPerOrder: Balance = 50 * UNIT;
+ pub const Slot: BlockNumber = 600;
+
+ pub const DutyRelayersRewardRatio: Permill = Permill::from_percent(60);
+ pub const MessageRelayersRewardRatio: Permill = Permill::from_percent(80);
+ pub const ConfirmRelayersRewardRatio: Permill = Permill::from_percent(20);
+ pub const AssignedRelayerSlashRatio: Permill = Permill::from_percent(20);
+}
+
+impl Config for Runtime {
+ type AssignedRelayerSlashRatio = AssignedRelayerSlashRatio;
+ type CollateralPerOrder = CollateralPerOrder;
+ type ConfirmRelayersRewardRatio = ConfirmRelayersRewardRatio;
+ type Currency = Balances;
+ type DutyRelayersRewardRatio = DutyRelayersRewardRatio;
+ type LockId = FeeMarketLockId;
+ type MessageRelayersRewardRatio = MessageRelayersRewardRatio;
+ type MinimumRelayFee = MinimumRelayFee;
+ type RuntimeEvent = RuntimeEvent;
+ type Slasher = FeeMarketSlasher;
+ type Slot = Slot;
+ type TreasuryPalletId = TreasuryPalletId;
+ type WeightInfo = ();
+}
diff --git a/runtime/crab/src/pallets/mod.rs b/runtime/crab/src/pallets/mod.rs
index 3442d4ded..6db8976d6 100644
--- a/runtime/crab/src/pallets/mod.rs
+++ b/runtime/crab/src/pallets/mod.rs
@@ -100,3 +100,16 @@ mod evm;
pub use evm::*;
mod base_fee;
+
+// S2S stuff
+mod bridge_dispatch;
+pub use bridge_dispatch::*;
+
+mod bridge_grandpa;
+pub use bridge_grandpa::*;
+
+mod bridge_messages;
+pub use bridge_messages::*;
+
+mod fee_market;
+pub use fee_market::*;
diff --git a/runtime/darwinia/src/bridges_message/crab.rs b/runtime/darwinia/src/bridges_message/crab.rs
new file mode 100644
index 000000000..dde6a12f8
--- /dev/null
+++ b/runtime/darwinia/src/bridges_message/crab.rs
@@ -0,0 +1,170 @@
+// 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 .
+
+// crates.io
+use codec::{Decode, Encode};
+use scale_info::TypeInfo;
+// paritytech
+use frame_support::{weights::Weight, RuntimeDebug};
+use sp_runtime::{FixedPointNumber, FixedU128};
+// darwinia
+use crate::*;
+use bp_messages::{source_chain::*, target_chain::*, *};
+use bp_runtime::*;
+use bridge_runtime_common::{
+ lanes::*,
+ messages::{source::*, target::*, *},
+};
+use darwinia_common_runtime::*;
+
+/// Message delivery proof for Darwinia -> Crab messages.
+pub type ToCrabMessagesDeliveryProof = FromBridgedChainMessagesDeliveryProof;
+/// Message proof for Crab -> Darwinia messages.
+pub type FromCrabMessagesProof = FromBridgedChainMessagesProof;
+
+/// Message payload for Darwinia -> Crab messages.
+pub type ToCrabMessagePayload = FromThisChainMessagePayload;
+/// Message payload for Crab -> Darwinia messages.
+pub type FromCrabMessagePayload = FromBridgedChainMessagePayload;
+
+/// Message verifier for Darwinia -> Crab messages.
+pub type ToCrabMessageVerifier =
+ FromThisChainMessageVerifier;
+
+/// Encoded Crab Call as it comes from Crab.
+pub type FromCrabEncodedCall = FromBridgedChainEncodedMessageCall;
+
+/// Call-dispatch based message dispatch for Crab -> Darwinia messages.
+pub type FromCrabMessageDispatch =
+ FromBridgedChainMessageDispatch;
+
+pub const INITIAL_CRAB_TO_DARWINIA_CONVERSION_RATE: FixedU128 =
+ FixedU128::from_inner(FixedU128::DIV);
+
+frame_support::parameter_types! {
+ /// Darwinia to Crab conversion rate. Initially we treate both tokens as equal.
+ pub storage CrabToDarwiniaConversionRate: FixedU128 = INITIAL_CRAB_TO_DARWINIA_CONVERSION_RATE;
+}
+
+#[derive(Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo)]
+pub enum DarwiniaToCrabParameter {
+ /// The conversion formula we use is: `CrabTokens = DarwiniaTokens *
+ /// conversion_rate`.
+ CrabToDarwiniaConversionRate(FixedU128),
+}
+impl Parameter for DarwiniaToCrabParameter {
+ fn save(&self) {
+ match *self {
+ DarwiniaToCrabParameter::CrabToDarwiniaConversionRate(ref conversion_rate) =>
+ CrabToDarwiniaConversionRate::set(conversion_rate),
+ }
+ }
+}
+
+pub type ToCrabMaximalOutboundPayloadSize =
+ bridge_runtime_common::messages::source::FromThisChainMaximalOutboundPayloadSize<
+ WithCrabMessageBridge,
+ >;
+
+/// Crab <-> Darwinia message bridge.
+#[derive(Clone, Copy, RuntimeDebug)]
+pub struct WithCrabMessageBridge;
+impl MessageBridge for WithCrabMessageBridge {
+ type BridgedChain = Crab;
+ type ThisChain = Darwinia;
+
+ const BRIDGED_CHAIN_ID: bp_runtime::ChainId = CRAB_CHAIN_ID;
+ const BRIDGED_MESSAGES_PALLET_NAME: &'static str =
+ bridge_runtime_common::pallets::WITH_DARWINIA_MESSAGES_PALLET_NAME;
+ const RELAYER_FEE_PERCENT: u32 = 10;
+ const THIS_CHAIN_ID: bp_runtime::ChainId = DARWINIA_CHAIN_ID;
+}
+
+#[derive(Clone, Copy, RuntimeDebug)]
+pub struct Darwinia;
+impl ChainWithMessages for Darwinia {
+ type AccountId = bp_darwinia::AccountId;
+ type Balance = bp_darwinia::Balance;
+ type Hash = bp_darwinia::Hash;
+ type Signature = bp_darwinia::Signature;
+ type Signer = bp_darwinia::AccountPublic;
+}
+impl ThisChainWithMessages for Darwinia {
+ type RuntimeCall = RuntimeCall;
+ type RuntimeOrigin = RuntimeOrigin;
+
+ fn is_message_accepted(_send_origin: &Self::RuntimeOrigin, lane: &LaneId) -> bool {
+ *lane == DARWINIA_CRAB_LANE
+ }
+
+ fn maximal_pending_messages_at_outbound_lane() -> MessageNonce {
+ MessageNonce::MAX
+ }
+}
+
+#[derive(Clone, Copy, RuntimeDebug)]
+pub struct Crab;
+impl ChainWithMessages for Crab {
+ type AccountId = bp_crab::AccountId;
+ type Balance = bp_crab::Balance;
+ type Hash = bp_crab::Hash;
+ type Signature = bp_crab::Signature;
+ type Signer = bp_crab::AccountPublic;
+}
+impl BridgedChainWithMessages for Crab {
+ fn maximal_extrinsic_size() -> u32 {
+ bp_crab::DarwiniaLike::max_extrinsic_size()
+ }
+
+ fn verify_dispatch_weight(_message_payload: &[u8], payload_weight: &Weight) -> bool {
+ let upper_limit = target::maximal_incoming_message_dispatch_weight(
+ bp_crab::DarwiniaLike::max_extrinsic_weight(),
+ );
+ payload_weight.all_lte(upper_limit)
+ }
+}
+impl TargetHeaderChain::AccountId> for Crab {
+ type Error = &'static str;
+ type MessagesDeliveryProof = ToCrabMessagesDeliveryProof;
+
+ fn verify_message(payload: &ToCrabMessagePayload) -> Result<(), Self::Error> {
+ source::verify_chain_message::(payload)
+ }
+
+ fn verify_messages_delivery_proof(
+ proof: Self::MessagesDeliveryProof,
+ ) -> Result<(LaneId, InboundLaneData), Self::Error> {
+ source::verify_messages_delivery_proof::(
+ proof,
+ )
+ }
+}
+impl SourceHeaderChain<::Balance> for Crab {
+ type Error = &'static str;
+ type MessagesProof = FromCrabMessagesProof;
+
+ fn verify_messages_proof(
+ proof: Self::MessagesProof,
+ messages_count: u32,
+ ) -> Result::Balance>>, Self::Error> {
+ target::verify_messages_proof::(
+ proof,
+ messages_count,
+ )
+ }
+}
diff --git a/runtime/darwinia/src/bridges_message/mod.rs b/runtime/darwinia/src/bridges_message/mod.rs
new file mode 100644
index 000000000..fd58eaf04
--- /dev/null
+++ b/runtime/darwinia/src/bridges_message/mod.rs
@@ -0,0 +1,20 @@
+// 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 .
+
+pub mod crab;
+pub use crab as bm_crab;
diff --git a/runtime/darwinia/src/lib.rs b/runtime/darwinia/src/lib.rs
index 81ad46221..a6ef11a7d 100644
--- a/runtime/darwinia/src/lib.rs
+++ b/runtime/darwinia/src/lib.rs
@@ -27,8 +27,12 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
mod pallets;
pub use pallets::*;
+mod bridges_message;
+pub use bridges_message::*;
+
mod weights;
+pub use darwinia_common_runtime::*;
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
// cumulus
@@ -309,6 +313,12 @@ frame_support::construct_runtime! {
Ethereum: pallet_ethereum = 31,
Evm: pallet_evm = 32,
BaseFee: pallet_base_fee = 33,
+
+ // S2S stuff
+ BridgeCrabGrandpa: pallet_bridge_grandpa:: = 35,
+ BridgeCrabMessages: pallet_bridge_messages:: = 36,
+ BridgeCrabDispatch: pallet_bridge_dispatch:: = 37,
+ CrabFeeMarket: pallet_fee_market:: = 38
}
}
diff --git a/runtime/darwinia/src/pallets/bridge_dispatch.rs b/runtime/darwinia/src/pallets/bridge_dispatch.rs
new file mode 100644
index 000000000..696eb8679
--- /dev/null
+++ b/runtime/darwinia/src/pallets/bridge_dispatch.rs
@@ -0,0 +1,47 @@
+// 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 .
+
+pub use pallet_bridge_dispatch::Instance1 as WithCrabDispatch;
+
+// darwinia
+use crate::*;
+use bp_message_dispatch::{Everything, IntoDispatchOrigin as IntoDispatchOriginT};
+use bp_messages::{LaneId, MessageNonce};
+use pallet_bridge_dispatch::Config;
+
+pub struct IntoDispatchOrigin;
+impl IntoDispatchOriginT
+ for IntoDispatchOrigin
+{
+ fn into_dispatch_origin(id: &bp_darwinia::AccountId, _: &RuntimeCall) -> RuntimeOrigin {
+ frame_system::RawOrigin::Signed(id.clone()).into()
+ }
+}
+
+impl Config for Runtime {
+ type AccountIdConverter = bp_darwinia::AccountIdConverter;
+ type BridgeMessageId = (LaneId, MessageNonce);
+ type CallValidator = Everything;
+ type EncodedCall = bm_crab::FromCrabEncodedCall;
+ type IntoDispatchOrigin = IntoDispatchOrigin;
+ type RuntimeCall = RuntimeCall;
+ type RuntimeEvent = RuntimeEvent;
+ type SourceChainAccountId = bp_crab::AccountId;
+ type TargetChainAccountPublic = bp_darwinia::AccountPublic;
+ type TargetChainSignature = bp_darwinia::Signature;
+}
diff --git a/runtime/darwinia/src/pallets/bridge_grandpa.rs b/runtime/darwinia/src/pallets/bridge_grandpa.rs
new file mode 100644
index 000000000..b2180fa6f
--- /dev/null
+++ b/runtime/darwinia/src/pallets/bridge_grandpa.rs
@@ -0,0 +1,41 @@
+// 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 .
+
+pub use pallet_bridge_grandpa::Instance1 as WithCrabGrandpa;
+
+// darwinia
+use crate::*;
+use pallet_bridge_grandpa::Config;
+
+frame_support::parameter_types! {
+ // This is a pretty unscientific cap.
+ //
+ // Note that once this is hit the pallet will essentially throttle incoming requests down to one
+ // call per block.
+ pub const MaxRequests: u32 = 50;
+ pub const CrabHeadersToKeep: u32 = 500;
+}
+
+impl Config for Runtime {
+ type BridgedChain = bp_crab::DarwiniaLike;
+ type HeadersToKeep = CrabHeadersToKeep;
+ type MaxBridgedAuthorities = ();
+ type MaxBridgedHeaderSize = ();
+ type MaxRequests = MaxRequests;
+ type WeightInfo = ();
+}
diff --git a/runtime/darwinia/src/pallets/bridge_messages.rs b/runtime/darwinia/src/pallets/bridge_messages.rs
new file mode 100644
index 000000000..544f5a894
--- /dev/null
+++ b/runtime/darwinia/src/pallets/bridge_messages.rs
@@ -0,0 +1,72 @@
+// 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 .
+
+use pallet_bridge_messages::Instance1 as WithCrabMessages;
+
+// darwinia
+use crate::{bm_crab::ToCrabMaximalOutboundPayloadSize, *};
+use bp_messages::{source_chain::SenderOrigin, MessageNonce};
+use bp_runtime::{ChainId, CRAB_CHAIN_ID};
+use pallet_bridge_messages::Config;
+use pallet_fee_market::s2s::{
+ FeeMarketMessageAcceptedHandler, FeeMarketMessageConfirmedHandler, FeeMarketPayment,
+};
+
+impl SenderOrigin for RuntimeOrigin {
+ fn linked_account(&self) -> Option {
+ match self.caller {
+ OriginCaller::system(frame_system::RawOrigin::Signed(ref submitter)) =>
+ Some(submitter.clone()),
+ _ => None,
+ }
+ }
+}
+
+frame_support::parameter_types! {
+ pub const MaxMessagesToPruneAtOnce: MessageNonce = 8;
+ pub const BridgedChainId: ChainId = CRAB_CHAIN_ID;
+ pub const MaxUnconfirmedMessagesAtInboundLane: MessageNonce =
+ bp_darwinia::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
+ pub const MaxUnrewardedRelayerEntriesAtInboundLane: MessageNonce =
+ bp_darwinia::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX;
+ pub RootAccountForPayments: Option = None;
+}
+
+impl Config for Runtime {
+ type AccountIdConverter = bp_darwinia::AccountIdConverter;
+ type BridgedChainId = BridgedChainId;
+ type InboundMessageFee = bp_crab::Balance;
+ type InboundPayload = bm_crab::FromCrabMessagePayload;
+ type InboundRelayer = bp_crab::AccountId;
+ type LaneMessageVerifier = bm_crab::ToCrabMessageVerifier;
+ type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce;
+ type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane;
+ type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane;
+ type MaximalOutboundPayloadSize = ToCrabMaximalOutboundPayloadSize;
+ type MessageDeliveryAndDispatchPayment = FeeMarketPayment;
+ type MessageDispatch = bm_crab::FromCrabMessageDispatch;
+ type OnDeliveryConfirmed = FeeMarketMessageConfirmedHandler;
+ type OnMessageAccepted = FeeMarketMessageAcceptedHandler;
+ type OutboundMessageFee = bp_darwinia::Balance;
+ type OutboundPayload = bm_crab::ToCrabMessagePayload;
+ type Parameter = bm_crab::DarwiniaToCrabParameter;
+ type RuntimeEvent = RuntimeEvent;
+ type SourceHeaderChain = bm_crab::Crab;
+ type TargetHeaderChain = bm_crab::Crab;
+ type WeightInfo = ();
+}
diff --git a/runtime/darwinia/src/pallets/fee_market.rs b/runtime/darwinia/src/pallets/fee_market.rs
new file mode 100644
index 000000000..67b134938
--- /dev/null
+++ b/runtime/darwinia/src/pallets/fee_market.rs
@@ -0,0 +1,70 @@
+// 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 .
+
+pub use pallet_fee_market::Instance1 as WithCrabFeeMarket;
+
+// --- core ---
+use core::cmp;
+// --- substrate ---
+use frame_support::{traits::LockIdentifier, PalletId};
+use sp_runtime::{traits::UniqueSaturatedInto, Permill};
+// --- darwinia ---
+use crate::*;
+use pallet_fee_market::{BalanceOf, Config, Slasher};
+
+pub struct FeeMarketSlasher;
+impl, I: 'static> Slasher for FeeMarketSlasher {
+ fn calc_amount(locked_collateral: BalanceOf, timeout: T::BlockNumber) -> BalanceOf {
+ let slash_each_block = 2 * UNIT;
+ let slash_value = UniqueSaturatedInto::::unique_saturated_into(timeout)
+ .saturating_mul(UniqueSaturatedInto::::unique_saturated_into(slash_each_block))
+ .unique_saturated_into();
+
+ cmp::min(locked_collateral, slash_value)
+ }
+}
+
+frame_support::parameter_types! {
+ pub const TreasuryPalletId: PalletId = PalletId(*b"da/trsry");
+ pub const FeeMarketLockId: LockIdentifier = *b"da/feecr";
+
+ pub const MinimumRelayFee: Balance = 15 * UNIT;
+ pub const CollateralPerOrder: Balance = 50 * UNIT;
+ pub const Slot: BlockNumber = 600;
+
+ pub const DutyRelayersRewardRatio: Permill = Permill::from_percent(60);
+ pub const MessageRelayersRewardRatio: Permill = Permill::from_percent(80);
+ pub const ConfirmRelayersRewardRatio: Permill = Permill::from_percent(20);
+ pub const AssignedRelayerSlashRatio: Permill = Permill::from_percent(20);
+}
+
+impl Config for Runtime {
+ type AssignedRelayerSlashRatio = AssignedRelayerSlashRatio;
+ type CollateralPerOrder = CollateralPerOrder;
+ type ConfirmRelayersRewardRatio = ConfirmRelayersRewardRatio;
+ type Currency = Balances;
+ type DutyRelayersRewardRatio = DutyRelayersRewardRatio;
+ type LockId = FeeMarketLockId;
+ type MessageRelayersRewardRatio = MessageRelayersRewardRatio;
+ type MinimumRelayFee = MinimumRelayFee;
+ type RuntimeEvent = RuntimeEvent;
+ type Slasher = FeeMarketSlasher;
+ type Slot = Slot;
+ type TreasuryPalletId = TreasuryPalletId;
+ type WeightInfo = ();
+}
diff --git a/runtime/darwinia/src/pallets/mod.rs b/runtime/darwinia/src/pallets/mod.rs
index 3442d4ded..6db8976d6 100644
--- a/runtime/darwinia/src/pallets/mod.rs
+++ b/runtime/darwinia/src/pallets/mod.rs
@@ -100,3 +100,16 @@ mod evm;
pub use evm::*;
mod base_fee;
+
+// S2S stuff
+mod bridge_dispatch;
+pub use bridge_dispatch::*;
+
+mod bridge_grandpa;
+pub use bridge_grandpa::*;
+
+mod bridge_messages;
+pub use bridge_messages::*;
+
+mod fee_market;
+pub use fee_market::*;