Skip to content

Commit 12986bb

Browse files
JoshOrndorff4meta5crystalinCrystalin
authored
Bake in chain specs (paritytech#169)
* Initial sketch * Override relay spec for well-known para specs * Update existing spec generation scripts * Update specs/README.md Co-authored-by: Amar Singh <[email protected]> * 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 <[email protected]> Co-authored-by: crystalin <[email protected]> Co-authored-by: Crystalin <[email protected]>
1 parent 5e360a7 commit 12986bb

25 files changed

+261
-482
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -214,30 +214,9 @@ jobs:
214214

215215
####### Prepare and Deploy Docker images #######
216216

217-
generate-parachain-specs:
218-
runs-on: ubuntu-latest
219-
if: github.event_name == 'push'
220-
needs: build
221-
steps:
222-
- name: Checkout
223-
uses: actions/checkout@v2
224-
- uses: actions/download-artifact@v2
225-
with:
226-
name: moonbase-alphanet
227-
path: build/alphanet
228-
- name: Generate specs
229-
run: |
230-
chmod uog+x build/alphanet/moonbase-alphanet
231-
PARACHAIN_BINARY=build/alphanet/moonbase-alphanet scripts/generate-parachain-specs.sh
232-
- name: Upload parachain specs
233-
uses: actions/upload-artifact@v2
234-
with:
235-
name: moonbase-alphanet
236-
path: build/alphanet
237-
238217
docker-parachain:
239218
runs-on: ubuntu-latest
240-
needs: ["build", "generate-parachain-specs"]
219+
needs: ["build"]
241220
if: github.event_name == 'push'
242221
steps:
243222
- name: Checkout
@@ -381,7 +360,7 @@ jobs:
381360

382361
publish-draft-release:
383362
runs-on: ubuntu-latest
384-
needs: ["build", "generate-parachain-specs"]
363+
needs: ["build"]
385364
if: |
386365
github.event_name == 'push' &&
387366
startsWith(github.ref, 'refs/tags/v')
@@ -461,30 +440,3 @@ jobs:
461440
asset_path: build/alphanet/${{ matrix.runtime }}
462441
asset_name: ${{ matrix.runtime }}
463442
asset_content_type: application/octet-stream
464-
- name: Upload ${{ matrix.runtime }} specs plain
465-
uses: actions/upload-release-asset@v1
466-
env:
467-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
468-
with:
469-
upload_url: ${{ needs.publish-draft-release.outputs.asset_upload_url }}
470-
asset_path: build/alphanet/${{ matrix.runtime }}-specs-plain.json
471-
asset_name: ${{ matrix.runtime }}-specs-plain.json
472-
asset_content_type: application/json
473-
- name: Upload ${{ matrix.runtime }} specs raw
474-
uses: actions/upload-release-asset@v1
475-
env:
476-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
477-
with:
478-
upload_url: ${{ needs.publish-draft-release.outputs.asset_upload_url }}
479-
asset_path: build/alphanet/${{ matrix.runtime }}-specs-raw.json
480-
asset_name: ${{ matrix.runtime }}-specs-raw.json
481-
asset_content_type: application/json
482-
- name: Upload ${{ matrix.runtime }} genesis
483-
uses: actions/upload-release-asset@v1
484-
env:
485-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
486-
with:
487-
upload_url: ${{ needs.publish-draft-release.outputs.asset_upload_url }}
488-
asset_path: build/alphanet/${{ matrix.runtime }}-genesis.txt
489-
asset_name: ${{ matrix.runtime }}-genesis.txt
490-
asset_content_type: text/plain

node/parachain/src/chain_spec.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use cumulus_primitives::ParaId;
1818
use moonbeam_runtime::{
1919
AccountId, BalancesConfig, EVMConfig, EthereumChainIdConfig, EthereumConfig, GenesisConfig,
20-
ParachainInfoConfig, StakeConfig, SudoConfig, SystemConfig, WASM_BINARY,
20+
ParachainInfoConfig, StakeConfig, SudoConfig, SystemConfig, GLMR, WASM_BINARY,
2121
};
2222
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
2323
use sc_service::ChainType;
@@ -45,6 +45,7 @@ impl Extensions {
4545
}
4646
}
4747

48+
// This is the only hard-coded spec for the parachain. All deployments are based on it.
4849
pub fn get_chain_spec(para_id: ParaId) -> ChainSpec {
4950
ChainSpec::from_genesis(
5051
"Moonbase Parachain Local Testnet",
@@ -86,7 +87,7 @@ fn testnet_genesis(
8687
balances: endowed_accounts
8788
.iter()
8889
.cloned()
89-
.map(|k| (k, 1 << 60))
90+
.map(|k| (k, 1 << 80))
9091
.collect(),
9192
}),
9293
pallet_sudo: Some(SudoConfig { key: root_key }),
@@ -102,7 +103,7 @@ fn testnet_genesis(
102103
stakers: endowed_accounts
103104
.iter()
104105
.cloned()
105-
.map(|k| (k, None, 100_000))
106+
.map(|k| (k, None, 100_000 * GLMR))
106107
.collect(),
107108
}),
108109
}

node/parachain/src/command.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use log::info;
2323
use moonbeam_runtime::Block;
2424
use parity_scale_codec::Encode;
2525
use polkadot_parachain::primitives::AccountIdConversion;
26+
use polkadot_service::RococoChainSpec;
2627
use sc_cli::{
2728
ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, InitLoggerParams,
2829
KeystoreParams, NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli,
@@ -40,7 +41,10 @@ fn load_spec(
4041
para_id: ParaId,
4142
) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
4243
match id {
43-
"" => Ok(Box::new(chain_spec::get_chain_spec(para_id))),
44+
"alphanet" => Ok(Box::new(chain_spec::ChainSpec::from_json_bytes(
45+
&include_bytes!("../../../specs/MoonbaseAlphaV5.json")[..],
46+
)?)),
47+
"dev" | "development" | "" => Ok(Box::new(chain_spec::get_chain_spec(para_id))),
4448
path => Ok(Box::new(chain_spec::ChainSpec::from_json_file(
4549
path.into(),
4650
)?)),
@@ -117,7 +121,15 @@ impl SubstrateCli for RelayChainCli {
117121
}
118122

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

123135
fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {

node/standalone/src/chain_spec.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

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

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

@@ -78,6 +81,7 @@ pub fn development_config() -> Result<ChainSpec, String> {
7881
))
7982
}
8083

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

@@ -161,7 +165,7 @@ fn testnet_genesis(
161165
stakers: endowed_accounts
162166
.iter()
163167
.cloned()
164-
.map(|k| (k, None, 100_000))
168+
.map(|k| (k, None, 100_000 * GLMR))
165169
.collect(),
166170
}),
167171
}

node/standalone/src/command.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl SubstrateCli for Cli {
4848

4949
fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
5050
Ok(match id {
51-
"dev" => Box::new(chain_spec::development_config()?),
51+
"dev" | "development" => Box::new(chain_spec::development_config()?),
5252
"" | "local" => Box::new(chain_spec::local_testnet_config()?),
5353
path => Box::new(chain_spec::ChainSpec::from_json_file(
5454
std::path::PathBuf::from(path),

runtime/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ impl pallet_ethereum::Config for Runtime {
312312
type StateRoot = pallet_ethereum::IntermediateStateRoot;
313313
}
314314

315+
// 18 decimals
316+
pub const GLMR: Balance = 1_000_000_000_000_000_000;
317+
315318
parameter_types! {
316319
/// Moonbeam starts a new round every 2 minutes (20 * block_time)
317320
pub const BlocksPerRound: u32 = 20;
@@ -322,13 +325,13 @@ parameter_types! {
322325
/// Maximum 10 nominators per validator
323326
pub const MaxNominatorsPerValidator: usize = 10;
324327
/// Issue 49 new tokens as rewards to validators every 2 minutes (round)
325-
pub const IssuancePerRound: u128 = 49;
328+
pub const IssuancePerRound: u128 = 49 * GLMR;
326329
/// The maximum percent a validator can take off the top of its rewards is 50%
327330
pub const MaxFee: Perbill = Perbill::from_percent(50);
328331
/// Minimum stake required to be reserved to be a validator is 5
329-
pub const MinValidatorStk: u128 = 100_000;
332+
pub const MinValidatorStk: u128 = 100_000 * GLMR;
330333
/// Minimum stake required to be reserved to be a nominator is 5
331-
pub const MinNominatorStk: u128 = 5;
334+
pub const MinNominatorStk: u128 = 5 * GLMR;
332335
}
333336
impl stake::Config for Runtime {
334337
type Event = Event;

scripts/generate-parachain-specs.sh

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,19 @@
11
#!/bin/bash
22
source scripts/_init_var.sh
33

4-
$PARACHAIN_BINARY build-spec \
5-
--disable-default-bootnode \
6-
| grep '\"code\"' \
7-
| head -n1 > $PARACHAIN_SPEC_TMP
8-
echo $PARACHAIN_SPEC_TMP generated
9-
10-
echo "Using $PARACHAIN_SPEC_TEMPLATE..."
11-
sed -e "/\"<runtime_code>\"/{r $PARACHAIN_SPEC_TMP" -e 'd;}' $PARACHAIN_SPEC_TEMPLATE \
12-
> $PARACHAIN_SPEC_PLAIN
13-
echo $PARACHAIN_SPEC_PLAIN generated
14-
154
$PARACHAIN_BINARY build-spec \
165
--disable-default-bootnode \
176
--raw \
18-
--chain $PARACHAIN_SPEC_PLAIN \
197
> $PARACHAIN_SPEC_RAW
208
echo $PARACHAIN_SPEC_RAW generated
219

2210
$PARACHAIN_BINARY export-genesis-wasm \
23-
--chain $PARACHAIN_SPEC_PLAIN \
11+
--chain $PARACHAIN_SPEC_RAW \
2412
> $PARACHAIN_WASM;
2513
echo $PARACHAIN_WASM generated
2614

2715
$PARACHAIN_BINARY export-genesis-state \
2816
--parachain-id $PARACHAIN_ID \
29-
--chain $PARACHAIN_SPEC_PLAIN \
17+
--chain $PARACHAIN_SPEC_RAW \
3018
> $PARACHAIN_GENESIS;
3119
echo $PARACHAIN_GENESIS generated

scripts/generate-relay-specs.sh

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,16 @@ fi
99

1010
echo "Using Polkadot revision #${POLKADOT_VERSION}"
1111

12-
docker run -it purestake/moonbase-relay-testnet:$POLKADOT_VERSION \
13-
/usr/local/bin/polkadot \
14-
build-spec \
15-
-lerror \
16-
--disable-default-bootnode \
17-
--chain rococo-local \
18-
| grep '\"code\"' > $POLKADOT_SPEC_TMP
19-
echo $POLKADOT_SPEC_TMP generated
20-
21-
echo "Using $POLKADOT_SPEC_TEMPLATE..."
22-
sed -e "/\"<runtime_code>\"/{r $POLKADOT_SPEC_TMP" -e 'd;}' $POLKADOT_SPEC_TEMPLATE \
23-
> $POLKADOT_SPEC_PLAIN
24-
echo $POLKADOT_SPEC_PLAIN generated
25-
26-
2712
# "Chain does not have enough staking candidates to operate" is displayed when no
2813
# staker is given at genesis
2914

3015
docker run -it -v $(pwd)/build:/build purestake/moonbase-relay-testnet:$POLKADOT_VERSION \
3116
/usr/local/bin/polkadot \
3217
build-spec \
18+
--chain rococo-local \
3319
-lerror \
3420
--disable-default-bootnode \
3521
--raw \
36-
--chain /$POLKADOT_SPEC_PLAIN \
3722
| grep -v 'Chain does not have enough staking candidates to operate' \
3823
> $POLKADOT_SPEC_RAW
3924
echo $POLKADOT_SPEC_RAW generated

scripts/generate-test-specs.sh

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)