Skip to content

Commit 493ad6b

Browse files
committed
Set get_preset for BridgeHubRococo
clippy clippy clippy
1 parent 2dc5e24 commit 493ad6b

8 files changed

Lines changed: 188 additions & 96 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bridges/modules/messages/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,9 @@ pub mod pallet {
561561
pub operating_mode: MessagesOperatingMode,
562562
/// Initial pallet owner.
563563
pub owner: Option<T::AccountId>,
564+
#[serde(skip)]
564565
/// Dummy marker.
565-
pub phantom: sp_std::marker::PhantomData<I>,
566+
pub _config: sp_std::marker::PhantomData<I>,
566567
}
567568

568569
#[pallet::genesis_build]

cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
156156
ROC * 1_000_000,
157157
1000.into(),
158158
),
159-
Err(_) | Ok(_) => return None,
159+
_ => return None,
160160
};
161161

162162
Some(

cumulus/parachains/runtimes/assets/asset-hub-westend/src/genesis_config_presets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
154154
WND * 1_000_000,
155155
1000.into(),
156156
),
157-
Err(_) | Ok(_) => return None,
157+
_ => return None,
158158
};
159159

160160
Some(

cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ scale-info = { features = [
2222
"derive",
2323
], workspace = true }
2424
serde = { optional = true, features = ["derive"], workspace = true, default-features = true }
25+
serde_json = { features = ["alloc"], workspace = true }
2526

2627
# Substrate
2728
frame-benchmarking = { optional = true, workspace = true }
@@ -192,6 +193,7 @@ std = [
192193
"rococo-runtime-constants/std",
193194
"scale-info/std",
194195
"serde",
196+
"serde_json/std",
195197
"snowbridge-beacon-primitives/std",
196198
"snowbridge-core/std",
197199
"snowbridge-outbound-queue-runtime-api/std",
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// Copyright (C) Parity Technologies (UK) Ltd.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
//! # Bridge Hub Rococo Runtime genesis config presets
17+
18+
use crate::*;
19+
use alloc::{vec, vec::Vec};
20+
use cumulus_primitives_core::ParaId;
21+
use parachains_common::{genesis_config_helpers::*, AccountId, AuraId};
22+
use sp_core::sr25519;
23+
use sp_genesis_builder::PresetId;
24+
use testnet_parachains_constants::rococo::xcm_version::SAFE_XCM_VERSION;
25+
26+
const BRIDGE_HUB_ROCOCO_ED: Balance = ExistentialDeposit::get();
27+
28+
fn bridge_hub_rococo_genesis(
29+
invulnerables: Vec<(AccountId, AuraId)>,
30+
endowed_accounts: Vec<AccountId>,
31+
id: ParaId,
32+
bridges_pallet_owner: Option<AccountId>,
33+
asset_hub_para_id: ParaId,
34+
) -> serde_json::Value {
35+
serde_json::json!({
36+
"balances": BalancesConfig {
37+
balances: endowed_accounts.iter().cloned().map(|k| (k, 1u128 << 60)).collect::<Vec<_>>(),
38+
},
39+
"parachainInfo": ParachainInfoConfig {
40+
parachain_id: id,
41+
..Default::default()
42+
},
43+
"collatorSelection": CollatorSelectionConfig {
44+
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
45+
candidacy_bond: BRIDGE_HUB_ROCOCO_ED * 16,
46+
..Default::default()
47+
},
48+
"session": SessionConfig {
49+
keys: invulnerables
50+
.into_iter()
51+
.map(|(acc, aura)| {
52+
(
53+
acc.clone(), // account id
54+
acc, // validator id
55+
SessionKeys { aura }, // session keys
56+
)
57+
})
58+
.collect(),
59+
..Default::default()
60+
},
61+
"polkadotXcm": PolkadotXcmConfig {
62+
safe_xcm_version: Some(SAFE_XCM_VERSION),
63+
..Default::default()
64+
},
65+
"bridgeWestendGrandpa": BridgeWestendGrandpaConfig {
66+
owner: bridges_pallet_owner.clone(),
67+
..Default::default()
68+
},
69+
"bridgeWestendMessages": BridgeWestendMessagesConfig {
70+
owner: bridges_pallet_owner.clone(),
71+
..Default::default()
72+
},
73+
"ethereumSystem": EthereumSystemConfig {
74+
para_id: id,
75+
asset_hub_para_id,
76+
..Default::default()
77+
}
78+
})
79+
}
80+
81+
/// Encapsulates names of predefined presets.
82+
mod preset_names {
83+
pub const PRESET_DEVELOPMENT: &str = "development";
84+
pub const PRESET_LOCAL: &str = "local";
85+
}
86+
87+
/// Provides the JSON representation of predefined genesis config for given `id`.
88+
pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<sp_std::vec::Vec<u8>> {
89+
use preset_names::*;
90+
let patch = match id.try_into() {
91+
Ok(PRESET_LOCAL) => bridge_hub_rococo_genesis(
92+
// initial collators.
93+
vec![
94+
(
95+
get_account_id_from_seed::<sr25519::Public>("Alice"),
96+
get_collator_keys_from_seed::<AuraId>("Alice"),
97+
),
98+
(
99+
get_account_id_from_seed::<sr25519::Public>("Bob"),
100+
get_collator_keys_from_seed::<AuraId>("Bob"),
101+
),
102+
],
103+
vec![
104+
get_account_id_from_seed::<sr25519::Public>("Alice"),
105+
get_account_id_from_seed::<sr25519::Public>("Bob"),
106+
get_account_id_from_seed::<sr25519::Public>("Charlie"),
107+
get_account_id_from_seed::<sr25519::Public>("Dave"),
108+
get_account_id_from_seed::<sr25519::Public>("Eve"),
109+
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
110+
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
111+
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
112+
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
113+
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
114+
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
115+
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
116+
],
117+
1013.into(),
118+
Some(get_account_id_from_seed::<sr25519::Public>("Bob")),
119+
rococo_runtime_constants::system_parachain::ASSET_HUB_ID.into(),
120+
),
121+
Ok(PRESET_DEVELOPMENT) => bridge_hub_rococo_genesis(
122+
// initial collators.
123+
vec![
124+
(
125+
get_account_id_from_seed::<sr25519::Public>("Alice"),
126+
get_collator_keys_from_seed::<AuraId>("Alice"),
127+
),
128+
(
129+
get_account_id_from_seed::<sr25519::Public>("Bob"),
130+
get_collator_keys_from_seed::<AuraId>("Bob"),
131+
),
132+
],
133+
vec![
134+
get_account_id_from_seed::<sr25519::Public>("Alice"),
135+
get_account_id_from_seed::<sr25519::Public>("Bob"),
136+
get_account_id_from_seed::<sr25519::Public>("Charlie"),
137+
get_account_id_from_seed::<sr25519::Public>("Dave"),
138+
get_account_id_from_seed::<sr25519::Public>("Eve"),
139+
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
140+
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
141+
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
142+
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
143+
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
144+
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
145+
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
146+
],
147+
1013.into(),
148+
Some(get_account_id_from_seed::<sr25519::Public>("Bob")),
149+
rococo_runtime_constants::system_parachain::ASSET_HUB_ID.into(),
150+
),
151+
_ => return None,
152+
};
153+
Some(
154+
serde_json::to_string(&patch)
155+
.expect("serialization to json is expected to work. qed.")
156+
.into_bytes(),
157+
)
158+
}
159+
160+
/// List of supported presets.
161+
pub fn preset_names() -> Vec<PresetId> {
162+
use preset_names::*;
163+
vec![PresetId::from(PRESET_DEVELOPMENT), PresetId::from(PRESET_LOCAL)]
164+
}

cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub mod bridge_common_config;
3232
pub mod bridge_to_bulletin_config;
3333
pub mod bridge_to_ethereum_config;
3434
pub mod bridge_to_westend_config;
35+
mod genesis_config_presets;
3536
mod weights;
3637
pub mod xcm_config;
3738

@@ -1569,11 +1570,11 @@ impl_runtime_apis! {
15691570
}
15701571

15711572
fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
1572-
get_preset::<RuntimeGenesisConfig>(id, |_| None)
1573+
get_preset::<RuntimeGenesisConfig>(id, &genesis_config_presets::get_preset)
15731574
}
15741575

15751576
fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
1576-
vec![]
1577+
genesis_config_presets::preset_names()
15771578
}
15781579
}
15791580
}

0 commit comments

Comments
 (0)