-
Notifications
You must be signed in to change notification settings - Fork 129
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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", | ||
] |
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. | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ourbp-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 dealThere are two huge issues with that:
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?There was a problem hiding this comment.
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.