Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add polkadot bulletin chain primitives #2542

Merged
merged 3 commits into from
Sep 8, 2023
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
15 changes: 15 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ members = [
"primitives/chain-kusama",
"primitives/chain-millau",
"primitives/chain-polkadot",
"primitives/chain-polkadot-bulletin",
"primitives/chain-rialto",
"primitives/chain-rialto-parachain",
"primitives/chain-rococo",
Expand Down
5 changes: 1 addition & 4 deletions primitives/chain-millau/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ mod millau_hash;

use bp_beefy::ChainWithBeefy;
use bp_header_chain::ChainWithGrandpa;
use bp_messages::{
ChainWithMessages, InboundMessageDetails, LaneId, MessageNonce, MessagePayload,
OutboundMessageDetails,
};
use bp_messages::{ChainWithMessages, MessageNonce};
use bp_runtime::{decl_bridge_finality_runtime_apis, decl_bridge_runtime_apis, Chain, ChainId};
use frame_support::{
dispatch::DispatchClass,
Expand Down
38 changes: 38 additions & 0 deletions primitives/chain-polkadot-bulletin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "bp-polkadot-bulletin"
description = "Primitives of Polkadot Bulletin chain runtime."
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[dependencies]

# Bridge Dependencies

bp-header-chain = { path = "../header-chain", default-features = false }
bp-messages = { path = "../messages", default-features = false }
bp-polkadot-core = { path = "../polkadot-core", default-features = false }
bp-runtime = { path = "../runtime", default-features = false }

# Substrate Based Dependencies

frame-support = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false }
frame-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false }
sp-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false }
sp-std = { git = "https://github.com/paritytech/polkadot-sdk", branch = "master", default-features = false }

[features]
default = ["std"]
std = [
"bp-header-chain/std",
"bp-messages/std",
"bp-polkadot-core/std",
"bp-runtime/std",
"frame-support/std",
"frame-system/std",
"sp-api/std",
"sp-runtime/std",
"sp-std/std",
]
131 changes: 131 additions & 0 deletions primitives/chain-polkadot-bulletin/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Parity Bridges Common.

// Parity Bridges Common 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.

// Parity Bridges Common 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 Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.

//! Polkadot Bulletin Chain primitives.

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

use bp_header_chain::ChainWithGrandpa;
use bp_messages::{ChainWithMessages, MessageNonce};
use bp_runtime::{
decl_bridge_finality_runtime_apis, decl_bridge_messages_runtime_apis, Chain, ChainId,
};
use frame_support::{
dispatch::DispatchClass,
parameter_types,
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
};
use frame_system::limits;
use sp_runtime::{Perbill, StateVersion};

// This chain reuses most of Polkadot primitives.

Choose a reason for hiding this comment

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

Not sure it's a good idea to tie these things to Polkadot? If they are changed in Polkadot they're not going to automatically change in the Bulletin Chain...

Choose a reason for hiding this comment

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

Should just take the definitions from runtime/src/lib.rs in the Bulletin Chain repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure it's a good idea to tie these things to Polkadot? If they are changed in Polkadot they're not going to automatically change in the Bulletin Chain...

True, but if types will change in Polkadot, they won't automatically change in bridges bp-polkadot-core crate as well :) Because polkadot uses its own crates and our bp-polkadot-core is just a minimal knowledge of Polkadot-like chains that we need to implement bridges. We need to track the possible type changes and act accordingly.

In bridges there are two "base" chain types that we are able to handle currently - standalone (Polkadot-like) chains and parachains (Cumulus-based mostly). To me the Bulletin Chain looks more Polkadot-like, hence the usage of the bp_polkadot_core crate. I could just copy paste those types and constants here, but it'll just increase amount of code and won't change anything in practice :) But feel free to insist - it isn't a big deal

Should just take the definitions from runtime/src/lib.rs in the Bulletin Chain repo?

There are two huge issues with that:

  • we are in a different repo and if we'll start referring bulleting chain crates here, it'll cause circular references;
  • this crate will be used by polkadot bridge hub runtime and we don't want to embed (at least build) another runtime when building Polkadot BH.

Actually, with your chain it is easier and I'd like to "use typedefs from this crate in Bulletin Chain runtime to avoid code duplication" as the PR description states later, if you'll accept such PR. I.e. instead of having type BlockNumber = u32; in bulletin chain runtime, I'd like to have it here and then simply reuse in runtime. WDYT?

Copy link

@zdave-parity zdave-parity Sep 8, 2023

Choose a reason for hiding this comment

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

I meant cut the definitions out of the Bulletin Chain's runtime/src/lib.rs and paste them here. They're just typedefs of Substrate types AFAIK, shouldn't be any dependency issues.

I'm happy to have the Bulletin Chain then get the definitions from here to avoid duplication; we're going to be depending on the bridges stuff anyway.

pub use bp_polkadot_core::{
AccountId, Balance, BlockNumber, Hash, Hasher, Header, Nonce, Signature,
AVERAGE_HEADER_SIZE_IN_JUSTIFICATION, MAX_HEADER_SIZE,
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY,
};

/// Maximal number of GRANDPA authorities at Polkadot Bulletin chain.
pub const MAX_AUTHORITIES_COUNT: u32 = 100;

/// Name of the With-Polkadot Bulletin chain GRANDPA pallet instance that is deployed at bridged
/// chains.
pub const WITH_POLKADOT_BULLETIN_GRANDPA_PALLET_NAME: &str = "BridgePolkadotBulletinGrandpa";
/// Name of the With-Polkadot Bulletin chain messages pallet instance that is deployed at bridged
/// chains.
pub const WITH_POLKADOT_BULLETIN_MESSAGES_PALLET_NAME: &str = "BridgePolkadotBulletinMessages";

// There are fewer system operations on this chain (e.g. staking, governance, etc.). Use a higher
// percentage of the block for data storage.
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(90);

// Re following constants - we are using the same values at Cumulus parachains. They are limited
// by the maximal transaction weight/size. Since block limits at Bulletin Chain are larger than
// at the Cumulus Bridgeg Hubs, we could reuse the same values.

/// Maximal number of unrewarded relayer entries at inbound lane for Cumulus-based parachains.
pub const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = 1024;

/// Maximal number of unconfirmed messages at inbound lane for Cumulus-based parachains.
pub const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce = 4096;

parameter_types! {
/// We allow for 2 seconds of compute with a 6 second average block time.
pub BlockWeights: limits::BlockWeights = limits::BlockWeights::with_sensible_defaults(
Weight::from_parts(2u64 * WEIGHT_REF_TIME_PER_SECOND, u64::MAX),
NORMAL_DISPATCH_RATIO,
);
// Note: Max transaction size is 8 MB. Set max block size to 10 MB to facilitate data storage.
// This is double the "normal" Relay Chain block length limit.
/// Maximal block length at Polkadot Bulletin chain.
pub BlockLength: limits::BlockLength = limits::BlockLength::max_with_normal_ratio(
10 * 1024 * 1024,
NORMAL_DISPATCH_RATIO,
);
}

/// Polkadot Bulletin Chain declaration.
pub struct PolkadotBulletin;

impl Chain for PolkadotBulletin {
const ID: ChainId = *b"pdbc";

type BlockNumber = BlockNumber;
type Hash = Hash;
type Hasher = Hasher;
type Header = Header;

type AccountId = AccountId;
type Balance = Balance;

Choose a reason for hiding this comment

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

The Bulletin Chain does not have balances at all. It's not that the tokens are worthless, they really just don't exist. I don't know if the bridges stuff supports not having a balance type, but if it doesn't it's at least worth a comment here explaining why we have to provide one and why that isn't a problem (assuming it isn't).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a fair point. I don't think we will be using this type anywhere for something critical. I'll add a comment in next commits

type Nonce = Nonce;
type Signature = Signature;

const STATE_VERSION: StateVersion = StateVersion::V1;

fn max_extrinsic_size() -> u32 {
*BlockLength::get().max.get(DispatchClass::Normal)
}

fn max_extrinsic_weight() -> Weight {
BlockWeights::get()
.get(DispatchClass::Normal)
.max_extrinsic
.unwrap_or(Weight::MAX)
}
}

impl ChainWithGrandpa for PolkadotBulletin {
const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = WITH_POLKADOT_BULLETIN_GRANDPA_PALLET_NAME;
const MAX_AUTHORITIES_COUNT: u32 = MAX_AUTHORITIES_COUNT;
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 =
REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY;
const MAX_HEADER_SIZE: u32 = MAX_HEADER_SIZE;
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
}

impl ChainWithMessages for PolkadotBulletin {
const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str =
WITH_POLKADOT_BULLETIN_MESSAGES_PALLET_NAME;

const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX;
const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce =
MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
}

decl_bridge_finality_runtime_apis!(polkadot_bulletin);
decl_bridge_messages_runtime_apis!(polkadot_bulletin);
5 changes: 1 addition & 4 deletions primitives/chain-rialto-parachain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
#![warn(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]

use bp_messages::{
ChainWithMessages, InboundMessageDetails, LaneId, MessageNonce, MessagePayload,
OutboundMessageDetails,
};
use bp_messages::{ChainWithMessages, MessageNonce};
use bp_runtime::{decl_bridge_runtime_apis, Chain, ChainId, Parachain};
use frame_support::{
dispatch::DispatchClass,
Expand Down
5 changes: 1 addition & 4 deletions primitives/chain-rialto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
#![cfg_attr(not(feature = "std"), no_std)]

use bp_header_chain::ChainWithGrandpa;
use bp_messages::{
ChainWithMessages, InboundMessageDetails, LaneId, MessageNonce, MessagePayload,
OutboundMessageDetails,
};
use bp_messages::{ChainWithMessages, MessageNonce};
use bp_runtime::{decl_bridge_finality_runtime_apis, decl_bridge_runtime_apis, Chain, ChainId};
use frame_support::{
dispatch::DispatchClass,
Expand Down
14 changes: 7 additions & 7 deletions primitives/runtime/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,10 @@ macro_rules! decl_bridge_messages_runtime_apis {
/// 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<OutboundMessageDetails>;
lane: bp_messages::LaneId,
begin: bp_messages::MessageNonce,
end: bp_messages::MessageNonce,
) -> Vec<bp_messages::OutboundMessageDetails>;
}

/// Inbound message lane API for messages sent by this chain.
Expand All @@ -387,9 +387,9 @@ macro_rules! decl_bridge_messages_runtime_apis {
pub trait [<From $chain:camel InboundLaneApi>] {
/// Return details of given inbound messages.
fn message_details(
lane: LaneId,
messages: Vec<(MessagePayload, OutboundMessageDetails)>,
) -> Vec<InboundMessageDetails>;
lane: bp_messages::LaneId,
messages: Vec<(bp_messages::MessagePayload, bp_messages::OutboundMessageDetails)>,
) -> Vec<bp_messages::InboundMessageDetails>;
}
}
}
Expand Down