Skip to content

Commit 5cc2571

Browse files
committed
Add feature flag support for Rococo vs Polkadot (init)
1 parent 4d62cca commit 5cc2571

File tree

9 files changed

+230
-55
lines changed

9 files changed

+230
-55
lines changed

.github/workflows/check.yml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
cache-all-crates: true
5252

5353
- name: Cargo check
54-
run: cargo check
54+
run: cargo check --workspace
5555

5656
check-benchmarking:
5757
name: Cargo check (benchmarking)
@@ -70,10 +70,13 @@ jobs:
7070
cache-on-failure: true
7171
cache-all-crates: true
7272

73-
- name: Cargo check (benchmarking)
74-
run: >
75-
cd node &&
76-
cargo check --features=runtime-benchmarks
73+
- name: Cargo check (Rococo) (benchmarking)
74+
run: |
75+
cargo check --workspace --features=runtime-benchmarks,rococo
76+
77+
#- name: Cargo check (Polkadot) (benchmarking)
78+
# run: |
79+
# cargo check --workspace --features=runtime-benchmarks,polkadot
7780

7881
test:
7982
name: Test
@@ -93,6 +96,13 @@ jobs:
9396
cache-on-failure: true
9497
cache-all-crates: true
9598

96-
# TODO: enable `--all-features`.
9799
- name: Run tests
98-
run: cargo test --workspace
100+
run: |
101+
cargo test --workspace
102+
cargo test --workspace --features=try-runtime
103+
cargo test --workspace --features=runtime-benchmarks
104+
105+
- name: Run (Rococo) runtime tests
106+
run: |
107+
cargo test -p polkadot-bulletin-chain-runtime --features=rococo
108+
cargo test -p polkadot-bulletin-chain-runtime --features=rococo,try-runtime,runtime-benchmarks

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ repository = "https://github.com/zdave-parity/polkadot-bulletin-chain.git"
55

66
[workspace.dependencies]
77
array-bytes = { version = "6.1" }
8+
cfg-if = { version = "1.0" }
89
clap = { version = "4.2.5" }
910
codec = { package = "parity-scale-codec", version = "3.7.5", default-features = false }
1011
futures = { version = "0.3.21" }
@@ -29,4 +30,6 @@ members = [
2930
"runtime",
3031
]
3132
[profile.release]
33+
# Polkadot runtime requires unwinding.
34+
opt-level = 3
3235
panic = "unwind"

node/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ try-runtime-cli = { optional = true, workspace = true }
6767
substrate-build-script-utils = { git = "https://github.com/paritytech/polkadot-sdk.git", rev = "db5e645422ccf952018a3c466a33fef477858602" }
6868

6969
[features]
70-
default = []
70+
default = [
71+
# TODO: temporary let's activate rococo by default
72+
"rococo"
73+
]
7174
# Dependencies that are only required if runtime benchmarking should be built.
7275
runtime-benchmarks = [
7376
"frame-benchmarking-cli/runtime-benchmarks",
@@ -85,5 +88,7 @@ try-runtime = [
8588
"sp-runtime/try-runtime",
8689
"try-runtime-cli?/try-runtime",
8790
]
88-
# To bridge with Rococo Bridge Hub instead of Polkadot Bridge Hub
91+
# To bridge with Rococo Bridge Hub
8992
rococo = ["polkadot-bulletin-chain-runtime/rococo"]
93+
# To bridge with PeoplePolkadot
94+
polkadot = ["polkadot-bulletin-chain-runtime/polkadot"]

runtime/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ repository = "https://github.com/paritytech/polkadot-bulletin-chain/"
1212
targets = ["x86_64-unknown-linux-gnu"]
1313

1414
[dependencies]
15+
cfg-if = { workspace = true }
1516
codec = { workspace = true, features = ["derive"] }
1617
log = { workspace = true }
1718
scale-info = { features = ["derive"], workspace = true }
@@ -237,3 +238,4 @@ try-runtime = [
237238
"sp-runtime/try-runtime",
238239
]
239240
rococo = []
241+
polkadot = []

runtime/src/bridge_config.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
//! With Polkadot Bridge Hub bridge configuration.
1+
#![cfg(feature = "rococo")]
2+
3+
//! With Rococo Bridge Hub bridge configuration.
24
35
use crate::{
46
xcm_config::{decode_bridge_message, XcmConfig},
@@ -25,7 +27,6 @@ use xcm_executor::XcmExecutor;
2527
pub const XCM_LANE: LegacyLaneId = LegacyLaneId([0, 0, 0, 0]);
2628

2729
parameter_types! {
28-
// TODO: (change to Polkadot - or make this `pub storage` for supporting Rococo and Polkadot)
2930
pub RococoGlobalConsensusNetwork: NetworkId = NetworkId::ByGenesis(ROCOCO_GENESIS_HASH);
3031
pub BridgedNetwork: NetworkId = RococoGlobalConsensusNetwork::get();
3132
pub RococoGlobalConsensusNetworkLocation: Location = Location::new(
@@ -41,8 +42,6 @@ parameter_types! {
4142
/// A name of parachains pallet at Pokadot.
4243
pub const AtRococoParasPalletName: &'static str = bp_rococo::PARAS_PALLET_NAME;
4344

44-
// /// Chain identifier of Polkadot Bridge Hub.
45-
// pub const BridgeHubPolkadotChainId: ChainId = bp_runtime::BRIDGE_HUB_POLKADOT_CHAIN_ID;
4645
/// A number of Polkadot Bridge Hub head digests that we keep in the storage.
4746
pub const BridgeHubRococoHeadsToKeep: u32 = 1024;
4847
/// A maximal size of Polkadot Bridge Hub head digest.
@@ -244,8 +243,8 @@ where
244243
.map_err(drop)
245244
.and_then(|payload| decode_bridge_message(payload).map(|(_, xcm)| xcm).map_err(drop))
246245
.and_then(|xcm| xcm.try_into().map_err(drop))
247-
// TODO: FAIL-CI Weight::MAX maybe change for something else, hard-coded or Weight::MAX/4...
248-
// TODO: (real weights) https://github.com/paritytech/polkadot-bulletin-chain/issues/22
246+
// TODO: FAIL-CI Weight::MAX maybe change for something else, hard-coded or
247+
// Weight::MAX/4... TODO: (real weights) https://github.com/paritytech/polkadot-bulletin-chain/issues/22
249248
.and_then(|xcm| XcmExecutor::<XcmConfig>::prepare(xcm, Weight::MAX).map_err(drop))
250249
.map(|weighed_xcm| weighed_xcm.weight_of())
251250
.unwrap_or(Weight::zero())
@@ -305,8 +304,8 @@ where
305304
}
306305
}
307306

308-
/// Export XCM messages to be relayed to the Polkadot Bridge Hub chain.
309-
pub type ToBridgeHubRococoHaulBlobExporter = HaulBlobExporter<
307+
/// Export XCM messages to be relayed to the Rococo Bridge Hub chain.
308+
pub type ToBridgeHaulBlobExporter = HaulBlobExporter<
310309
XcmBlobHauler<Runtime, WithBridgeHubRococoMessagesInstance>,
311310
RococoGlobalConsensusNetworkLocation,
312311
AlwaysV5,

runtime/src/genesis_config_presets.rs

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
use crate::{
2-
bridge_config::XCM_LANE, opaque::SessionKeys, AccountId, BabeConfig, BridgeRococoGrandpaConfig,
3-
BridgeRococoMessagesConfig, BridgeRococoParachainsConfig, RelayerSetConfig,
4-
RuntimeGenesisConfig, SessionConfig, Signature, SudoConfig, ValidatorSetConfig,
5-
BABE_GENESIS_EPOCH_CONFIG,
2+
opaque::SessionKeys, AccountId, BabeConfig, RelayerSetConfig, RuntimeGenesisConfig,
3+
SessionConfig, Signature, SudoConfig, ValidatorSetConfig, BABE_GENESIS_EPOCH_CONFIG,
64
};
5+
6+
#[cfg(feature = "polkadot")]
7+
use crate::{
8+
bridge_config::XCM_LANE, BridgePolkadotGrandpaConfig, BridgePolkadotMessagesConfig,
9+
BridgePolkadotParachainsConfig,
10+
};
11+
#[cfg(feature = "rococo")]
12+
use crate::{
13+
bridge_config::XCM_LANE, BridgeRococoGrandpaConfig, BridgeRococoMessagesConfig,
14+
BridgeRococoParachainsConfig,
15+
};
16+
717
use scale_info::prelude::format;
818
use sp_consensus_babe::AuthorityId as BabeId;
919
use sp_consensus_grandpa::AuthorityId as GrandpaId;
@@ -45,6 +55,7 @@ fn session_keys(babe: BabeId, grandpa: GrandpaId) -> SessionKeys {
4555
/// Configure initial storage state for FRAME modules.
4656
fn testnet_genesis(
4757
initial_authorities: Vec<(AccountId, BabeId, GrandpaId)>,
58+
bridges_pallet_owner: Option<AccountId>,
4859
root_key: AccountId,
4960
) -> serde_json::Value {
5061
let config = RuntimeGenesisConfig {
@@ -74,16 +85,35 @@ fn testnet_genesis(
7485
// would want to use separate keys for the relayers.
7586
initial_relayers: initial_authorities.into_iter().map(|x| x.0).collect::<Vec<_>>(),
7687
},
88+
#[cfg(feature = "rococo")]
7789
bridge_rococo_grandpa: BridgeRococoGrandpaConfig {
78-
owner: Some(root_key.clone()),
90+
owner: bridges_pallet_owner.clone(),
7991
..Default::default()
8092
},
93+
#[cfg(feature = "rococo")]
8194
bridge_rococo_parachains: BridgeRococoParachainsConfig {
82-
owner: Some(root_key.clone()),
95+
owner: bridges_pallet_owner.clone(),
8396
..Default::default()
8497
},
98+
#[cfg(feature = "rococo")]
8599
bridge_rococo_messages: BridgeRococoMessagesConfig {
86-
owner: Some(root_key),
100+
owner: bridges_pallet_owner,
101+
opened_lanes: vec![XCM_LANE],
102+
..Default::default()
103+
},
104+
#[cfg(feature = "polkadot")]
105+
bridge_polkadot_grandpa: BridgePolkadotGrandpaConfig {
106+
owner: bridges_pallet_owner.clone(),
107+
..Default::default()
108+
},
109+
#[cfg(feature = "polkadot")]
110+
bridge_polkadot_parachains: BridgePolkadotParachainsConfig {
111+
owner: bridges_pallet_owner.clone(),
112+
..Default::default()
113+
},
114+
#[cfg(feature = "polkadot")]
115+
bridge_polkadot_messages: BridgePolkadotMessagesConfig {
116+
owner: bridges_pallet_owner,
87117
opened_lanes: vec![XCM_LANE],
88118
..Default::default()
89119
},
@@ -99,6 +129,8 @@ pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
99129
sp_genesis_builder::DEV_RUNTIME_PRESET => testnet_genesis(
100130
// Initial PoA authorities
101131
vec![authority_keys_from_seed("Alice")],
132+
// Bridges pallet owner
133+
Some(get_account_id_from_seed::<sr25519::Public>("Alice")),
102134
// Sudo account
103135
get_account_id_from_seed::<sr25519::Public>("Alice"),
104136
),
@@ -110,14 +142,16 @@ pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
110142
authority_keys_from_seed("Bob"),
111143
authority_keys_from_seed("Bob//stash"),
112144
],
145+
// Bridges pallet owner
146+
Some(get_account_id_from_seed::<sr25519::Public>("Alice")),
113147
// Sudo account
114148
get_account_id_from_seed::<sr25519::Public>("Alice"),
115149
),
116150
_ => return None,
117151
};
118152
Some(
119153
serde_json::to_string(&patch)
120-
.expect("serialization to json is expected to work. qed.")
154+
.expect("serialization to JSON is expected to work. qed.")
121155
.into_bytes(),
122156
)
123157
}

0 commit comments

Comments
 (0)