Update bridges subtree (#1740)

Co-authored-by: Branislav Kontur <bkontur@gmail.com>
This commit is contained in:
Svyatoslav Nikolsky
2023-10-04 01:14:01 +03:00
committed by GitHub
parent aad80cce31
commit d80171ec22
19 changed files with 1088 additions and 327 deletions
Generated
+17
View File
@@ -1654,6 +1654,23 @@ dependencies = [
"sp-std",
]
[[package]]
name = "bp-polkadot-bulletin"
version = "0.1.0"
dependencies = [
"bp-header-chain",
"bp-messages",
"bp-polkadot-core",
"bp-runtime",
"frame-support",
"frame-system",
"parity-scale-codec",
"scale-info",
"sp-api",
"sp-runtime",
"sp-std",
]
[[package]]
name = "bp-polkadot-core"
version = "0.1.0"
+1
View File
@@ -23,6 +23,7 @@ members = [
"bridges/primitives/chain-bridge-hub-wococo",
"bridges/primitives/chain-kusama",
"bridges/primitives/chain-polkadot",
"bridges/primitives/chain-polkadot-bulletin",
"bridges/primitives/chain-rococo",
"bridges/primitives/chain-wococo",
"bridges/primitives/header-chain",
@@ -38,7 +38,7 @@ where
PriorityBoostPerMessage: Get<TransactionPriority>,
{
// we don't want any boost for transaction with single message => minus one
PriorityBoostPerMessage::get().saturating_mul(messages - 1)
PriorityBoostPerMessage::get().saturating_mul(messages.saturating_sub(1))
}
#[cfg(not(feature = "integrity-test"))]
File diff suppressed because it is too large Load Diff
@@ -29,7 +29,6 @@ use frame_support::{
sp_runtime::{MultiAddress, MultiSigner},
};
use sp_runtime::RuntimeDebug;
use sp_std::prelude::Vec;
/// BridgeHubKusama parachain.
#[derive(RuntimeDebug)]
@@ -26,7 +26,6 @@ use bp_runtime::{
};
use frame_support::dispatch::DispatchClass;
use sp_runtime::RuntimeDebug;
use sp_std::prelude::Vec;
/// BridgeHubPolkadot parachain.
#[derive(RuntimeDebug)]
@@ -26,7 +26,7 @@ use bp_runtime::{
};
use frame_support::dispatch::DispatchClass;
use sp_runtime::{MultiAddress, MultiSigner, RuntimeDebug};
use sp_std::prelude::Vec;
/// BridgeHubRococo parachain.
#[derive(RuntimeDebug)]
pub struct BridgeHubRococo;
@@ -26,7 +26,6 @@ use bp_runtime::{
};
use frame_support::dispatch::DispatchClass;
use sp_runtime::RuntimeDebug;
use sp_std::prelude::Vec;
/// BridgeHubWococo parachain.
#[derive(RuntimeDebug)]
@@ -23,7 +23,6 @@ pub use bp_polkadot_core::*;
use bp_header_chain::ChainWithGrandpa;
use bp_runtime::{decl_bridge_finality_runtime_apis, Chain};
use frame_support::weights::Weight;
use sp_std::prelude::Vec;
/// Kusama Chain
pub struct Kusama;
@@ -0,0 +1,41 @@
[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]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] }
scale-info = { version = "2.9.0", default-features = false, features = ["derive"] }
# 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 = { path = "../../../substrate/frame/support", default-features = false }
frame-system = { path = "../../../substrate/frame/system", default-features = false }
sp-api = { path = "../../../substrate/primitives/api", default-features = false }
sp-runtime = { path = "../../../substrate/primitives/runtime", default-features = false }
sp-std = { path = "../../../substrate/primitives/std", default-features = false }
[features]
default = [ "std" ]
std = [
"bp-header-chain/std",
"bp-messages/std",
"bp-polkadot-core/std",
"bp-runtime/std",
"codec/std",
"frame-support/std",
"frame-system/std",
"sp-api/std",
"sp-runtime/std",
"sp-std/std",
]
@@ -0,0 +1,215 @@
// 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::MessageNonce;
use bp_runtime::{
decl_bridge_finality_runtime_apis, decl_bridge_messages_runtime_apis,
extensions::{
CheckEra, CheckGenesis, CheckNonZeroSender, CheckNonce, CheckSpecVersion, CheckTxVersion,
CheckWeight, GenericSignedExtension, GenericSignedExtensionSchema,
},
Chain, TransactionEra,
};
use codec::{Decode, Encode};
use frame_support::{
dispatch::DispatchClass,
parameter_types,
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
};
use frame_system::limits;
use scale_info::TypeInfo;
use sp_runtime::{traits::DispatchInfoOf, transaction_validity::TransactionValidityError, Perbill};
// This chain reuses most of Polkadot primitives.
pub use bp_polkadot_core::{
AccountAddress, AccountId, Balance, Block, BlockNumber, Hash, Hasher, Header, Nonce, Signature,
SignedBlock, UncheckedExtrinsic, AVERAGE_HEADER_SIZE_IN_JUSTIFICATION,
EXTRA_STORAGE_PROOF_SIZE, 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;
/// This signed extension is used to ensure that the chain transactions are signed by proper
pub type ValidateSigned = GenericSignedExtensionSchema<(), ()>;
/// Signed extension schema, used by Polkadot Bulletin.
pub type SignedExtensionSchema = GenericSignedExtension<(
(
CheckNonZeroSender,
CheckSpecVersion,
CheckTxVersion,
CheckGenesis<Hash>,
CheckEra<Hash>,
CheckNonce<Nonce>,
CheckWeight,
),
ValidateSigned,
)>;
/// Signed extension, used by Polkadot Bulletin.
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub struct SignedExtension(SignedExtensionSchema);
impl sp_runtime::traits::SignedExtension for SignedExtension {
const IDENTIFIER: &'static str = "Not needed.";
type AccountId = ();
type Call = ();
type AdditionalSigned =
<SignedExtensionSchema as sp_runtime::traits::SignedExtension>::AdditionalSigned;
type Pre = ();
fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
self.0.additional_signed()
}
fn pre_dispatch(
self,
_who: &Self::AccountId,
_call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
Ok(())
}
}
impl SignedExtension {
/// Create signed extension from its components.
pub fn from_params(
spec_version: u32,
transaction_version: u32,
era: TransactionEra<BlockNumber, Hash>,
genesis_hash: Hash,
nonce: Nonce,
) -> Self {
Self(GenericSignedExtension::new(
(
(
(), // non-zero sender
(), // spec version
(), // tx version
(), // genesis
era.frame_era(), // era
nonce.into(), // nonce (compact encoding)
(), // Check weight
),
(),
),
Some((
(
(),
spec_version,
transaction_version,
genesis_hash,
era.signed_payload(genesis_hash),
(),
(),
),
(),
)),
))
}
/// Return transaction nonce.
pub fn nonce(&self) -> Nonce {
let common_payload = self.0.payload.0;
common_payload.5 .0
}
}
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 {
type BlockNumber = BlockNumber;
type Hash = Hash;
type Hasher = Hasher;
type Header = Header;
type AccountId = AccountId;
// The Bulletin Chain is a permissioned blockchain without any balances. Our `Chain` trait
// requires balance type, which is then used by various bridge infrastructure code. However
// this code is optional and we are not planning to use it in our bridge.
type Balance = Balance;
type Nonce = Nonce;
type Signature = Signature;
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;
}
decl_bridge_finality_runtime_apis!(polkadot_bulletin, grandpa);
decl_bridge_messages_runtime_apis!(polkadot_bulletin);
@@ -23,7 +23,6 @@ pub use bp_polkadot_core::*;
use bp_header_chain::ChainWithGrandpa;
use bp_runtime::{decl_bridge_finality_runtime_apis, extensions::PrevalidateAttests, Chain};
use frame_support::weights::Weight;
use sp_std::prelude::Vec;
/// Polkadot Chain
pub struct Polkadot;
@@ -23,7 +23,6 @@ pub use bp_polkadot_core::*;
use bp_header_chain::ChainWithGrandpa;
use bp_runtime::{decl_bridge_finality_runtime_apis, Chain};
use frame_support::{parameter_types, weights::Weight};
use sp_std::prelude::Vec;
/// Rococo Chain
pub struct Rococo;
@@ -26,7 +26,6 @@ pub use bp_rococo::{
use bp_header_chain::ChainWithGrandpa;
use bp_runtime::{decl_bridge_finality_runtime_apis, Chain};
use frame_support::weights::Weight;
use sp_std::prelude::Vec;
/// Wococo Chain
pub struct Wococo;
@@ -143,6 +143,7 @@ pub enum PrecommitError {
}
/// The context needed for validating GRANDPA finality proofs.
#[derive(RuntimeDebug)]
pub struct JustificationVerificationContext {
/// The authority set used to verify the justification.
pub voter_set: VoterSet<AuthorityId>,
+8 -8
View File
@@ -311,7 +311,7 @@ macro_rules! decl_bridge_finality_runtime_apis {
$(
/// Returns the justifications accepted in the current block.
fn [<synced_headers_ $consensus:lower _info>](
) -> Vec<$justification_type>;
) -> sp_std::vec::Vec<$justification_type>;
)?
}
}
@@ -360,10 +360,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,
) -> sp_std::vec::Vec<bp_messages::OutboundMessageDetails>;
}
/// Inbound message lane API for messages sent by this chain.
@@ -376,9 +376,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: sp_std::vec::Vec<(bp_messages::MessagePayload, bp_messages::OutboundMessageDetails)>,
) -> sp_std::vec::Vec<bp_messages::InboundMessageDetails>;
}
}
}
+3
View File
@@ -74,6 +74,9 @@ pub const MILLAU_CHAIN_ID: ChainId = *b"mlau";
/// Polkadot chain id.
pub const POLKADOT_CHAIN_ID: ChainId = *b"pdot";
/// Polkadot Bulletin chain id.
pub const POLKADOT_BULLETIN_CHAIN_ID: ChainId = *b"pdbc";
/// Kusama chain id.
pub const KUSAMA_CHAIN_ID: ChainId = *b"ksma";
@@ -29,8 +29,8 @@ use bridge_runtime_common::{
},
messages_xcm_extension::{SenderAndLane, XcmBlobHauler, XcmBlobHaulerAdapter},
refund_relayer_extension::{
ActualFeeRefund, RefundBridgedParachainMessages, RefundableMessagesLane,
RefundableParachain,
ActualFeeRefund, RefundBridgedParachainMessages, RefundSignedExtensionAdapter,
RefundableMessagesLane, RefundableParachain,
},
};
use frame_support::{parameter_types, traits::PalletInfoAccess};
@@ -136,13 +136,15 @@ impl ThisChainWithMessages for BridgeHubRococo {
}
/// Signed extension that refunds relayers that are delivering messages from the Wococo parachain.
pub type BridgeRefundBridgeHubWococoMessages = RefundBridgedParachainMessages<
Runtime,
RefundableParachain<BridgeParachainWococoInstance, bp_bridge_hub_wococo::BridgeHubWococo>,
RefundableMessagesLane<WithBridgeHubWococoMessagesInstance, BridgeHubWococoMessagesLane>,
ActualFeeRefund<Runtime>,
PriorityBoostPerMessage,
StrBridgeRefundBridgeHubWococoMessages,
pub type BridgeRefundBridgeHubWococoMessages = RefundSignedExtensionAdapter<
RefundBridgedParachainMessages<
Runtime,
RefundableParachain<BridgeParachainWococoInstance, bp_bridge_hub_wococo::BridgeHubWococo>,
RefundableMessagesLane<WithBridgeHubWococoMessagesInstance, BridgeHubWococoMessagesLane>,
ActualFeeRefund<Runtime>,
PriorityBoostPerMessage,
StrBridgeRefundBridgeHubWococoMessages,
>,
>;
bp_runtime::generate_static_str_provider!(BridgeRefundBridgeHubWococoMessages);
@@ -29,8 +29,8 @@ use bridge_runtime_common::{
},
messages_xcm_extension::{SenderAndLane, XcmBlobHauler, XcmBlobHaulerAdapter},
refund_relayer_extension::{
ActualFeeRefund, RefundBridgedParachainMessages, RefundableMessagesLane,
RefundableParachain,
ActualFeeRefund, RefundBridgedParachainMessages, RefundSignedExtensionAdapter,
RefundableMessagesLane, RefundableParachain,
},
};
use frame_support::{parameter_types, traits::PalletInfoAccess};
@@ -136,13 +136,15 @@ impl ThisChainWithMessages for BridgeHubWococo {
}
/// Signed extension that refunds relayers that are delivering messages from the Rococo parachain.
pub type BridgeRefundBridgeHubRococoMessages = RefundBridgedParachainMessages<
Runtime,
RefundableParachain<BridgeParachainRococoInstance, bp_bridge_hub_rococo::BridgeHubRococo>,
RefundableMessagesLane<WithBridgeHubRococoMessagesInstance, BridgeHubRococoMessagesLane>,
ActualFeeRefund<Runtime>,
PriorityBoostPerMessage,
StrBridgeRefundBridgeHubRococoMessages,
pub type BridgeRefundBridgeHubRococoMessages = RefundSignedExtensionAdapter<
RefundBridgedParachainMessages<
Runtime,
RefundableParachain<BridgeParachainRococoInstance, bp_bridge_hub_rococo::BridgeHubRococo>,
RefundableMessagesLane<WithBridgeHubRococoMessagesInstance, BridgeHubRococoMessagesLane>,
ActualFeeRefund<Runtime>,
PriorityBoostPerMessage,
StrBridgeRefundBridgeHubRococoMessages,
>,
>;
bp_runtime::generate_static_str_provider!(BridgeRefundBridgeHubRococoMessages);