Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime and Node refactor #150

Merged
merged 17 commits into from
Jun 2, 2024
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
wget https://github.com/xd009642/tarpaulin/releases/download/${{ env.TARPAULIN_VERSION }}/cargo-tarpaulin-x86_64-unknown-linux-musl.tar.gz
tar -zxvf cargo-tarpaulin-x86_64-unknown-linux-musl.tar.gz -C $HOME/.cargo/bin
cargo tarpaulin --workspace \
-e regionx-node regionx-runtime \
-e regionx-node regionx-rococo-runtime \
--exclude-files **/mock.rs **/weights/* **/weights.rs \
--out xml

Expand Down
33 changes: 19 additions & 14 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ ismp-testsuite = { git="https://github.com/polytope-labs/hyperbridge.git", branc
# Local
region-primitives = { path = "./primitives/region", default-features = false }
nonfungible-primitives = { path = "./primitives/nonfungible", default-features = false }
regionx-primitives = { path = "./runtime/primitives", default-features = false }
regionx-runtime = { path = "./runtime/regionx", default-features = false }
regionx-runtime-common = { path = "./runtime/common", default-features = false }
regionx-rococo-runtime = { path = "./runtime/regionx-rococo", default-features = false }
pallet-market = { path = "./pallets/market", default-features = false }
pallet-regions = { path = "./pallets/regions", default-features = false }
6 changes: 3 additions & 3 deletions e2e_tests/xc-transfer/asset-transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ async function run(nodeName: string, networkInfo: any, _jsArgs: any) {
assert(balance - BigInt(free) < TOLERANCE);
};

await assertRegionXBalance(alice.address, 10n ** 12n);
await assertRegionXBalance(alice.address, 0n);
await assertRococoBalance(alice.address, 10n ** 18n);

await transferRelayAssetToPara(3n * 10n ** 12n, 2000, rococoApi, alice);
await sleep(5 * 1000);

await assertRegionXBalance(alice.address, 4n * 10n ** 12n);
await assertRegionXBalance(alice.address, 3n * 10n ** 12n);
await assertRococoBalance(alice.address, 10n ** 18n - 3n * 10n ** 12n);

const regionXReserveTransfer = regionXApi.tx.polkadotXcm.limitedReserveTransferAssets(
Expand Down Expand Up @@ -92,7 +92,7 @@ async function run(nodeName: string, networkInfo: any, _jsArgs: any) {

await sleep(5 * 1000);

await assertRegionXBalance(alice.address, 3n * 10n ** 12n);
await assertRegionXBalance(alice.address, 2n * 10n ** 12n);
await assertRococoBalance(alice.address, 10n ** 18n - 3n * 10n ** 12n);
}

Expand Down
12 changes: 8 additions & 4 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ futures = { workspace = true }
serde_json = { workspace = true }

# Local
regionx-runtime = { workspace = true }
regionx-primitives = { workspace = true }
regionx-rococo-runtime = { workspace = true }
regionx-runtime-common = { workspace = true }

# Polytope Labs
pallet-ismp-runtime-api = { workspace = true }
pallet-ismp-rpc = { workspace = true }
ismp-parachain-inherent = { workspace = true }
ismp-parachain-runtime-api = { workspace = true }

# Substrate
frame-benchmarking = { workspace = true }
Expand All @@ -47,6 +48,8 @@ sc-tracing = { workspace = true }
sc-transaction-pool = { workspace = true }
sc-transaction-pool-api = { workspace = true }
sp-api = { workspace = true }
sp-transaction-pool = { workspace = true }
sp-session = { workspace = true }
sp-block-builder = { workspace = true }
sp-blockchain = { workspace = true }
sp-consensus-aura = { workspace = true }
Expand All @@ -72,6 +75,7 @@ cumulus-client-consensus-common = { workspace = true }
cumulus-client-consensus-proposer = { workspace = true }
cumulus-client-service = { workspace = true }
cumulus-client-parachain-inherent = { workspace = true }
cumulus-primitives-aura = { workspace = true }
cumulus-primitives-core = { workspace = true }
cumulus-primitives-parachain-inherent = { workspace = true }
cumulus-relay-chain-interface = { workspace = true }
Expand All @@ -83,10 +87,10 @@ substrate-build-script-utils = { workspace = true }
[features]
default = []
runtime-benchmarks = [
"regionx-runtime/runtime-benchmarks",
"regionx-rococo-runtime/runtime-benchmarks",
"polkadot-cli/runtime-benchmarks",
]
try-runtime = [
"try-runtime-cli/try-runtime",
"regionx-runtime/try-runtime"
"regionx-rococo-runtime/try-runtime"
]
65 changes: 65 additions & 0 deletions node/src/chain_spec/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// This file is part of RegionX.
//
// RegionX is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// RegionX is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with RegionX. If not, see <https://www.gnu.org/licenses/>.
use regionx_runtime_common::primitives::{AccountId, AuraId, Signature};
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use serde::{Deserialize, Serialize};
use sp_core::{Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};

pub mod regionx_rococo;

type AccountPublic = <Signature as Verify>::Signer;

/// Specialized `ChainSpec` for the normal parachain runtime.
pub type ChainSpec<T> = sc_service::GenericChainSpec<T, Extensions>;

/// The extensions for the [`ChainSpec`].
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
#[serde(deny_unknown_fields)]
pub struct Extensions {
/// The relay chain of the Parachain.
pub relay_chain: String,
/// The id of the Parachain.
pub para_id: u32,
}

impl Extensions {
/// Try to get the extension from the given `ChainSpec`.
pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> {
sc_chain_spec::get_extension(chain_spec.extensions())
}
}

/// Helper function to generate a crypto pair from seed
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
.expect("static values are valid; qed")
.public()
}

/// Generate collator keys from seed.
///
/// This function's return type must always match the session keys of the chain in tuple format.
pub fn get_collator_keys_from_seed(seed: &str) -> AuraId {
get_from_seed::<AuraId>(seed)
}

/// Helper function to generate an account ID from seed
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
{
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
}
72 changes: 15 additions & 57 deletions node/src/chain_spec.rs → node/src/chain_spec/regionx_rococo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,70 +13,26 @@
// You should have received a copy of the GNU General Public License
// along with RegionX. If not, see <https://www.gnu.org/licenses/>.

use crate::chain_spec::{
get_account_id_from_seed, get_collator_keys_from_seed, ChainSpec, Extensions,
};
use cumulus_primitives_core::ParaId;
use regionx_primitives::{AccountId, Signature};
use regionx_runtime::{AuraId, EXISTENTIAL_DEPOSIT};
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use regionx_rococo_runtime::EXISTENTIAL_DEPOSIT;
use regionx_runtime_common::primitives::{AccountId, AuraId};
use sc_service::ChainType;
use serde::{Deserialize, Serialize};
use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};

/// Specialized `ChainSpec` for the normal parachain runtime.
pub type ChainSpec<T> = sc_service::GenericChainSpec<T, Extensions>;
use sp_core::sr25519;

/// The default XCM version to set in genesis config.
const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION;

/// Helper function to generate a crypto pair from seed
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
.expect("static values are valid; qed")
.public()
}

/// The extensions for the [`ChainSpec`].
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
#[serde(deny_unknown_fields)]
pub struct Extensions {
/// The relay chain of the Parachain.
pub relay_chain: String,
/// The id of the Parachain.
pub para_id: u32,
}

impl Extensions {
/// Try to get the extension from the given `ChainSpec`.
pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> {
sc_chain_spec::get_extension(chain_spec.extensions())
}
}

type AccountPublic = <Signature as Verify>::Signer;

/// Generate collator keys from seed.
///
/// This function's return type must always match the session keys of the chain in tuple format.
pub fn get_collator_keys_from_seed(seed: &str) -> AuraId {
get_from_seed::<AuraId>(seed)
}

/// Helper function to generate an account ID from seed
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
{
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
}

/// Generate the session keys from individual elements.
///
/// The input must be a tuple of individual keys (a single arg for now since we have just one key).
pub fn session_keys(keys: AuraId) -> regionx_runtime::SessionKeys {
regionx_runtime::SessionKeys { aura: keys }
pub fn session_keys(keys: AuraId) -> regionx_rococo_runtime::SessionKeys {
regionx_rococo_runtime::SessionKeys { aura: keys }
}

pub fn development_config(id: u32) -> ChainSpec<regionx_runtime::RuntimeGenesisConfig> {
pub fn development_config(id: u32) -> ChainSpec<regionx_rococo_runtime::RuntimeGenesisConfig> {
// Give your base currency a unit name and decimal places
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "REGX".into());
Expand All @@ -85,11 +41,11 @@ pub fn development_config(id: u32) -> ChainSpec<regionx_runtime::RuntimeGenesisC
properties.insert("ss58Format".into(), 42.into());

ChainSpec::builder(
regionx_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
regionx_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
Extensions {
relay_chain: "rococo-local".into(),
// You MUST set this to the correct network!
para_id: 2000,
para_id: id,
},
)
.with_name("RegionX Development")
Expand Down Expand Up @@ -124,10 +80,12 @@ pub fn development_config(id: u32) -> ChainSpec<regionx_runtime::RuntimeGenesisC
get_account_id_from_seed::<sr25519::Public>("Alice"),
id.into(),
))
.with_protocol_id("regionx-dev")
.with_properties(properties)
.build()
}

pub fn local_testnet_config(id: u32) -> ChainSpec<regionx_runtime::RuntimeGenesisConfig> {
pub fn local_testnet_config(id: u32) -> ChainSpec<regionx_rococo_runtime::RuntimeGenesisConfig> {
// Give your base currency a unit name and decimal places
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "REGX".into());
Expand All @@ -136,7 +94,7 @@ pub fn local_testnet_config(id: u32) -> ChainSpec<regionx_runtime::RuntimeGenesi
properties.insert("ss58Format".into(), 42.into());

ChainSpec::builder(
regionx_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
regionx_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
Extensions {
relay_chain: "rococo-local".into(),
// You MUST set this to the correct network!
Expand Down
Loading
Loading