Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Add Crab & Crab parachain
Browse files Browse the repository at this point in the history
  • Loading branch information
jiguantong committed Jun 9, 2022
1 parent 9b2dbee commit ea3adff
Show file tree
Hide file tree
Showing 8 changed files with 348 additions and 1 deletion.
13 changes: 13 additions & 0 deletions bin/runtime-common/src/lanes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use bp_messages::LaneId;

/// Identifier of bridge between Darwinia and Crab.
pub const DARWINIA_CRAB_LANE: LaneId = [0; 4];

// Identifier of bridge between Pangoro and Pangolin.
pub const PANGORO_PANGOLIN_LANE: LaneId = *b"roli";

/// Identifier of bridge between Pangolin and Pangolin Parachain.
pub const PANGOLIN_PANGOLIN_PARACHAIN_LANE: LaneId = *b"pali";

/// Identifier of bridge between Crab and Crab Parachain.
pub const CRAB_CRAB_PARACHAIN_LANE: LaneId = *b"pacr";
1 change: 1 addition & 0 deletions bin/runtime-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#![cfg_attr(not(feature = "std"), no_std)]

pub mod lanes;
pub mod messages;
pub mod messages_api;
pub mod messages_benchmarking;
Expand Down
34 changes: 34 additions & 0 deletions primitives/chain-crab-parachain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
authors = ["Darwinia Network <hello@darwinia.network>"]
description = "Primitives of Crab Parachain runtime."
edition = "2021"
license = "GPL-3.0"
name = "bp-crab-parachain"
version = "0.1.0"

[dependencies]
# darwinia-network
bp-darwinia-core = { default-features = false, path = "../darwinia-core" }
# paritytech
bp-messages = { default-features = false, path = "../messages" }
bp-runtime = { default-features = false, path = "../runtime" }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.20" }
sp-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.20" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.20" }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.20" }
sp-version = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.20" }

[features]
default = ["std"]
std = [
# darwinia-network
"bp-darwinia-core/std",
# paritytech
"bp-messages/std",
"bp-runtime/std",
"frame-support/std",
"sp-api/std",
"sp-runtime/std",
"sp-std/std",
"sp-version/std",
]
122 changes: 122 additions & 0 deletions primitives/chain-crab-parachain/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// 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/>.

#![cfg_attr(not(feature = "std"), no_std)]

mod copy_paste_from_darwinia {
// --- darwinia-network ---
use bp_darwinia_core::*;
// --- paritytech ---
use sp_version::RuntimeVersion;

pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: sp_runtime::create_runtime_str!("Crab Parachain"),
impl_name: sp_runtime::create_runtime_str!("Darwinia Crab Parachain"),
authoring_version: 1,
spec_version: 4,
impl_version: 1,
apis: sp_version::create_apis_vec![[]],
transaction_version: 1,
state_version: 0,
};

pub const EXISTENTIAL_DEPOSIT: Balance = 0;
}
pub use copy_paste_from_darwinia::*;

pub use bp_darwinia_core::*;

// --- paritytech ---
use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState};
use frame_support::Parameter;
use sp_std::prelude::*;

/// CrabParachain Chain.
pub type CrabParachain = DarwiniaLike;

/// Name of the With-CrabParachain messages pallet instance that is deployed at bridged chains.
pub const WITH_CRAB_PARACHAIN_MESSAGES_PALLET_NAME: &str = "BridgeCrabParachainMessages";

/// Name of the `CrabParachainFinalityApi::best_finalized` runtime method.
pub const BEST_FINALIZED_CRAB_PARACHAIN_HEADER_METHOD: &str =
"CrabParachainFinalityApi_best_finalized";

/// Name of the `ToCrabParachainOutboundLaneApi::message_details` runtime method.
pub const TO_CRAB_PARACHAIN_MESSAGE_DETAILS_METHOD: &str =
"ToCrabParachainOutboundLaneApi_message_details";
/// Name of the `ToCrabParachainOutboundLaneApi::latest_received_nonce` runtime method.
pub const TO_CRAB_PARACHAIN_LATEST_RECEIVED_NONCE_METHOD: &str =
"ToCrabParachainOutboundLaneApi_latest_received_nonce";
/// Name of the `ToCrabParachainOutboundLaneApi::latest_generated_nonce` runtime method.
pub const TO_CRAB_PARACHAIN_LATEST_GENERATED_NONCE_METHOD: &str =
"ToCrabParachainOutboundLaneApi_latest_generated_nonce";

/// Name of the `FromCrabParachainInboundLaneApi::latest_received_nonce` runtime method.
pub const FROM_CRAB_PARACHAIN_LATEST_RECEIVED_NONCE_METHOD: &str =
"FromCrabParachainInboundLaneApi_latest_received_nonce";
/// Name of the `FromCrabParachainInboundLaneApi::latest_onfirmed_nonce` runtime method.
pub const FROM_CRAB_PARACHAIN_LATEST_CONFIRMED_NONCE_METHOD: &str =
"FromCrabParachainInboundLaneApi_latest_confirmed_nonce";
/// Name of the `FromCrabParachainInboundLaneApi::unrewarded_relayers_state` runtime method.
pub const FROM_CRAB_PARACHAIN_UNREWARDED_RELAYERS_STATE: &str =
"FromCrabParachainInboundLaneApi_unrewarded_relayers_state";

sp_api::decl_runtime_apis! {
/// API for querying information about the finalized CrabParachain headers.
///
/// This API is implemented by runtimes that are bridging with the CrabParachain chain, not the
/// CrabParachain runtime itself.
pub trait CrabParachainFinalityApi {
/// Returns number and hash of the best finalized header known to the bridge module.
fn best_finalized() -> (BlockNumber, Hash);
}

/// Outbound message lane API for messages that are sent to CrabParachain chain.
///
/// This API is implemented by runtimes that are sending messages to CrabParachain chain, not the
/// CrabParachain runtime itself.
pub trait ToCrabParachainOutboundLaneApi<OutboundMessageFee: Parameter, OutboundPayload: Parameter> {
/// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all
/// messages in given inclusive range.
///
/// If some (or all) messages are missing from the storage, they'll also will
/// be missing from the resulting vector. The vector is ordered by the nonce.
fn message_details(
lane: LaneId,
begin: MessageNonce,
end: MessageNonce,
) -> Vec<MessageDetails<OutboundMessageFee>>;
/// Returns nonce of the latest message, received by bridged chain.
fn latest_received_nonce(lane: LaneId) -> MessageNonce;
/// Returns nonce of the latest message, generated by given lane.
fn latest_generated_nonce(lane: LaneId) -> MessageNonce;
}

/// Inbound message lane API for messages sent by CrabParachain chain.
///
/// This API is implemented by runtimes that are receiving messages from CrabParachain chain, not the
/// CrabParachain runtime itself.
pub trait FromCrabParachainInboundLaneApi {
/// Returns nonce of the latest message, received by given lane.
fn latest_received_nonce(lane: LaneId) -> MessageNonce;
/// Nonce of latest message that has been confirmed to the bridged chain.
fn latest_confirmed_nonce(lane: LaneId) -> MessageNonce;
/// State of the unrewarded relayers set at given lane.
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
}
}
34 changes: 34 additions & 0 deletions primitives/chain-crab/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
authors = ["Darwinia Network <hello@darwinia.network>"]
description = "Primitives of Crab runtime."
edition = "2021"
license = "GPL-3.0"
name = "bp-crab"
version = "0.1.0"

[dependencies]
# darwinia-network
bp-darwinia-core = { default-features = false, path = "../darwinia-core" }
# paritytech
bp-messages = { default-features = false, path = "../messages" }
bp-runtime = { default-features = false, path = "../runtime" }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.20" }
sp-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.20" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.20" }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.20" }
sp-version = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.20" }

[features]
default = ["std"]
std = [
# darwinia-network
"bp-darwinia-core/std",
# paritytech
"bp-messages/std",
"bp-runtime/std",
"frame-support/std",
"sp-api/std",
"sp-runtime/std",
"sp-std/std",
"sp-version/std",
]
126 changes: 126 additions & 0 deletions primitives/chain-crab/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// 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/>.

#![cfg_attr(not(feature = "std"), no_std)]

mod copy_paste_from_darwinia {
// --- darwinia-network ---
use bp_darwinia_core::*;
// --- paritytech ---
use sp_version::RuntimeVersion;

pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: sp_runtime::create_runtime_str!("Crab"),
impl_name: sp_runtime::create_runtime_str!("Darwinia Crab"),
authoring_version: 0,
spec_version: 12_0_0,
impl_version: 0,
apis: sp_version::create_apis_vec![[]],
transaction_version: 0,
state_version: 0,
};

pub const EXISTENTIAL_DEPOSIT: Balance = 0;

pub const SESSION_LENGTH: BlockNumber = 1 * HOURS;
}
pub use copy_paste_from_darwinia::*;

pub use bp_darwinia_core::*;

// --- paritytech ---
use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState};
use frame_support::Parameter;
use sp_std::prelude::*;

/// Crab Chain.
pub type Crab = DarwiniaLike;

/// Name of the With-Crab GRANDPA pallet instance that is deployed at bridged chains.
pub const WITH_CRAB_GRANDPA_PALLET_NAME: &str = "BridgeCrabGrandpa";
/// Name of the With-Crab messages pallet instance that is deployed at bridged chains.
pub const WITH_CRAB_MESSAGES_PALLET_NAME: &str = "BridgeCrabMessages";
/// Name of the With-Crab parachains bridge pallet name in the Crab runtime.
pub const BRIDGE_PARAS_PALLET_NAME: &str = "BridgeCrabParachains";

/// Name of the `CrabFinalityApi::best_finalized` runtime method.
pub const BEST_FINALIZED_CRAB_HEADER_METHOD: &str = "CrabFinalityApi_best_finalized";

/// Name of the `ToCrabOutboundLaneApi::message_details` runtime method.
pub const TO_CRAB_MESSAGE_DETAILS_METHOD: &str = "ToCrabOutboundLaneApi_message_details";
/// Name of the `ToCrabOutboundLaneApi::latest_received_nonce` runtime method.
pub const TO_CRAB_LATEST_RECEIVED_NONCE_METHOD: &str =
"ToCrabOutboundLaneApi_latest_received_nonce";
/// Name of the `ToCrabOutboundLaneApi::latest_generated_nonce` runtime method.
pub const TO_CRAB_LATEST_GENERATED_NONCE_METHOD: &str =
"ToCrabOutboundLaneApi_latest_generated_nonce";

/// Name of the `FromCrabInboundLaneApi::latest_received_nonce` runtime method.
pub const FROM_CRAB_LATEST_RECEIVED_NONCE_METHOD: &str =
"FromCrabInboundLaneApi_latest_received_nonce";
/// Name of the `FromCrabInboundLaneApi::latest_cnfirmed_nonce` runtime method.
pub const FROM_CRAB_LATEST_CONFIRMED_NONCE_METHOD: &str =
"FromCrabInboundLaneApi_latest_confirmed_nonce";
/// Name of the `FromCrabInboundLaneApi::unrewarded_relayers_state` runtime method.
pub const FROM_CRAB_UNREWARDED_RELAYERS_STATE: &str =
"FromCrabInboundLaneApi_unrewarded_relayers_state";

sp_api::decl_runtime_apis! {
/// API for querying information about the finalized Crab headers.
///
/// This API is implemented by runtimes that are bridging with the Crab chain, not the
/// Crab runtime itself.
pub trait CrabFinalityApi {
/// Returns number and hash of the best finalized header known to the bridge module.
fn best_finalized() -> (BlockNumber, Hash);
}

/// Outbound message lane API for messages that are sent to Crab chain.
///
/// This API is implemented by runtimes that are sending messages to Crab chain, not the
/// Crab runtime itself.
pub trait ToCrabOutboundLaneApi<OutboundMessageFee: Parameter, OutboundPayload: Parameter> {
/// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all
/// messages in given inclusive range.
///
/// If some (or all) messages are missing from the storage, they'll also will
/// be missing from the resulting vector. The vector is ordered by the nonce.
fn message_details(
lane: LaneId,
begin: MessageNonce,
end: MessageNonce,
) -> Vec<MessageDetails<OutboundMessageFee>>;
/// Returns nonce of the latest message, received by bridged chain.
fn latest_received_nonce(lane: LaneId) -> MessageNonce;
/// Returns nonce of the latest message, generated by given lane.
fn latest_generated_nonce(lane: LaneId) -> MessageNonce;
}

/// Inbound message lane API for messages sent by Crab chain.
///
/// This API is implemented by runtimes that are receiving messages from Crab chain, not the
/// Crab runtime itself.
pub trait FromCrabInboundLaneApi {
/// Returns nonce of the latest message, received by given lane.
fn latest_received_nonce(lane: LaneId) -> MessageNonce;
/// Nonce of latest message that has been confirmed to the bridged chain.
fn latest_confirmed_nonce(lane: LaneId) -> MessageNonce;
/// State of the unrewarded relayers set at given lane.
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
}
}
18 changes: 18 additions & 0 deletions primitives/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ pub const ROCOCO_CHAIN_ID: ChainId = *b"roco";
/// Bridge-with-Wococo instance id.
pub const WOCOCO_CHAIN_ID: ChainId = *b"woco";

/// Bridge-with-Darwinia instance id.
pub const DARWINIA_CHAIN_ID: ChainId = *b"darw";

/// Bridge-with-Crab instance id.
pub const CRAB_CHAIN_ID: ChainId = *b"crab";

/// Bridge-with-Pangoro instance id.
pub const PANGORO_CHAIN_ID: ChainId = *b"pagr";

/// Bridge-with-Pangolin instance id.
pub const PANGOLIN_CHAIN_ID: ChainId = *b"pagl";

/// Bridge-with-PangolinParachain instance id.
pub const PANGOLIN_PARACHAIN_CHAIN_ID: ChainId = *b"pglp";

/// Bridge-with-CrabParachain instance id.
pub const CRAB_PARACHAIN_CHAIN_ID: ChainId = *b"crap";

/// Call-dispatch module prefix.
pub const CALL_DISPATCH_MODULE_PREFIX: &[u8] = b"pallet-bridge/dispatch";

Expand Down
1 change: 0 additions & 1 deletion primitives/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

use bp_header_chain::justification::GrandpaJustification;
use codec::Encode;
use sp_application_crypto::TryFrom;
use sp_finality_grandpa::{AuthorityId, AuthoritySignature, AuthorityWeight, SetId};
use sp_runtime::traits::{Header as HeaderT, One, Zero};
use sp_std::prelude::*;
Expand Down

0 comments on commit ea3adff

Please sign in to comment.