Skip to content

Commit

Permalink
fix: polkadot v1.1.0 client (#1808)
Browse files Browse the repository at this point in the history
* fix: deprecate parachain CLI

* chore: cleanup deprecated chain specs

* fix: clippy
  • Loading branch information
wischli authored Apr 15, 2024
1 parent 83dc357 commit 399228a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 253 deletions.
20 changes: 13 additions & 7 deletions docs/DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,16 @@ It runs a [collator](https://wiki.polkadot.network/docs/learn-collator) node:
Similar to the relay chain, you can explore the parachain using the [polkadot.js (on localhost:11936)](https://polkadot.js.org/apps/?rpc=ws%3A%2F%2Flocalhost%3A11936#/explorer) client.
You will see the block production frozen until you connect it to the relay chain.

By default, the initialized parachain will have the id `2000`.
If you need more than one parachain or choose other chain specifications,
you can set `PARA_ID` or `PARA_CHAIN_SPEC`, example:
By default, the initialized parachain will have the id `2000`.
Please note that for ephemeral chains specs such as `development`, `centrifuge-local` or `altair-local`, the
parachain ID is currently hardcoded.
If you need to customize it, please open an issue and we will add such a feature.
If choose other chain specifications, you can set the `PARA_CHAIN_SPEC` env var, e.g.:
```bash
PARA_ID=2001 ./scripts/init.sh start-parachain
PARA_CHAIN_SPEC=development ./scripts/init.sh start-parachain
```
The different `PARA_CHAIN_SPEC` values can be found at [`src/command.rs`](src/command.rs) under the `load_spec()` function.
The different `PARA_CHAIN_SPEC` values can be found at [`src/command.rs`](src/command.rs) under the `load_spec()`
function.

3. Onboard the parachain
This step will have the targeted parachain onboarded in the relay chain. The parachain will NOT produce blocks until this step is completed successfully.
Expand Down Expand Up @@ -109,9 +112,12 @@ Lint the source code with `cargo fmt --all`. This excludes certain paths (define
See more [here](docs/runtime-upgrade.md).
## Generate new Spec and Parachain files
This script will take a valid chain-spec chain_id, a parachain_id and a flag to build new spec or not, and will output genesis spec (raw and plain), wasm and state files.
This script will take a valid chain-spec chain_id and a flag to build new spec or not, and will output genesis spec (raw
and plain), wasm and state files.
```shell
./scripts/export_parachain_files.sh charcoal-staging 10001 true
./scripts/export_parachain_files.sh demo true
```
Adapt parameters accordingly.
Expand Down
214 changes: 0 additions & 214 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,47 +141,6 @@ pub fn centrifuge_config() -> CentrifugeChainSpec {
.unwrap()
}

pub fn centrifuge_dev(para_id: ParaId) -> CentrifugeChainSpec {
let mut properties = Properties::new();
properties.insert("tokenSymbol".into(), "DCFG".into());
properties.insert("tokenDecimals".into(), currency_decimals::NATIVE.into());

CentrifugeChainSpec::from_genesis(
"Centrifuge Dev",
"centrifuge_dev",
ChainType::Live,
move || {
centrifuge_genesis(
vec![
(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_from_seed::<AuraId>("Alice"),
),
(
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_from_seed::<AuraId>("Bob"),
),
(
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_from_seed::<AuraId>("Charlie"),
),
],
endowed_accounts(),
endowed_evm_accounts(),
Some(100000000 * CFG),
para_id,
council_members_bootstrap(),
)
},
vec![],
None,
None,
None,
Some(properties),
development_extensions(para_id.into()),
)
}

pub fn centrifuge_local(para_id: ParaId) -> CentrifugeChainSpec {
let mut properties = Properties::new();
properties.insert("tokenSymbol".into(), "DCFG".into());
Expand Down Expand Up @@ -218,85 +177,13 @@ pub fn catalyst_config() -> CentrifugeChainSpec {
.unwrap()
}

pub fn catalyst_local(para_id: ParaId) -> CentrifugeChainSpec {
let mut properties = Properties::new();
properties.insert("tokenSymbol".into(), "NCFG".into());
properties.insert("tokenDecimals".into(), currency_decimals::NATIVE.into());

CentrifugeChainSpec::from_genesis(
"Catalyst Local",
"catalyst_local",
ChainType::Local,
move || {
centrifuge_genesis(
vec![(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_from_seed::<AuraId>("Alice"),
)],
endowed_accounts(),
endowed_evm_accounts(),
Some(10000000 * CFG),
para_id,
Default::default(),
)
},
vec![],
None,
None,
None,
Some(properties),
development_extensions(para_id.into()),
)
}

pub fn altair_config() -> AltairChainSpec {
AltairChainSpec::from_json_bytes(
&include_bytes!("../res/genesis/altair-genesis-spec-raw.json")[..],
)
.unwrap()
}

pub fn altair_dev(para_id: ParaId) -> AltairChainSpec {
let mut properties = Properties::new();
properties.insert("tokenSymbol".into(), "DAIR".into());
properties.insert("tokenDecimals".into(), currency_decimals::NATIVE.into());

AltairChainSpec::from_genesis(
"Altair Dev",
"altair_dev",
ChainType::Live,
move || {
altair_genesis(
vec![
(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_from_seed::<AuraId>("Alice"),
),
(
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_from_seed::<AuraId>("Bob"),
),
(
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_from_seed::<AuraId>("Charlie"),
),
],
endowed_accounts(),
endowed_evm_accounts(),
Some(100000000 * AIR),
para_id,
council_members_bootstrap(),
)
},
vec![],
None,
None,
None,
Some(properties),
development_extensions(para_id.into()),
)
}

pub fn altair_local(para_id: ParaId) -> AltairChainSpec {
let mut properties = Properties::new();
properties.insert("tokenSymbol".into(), "DAIR".into());
Expand Down Expand Up @@ -328,76 +215,6 @@ pub fn altair_local(para_id: ParaId) -> AltairChainSpec {
)
}

pub fn antares_config() -> AltairChainSpec {
AltairChainSpec::from_json_bytes(&include_bytes!("../res/antares-spec-raw.json")[..]).unwrap()
}

pub fn antares_local(para_id: ParaId) -> AltairChainSpec {
let mut properties = Properties::new();
properties.insert("tokenSymbol".into(), "NAIR".into());
properties.insert("tokenDecimals".into(), currency_decimals::NATIVE.into());

AltairChainSpec::from_genesis(
"Antares Local",
"antares_local",
ChainType::Local,
move || {
altair_genesis(
vec![(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_from_seed::<AuraId>("Alice"),
)],
endowed_accounts(),
endowed_evm_accounts(),
Some(10000000 * AIR),
para_id,
Default::default(),
)
},
vec![],
None,
None,
None,
Some(properties),
development_extensions(para_id.into()),
)
}

pub fn charcoal_config() -> AltairChainSpec {
AltairChainSpec::from_json_bytes(&include_bytes!("../res/charcoal-spec-raw.json")[..]).unwrap()
}

pub fn charcoal_local(para_id: ParaId) -> AltairChainSpec {
let mut properties = Properties::new();
properties.insert("tokenSymbol".into(), "CAIR".into());
properties.insert("tokenDecimals".into(), currency_decimals::NATIVE.into());

AltairChainSpec::from_genesis(
"Charcoal Local",
"charcoal_local",
ChainType::Local,
move || {
altair_genesis(
vec![(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_from_seed::<AuraId>("Alice"),
)],
endowed_accounts(),
endowed_evm_accounts(),
Some(10000000 * AIR),
para_id,
Default::default(),
)
},
vec![],
None,
None,
None,
Some(properties),
development_extensions(para_id.into()),
)
}

pub fn demo(para_id: ParaId) -> DevelopmentChainSpec {
let mut properties = Properties::new();
properties.insert("tokenSymbol".into(), "DEMO".into());
Expand Down Expand Up @@ -464,37 +281,6 @@ pub fn development(para_id: ParaId) -> DevelopmentChainSpec {
)
}

pub fn development_local(para_id: ParaId) -> DevelopmentChainSpec {
let mut properties = Properties::new();
properties.insert("tokenSymbol".into(), "DEVEL".into());
properties.insert("tokenDecimals".into(), currency_decimals::NATIVE.into());

DevelopmentChainSpec::from_genesis(
"Dev Local",
"devel_local",
ChainType::Local,
move || {
development_genesis(
get_account_id_from_seed::<sr25519::Public>("Alice"),
vec![(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_from_seed::<AuraId>("Alice"),
)],
endowed_accounts(),
endowed_evm_accounts(),
Some(10000000 * CFG),
para_id,
)
},
vec![],
None,
None,
None,
Some(properties),
development_extensions(para_id.into()),
)
}

fn demo_endowed_accounts() -> Vec<AccountId> {
vec![
//kANEUrMbi9xC16AfL5vSGwfvBVRoRdfWoQ8abPiXi5etFxpdP
Expand Down
31 changes: 9 additions & 22 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ use crate::{
service::{evm, AltairRuntimeExecutor, CentrifugeRuntimeExecutor, DevelopmentRuntimeExecutor},
};

pub const LOCAL_PARA_ID: ParaId = ParaId::new(2000u32);

enum ChainIdentity {
Altair,
Centrifuge,
Expand All @@ -44,11 +46,7 @@ impl IdentifyChain for dyn sc_service::ChainSpec {
fn identify(&self) -> ChainIdentity {
if self.id().starts_with("centrifuge") || self.id().starts_with("catalyst") {
ChainIdentity::Centrifuge
} else if self.id().starts_with("altair")
|| self.id().starts_with("charcoal")
|| self.id().starts_with("antares")
|| self.id().starts_with("algol")
{
} else if self.id().starts_with("altair") {

Check warning on line 49 in node/src/command.rs

View check run for this annotation

Codecov / codecov/patch

node/src/command.rs#L49

Added line #L49 was not covered by tests
ChainIdentity::Altair
} else {
ChainIdentity::Development
Expand All @@ -62,26 +60,15 @@ impl<T: sc_service::ChainSpec + 'static> IdentifyChain for T {
}
}

fn load_spec(
id: &str,
para_id: ParaId,
) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {

Check warning on line 63 in node/src/command.rs

View check run for this annotation

Codecov / codecov/patch

node/src/command.rs#L63

Added line #L63 was not covered by tests
match id {
"centrifuge" => Ok(Box::new(chain_spec::centrifuge_config())),
"centrifuge-dev" => Ok(Box::new(chain_spec::centrifuge_dev(para_id))),
"centrifuge-local" => Ok(Box::new(chain_spec::centrifuge_local(para_id))),
"centrifuge-local" => Ok(Box::new(chain_spec::centrifuge_local(LOCAL_PARA_ID))),

Check warning on line 66 in node/src/command.rs

View check run for this annotation

Codecov / codecov/patch

node/src/command.rs#L66

Added line #L66 was not covered by tests
"altair" => Ok(Box::new(chain_spec::altair_config())),
"altair-dev" => Ok(Box::new(chain_spec::altair_dev(para_id))),
"altair-local" => Ok(Box::new(chain_spec::altair_local(para_id))),
"altair-local" => Ok(Box::new(chain_spec::altair_local(LOCAL_PARA_ID))),

Check warning on line 68 in node/src/command.rs

View check run for this annotation

Codecov / codecov/patch

node/src/command.rs#L68

Added line #L68 was not covered by tests
"catalyst" => Ok(Box::new(chain_spec::catalyst_config())),
"catalyst-local" => Ok(Box::new(chain_spec::catalyst_local(para_id))),
"antares" => Ok(Box::new(chain_spec::antares_config())),
"antares-local" => Ok(Box::new(chain_spec::antares_local(para_id))),
"charcoal" => Ok(Box::new(chain_spec::charcoal_config())),
"charcoal-local" => Ok(Box::new(chain_spec::charcoal_local(para_id))),
"demo" => Ok(Box::new(chain_spec::demo(para_id))),
"development" => Ok(Box::new(chain_spec::development(para_id))),
"development-local" => Ok(Box::new(chain_spec::development_local(para_id))),
"demo" => Ok(Box::new(chain_spec::demo(LOCAL_PARA_ID))),
"development" => Ok(Box::new(chain_spec::development(LOCAL_PARA_ID))),

Check warning on line 71 in node/src/command.rs

View check run for this annotation

Codecov / codecov/patch

node/src/command.rs#L70-L71

Added lines #L70 - L71 were not covered by tests
"" => Err(String::from("No Chain-id provided")),

path => {
Expand Down Expand Up @@ -133,7 +120,7 @@ impl SubstrateCli for Cli {
}

fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
load_spec(id, self.parachain_id.unwrap_or(10001).into())
load_spec(id)

Check warning on line 123 in node/src/command.rs

View check run for this annotation

Codecov / codecov/patch

node/src/command.rs#L123

Added line #L123 was not covered by tests
}
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/check_benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ then
chain="development-local"
elif [[ $runtime == "centrifuge" ]];
then
chain="centrifuge-dev"
chain="centrifuge-local"
elif [[ $runtime == "altair" ]];
then
chain="altair-dev"
chain="altair-local"
else
echo "Unknown runtime. Aborting!"
exit 1;
Expand Down
11 changes: 5 additions & 6 deletions scripts/export_parachain_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
set -e

chain_name=$1
parachain_id=$2
should_build=$3
should_build=$2

if [[ $chain_name == "" || $parachain_id == "" ]]; then
echo "Chain Name or Parachain ID argument not provided"
if [[ $chain_name == "" ]]; then
echo "Chain Name argument not provided"
exit 1
fi

Expand All @@ -20,11 +19,11 @@ fi
if [[ $should_build == "true" ]]; then
echo "Building Spec for $chain_name"
$PWD/target/release/centrifuge-chain build-spec --chain $chain_name --disable-default-bootnode > node/res/$chain_name-spec.json
sed -i.bu "s/\"parachainId\": 10001/\"parachainId\": $parachain_id/g" node/res/$chain_name-spec.json
sed -i.bu "s/\"parachainId\": 2000/" node/res/$chain_name-spec.json
$PWD/target/release/centrifuge-chain build-spec --chain node/res/$chain_name-spec.json --disable-default-bootnode --raw > node/res/$chain_name-spec-raw.json
rm node/res/$chain_name-spec.json.bu
fi

echo "Exporting State & Wasm"
$PWD/target/release/centrifuge-chain export-genesis-state --chain node/res/$chain_name-spec-raw.json --parachain-id $parachain_id > $chain_name-genesis-state
$PWD/target/release/centrifuge-chain export-genesis-state --chain node/res/$chain_name-spec-raw.json > $chain_name-genesis-state
$PWD/target/release/centrifuge-chain export-genesis-wasm --chain node/res/$chain_name-spec-raw.json > $chain_name-genesis-wasm
Loading

0 comments on commit 399228a

Please sign in to comment.