Skip to content

Commit

Permalink
Bake in chain specs (paritytech#169)
Browse files Browse the repository at this point in the history
* Initial sketch

* Override relay spec for well-known para specs

* Update existing spec generation scripts

* Update specs/README.md

Co-authored-by: Amar Singh <asinghchrony@protonmail.com>

* Prettier

* note

* Better naming

* cargo fmt

But actually, I don't like converting to and from String like this 
anyway.

* Clean tests readme

* Newlines at end of spec files

* line length

* cleaner way to associate a relay spec.

* Newer spec files. These are mocks

* oops import

* cargo fmt

* prettier spec

* Fix type

Basti confirmed I "should" use the rococo one here. He also mentioned it 
didn't really matter when using a raw spec.

* use specs for alphanet blue

* remove spec publishing from CI

* Fixes staking parameter to include 18 decimals

* fix previous formatting issue

* Forces ts target to 2020 for tests

Co-authored-by: Amar Singh <asinghchrony@protonmail.com>
Co-authored-by: crystalin <alan.sapede@gmail.com>
Co-authored-by: Crystalin <alan@purestake.com>
  • Loading branch information
4 people committed Jan 17, 2021
1 parent 5e360a7 commit 12986bb
Show file tree
Hide file tree
Showing 25 changed files with 261 additions and 482 deletions.
52 changes: 2 additions & 50 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,30 +214,9 @@ jobs:

####### Prepare and Deploy Docker images #######

generate-parachain-specs:
runs-on: ubuntu-latest
if: github.event_name == 'push'
needs: build
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
name: moonbase-alphanet
path: build/alphanet
- name: Generate specs
run: |
chmod uog+x build/alphanet/moonbase-alphanet
PARACHAIN_BINARY=build/alphanet/moonbase-alphanet scripts/generate-parachain-specs.sh
- name: Upload parachain specs
uses: actions/upload-artifact@v2
with:
name: moonbase-alphanet
path: build/alphanet

docker-parachain:
runs-on: ubuntu-latest
needs: ["build", "generate-parachain-specs"]
needs: ["build"]
if: github.event_name == 'push'
steps:
- name: Checkout
Expand Down Expand Up @@ -381,7 +360,7 @@ jobs:

publish-draft-release:
runs-on: ubuntu-latest
needs: ["build", "generate-parachain-specs"]
needs: ["build"]
if: |
github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags/v')
Expand Down Expand Up @@ -461,30 +440,3 @@ jobs:
asset_path: build/alphanet/${{ matrix.runtime }}
asset_name: ${{ matrix.runtime }}
asset_content_type: application/octet-stream
- name: Upload ${{ matrix.runtime }} specs plain
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.publish-draft-release.outputs.asset_upload_url }}
asset_path: build/alphanet/${{ matrix.runtime }}-specs-plain.json
asset_name: ${{ matrix.runtime }}-specs-plain.json
asset_content_type: application/json
- name: Upload ${{ matrix.runtime }} specs raw
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.publish-draft-release.outputs.asset_upload_url }}
asset_path: build/alphanet/${{ matrix.runtime }}-specs-raw.json
asset_name: ${{ matrix.runtime }}-specs-raw.json
asset_content_type: application/json
- name: Upload ${{ matrix.runtime }} genesis
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.publish-draft-release.outputs.asset_upload_url }}
asset_path: build/alphanet/${{ matrix.runtime }}-genesis.txt
asset_name: ${{ matrix.runtime }}-genesis.txt
asset_content_type: text/plain
7 changes: 4 additions & 3 deletions node/parachain/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use cumulus_primitives::ParaId;
use moonbeam_runtime::{
AccountId, BalancesConfig, EVMConfig, EthereumChainIdConfig, EthereumConfig, GenesisConfig,
ParachainInfoConfig, StakeConfig, SudoConfig, SystemConfig, WASM_BINARY,
ParachainInfoConfig, StakeConfig, SudoConfig, SystemConfig, GLMR, WASM_BINARY,
};
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::ChainType;
Expand Down Expand Up @@ -45,6 +45,7 @@ impl Extensions {
}
}

// This is the only hard-coded spec for the parachain. All deployments are based on it.
pub fn get_chain_spec(para_id: ParaId) -> ChainSpec {
ChainSpec::from_genesis(
"Moonbase Parachain Local Testnet",
Expand Down Expand Up @@ -86,7 +87,7 @@ fn testnet_genesis(
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, 1 << 60))
.map(|k| (k, 1 << 80))
.collect(),
}),
pallet_sudo: Some(SudoConfig { key: root_key }),
Expand All @@ -102,7 +103,7 @@ fn testnet_genesis(
stakers: endowed_accounts
.iter()
.cloned()
.map(|k| (k, None, 100_000))
.map(|k| (k, None, 100_000 * GLMR))
.collect(),
}),
}
Expand Down
16 changes: 14 additions & 2 deletions node/parachain/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use log::info;
use moonbeam_runtime::Block;
use parity_scale_codec::Encode;
use polkadot_parachain::primitives::AccountIdConversion;
use polkadot_service::RococoChainSpec;
use sc_cli::{
ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, InitLoggerParams,
KeystoreParams, NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli,
Expand All @@ -40,7 +41,10 @@ fn load_spec(
para_id: ParaId,
) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
match id {
"" => Ok(Box::new(chain_spec::get_chain_spec(para_id))),
"alphanet" => Ok(Box::new(chain_spec::ChainSpec::from_json_bytes(
&include_bytes!("../../../specs/MoonbaseAlphaV5.json")[..],
)?)),
"dev" | "development" | "" => Ok(Box::new(chain_spec::get_chain_spec(para_id))),
path => Ok(Box::new(chain_spec::ChainSpec::from_json_file(
path.into(),
)?)),
Expand Down Expand Up @@ -117,7 +121,15 @@ impl SubstrateCli for RelayChainCli {
}

fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id)
match id {
"moonbase_alpha_relay" => Ok(Box::new(RococoChainSpec::from_json_bytes(
&include_bytes!("../../../specs/MoonbaseAlphaV5-Relay.json")[..],
)?)),
// If we are not using a moonbeam-centric pre-baked relay spec, then fall back to the
// Polkadot service to interpret the id.
_ => polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter())
.load_spec(id),
}
}

fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
Expand Down
8 changes: 6 additions & 2 deletions node/standalone/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use moonbeam_runtime::{
AccountId, AuraConfig, BalancesConfig, EVMConfig, EthereumChainIdConfig, EthereumConfig,
GenesisConfig, GrandpaConfig, StakeConfig, SudoConfig, SystemConfig, WASM_BINARY,
GenesisConfig, GrandpaConfig, StakeConfig, SudoConfig, SystemConfig, GLMR, WASM_BINARY,
};
use sc_service::ChainType;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
Expand All @@ -43,6 +43,9 @@ pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
(get_from_seed::<AuraId>(s), get_from_seed::<GrandpaId>(s))
}

// The development config is useful for starting a single-node local network to test your runtime.
// This is not useful for testing ntworking or consensus.
// It is used in the typescript integration tests found in `/tests`.
pub fn development_config() -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or("Development wasm binary not available".to_string())?;

Expand Down Expand Up @@ -78,6 +81,7 @@ pub fn development_config() -> Result<ChainSpec, String> {
))
}

// The local testnet is useful for spinning up a two-node network.
pub fn local_testnet_config() -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or("Development wasm binary not available".to_string())?;

Expand Down Expand Up @@ -161,7 +165,7 @@ fn testnet_genesis(
stakers: endowed_accounts
.iter()
.cloned()
.map(|k| (k, None, 100_000))
.map(|k| (k, None, 100_000 * GLMR))
.collect(),
}),
}
Expand Down
2 changes: 1 addition & 1 deletion node/standalone/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl SubstrateCli for Cli {

fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match id {
"dev" => Box::new(chain_spec::development_config()?),
"dev" | "development" => Box::new(chain_spec::development_config()?),
"" | "local" => Box::new(chain_spec::local_testnet_config()?),
path => Box::new(chain_spec::ChainSpec::from_json_file(
std::path::PathBuf::from(path),
Expand Down
9 changes: 6 additions & 3 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ impl pallet_ethereum::Config for Runtime {
type StateRoot = pallet_ethereum::IntermediateStateRoot;
}

// 18 decimals
pub const GLMR: Balance = 1_000_000_000_000_000_000;

parameter_types! {
/// Moonbeam starts a new round every 2 minutes (20 * block_time)
pub const BlocksPerRound: u32 = 20;
Expand All @@ -322,13 +325,13 @@ parameter_types! {
/// Maximum 10 nominators per validator
pub const MaxNominatorsPerValidator: usize = 10;
/// Issue 49 new tokens as rewards to validators every 2 minutes (round)
pub const IssuancePerRound: u128 = 49;
pub const IssuancePerRound: u128 = 49 * GLMR;
/// The maximum percent a validator can take off the top of its rewards is 50%
pub const MaxFee: Perbill = Perbill::from_percent(50);
/// Minimum stake required to be reserved to be a validator is 5
pub const MinValidatorStk: u128 = 100_000;
pub const MinValidatorStk: u128 = 100_000 * GLMR;
/// Minimum stake required to be reserved to be a nominator is 5
pub const MinNominatorStk: u128 = 5;
pub const MinNominatorStk: u128 = 5 * GLMR;
}
impl stake::Config for Runtime {
type Event = Event;
Expand Down
16 changes: 2 additions & 14 deletions scripts/generate-parachain-specs.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
#!/bin/bash
source scripts/_init_var.sh

$PARACHAIN_BINARY build-spec \
--disable-default-bootnode \
| grep '\"code\"' \
| head -n1 > $PARACHAIN_SPEC_TMP
echo $PARACHAIN_SPEC_TMP generated

echo "Using $PARACHAIN_SPEC_TEMPLATE..."
sed -e "/\"<runtime_code>\"/{r $PARACHAIN_SPEC_TMP" -e 'd;}' $PARACHAIN_SPEC_TEMPLATE \
> $PARACHAIN_SPEC_PLAIN
echo $PARACHAIN_SPEC_PLAIN generated

$PARACHAIN_BINARY build-spec \
--disable-default-bootnode \
--raw \
--chain $PARACHAIN_SPEC_PLAIN \
> $PARACHAIN_SPEC_RAW
echo $PARACHAIN_SPEC_RAW generated

$PARACHAIN_BINARY export-genesis-wasm \
--chain $PARACHAIN_SPEC_PLAIN \
--chain $PARACHAIN_SPEC_RAW \
> $PARACHAIN_WASM;
echo $PARACHAIN_WASM generated

$PARACHAIN_BINARY export-genesis-state \
--parachain-id $PARACHAIN_ID \
--chain $PARACHAIN_SPEC_PLAIN \
--chain $PARACHAIN_SPEC_RAW \
> $PARACHAIN_GENESIS;
echo $PARACHAIN_GENESIS generated
17 changes: 1 addition & 16 deletions scripts/generate-relay-specs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,16 @@ fi

echo "Using Polkadot revision #${POLKADOT_VERSION}"

docker run -it purestake/moonbase-relay-testnet:$POLKADOT_VERSION \
/usr/local/bin/polkadot \
build-spec \
-lerror \
--disable-default-bootnode \
--chain rococo-local \
| grep '\"code\"' > $POLKADOT_SPEC_TMP
echo $POLKADOT_SPEC_TMP generated

echo "Using $POLKADOT_SPEC_TEMPLATE..."
sed -e "/\"<runtime_code>\"/{r $POLKADOT_SPEC_TMP" -e 'd;}' $POLKADOT_SPEC_TEMPLATE \
> $POLKADOT_SPEC_PLAIN
echo $POLKADOT_SPEC_PLAIN generated


# "Chain does not have enough staking candidates to operate" is displayed when no
# staker is given at genesis

docker run -it -v $(pwd)/build:/build purestake/moonbase-relay-testnet:$POLKADOT_VERSION \
/usr/local/bin/polkadot \
build-spec \
--chain rococo-local \
-lerror \
--disable-default-bootnode \
--raw \
--chain /$POLKADOT_SPEC_PLAIN \
| grep -v 'Chain does not have enough staking candidates to operate' \
> $POLKADOT_SPEC_RAW
echo $POLKADOT_SPEC_RAW generated
23 changes: 0 additions & 23 deletions scripts/generate-test-specs.sh

This file was deleted.

Loading

0 comments on commit 12986bb

Please sign in to comment.