Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit d8f9a28

Browse files
svyatonikEgorPopelyaev
authored andcommitted
Update bridges subtree (#2903)
* Squashed 'bridges/' changes from 0417308a48..3c4ada921b 3c4ada921b Update dependecies (#2277) (#2281) 3e195c9e76 GRANDPA: optimize votes_ancestries when needed (#2262) (#2264) 7065bbabc6 Implement RuntimeDebug for GrandpaJustification (#2254) 8c9e59bcbc Define generate_grandpa_key_ownership_proof() (#2247) (#2248) 0b46956df7 Deduplicate Grandpa consensus log reading logic (#2245) (#2246) 96c9701710 Fix deps from Cumulus (#2244) git-subtree-dir: bridges git-subtree-split: 3c4ada921bbdbdba945c3aa85d76ce316f7baab3 * removed extra files * post-merge fixes * also post-merge fixes
1 parent f21967c commit d8f9a28

File tree

28 files changed

+392
-241
lines changed

28 files changed

+392
-241
lines changed

bridges/bin/runtime-common/src/integrity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ macro_rules! assert_chain_types(
3838
// if one of asserts fail, then either bridge isn't configured properly (or alternatively - non-standard
3939
// configuration is used), or something has broke existing configuration (meaning that all bridged chains
4040
// and relays will stop functioning)
41-
use frame_system::{Config as SystemConfig, pallet_prelude::*};
41+
use frame_system::{Config as SystemConfig, pallet_prelude::{BlockNumberFor, HeaderFor}};
4242
use static_assertions::assert_type_eq_all;
4343

4444
assert_type_eq_all!(<$r as SystemConfig>::Nonce, bp_runtime::NonceOf<$this>);

bridges/bin/runtime-common/src/mock.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ pub type ThisChainHasher = BlakeTwo256;
6363
pub type ThisChainRuntimeCall = RuntimeCall;
6464
/// Runtime call origin at `ThisChain`.
6565
pub type ThisChainCallOrigin = RuntimeOrigin;
66-
// Block of `ThisChain`.
66+
/// Header of `ThisChain`.
67+
pub type ThisChainHeader = sp_runtime::generic::Header<ThisChainBlockNumber, ThisChainHasher>;
68+
/// Block of `ThisChain`.
6769
pub type ThisChainBlock = frame_system::mocking::MockBlockU32<TestRuntime>;
6870

6971
/// Account identifier at the `BridgedChain`.
@@ -79,8 +81,6 @@ pub type BridgedChainHasher = BlakeTwo256;
7981
/// Header of the `BridgedChain`.
8082
pub type BridgedChainHeader =
8183
sp_runtime::generic::Header<BridgedChainBlockNumber, BridgedChainHasher>;
82-
/// Block of the `BridgedChain`.
83-
pub type BridgedChainBlock = frame_system::mocking::MockBlockU32<TestRuntime>;
8484

8585
/// Rewards payment procedure.
8686
pub type TestPaymentProcedure = PayRewardFromAccount<Balances, ThisChainAccountId>;
@@ -312,9 +312,10 @@ impl From<BridgedChainOrigin>
312312
pub struct ThisUnderlyingChain;
313313

314314
impl Chain for ThisUnderlyingChain {
315-
type Block = ThisChainBlock;
315+
type BlockNumber = ThisChainBlockNumber;
316316
type Hash = ThisChainHash;
317317
type Hasher = ThisChainHasher;
318+
type Header = ThisChainHeader;
318319
type AccountId = ThisChainAccountId;
319320
type Balance = ThisChainBalance;
320321
type Nonce = u32;
@@ -351,9 +352,10 @@ pub struct BridgedUnderlyingParachain;
351352
pub struct BridgedChainCall;
352353

353354
impl Chain for BridgedUnderlyingChain {
354-
type Block = BridgedChainBlock;
355+
type BlockNumber = BridgedChainBlockNumber;
355356
type Hash = BridgedChainHash;
356357
type Hasher = BridgedChainHasher;
358+
type Header = BridgedChainHeader;
357359
type AccountId = BridgedChainAccountId;
358360
type Balance = BridgedChainBalance;
359361
type Nonce = u32;
@@ -376,9 +378,10 @@ impl ChainWithGrandpa for BridgedUnderlyingChain {
376378
}
377379

378380
impl Chain for BridgedUnderlyingParachain {
379-
type Block = BridgedChainBlock;
381+
type BlockNumber = BridgedChainBlockNumber;
380382
type Hash = BridgedChainHash;
381383
type Hasher = BridgedChainHasher;
384+
type Header = BridgedChainHeader;
382385
type AccountId = BridgedChainAccountId;
383386
type Balance = BridgedChainBalance;
384387
type Nonce = u32;

bridges/bin/runtime-common/src/parachains_benchmarking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ where
4646
+ pallet_bridge_grandpa::Config<R::BridgesGrandpaPalletInstance>,
4747
PI: 'static,
4848
<R as pallet_bridge_grandpa::Config<R::BridgesGrandpaPalletInstance>>::BridgedChain:
49-
bp_runtime::Chain<Block = pallet_bridge_parachains::RelayBlock, Hash = RelayBlockHash>,
49+
bp_runtime::Chain<BlockNumber = RelayBlockNumber, Hash = RelayBlockHash>,
5050
{
5151
let parachain_head = ParaHead(vec![0u8; parachain_head_size as usize]);
5252

bridges/bin/runtime-common/src/refund_relayer_extension.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::messages_call_ext::{
2424
};
2525
use bp_messages::{LaneId, MessageNonce};
2626
use bp_relayers::{RewardsAccountOwner, RewardsAccountParams};
27-
use bp_runtime::{Chain, Parachain, ParachainIdOf, RangeInclusiveExt, StaticStrProvider};
27+
use bp_runtime::{Parachain, ParachainIdOf, RangeInclusiveExt, StaticStrProvider};
2828
use codec::{Decode, Encode};
2929
use frame_support::{
3030
dispatch::{CallableCallFor, DispatchInfo, Dispatchable, PostDispatchInfo},
@@ -47,10 +47,7 @@ use pallet_transaction_payment::{Config as TransactionPaymentConfig, OnChargeTra
4747
use pallet_utility::{Call as UtilityCall, Config as UtilityConfig, Pallet as UtilityPallet};
4848
use scale_info::TypeInfo;
4949
use sp_runtime::{
50-
traits::{
51-
Block as BlockT, DispatchInfoOf, Get, Header as HeaderT, PostDispatchInfoOf,
52-
SignedExtension, Zero,
53-
},
50+
traits::{DispatchInfoOf, Get, PostDispatchInfoOf, SignedExtension, Zero},
5451
transaction_validity::{
5552
TransactionPriority, TransactionValidity, TransactionValidityError, ValidTransactionBuilder,
5653
},
@@ -281,7 +278,6 @@ where
281278
+ GrandpaCallSubType<Runtime, Runtime::BridgesGrandpaPalletInstance>
282279
+ ParachainsCallSubType<Runtime, Para::Instance>
283280
+ MessagesCallSubType<Runtime, Msgs::Instance>,
284-
<<<Runtime as BoundedBridgeGrandpaConfig<Runtime::BridgesGrandpaPalletInstance>>::BridgedRelayChain as Chain>::Block as BlockT>::Header: HeaderT<Number = RelayBlockNumber>
285281
{
286282
fn expand_call<'a>(&self, call: &'a CallOf<Runtime>) -> Vec<&'a CallOf<Runtime>> {
287283
match call.is_sub_type() {
@@ -529,7 +525,6 @@ where
529525
+ GrandpaCallSubType<Runtime, Runtime::BridgesGrandpaPalletInstance>
530526
+ ParachainsCallSubType<Runtime, Para::Instance>
531527
+ MessagesCallSubType<Runtime, Msgs::Instance>,
532-
<<<Runtime as BoundedBridgeGrandpaConfig<Runtime::BridgesGrandpaPalletInstance>>::BridgedRelayChain as Chain>::Block as BlockT>::Header: HeaderT<Number = RelayBlockNumber>
533528
{
534529
const IDENTIFIER: &'static str = Id::STR;
535530
type AccountId = Runtime::AccountId;

bridges/modules/grandpa/src/call_ext.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use bp_header_chain::{justification::GrandpaJustification, ChainWithGrandpa};
1919
use bp_runtime::BlockNumberOf;
2020
use codec::Encode;
2121
use frame_support::{dispatch::CallableCallFor, traits::IsSubType, weights::Weight, RuntimeDebug};
22-
use frame_system::pallet_prelude::HeaderFor;
2322
use sp_runtime::{
2423
traits::{Header, Zero},
2524
transaction_validity::{InvalidTransaction, TransactionValidity, ValidTransaction},
@@ -179,9 +178,10 @@ pub(crate) fn submit_finality_proof_info_from_args<T: Config<I>, I: 'static>(
179178

180179
/// Returns maximal expected size of `submit_finality_proof` call arguments.
181180
fn max_expected_call_size<T: Config<I>, I: 'static>(required_precommits: u32) -> u32 {
182-
let max_expected_justification_size = GrandpaJustification::<HeaderFor<T>>::max_reasonable_size::<
183-
T::BridgedChain,
184-
>(required_precommits);
181+
let max_expected_justification_size =
182+
GrandpaJustification::<BridgedHeader<T, I>>::max_reasonable_size::<T::BridgedChain>(
183+
required_precommits,
184+
);
185185

186186
// call arguments are header and justification
187187
T::BridgedChain::MAX_HEADER_SIZE.saturating_add(max_expected_justification_size)

bridges/modules/grandpa/src/lib.rs

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@
3939
pub use storage_types::StoredAuthoritySet;
4040

4141
use bp_header_chain::{
42-
justification::GrandpaJustification, ChainWithGrandpa, HeaderChain, InitializationData,
43-
StoredHeaderData, StoredHeaderDataBuilder,
42+
justification::GrandpaJustification, ChainWithGrandpa, GrandpaConsensusLogReader, HeaderChain,
43+
InitializationData, StoredHeaderData, StoredHeaderDataBuilder,
4444
};
4545
use bp_runtime::{BlockNumberOf, HashOf, HasherOf, HeaderId, HeaderOf, OwnedBridgeModule};
4646
use finality_grandpa::voter_set::VoterSet;
4747
use frame_support::{dispatch::PostDispatchInfo, ensure, DefaultNoBound};
48-
use sp_consensus_grandpa::{ConsensusLog, GRANDPA_ENGINE_ID};
4948
use sp_runtime::{
5049
traits::{Header as HeaderT, Zero},
5150
SaturatedConversion,
@@ -443,11 +442,17 @@ pub mod pallet {
443442

444443
// We don't support forced changes - at that point governance intervention is required.
445444
ensure!(
446-
super::find_forced_change(header).is_none(),
445+
GrandpaConsensusLogReader::<BridgedBlockNumber<T, I>>::find_forced_change(
446+
header.digest()
447+
)
448+
.is_none(),
447449
<Error<T, I>>::UnsupportedScheduledChange
448450
);
449451

450-
if let Some(change) = super::find_scheduled_change(header) {
452+
if let Some(change) =
453+
GrandpaConsensusLogReader::<BridgedBlockNumber<T, I>>::find_scheduled_change(
454+
header.digest(),
455+
) {
451456
// GRANDPA only includes a `delay` for forced changes, so this isn't valid.
452457
ensure!(change.delay == Zero::zero(), <Error<T, I>>::UnsupportedScheduledChange);
453458

@@ -616,42 +621,6 @@ impl<T: Config<I>, I: 'static> HeaderChain<BridgedChain<T, I>> for GrandpaChainH
616621
}
617622
}
618623

619-
pub(crate) fn find_scheduled_change<H: HeaderT>(
620-
header: &H,
621-
) -> Option<sp_consensus_grandpa::ScheduledChange<H::Number>> {
622-
use sp_runtime::generic::OpaqueDigestItemId;
623-
624-
let id = OpaqueDigestItemId::Consensus(&GRANDPA_ENGINE_ID);
625-
626-
let filter_log = |log: ConsensusLog<H::Number>| match log {
627-
ConsensusLog::ScheduledChange(change) => Some(change),
628-
_ => None,
629-
};
630-
631-
// find the first consensus digest with the right ID which converts to
632-
// the right kind of consensus log.
633-
header.digest().convert_first(|l| l.try_to(id).and_then(filter_log))
634-
}
635-
636-
/// Checks the given header for a consensus digest signaling a **forced** scheduled change and
637-
/// extracts it.
638-
pub(crate) fn find_forced_change<H: HeaderT>(
639-
header: &H,
640-
) -> Option<(H::Number, sp_consensus_grandpa::ScheduledChange<H::Number>)> {
641-
use sp_runtime::generic::OpaqueDigestItemId;
642-
643-
let id = OpaqueDigestItemId::Consensus(&GRANDPA_ENGINE_ID);
644-
645-
let filter_log = |log: ConsensusLog<H::Number>| match log {
646-
ConsensusLog::ForcedChange(delay, change) => Some((delay, change)),
647-
_ => None,
648-
};
649-
650-
// find the first consensus digest with the right ID which converts to
651-
// the right kind of consensus log.
652-
header.digest().convert_first(|l| l.try_to(id).and_then(filter_log))
653-
}
654-
655624
/// (Re)initialize bridge with given header for using it in `pallet-bridge-messages` benchmarks.
656625
#[cfg(feature = "runtime-benchmarks")]
657626
pub fn initialize_for_benchmarks<T: Config<I>, I: 'static>(header: BridgedHeader<T, I>) {
@@ -685,6 +654,7 @@ mod tests {
685654
storage::generator::StorageValue,
686655
};
687656
use frame_system::{EventRecord, Phase};
657+
use sp_consensus_grandpa::{ConsensusLog, GRANDPA_ENGINE_ID};
688658
use sp_core::Get;
689659
use sp_runtime::{Digest, DigestItem, DispatchError};
690660

bridges/modules/grandpa/src/mock.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ use sp_runtime::{
3232
};
3333

3434
pub type AccountId = u64;
35-
pub type TestHeader = crate::BridgedHeader<TestRuntime, ()>;
36-
pub type TestNumber = crate::BridgedBlockNumber<TestRuntime, ()>;
35+
pub type TestHeader = sp_runtime::testing::Header;
36+
pub type TestNumber = u64;
3737

3838
type Block = frame_system::mocking::MockBlock<TestRuntime>;
3939

@@ -100,9 +100,10 @@ impl grandpa::Config for TestRuntime {
100100
pub struct TestBridgedChain;
101101

102102
impl Chain for TestBridgedChain {
103-
type Block = Block;
103+
type BlockNumber = TestNumber;
104104
type Hash = <TestRuntime as frame_system::Config>::Hash;
105105
type Hasher = <TestRuntime as frame_system::Config>::Hashing;
106+
type Header = TestHeader;
106107

107108
type AccountId = AccountId;
108109
type Balance = u64;

bridges/modules/parachains/src/benchmarking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ benchmarks_instance_pallet! {
4747
where
4848
<T as pallet_bridge_grandpa::Config<T::BridgesGrandpaPalletInstance>>::BridgedChain:
4949
bp_runtime::Chain<
50-
Block = crate::RelayBlock,
50+
BlockNumber = RelayBlockNumber,
5151
Hash = RelayBlockHash,
5252
Hasher = RelayBlockHasher,
5353
>,

bridges/modules/parachains/src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ pub type RelayBlockHash = bp_polkadot_core::Hash;
6363
pub type RelayBlockNumber = bp_polkadot_core::BlockNumber;
6464
/// Hasher of the bridged relay chain.
6565
pub type RelayBlockHasher = bp_polkadot_core::Hasher;
66-
/// Block type of the bridged relay chain.
67-
pub type RelayBlock = bp_polkadot_core::Block;
6866

6967
/// Artifacts of the parachains head update.
7068
struct UpdateParachainHeadArtifacts {
@@ -139,15 +137,18 @@ pub mod pallet {
139137
pub trait BoundedBridgeGrandpaConfig<I: 'static>:
140138
pallet_bridge_grandpa::Config<I, BridgedChain = Self::BridgedRelayChain>
141139
{
142-
type BridgedRelayChain: Chain<Hash = RelayBlockHash, Hasher = RelayBlockHasher>;
140+
type BridgedRelayChain: Chain<
141+
BlockNumber = RelayBlockNumber,
142+
Hash = RelayBlockHash,
143+
Hasher = RelayBlockHasher,
144+
>;
143145
}
144146

145147
impl<T, I: 'static> BoundedBridgeGrandpaConfig<I> for T
146148
where
147149
T: pallet_bridge_grandpa::Config<I>,
148-
T::BridgedChain: Chain<Hash = RelayBlockHash, Hasher = RelayBlockHasher>,
149-
<<T::BridgedChain as Chain>::Block as sp_runtime::traits::Block>::Header:
150-
sp_runtime::traits::Header<Number = RelayBlockNumber>,
150+
T::BridgedChain:
151+
Chain<BlockNumber = RelayBlockNumber, Hash = RelayBlockHash, Hasher = RelayBlockHasher>,
151152
{
152153
type BridgedRelayChain = T::BridgedChain;
153154
}
@@ -322,7 +323,7 @@ pub mod pallet {
322323
>::get(relay_block_hash)
323324
.ok_or(Error::<T, I>::UnknownRelayChainBlock)?;
324325
ensure!(
325-
relay_block.number == relay_block_number.into(),
326+
relay_block.number == relay_block_number,
326327
Error::<T, I>::InvalidRelayChainBlockNumber,
327328
);
328329

bridges/modules/parachains/src/mock.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use bp_runtime::{Chain, Parachain};
2020
use frame_support::{construct_runtime, parameter_types, traits::ConstU32, weights::Weight};
2121
use sp_runtime::{
2222
testing::H256,
23-
traits::{BlakeTwo256, Header, IdentityLookup},
23+
traits::{BlakeTwo256, Header as HeaderT, IdentityLookup},
2424
MultiSignature, Perbill,
2525
};
2626

@@ -48,9 +48,10 @@ pub type BigParachainHeader = sp_runtime::generic::Header<u128, BlakeTwo256>;
4848
pub struct Parachain1;
4949

5050
impl Chain for Parachain1 {
51-
type Block = Block;
51+
type BlockNumber = u64;
5252
type Hash = H256;
5353
type Hasher = RegularParachainHasher;
54+
type Header = RegularParachainHeader;
5455
type AccountId = u64;
5556
type Balance = u64;
5657
type Nonce = u64;
@@ -71,9 +72,10 @@ impl Parachain for Parachain1 {
7172
pub struct Parachain2;
7273

7374
impl Chain for Parachain2 {
74-
type Block = Block;
75+
type BlockNumber = u64;
7576
type Hash = H256;
7677
type Hasher = RegularParachainHasher;
78+
type Header = RegularParachainHeader;
7779
type AccountId = u64;
7880
type Balance = u64;
7981
type Nonce = u64;
@@ -94,9 +96,10 @@ impl Parachain for Parachain2 {
9496
pub struct Parachain3;
9597

9698
impl Chain for Parachain3 {
97-
type Block = Block;
99+
type BlockNumber = u64;
98100
type Hash = H256;
99101
type Hasher = RegularParachainHasher;
102+
type Header = RegularParachainHeader;
100103
type AccountId = u64;
101104
type Balance = u64;
102105
type Nonce = u64;
@@ -117,12 +120,11 @@ impl Parachain for Parachain3 {
117120
// this parachain is using u128 as block number and stored head data size exceeds limit
118121
pub struct BigParachain;
119122

120-
type BigBlock = frame_system::mocking::MockBlockU128<TestRuntime>;
121-
122123
impl Chain for BigParachain {
123-
type Block = BigBlock;
124+
type BlockNumber = u128;
124125
type Hash = H256;
125126
type Hasher = RegularParachainHasher;
127+
type Header = BigParachainHeader;
126128
type AccountId = u64;
127129
type Balance = u64;
128130
type Nonce = u64;
@@ -161,11 +163,11 @@ impl frame_system::Config for TestRuntime {
161163
type RuntimeOrigin = RuntimeOrigin;
162164
type Nonce = u64;
163165
type RuntimeCall = RuntimeCall;
166+
type Block = Block;
164167
type Hash = H256;
165168
type Hashing = RegularParachainHasher;
166169
type AccountId = AccountId;
167170
type Lookup = IdentityLookup<Self::AccountId>;
168-
type Block = Block;
169171
type RuntimeEvent = RuntimeEvent;
170172
type BlockHashCount = BlockHashCount;
171173
type Version = ();
@@ -256,9 +258,10 @@ impl pallet_bridge_parachains::benchmarking::Config<()> for TestRuntime {
256258
pub struct TestBridgedChain;
257259

258260
impl Chain for TestBridgedChain {
259-
type Block = crate::RelayBlock;
261+
type BlockNumber = crate::RelayBlockNumber;
260262
type Hash = crate::RelayBlockHash;
261263
type Hasher = crate::RelayBlockHasher;
264+
type Header = RelayBlockHeader;
262265

263266
type AccountId = AccountId;
264267
type Balance = u32;
@@ -286,9 +289,10 @@ impl ChainWithGrandpa for TestBridgedChain {
286289
pub struct OtherBridgedChain;
287290

288291
impl Chain for OtherBridgedChain {
289-
type Block = Block;
292+
type BlockNumber = u64;
290293
type Hash = crate::RelayBlockHash;
291294
type Hasher = crate::RelayBlockHasher;
295+
type Header = sp_runtime::generic::Header<u64, crate::RelayBlockHasher>;
292296

293297
type AccountId = AccountId;
294298
type Balance = u32;

0 commit comments

Comments
 (0)