Skip to content

Commit f99f222

Browse files
HCastanotomusdrw
andauthored
Westend<>Rococo Headers Relay (paritytech#875)
* Add modules for Rococo<>Westend header sync * Use mock Westend and Rococo finaltiy tx calls * Add Westend<>Rococo variants to `init_bridge` * Add Westend<>Rococo variants to `relay_headers` * Simplify the Rococo and Westend signing params * Add `submit_finality_proof` mock Call variant * Add note to more closely match `initialize` Call variant * Accidentally committed `cargo-expand`ed code 🤦 * Add `initialize` Call variant to Rococo mock * Fix call enums. * Add explainatory comment. * clippy. * Add issue number. * De-duplicate metrics customisation. * Add comments to Rococo/Westend runtimes. * Add scale-encoding compatibility test. * Fix tests. * Clippy. Co-authored-by: Tomasz Drwięga <tomasz@parity.io>
1 parent 72c9117 commit f99f222

File tree

19 files changed

+392
-111
lines changed

19 files changed

+392
-111
lines changed

Cargo.lock

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/dispatch/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ use sp_std::{fmt::Debug, marker::PhantomData, prelude::*};
4545
/// Spec version type.
4646
pub type SpecVersion = u32;
4747

48+
// TODO [#895] move to primitives
4849
/// Origin of a Call when it is dispatched on the target chain.
4950
///
5051
/// The source chain can (and should) verify that the message can be dispatched on the target chain
@@ -89,6 +90,7 @@ pub enum CallOrigin<SourceChainAccountId, TargetChainAccountPublic, TargetChainS
8990
SourceAccount(SourceChainAccountId),
9091
}
9192

93+
// TODO [#895] move to primitives
9294
/// Message payload type used by dispatch module.
9395
#[derive(RuntimeDebug, Encode, Decode, Clone, PartialEq, Eq)]
9496
pub struct MessagePayload<SourceChainAccountId, TargetChainAccountPublic, TargetChainSignature, Call> {

modules/grandpa/src/lib.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,13 @@
3939
use crate::weights::WeightInfo;
4040

4141
use bp_header_chain::justification::GrandpaJustification;
42+
use bp_header_chain::InitializationData;
4243
use bp_runtime::{BlockNumberOf, Chain, HashOf, HasherOf, HeaderOf};
43-
use codec::{Decode, Encode};
4444
use finality_grandpa::voter_set::VoterSet;
4545
use frame_support::ensure;
4646
use frame_system::{ensure_signed, RawOrigin};
47-
#[cfg(feature = "std")]
48-
use serde::{Deserialize, Serialize};
4947
use sp_finality_grandpa::{ConsensusLog, GRANDPA_ENGINE_ID};
5048
use sp_runtime::traits::{BadOrigin, Header as HeaderT, Zero};
51-
use sp_runtime::RuntimeDebug;
5249

5350
#[cfg(test)]
5451
mod mock;
@@ -511,22 +508,6 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
511508
}
512509
}
513510

514-
/// Data required for initializing the bridge pallet.
515-
///
516-
/// The bridge needs to know where to start its sync from, and this provides that initial context.
517-
#[derive(Default, Encode, Decode, RuntimeDebug, PartialEq, Clone)]
518-
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
519-
pub struct InitializationData<H: HeaderT> {
520-
/// The header from which we should start syncing.
521-
pub header: H,
522-
/// The initial authorities of the pallet.
523-
pub authority_list: sp_finality_grandpa::AuthorityList,
524-
/// The ID of the initial authority set.
525-
pub set_id: sp_finality_grandpa::SetId,
526-
/// Should the pallet block transaction immediately after initialization.
527-
pub is_halted: bool,
528-
}
529-
530511
pub(crate) fn find_scheduled_change<H: HeaderT>(header: &H) -> Option<sp_finality_grandpa::ScheduledChange<H::Number>> {
531512
use sp_runtime::generic::OpaqueDigestItemId;
532513

primitives/chain-rococo/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
1010
parity-scale-codec = { version = "2.0.0", default-features = false, features = ["derive"] }
1111

1212
# Bridge Dependencies
13+
bp-header-chain = { path = "../header-chain", default-features = false }
1314
bp-messages = { path = "../messages", default-features = false }
1415
bp-polkadot-core = { path = "../polkadot-core", default-features = false }
1516
bp-runtime = { path = "../runtime", default-features = false }
@@ -23,6 +24,7 @@ sp-version = { git = "https://github.com/paritytech/substrate", branch = "master
2324
[features]
2425
default = ["std"]
2526
std = [
27+
"bp-header-chain/std",
2628
"bp-messages/std",
2729
"bp-polkadot-core/std",
2830
"bp-runtime/std",

primitives/chain-rococo/src/lib.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#![allow(clippy::unnecessary_mut_passed)]
2222

2323
use bp_messages::{LaneId, MessageNonce, UnrewardedRelayersState, Weight};
24+
use bp_runtime::Chain;
2425
use sp_std::prelude::*;
2526
use sp_version::RuntimeVersion;
2627

@@ -41,9 +42,33 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
4142
transaction_version: 6,
4243
};
4344

45+
/// Rococo Runtime `Call` enum.
46+
///
47+
/// The enum represents a subset of possible `Call`s we can send to Rococo chain.
48+
/// Ideally this code would be auto-generated from Metadata, because we want to
49+
/// avoid depending directly on the ENTIRE runtime just to get the encoding of `Dispatchable`s.
50+
///
51+
/// All entries here (like pretty much in the entire file) must be kept in sync with Rococo
52+
/// `construct_runtime`, so that we maintain SCALE-compatibility.
53+
///
54+
/// See: https://github.com/paritytech/polkadot/blob/master/runtime/rococo/src/lib.rs
4455
#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode, Debug, PartialEq, Eq, Clone)]
4556
pub enum Call {
46-
MockPallet,
57+
/// Westend bridge pallet.
58+
#[codec(index = 40)]
59+
BridgeGrandpaWestend(BridgeGrandpaWestendCall),
60+
}
61+
62+
#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode, Debug, PartialEq, Eq, Clone)]
63+
#[allow(non_camel_case_types)]
64+
pub enum BridgeGrandpaWestendCall {
65+
#[codec(index = 0)]
66+
submit_finality_proof(
67+
<PolkadotLike as Chain>::Header,
68+
bp_header_chain::justification::GrandpaJustification<<PolkadotLike as Chain>::Header>,
69+
),
70+
#[codec(index = 1)]
71+
initialize(bp_header_chain::InitializationData<<PolkadotLike as Chain>::Header>),
4772
}
4873

4974
impl sp_runtime::traits::Dispatchable for Call {

primitives/chain-westend/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
1010
parity-scale-codec = { version = "2.0.0", default-features = false, features = ["derive"] }
1111

1212
# Bridge Dependencies
13+
bp-header-chain = { path = "../header-chain", default-features = false }
1314
bp-messages = { path = "../messages", default-features = false }
1415
bp-polkadot-core = { path = "../polkadot-core", default-features = false }
1516
bp-runtime = { path = "../runtime", default-features = false }
@@ -23,6 +24,7 @@ sp-version = { git = "https://github.com/paritytech/substrate", branch = "master
2324
[features]
2425
default = ["std"]
2526
std = [
27+
"bp-header-chain/std",
2628
"bp-messages/std",
2729
"bp-polkadot-core/std",
2830
"bp-runtime/std",

primitives/chain-westend/src/lib.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#![allow(clippy::unnecessary_mut_passed)]
2222

2323
use bp_messages::{LaneId, MessageNonce, UnrewardedRelayersState, Weight};
24+
use bp_runtime::Chain;
2425
use sp_std::prelude::*;
2526
use sp_version::RuntimeVersion;
2627

@@ -42,9 +43,33 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
4243
transaction_version: 5,
4344
};
4445

46+
/// Westend Runtime `Call` enum.
47+
///
48+
/// The enum represents a subset of possible `Call`s we can send to Westend chain.
49+
/// Ideally this code would be auto-generated from Metadata, because we want to
50+
/// avoid depending directly on the ENTIRE runtime just to get the encoding of `Dispatchable`s.
51+
///
52+
/// All entries here (like pretty much in the entire file) must be kept in sync with Westend
53+
/// `construct_runtime`, so that we maintain SCALE-compatibility.
54+
///
55+
/// See: https://github.com/paritytech/polkadot/blob/master/runtime/westend/src/lib.rs
4556
#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode, Debug, PartialEq, Eq, Clone)]
4657
pub enum Call {
47-
MockModule,
58+
/// Rococo bridge pallet.
59+
#[codec(index = 40)]
60+
BridgeGrandpaRococo(BridgeGrandpaRococoCall),
61+
}
62+
63+
#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode, Debug, PartialEq, Eq, Clone)]
64+
#[allow(non_camel_case_types)]
65+
pub enum BridgeGrandpaRococoCall {
66+
#[codec(index = 0)]
67+
submit_finality_proof(
68+
<PolkadotLike as Chain>::Header,
69+
bp_header_chain::justification::GrandpaJustification<<PolkadotLike as Chain>::Header>,
70+
),
71+
#[codec(index = 1)]
72+
initialize(bp_header_chain::InitializationData<<PolkadotLike as Chain>::Header>),
4873
}
4974

5075
impl sp_runtime::traits::Dispatchable for Call {

primitives/header-chain/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ impl AuthoritySet {
5555
}
5656
}
5757

58+
/// Data required for initializing the bridge pallet.
59+
///
60+
/// The bridge needs to know where to start its sync from, and this provides that initial context.
61+
#[derive(Default, Encode, Decode, RuntimeDebug, PartialEq, Eq, Clone)]
62+
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
63+
pub struct InitializationData<H: HeaderT> {
64+
/// The header from which we should start syncing.
65+
pub header: H,
66+
/// The initial authorities of the pallet.
67+
pub authority_list: AuthorityList,
68+
/// The ID of the initial authority set.
69+
pub set_id: SetId,
70+
/// Should the pallet block transaction immediately after initialization.
71+
pub is_halted: bool,
72+
}
73+
5874
/// base trait for verifying transaction inclusion proofs.
5975
pub trait InclusionProofVerifier {
6076
/// Transaction type.

relays/bin-substrate/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ bp-messages = { path = "../../primitives/messages" }
2626
bp-millau = { path = "../../primitives/chain-millau" }
2727
bp-polkadot = { path = "../../primitives/chain-polkadot" }
2828
bp-rialto = { path = "../../primitives/chain-rialto" }
29+
bp-rococo = { path = "../../primitives/chain-rococo" }
2930
bp-runtime = { path = "../../primitives/runtime" }
3031
bp-westend = { path = "../../primitives/chain-westend" }
3132
bridge-runtime-common = { path = "../../bin/runtime-common" }
@@ -35,12 +36,12 @@ headers-relay = { path = "../headers" }
3536
messages-relay = { path = "../messages" }
3637
millau-runtime = { path = "../../bin/millau/runtime" }
3738
pallet-bridge-dispatch = { path = "../../modules/dispatch" }
38-
pallet-bridge-grandpa = { path = "../../modules/grandpa" }
3939
pallet-bridge-messages = { path = "../../modules/messages" }
4040
relay-kusama-client = { path = "../client-kusama" }
4141
relay-millau-client = { path = "../client-millau" }
4242
relay-polkadot-client = { path = "../client-polkadot" }
4343
relay-rialto-client = { path = "../client-rialto" }
44+
relay-rococo-client = { path = "../client-rococo" }
4445
relay-substrate-client = { path = "../client-substrate" }
4546
relay-utils = { path = "../utils" }
4647
relay-westend-client = { path = "../client-westend" }

relays/bin-substrate/src/cli/init_bridge.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
1616

1717
use crate::cli::{SourceConnectionParams, TargetConnectionParams, TargetSigningParams};
18+
use bp_header_chain::InitializationData;
1819
use bp_runtime::Chain as ChainBase;
1920
use codec::Encode;
20-
use pallet_bridge_grandpa::InitializationData;
2121
use relay_substrate_client::{Chain, TransactionSignScheme};
2222
use sp_core::{Bytes, Pair};
2323
use structopt::{clap::arg_enum, StructOpt};
@@ -44,6 +44,8 @@ arg_enum! {
4444
MillauToRialto,
4545
RialtoToMillau,
4646
WestendToMillau,
47+
WestendToRococo,
48+
RococoToWestend,
4749
}
4850
}
4951

@@ -98,6 +100,30 @@ macro_rules! select_bridge {
98100
.into()
99101
}
100102

103+
$generic
104+
}
105+
InitBridgeName::WestendToRococo => {
106+
type Source = relay_westend_client::Westend;
107+
type Target = relay_rococo_client::Rococo;
108+
109+
fn encode_init_bridge(
110+
init_data: InitializationData<<Source as ChainBase>::Header>,
111+
) -> <Target as Chain>::Call {
112+
bp_rococo::Call::BridgeGrandpaWestend(bp_rococo::BridgeGrandpaWestendCall::initialize(init_data))
113+
}
114+
115+
$generic
116+
}
117+
InitBridgeName::RococoToWestend => {
118+
type Source = relay_rococo_client::Rococo;
119+
type Target = relay_westend_client::Westend;
120+
121+
fn encode_init_bridge(
122+
init_data: InitializationData<<Source as ChainBase>::Header>,
123+
) -> <Target as Chain>::Call {
124+
bp_westend::Call::BridgeGrandpaRococo(bp_westend::BridgeGrandpaRococoCall::initialize(init_data))
125+
}
126+
101127
$generic
102128
}
103129
}

0 commit comments

Comments
 (0)