Skip to content

Commit 40b3136

Browse files
committed
Squashed 'bridges/' changes from 89a76998f..025222498
025222498 Fix test 48b41d82b Add support for relaying headers between Rococo and Wococo f16b6b411 Add CLI support for initializing the Wococo<>Rococo bridge 8c6e6443d Add more Wococo boilerplate code 28d3ed2fe Add Wococo primitives crate d691c73e9 Fix issue with on-demand headers relay not starting (paritytech#921) 8ee55c1e1 Fix image publishing. (paritytech#922) f51fb59d0 Prefix in relay loops logs (paritytech#920) git-subtree-dir: bridges git-subtree-split: 02522249876f1e2463143a532653764f82e33e07
1 parent 9781c79 commit 40b3136

31 files changed

+796
-116
lines changed

.github/workflows/rust.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ jobs:
8585
matrix:
8686
toolchain:
8787
- stable
88-
#- beta
89-
- nightly
88+
#- beta
89+
- nightly-2021-04-10
9090
runs-on: ubuntu-latest
9191
env:
9292
RUST_BACKTRACE: full

Cargo.lock

+34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

primitives/chain-rococo/src/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,16 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
5757
pub enum Call {
5858
/// Westend bridge pallet.
5959
#[codec(index = 40)]
60-
BridgeGrandpaWestend(BridgeGrandpaWestendCall),
60+
BridgeGrandpaWestend(BridgeGrandpaCall),
61+
62+
/// Wococo bridge pallet.
63+
#[codec(index = 41)]
64+
BridgeGrandpaWococo(BridgeGrandpaCall),
6165
}
6266

6367
#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode, Debug, PartialEq, Eq, Clone)]
6468
#[allow(non_camel_case_types)]
65-
pub enum BridgeGrandpaWestendCall {
69+
pub enum BridgeGrandpaCall {
6670
#[codec(index = 0)]
6771
submit_finality_proof(
6872
<PolkadotLike as Chain>::Header,

primitives/chain-wococo/Cargo.toml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[package]
2+
name = "bp-wococo"
3+
description = "Primitives of Wococo runtime."
4+
version = "0.1.0"
5+
authors = ["Parity Technologies <admin@parity.io>"]
6+
edition = "2018"
7+
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
8+
9+
[dependencies]
10+
parity-scale-codec = { version = "2.0.0", default-features = false, features = ["derive"] }
11+
12+
# Bridge Dependencies
13+
bp-header-chain = { path = "../header-chain", default-features = false }
14+
bp-messages = { path = "../messages", default-features = false }
15+
bp-polkadot-core = { path = "../polkadot-core", default-features = false }
16+
bp-runtime = { path = "../runtime", default-features = false }
17+
18+
# Substrate Based Dependencies
19+
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" , default-features = false }
20+
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
21+
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
22+
sp-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
23+
24+
[features]
25+
default = ["std"]
26+
std = [
27+
"bp-header-chain/std",
28+
"bp-messages/std",
29+
"bp-polkadot-core/std",
30+
"bp-runtime/std",
31+
"parity-scale-codec/std",
32+
"sp-api/std",
33+
"sp-runtime/std",
34+
"sp-std/std",
35+
"sp-version/std",
36+
]

primitives/chain-wococo/src/lib.rs

+172
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
2+
// This file is part of Parity Bridges Common.
3+
4+
// Parity Bridges Common is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// Parity Bridges Common is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
16+
17+
#![cfg_attr(not(feature = "std"), no_std)]
18+
// RuntimeApi generated functions
19+
#![allow(clippy::too_many_arguments)]
20+
// Runtime-generated DecodeLimit::decode_all_with_depth_limit
21+
#![allow(clippy::unnecessary_mut_passed)]
22+
23+
use bp_messages::{LaneId, MessageNonce, UnrewardedRelayersState, Weight};
24+
use bp_runtime::Chain;
25+
use sp_std::prelude::*;
26+
use sp_version::RuntimeVersion;
27+
28+
pub use bp_polkadot_core::*;
29+
30+
/// Wococo Chain
31+
pub type Wococo = PolkadotLike;
32+
33+
pub type UncheckedExtrinsic = bp_polkadot_core::UncheckedExtrinsic<Call>;
34+
35+
// NOTE: This needs to be kept up to date with the Rococo runtime found in the Polkadot repo.
36+
pub const VERSION: RuntimeVersion = RuntimeVersion {
37+
spec_name: sp_version::create_runtime_str!("rococo"),
38+
impl_name: sp_version::create_runtime_str!("parity-rococo-v1.5"),
39+
authoring_version: 0,
40+
spec_version: 231,
41+
impl_version: 0,
42+
apis: sp_version::create_apis_vec![[]],
43+
transaction_version: 0,
44+
};
45+
46+
/// Wococo Runtime `Call` enum.
47+
///
48+
/// The enum represents a subset of possible `Call`s we can send to Rococo 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 Rococo
53+
/// `construct_runtime`, so that we maintain SCALE-compatibility.
54+
///
55+
/// See: https://github.com/paritytech/polkadot/blob/master/runtime/rococo/src/lib.rs
56+
#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode, Debug, PartialEq, Eq, Clone)]
57+
pub enum Call {
58+
/// Westend 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>),
73+
}
74+
75+
impl sp_runtime::traits::Dispatchable for Call {
76+
type Origin = ();
77+
type Config = ();
78+
type Info = ();
79+
type PostInfo = ();
80+
81+
fn dispatch(self, _origin: Self::Origin) -> sp_runtime::DispatchResultWithInfo<Self::PostInfo> {
82+
unimplemented!("The Call is not expected to be dispatched.")
83+
}
84+
}
85+
86+
// We use this to get the account on Wococo (target) which is derived from Rococo's (source)
87+
// account.
88+
pub fn derive_account_from_rococo_id(id: bp_runtime::SourceAccount<AccountId>) -> AccountId {
89+
let encoded_id = bp_runtime::derive_account_id(bp_runtime::ROCOCO_BRIDGE_INSTANCE, id);
90+
AccountIdConverter::convert(encoded_id)
91+
}
92+
93+
/// Name of the `WococoFinalityApi::best_finalized` runtime method.
94+
pub const BEST_FINALIZED_WOCOCO_HEADER_METHOD: &str = "WococoFinalityApi_best_finalized";
95+
/// Name of the `WococoFinalityApi::is_known_header` runtime method.
96+
pub const IS_KNOWN_WOCOCO_HEADER_METHOD: &str = "WococoFinalityApi_is_known_header";
97+
98+
/// Name of the `ToWococoOutboundLaneApi::estimate_message_delivery_and_dispatch_fee` runtime method.
99+
pub const TO_WOCOCO_ESTIMATE_MESSAGE_FEE_METHOD: &str =
100+
"ToWococoOutboundLaneApi_estimate_message_delivery_and_dispatch_fee";
101+
/// Name of the `ToWococoOutboundLaneApi::messages_dispatch_weight` runtime method.
102+
pub const TO_WOCOCO_MESSAGES_DISPATCH_WEIGHT_METHOD: &str = "ToWococoOutboundLaneApi_messages_dispatch_weight";
103+
/// Name of the `ToWococoOutboundLaneApi::latest_generated_nonce` runtime method.
104+
pub const TO_WOCOCO_LATEST_GENERATED_NONCE_METHOD: &str = "ToWococoOutboundLaneApi_latest_generated_nonce";
105+
/// Name of the `ToWococoOutboundLaneApi::latest_received_nonce` runtime method.
106+
pub const TO_WOCOCO_LATEST_RECEIVED_NONCE_METHOD: &str = "ToWococoOutboundLaneApi_latest_received_nonce";
107+
108+
/// Name of the `FromWococoInboundLaneApi::latest_received_nonce` runtime method.
109+
pub const FROM_WOCOCO_LATEST_RECEIVED_NONCE_METHOD: &str = "FromWococoInboundLaneApi_latest_received_nonce";
110+
/// Name of the `FromWococoInboundLaneApi::latest_onfirmed_nonce` runtime method.
111+
pub const FROM_WOCOCO_LATEST_CONFIRMED_NONCE_METHOD: &str = "FromWococoInboundLaneApi_latest_confirmed_nonce";
112+
/// Name of the `FromWococoInboundLaneApi::unrewarded_relayers_state` runtime method.
113+
pub const FROM_WOCOCO_UNREWARDED_RELAYERS_STATE: &str = "FromWococoInboundLaneApi_unrewarded_relayers_state";
114+
115+
sp_api::decl_runtime_apis! {
116+
/// API for querying information about the finalized Wococo headers.
117+
///
118+
/// This API is implemented by runtimes that are bridging with the Wococo chain, not the
119+
/// Wococo runtime itself.
120+
pub trait WococoFinalityApi {
121+
/// Returns number and hash of the best finalized header known to the bridge module.
122+
fn best_finalized() -> (BlockNumber, Hash);
123+
/// Returns true if the header is known to the runtime.
124+
fn is_known_header(hash: Hash) -> bool;
125+
}
126+
127+
/// Outbound message lane API for messages that are sent to Wococo chain.
128+
///
129+
/// This API is implemented by runtimes that are sending messages to Wococo chain, not the
130+
/// Wococo runtime itself.
131+
pub trait ToWococoOutboundLaneApi<OutboundMessageFee: Parameter, OutboundPayload: Parameter> {
132+
/// Estimate message delivery and dispatch fee that needs to be paid by the sender on
133+
/// this chain.
134+
///
135+
/// Returns `None` if message is too expensive to be sent to Wococo from this chain.
136+
///
137+
/// Please keep in mind that this method returns lowest message fee required for message
138+
/// to be accepted to the lane. It may be good idea to pay a bit over this price to account
139+
/// future exchange rate changes and guarantee that relayer would deliver your message
140+
/// to the target chain.
141+
fn estimate_message_delivery_and_dispatch_fee(
142+
lane_id: LaneId,
143+
payload: OutboundPayload,
144+
) -> Option<OutboundMessageFee>;
145+
/// Returns total dispatch weight and encoded payload size of all messages in given inclusive range.
146+
///
147+
/// If some (or all) messages are missing from the storage, they'll also will
148+
/// be missing from the resulting vector. The vector is ordered by the nonce.
149+
fn messages_dispatch_weight(
150+
lane: LaneId,
151+
begin: MessageNonce,
152+
end: MessageNonce,
153+
) -> Vec<(MessageNonce, Weight, u32)>;
154+
/// Returns nonce of the latest message, received by bridged chain.
155+
fn latest_received_nonce(lane: LaneId) -> MessageNonce;
156+
/// Returns nonce of the latest message, generated by given lane.
157+
fn latest_generated_nonce(lane: LaneId) -> MessageNonce;
158+
}
159+
160+
/// Inbound message lane API for messages sent by Wococo chain.
161+
///
162+
/// This API is implemented by runtimes that are receiving messages from Wococo chain, not the
163+
/// Wococo runtime itself.
164+
pub trait FromWococoInboundLaneApi {
165+
/// Returns nonce of the latest message, received by given lane.
166+
fn latest_received_nonce(lane: LaneId) -> MessageNonce;
167+
/// Nonce of latest message that has been confirmed to the bridged chain.
168+
fn latest_confirmed_nonce(lane: LaneId) -> MessageNonce;
169+
/// State of the unrewarded relayers set at given lane.
170+
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
171+
}
172+
}

primitives/runtime/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ pub const KUSAMA_BRIDGE_INSTANCE: InstanceId = *b"ksma";
5050
/// Bridge-with-Rococo instance id.
5151
pub const ROCOCO_BRIDGE_INSTANCE: InstanceId = *b"roco";
5252

53+
/// Bridge-with-Wococo instance id.
54+
pub const WOCOCO_BRIDGE_INSTANCE: InstanceId = *b"woco";
55+
5356
/// Bridge-with-Westend instance id.
5457
pub const WESTEND_BRIDGE_INSTANCE: InstanceId = *b"wend";
5558

relays/bin-substrate/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ bp-millau = { path = "../../primitives/chain-millau" }
2727
bp-polkadot = { path = "../../primitives/chain-polkadot" }
2828
bp-rialto = { path = "../../primitives/chain-rialto" }
2929
bp-rococo = { path = "../../primitives/chain-rococo" }
30+
bp-wococo = { path = "../../primitives/chain-wococo" }
3031
bp-runtime = { path = "../../primitives/runtime" }
3132
bp-westend = { path = "../../primitives/chain-westend" }
3233
bridge-runtime-common = { path = "../../bin/runtime-common" }
@@ -42,6 +43,7 @@ relay-millau-client = { path = "../client-millau" }
4243
relay-polkadot-client = { path = "../client-polkadot" }
4344
relay-rialto-client = { path = "../client-rialto" }
4445
relay-rococo-client = { path = "../client-rococo" }
46+
relay-wococo-client = { path = "../client-wococo" }
4547
relay-substrate-client = { path = "../client-substrate" }
4648
relay-utils = { path = "../utils" }
4749
relay-westend-client = { path = "../client-westend" }

relays/bin-substrate/src/chains/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ pub mod millau_messages_to_rialto;
2121
pub mod rialto_headers_to_millau;
2222
pub mod rialto_messages_to_millau;
2323
pub mod rococo_headers_to_westend;
24+
pub mod rococo_headers_to_wococo;
2425
pub mod westend_headers_to_millau;
2526
pub mod westend_headers_to_rococo;
27+
pub mod wococo_headers_to_rococo;
2628

2729
mod millau;
2830
mod rialto;
2931
mod rococo;
3032
mod westend;
33+
mod wococo;
3134

3235
use relay_utils::metrics::{FloatJsonValueMetric, MetricsParams};
3336

@@ -270,7 +273,7 @@ mod rococo_tests {
270273
votes_ancestries: vec![],
271274
};
272275

273-
let actual = bp_rococo::BridgeGrandpaWestendCall::submit_finality_proof(header.clone(), justification.clone());
276+
let actual = bp_rococo::BridgeGrandpaCall::submit_finality_proof(header.clone(), justification.clone());
274277
let expected = millau_runtime::BridgeGrandpaRialtoCall::<millau_runtime::Runtime>::submit_finality_proof(
275278
header,
276279
justification,

0 commit comments

Comments
 (0)