Deduplicate pallet call structs used for indirect runtime calls (#1744)

* Small changes

* Define generic bridge pallets call structs

* polkadot-core SignedExtension simplifications

- we don't seem to need to pass the Call as a generic param
- we can use codec(skip) instead of implementing Encode and Decode

* Split BridgeHubRococo and BridgeHubWococo calls

* code review fixes
This commit is contained in:
Serban Iorga
2023-01-09 15:29:53 +02:00
committed by Bastian Köcher
parent a21617082e
commit 63a538a9bb
24 changed files with 342 additions and 238 deletions
@@ -692,6 +692,13 @@ pub mod target {
}
}
/// The `BridgeMessagesCall` used by a chain.
pub type BridgeMessagesCallOf<C> = bp_messages::BridgeMessagesCall<
bp_runtime::AccountIdOf<C>,
target::FromBridgedChainMessagesProof<bp_runtime::HashOf<C>>,
source::FromBridgedChainMessagesDeliveryProof<bp_runtime::HashOf<C>>,
>;
#[cfg(test)]
mod tests {
use super::*;
+29
View File
@@ -612,6 +612,7 @@ mod tests {
run_test, test_header, RuntimeOrigin, TestHeader, TestNumber, TestRuntime,
MAX_BRIDGED_AUTHORITIES,
};
use bp_header_chain::BridgeGrandpaCall;
use bp_runtime::BasicOperatingMode;
use bp_test_utils::{
authority_list, generate_owned_bridge_module_tests, make_default_justification,
@@ -1160,5 +1161,33 @@ mod tests {
);
}
#[test]
fn test_bridge_grandpa_call_is_correctly_defined() {
let header = test_header(0);
let init_data = InitializationData {
header: Box::new(header.clone()),
authority_list: authority_list(),
set_id: 1,
operating_mode: BasicOperatingMode::Normal,
};
let justification = make_default_justification(&header);
let direct_initialize_call =
Call::<TestRuntime>::initialize { init_data: init_data.clone() };
let indirect_initialize_call = BridgeGrandpaCall::<TestHeader>::initialize(init_data);
assert_eq!(direct_initialize_call.encode(), indirect_initialize_call.encode());
let direct_submit_finality_proof_call = Call::<TestRuntime>::submit_finality_proof {
finality_target: Box::new(header.clone()),
justification: justification.clone(),
};
let indirect_submit_finality_proof_call =
BridgeGrandpaCall::<TestHeader>::submit_finality_proof(Box::new(header), justification);
assert_eq!(
direct_submit_finality_proof_call.encode(),
indirect_submit_finality_proof_call.encode()
);
}
generate_owned_bridge_module_tests!(BasicOperatingMode::Normal, BasicOperatingMode::Halted);
}
+65 -2
View File
@@ -885,13 +885,13 @@ fn verify_and_decode_messages_proof<Chain: SourceHeaderChain, DispatchPayload: D
mod tests {
use super::*;
use crate::mock::{
message, message_payload, run_test, unrewarded_relayer, DbWeight,
message, message_payload, run_test, unrewarded_relayer, AccountId, DbWeight,
RuntimeEvent as TestEvent, RuntimeOrigin, TestDeliveryConfirmationPayments,
TestDeliveryPayments, TestMessagesDeliveryProof, TestMessagesProof, TestRuntime,
MAX_OUTBOUND_PAYLOAD_SIZE, PAYLOAD_REJECTED_BY_TARGET_CHAIN, REGULAR_PAYLOAD, TEST_LANE_ID,
TEST_LANE_ID_2, TEST_LANE_ID_3, TEST_RELAYER_A, TEST_RELAYER_B,
};
use bp_messages::{UnrewardedRelayer, UnrewardedRelayersState};
use bp_messages::{BridgeMessagesCall, UnrewardedRelayer, UnrewardedRelayersState};
use bp_test_utils::generate_owned_bridge_module_tests;
use frame_support::{
assert_noop, assert_ok,
@@ -1891,6 +1891,69 @@ mod tests {
});
}
#[test]
fn test_bridge_messages_call_is_correctly_defined() {
let account_id = 1;
let message_proof: TestMessagesProof = Ok(vec![message(1, REGULAR_PAYLOAD)]).into();
let message_delivery_proof = TestMessagesDeliveryProof(Ok((
TEST_LANE_ID,
InboundLaneData {
last_confirmed_nonce: 1,
relayers: vec![UnrewardedRelayer {
relayer: 0,
messages: DeliveredMessages::new(1),
}]
.into_iter()
.collect(),
},
)));
let unrewarded_relayer_state = UnrewardedRelayersState {
unrewarded_relayer_entries: 1,
total_messages: 1,
last_delivered_nonce: 1,
..Default::default()
};
let direct_receive_messages_proof_call = Call::<TestRuntime>::receive_messages_proof {
relayer_id_at_bridged_chain: account_id,
proof: message_proof.clone(),
messages_count: 1,
dispatch_weight: REGULAR_PAYLOAD.declared_weight,
};
let indirect_receive_messages_proof_call = BridgeMessagesCall::<
AccountId,
TestMessagesProof,
TestMessagesDeliveryProof,
>::receive_messages_proof(
account_id,
message_proof,
1,
REGULAR_PAYLOAD.declared_weight,
);
assert_eq!(
direct_receive_messages_proof_call.encode(),
indirect_receive_messages_proof_call.encode()
);
let direct_receive_messages_delivery_proof_call =
Call::<TestRuntime>::receive_messages_delivery_proof {
proof: message_delivery_proof.clone(),
relayers_state: unrewarded_relayer_state.clone(),
};
let indirect_receive_messages_delivery_proof_call = BridgeMessagesCall::<
AccountId,
TestMessagesProof,
TestMessagesDeliveryProof,
>::receive_messages_delivery_proof(
message_delivery_proof,
unrewarded_relayer_state,
);
assert_eq!(
direct_receive_messages_delivery_proof_call.encode(),
indirect_receive_messages_delivery_proof_call.encode()
);
}
generate_owned_bridge_module_tests!(
MessagesOperatingMode::Basic(BasicOperatingMode::Normal),
MessagesOperatingMode::Basic(BasicOperatingMode::Halted)
+22 -1
View File
@@ -661,7 +661,9 @@ mod tests {
};
use codec::Encode;
use bp_parachains::{BestParaHeadHash, ImportedParaHeadsKeyProvider, ParasInfoKeyProvider};
use bp_parachains::{
BestParaHeadHash, BridgeParachainCall, ImportedParaHeadsKeyProvider, ParasInfoKeyProvider,
};
use bp_runtime::{
record_all_trie_keys, BasicOperatingMode, OwnedBridgeModuleError,
StorageDoubleMapKeyProvider, StorageMapKeyProvider,
@@ -1471,5 +1473,24 @@ mod tests {
});
}
#[test]
fn test_bridge_parachain_call_is_correctly_defined() {
let (state_root, proof, _) = prepare_parachain_heads_proof(vec![(1, head_data(1, 0))]);
let parachains = vec![(ParaId(2), Default::default())];
let relay_header_id = (0, test_relay_header(0, state_root).hash());
let direct_submit_parachain_heads_call = Call::<TestRuntime>::submit_parachain_heads {
at_relay_block: relay_header_id,
parachains: parachains.clone(),
parachain_heads_proof: proof.clone(),
};
let indirect_submit_parachain_heads_call =
BridgeParachainCall::submit_parachain_heads(relay_header_id, parachains, proof);
assert_eq!(
direct_submit_parachain_heads_call.encode(),
indirect_submit_parachain_heads_call.encode()
);
}
generate_owned_bridge_module_tests!(BasicOperatingMode::Normal, BasicOperatingMode::Halted);
}
@@ -7,8 +7,6 @@ edition = "2021"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[dependencies]
smallvec = "1.10.0"
# Bridge Dependencies
bp-polkadot-core = { path = "../../primitives/polkadot-core", default-features = false }
@@ -23,15 +21,15 @@ sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", d
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
# Polkadot Dependencies
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
polkadot-runtime-constants = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false }
polkadot-runtime-constants = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false }
[features]
default = ["std"]
std = [
"bp-polkadot-core/std",
"bp-messages/std",
"bp-runtime/std",
"bp-messages/std",
"frame-system/std",
"frame-support/std",
"sp-api/std",
@@ -7,8 +7,6 @@ edition = "2021"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[dependencies]
smallvec = "1.10.0"
# Bridge Dependencies
bp-bridge-hub-cumulus = { path = "../chain-bridge-hub-cumulus", default-features = false }
@@ -16,13 +16,9 @@
//! Module with configuration which reflects BridgeHubWococo runtime setup
//! (AccountId, Headers, Hashes...)
//!
//! but actually this is just reexported BridgeHubRococo stuff, because they are supposed to be
//! identical, at least uses the same parachain runtime
#![cfg_attr(not(feature = "std"), no_std)]
// Re-export only what is really needed
pub use bp_bridge_hub_cumulus::*;
use bp_messages::*;
use bp_runtime::{
+16 -1
View File
@@ -19,7 +19,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
use bp_runtime::{BasicOperatingMode, Chain, HashOf, HasherOf, StorageProofChecker};
use bp_runtime::{BasicOperatingMode, Chain, HashOf, HasherOf, HeaderOf, StorageProofChecker};
use codec::{Codec, Decode, Encode, EncodeLike, MaxEncodedLen};
use core::{clone::Clone, cmp::Eq, default::Default, fmt::Debug};
use frame_support::PalletError;
@@ -169,3 +169,18 @@ impl<Number: Codec> ConsensusLogReader for GrandpaConsensusLogReader<Number> {
GrandpaConsensusLogReader::<Number>::find_authorities_change(digest).is_some()
}
}
/// A minimized version of `pallet-bridge-grandpa::Call` that can be used without a runtime.
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[allow(non_camel_case_types)]
pub enum BridgeGrandpaCall<Header: HeaderT> {
/// `pallet-bridge-grandpa::Call::submit_finality_proof`
#[codec(index = 0)]
submit_finality_proof(Box<Header>, justification::GrandpaJustification<Header>),
/// `pallet-bridge-grandpa::Call::initialize`
#[codec(index = 1)]
initialize(InitializationData<Header>),
}
/// The `BridgeGrandpaCall` used by a chain.
pub type BridgeGrandpaCallOf<C> = BridgeGrandpaCall<HeaderOf<C>>;
+12
View File
@@ -391,6 +391,18 @@ where
relayers_rewards
}
/// A minimized version of `pallet-bridge-messages::Call` that can be used without a runtime.
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[allow(non_camel_case_types)]
pub enum BridgeMessagesCall<AccountId, MessagesProof, MessagesDeliveryProof> {
/// `pallet-bridge-messages::Call::receive_messages_proof`
#[codec(index = 2)]
receive_messages_proof(AccountId, MessagesProof, u32, Weight),
/// `pallet-bridge-messages::Call::receive_messages_delivery_proof`
#[codec(index = 3)]
receive_messages_delivery_proof(MessagesDeliveryProof, UnrewardedRelayersState),
}
#[cfg(test)]
mod tests {
use super::*;
+15 -2
View File
@@ -21,8 +21,8 @@
pub use bp_header_chain::StoredHeaderData;
use bp_polkadot_core::{
parachains::{ParaHash, ParaHead, ParaId},
BlockNumber as RelayBlockNumber,
parachains::{ParaHash, ParaHead, ParaHeadsProof, ParaId},
BlockNumber as RelayBlockNumber, Hash as RelayBlockHash,
};
use bp_runtime::{
BlockNumberOf, Chain, HashOf, HeaderOf, Parachain, StorageDoubleMapKeyProvider,
@@ -150,3 +150,16 @@ impl ParaStoredHeaderDataBuilder for C {
None
}
}
/// A minimized version of `pallet-bridge-parachains::Call` that can be used without a runtime.
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[allow(non_camel_case_types)]
pub enum BridgeParachainCall {
/// `pallet-bridge-parachains::Call::submit_parachain_heads`
#[codec(index = 0)]
submit_parachain_heads(
(RelayBlockNumber, RelayBlockHash),
Vec<(ParaId, ParaHash)>,
ParaHeadsProof,
),
}
+10 -31
View File
@@ -20,7 +20,7 @@ use bp_messages::MessageNonce;
use bp_runtime::{Chain, EncodedOrDecodedCall, StorageMapKeyProvider};
use codec::Compact;
use frame_support::{
dispatch::{DispatchClass, Dispatchable},
dispatch::DispatchClass,
parameter_types,
weights::{
constants::{BlockExecutionWeight, WEIGHT_PER_SECOND},
@@ -29,7 +29,7 @@ use frame_support::{
Blake2_128Concat, RuntimeDebug,
};
use frame_system::limits;
use scale_info::{StaticTypeInfo, TypeInfo};
use scale_info::TypeInfo;
use sp_core::{storage::StorageKey, Hasher as HasherT};
use sp_runtime::{
generic,
@@ -194,7 +194,7 @@ pub type UncheckedExtrinsic<Call> = generic::UncheckedExtrinsic<
AccountAddress,
EncodedOrDecodedCall<Call>,
Signature,
SignedExtensions<Call>,
SignedExtensions,
>;
/// Account address, used by the Polkadot-like chain.
@@ -210,34 +210,18 @@ pub type AdditionalSigned = ((), u32, u32, Hash, Hash, (), (), ());
/// A simplified version of signed extensions meant for producing signed transactions
/// and signed payload in the client code.
#[derive(PartialEq, Eq, Clone, RuntimeDebug, TypeInfo)]
pub struct SignedExtensions<Call> {
#[derive(codec::Encode, codec::Decode, PartialEq, Eq, Clone, RuntimeDebug, TypeInfo)]
pub struct SignedExtensions {
encode_payload: SignedExtra,
// It may be set to `None` if extensions are decoded. We are never reconstructing transactions
// (and it makes no sense to do that) => decoded version of `SignedExtensions` is only used to
// read fields of `encode_payload`. And when resigning transaction, we're reconstructing
// `SignedExtensions` from the scratch.
#[codec(skip)]
additional_signed: Option<AdditionalSigned>,
_data: sp_std::marker::PhantomData<Call>,
}
impl<Call> codec::Encode for SignedExtensions<Call> {
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
self.encode_payload.using_encoded(f)
}
}
impl<Call> codec::Decode for SignedExtensions<Call> {
fn decode<I: codec::Input>(input: &mut I) -> Result<Self, codec::Error> {
SignedExtra::decode(input).map(|encode_payload| SignedExtensions {
encode_payload,
additional_signed: None,
_data: Default::default(),
})
}
}
impl<Call> SignedExtensions<Call> {
impl SignedExtensions {
pub fn new(
spec_version: u32,
transaction_version: u32,
@@ -267,12 +251,11 @@ impl<Call> SignedExtensions<Call> {
(),
(),
)),
_data: Default::default(),
}
}
}
impl<Call> SignedExtensions<Call> {
impl SignedExtensions {
/// Return signer nonce, used to craft transaction.
pub fn nonce(&self) -> Nonce {
self.encode_payload.5.into()
@@ -284,15 +267,11 @@ impl<Call> SignedExtensions<Call> {
}
}
impl<Call> sp_runtime::traits::SignedExtension for SignedExtensions<Call>
where
Call: codec::Codec + sp_std::fmt::Debug + Sync + Send + Clone + Eq + PartialEq + StaticTypeInfo,
Call: Dispatchable,
{
impl sp_runtime::traits::SignedExtension for SignedExtensions {
const IDENTIFIER: &'static str = "Not needed.";
type AccountId = AccountId;
type Call = Call;
type Call = ();
type AdditionalSigned = AdditionalSigned;
type Pre = ();
+30
View File
@@ -0,0 +1,30 @@
// Copyright 2019-2023 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/>.
//! Basic runtime calls.
use codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_std::vec::Vec;
/// A minimized version of `frame-system::Call` that can be used without a runtime.
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[allow(non_camel_case_types)]
pub enum SystemCall {
/// `frame-system::Call::remark`
#[codec(index = 1)]
remark(Vec<u8>),
}
+1
View File
@@ -47,6 +47,7 @@ pub use storage_types::BoundedStorageValue;
#[cfg(feature = "std")]
pub use storage_proof::craft_valid_storage_proof;
pub mod calls;
pub mod messages;
mod chain;
+1
View File
@@ -26,6 +26,7 @@ bp-bridge-hub-rococo = { path = "../../primitives/chain-bridge-hub-rococo" }
bp-bridge-hub-wococo = { path = "../../primitives/chain-bridge-hub-wococo" }
bp-header-chain = { path = "../../primitives/header-chain" }
bp-messages = { path = "../../primitives/messages" }
bp-parachains = { path = "../../primitives/parachains" }
bp-millau = { path = "../../primitives/chain-millau" }
bp-polkadot-core = { path = "../../primitives/polkadot-core" }
bp-rialto = { path = "../../primitives/chain-rialto" }
@@ -33,7 +33,7 @@ substrate_relay_helper::generate_mocked_submit_finality_proof_call_builder!(
RococoFinalityToBridgeHubWococo,
RococoFinalityToBridgeHubWococoCallBuilder,
relay_bridge_hub_wococo_client::runtime::Call::BridgeRococoGrandpa,
relay_bridge_hub_wococo_client::runtime::BridgeGrandpaRococoCall::submit_finality_proof
relay_bridge_hub_wococo_client::runtime::BridgeRococoGrandpaCall::submit_finality_proof
);
#[async_trait]
@@ -51,7 +51,7 @@ impl SubmitParachainHeadsCallBuilder<BridgeHubWococoToBridgeHubRococo>
parachain_heads_proof: ParaHeadsProof,
) -> CallOf<relay_bridge_hub_rococo_client::BridgeHubRococo> {
relay_bridge_hub_rococo_client::runtime::Call::BridgeWococoParachain(
relay_bridge_hub_rococo_client::runtime::BridgeParachainCall::submit_parachain_heads(
bp_parachains::BridgeParachainCall::submit_parachain_heads(
(at_relay_block.0, at_relay_block.1),
parachains,
parachain_heads_proof,
@@ -176,7 +176,7 @@ impl BridgeInitializer for RococoToBridgeHubWococoCliBridge {
init_data: <Self::Engine as Engine<Self::Source>>::InitializationData,
) -> <Self::Target as Chain>::Call {
relay_bridge_hub_wococo_client::runtime::Call::BridgeRococoGrandpa(
relay_bridge_hub_wococo_client::runtime::BridgeGrandpaRococoCall::initialize(init_data),
relay_bridge_hub_wococo_client::runtime::BridgeRococoGrandpaCall::initialize(init_data),
)
}
}
@@ -16,14 +16,13 @@ bp-bridge-hub-rococo = { path = "../../primitives/chain-bridge-hub-rococo" }
bp-bridge-hub-wococo = { path = "../../primitives/chain-bridge-hub-wococo" }
bp-header-chain = { path = "../../primitives/header-chain" }
bp-messages = { path = "../../primitives/messages" }
bp-polkadot-core = { path = "../../primitives/polkadot-core" }
bp-parachains = { path = "../../primitives/parachains" }
bp-rococo = { path = "../../primitives/chain-rococo" }
bp-runtime = { path = "../../primitives/runtime" }
bp-wococo = { path = "../../primitives/chain-wococo" }
bridge-runtime-common = { path = "../../bin/runtime-common" }
# Substrate Dependencies
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
[dev-dependencies]
sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master" }
@@ -132,8 +132,10 @@ mod tests {
#[test]
fn parse_transaction_works() {
let unsigned = UnsignedTransaction {
call: runtime::Call::System(runtime::SystemCall::remark(b"Hello world!".to_vec()))
.into(),
call: runtime::Call::System(bp_runtime::calls::SystemCall::remark(
b"Hello world!".to_vec(),
))
.into(),
nonce: 777,
tip: 888,
era: TransactionEra::immortal(),
@@ -18,201 +18,48 @@
//! Types that are specific to the BridgeHubRococo runtime.
use bp_polkadot_core::PolkadotLike;
use codec::{Decode, Encode};
use scale_info::TypeInfo;
use bp_messages::UnrewardedRelayersState;
use bp_polkadot_core::parachains::{ParaHash, ParaHeadsProof, ParaId};
use bp_runtime::Chain;
pub use bp_header_chain::BridgeGrandpaCallOf;
pub use bp_parachains::BridgeParachainCall;
pub use bp_runtime::calls::SystemCall;
pub use bridge_runtime_common::messages::BridgeMessagesCallOf;
// TODO:check-parameter - check SignedExtension
/// Unchecked BridgeHubRococo extrinsic.
pub type UncheckedExtrinsic = bp_bridge_hub_rococo::UncheckedExtrinsic<Call>;
/// Rococo Runtime `Call` enum.
// The indirect pallet call used to sync `Wococo` GRANDPA finality to `BHRococo`.
pub type BridgeWococoGrandpaCall = BridgeGrandpaCallOf<bp_wococo::Wococo>;
// The indirect pallet call used to sync `BridgeHubWococo` messages to `BHRococo`.
pub type BridgeWococoMessagesCall = BridgeMessagesCallOf<bp_bridge_hub_wococo::BridgeHubWococo>;
/// `BridgeHubRococo` Runtime `Call` enum.
///
/// The enum represents a subset of possible `Call`s we can send to Rococo chain.
/// The enum represents a subset of possible `Call`s we can send to `BridgeHubRococo` chain.
/// Ideally this code would be auto-generated from metadata, because we want to
/// avoid depending directly on the ENTIRE runtime just to get the encoding of `Dispatchable`s.
///
/// All entries here (like pretty much in the entire file) must be kept in sync with Rococo
/// `construct_runtime`, so that we maintain SCALE-compatibility.
/// All entries here (like pretty much in the entire file) must be kept in sync with
/// `BridgeHubRococo` `construct_runtime`, so that we maintain SCALE-compatibility.
///
/// // TODO:check-parameter -> change bko-bridge-rococo-wococo when merged to master in cumulus
/// See: [link](https://github.com/paritytech/cumulus/blob/bko-bridge-rococo-wococo/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs)
/// // TODO:check-parameter -> change bridge-hub-rococo-wococo when merged to master in cumulus
/// See: [link](https://github.com/paritytech/cumulus/blob/bridge-hub-rococo-wococo/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs)
#[allow(clippy::large_enum_variant)]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub enum Call {
/// System pallet.
#[cfg(test)]
#[codec(index = 0)]
System(SystemCall),
/// Wococo bridge pallet.
#[codec(index = 41)]
BridgeWococoGrandpa(BridgeWococoGrandpaCall),
/// Rococo bridge pallet.
#[codec(index = 43)]
BridgeRococoGrandpa(BridgeRococoGrandpaCall),
/// Wococo parachain bridge pallet.
#[codec(index = 42)]
BridgeWococoParachain(BridgeParachainCall),
/// Rococo parachain bridge pallet.
#[codec(index = 44)]
BridgeRococoParachain(BridgeParachainCall),
/// Wococo messages bridge pallet.
#[codec(index = 46)]
BridgeWococoMessages(BridgeWococoMessagesCall),
/// Rococo messages bridge pallet.
#[codec(index = 45)]
BridgeRococoMessages(BridgeRococoMessagesCall),
}
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[allow(non_camel_case_types)]
pub enum SystemCall {
#[codec(index = 1)]
remark(Vec<u8>),
}
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[allow(non_camel_case_types)]
pub enum BridgeWococoGrandpaCall {
#[codec(index = 0)]
submit_finality_proof(
Box<<PolkadotLike as Chain>::Header>,
bp_header_chain::justification::GrandpaJustification<<PolkadotLike as Chain>::Header>,
),
#[codec(index = 1)]
initialize(bp_header_chain::InitializationData<<PolkadotLike as Chain>::Header>),
}
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[allow(non_camel_case_types)]
pub enum BridgeRococoGrandpaCall {
#[codec(index = 0)]
submit_finality_proof(
Box<<PolkadotLike as Chain>::Header>,
bp_header_chain::justification::GrandpaJustification<<PolkadotLike as Chain>::Header>,
),
#[codec(index = 1)]
initialize(bp_header_chain::InitializationData<<PolkadotLike as Chain>::Header>),
}
pub type RelayBlockHash = bp_polkadot_core::Hash;
pub type RelayBlockNumber = bp_polkadot_core::BlockNumber;
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[allow(non_camel_case_types)]
pub enum BridgeParachainCall {
#[codec(index = 0)]
submit_parachain_heads(
(RelayBlockNumber, RelayBlockHash),
Vec<(ParaId, ParaHash)>,
ParaHeadsProof,
),
}
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[allow(non_camel_case_types)]
pub enum BridgeWococoMessagesCall {
#[codec(index = 2)]
receive_messages_proof(
relay_substrate_client::AccountIdOf<bp_bridge_hub_wococo::BridgeHubWococo>,
bridge_runtime_common::messages::target::FromBridgedChainMessagesProof<
relay_substrate_client::HashOf<bp_bridge_hub_wococo::BridgeHubWococo>,
>,
u32,
bp_messages::Weight,
),
#[codec(index = 3)]
receive_messages_delivery_proof(
bridge_runtime_common::messages::source::FromBridgedChainMessagesDeliveryProof<
relay_substrate_client::HashOf<bp_bridge_hub_wococo::BridgeHubWococo>,
>,
UnrewardedRelayersState,
),
}
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
#[allow(non_camel_case_types)]
pub enum BridgeRococoMessagesCall {
#[codec(index = 2)]
receive_messages_proof(
relay_substrate_client::AccountIdOf<bp_bridge_hub_rococo::BridgeHubRococo>,
bridge_runtime_common::messages::target::FromBridgedChainMessagesProof<
relay_substrate_client::HashOf<bp_bridge_hub_rococo::BridgeHubRococo>,
>,
u32,
bp_messages::Weight,
),
#[codec(index = 3)]
receive_messages_delivery_proof(
bridge_runtime_common::messages::source::FromBridgedChainMessagesDeliveryProof<
relay_substrate_client::HashOf<bp_bridge_hub_rococo::BridgeHubRococo>,
>,
UnrewardedRelayersState,
),
}
impl sp_runtime::traits::Dispatchable for Call {
type RuntimeOrigin = ();
type Config = ();
type Info = ();
type PostInfo = ();
fn dispatch(
self,
_origin: Self::RuntimeOrigin,
) -> sp_runtime::DispatchResultWithInfo<Self::PostInfo> {
unimplemented!("The Call is not expected to be dispatched.")
}
}
#[cfg(test)]
mod tests {
use super::*;
use bp_runtime::BasicOperatingMode;
use sp_core::hexdisplay::HexDisplay;
use sp_finality_grandpa::AuthorityList;
use sp_runtime::traits::Header;
use std::str::FromStr;
pub type RelayBlockHasher = bp_polkadot_core::Hasher;
pub type RelayBlockHeader = sp_runtime::generic::Header<RelayBlockNumber, RelayBlockHasher>;
#[test]
fn encode_decode_calls() {
let header = RelayBlockHeader::new(
75,
bp_polkadot_core::Hash::from_str(
"0xd2c0afaab32de0cb8f7f0d89217e37c5ea302c1ffb5a7a83e10d20f12c32874d",
)
.expect("invalid value"),
bp_polkadot_core::Hash::from_str(
"0x92b965f0656a4e0e5fc0167da2d4b5ee72b3be2c1583c4c1e5236c8c12aa141b",
)
.expect("invalid value"),
bp_polkadot_core::Hash::from_str(
"0xae4a25acf250d72ed02c149ecc7dd3c9ee976d41a2888fc551de8064521dc01d",
)
.expect("invalid value"),
Default::default(),
);
let init_data = bp_header_chain::InitializationData {
header: Box::new(header),
authority_list: AuthorityList::default(),
set_id: 6,
operating_mode: BasicOperatingMode::Normal,
};
let call = BridgeRococoGrandpaCall::initialize(init_data);
let tx = Call::BridgeRococoGrandpa(call);
// encode call as hex string
let hex_encoded_call = format!("0x{:?}", HexDisplay::from(&Encode::encode(&tx)));
assert_eq!(hex_encoded_call, "0x2b01ae4a25acf250d72ed02c149ecc7dd3c9ee976d41a2888fc551de8064521dc01d2d0192b965f0656a4e0e5fc0167da2d4b5ee72b3be2c1583c4c1e5236c8c12aa141bd2c0afaab32de0cb8f7f0d89217e37c5ea302c1ffb5a7a83e10d20f12c32874d0000060000000000000000");
}
}
@@ -12,11 +12,21 @@ relay-substrate-client = { path = "../client-substrate" }
# Bridge dependencies
bp-bridge-hub-rococo = { path = "../../primitives/chain-bridge-hub-rococo" }
bp-bridge-hub-wococo = { path = "../../primitives/chain-bridge-hub-wococo" }
bp-header-chain = { path = "../../primitives/header-chain" }
bp-messages = { path = "../../primitives/messages" }
relay-bridge-hub-rococo-client = { path = "../client-bridge-hub-rococo" }
bp-parachains = { path = "../../primitives/parachains" }
bp-rococo = { path = "../../primitives/chain-rococo" }
bp-runtime = { path = "../../primitives/runtime" }
bridge-runtime-common = { path = "../../bin/runtime-common" }
# Substrate Dependencies
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
[dev-dependencies]
bp-polkadot-core = { path = "../../primitives/polkadot-core" }
sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master" }
@@ -16,11 +16,94 @@
//! Types that are specific to the BridgeHubWococo runtime.
// We reuse everything from rococo runtime wrapper
pub type Call = relay_bridge_hub_rococo_client::runtime::Call;
use codec::{Decode, Encode};
use scale_info::TypeInfo;
pub use bp_header_chain::BridgeGrandpaCallOf;
pub use bp_parachains::BridgeParachainCall;
pub use bp_runtime::calls::SystemCall;
pub use bridge_runtime_common::messages::BridgeMessagesCallOf;
// TODO:check-parameter - check SignedExtension
/// Unchecked BridgeHubWococo extrinsic.
pub type UncheckedExtrinsic = bp_bridge_hub_wococo::UncheckedExtrinsic<Call>;
pub type BridgeGrandpaRococoCall = relay_bridge_hub_rococo_client::runtime::BridgeRococoGrandpaCall;
pub type BridgeParachainCall = relay_bridge_hub_rococo_client::runtime::BridgeParachainCall;
pub type BridgeRococoMessagesCall =
relay_bridge_hub_rococo_client::runtime::BridgeRococoMessagesCall;
pub type SystemCall = relay_bridge_hub_rococo_client::runtime::SystemCall;
// The indirect pallet call used to sync `Rococo` GRANDPA finality to `BHWococo`.
pub type BridgeRococoGrandpaCall = BridgeGrandpaCallOf<bp_rococo::Rococo>;
// The indirect pallet call used to sync `BridgeHubRococo` messages to `BridgeHubWococo`.
pub type BridgeRococoMessagesCall = BridgeMessagesCallOf<bp_bridge_hub_rococo::BridgeHubRococo>;
/// `BridgeHubWococo` Runtime `Call` enum.
///
/// The enum represents a subset of possible `Call`s we can send to `BridgeHubWococo` chain.
/// Ideally this code would be auto-generated from metadata, because we want to
/// avoid depending directly on the ENTIRE runtime just to get the encoding of `Dispatchable`s.
///
/// All entries here (like pretty much in the entire file) must be kept in sync with
/// `BridgeHubWococo` `construct_runtime`, so that we maintain SCALE-compatibility.
///
/// TODO:check-parameter -> change bridge-hub-rococo-wococo when merged to master in cumulus
/// See: [link](https://github.com/paritytech/cumulus/blob/bridge-hub-rococo-wococo/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs)
#[allow(clippy::large_enum_variant)]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub enum Call {
#[cfg(test)]
#[codec(index = 0)]
System(SystemCall),
/// Rococo bridge pallet.
#[codec(index = 43)]
BridgeRococoGrandpa(BridgeRococoGrandpaCall),
/// Rococo parachain bridge pallet.
#[codec(index = 44)]
BridgeRococoParachain(BridgeParachainCall),
/// Rococo messages bridge pallet.
#[codec(index = 45)]
BridgeRococoMessages(BridgeRococoMessagesCall),
}
#[cfg(test)]
mod tests {
use super::*;
use bp_runtime::BasicOperatingMode;
use sp_core::hexdisplay::HexDisplay;
use sp_finality_grandpa::AuthorityList;
use sp_runtime::traits::Header;
use std::str::FromStr;
pub type RelayBlockNumber = bp_polkadot_core::BlockNumber;
pub type RelayBlockHasher = bp_polkadot_core::Hasher;
pub type RelayBlockHeader = sp_runtime::generic::Header<RelayBlockNumber, RelayBlockHasher>;
#[test]
fn encode_decode_calls() {
let header = RelayBlockHeader::new(
75,
bp_polkadot_core::Hash::from_str(
"0xd2c0afaab32de0cb8f7f0d89217e37c5ea302c1ffb5a7a83e10d20f12c32874d",
)
.expect("invalid value"),
bp_polkadot_core::Hash::from_str(
"0x92b965f0656a4e0e5fc0167da2d4b5ee72b3be2c1583c4c1e5236c8c12aa141b",
)
.expect("invalid value"),
bp_polkadot_core::Hash::from_str(
"0xae4a25acf250d72ed02c149ecc7dd3c9ee976d41a2888fc551de8064521dc01d",
)
.expect("invalid value"),
Default::default(),
);
let init_data = bp_header_chain::InitializationData {
header: Box::new(header),
authority_list: AuthorityList::default(),
set_id: 6,
operating_mode: BasicOperatingMode::Normal,
};
let call = BridgeRococoGrandpaCall::initialize(init_data);
let tx = Call::BridgeRococoGrandpa(call);
// encode call as hex string
let hex_encoded_call = format!("0x{:?}", HexDisplay::from(&Encode::encode(&tx)));
assert_eq!(hex_encoded_call, "0x2b01ae4a25acf250d72ed02c149ecc7dd3c9ee976d41a2888fc551de8064521dc01d2d0192b965f0656a4e0e5fc0167da2d4b5ee72b3be2c1583c4c1e5236c8c12aa141bd2c0afaab32de0cb8f7f0d89217e37c5ea302c1ffb5a7a83e10d20f12c32874d0000060000000000000000");
}
}
+2 -2
View File
@@ -26,7 +26,7 @@ use sc_transaction_pool_api::TransactionStatus;
use sp_core::{storage::StorageKey, Pair};
use sp_runtime::{
generic::SignedBlock,
traits::{Block as BlockT, Dispatchable, Member},
traits::{Block as BlockT, Member},
ConsensusEngineId, EncodedJustification,
};
use std::{fmt::Debug, time::Duration};
@@ -56,7 +56,7 @@ pub trait Chain: ChainBase + Clone {
/// Block type.
type SignedBlock: Member + Serialize + DeserializeOwned + BlockWithJustification<Self::Header>;
/// The aggregated `Call` type.
type Call: Clone + Codec + Dispatchable + Debug + Send;
type Call: Clone + Codec + Debug + Send;
}
/// Substrate-based relay chain that supports parachains.
@@ -316,7 +316,7 @@ async fn background_task<P: SubstrateFinalitySyncPipeline>(
stall_timeout,
only_mandatory_headers,
},
metrics_params.clone().unwrap_or_else(|| MetricsParams::disabled()),
metrics_params.clone().unwrap_or_else(MetricsParams::disabled),
futures::future::pending(),
)
.fuse(),