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

Add Bridge Header Sync to Rococo Runtime #2983

Merged
20 commits merged into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f6682b8
Add bridges code to workspace
HCastano May 5, 2021
eed0d61
Add Rococo and Wococo bridge instances to Rococo runtime
HCastano Apr 27, 2021
2c5e641
Add Rococo and Wococo runtime APIs
HCastano Apr 27, 2021
060c9e2
Add GenesisConfig parameters for bridge pallet
HCastano Apr 27, 2021
99a4c21
Update Rococo spec_version used by bridge relayer
HCastano May 5, 2021
8d5c068
Add scripts for running Rococo and Wococo dev nodes
HCastano Apr 27, 2021
c52b752
Add scripts for running Rococo<>Wococo header sync
HCastano Apr 27, 2021
e969faf
Apply patch for build artifact location
HCastano May 5, 2021
fbbc6a5
Remove bridges crates from workspace
HCastano May 6, 2021
7727420
Merge branch 'master' into hc-wococo-rococo-bridge-integration
HCastano May 7, 2021
348a5f2
Downgrade async related dependencies
HCastano May 7, 2021
ff0fee4
Change bridge pallet owner to be `root_key`
HCastano May 10, 2021
9cf8fbb
Bump number of `MaxRequests` allowed
HCastano May 10, 2021
8a029c9
Revert changes in `bridges` subtree folder
HCastano May 10, 2021
f65482d
Merge branch 'master' into hc-wococo-rococo-bridge-integration
HCastano May 10, 2021
5e30ceb
Use correct account for Sudo
HCastano May 10, 2021
3b69d93
Add comment explaining duplicate bridge pallets
HCastano May 12, 2021
1bcf77a
Merge branch 'master' into hc-wococo-rococo-bridge-integration
HCastano May 12, 2021
d998df1
Remove WeightInfo comment.
tomusdrw May 13, 2021
92f2205
Merge branch 'master' into hc-wococo-rococo-bridge-integration
HCastano May 13, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 26 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ tempfile = "3.2.0"

[workspace]
members = [
"bridges/primitives/chain-kusama",
"bridges/primitives/chain-polkadot",
"bridges/primitives/chain-rococo",
"bridges/primitives/chain-westend",
"bridges/primitives/runtime",
ordian marked this conversation as resolved.
Show resolved Hide resolved
"cli",
"core-primitives",
"erasure-coding",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose these changes don't come via subtree update, IMHO we shouldn't be mixing adding bridges code and polkadot code in one PR. The point of bridges code being part of the repository is to make it easy for polkadot devs to fix any substrate inconsistencies, not to add features.

#
# Run an instance of the Rococo -> Wococo header sync.
#
# Right now this relies on local Wococo and Rococo networks
# running (which include `pallet-bridge-grandpa` in their
# runtimes), but in the future it could use use public RPC nodes.

set -xeu

RUST_LOG=rpc=trace,bridge=trace ./target/debug/substrate-relay init-bridge RococoToWococo \
--source-host 127.0.0.1 \
--source-port 9955 \
--target-host 127.0.0.1 \
--target-port 9944 \
--target-signer //Dave

RUST_LOG=rpc=trace,bridge=trace ./target/debug/substrate-relay relay-headers RococoToWococo \
--source-host 127.0.0.1 \
--source-port 9955 \
--target-host 127.0.0.1 \
--target-port 9944 \
--target-signer //Bob \
--prometheus-host=0.0.0.0 \
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
#
# Run an instance of the Wococo -> Rococo header sync.
#
# Right now this relies on local Wococo and Rococo networks
# running (which include `pallet-bridge-grandpa` in their
# runtimes), but in the future it could use use public RPC nodes.

set -xeu

RUST_LOG=rpc=trace,bridge=trace ./target/debug/substrate-relay init-bridge WococoToRococo \
--source-host 127.0.0.1 \
--source-port 9944 \
--target-host 127.0.0.1 \
--target-port 9955 \
--target-signer //Eve

RUST_LOG=rpc=trace,bridge=trace ./target/debug/substrate-relay relay-headers WococoToRococo \
--source-host 127.0.0.1 \
--source-port 9944 \
--target-host 127.0.0.1 \
--target-port 9955 \
--target-signer //Charlie \
--prometheus-host=0.0.0.0 \
2 changes: 1 addition & 1 deletion bridges/deployments/local-scripts/run-rococo-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
ROCOCO_PORT="${ROCOCO_PORT:-9955}"

RUST_LOG=runtime=trace,runtime::bridge=trace \
./target/debug/polkadot --chain=rococo-local --alice --tmp \
./target/debug/polkadot --chain=rococo-dev --alice --tmp \
--rpc-cors=all --unsafe-rpc-external --unsafe-ws-external \
--port 33044 --rpc-port 9934 --ws-port $ROCOCO_PORT \
14 changes: 14 additions & 0 deletions bridges/deployments/local-scripts/run-wococo-node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# Run a development instance of the Wococo Substrate bridge node.
# To override the default port just export WOCOCO_PORT=9955
#
# Note: This script will not work out of the box with the bridges
# repo since it relies on a Polkadot binary.

WOCOCO_PORT="${WOCOCO_PORT:-9944}"

RUST_LOG=runtime=trace,runtime::bridge=trace \
./target/debug/polkadot --chain=wococo-dev --alice --tmp \
--rpc-cors=all --unsafe-rpc-external --unsafe-ws-external \
--port 33033 --rpc-port 9933 --ws-port $WOCOCO_PORT \
2 changes: 1 addition & 1 deletion bridges/primitives/chain-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: sp_version::create_runtime_str!("rococo"),
impl_name: sp_version::create_runtime_str!("parity-rococo-v1.5"),
authoring_version: 0,
spec_version: 232,
spec_version: 9000,
impl_version: 0,
apis: sp_version::create_apis_vec![[]],
transaction_version: 0,
Expand Down
2 changes: 1 addition & 1 deletion bridges/primitives/chain-wococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: sp_version::create_runtime_str!("rococo"),
impl_name: sp_version::create_runtime_str!("parity-rococo-v1.5"),
authoring_version: 0,
spec_version: 232,
spec_version: 9000,
impl_version: 0,
apis: sp_version::create_apis_vec![[]],
transaction_version: 0,
Expand Down
16 changes: 16 additions & 0 deletions node/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,14 @@ fn rococo_staging_testnet_config_genesis(wasm_binary: &[u8]) -> rococo_runtime::
..Default::default()
},
},
pallet_bridge_grandpa: rococo_runtime::BridgeRococoGrandpaConfig {
owner: Some(get_account_id_from_seed::<sr25519::Public>("Dave")),
..Default::default()
},
pallet_bridge_grandpa_Instance1: rococo_runtime::BridgeWococoGrandpaConfig {
owner: Some(get_account_id_from_seed::<sr25519::Public>("Eve")),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woah, please use real accounts, that's rococo staging.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the problem is what accounts do we use? I figured it would be best to use dev accounts, and then talk to the DevOps team to see what "real" accounts to use.

We'd need to talk to them anyways before this would be deployed to Rococo anyways

..Default::default()
},
}
}

Expand Down Expand Up @@ -1475,6 +1483,14 @@ pub fn rococo_testnet_genesis(
paras: vec![],
_phdata: Default::default(),
},
pallet_bridge_grandpa: rococo_runtime::BridgeRococoGrandpaConfig {
owner: Some(get_account_id_from_seed::<sr25519::Public>("Dave")),
..Default::default()
},
pallet_bridge_grandpa_Instance1: rococo_runtime::BridgeWococoGrandpaConfig {
owner: Some(get_account_id_from_seed::<sr25519::Public>("Eve")),
..Default::default()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pallet_bridge_grandpa: rococo_runtime::BridgeRococoGrandpaConfig {
owner: Some(get_account_id_from_seed::<sr25519::Public>("Dave")),
..Default::default()
},
pallet_bridge_grandpa_Instance1: rococo_runtime::BridgeWococoGrandpaConfig {
owner: Some(get_account_id_from_seed::<sr25519::Public>("Eve")),
..Default::default()
pallet_bridge_grandpa: rococo_runtime::BridgeRococoGrandpaConfig {
owner: Some(root_key),
..Default::default()
},
pallet_bridge_grandpa_Instance1: rococo_runtime::BridgeWococoGrandpaConfig {
owner: Some(root_key),
..Default::default()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess root is reasonable to start

},
}
}

Expand Down
8 changes: 8 additions & 0 deletions runtime/rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ xcm-executor = { package = "xcm-executor", path = "../../xcm/xcm-executor", defa
xcm-builder = { package = "xcm-builder", path = "../../xcm/xcm-builder", default-features = false }
pallet-xcm = { path = "../../xcm/pallet-xcm", default-features = false }

# Bridge Dependencies
bp-rococo = { path = "../../bridges/primitives/chain-rococo", default-features = false }
bp-wococo = { path = "../../bridges/primitives/chain-wococo", default-features = false }
pallet-bridge-grandpa = { path = "../../bridges/modules/grandpa", default-features = false }

[build-dependencies]
substrate-wasm-builder = "3.0.0"

Expand All @@ -77,13 +82,16 @@ no_std = []
std = [
"authority-discovery-primitives/std",
"babe-primitives/std",
"bp-rococo/std",
"bp-wococo/std",
"parity-scale-codec/std",
"frame-executive/std",
"pallet-authority-discovery/std",
"pallet-authorship/std",
"pallet-babe/std",
"beefy-primitives/std",
"pallet-balances/std",
"pallet-bridge-grandpa/std",
"pallet-collective/std",
"pallet-beefy/std",
"pallet-grandpa/std",
Expand Down
58 changes: 58 additions & 0 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ construct_runtime! {
Mmr: pallet_mmr::{Pallet, Call, Storage},
Beefy: pallet_beefy::{Pallet, Config<T>, Storage},
MmrLeaf: mmr_common::{Pallet, Storage},
BridgeRococoGrandpa: pallet_bridge_grandpa::{Pallet, Call, Storage, Config<T>} = 40,
BridgeWococoGrandpa: pallet_bridge_grandpa::<Instance1>::{Pallet, Call, Storage, Config<T>} = 41,
Comment on lines +242 to +243
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an explanatory comment would be nice here, cause we are adding Rococo bridge pallet to Rococo runtime. It's only because Rococo and Wococo have exactly the same runtime, but the intention is to use BridgeWococoGrandpa pallet on Rococo and BridgeRococoGrandpa pallet on Wococo. The other pallet will always be uninitialized/halted.
This is a bit excessive and confusing, but I think it's acceptable for the matter of simplicity (no runtime duplication).


// Validator Manager pallet.
ValidatorManager: validator_manager::{Pallet, Call, Storage, Event<T>},
Expand Down Expand Up @@ -789,6 +791,40 @@ impl mmr_common::Config for Runtime {
type ParachainHeads = Paras;
}

parameter_types! {
// This is a pretty unscientific cap.
//
// Note that once this is hit the pallet will essentially throttle incoming requests down to one
// call per block.
pub const MaxRequests: u32 = 50;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub const MaxRequests: u32 = 50;
pub const MaxRequests: u32 = 4 * HOURS as u32;

Can we do something like that instead? This will allow us to catch-up immediately in case of 4 hours downtime.


// Number of headers to keep.
//
// Assuming the worst case of every header being finalized, we will keep headers at least for a
// week.
pub const HeadersToKeep: u32 = 7 * DAYS as u32;
}

pub type RococoGrandpaInstance = ();
impl pallet_bridge_grandpa::Config for Runtime {
type BridgedChain = bp_rococo::Rococo;
type MaxRequests = MaxRequests;
type HeadersToKeep = HeadersToKeep;

// TODO [#391]: Use weights generated for the Rococo runtime instead of Rialto ones.
ordian marked this conversation as resolved.
Show resolved Hide resolved
type WeightInfo = pallet_bridge_grandpa::weights::RialtoWeight<Runtime>;
}

pub type WococoGrandpaInstance = pallet_bridge_grandpa::Instance1;
impl pallet_bridge_grandpa::Config<WococoGrandpaInstance> for Runtime {
type BridgedChain = bp_wococo::Wococo;
type MaxRequests = MaxRequests;
type HeadersToKeep = HeadersToKeep;

// TODO [#391]: Use weights generated for the Rococo runtime instead of Rialto ones.
type WeightInfo = pallet_bridge_grandpa::weights::RialtoWeight<Runtime>;
}

impl Randomness<Hash, BlockNumber> for ParentHashRandomness {
fn random(subject: &[u8]) -> (Hash, BlockNumber) {
(
Expand Down Expand Up @@ -1218,6 +1254,28 @@ sp_api::impl_runtime_apis! {
}
}

impl bp_rococo::RococoFinalityApi<Block> for Runtime {
fn best_finalized() -> (bp_rococo::BlockNumber, bp_rococo::Hash) {
let header = BridgeRococoGrandpa::best_finalized();
(header.number, header.hash())
}

fn is_known_header(hash: bp_rococo::Hash) -> bool {
BridgeRococoGrandpa::is_known_header(hash)
}
}

impl bp_wococo::WococoFinalityApi<Block> for Runtime {
fn best_finalized() -> (bp_wococo::BlockNumber, bp_wococo::Hash) {
let header = BridgeWococoGrandpa::best_finalized();
(header.number, header.hash())
}

fn is_known_header(hash: bp_wococo::Hash) -> bool {
BridgeWococoGrandpa::is_known_header(hash)
}
}

impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Nonce> for Runtime {
fn account_nonce(account: AccountId) -> Nonce {
System::account_nonce(account)
Expand Down