From c67d06aa59e85eb05806a78c3344d0157572b37a Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Thu, 16 Feb 2023 15:20:45 +0300 Subject: [PATCH] ChainWithGrandpa in primitives (#1885) * ChainWithGrandpa in primitives * clippy ++ spelling * fix benchmarks comppilation --- Cargo.lock | 10 ++++++ bin/millau/runtime/src/lib.rs | 27 +++----------- bin/rialto-parachain/runtime/src/lib.rs | 14 +------- bin/rialto/runtime/src/lib.rs | 14 +------- bin/runtime-common/src/mock.rs | 11 ++++-- modules/grandpa/src/benchmarking.rs | 3 +- modules/grandpa/src/lib.rs | 14 +++----- modules/grandpa/src/mock.rs | 18 ++++++++-- modules/grandpa/src/storage_types.rs | 16 +++++++-- modules/parachains/src/mock.rs | 19 ++++++++-- primitives/chain-kusama/Cargo.toml | 4 +++ primitives/chain-kusama/src/lib.rs | 36 +++++++++++++++++-- primitives/chain-millau/Cargo.toml | 13 ++++--- primitives/chain-millau/src/lib.rs | 31 ++++++++++++++++ primitives/chain-polkadot/Cargo.toml | 5 +++ primitives/chain-polkadot/src/lib.rs | 36 +++++++++++++++++-- primitives/chain-rialto/Cargo.toml | 2 ++ primitives/chain-rialto/src/lib.rs | 31 ++++++++++++++++ primitives/chain-rococo/Cargo.toml | 6 +++- primitives/chain-rococo/src/lib.rs | 37 +++++++++++++++++-- primitives/chain-westend/Cargo.toml | 2 ++ primitives/chain-westend/src/lib.rs | 33 ++++++++++++++++- primitives/chain-wococo/Cargo.toml | 6 ++++ primitives/chain-wococo/src/lib.rs | 36 +++++++++++++++++-- primitives/header-chain/src/lib.rs | 47 ++++++++++++++++++++++++- primitives/polkadot-core/src/lib.rs | 22 ++++++++++++ relays/client-kusama/src/lib.rs | 6 +--- relays/client-millau/src/lib.rs | 10 ++---- relays/client-polkadot/src/lib.rs | 7 +--- relays/client-rialto/src/lib.rs | 10 ++---- relays/client-rococo/src/lib.rs | 8 +---- relays/client-substrate/src/chain.rs | 19 +++++++--- relays/client-westend/src/lib.rs | 9 +---- relays/client-wococo/src/lib.rs | 8 +---- 34 files changed, 431 insertions(+), 139 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cad628df103..a5298107be1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -869,8 +869,10 @@ dependencies = [ name = "bp-kusama" version = "0.1.0" dependencies = [ + "bp-header-chain", "bp-polkadot-core", "bp-runtime", + "frame-support", "sp-api", ] @@ -894,6 +896,7 @@ name = "bp-millau" version = "0.1.0" dependencies = [ "bp-beefy", + "bp-header-chain", "bp-messages", "bp-runtime", "fixed-hash", @@ -933,8 +936,10 @@ dependencies = [ name = "bp-polkadot" version = "0.1.0" dependencies = [ + "bp-header-chain", "bp-polkadot-core", "bp-runtime", + "frame-support", "sp-api", ] @@ -973,6 +978,7 @@ dependencies = [ name = "bp-rialto" version = "0.1.0" dependencies = [ + "bp-header-chain", "bp-messages", "bp-runtime", "frame-support", @@ -1002,6 +1008,7 @@ dependencies = [ name = "bp-rococo" version = "0.1.0" dependencies = [ + "bp-header-chain", "bp-polkadot-core", "bp-runtime", "frame-support", @@ -1048,6 +1055,7 @@ dependencies = [ name = "bp-westend" version = "0.1.0" dependencies = [ + "bp-header-chain", "bp-polkadot-core", "bp-runtime", "frame-support", @@ -1058,9 +1066,11 @@ dependencies = [ name = "bp-wococo" version = "0.1.0" dependencies = [ + "bp-header-chain", "bp-polkadot-core", "bp-rococo", "bp-runtime", + "frame-support", "sp-api", ] diff --git a/bin/millau/runtime/src/lib.rs b/bin/millau/runtime/src/lib.rs index 8f82e645f9e..5a18f8b12c0 100644 --- a/bin/millau/runtime/src/lib.rs +++ b/bin/millau/runtime/src/lib.rs @@ -387,21 +387,6 @@ impl pallet_bridge_relayers::Config for Runtime { type WeightInfo = (); } -parameter_types! { - /// Number of headers to keep. - /// - /// Assuming the worst case of every header being finalized, we will keep headers at least for a - /// day. - pub const HeadersToKeep: u32 = bp_rialto::DAYS; - /// Maximal number of authorities at Rialto. - pub const MaxAuthoritiesAtRialto: u32 = bp_rialto::MAX_AUTHORITIES_COUNT; -} - -parameter_types! { - /// Maximal number of authorities at Westend. - pub const MaxAuthoritiesAtWestend: u32 = bp_westend::MAX_AUTHORITIES_COUNT; -} - pub type RialtoGrandpaInstance = (); impl pallet_bridge_grandpa::Config for Runtime { type BridgedChain = bp_rialto::Rialto; @@ -410,9 +395,7 @@ impl pallet_bridge_grandpa::Config for Runtime { // Note that once this is hit the pallet will essentially throttle incoming requests down to one // call per block. type MaxRequests = ConstU32<50>; - type HeadersToKeep = HeadersToKeep; - type MaxBridgedAuthorities = MaxAuthoritiesAtRialto; - + type HeadersToKeep = ConstU32<{ bp_rialto::DAYS }>; type WeightInfo = pallet_bridge_grandpa::weights::BridgeWeight; } @@ -420,9 +403,7 @@ pub type WestendGrandpaInstance = pallet_bridge_grandpa::Instance1; impl pallet_bridge_grandpa::Config for Runtime { type BridgedChain = bp_westend::Westend; type MaxRequests = ConstU32<50>; - type HeadersToKeep = HeadersToKeep; - type MaxBridgedAuthorities = MaxAuthoritiesAtWestend; - + type HeadersToKeep = ConstU32<{ bp_westend::DAYS }>; type WeightInfo = pallet_bridge_grandpa::weights::BridgeWeight; } @@ -521,7 +502,7 @@ impl pallet_bridge_parachains::Config for Runtime type ParasPalletName = RialtoParasPalletName; type ParaStoredHeaderDataBuilder = SingleParaStoredHeaderDataBuilder; - type HeadsToKeep = HeadersToKeep; + type HeadsToKeep = ConstU32<1024>; type MaxParaHeadDataSize = MaxRialtoParaHeadDataSize; } @@ -534,7 +515,7 @@ impl pallet_bridge_parachains::Config for Runtime type BridgesGrandpaPalletInstance = WestendGrandpaInstance; type ParasPalletName = WestendParasPalletName; type ParaStoredHeaderDataBuilder = SingleParaStoredHeaderDataBuilder; - type HeadsToKeep = HeadersToKeep; + type HeadsToKeep = ConstU32<1024>; type MaxParaHeadDataSize = MaxWestendParaHeadDataSize; } diff --git a/bin/rialto-parachain/runtime/src/lib.rs b/bin/rialto-parachain/runtime/src/lib.rs index ba1aa05463b..5eeddf41e52 100644 --- a/bin/rialto-parachain/runtime/src/lib.rs +++ b/bin/rialto-parachain/runtime/src/lib.rs @@ -525,17 +525,6 @@ impl pallet_bridge_relayers::Config for Runtime { type WeightInfo = (); } -parameter_types! { - /// Number of headers to keep. - /// - /// Assuming the worst case of every header being finalized, we will keep headers at least for a - /// day. - pub const HeadersToKeep: u32 = bp_millau::DAYS as u32; - - /// Maximal number of authorities at Millau. - pub const MaxAuthoritiesAtMillau: u32 = bp_millau::MAX_AUTHORITIES_COUNT; -} - pub type MillauGrandpaInstance = (); impl pallet_bridge_grandpa::Config for Runtime { type BridgedChain = bp_millau::Millau; @@ -544,8 +533,7 @@ impl pallet_bridge_grandpa::Config for Runtime { /// Note that once this is hit the pallet will essentially throttle incoming requests down to /// one call per block. type MaxRequests = ConstU32<50>; - type HeadersToKeep = HeadersToKeep; - type MaxBridgedAuthorities = MaxAuthoritiesAtMillau; + type HeadersToKeep = ConstU32<{ bp_millau::DAYS as u32 }>; type WeightInfo = pallet_bridge_grandpa::weights::BridgeWeight; } diff --git a/bin/rialto/runtime/src/lib.rs b/bin/rialto/runtime/src/lib.rs index cb3b6d60486..3959dbea1aa 100644 --- a/bin/rialto/runtime/src/lib.rs +++ b/bin/rialto/runtime/src/lib.rs @@ -397,17 +397,6 @@ impl pallet_bridge_relayers::Config for Runtime { type WeightInfo = (); } -parameter_types! { - /// Number of headers to keep. - /// - /// Assuming the worst case of every header being finalized, we will keep headers at least for a - /// day. - pub const HeadersToKeep: u32 = bp_rialto::DAYS; - - /// Maximal number of authorities at Millau. - pub const MaxAuthoritiesAtMillau: u32 = bp_millau::MAX_AUTHORITIES_COUNT; -} - pub type MillauGrandpaInstance = (); impl pallet_bridge_grandpa::Config for Runtime { type BridgedChain = bp_millau::Millau; @@ -416,8 +405,7 @@ impl pallet_bridge_grandpa::Config for Runtime { /// Note that once this is hit the pallet will essentially throttle incoming requests down to /// one call per block. type MaxRequests = ConstU32<50>; - type HeadersToKeep = HeadersToKeep; - type MaxBridgedAuthorities = MaxAuthoritiesAtMillau; + type HeadersToKeep = ConstU32<{ bp_millau::DAYS as u32 }>; type WeightInfo = pallet_bridge_grandpa::weights::BridgeWeight; } diff --git a/bin/runtime-common/src/mock.rs b/bin/runtime-common/src/mock.rs index 51b03447c63..a5ae9131f03 100644 --- a/bin/runtime-common/src/mock.rs +++ b/bin/runtime-common/src/mock.rs @@ -32,7 +32,7 @@ use crate::messages::{ BridgedChainWithMessages, HashOf, MessageBridge, ThisChainWithMessages, }; -use bp_header_chain::HeaderChain; +use bp_header_chain::{ChainWithGrandpa, HeaderChain}; use bp_messages::{target_chain::ForbidInboundMessages, LaneId, MessageNonce}; use bp_parachains::SingleParaStoredHeaderDataBuilder; use bp_runtime::{Chain, ChainId, Parachain, UnderlyingChainProvider}; @@ -195,7 +195,6 @@ impl pallet_bridge_grandpa::Config for TestRuntime { type BridgedChain = BridgedUnderlyingChain; type MaxRequests = ConstU32<50>; type HeadersToKeep = ConstU32<8>; - type MaxBridgedAuthorities = ConstU32<1024>; type WeightInfo = pallet_bridge_grandpa::weights::BridgeWeight; } @@ -372,6 +371,14 @@ impl Chain for BridgedUnderlyingChain { } } +impl ChainWithGrandpa for BridgedUnderlyingChain { + const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = ""; + const MAX_AUTHORITIES_COUNT: u32 = 16; + const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8; + const MAX_HEADER_SIZE: u32 = 256; + const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64; +} + impl Chain for BridgedUnderlyingParachain { type BlockNumber = BridgedChainBlockNumber; type Hash = BridgedChainHash; diff --git a/modules/grandpa/src/benchmarking.rs b/modules/grandpa/src/benchmarking.rs index 710a7e0952c..337943bee4e 100644 --- a/modules/grandpa/src/benchmarking.rs +++ b/modules/grandpa/src/benchmarking.rs @@ -47,7 +47,6 @@ use bp_test_utils::{ TEST_GRANDPA_SET_ID, }; use frame_benchmarking::{benchmarks_instance_pallet, whitelisted_caller}; -use frame_support::traits::Get; use frame_system::RawOrigin; use sp_finality_grandpa::AuthorityId; use sp_runtime::traits::{One, Zero}; @@ -68,7 +67,7 @@ const MAX_VOTE_ANCESTRIES_RANGE_END: u32 = // the same with validators - if there are too much validators, let's run benchmarks on subrange fn validator_set_range_end, I: 'static>() -> u32 { - let max_bridged_authorities = T::MaxBridgedAuthorities::get(); + let max_bridged_authorities = T::BridgedChain::MAX_AUTHORITIES_COUNT; if max_bridged_authorities > 128 { sp_std::cmp::max(128, max_bridged_authorities / 5) } else { diff --git a/modules/grandpa/src/lib.rs b/modules/grandpa/src/lib.rs index fca0cb1b758..197726dd47a 100644 --- a/modules/grandpa/src/lib.rs +++ b/modules/grandpa/src/lib.rs @@ -39,10 +39,10 @@ use storage_types::StoredAuthoritySet; use bp_header_chain::{ - justification::GrandpaJustification, HeaderChain, InitializationData, StoredHeaderData, - StoredHeaderDataBuilder, + justification::GrandpaJustification, ChainWithGrandpa, HeaderChain, InitializationData, + StoredHeaderData, StoredHeaderDataBuilder, }; -use bp_runtime::{BlockNumberOf, Chain, HashOf, HasherOf, HeaderId, HeaderOf, OwnedBridgeModule}; +use bp_runtime::{BlockNumberOf, HashOf, HasherOf, HeaderId, HeaderOf, OwnedBridgeModule}; use finality_grandpa::voter_set::VoterSet; use frame_support::{dispatch::PostDispatchInfo, ensure}; use sp_finality_grandpa::{ConsensusLog, GRANDPA_ENGINE_ID}; @@ -97,7 +97,7 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config { /// The chain we are bridging to here. - type BridgedChain: Chain; + type BridgedChain: ChainWithGrandpa; /// The upper bound on the number of requests allowed by the pallet. /// @@ -118,10 +118,6 @@ pub mod pallet { #[pallet::constant] type HeadersToKeep: Get; - /// Max number of authorities at the bridged chain. - #[pallet::constant] - type MaxBridgedAuthorities: Get; - /// Weights gathered through benchmarking. type WeightInfo: WeightInfo; } @@ -513,7 +509,7 @@ pub mod pallet { target: LOG_TARGET, "Failed to initialize bridge. Number of authorities in the set {} is larger than the configured value {}", authority_set_length, - T::MaxBridgedAuthorities::get(), + T::BridgedChain::MAX_AUTHORITIES_COUNT, ); Error::TooManyAuthoritiesInSet diff --git a/modules/grandpa/src/mock.rs b/modules/grandpa/src/mock.rs index 8757093ee68..f0ae2583529 100644 --- a/modules/grandpa/src/mock.rs +++ b/modules/grandpa/src/mock.rs @@ -17,8 +17,13 @@ // From construct_runtime macro #![allow(clippy::from_over_into)] +use bp_header_chain::ChainWithGrandpa; use bp_runtime::Chain; -use frame_support::{construct_runtime, parameter_types, traits::ConstU64, weights::Weight}; +use frame_support::{ + construct_runtime, parameter_types, + traits::{ConstU32, ConstU64}, + weights::Weight, +}; use sp_core::sr25519::Signature; use sp_runtime::{ testing::{Header, H256}, @@ -78,7 +83,7 @@ impl frame_system::Config for TestRuntime { type BlockLength = (); type SS58Prefix = (); type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; + type MaxConsumers = ConstU32<16>; } parameter_types! { @@ -92,7 +97,6 @@ impl grandpa::Config for TestRuntime { type BridgedChain = TestBridgedChain; type MaxRequests = MaxRequests; type HeadersToKeep = HeadersToKeep; - type MaxBridgedAuthorities = frame_support::traits::ConstU32; type WeightInfo = (); } @@ -118,6 +122,14 @@ impl Chain for TestBridgedChain { } } +impl ChainWithGrandpa for TestBridgedChain { + const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = ""; + const MAX_AUTHORITIES_COUNT: u32 = MAX_BRIDGED_AUTHORITIES; + const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8; + const MAX_HEADER_SIZE: u32 = 256; + const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64; +} + pub fn run_test(test: impl FnOnce() -> T) -> T { sp_io::TestExternalities::new(Default::default()).execute_with(test) } diff --git a/modules/grandpa/src/storage_types.rs b/modules/grandpa/src/storage_types.rs index 732e72e2c0d..918c131289c 100644 --- a/modules/grandpa/src/storage_types.rs +++ b/modules/grandpa/src/storage_types.rs @@ -18,22 +18,32 @@ use crate::Config; -use bp_header_chain::AuthoritySet; +use bp_header_chain::{AuthoritySet, ChainWithGrandpa}; use codec::{Decode, Encode, MaxEncodedLen}; use frame_support::{traits::Get, BoundedVec, RuntimeDebugNoBound}; use scale_info::TypeInfo; use sp_finality_grandpa::{AuthorityId, AuthorityList, AuthorityWeight, SetId}; +use sp_std::marker::PhantomData; /// A bounded list of Grandpa authorities with associated weights. pub type StoredAuthorityList = BoundedVec<(AuthorityId, AuthorityWeight), MaxBridgedAuthorities>; +/// Adapter for using `T::BridgedChain::MAX_BRIDGED_AUTHORITIES` in `BoundedVec`. +pub struct StoredAuthorityListLimit(PhantomData<(T, I)>); + +impl, I: 'static> Get for StoredAuthorityListLimit { + fn get() -> u32 { + T::BridgedChain::MAX_AUTHORITIES_COUNT + } +} + /// A bounded GRANDPA Authority List and ID. #[derive(Clone, Decode, Encode, Eq, TypeInfo, MaxEncodedLen, RuntimeDebugNoBound)] #[scale_info(skip_type_params(T, I))] pub struct StoredAuthoritySet, I: 'static> { /// List of GRANDPA authorities for the current round. - pub authorities: StoredAuthorityList<>::MaxBridgedAuthorities>, + pub authorities: StoredAuthorityList>, /// Monotonic identifier of the current GRANDPA authority set. pub set_id: SetId, } @@ -60,7 +70,7 @@ impl, I: 'static> StoredAuthoritySet { let single_authority_max_encoded_len = <(AuthorityId, AuthorityWeight)>::max_encoded_len() as u64; let extra_authorities = - T::MaxBridgedAuthorities::get().saturating_sub(self.authorities.len() as _); + T::BridgedChain::MAX_AUTHORITIES_COUNT.saturating_sub(self.authorities.len() as _); single_authority_max_encoded_len.saturating_mul(extra_authorities as u64) } } diff --git a/modules/parachains/src/mock.rs b/modules/parachains/src/mock.rs index 8248964263c..0e8261f6899 100644 --- a/modules/parachains/src/mock.rs +++ b/modules/parachains/src/mock.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity Bridges Common. If not, see . +use bp_header_chain::ChainWithGrandpa; use bp_polkadot_core::parachains::ParaId; use bp_runtime::{Chain, Parachain}; use frame_support::{construct_runtime, parameter_types, traits::ConstU32, weights::Weight}; @@ -199,7 +200,6 @@ impl pallet_bridge_grandpa::Config for TestRun type BridgedChain = TestBridgedChain; type MaxRequests = ConstU32<2>; type HeadersToKeep = HeadersToKeep; - type MaxBridgedAuthorities = frame_support::traits::ConstU32<5>; type WeightInfo = (); } @@ -207,7 +207,6 @@ impl pallet_bridge_grandpa::Config for TestRun type BridgedChain = TestBridgedChain; type MaxRequests = ConstU32<2>; type HeadersToKeep = HeadersToKeep; - type MaxBridgedAuthorities = frame_support::traits::ConstU32<5>; type WeightInfo = (); } @@ -250,6 +249,14 @@ impl Chain for TestBridgedChain { } } +impl ChainWithGrandpa for TestBridgedChain { + const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = ""; + const MAX_AUTHORITIES_COUNT: u32 = 16; + const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8; + const MAX_HEADER_SIZE: u32 = 256; + const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64; +} + #[derive(Debug)] pub struct OtherBridgedChain; @@ -273,6 +280,14 @@ impl Chain for OtherBridgedChain { } } +impl ChainWithGrandpa for OtherBridgedChain { + const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = ""; + const MAX_AUTHORITIES_COUNT: u32 = 16; + const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8; + const MAX_HEADER_SIZE: u32 = 256; + const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64; +} + pub fn run_test(test: impl FnOnce() -> T) -> T { sp_io::TestExternalities::new(Default::default()).execute_with(|| { System::set_block_number(1); diff --git a/primitives/chain-kusama/Cargo.toml b/primitives/chain-kusama/Cargo.toml index 3bca5f4c3f0..7f48ded1a37 100644 --- a/primitives/chain-kusama/Cargo.toml +++ b/primitives/chain-kusama/Cargo.toml @@ -10,17 +10,21 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" # Bridge Dependencies +bp-header-chain = { path = "../header-chain", 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/substrate", branch = "master", default-features = false } sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } [features] default = ["std"] std = [ + "bp-header-chain/std", "bp-polkadot-core/std", "bp-runtime/std", + "frame-support/std", "sp-api/std", ] diff --git a/primitives/chain-kusama/src/lib.rs b/primitives/chain-kusama/src/lib.rs index 27d5f125ee2..9ada688bf11 100644 --- a/primitives/chain-kusama/src/lib.rs +++ b/primitives/chain-kusama/src/lib.rs @@ -19,10 +19,42 @@ #![allow(clippy::too_many_arguments)] pub use bp_polkadot_core::*; -use bp_runtime::decl_bridge_finality_runtime_apis; + +use bp_header_chain::ChainWithGrandpa; +use bp_runtime::{decl_bridge_finality_runtime_apis, Chain}; +use frame_support::weights::Weight; /// Kusama Chain -pub type Kusama = PolkadotLike; +pub struct Kusama; + +impl Chain for Kusama { + type BlockNumber = ::BlockNumber; + type Hash = ::Hash; + type Hasher = ::Hasher; + type Header = ::Header; + + type AccountId = ::AccountId; + type Balance = ::Balance; + type Index = ::Index; + type Signature = ::Signature; + + fn max_extrinsic_size() -> u32 { + PolkadotLike::max_extrinsic_size() + } + + fn max_extrinsic_weight() -> Weight { + PolkadotLike::max_extrinsic_weight() + } +} + +impl ChainWithGrandpa for Kusama { + const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = WITH_KUSAMA_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; +} /// Name of the With-Kusama GRANDPA pallet instance that is deployed at bridged chains. pub const WITH_KUSAMA_GRANDPA_PALLET_NAME: &str = "BridgeKusamaGrandpa"; diff --git a/primitives/chain-millau/Cargo.toml b/primitives/chain-millau/Cargo.toml index 7600781d891..00d5a02d47c 100644 --- a/primitives/chain-millau/Cargo.toml +++ b/primitives/chain-millau/Cargo.toml @@ -8,11 +8,6 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] -# Bridge Dependencies - -bp-beefy = { path = "../beefy", default-features = false } -bp-messages = { path = "../messages", default-features = false } -bp-runtime = { path = "../runtime", default-features = false } fixed-hash = { version = "0.8.0", default-features = false } hash256-std-hasher = { version = "0.15.2", default-features = false } impl-codec = { version = "0.6", default-features = false } @@ -21,6 +16,13 @@ parity-util-mem = { version = "0.12.0", default-features = false, features = ["p scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } serde = { version = "1.0", optional = true, features = ["derive"] } +# Bridge Dependencies + +bp-beefy = { path = "../beefy", default-features = false } +bp-header-chain = { path = "../header-chain", default-features = false } +bp-messages = { path = "../messages", default-features = false } +bp-runtime = { path = "../runtime", default-features = false } + # Substrate Based Dependencies frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -36,6 +38,7 @@ sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master", default = ["std"] std = [ "bp-beefy/std", + "bp-header-chain/std", "bp-messages/std", "bp-runtime/std", "fixed-hash/std", diff --git a/primitives/chain-millau/src/lib.rs b/primitives/chain-millau/src/lib.rs index 73515a7f409..81ed5436263 100644 --- a/primitives/chain-millau/src/lib.rs +++ b/primitives/chain-millau/src/lib.rs @@ -21,6 +21,7 @@ mod millau_hash; use bp_beefy::ChainWithBeefy; +use bp_header_chain::ChainWithGrandpa; use bp_messages::{ InboundMessageDetails, LaneId, MessageNonce, MessagePayload, OutboundMessageDetails, }; @@ -83,6 +84,27 @@ pub const SESSION_LENGTH: BlockNumber = 5 * time_units::MINUTES; /// Maximal number of GRANDPA authorities at Millau. pub const MAX_AUTHORITIES_COUNT: u32 = 5; +/// Reasonable number of headers in the `votes_ancestries` on Millau chain. +/// +/// See [`bp_header_chain::ChainWithGrandpa`] for more details. +pub const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8; + +/// Approximate average header size in `votes_ancestries` field of justification on Millau chain. +/// +/// See [`bp_header_chain::ChainWithGrandpa`] for more details. +pub const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 256; + +/// Approximate maximal header size on Millau chain. +/// +/// We expect maximal header to have digest item with the new authorities set for every consensus +/// engine (GRANDPA, Babe, BEEFY, ...) - so we multiply it by 3. And also +/// `AVERAGE_HEADER_SIZE_IN_JUSTIFICATION` bytes for other stuff. +/// +/// See [`bp_header_chain::ChainWithGrandpa`] for more details. +pub const MAX_HEADER_SIZE: u32 = MAX_AUTHORITIES_COUNT + .saturating_mul(3) + .saturating_add(AVERAGE_HEADER_SIZE_IN_JUSTIFICATION); + /// Re-export `time_units` to make usage easier. pub use time_units::*; @@ -156,6 +178,15 @@ impl Chain for Millau { } } +impl ChainWithGrandpa for Millau { + const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = WITH_MILLAU_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 ChainWithBeefy for Millau { type CommitmentHasher = Keccak256; type MmrHashing = Keccak256; diff --git a/primitives/chain-polkadot/Cargo.toml b/primitives/chain-polkadot/Cargo.toml index b26093a0570..def26bdda1c 100644 --- a/primitives/chain-polkadot/Cargo.toml +++ b/primitives/chain-polkadot/Cargo.toml @@ -7,19 +7,24 @@ 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-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/substrate", branch = "master", default-features = false } sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } [features] default = ["std"] std = [ + "bp-header-chain/std", "bp-polkadot-core/std", "bp-runtime/std", + "frame-support/std", "sp-api/std", ] diff --git a/primitives/chain-polkadot/src/lib.rs b/primitives/chain-polkadot/src/lib.rs index 0cada4e49a9..e1600102fcd 100644 --- a/primitives/chain-polkadot/src/lib.rs +++ b/primitives/chain-polkadot/src/lib.rs @@ -19,10 +19,42 @@ #![allow(clippy::too_many_arguments)] pub use bp_polkadot_core::*; -use bp_runtime::decl_bridge_finality_runtime_apis; + +use bp_header_chain::ChainWithGrandpa; +use bp_runtime::{decl_bridge_finality_runtime_apis, Chain}; +use frame_support::weights::Weight; /// Polkadot Chain -pub type Polkadot = PolkadotLike; +pub struct Polkadot; + +impl Chain for Polkadot { + type BlockNumber = ::BlockNumber; + type Hash = ::Hash; + type Hasher = ::Hasher; + type Header = ::Header; + + type AccountId = ::AccountId; + type Balance = ::Balance; + type Index = ::Index; + type Signature = ::Signature; + + fn max_extrinsic_size() -> u32 { + PolkadotLike::max_extrinsic_size() + } + + fn max_extrinsic_weight() -> Weight { + PolkadotLike::max_extrinsic_weight() + } +} + +impl ChainWithGrandpa for Polkadot { + const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = WITH_POLKADOT_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; +} /// Name of the With-Polkadot GRANDPA pallet instance that is deployed at bridged chains. pub const WITH_POLKADOT_GRANDPA_PALLET_NAME: &str = "BridgePolkadotGrandpa"; diff --git a/primitives/chain-rialto/Cargo.toml b/primitives/chain-rialto/Cargo.toml index 663f9076657..0a70e0504c9 100644 --- a/primitives/chain-rialto/Cargo.toml +++ b/primitives/chain-rialto/Cargo.toml @@ -10,6 +10,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" # Bridge Dependencies +bp-header-chain = { path = "../header-chain", default-features = false } bp-messages = { path = "../messages", default-features = false } bp-runtime = { path = "../runtime", default-features = false } @@ -25,6 +26,7 @@ sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", d [features] default = ["std"] std = [ + "bp-header-chain/std", "bp-messages/std", "bp-runtime/std", "frame-support/std", diff --git a/primitives/chain-rialto/src/lib.rs b/primitives/chain-rialto/src/lib.rs index ca0a3dfee88..a1c4a7267a7 100644 --- a/primitives/chain-rialto/src/lib.rs +++ b/primitives/chain-rialto/src/lib.rs @@ -18,6 +18,7 @@ // RuntimeApi generated functions #![allow(clippy::too_many_arguments)] +use bp_header_chain::ChainWithGrandpa; use bp_messages::{ InboundMessageDetails, LaneId, MessageNonce, MessagePayload, OutboundMessageDetails, }; @@ -72,6 +73,27 @@ pub const SESSION_LENGTH: BlockNumber = 4; /// Maximal number of GRANDPA authorities at Rialto. pub const MAX_AUTHORITIES_COUNT: u32 = 5; +/// Reasonable number of headers in the `votes_ancestries` on Rialto chain. +/// +/// See [`bp_header_chain::ChainWithGrandpa`] for more details. +pub const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8; + +/// Approximate average header size in `votes_ancestries` field of justification on Rialto chain. +/// +/// See [`bp_header_chain::ChainWithGrandpa`] for more details. +pub const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 256; + +/// Approximate maximal header size on Rialto chain. +/// +/// We expect maximal header to have digest item with the new authorities set for every consensus +/// engine (GRANDPA, Babe, BEEFY, ...) - so we multiply it by 3. And also +/// `AVERAGE_HEADER_SIZE_IN_JUSTIFICATION` bytes for other stuff. +/// +/// See [`bp_header_chain::ChainWithGrandpa`] for more details. +pub const MAX_HEADER_SIZE: u32 = MAX_AUTHORITIES_COUNT + .saturating_mul(3) + .saturating_add(AVERAGE_HEADER_SIZE_IN_JUSTIFICATION); + /// Maximal size of encoded `bp_parachains::ParaStoredHeaderData` structure among all Rialto /// parachains. /// @@ -160,6 +182,15 @@ impl Chain for Rialto { } } +impl ChainWithGrandpa for Rialto { + const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = WITH_RIALTO_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; +} + frame_support::parameter_types! { pub BlockLength: limits::BlockLength = limits::BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); diff --git a/primitives/chain-rococo/Cargo.toml b/primitives/chain-rococo/Cargo.toml index 73a2450cd17..4e21bd38b7a 100644 --- a/primitives/chain-rococo/Cargo.toml +++ b/primitives/chain-rococo/Cargo.toml @@ -9,18 +9,22 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] # Bridge Dependencies + +bp-header-chain = { path = "../header-chain", default-features = false } bp-polkadot-core = { path = "../polkadot-core", default-features = false } bp-runtime = { path = "../runtime", default-features = false } # Substrate Based Dependencies + sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } [features] default = ["std"] std = [ + "bp-header-chain/std", "bp-polkadot-core/std", "bp-runtime/std", - "sp-api/std", "frame-support/std", + "sp-api/std", ] diff --git a/primitives/chain-rococo/src/lib.rs b/primitives/chain-rococo/src/lib.rs index 41fc65e0e93..0cb0b1d41e6 100644 --- a/primitives/chain-rococo/src/lib.rs +++ b/primitives/chain-rococo/src/lib.rs @@ -19,11 +19,42 @@ #![allow(clippy::too_many_arguments)] pub use bp_polkadot_core::*; -use bp_runtime::decl_bridge_finality_runtime_apis; -use frame_support::parameter_types; + +use bp_header_chain::ChainWithGrandpa; +use bp_runtime::{decl_bridge_finality_runtime_apis, Chain}; +use frame_support::{parameter_types, weights::Weight}; /// Rococo Chain -pub type Rococo = PolkadotLike; +pub struct Rococo; + +impl Chain for Rococo { + type BlockNumber = ::BlockNumber; + type Hash = ::Hash; + type Hasher = ::Hasher; + type Header = ::Header; + + type AccountId = ::AccountId; + type Balance = ::Balance; + type Index = ::Index; + type Signature = ::Signature; + + fn max_extrinsic_size() -> u32 { + PolkadotLike::max_extrinsic_size() + } + + fn max_extrinsic_weight() -> Weight { + PolkadotLike::max_extrinsic_weight() + } +} + +impl ChainWithGrandpa for Rococo { + const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = WITH_ROCOCO_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; +} parameter_types! { pub const SS58Prefix: u8 = 42; diff --git a/primitives/chain-westend/Cargo.toml b/primitives/chain-westend/Cargo.toml index 75f6727d764..13a2e597f9d 100644 --- a/primitives/chain-westend/Cargo.toml +++ b/primitives/chain-westend/Cargo.toml @@ -10,6 +10,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" # Bridge Dependencies +bp-header-chain = { path = "../header-chain", default-features = false } bp-polkadot-core = { path = "../polkadot-core", default-features = false } bp-runtime = { path = "../runtime", default-features = false } @@ -21,6 +22,7 @@ sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", d [features] default = ["std"] std = [ + "bp-header-chain/std", "bp-polkadot-core/std", "bp-runtime/std", "frame-support/std", diff --git a/primitives/chain-westend/src/lib.rs b/primitives/chain-westend/src/lib.rs index 910a6c4acbd..b6d41ece286 100644 --- a/primitives/chain-westend/src/lib.rs +++ b/primitives/chain-westend/src/lib.rs @@ -19,11 +19,42 @@ #![allow(clippy::too_many_arguments)] pub use bp_polkadot_core::*; + +use bp_header_chain::ChainWithGrandpa; use bp_runtime::{decl_bridge_finality_runtime_apis, Chain, Parachain}; use frame_support::weights::Weight; /// Westend Chain -pub type Westend = PolkadotLike; +pub struct Westend; + +impl Chain for Westend { + type BlockNumber = ::BlockNumber; + type Hash = ::Hash; + type Hasher = ::Hasher; + type Header = ::Header; + + type AccountId = ::AccountId; + type Balance = ::Balance; + type Index = ::Index; + type Signature = ::Signature; + + fn max_extrinsic_size() -> u32 { + PolkadotLike::max_extrinsic_size() + } + + fn max_extrinsic_weight() -> Weight { + PolkadotLike::max_extrinsic_weight() + } +} + +impl ChainWithGrandpa for Westend { + const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = WITH_WESTEND_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; +} /// Westmint parachain definition #[derive(Debug, Clone, Copy)] diff --git a/primitives/chain-wococo/Cargo.toml b/primitives/chain-wococo/Cargo.toml index 6b741cd4b73..25fd7b9fd94 100644 --- a/primitives/chain-wococo/Cargo.toml +++ b/primitives/chain-wococo/Cargo.toml @@ -9,18 +9,24 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] # Bridge Dependencies + +bp-header-chain = { path = "../header-chain", default-features = false } bp-polkadot-core = { path = "../polkadot-core", default-features = false } bp-runtime = { path = "../runtime", default-features = false } bp-rococo = { path = "../chain-rococo", default-features = false } # Substrate Based Dependencies + +frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } [features] default = ["std"] std = [ + "bp-header-chain/std", "bp-polkadot-core/std", "bp-runtime/std", "bp-rococo/std", + "frame-support/std", "sp-api/std", ] diff --git a/primitives/chain-wococo/src/lib.rs b/primitives/chain-wococo/src/lib.rs index 1cf666c7f96..2df019496ab 100644 --- a/primitives/chain-wococo/src/lib.rs +++ b/primitives/chain-wococo/src/lib.rs @@ -22,10 +22,42 @@ pub use bp_polkadot_core::*; pub use bp_rococo::{ SS58Prefix, MAX_AUTHORITIES_COUNT, MAX_NESTED_PARACHAIN_HEAD_DATA_SIZE, PARAS_PALLET_NAME, }; -use bp_runtime::decl_bridge_finality_runtime_apis; + +use bp_header_chain::ChainWithGrandpa; +use bp_runtime::{decl_bridge_finality_runtime_apis, Chain}; +use frame_support::weights::Weight; /// Wococo Chain -pub type Wococo = PolkadotLike; +pub struct Wococo; + +impl Chain for Wococo { + type BlockNumber = ::BlockNumber; + type Hash = ::Hash; + type Hasher = ::Hasher; + type Header = ::Header; + + type AccountId = ::AccountId; + type Balance = ::Balance; + type Index = ::Index; + type Signature = ::Signature; + + fn max_extrinsic_size() -> u32 { + PolkadotLike::max_extrinsic_size() + } + + fn max_extrinsic_weight() -> Weight { + PolkadotLike::max_extrinsic_weight() + } +} + +impl ChainWithGrandpa for Wococo { + const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = WITH_WOCOCO_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; +} /// Name of the With-Wococo GRANDPA pallet instance that is deployed at bridged chains. pub const WITH_WOCOCO_GRANDPA_PALLET_NAME: &str = "BridgeWococoGrandpa"; diff --git a/primitives/header-chain/src/lib.rs b/primitives/header-chain/src/lib.rs index 49d1ae89406..cafb8e7a3c8 100644 --- a/primitives/header-chain/src/lib.rs +++ b/primitives/header-chain/src/lib.rs @@ -119,7 +119,7 @@ impl AuthoritySet { } } -/// Data required for initializing the bridge pallet. +/// Data required for initializing the GRANDPA bridge pallet. /// /// The bridge needs to know where to start its sync from, and this provides that initial context. #[derive(Default, Encode, Decode, RuntimeDebug, PartialEq, Eq, Clone, TypeInfo)] @@ -188,3 +188,48 @@ pub enum BridgeGrandpaCall { /// The `BridgeGrandpaCall` used by a chain. pub type BridgeGrandpaCallOf = BridgeGrandpaCall>; + +/// Substrate-based chain that is using direct GRANDPA finality. +/// +/// Keep in mind that parachains are relying on relay chain GRANDPA, so they should not implement +/// this trait. +pub trait ChainWithGrandpa: Chain { + /// Name of the bridge GRANDPA pallet (used in `construct_runtime` macro call) that is deployed + /// at some other chain to bridge with this `ChainWithGrandpa`. + /// + /// We assume that all chains that are bridging with this `ChainWithGrandpa` are using + /// the same name. + const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str; + + /// Max number of GRANDPA authorities at the chain. + /// + /// This is a strict constant. If bridged chain will have more authorities than that, + /// the GRANDPA bridge pallet may halt. + const MAX_AUTHORITIES_COUNT: u32; + + /// Max reasonable number of headers in `votes_ancestries` vector of the GRANDPA justification. + /// + /// This isn't a strict limit. The relay may submit justifications with more headers in its + /// ancestry and the pallet will accept such justification. The limit is only used to compute + /// maximal refund amount and submitting justifications which exceed the limit, may be costly + /// to submitter. + const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32; + + /// Maximal size of the chain header. The header may be the header that enacts new GRANDPA + /// authorities set (so it has large digest inside). + /// + /// This isn't a strict limit. The relay may submit larger headers and the pallet will accept + /// the call. The limit is only used to compute maximal refund amount and doing calls which + /// exceed the limit, may be costly to submitter. + const MAX_HEADER_SIZE: u32; + + /// Average size of the chain header from justification ancestry. We don't expect to see there + /// headers that change GRANDPA authorities set (GRANDPA will probably be able to finalize at + /// least one additional header per session on non test chains), so this is average size of + /// headers that aren't changing the set. + /// + /// This isn't a strict limit. The relay may submit justifications with larger headers in its + /// ancestry and the pallet will accept the call. The limit is only used to compute maximal + /// refund amount and doing calls which exceed the limit, may be costly to submitter. + const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32; +} diff --git a/primitives/polkadot-core/src/lib.rs b/primitives/polkadot-core/src/lib.rs index b13ceb5df50..3b1712042d8 100644 --- a/primitives/polkadot-core/src/lib.rs +++ b/primitives/polkadot-core/src/lib.rs @@ -53,6 +53,28 @@ pub mod parachains; /// take twice as much here. pub const MAX_AUTHORITIES_COUNT: u32 = 2_048; +/// Reasonable number of headers in the `votes_ancestries` on Polkadot-like chains. +/// +/// See [`bp_header_chain::ChainWithGrandpa`] for more details. +pub const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8; + +/// Approximate average header size in `votes_ancestries` field of justification on Polkadot-like +/// chains. +/// +/// See [`bp_header_chain::ChainWithGrandpa`] for more details. +pub const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 256; + +/// Approximate maximal header size on Polkadot-like chains. +/// +/// We expect maximal header to have digest item with the new authorities set for every consensus +/// engine (GRANDPA, Babe, BEEFY, ...) - so we multiply it by 3. And also +/// `AVERAGE_HEADER_SIZE_IN_JUSTIFICATION` bytes for other stuff. +/// +/// See [`bp_header_chain::ChainWithGrandpa`] for more details. +pub const MAX_HEADER_SIZE: u32 = MAX_AUTHORITIES_COUNT + .saturating_mul(3) + .saturating_add(AVERAGE_HEADER_SIZE_IN_JUSTIFICATION); + /// Number of extra bytes (excluding size of storage value itself) of storage proof, built at /// Polkadot-like chain. This mostly depends on number of entries in the storage trie. /// Some reserve is reserved to account future chain growth. diff --git a/relays/client-kusama/src/lib.rs b/relays/client-kusama/src/lib.rs index cd6e23a4607..83f6b30f4cb 100644 --- a/relays/client-kusama/src/lib.rs +++ b/relays/client-kusama/src/lib.rs @@ -17,7 +17,7 @@ //! Types used to connect to the Kusama chain. use bp_kusama::AccountInfoStorageMapKeyProvider; -use relay_substrate_client::{Chain, ChainWithBalances, ChainWithGrandpa, UnderlyingChainProvider}; +use relay_substrate_client::{Chain, ChainWithBalances, UnderlyingChainProvider}; use sp_core::storage::StorageKey; use std::time::Duration; @@ -43,10 +43,6 @@ impl Chain for Kusama { type Call = (); } -impl ChainWithGrandpa for Kusama { - const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = bp_kusama::WITH_KUSAMA_GRANDPA_PALLET_NAME; -} - impl ChainWithBalances for Kusama { fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey { AccountInfoStorageMapKeyProvider::final_key(account_id) diff --git a/relays/client-millau/src/lib.rs b/relays/client-millau/src/lib.rs index 34bbea92d57..711b4f32cc6 100644 --- a/relays/client-millau/src/lib.rs +++ b/relays/client-millau/src/lib.rs @@ -19,9 +19,9 @@ use bp_messages::MessageNonce; use codec::{Compact, Decode, Encode}; use relay_substrate_client::{ - BalanceOf, Chain, ChainWithBalances, ChainWithGrandpa, ChainWithMessages, - ChainWithTransactions, ChainWithUtilityPallet, Error as SubstrateError, - FullRuntimeUtilityPallet, IndexOf, SignParam, UnderlyingChainProvider, UnsignedTransaction, + BalanceOf, Chain, ChainWithBalances, ChainWithMessages, ChainWithTransactions, + ChainWithUtilityPallet, Error as SubstrateError, FullRuntimeUtilityPallet, IndexOf, SignParam, + UnderlyingChainProvider, UnsignedTransaction, }; use sp_core::{storage::StorageKey, Pair}; use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount}; @@ -38,10 +38,6 @@ impl UnderlyingChainProvider for Millau { type Chain = bp_millau::Millau; } -impl ChainWithGrandpa for Millau { - const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = bp_millau::WITH_MILLAU_GRANDPA_PALLET_NAME; -} - impl ChainWithMessages for Millau { const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str = bp_millau::WITH_MILLAU_MESSAGES_PALLET_NAME; diff --git a/relays/client-polkadot/src/lib.rs b/relays/client-polkadot/src/lib.rs index ac67d55ab54..19326dd4c73 100644 --- a/relays/client-polkadot/src/lib.rs +++ b/relays/client-polkadot/src/lib.rs @@ -17,7 +17,7 @@ //! Types used to connect to the Polkadot chain. use bp_polkadot::AccountInfoStorageMapKeyProvider; -use relay_substrate_client::{Chain, ChainWithBalances, ChainWithGrandpa, UnderlyingChainProvider}; +use relay_substrate_client::{Chain, ChainWithBalances, UnderlyingChainProvider}; use sp_core::storage::StorageKey; use std::time::Duration; @@ -43,11 +43,6 @@ impl Chain for Polkadot { type Call = (); } -impl ChainWithGrandpa for Polkadot { - const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = - bp_polkadot::WITH_POLKADOT_GRANDPA_PALLET_NAME; -} - impl ChainWithBalances for Polkadot { fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey { AccountInfoStorageMapKeyProvider::final_key(account_id) diff --git a/relays/client-rialto/src/lib.rs b/relays/client-rialto/src/lib.rs index 8ad31de4d58..39cc2721ddb 100644 --- a/relays/client-rialto/src/lib.rs +++ b/relays/client-rialto/src/lib.rs @@ -19,9 +19,9 @@ use bp_messages::MessageNonce; use codec::{Compact, Decode, Encode}; use relay_substrate_client::{ - BalanceOf, Chain, ChainWithBalances, ChainWithGrandpa, ChainWithMessages, - ChainWithTransactions, Error as SubstrateError, IndexOf, RelayChain, SignParam, - UnderlyingChainProvider, UnsignedTransaction, + BalanceOf, Chain, ChainWithBalances, ChainWithMessages, ChainWithTransactions, + Error as SubstrateError, IndexOf, RelayChain, SignParam, UnderlyingChainProvider, + UnsignedTransaction, }; use sp_core::{storage::StorageKey, Pair}; use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount}; @@ -56,10 +56,6 @@ impl RelayChain for Rialto { bp_rialto::WITH_RIALTO_BRIDGE_PARAS_PALLET_NAME; } -impl ChainWithGrandpa for Rialto { - const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = bp_rialto::WITH_RIALTO_GRANDPA_PALLET_NAME; -} - impl ChainWithMessages for Rialto { const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str = bp_rialto::WITH_RIALTO_MESSAGES_PALLET_NAME; diff --git a/relays/client-rococo/src/lib.rs b/relays/client-rococo/src/lib.rs index a764759906a..a0730026e04 100644 --- a/relays/client-rococo/src/lib.rs +++ b/relays/client-rococo/src/lib.rs @@ -16,9 +16,7 @@ //! Types used to connect to the Rococo-Substrate chain. -use relay_substrate_client::{ - Chain, ChainWithBalances, ChainWithGrandpa, RelayChain, UnderlyingChainProvider, -}; +use relay_substrate_client::{Chain, ChainWithBalances, RelayChain, UnderlyingChainProvider}; use sp_core::storage::StorageKey; use std::time::Duration; @@ -47,10 +45,6 @@ impl Chain for Rococo { type Call = (); } -impl ChainWithGrandpa for Rococo { - const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = bp_rococo::WITH_ROCOCO_GRANDPA_PALLET_NAME; -} - impl ChainWithBalances for Rococo { fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey { bp_rococo::AccountInfoStorageMapKeyProvider::final_key(account_id) diff --git a/relays/client-substrate/src/chain.rs b/relays/client-substrate/src/chain.rs index 4ec5edfc41b..b9c5793842e 100644 --- a/relays/client-substrate/src/chain.rs +++ b/relays/client-substrate/src/chain.rs @@ -73,11 +73,6 @@ pub trait RelayChain: Chain { const PARACHAINS_FINALITY_PALLET_NAME: &'static str; } -/// Substrate-based parachain from minimal relay-client point of view. -pub trait Parachain: Chain + ParachainBase {} - -impl Parachain for T where T: UnderlyingChainProvider + Chain + ParachainBase {} - /// Substrate-based chain that is using direct GRANDPA finality from minimal relay-client point of /// view. /// @@ -92,6 +87,20 @@ pub trait ChainWithGrandpa: Chain { const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str; } +impl ChainWithGrandpa for T +where + T: Chain + UnderlyingChainProvider, + T::Chain: bp_header_chain::ChainWithGrandpa, +{ + const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = + ::WITH_CHAIN_GRANDPA_PALLET_NAME; +} + +/// Substrate-based parachain from minimal relay-client point of view. +pub trait Parachain: Chain + ParachainBase {} + +impl Parachain for T where T: UnderlyingChainProvider + Chain + ParachainBase {} + /// Substrate-based chain with messaging support from minimal relay-client point of view. pub trait ChainWithMessages: Chain { /// Name of the bridge messages pallet (used in `construct_runtime` macro call) that is deployed diff --git a/relays/client-westend/src/lib.rs b/relays/client-westend/src/lib.rs index 6467f431335..a8a8df36b8b 100644 --- a/relays/client-westend/src/lib.rs +++ b/relays/client-westend/src/lib.rs @@ -16,9 +16,7 @@ //! Types used to connect to the Westend chain. -use relay_substrate_client::{ - Chain, ChainWithBalances, ChainWithGrandpa, RelayChain, UnderlyingChainProvider, -}; +use relay_substrate_client::{Chain, ChainWithBalances, RelayChain, UnderlyingChainProvider}; use sp_core::storage::StorageKey; use std::time::Duration; @@ -53,11 +51,6 @@ impl RelayChain for Westend { bp_westend::WITH_WESTEND_BRIDGE_PARAS_PALLET_NAME; } -impl ChainWithGrandpa for Westend { - const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = - bp_westend::WITH_WESTEND_GRANDPA_PALLET_NAME; -} - impl ChainWithBalances for Westend { fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey { bp_westend::AccountInfoStorageMapKeyProvider::final_key(account_id) diff --git a/relays/client-wococo/src/lib.rs b/relays/client-wococo/src/lib.rs index a3e10729ba0..8f30572db63 100644 --- a/relays/client-wococo/src/lib.rs +++ b/relays/client-wococo/src/lib.rs @@ -16,9 +16,7 @@ //! Types used to connect to the Wococo-Substrate chain. -use relay_substrate_client::{ - Chain, ChainWithBalances, ChainWithGrandpa, RelayChain, UnderlyingChainProvider, -}; +use relay_substrate_client::{Chain, ChainWithBalances, RelayChain, UnderlyingChainProvider}; use sp_core::storage::StorageKey; use std::time::Duration; @@ -47,10 +45,6 @@ impl Chain for Wococo { type Call = (); } -impl ChainWithGrandpa for Wococo { - const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = bp_wococo::WITH_WOCOCO_GRANDPA_PALLET_NAME; -} - impl ChainWithBalances for Wococo { fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey { bp_wococo::AccountInfoStorageMapKeyProvider::final_key(account_id)