Skip to content

Commit

Permalink
Merge pull request #21 from PureStake/crystalin-update-substrate-rc5
Browse files Browse the repository at this point in the history
Updates frontier and substrate to rc5+2
  • Loading branch information
crystalin authored Jul 30, 2020
2 parents 2c1e8f1 + 6502812 commit 165d8e2
Show file tree
Hide file tree
Showing 11 changed files with 1,137 additions and 811 deletions.
767 changes: 453 additions & 314 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,3 @@ panic = 'unwind'

[patch.crates-io]
ethereum = { path = "vendor/ethereum" }
evm = { path = "vendor/frontier/vendor/evm" }
evm-core = { path = "vendor/frontier/vendor/evm/core" }
evm-gasometer = { path = "vendor/frontier/vendor/evm/gasometer" }
evm-runtime = { path = "vendor/frontier/vendor/evm/runtime" }
4 changes: 4 additions & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jsonrpc-core = "14.0.3"
sp-api = { version = "2.0.0-dev", path = "../vendor/frontier/vendor/substrate/primitives/api" }
sp-blockchain = { version = "2.0.0-dev", path = "../vendor/frontier/vendor/substrate/primitives/blockchain" }
sc-rpc-api = { version = "0.8.0-dev", path = "../vendor/frontier/vendor/substrate/client/rpc-api" }
sc-rpc = { version = "2.0.0-dev", path = "../vendor/frontier/vendor/substrate/client/rpc" }
substrate-frame-rpc-system = { version = "2.0.0-dev", path = "../vendor/frontier/vendor/substrate/utils/frame/rpc/system" }
pallet-transaction-payment-rpc = { version = "2.0.0-dev", path = "../vendor/frontier/vendor/substrate/frame/transaction-payment/rpc/" }
sc-cli = { version = "0.8.0-dev", path = "../vendor/frontier/vendor/substrate/client/cli" }
Expand All @@ -34,9 +35,12 @@ sp-transaction-pool = { version = "2.0.0-dev", path = "../vendor/frontier/vendor
sc-network = { version = "0.8.0-dev", path = "../vendor/frontier/vendor/substrate/client/network" }
sc-consensus-aura = { version = "0.8.0-dev", path = "../vendor/frontier/vendor/substrate/client/consensus/aura" }
sp-consensus-aura = { version = "0.8.0-dev", path = "../vendor/frontier/vendor/substrate/primitives/consensus/aura" }
sc-consensus-manual-seal = { path = "../vendor/frontier/vendor/substrate/client/consensus/manual-seal" }
sp-consensus = { version = "0.8.0-dev", path = "../vendor/frontier/vendor/substrate/primitives/consensus/common" }
sc-consensus = { version = "0.8.0-dev", path = "../vendor/frontier/vendor/substrate/client/consensus/common" }
sp-timestamp = { version = "2.0.0-dev", default-features = false, path = "../vendor/frontier/vendor/substrate/primitives/timestamp" }
evm = { version = "2.0.0-dev", package = "pallet-evm", path = "../vendor/frontier/vendor/substrate/frame/evm" }
ethereum = { version = "0.1.0", package = "pallet-ethereum", path = "../vendor/frontier/frame/ethereum" }
sc-finality-grandpa = { version = "0.8.0-dev", path = "../vendor/frontier/vendor/substrate/client/finality-grandpa" }
sp-finality-grandpa = { version = "2.0.0-dev", path = "../vendor/frontier/vendor/substrate/primitives/finality-grandpa" }
sc-client-api = { version = "2.0.0-dev", path = "../vendor/frontier/vendor/substrate/client/api" }
Expand Down
178 changes: 111 additions & 67 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
// This file is part of Frontier.

// Copyright (C) 2019-2020 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use sp_core::{Pair, Public, sr25519, H160, U256};
use moonbeam_runtime::{
AccountId, AuraConfig, BalancesConfig, EVMConfig, GenesisConfig, GrandpaConfig, Signature,
SudoConfig, SystemConfig, WASM_BINARY,
AccountId, AuraConfig, BalancesConfig, EVMConfig, EthereumConfig, GenesisConfig, GrandpaConfig,
SudoConfig, SystemConfig, WASM_BINARY, Signature
};
use sc_service::ChainType;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{sr25519, Pair, Public, H160, U256};
use sp_finality_grandpa::AuthorityId as GrandpaId;
use sp_runtime::traits::{IdentifyAccount, Verify};
use sp_runtime::traits::{Verify, IdentifyAccount};
use sc_service::ChainType;
use std::collections::BTreeMap;
use std::str::FromStr;
// Note this is the URL for the telemetry server
//const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";

// The URL for the telemetry server.
// const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";

/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;

/// Helper function to generate a crypto pair from seed
/// 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")
Expand All @@ -24,83 +42,111 @@ pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Pu

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

/// 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>,
/// 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()
}

/// Helper function to generate an authority key for Aura
/// Generate an Aura authority key.
pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
(get_from_seed::<AuraId>(s), get_from_seed::<GrandpaId>(s))
(
get_from_seed::<AuraId>(s),
get_from_seed::<GrandpaId>(s),
)
}

pub fn development_config() -> ChainSpec {
ChainSpec::from_genesis(
pub fn development_config() -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or("Development wasm binary not available".to_string())?;

Ok(ChainSpec::from_genesis(
// Name
"Development",
// ID
"dev",
ChainType::Development,
|| {
testnet_genesis(
vec![authority_keys_from_seed("Alice")],
move || testnet_genesis(
wasm_binary,
// Initial PoA authorities
vec![
authority_keys_from_seed("Alice"),
],
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
// Pre-funded accounts
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
],
true,
)
},
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
],
true,
),
// Bootnodes
vec![],
// Telemetry
None,
// Protocol ID
None,
// Properties
None,
// Extensions
None,
)
))
}

pub fn local_testnet_config() -> ChainSpec {
ChainSpec::from_genesis(
pub fn local_testnet_config() -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or("Development wasm binary not available".to_string())?;

Ok(ChainSpec::from_genesis(
// Name
"Local Testnet",
// ID
"local_testnet",
ChainType::Local,
|| {
testnet_genesis(
vec![
authority_keys_from_seed("Alice"),
authority_keys_from_seed("Bob"),
],
move || testnet_genesis(
wasm_binary,
// Initial PoA authorities
vec![
authority_keys_from_seed("Alice"),
authority_keys_from_seed("Bob"),
],
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
// Pre-funded accounts
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
],
true,
)
},
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
],
true,
),
// Bootnodes
vec![],
// Telemetry
None,
// Protocol ID
None,
// Properties
None,
// Extensions
None,
)
))
}

/// Configure initial storage state for FRAME modules.
fn testnet_genesis(
wasm_binary: &[u8],
initial_authorities: Vec<(AuraId, GrandpaId)>,
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
Expand All @@ -117,31 +163,29 @@ fn testnet_genesis(
code: vec![],
},
);

GenesisConfig {
system: Some(SystemConfig {
code: WASM_BINARY.to_vec(),
// Add Wasm runtime to storage.
code: wasm_binary.to_vec(),
changes_trie_config: Default::default(),
}),
balances: Some(BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, 1 << 60))
.collect(),
// Configure endowed accounts with initial balance of 1 << 60.
balances: endowed_accounts.iter().cloned().map(|k|(k, 1 << 60)).collect(),
}),
aura: Some(AuraConfig {
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),
}),
grandpa: Some(GrandpaConfig {
authorities: initial_authorities
.iter()
.map(|x| (x.1.clone(), 1))
.collect(),
authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(),
}),
sudo: Some(SudoConfig {
// Assign network admin rights.
key: root_key,
}),
sudo: Some(SudoConfig { key: root_key }),
evm: Some(EVMConfig {
accounts: evm_accounts,
}),
ethereum: Some(EthereumConfig {}),
}
}
15 changes: 14 additions & 1 deletion node/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
use sc_cli::{RunCmd, Subcommand};
use sc_cli::{Subcommand};
use structopt::StructOpt;


#[allow(missing_docs)]
#[derive(Debug, StructOpt)]
pub struct RunCmd {
#[allow(missing_docs)]
#[structopt(flatten)]
pub base: sc_cli::RunCmd,

/// Force using Kusama native runtime.
#[structopt(long = "manual-seal")]
pub manual_seal: bool,
}

#[derive(Debug, StructOpt)]
pub struct Cli {
#[structopt(subcommand)]
Expand Down
53 changes: 29 additions & 24 deletions node/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
use crate::chain_spec;
use crate::cli::Cli;
use crate::service;
use sc_cli::SubstrateCli;
use sc_cli::{SubstrateCli, RuntimeVersion, Role, ChainSpec};
use sc_service::ServiceParams;
use crate::service::new_full_params;

impl SubstrateCli for Cli {
fn impl_name() -> &'static str {
"Substrate Node"
fn impl_name() -> String {
"Substrate Node".into()
}

fn impl_version() -> &'static str {
env!("SUBSTRATE_CLI_IMPL_VERSION")
fn impl_version() -> String {
env!("SUBSTRATE_CLI_IMPL_VERSION").into()
}

fn description() -> &'static str {
env!("CARGO_PKG_DESCRIPTION")
fn description() -> String {
env!("CARGO_PKG_DESCRIPTION").into()
}

fn author() -> &'static str {
env!("CARGO_PKG_AUTHORS")
fn author() -> String {
env!("CARGO_PKG_AUTHORS").into()
}

fn support_url() -> &'static str {
"support.anonymous.an"
fn support_url() -> String {
"support.anonymous.an".into()
}

fn copyright_start_year() -> i32 {
2017
}

fn executable_name() -> &'static str {
env!("CARGO_PKG_NAME")
}

fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match id {
"dev" => Box::new(chain_spec::development_config()),
"" | "local" => Box::new(chain_spec::local_testnet_config()),
"dev" => 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),
)?),
})
}

fn native_runtime_version(_: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
&moonbeam_runtime::VERSION
}
}

/// Parse and run command line arguments
Expand All @@ -50,15 +52,18 @@ pub fn run() -> sc_cli::Result<()> {
match &cli.subcommand {
Some(subcommand) => {
let runner = cli.create_runner(subcommand)?;
runner.run_subcommand(subcommand, |config| Ok(new_full_start!(config).0))
runner.run_subcommand(subcommand, |config| {
let (ServiceParams { client, backend, task_manager, import_queue, .. }, ..)
= new_full_params(config, cli.run.manual_seal)?;
Ok((client, backend, import_queue, task_manager))
})
}
None => {
let runner = cli.create_runner(&cli.run)?;
runner.run_node(
service::new_light,
service::new_full,
moonbeam_runtime::VERSION,
)
let runner = cli.create_runner(&cli.run.base)?;
runner.run_node_until_exit(|config| match config.role {
Role::Light => service::new_light(config),
_ => service::new_full(config, cli.run.manual_seal),
})
}
}
}
Loading

0 comments on commit 165d8e2

Please sign in to comment.