Skip to content

Commit

Permalink
split runtimes (#420)
Browse files Browse the repository at this point in the history
* move and rename runtime to one subfolder

* remove unused deps on pallet-staking

* remove old migrations code

* create minimum staking runtime

* remove with-staking feature flag

* remove unused spec

* remove executor crate

* remove nodle_ and nodle_chain_ prefixes

* make node work with runtime_main

* fix benchmarking
  • Loading branch information
ETeissonniere authored Nov 4, 2021
1 parent bef7df3 commit 661a9fe
Show file tree
Hide file tree
Showing 48 changed files with 1,496 additions and 996 deletions.
304 changes: 147 additions & 157 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
[workspace]
members = [
"executor",
"node",
"pallets/*",
"primitives",
"runtime",
"runtimes/*",
"support",
]

Expand Down
26 changes: 0 additions & 26 deletions executor/Cargo.toml

This file was deleted.

32 changes: 0 additions & 32 deletions executor/src/lib.rs

This file was deleted.

42 changes: 22 additions & 20 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,39 @@ name = "nodle-chain"
path = "src/main.rs"

[features]
default = [ "cli" ]
runtime-benchmarks = [
"nodle-chain-runtime/runtime-benchmarks",
]
cli = [
"nodle-chain-executor/wasmi-errno",
]
with-staking = [
"nodle-chain-runtime/with-staking",
]
default = ["cli"]
runtime-benchmarks = ["runtime-main/runtime-benchmarks"]
cli = ["sc-executor/wasmi-errno"]

[package.metadata.wasm-pack.profile.release]
# `wasm-opt` has some problems on linux, see
# https://github.com/rustwasm/wasm-pack/issues/781 etc.
wasm-opt = false

[target.'cfg(target_arch="x86_64")'.dependencies]
nodle-chain-executor = { path = "../executor", features = [ "wasmtime" ] }
sc-cli = { version = "0.9.0", features = [ "wasmtime" ] }
sc-service = { version = "0.9.0", default-features = false, features = [ "wasmtime" ] }
sp-trie = { version = "3.0.0", default-features = false, features = ["memory-tracker"] }
sc-cli = { version = "0.9.0", features = ["wasmtime"] }
sc-executor = { version = "0.9.0", features = ["wasmtime"] }
sc-service = { version = "0.9.0", default-features = false, features = [
"wasmtime",
] }
sp-trie = { version = "3.0.0", default-features = false, features = [
"memory-tracker",
] }

[dependencies]
frame-benchmarking = { version = "3.1.0", default-features = false }
frame-benchmarking-cli = { version = "3.0.0", default-features = false }
futures = { version = "0.3.16", features = ["compat"] }
jsonrpc-core = "15.1.0"
nodle-chain-executor = { path = "../executor" }
nodle-chain-primitives = { path = "../primitives" }
nodle-chain-runtime = { path = "../runtime" }
pallet-contracts = "3.0.0"
pallet-contracts-rpc = "3.0.0"
pallet-im-online = { version = "3.0.0", default-features = false }
pallet-root-of-trust-rpc = { path = "../pallets/root-of-trust/rpc" }
pallet-nodle-staking = { default-features = false, path = "../pallets/nodle-staking", optional = true }
pallet-root-of-trust-rpc = { path = "../pallets/root-of-trust/rpc" }
pallet-staking = { default-features = false, path = "../pallets/staking", optional = true }
pallet-transaction-payment-rpc = "3.0.0"
primitives = { path = "../primitives" }
runtime-main = { path = "../runtimes/main" }
#runtime-staking = { path = "../runtimes/staking" }
sc-authority-discovery = "0.9.0"
sc-basic-authorship = "0.9.0"
sc-cli = "0.9.0"
Expand All @@ -55,6 +52,7 @@ sc-consensus-babe = "0.9.0"
sc-consensus-babe-rpc = "0.9.0"
sc-consensus-epochs = "0.9.0"
sc-consensus-slots = "0.9.0"
sc-executor = "0.9.0"
sc-finality-grandpa = "0.9.0"
sc-finality-grandpa-rpc = "0.9.0"
sc-finality-grandpa-warp-sync = "0.9.0"
Expand All @@ -75,11 +73,15 @@ sp-consensus-babe = "0.9.0"
sp-core = "3.0.0"
sp-finality-grandpa = "3.0.0"
sp-inherents = "3.0.0"
sp-io = "3.0.0"
sp-keystore = "0.9.0"
sp-runtime = "3.0.0"
sp-state-machine = "0.9.0"
sp-transaction-pool = "3.0.0"
sp-trie = "3.0.0"
structopt = "0.3.22"
substrate-frame-rpc-system = "3.0.0"
trie-root = "0.16.0"
log = { version = "0.4.14", default-features = false }
# sp-tracing = { version = "3.0.0", default-features = false }
env_logger = "0.9.0"
Expand All @@ -88,4 +90,4 @@ env_logger = "0.9.0"
frame-benchmarking-cli = { version = "3.0.0", default-features = false }
sc-cli = "0.9.0"
structopt = "0.3.22"
substrate-build-script-utils = "3.0.0"
substrate-build-script-utils = "3.0.0"
390 changes: 0 additions & 390 deletions node/res/fork.json

This file was deleted.

32 changes: 12 additions & 20 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

use nodle_chain_primitives::{AccountId, Balance, BlockNumber, Signature};
#[cfg(feature = "with-staking")]
use nodle_chain_runtime::NodleStakingConfig;
use nodle_chain_runtime::{
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use primitives::{AccountId, Balance, BlockNumber, Signature};
use runtime_main::{
constants::*, wasm_binary_unwrap, AuthorityDiscoveryConfig, BabeConfig, BalancesConfig,
ContractsConfig, FinancialMembershipConfig, GenesisConfig, GrandpaConfig, ImOnlineConfig,
RootMembershipConfig, SessionConfig, SessionKeys, SystemConfig, TechnicalMembershipConfig,
ValidatorsSetConfig, VestingConfig,
};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use sc_service::ChainType;
use serde_json::json;
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
Expand Down Expand Up @@ -140,9 +138,7 @@ pub fn testnet_genesis(
});

const ENDOWMENT: Balance = 10_000 * NODL;

#[cfg(feature = "with-staking")]
const STASH: Balance = ENDOWMENT / 1_000;
//const STASH: Balance = ENDOWMENT / 1_000;

GenesisConfig {
// Core
Expand Down Expand Up @@ -205,15 +201,14 @@ pub fn testnet_genesis(
pallet_grandpa: Some(GrandpaConfig {
authorities: vec![],
}),
#[cfg(feature = "with-staking")]
pallet_nodle_staking: Some(NodleStakingConfig {
stakers: initial_authorities
.iter()
.map(|x| (x.0.clone(), None, STASH))
.collect(),
invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(),
..Default::default()
}),
// pallet_nodle_staking: Some(NodleStakingConfig {
// stakers: initial_authorities
// .iter()
// .map(|x| (x.0.clone(), None, STASH))
// .collect(),
// invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(),
// ..Default::default()
// }),
pallet_membership_Instance2: Some(ValidatorsSetConfig {
members: initial_authorities
.iter()
Expand Down Expand Up @@ -312,7 +307,6 @@ pub fn local_testnet_config() -> ChainSpec {
)
}

#[cfg(feature = "with-staking")]
fn local_staking_genesis() -> GenesisConfig {
testnet_genesis(
vec![get_authority_keys_from_seed("Alice")],
Expand All @@ -329,7 +323,6 @@ fn local_staking_genesis() -> GenesisConfig {
}

/// Local testnet config to test the staking pallet
#[cfg(feature = "with-staking")]
pub fn local_staking_config() -> ChainSpec {
ChainSpec::from_genesis(
"Local Staking Testnet",
Expand Down Expand Up @@ -370,7 +363,6 @@ pub(crate) mod tests {
}

#[test]
#[cfg(feature = "with-staking")]
fn test_create_staking_local_chain_spec() {
local_staking_config().build_storage().unwrap();
}
Expand Down
7 changes: 3 additions & 4 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

use crate::service::Executor;
use crate::{
chain_spec,
cli::{Cli, Subcommand},
service::{self, new_partial},
};
use nodle_chain_executor::Executor;
use nodle_chain_primitives::Block;
use primitives::Block;
use sc_cli::{ChainSpec, Result, Role, RuntimeVersion, SubstrateCli};
use sc_service::PartialComponents;

Expand Down Expand Up @@ -57,7 +57,6 @@ impl SubstrateCli for Cli {
"local" => Box::new(chain_spec::local_testnet_config()),
"" | "main" => Box::new(chain_spec::main_config()),
"arcadia" => Box::new(chain_spec::arcadia_config()),
#[cfg(feature = "with-staking")]
"staking-local" => Box::new(chain_spec::local_staking_config()),
path => Box::new(chain_spec::ChainSpec::from_json_file(
std::path::PathBuf::from(path),
Expand All @@ -66,7 +65,7 @@ impl SubstrateCli for Cli {
}

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

Expand Down
2 changes: 1 addition & 1 deletion node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

//! RPC APIs instantiation code for the Nodle Chain.
use nodle_chain_primitives::{AccountId, Balance, Block, BlockNumber, CertificateId, Hash, Index};
use pallet_root_of_trust_rpc::{RootOfTrust, RootOfTrustApi, RootOfTrustRuntimeApi};
use primitives::{AccountId, Balance, Block, BlockNumber, CertificateId, Hash, Index};
use sc_consensus_babe::{Config, Epoch};
use sc_consensus_babe_rpc::BabeRpcHandler;
use sc_consensus_epochs::SharedEpochChanges;
Expand Down
14 changes: 11 additions & 3 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
use crate::rpc::{self, DenyUnsafe, IoHandler};
use futures::prelude::*;
use nodle_chain_executor::Executor;
use nodle_chain_primitives::Block;
use nodle_chain_runtime::RuntimeApi;
use primitives::Block;
use runtime_main::RuntimeApi;
use sc_client_api::{ExecutorProvider, RemoteBackend};
use sc_consensus_babe;
use sc_executor::native_executor_instance;
use sc_finality_grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider};
use sc_network::{Event, NetworkService};
use sc_service::{config::Configuration, error::Error as ServiceError, RpcHandlers, TaskManager};
Expand All @@ -33,6 +33,14 @@ use sp_inherents::InherentDataProviders;
use sp_runtime::traits::Block as BlockT;
use std::sync::Arc;

// Our native executor instance.
native_executor_instance!(
pub Executor,
runtime_main::api::dispatch,
runtime_main::native_version,
frame_benchmarking::benchmarking::HostFunctions,
);

type FullClient = sc_service::TFullClient<Block, RuntimeApi, Executor>;
type FullBackend = sc_service::TFullBackend<Block>;
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
Expand Down
6 changes: 4 additions & 2 deletions pallets/allocations/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ runtime-benchmarks = [
frame-benchmarking = { version = "3.0.0", default-features = false, optional = true }
frame-support = { version = "3.0.0", default-features = false }
frame-system = { version = "3.0.0", default-features = false }
nodle-support = { path = "../../support" }
support = { path = "../../support" }
pallet-balances = { version = "3.0.0", default-features = false }
pallet-emergency-shutdown = { default-features = false, path = "../emergency-shutdown" }
parity-scale-codec = { version = "2.2.0", default-features = false, features = ["derive"] }
parity-scale-codec = { version = "2.2.0", default-features = false, features = [
"derive",
] }
serde = { version = "1.0.129", optional = true, features = ["derive"] }
sp-io = { version = "3.0.0", default-features = false }
sp-runtime = { version = "3.0.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion pallets/allocations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use frame_support::{
traits::{ChangeMembers, Currency, Get, InitializeMembers},
};
use frame_system::ensure_signed;
use nodle_support::WithAccountId;
use support::WithAccountId;

use sp_runtime::{
traits::{CheckedAdd, Saturating},
Expand Down
10 changes: 6 additions & 4 deletions pallets/reserve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ std = [
"sp-std/std",
]
runtime-benchmarks = [
"frame-benchmarking",
"frame-benchmarking",
"frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-support/runtime-benchmarks",
]

[dependencies]
frame-benchmarking = { version = "3.1.0", default-features = false, optional = true }
frame-support = { version = "3.0.0", default-features = false }
frame-system = { version = "3.0.0", default-features = false }
nodle-support = { path = "../../support" }
support = { path = "../../support" }
pallet-balances = { version = "3.0.0", default-features = false }
parity-scale-codec = { version = "2.2.0", default-features = false, features = ["derive"] }
parity-scale-codec = { version = "2.2.0", default-features = false, features = [
"derive",
] }
serde = { version = "1.0.129", optional = true, features = ["derive"] }
sp-io = { version = "3.0.0", default-features = false }
sp-runtime = { version = "3.0.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion pallets/reserve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ use frame_support::{
traits::{Currency, ExistenceRequirement, Get, Imbalance, OnUnbalanced},
weights::GetDispatchInfo,
};
use nodle_support::WithAccountId;
use sp_runtime::{
traits::{AccountIdConversion, Dispatchable},
DispatchResult, ModuleId,
};
use sp_std::prelude::Box;
use support::WithAccountId;

#[cfg(feature = "std")]
use frame_support::traits::GenesisBuild;
Expand Down
Loading

0 comments on commit 661a9fe

Please sign in to comment.