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

Prepare for Crab<>Crab Parachain #76

Merged
merged 5 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions bin/runtime-common/src/lanes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ 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";
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/darwinia-network/substrate", branch = "darwinia-v0.12.2" }
sp-api = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "darwinia-v0.12.2" }
sp-runtime = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "darwinia-v0.12.2" }
sp-std = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "darwinia-v0.12.2" }
sp-version = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "darwinia-v0.12.2" }

[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",
]
121 changes: 121 additions & 0 deletions primitives/chain-crab-parachain/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// --- 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,
Comment on lines +31 to +32
Copy link
Contributor

@hackfisher hackfisher May 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How this settings be used? What if crab parachain's spec changes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bridger has a startegy related to this setting. If the strategy is Auto, bridger will try to use the latest spec version on the Crab, and ignore this setting. If the strategy is Bundle, bridger will use this setting to communicate with Crab. And if the strategy is Custom, bridger can custom spec_version with the local config file.

CC @fewensa

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean and move this to bridger if it is only used by bridger.

apis: sp_version::create_apis_vec![[]],
transaction_version: 1,
};

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;
}
}
2 changes: 2 additions & 0 deletions primitives/chain-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ pub const FROM_KUSAMA_LATEST_CONFIRMED_NONCE_METHOD: &str =
pub const FROM_KUSAMA_UNREWARDED_RELAYERS_STATE: &str =
"FromKusamaInboundLaneApi_unrewarded_relayers_state";

pub const PARAS_PALLET_NAME: &str = "Paras";

sp_api::decl_runtime_apis! {
/// API for querying information about the finalized Kusama headers.
///
Expand Down
3 changes: 3 additions & 0 deletions primitives/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ 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
29 changes: 29 additions & 0 deletions relays/client-crab-parachain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
authors = ["Darwinia Network <hello@darwinia.network>"]
edition = "2021"
license = "GPL-3.0"
name = "relay-crab-parachain-client"
version = "0.1.0"


[dependencies]
codec = { package = "parity-scale-codec", version = "2.2.0" }
relay-substrate-client = { path = "../client-substrate" }
relay-utils = { path = "../utils" }
scale-info = { version = "1.0", features = ["derive"] }

bp-header-chain = { path = "../../primitives/header-chain" }
bp-message-dispatch = { path = "../../primitives/message-dispatch" }
bp-messages = { path = "../../primitives/messages" }
bp-runtime = { path = "../../primitives/runtime" }
bridge-runtime-common = { path = "../../bin/runtime-common" }
pallet-bridge-dispatch = { path = "../../modules/dispatch" }

bp-darwinia-core = { path = "../../primitives/darwinia-core" }
bp-crab = { path = "../../primitives/chain-crab" }
bp-crab-parachain = { path = "../../primitives/chain-crab-parachain" }

## Substrate Dependencies
frame-support = { git = "https://github.com/darwinia-network/substrate", branch = "darwinia-v0.12.2" }
sp-core = { git = "https://github.com/darwinia-network/substrate", branch = "darwinia-v0.12.2" }
sp-runtime = { git = "https://github.com/darwinia-network/substrate", branch = "darwinia-v0.12.2" }
Loading