Skip to content

Commit

Permalink
Set get_preset for BridgeHubRococo
Browse files Browse the repository at this point in the history
clippy

clippy

clippy
  • Loading branch information
bkontur committed Aug 30, 2024
1 parent 522c47b commit 80475ff
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 100 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion bridges/modules/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,9 @@ pub mod pallet {
pub operating_mode: MessagesOperatingMode,
/// Initial pallet owner.
pub owner: Option<T::AccountId>,
#[serde(skip)]
/// Dummy marker.
pub phantom: sp_std::marker::PhantomData<I>,
pub _config: sp_std::marker::PhantomData<I>,
}

#[pallet::genesis_build]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,11 @@ pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<sp_std::vec::Vec<
.into_bytes(),
)
}

/// List of supported presets.
pub fn preset_names() -> sp_std::vec::Vec<sp_genesis_builder::PresetId> {
sp_std::vec![
sp_genesis_builder::PresetId::from("local_testnet"),
sp_genesis_builder::PresetId::from("development"),
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -1776,10 +1776,7 @@ impl_runtime_apis! {
}

fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
vec![
sp_genesis_builder::PresetId::from("local_testnet"),
sp_genesis_builder::PresetId::from("development"),
]
genesis_config_presets::preset_names()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ scale-info = { features = [
"derive",
], workspace = true }
serde = { optional = true, features = ["derive"], workspace = true, default-features = true }
serde_json = { features = ["alloc"], workspace = true }

# Substrate
frame-benchmarking = { optional = true, workspace = true }
Expand Down Expand Up @@ -192,6 +193,7 @@ std = [
"rococo-runtime-constants/std",
"scale-info/std",
"serde",
"serde_json/std",
"snowbridge-beacon-primitives/std",
"snowbridge-core/std",
"snowbridge-outbound-queue-runtime-api/std",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Genesis configs presets for the BridgeHubRococo runtime

use crate::*;
use sp_core::sr25519;
use sp_std::vec::Vec;
use testnet_parachains_constants::genesis_presets::*;

const BRIDGE_HUB_ROCOCO_ED: Balance = ExistentialDeposit::get();

/// Default genesis pallet configurations for BridgeHubRococo
pub fn bridge_hub_rococo_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
id: ParaId,
bridges_pallet_owner: Option<AccountId>,
asset_hub_para_id: ParaId,
) -> serde_json::Value {
serde_json::json!({
"balances": BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k| (k, 1u128 << 60)).collect::<Vec<_>>(),
},
"parachainInfo": ParachainInfoConfig {
parachain_id: id,
..Default::default()
},
"collatorSelection": CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: BRIDGE_HUB_ROCOCO_ED * 16,
..Default::default()
},
"session": SessionConfig {
keys: invulnerables
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
SessionKeys { aura }, // session keys
)
})
.collect(),
..Default::default()
},
"polkadotXcm": PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
..Default::default()
},
"bridgeWestendGrandpa": BridgeWestendGrandpaConfig {
owner: bridges_pallet_owner.clone(),
..Default::default()
},
"bridgeWestendMessages": BridgeWestendMessagesConfig {
owner: bridges_pallet_owner.clone(),
..Default::default()
},
"ethereumSystem": EthereumSystemConfig {
para_id: id,
asset_hub_para_id,
..Default::default()
}
})
}

/// Default genesis setup for `local_testnet` preset id.
pub fn bridge_hub_rococo_local_testnet_genesis(
para_id: ParaId,
bridges_pallet_owner: Option<AccountId>,
asset_hub_para_id: ParaId,
) -> serde_json::Value {
bridge_hub_rococo_genesis(
test_invulnerables(),
testnet_accounts(),
para_id,
bridges_pallet_owner,
asset_hub_para_id,
)
}

/// Default genesis setup for `development` preset id.
pub fn bridge_hub_rococo_development_genesis(
para_id: ParaId,
bridges_pallet_owner: Option<AccountId>,
asset_hub_para_id: ParaId,
) -> serde_json::Value {
bridge_hub_rococo_genesis(
test_invulnerables(),
testnet_accounts(),
para_id,
bridges_pallet_owner,
asset_hub_para_id,
)
}

/// Provides the JSON representation of predefined genesis config for given `id`.
pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<sp_std::vec::Vec<u8>> {
let patch = match id.try_into() {
Ok("development") => bridge_hub_rococo_development_genesis(
1013.into(),
Some(get_account_id_from_seed::<sr25519::Public>("Bob")),
rococo_runtime_constants::system_parachain::ASSET_HUB_ID.into(),
),
Ok("local_testnet") => bridge_hub_rococo_local_testnet_genesis(
1013.into(),
Some(get_account_id_from_seed::<sr25519::Public>("Bob")),
rococo_runtime_constants::system_parachain::ASSET_HUB_ID.into(),
),
_ => return None,
};
Some(
serde_json::to_string(&patch)
.expect("serialization to json is expected to work. qed.")
.into_bytes(),
)
}

/// List of supported presets.
pub fn preset_names() -> sp_std::vec::Vec<sp_genesis_builder::PresetId> {
sp_std::vec![
sp_genesis_builder::PresetId::from("local_testnet"),
sp_genesis_builder::PresetId::from("development"),
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub mod bridge_common_config;
pub mod bridge_to_bulletin_config;
pub mod bridge_to_ethereum_config;
pub mod bridge_to_westend_config;
// Genesis preset configurations.
pub mod genesis_config_presets;
mod weights;
pub mod xcm_config;

Expand Down Expand Up @@ -1569,11 +1571,11 @@ impl_runtime_apis! {
}

fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
get_preset::<RuntimeGenesisConfig>(id, |_| None)
get_preset::<RuntimeGenesisConfig>(id, &genesis_config_presets::get_preset)
}

fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
vec![]
genesis_config_presets::preset_names()
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

use crate::chain_spec::{Extensions, GenericChainSpec};
use asset_hub_rococo_runtime::genesis_config_presets::{
asset_hub_rococo_development_genesis, asset_hub_rococo_genesis,
asset_hub_rococo_local_testnet_genesis,
Expand All @@ -23,7 +24,7 @@ use asset_hub_westend_runtime::genesis_config_presets::{
asset_hub_westend_local_testnet_genesis,
};
use hex_literal::hex;
use parachains_common::{Balance as AssetHubBalance};
use parachains_common::Balance as AssetHubBalance;
use polkadot_parachain_lib::chain_spec::{Extensions, GenericChainSpec};
use sc_service::ChainType;
use sp_core::crypto::UncheckedInto;
Expand All @@ -35,16 +36,17 @@ pub fn asset_hub_westend_development_config() -> GenericChainSpec {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "WND".into());
properties.insert("tokenDecimals".into(), 12.into());
let para_id = 1000;

GenericChainSpec::builder(
asset_hub_westend_runtime::WASM_BINARY
.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: "westend".into(), para_id: 1000 },
Extensions { relay_chain: "westend".into(), para_id },
)
.with_name("Westend Asset Hub Development")
.with_id("asset-hub-westend-dev")
.with_chain_type(ChainType::Local)
.with_genesis_config_patch(asset_hub_westend_development_genesis(1000.into()))
.with_genesis_config_patch(asset_hub_westend_development_genesis(para_id.into()))
.with_properties(properties)
.build()
}
Expand All @@ -53,16 +55,17 @@ pub fn asset_hub_westend_local_config() -> GenericChainSpec {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "WND".into());
properties.insert("tokenDecimals".into(), 12.into());
let para_id = 1000;

GenericChainSpec::builder(
asset_hub_westend_runtime::WASM_BINARY
.expect("WASM binary was not built, please build it!"),
Extensions { relay_chain: "westend-local".into(), para_id: 1000 },
Extensions { relay_chain: "westend-local".into(), para_id },
)
.with_name("Westend Asset Hub Local")
.with_id("asset-hub-westend-local")
.with_chain_type(ChainType::Local)
.with_genesis_config_patch(asset_hub_westend_local_testnet_genesis(1000))
.with_genesis_config_patch(asset_hub_westend_local_testnet_genesis(para_id.into()))
.with_properties(properties)
.build()
}
Expand Down
Loading

0 comments on commit 80475ff

Please sign in to comment.