Skip to content

Commit

Permalink
Prepare chainspec and client for Polkadot parachain (#989)
Browse files Browse the repository at this point in the history
* Adjust chainspecs and clients

* More adjustment in client,chainspec and runtime

* Bump runtime version and remove migrations

* Use DOT in Zeitgeist XCM integration tests

* Use Rococo in Battery Station XCM tests

* Bump battery station spec_version

* Update lib.rs
  • Loading branch information
sea212 authored Mar 13, 2023
1 parent fc6265b commit 9b3a865
Show file tree
Hide file tree
Showing 27 changed files with 108 additions and 122 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion integration-tests/package-lock.json

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

6 changes: 3 additions & 3 deletions node/res/bs_parachain.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
0
]
],
"protocolId": "battery_station_v2",
"protocolId": "battery_station_v3",
"properties": {
"ss58Format": 73,
"tokenDecimals": 10,
"tokenSymbol": "ZBS"
},
"parachain_id": 2050,
"relay_chain": "battery_station_relay_v3",
"parachain_id": 2101,
"relay_chain": "rococo",
"consensusEngine": null,
"codeSubstitutes": {},
"genesis": {
Expand Down
6 changes: 3 additions & 3 deletions node/res/zeitgeist_parachain.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
0
]
],
"protocolId": "zeitgeist",
"protocolId": "zeitgeist-polkadot",
"properties": {
"ss58Format": 73,
"tokenDecimals": 10,
"tokenSymbol": "ZTG"
},
"parachain_id": 2101,
"relay_chain": "kusama",
"parachain_id": 2092,
"relay_chain": "polkadot",
"consensusEngine": null,
"codeSubstitutes": {},
"genesis": {
Expand Down
1 change: 1 addition & 0 deletions node/src/chain_spec/battery_station.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ pub fn battery_station_staging_config() -> Result<BatteryStationChainSpec, Strin
crate::chain_spec::Extensions {
relay_chain: "rococo".into(),
parachain_id: BATTERY_STATION_PARACHAIN_ID,
bad_blocks: None,
},
#[cfg(not(feature = "parachain"))]
Default::default(),
Expand Down
1 change: 1 addition & 0 deletions node/src/chain_spec/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ pub fn dev_config() -> Result<BatteryStationChainSpec, String> {
crate::chain_spec::Extensions {
relay_chain: "rococo-dev".into(),
parachain_id: crate::BATTERY_STATION_PARACHAIN_ID,
bad_blocks: None,
},
#[cfg(not(feature = "parachain"))]
Default::default(),
Expand Down
2 changes: 2 additions & 0 deletions node/src/chain_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ pub struct Extensions {
pub parachain_id: u32,
/// The relay chain of the Parachain.
pub relay_chain: String,
/// Known bad block hashes.
pub bad_blocks: sc_client_api::BadBlocks<polkadot_primitives::v2::Block>,
}

#[cfg(feature = "parachain")]
Expand Down
9 changes: 5 additions & 4 deletions node/src/chain_spec/zeitgeist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use zeitgeist_primitives::constants::ztg::{LIQUIDITY_MINING, LIQUIDITY_MINING_PT
#[cfg(feature = "parachain")]
use {
super::{Extensions, DEFAULT_COLLATOR_INFLATION_INFO},
crate::KUSAMA_PARACHAIN_ID,
crate::POLKADOT_PARACHAIN_ID,
zeitgeist_runtime::{
CollatorDeposit, DefaultBlocksPerRound, DefaultCollatorCommission,
DefaultParachainBondReservePercent, EligibilityValue, MinCollatorStk, PolkadotXcmConfig,
Expand Down Expand Up @@ -138,7 +138,7 @@ pub fn zeitgeist_staging_config() -> Result<ZeitgeistChainSpec, String> {
generic_genesis(
additional_chain_spec_staging_zeitgeist(
#[cfg(feature = "parachain")]
KUSAMA_PARACHAIN_ID.into(),
POLKADOT_PARACHAIN_ID.into(),
),
endowed_accounts_staging_zeitgeist(),
wasm,
Expand All @@ -151,8 +151,9 @@ pub fn zeitgeist_staging_config() -> Result<ZeitgeistChainSpec, String> {
Some(token_properties("ZTG", SS58Prefix::get())),
#[cfg(feature = "parachain")]
crate::chain_spec::Extensions {
relay_chain: "kusama".into(),
parachain_id: KUSAMA_PARACHAIN_ID,
relay_chain: "polkadot".into(),
parachain_id: POLKADOT_PARACHAIN_ID,
bad_blocks: None,
},
#[cfg(not(feature = "parachain"))]
Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ fn none_command(cli: &Cli) -> sc_cli::Result<()> {
);

let parachain_id = cumulus_primitives_core::ParaId::from(
cli.parachain_id.or(parachain_id_extension).unwrap_or(super::KUSAMA_PARACHAIN_ID),
cli.parachain_id.or(parachain_id_extension).unwrap_or(super::POLKADOT_PARACHAIN_ID),
);

let parachain_account =
Expand Down
6 changes: 3 additions & 3 deletions node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ pub const ZEITGEIST_RUNTIME_NOT_AVAILABLE: &str = "Zeitgeist runtime is not avai

cfg_if::cfg_if!(
if #[cfg(feature = "parachain")] {
const KUSAMA_PARACHAIN_ID: u32 = 2101;
const BATTERY_STATION_PARACHAIN_ID: u32 = 2050;
const KUSAMA_BLOCK_DURATION: core::time::Duration = core::time::Duration::from_secs(6);
const POLKADOT_PARACHAIN_ID: u32 = 2092;
const BATTERY_STATION_PARACHAIN_ID: u32 = 2101;
const POLKADOT_BLOCK_DURATION: core::time::Duration = core::time::Duration::from_secs(6);
const SOFT_DEADLINE_PERCENT: sp_runtime::Percent = sp_runtime::Percent::from_percent(100);
}
);
Expand Down
4 changes: 2 additions & 2 deletions node/src/service/service_parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use crate::{
service::{AdditionalRuntimeApiCollection, RuntimeApiCollection},
KUSAMA_BLOCK_DURATION, SOFT_DEADLINE_PERCENT,
POLKADOT_BLOCK_DURATION, SOFT_DEADLINE_PERCENT,
};
use cumulus_client_cli::CollatorOptions;
use cumulus_client_consensus_common::ParachainConsensus;
Expand Down Expand Up @@ -346,7 +346,7 @@ where
Arc::new(move |hash, data| network.announce_block(hash, data))
};

let relay_chain_slot_duration = KUSAMA_BLOCK_DURATION;
let relay_chain_slot_duration = POLKADOT_BLOCK_DURATION;

if collator {
let parachain_consensus = build_consensus(
Expand Down
8 changes: 4 additions & 4 deletions runtime/battery-station/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ hex-literal = { default-features = false, optional = true, version = "0.3.4" }
log = { version = "0.4.17", default-features = false, optional = true }

# XCM
kusama-runtime = { branch = "moonbeam-polkadot-v0.9.29", default-features = false, git = "https://github.com/zeitgeistpm/polkadot", optional = true }
rococo-runtime = { branch = "moonbeam-polkadot-v0.9.29", default-features = false, git = "https://github.com/zeitgeistpm/polkadot", optional = true }
orml-asset-registry = { branch = "moonbeam-polkadot-v0.9.29", default-features = false, git = "https://github.com/zeitgeistpm/open-runtime-module-library", optional = true }
orml-unknown-tokens = { branch = "moonbeam-polkadot-v0.9.29", default-features = false, git = "https://github.com/zeitgeistpm/open-runtime-module-library", optional = true }
orml-xcm-support = { branch = "moonbeam-polkadot-v0.9.29", default-features = false, git = "https://github.com/zeitgeistpm/open-runtime-module-library", optional = true }
Expand Down Expand Up @@ -150,7 +150,7 @@ parachain = [

# XCM

"kusama-runtime",
"rococo-runtime",
"polkadot-primitives",
"polkadot-runtime-parachains",
"orml-asset-registry",
Expand All @@ -175,7 +175,7 @@ runtime-benchmarks = [
"frame-system-benchmarking",
"frame-system/runtime-benchmarks",
"hex-literal",
"kusama-runtime?/runtime-benchmarks",
"rococo-runtime?/runtime-benchmarks",
"orml-asset-registry?/runtime-benchmarks",
"orml-tokens/runtime-benchmarks",
"orml-benchmarking",
Expand Down Expand Up @@ -299,7 +299,7 @@ std = [

# XCM

"kusama-runtime?/std",
"rococo-runtime?/std",
"polkadot-primitives?/std",
"polkadot-runtime-parachains?/std",
"orml-asset-registry?/std",
Expand Down
10 changes: 5 additions & 5 deletions runtime/battery-station/src/integration_tests/xcm/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ pub(super) fn register_foreign_sibling(additional_meta: Option<CustomMetadata>)
}

pub(super) fn register_foreign_parent(additional_meta: Option<CustomMetadata>) {
// Register KSM as foreign asset in the sibling parachain
// Register roc as foreign asset in the sibling parachain
let meta: AssetMetadata<Balance, CustomMetadata> = AssetMetadata {
decimals: 12,
name: "Kusama".into(),
symbol: "KSM".into(),
existential_deposit: 10_000_000_000, // 0.01
name: "Rococo".into(),
symbol: "ROC".into(),
existential_deposit: 33_333_333, // 0.0033333333
location: Some(VersionedMultiLocation::V1(foreign_parent_multilocation())),
additional: additional_meta.unwrap_or_default(),
};
Expand All @@ -170,7 +170,7 @@ pub(super) fn ztg(amount: Balance) -> Balance {
}

#[inline]
pub(super) fn ksm(amount: Balance) -> Balance {
pub(super) fn roc(amount: Balance) -> Balance {
foreign(amount, 12)
}

Expand Down
20 changes: 10 additions & 10 deletions runtime/battery-station/src/integration_tests/xcm/test_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ use polkadot_primitives::v2::{BlockNumber, MAX_CODE_SIZE, MAX_POV_SIZE};
use polkadot_runtime_parachains::configuration::HostConfiguration;
use xcm_emulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain};

use super::setup::{ksm, ztg, ExtBuilder, ALICE, FOREIGN_PARENT_ID, PARA_ID_SIBLING};
use super::setup::{roc, ztg, ExtBuilder, ALICE, FOREIGN_PARENT_ID, PARA_ID_SIBLING};

decl_test_relay_chain! {
pub struct KusamaNet {
Runtime = kusama_runtime::Runtime,
XcmConfig = kusama_runtime::xcm_config::XcmConfig,
pub struct RococoNet {
Runtime = rococo_runtime::Runtime,
XcmConfig = rococo_runtime::xcm_config::XcmConfig,
new_ext = relay_ext(),
}
}
Expand All @@ -56,26 +56,26 @@ decl_test_parachain! {

decl_test_network! {
pub struct TestNet {
relay_chain = KusamaNet,
relay_chain = RococoNet,
parachains = vec![
// N.B: Ideally, we could use the defined para id constants but doing so
// fails with: "error: arbitrary expressions aren't allowed in patterns"

// Be sure to use `xcm_config::config::battery_station::ID`
(2050, Zeitgeist),
(2101, Zeitgeist),
// Be sure to use `PARA_ID_SIBLING`
(3000, Sibling),
],
}
}

pub(super) fn relay_ext() -> sp_io::TestExternalities {
use kusama_runtime::{Runtime, System};
use rococo_runtime::{Runtime, System};

let mut t = frame_system::GenesisConfig::default().build_storage::<Runtime>().unwrap();

pallet_balances::GenesisConfig::<Runtime> {
balances: vec![(AccountId::from(ALICE), ksm(2002))],
balances: vec![(AccountId::from(ALICE), roc(2002))],
}
.assimilate_storage(&mut t)
.unwrap();
Expand All @@ -101,8 +101,8 @@ pub(super) fn para_ext(parachain_id: u32) -> sp_io::TestExternalities {
ExtBuilder::default()
.set_balances(vec![
(AccountId::from(ALICE), CurrencyId::Ztg, ztg(10)),
(AccountId::from(ALICE), FOREIGN_PARENT_ID, ksm(10)),
(ZeitgeistTreasuryAccount::get(), FOREIGN_PARENT_ID, ksm(1)),
(AccountId::from(ALICE), FOREIGN_PARENT_ID, roc(10)),
(ZeitgeistTreasuryAccount::get(), FOREIGN_PARENT_ID, roc(1)),
])
.set_parachain_id(parachain_id)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
use crate::{
integration_tests::xcm::{
setup::{
ksm, register_foreign_parent, register_foreign_ztg, sibling_parachain_account,
roc, register_foreign_parent, register_foreign_ztg, sibling_parachain_account,
zeitgeist_parachain_account, ztg, ALICE, BOB, FOREIGN_PARENT_ID, FOREIGN_ZTG_ID,
PARA_ID_SIBLING,
},
test_net::{KusamaNet, Sibling, TestNet, Zeitgeist},
test_net::{RococoNet, Sibling, TestNet, Zeitgeist},
},
xcm_config::{config::battery_station, fees::default_per_second},
AssetRegistry, Balance, Balances, CurrencyId, Origin, Tokens, XTokens,
Expand Down Expand Up @@ -173,21 +173,21 @@ fn transfer_ztg_sibling_to_zeitgeist() {
}

#[test]
fn transfer_ksm_from_relay_chain() {
fn transfer_roc_from_relay_chain() {
TestNet::reset();

let transfer_amount: Balance = ksm(1);
let transfer_amount: Balance = roc(1);

Zeitgeist::execute_with(|| {
register_foreign_parent(None);
});

KusamaNet::execute_with(|| {
let initial_balance = kusama_runtime::Balances::free_balance(&ALICE.into());
RococoNet::execute_with(|| {
let initial_balance = rococo_runtime::Balances::free_balance(&ALICE.into());
assert!(initial_balance >= transfer_amount);

assert_ok!(kusama_runtime::XcmPallet::reserve_transfer_assets(
kusama_runtime::Origin::signed(ALICE.into()),
assert_ok!(rococo_runtime::XcmPallet::reserve_transfer_assets(
rococo_runtime::Origin::signed(ALICE.into()),
Box::new(Parachain(battery_station::ID).into().into()),
Box::new(Junction::AccountId32 { network: NetworkId::Any, id: BOB }.into().into()),
Box::new((Here, transfer_amount).into()),
Expand All @@ -198,17 +198,17 @@ fn transfer_ksm_from_relay_chain() {
Zeitgeist::execute_with(|| {
assert_eq!(
Tokens::free_balance(FOREIGN_PARENT_ID, &BOB.into()),
transfer_amount - ksm_fee()
transfer_amount - roc_fee()
);
});
}

#[test]
fn transfer_ksm_to_relay_chain() {
fn transfer_roc_to_relay_chain() {
TestNet::reset();

let transfer_amount: Balance = ksm(1);
transfer_ksm_from_relay_chain();
let transfer_amount: Balance = roc(1);
transfer_roc_from_relay_chain();

Zeitgeist::execute_with(|| {
let initial_balance = Tokens::free_balance(FOREIGN_PARENT_ID, &ALICE.into());
Expand All @@ -234,8 +234,8 @@ fn transfer_ksm_to_relay_chain() {
)
});

KusamaNet::execute_with(|| {
assert_eq!(kusama_runtime::Balances::free_balance(&BOB.into()), 999_988_476_752);
RococoNet::execute_with(|| {
assert_eq!(rococo_runtime::Balances::free_balance(&BOB.into()), 948_894_198_216);
});
}

Expand Down Expand Up @@ -318,7 +318,7 @@ fn transfer_ztg_to_sibling_with_custom_fee() {
#[test]
fn test_total_fee() {
assert_eq!(ztg_fee(), 92_696_000);
assert_eq!(ksm_fee(), 9_269_600_000);
assert_eq!(roc_fee(), 9_269_600_000);
}

#[inline]
Expand All @@ -331,9 +331,9 @@ fn fee(decimals: u32) -> Balance {
calc_fee(default_per_second(decimals))
}

// The fee associated with transferring KSM tokens
// The fee associated with transferring roc tokens
#[inline]
fn ksm_fee() -> Balance {
fn roc_fee() -> Balance {
fee(12)
}

Expand Down
Loading

0 comments on commit 9b3a865

Please sign in to comment.