Skip to content

Commit

Permalink
Stafi node
Browse files Browse the repository at this point in the history
  • Loading branch information
Tore19 committed Nov 21, 2019
1 parent fefe3a6 commit 08d05d7
Show file tree
Hide file tree
Showing 18 changed files with 2,193 additions and 42 deletions.
12 changes: 6 additions & 6 deletions node/cli/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

//! Substrate Node CLI
//! Stafi Node CLI
#![warn(missing_docs)]

Expand Down Expand Up @@ -45,13 +45,13 @@ impl substrate_cli::IntoExit for Exit {

fn main() -> Result<(), substrate_cli::error::Error> {
let version = VersionInfo {
name: "Substrate Node",
name: "Stafi Node",
commit: env!("VERGEN_SHA_SHORT"),
version: env!("CARGO_PKG_VERSION"),
executable_name: "substrate",
author: "Parity Technologies <admin@parity.io>",
description: "Generic substrate node",
support_url: "https://github.com/paritytech/substrate/issues/new",
executable_name: "stafi",
author: "Stafi Protocol <technical@stafi.com>",
description: "Generic stafi node",
support_url: "https://github.com/stafiprotocol/stafi/issues/new",
};

node_cli::run(std::env::args(), Exit, version)
Expand Down
2 changes: 1 addition & 1 deletion node/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ fn build_completion(shell: &Shell) {

fs::create_dir(&path).ok();

CoreParams::<NoCustom, NoCustom>::clap().gen_completions("substrate-node", *shell, &path);
CoreParams::<NoCustom, NoCustom>::clap().gen_completions("stafi-node", *shell, &path);
}
21 changes: 12 additions & 9 deletions node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Stafi. If not, see <http://www.gnu.org/licenses/>

use chain_spec::ChainSpecExtension;
use primitives::{Pair, Public, crypto::UncheckedInto, sr25519};
use primitives::{Pair, Public, sr25519};
use serde::{Serialize, Deserialize};
use node_runtime::{
AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, ContractsConfig, CouncilConfig, DemocracyConfig,
Expand All @@ -25,7 +25,6 @@ use node_runtime::{
use node_runtime::Block;
use node_primitives::{constants::currency::*, ChainType};
use substrate_service;
use hex_literal::hex;
use substrate_telemetry::TelemetryEndpoints;
use grandpa_primitives::{AuthorityId as GrandpaId};
use babe_primitives::{AuthorityId as BabeId};
Expand All @@ -41,7 +40,7 @@ type AccountPublic = <Signature as Verify>::Signer;

const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";

const DEFAULT_PROTOCOL_ID: &str = "sfi";
const DEFAULT_PROTOCOL_ID: &str = "fis";

/// Node `ChainSpec` extensions.
///
Expand All @@ -59,6 +58,7 @@ pub type ChainSpec = substrate_service::ChainSpec<
Extensions,
>;

/// Stafi generator
pub fn stafi_config() -> Result<ChainSpec, String> {
ChainSpec::from_json_bytes(&include_bytes!("../../../testnets/v0.1.0/stafi.json")[..])
}
Expand All @@ -72,6 +72,7 @@ fn session_keys(
SessionKeys { grandpa, babe, im_online, authority_discovery }
}

/// Stafi testnet generator
pub fn stafi_testnet_config_gensis() -> GenesisConfig {
let initial_authorities: Vec<(AccountId, AccountId, GrandpaId, BabeId, ImOnlineId, AuthorityDiscoveryId)> = get_vals();
let root_key = get_root_key();
Expand All @@ -81,7 +82,8 @@ pub fn stafi_testnet_config_gensis() -> GenesisConfig {
testnet_genesis(
initial_authorities,
root_key,
Some(endowed_accounts)
Some(endowed_accounts),
false
)
}

Expand Down Expand Up @@ -137,9 +139,8 @@ pub fn testnet_genesis(
initial_authorities: Vec<(AccountId, AccountId, GrandpaId, BabeId, ImOnlineId, AuthorityDiscoveryId)>,
root_key: AccountId,
endowed_accounts: Option<Vec<AccountId>>,
enable_println: bool,
) -> GenesisConfig {
let enable_println: bool = false;

let endowed_accounts: Vec<AccountId> = endowed_accounts.unwrap_or_else(|| {
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
Expand Down Expand Up @@ -247,7 +248,8 @@ fn development_config_genesis() -> GenesisConfig {
get_authority_keys_from_seed("Alice"),
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
None
None,
true
)
}

Expand All @@ -259,7 +261,7 @@ pub fn development_config() -> ChainSpec {
development_config_genesis,
vec![],
None,
Some(DEFAULT_PROTOCOL_ID),
None,
None,
Default::default(),
)
Expand All @@ -272,7 +274,8 @@ fn local_testnet_genesis() -> GenesisConfig {
get_authority_keys_from_seed("Bob"),
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
None
None,
false
)
}

Expand Down
4 changes: 2 additions & 2 deletions node/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ pub fn run<I, T, E>(args: I, exit: E, version: substrate_cli::VersionInfo) -> er
{
type Config<A, B> = Configuration<(), A, B>;

match parse_and_prepare::<CustomSubcommands, NoCustom, _>(&version, "substrate-node", args) {
match parse_and_prepare::<CustomSubcommands, NoCustom, _>(&version, "stafi-node", args) {
ParseAndPrepare::Run(cmd) => cmd.run(load_spec, exit,
|exit, _cli_args, _custom_args, config: Config<_, _>| {
info!("{}", version.name);
info!(" version {}", config.full_version());
info!(" by Parity Technologies, 2017-2019");
info!(" by Stafi Protocol, 2018-2019");
info!("Chain specification: {}", config.chain_spec.name());
info!("Node name: {}", config.name);
info!("Roles: {}", display_role(&config));
Expand Down
2 changes: 1 addition & 1 deletion node/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ fn load_spec(id: &str) -> Result<Option<chain_spec::ChainSpec>, String> {
Some(spec) => Some(spec.load()?),
None => None,
})
}
}
4 changes: 2 additions & 2 deletions node/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,11 +1017,11 @@ mod tests {

#[test]
fn transaction_fee_is_correct_ultimate() {
// This uses the exact values of substrate-node.
// This uses the exact values of stafi-node.
//
// weight of transfer call as of now: 1_000_000
// if weight of the cheapest weight would be 10^7, this would be 10^9, which is:
// - 1 MILLICENTS in substrate node.
// - 1 MILLICENTS in stafi node.
// - 1 milli-dot based on current polkadot runtime.
// (this baed on assigning 0.1 CENT to the cheapest tx with `weight = 100`)
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, (map![
Expand Down
19 changes: 7 additions & 12 deletions node/runtime/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@ use wasm_builder_runner::{build_current_project_with_rustflags, WasmBuilderSourc

fn main() {
build_current_project_with_rustflags(
"wasm_binary.rs",
WasmBuilderSource::Crates("1.0.4"),
"wasm_binary.rs",
WasmBuilderSource::CratesOrPath {
path: "../../utils/wasm-builder",
version: "1.0.8",
},
// This instructs LLD to export __heap_base as a global variable, which is used by the
// external memory allocator.
"-Clink-arg=--export=__heap_base",
);
// build_current_project_with_rustflags(
// "wasm_binary.rs",
// WasmBuilderSource::CratesOrPath {
// path: "../../core/utils/wasm-builder",
// version: "1.0.7",
// },
// // This instructs LLD to export __heap_base as a global variable, which is used by the
// // external memory allocator.
// "-Clink-arg=--export=__heap_base",
// );
}
2 changes: 1 addition & 1 deletion node/runtime/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct LinearWeightToFee<C>(rstd::marker::PhantomData<C>);

impl<C: Get<Balance>> Convert<Weight, Balance> for LinearWeightToFee<C> {
fn convert(w: Weight) -> Balance {
// substrate-node a weight of 10_000 (smallest non-zero weight) to be mapped to 10^7 units of
// stafi-node a weight of 10_000 (smallest non-zero weight) to be mapped to 10^7 units of
// fees, hence:
let coefficient = C::get();
Balance::from(w).saturating_mul(coefficient)
Expand Down
8 changes: 0 additions & 8 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,6 @@ impl authorship::Trait for Runtime {
type EventHandler = (Staking, ImOnline);
}

type SessionHandlers = (Grandpa, Babe, ImOnline, AuthorityDiscovery, Stafifund);


impl_opaque_keys! {
pub struct SessionKeys {
pub grandpa: Grandpa,
Expand All @@ -225,11 +222,6 @@ impl_opaque_keys! {
}
}

// NOTE: `SessionHandler` and `SessionKeys` are co-dependent: One key will be used for each handler.
// The number and order of items in `SessionHandler` *MUST* be the same number and order of keys in
// `SessionKeys`.
// TODO: Introduce some structure to tie these together to make it a bit less of a footgun. This
// should be easy, since OneSessionHandler trait provides the `Key` as an associated type. #2858
parameter_types! {
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(17);
}
Expand Down
7 changes: 7 additions & 0 deletions utils/build-script-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "substrate-build-script-utils"
version = "2.0.0"
authors = ["Stafi Protocol <technical@stafi.com>"]
edition = "2018"

[dependencies]
44 changes: 44 additions & 0 deletions utils/build-script-utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.

// Substrate 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.

// Substrate 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 Substrate. If not, see <http://www.gnu.org/licenses/>.

//! Crate with utility functions for `build.rs` scripts.
use std::{env, path::PathBuf};

/// Make sure the calling `build.rs` script is rerun when `.git/HEAD` changed.
///
/// The file is searched from the `CARGO_MANIFEST_DIR` upwards. If the file can not be found,
/// a warning is generated.
pub fn rerun_if_git_head_changed() {
let mut manifest_dir = PathBuf::from(
env::var("CARGO_MANIFEST_DIR").expect("`CARGO_MANIFEST_DIR` is always set by cargo.")
);
let manifest_dir_copy = manifest_dir.clone();

while manifest_dir.parent().is_some() {
if manifest_dir.join(".git/HEAD").exists() {
println!("cargo:rerun-if-changed={}", manifest_dir.join(".git/HEAD").display());
return
}

manifest_dir.pop();
}

println!(
"cargo:warning=Could not find `.git/HEAD` searching from `{}` upwards!",
manifest_dir_copy.display(),
);
}
8 changes: 8 additions & 0 deletions utils/fork-tree/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "fork-tree"
version = "2.0.0"
authors = ["Stafi Protocol <technical@stafi.com>"]
edition = "2018"

[dependencies]
codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive"] }
Loading

0 comments on commit 08d05d7

Please sign in to comment.