Remove node-service (#933)

* Move `chain_spec` into `node-cli`

* Fixes tests

* Adds `construct_simple_service` and `construct_service_factory` macros

* Remove the `node-service` crate

* Add some documentation

* Fixes compilation on stable
This commit is contained in:
Bastian Köcher authored and Gav Wood committed 2018-10-19 12:22:32 +02:00
1 parent ca38fd72f6
commit 7f6862ba5e
11 files changed
+379 -365

No files matched your search

+13 -1
View File
@@ -9,4 +9,16 @@ log = "0.4"
tokio = "0.1.7"
exit-future = "0.1"
substrate-cli = { path = "../../core/cli" }
node-service = { path = "../service" }
substrate-primitives = { path = "../../core/primitives" }
node-runtime = { path = "../runtime" }
node-primitives = { path = "../primitives" }
node-network = { path = "../network" }
hex-literal = "0.1"
substrate-service = { path = "../../core/service" }
substrate-transaction-pool = { path = "../../core/transaction-pool" }
substrate-network = { path = "../../core/network" }
sr-primitives = { path = "../../core/sr-primitives" }
node-executor = { path = "../executor" }
[dev-dependencies]
substrate-service-test = { path = "../../core/service/test" }
+78
View File
@@ -0,0 +1,78 @@
{
"name": "BBQ Birch",
"id": "bbq-birch",
"telemetryUrl": "wss://telemetry.polkadot.io/submit/",
"protocolId": null,
"bootNodes": [
"/ip4/104.211.54.233/tcp/30333/p2p/QmV6ttrdRBjuY6EV4Zh5saz8MaqY6anjXo4SrCWt5caANX",
"/ip4/104.211.48.51/tcp/30333/p2p/QmNWVCgizRFj96AkPv2Zi2MHUnSDBTF3y9eMsa3cJgAJV7",
"/ip4/104.211.48.247/tcp/30333/p2p/QmfPmL2L1cmupSgJSJgVg4KW8frGLq9AEH2iwHE3rCsfvg",
"/ip4/40.114.120.164/tcp/30333/p2p/QmYV2Dv6ZfHkxHtQgYMGPTkNbtaSHUb4r8CsP4Pp2PDTNs"
],
"genesis": {
"raw": {
"0x3a617574683a00000000": "0x82c39b31a2b79a90f8e66e7a77fdb85a4ed5517f2ae39f6a80565e8ecae85cf5",
"0x7935e46f94f24b82716c0142e2271de9": "0x0087000000000000",
"0x27b3872d47181b4a2dc15f0da43e7026": "0xe803000000000000",
"0x5278a9149ec1adfa8090a8ad336c881e": "0x0500000000000000",
"0x329586a7b97f2ac15f6c26a02c3c5621": "0x1082c39b31a2b79a90f8e66e7a77fdb85a4ed5517f2ae39f6a80565e8ecae85cf54de37a07567ebcbf8c64568428a835269a566723687058e017b6d69db00a77e7063d7787ebca768b7445dfebe7d62cbb1625ff4dba288ea34488da266dd6dca58101764f45778d4980dadaceee6e8af2517d3ab91ac9bec9cd1714fa5994081c",
"0xb9b861cab4bbce870c811515bd5f33d7": "0x00",
"0xd437fe93b0bd0a5d67d30d85d010edc2": "0x40420f00",
"0x3a617574683a03000000": "0x8101764f45778d4980dadaceee6e8af2517d3ab91ac9bec9cd1714fa5994081c",
"0x472b8f236d06a2ff7f1e9b2e848ef1d5": "0x0080e03779c311000000000000000000",
"0x3a636f6465": "0x0061736d0100000001f3012260017f0060037f7f7f017f60027f7f017f60057f7f7f7f7f0060047f7f7f7f0060037f7f7f0060017f017f60057f7f7f7f7f017f60027f7f0060017e0060047f7f7f7f017f60067f7f7f7f7f7f017f60087f7f7f7f7f7f7f7f017f60027e7f017f60000060017f017e60067f7f7f7f7f7f00600a7f7f7f7f7e7e7f7f7f7f00600a7f7f7f7e7e7f7f7f7f7f0060047f7e7f7f006000017e60047f7f7f7f017e60027f7e0060037e7e7f0060027e7f0060037f7e7e017f60027f7f017e60037f7e7e0060087f7f7f7f7f7e7e7f0060037f7f7e0060047f7f7e7e0060057f7e7e7e7e0060067f7e7e7e7e7f0060047f7e7e7f0002cc041703656e760a6578745f6d616c6c6f63000603656e76086578745f66726565000003656e760c6578745f74776f785f313238000503656e760f6578745f7365745f73746f72616765000403656e76146578745f6765745f73746f726167655f696e746f000703656e76236578745f626c616b65325f3235365f656e756d6572617465645f747269655f726f6f74000403656e760e6578745f7072696e745f75746638000803656e760d6578745f7072696e745f6e756d000903656e76166578745f73616e64626f785f6d656d6f72795f676574000a03656e76166578745f73616e64626f785f6d656d6f72795f736574000a03656e76116578745f636c6561725f73746f72616765000803656e76126578745f656432353531395f766572696679000a03656e76166578745f73616e64626f785f6d656d6f72795f6e6577000203656e761b6578745f73616e64626f785f6d656d6f72795f74656172646f776e000003656e76176578745f73616e64626f785f696e7374616e7469617465000b03656e76126578745f73616e64626f785f696e766f6b65000c03656e761d6578745f73616e64626f785f696e7374616e63655f74656172646f776e000003656e760e6578745f626c616b65325f323536000503656e760d6578745f7072696e745f686578000803656e76106578745f73746f726167655f726f6f74000003656e76126578745f6578697374735f73746f72616765000203656e76106578745f636c6561725f707265666978000803656e76186578745f73746f726167655f6368616e6765735f726f6f74000d03c602c402080e0808080808080805080808080808080505080000080e00000008080808080808080808080808050805080805050805050505020800080808080805020005020608080b0208000500010e020208020201020808050402020202020602020100000f0404041004100405050808080805050508040405080002040e04030411041204040404040813080000080808080808000005140000000808080808080808050500080000050200000000000000050500000005000808080c04080005080815080005050816081718080505050803050808081908000508080200050805020e08050000021a1a1a1a051a051a0e09001a1a1a1a1a1a1a0f1a1a0218081b000400080802060000000508021c0000060800060505051d061e1f1e001b1b1e091b000000050800080000000800000000000000000000010101011f201f1f1f212121210405017001484805030100110619037f01418080c0000b7f0041eedfc2000b7f0041eedfc2000b07c00213066d656d6f72790200195f5f696e6469726563745f66756e6374696f6e5f7461626c6501000b5f5f686561705f6261736503010a5f5f646174615f656e6403020776657273696f6e00fe01086d6574616461746100ff010b617574686f72697469657300800210696e697469616c6973655f626c6f636b0081020f6170706c795f65787472696e7369630083020d657865637574655f626c6f636b0085020e66696e616c6973655f626c6f636b00890213696e686572656e745f65787472696e73696373008a020f76616c696461746f725f636f756e74008b020a76616c696461746f7273008c020974696d657374616d70008d020b72616e646f6d5f73656564008e020d6163636f756e745f6e6f6e6365008f020e6c6f6f6b75705f616464726573730091021476616c69646174655f7472616e73616374696f6e009202098201010041010b47644b546974636e6f705c728b018c0193019501970199019a019b019c019d01d80171fd017868666779e701ef01e501e901a6029401fa01f601f9015ec702c501a002af01bb02cd02c601ca02ae01c102c002c602c502c402c202fc01fb01c201c1019f029e02ad01aa01ba02b902cc02cb02c401c301c902c802a9010adeb821c4029e0203097f017e017f024002400240024002400240200041046a2802002202200041086a28020022036b2001410c6a2802002204200141086a28020022056b220641d0006d22074f0d00200320076a22082003490d0420024101742209200820082009491b220aad42d0007e220b422088a70d04200ba722094100480d042002450d012000280200210c200910002208450d052008200c2009200241d0006c2202200220094b1b10ce021a200c10010c020b200028020021080c020b200910002208450d030b20002008360200200041046a200a3602000b2008200341d0006c6a2005200610ce021a200141086a2004360200200041086a200320076a36020002402001280204450d00200128020010010b0f0b1018000b200941081019000b0a0041c083c000104d000b0d0041eda0c1004122100600000bafa601030a7f027e017f230041206b2202240020024100360218200242013703102000280200210302400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024002400240024020002802082200413f4b0d00410110002204450d6b200220043602102002428180808010370214200420004102743a000020000d010c020b02402000418080014f0d00410210002204450d6a200220043602102002428280808020370214200420004102744101723b00000c010b024020004180808080044f0d00410410002204450d692002200436021020024284808080c000370214200420004102744102723600000c010b410110002204450d67200220043602102002428180808010370214200441033a0000024002400240024020022802142205200241186a28020022046b41044f0d00200441046a22062004490d062Line truncated
"0x4664fb5d4e16f894df23cadb3faaa9a6": "0x04000000",
"0xfb4fdd0ab2d85118e220e2e7473cd3b5": "0x0000a0dec5adc9353600000000000000",
"0x3a617574683a6c656e": "0x04000000",
"0xa36baa0f89eff09b2facf282f27a11ba": "0x50c30000",
"0x52b963fbdb3d6e1b03808fc20071f07f": "0x0062070000000000",
"0x8366297e853b97a38cca0f62019a717b": "0x00000000000000000000000000000000",
"0x59b17352bea17cb7dec6dde697de7db4": "0x3c00000000000000",
"0xfc2dc4b8bb0b9ca8f01a73a726f7c7f5": "0x000e010000000000",
"0x24b2518f9a9ee24ab0b62346d83d90b0": "0x11080000",
"0xf718f07ec955fb94f1b3069713461089": "0x0010a5d4e80000000000000000000000",
"0x34de7fc8c73e4252b9e09a9e3bf602f8": "0x3c00000000000000",
"0x637414312dac3b280120bf15b4f66cee": "0x00000000",
"0x3a617574683a02000000": "0x063d7787ebca768b7445dfebe7d62cbb1625ff4dba288ea34488da266dd6dca5",
"0xdade128e67a5ed110063f56a01ab6bbf": "0x0000000000000000",
"0x579ab55d37b1220812be3c3df29d4858": "0x0000000000000000",
"0xa902f1f0ef97177b8df9f9fd413768e7": "0x00000000",
"0x0b21b3456b23e90d061941ab416f5ea2": "0x00000000000000000000000000000000",
"0xb8f48a8c01f629d6dc877f64892bed49": "0x0000000000000000",
"0x90e2849b965314409e8bc00011f3004f": "0x04000000",
"0x99e2aba8a2b7c8ccba2d740fb86adb0c": "0x00",
"0x24586f4898a5a637b755b658ec163d00": "0x00407a10f35a00000000000000000000",
"0xa361c08e2d7768113505020abde19e30": "0x00000000",
"0x0e0cdac0d4de97c54f3ae216b003fa81": "0x8043000000000000",
"0x799192c17c5cc562d709af11ace92e6a": "0x00040000",
"0x9651d20f401bfac47731a01d6eba33b4": "0x00000000",
"0x3b7d32346a3315a351084927a27d06a7": "0x0010a5d4e80000000000000000000000",
"0x125dc846383907f5846f72ce53ca0e4b": "0x00ca9a3b000000000000000000000000",
"0x2dce29f1a768624dc5343063cb77f77d": "0x07000000",
"0xdee5bbb035d9ebc2c9338b5aedf744d7": "0x8043000000000000",
"0x6e45a8645fa8f905c49fecfef3d06c67": "0x0100000000000000",
"0x53d1471b684c8a776c80353e5981c960": "0x00407a10f35a00000000000000000000",
"0xe026dd082e3158e72eb7c985fc8bac4f": "0x8043000000000000",
"0x62f532424b7b1c52f522857315040f27": "0x00407a10f35a00000000000000000000",
"0xdfaac108e0d4bc78fc9419a7fcfa84dc": "0x1082c39b31a2b79a90f8e66e7a77fdb85a4ed5517f2ae39f6a80565e8ecae85cf54de37a07567ebcbf8c64568428a835269a566723687058e017b6d69db00a77e7063d7787ebca768b7445dfebe7d62cbb1625ff4dba288ea34488da266dd6dca58101764f45778d4980dadaceee6e8af2517d3ab91ac9bec9cd1714fa5994081c",
"0xb7b6ec0f25eb1ed8b91d05f697d7a874": "0x0c00000000000000",
"0x500603c2af44c475f017a2bbd8d08cbf": "0x04f295940fa750df68a686fcf4abd4111c8a9c5a5a5a83c4c8639c451a94a7adfd",
"0x934302c5ec4cb4f73a395e2184ab0aa6": "0x00e40b54020000000000000000000000",
"0x0e4944cfd98d6f4cc374d16f5a4e3f9c": "0x0000000000000000",
"0xb553f17a95cb65012a4326bbaae97035": "0x0010a5d4e80000000000000000000000",
"0x52c9048efbfc40fd1e312b7bed451dee": "0x06000000",
"0xf4039aa8ae697861be900c58239e96f7": "0x0010a5d4e80000000000000000000000",
"0x90d5871cf3f4d0a3642cf2043a7d8eda": "0x0010a5d4e80000000000000000000000",
"0xcf9a75deea0508104cd993c82daf57d3": "0x8096980000000000",
"0xfe7030fd433199728c516e4392091aa5": "0x0080c6a47e8d03000000000000000000",
"0x2b89d3b6f46fc8a3aee48c9cb06d7670": "0x0010a5d4e80000000000000000000000",
"0xdd9b01f8462dc19488279cb351a6d861": "0x20a10700",
"0xd9c94b41dc87728ebf0a966d2e9ad9c0": "0x3c00000000000000",
"0x3a617574683a01000000": "0x4de37a07567ebcbf8c64568428a835269a566723687058e017b6d69db00a77e7",
"0xfbb77d814ac81cfe0ef7030e8bd686f0": "0xe803000000000000",
"0x4a8b1a5c7681353a6a320553abbbca49": "0x8043000000000000",
"0x78f4ad73d6b7279f8d06f359e363c829": "0x0000a0dec5adc9353600000000000000",
"0xf14d23a9d4492a1efc9194e257b3c3d9": "0x00000000"
}
}
}
+270
View File
@@ -0,0 +1,270 @@
// Copyright 2018 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/>.
//! Substrate chain configurations.
use primitives::{AuthorityId, ed25519};
use node_runtime::{GenesisConfig, ConsensusConfig, CouncilSeatsConfig, CouncilVotingConfig, DemocracyConfig,
SessionConfig, StakingConfig, TimestampConfig, BalancesConfig, TreasuryConfig,
ContractConfig, Permill, Perbill};
use substrate_service;
const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
/// Specialised `ChainSpec`.
pub type ChainSpec = substrate_service::ChainSpec<GenesisConfig>;
pub fn bbq_birch_config() -> Result<ChainSpec, String> {
ChainSpec::from_embedded(include_bytes!("../res/bbq-birch.json"))
}
fn staging_testnet_config_genesis() -> GenesisConfig {
let initial_authorities = vec![
hex!["82c39b31a2b79a90f8e66e7a77fdb85a4ed5517f2ae39f6a80565e8ecae85cf5"].into(),
hex!["4de37a07567ebcbf8c64568428a835269a566723687058e017b6d69db00a77e7"].into(),
hex!["063d7787ebca768b7445dfebe7d62cbb1625ff4dba288ea34488da266dd6dca5"].into(),
hex!["8101764f45778d4980dadaceee6e8af2517d3ab91ac9bec9cd1714fa5994081c"].into(),
];
let endowed_accounts = vec![
hex!["f295940fa750df68a686fcf4abd4111c8a9c5a5a5a83c4c8639c451a94a7adfd"].into(),
];
const MILLICENTS: u128 = 1_000_000_000;
const CENTS: u128 = 1_000 * MILLICENTS; // assume this is worth about a cent.
const DOLLARS: u128 = 100 * CENTS;
const SECS_PER_BLOCK: u64 = 5;
const MINUTES: u64 = 60 / SECS_PER_BLOCK;
const HOURS: u64 = MINUTES * 60;
const DAYS: u64 = HOURS * 24;
GenesisConfig {
consensus: Some(ConsensusConfig {
code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm").to_vec(), // TODO change
authorities: initial_authorities.clone(),
}),
system: None,
balances: Some(BalancesConfig {
balances: endowed_accounts.iter().map(|&k|(k, 10_000_000 * DOLLARS)).collect(),
transaction_base_fee: 1 * CENTS,
transaction_byte_fee: 10 * MILLICENTS,
existential_deposit: 1 * DOLLARS,
transfer_fee: 1 * CENTS,
creation_fee: 1 * CENTS,
reclaim_rebate: 1 * CENTS,
}),
session: Some(SessionConfig {
validators: initial_authorities.iter().cloned().map(Into::into).collect(),
session_length: 5 * MINUTES
}),
staking: Some(StakingConfig {
current_era: 0,
intentions: initial_authorities.iter().cloned().map(Into::into).collect(),
offline_slash: Perbill::from_billionths(1_000_000),
session_reward: Perbill::from_billionths(2_065),
current_offline_slash: 0,
current_session_reward: 0,
validator_count: 7,
sessions_per_era: 12,
bonding_duration: 1 * DAYS,
offline_slash_grace: 4,
minimum_validator_count: 4,
}),
democracy: Some(DemocracyConfig {
launch_period: 5 * MINUTES, // 1 day per public referendum
voting_period: 5 * MINUTES, // 3 days to discuss & vote on an active referendum
minimum_deposit: 50 * DOLLARS, // 12000 as the minimum deposit for a referendum
}),
council_seats: Some(CouncilSeatsConfig {
active_council: vec![],
candidacy_bond: 10 * DOLLARS,
voter_bond: 1 * DOLLARS,
present_slash_per_voter: 1 * CENTS,
carry_count: 6,
presentation_duration: 1 * DAYS,
approval_voting_period: 2 * DAYS,
term_duration: 28 * DAYS,
desired_seats: 0,
inactive_grace_period: 1, // one additional vote should go by before an inactive voter can be reaped.
}),
council_voting: Some(CouncilVotingConfig {
cooloff_period: 4 * DAYS,
voting_period: 1 * DAYS,
}),
timestamp: Some(TimestampConfig {
period: SECS_PER_BLOCK,
}),
treasury: Some(TreasuryConfig {
proposal_bond: Permill::from_percent(5),
proposal_bond_minimum: 1 * DOLLARS,
spend_period: 1 * DAYS,
burn: Permill::from_percent(50),
}),
contract: Some(ContractConfig {
contract_fee: 1 * CENTS,
call_base_fee: 1000,
create_base_fee: 1000,
gas_price: 1 * MILLICENTS,
max_depth: 1024,
block_gas_limit: 10_000_000,
}),
}
}
/// Staging testnet config.
pub fn staging_testnet_config() -> ChainSpec {
let boot_nodes = vec![
];
ChainSpec::from_genesis(
"Staging Testnet",
"staging_testnet",
staging_testnet_config_genesis,
boot_nodes,
Some(STAGING_TELEMETRY_URL.into()),
None,
None,
)
}
fn testnet_genesis(initial_authorities: Vec<AuthorityId>) -> GenesisConfig {
let endowed_accounts = vec![
ed25519::Pair::from_seed(b"Alice ").public().0.into(),
ed25519::Pair::from_seed(b"Bob ").public().0.into(),
ed25519::Pair::from_seed(b"Charlie ").public().0.into(),
ed25519::Pair::from_seed(b"Dave ").public().0.into(),
ed25519::Pair::from_seed(b"Eve ").public().0.into(),
ed25519::Pair::from_seed(b"Ferdie ").public().0.into(),
];
GenesisConfig {
consensus: Some(ConsensusConfig {
code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm").to_vec(),
authorities: initial_authorities.clone(),
}),
system: None,
balances: Some(BalancesConfig {
transaction_base_fee: 1,
transaction_byte_fee: 0,
existential_deposit: 500,
transfer_fee: 0,
creation_fee: 0,
reclaim_rebate: 0,
balances: endowed_accounts.iter().map(|&k|(k, (1 << 60))).collect(),
}),
session: Some(SessionConfig {
validators: initial_authorities.iter().cloned().map(Into::into).collect(),
session_length: 10,
}),
staking: Some(StakingConfig {
current_era: 0,
intentions: initial_authorities.iter().cloned().map(Into::into).collect(),
minimum_validator_count: 1,
validator_count: 2,
sessions_per_era: 5,
bonding_duration: 2 * 60 * 12,
offline_slash: Perbill::zero(),
session_reward: Perbill::zero(),
current_offline_slash: 0,
current_session_reward: 0,
offline_slash_grace: 0,
}),
democracy: Some(DemocracyConfig {
launch_period: 9,
voting_period: 18,
minimum_deposit: 10,
}),
council_seats: Some(CouncilSeatsConfig {
active_council: endowed_accounts.iter()
.filter(|a| initial_authorities.iter().find(|&b| a.0 == b.0).is_none())
.map(|a| (a.clone(), 1000000)).collect(),
candidacy_bond: 10,
voter_bond: 2,
present_slash_per_voter: 1,
carry_count: 4,
presentation_duration: 10,
approval_voting_period: 20,
term_duration: 1000000,
desired_seats: (endowed_accounts.len() - initial_authorities.len()) as u32,
inactive_grace_period: 1,
}),
council_voting: Some(CouncilVotingConfig {
cooloff_period: 75,
voting_period: 20,
}),
timestamp: Some(TimestampConfig {
period: 5, // 5 second block time.
}),
treasury: Some(TreasuryConfig {
proposal_bond: Permill::from_percent(5),
proposal_bond_minimum: 1_000_000,
spend_period: 12 * 60 * 24,
burn: Permill::from_percent(50),
}),
contract: Some(ContractConfig {
contract_fee: 21,
call_base_fee: 135,
create_base_fee: 175,
gas_price: 1,
max_depth: 1024,
block_gas_limit: 10_000_000,
}),
}
}
fn development_config_genesis() -> GenesisConfig {
testnet_genesis(vec![
ed25519::Pair::from_seed(b"Alice ").public().into(),
])
}
/// Development config (single validator Alice)
pub fn development_config() -> ChainSpec {
ChainSpec::from_genesis("Development", "development", development_config_genesis, vec![], None, None, None)
}
fn local_testnet_genesis() -> GenesisConfig {
testnet_genesis(vec![
ed25519::Pair::from_seed(b"Alice ").public().into(),
ed25519::Pair::from_seed(b"Bob ").public().into(),
])
}
/// Local testnet config (multivalidator Alice + Bob)
pub fn local_testnet_config() -> ChainSpec {
ChainSpec::from_genesis("Local Testnet", "local_testnet", local_testnet_genesis, vec![], None, None, None)
}
#[cfg(test)]
mod tests {
use super::*;
use service_test;
use service::Factory;
fn local_testnet_genesis_instant() -> GenesisConfig {
let mut genesis = local_testnet_genesis();
genesis.timestamp = Some(TimestampConfig { period: 0 });
genesis
}
/// Local testnet config (multivalidator Alice + Bob)
pub fn integration_test_config() -> ChainSpec {
ChainSpec::from_genesis("Integration Test", "test", local_testnet_genesis_instant, vec![], None, None, None)
}
#[test]
fn test_connectivity() {
service_test::connectivity::<Factory>(integration_test_config());
}
}
+25 -10
View File
@@ -22,17 +22,32 @@
extern crate tokio;
extern crate substrate_cli as cli;
extern crate node_service as service;
extern crate substrate_primitives as primitives;
extern crate node_runtime;
extern crate exit_future;
#[macro_use]
extern crate hex_literal;
#[cfg(test)]
extern crate substrate_service_test as service_test;
extern crate substrate_transaction_pool as transaction_pool;
extern crate substrate_network as network;
extern crate node_network;
extern crate sr_primitives as runtime_primitives;
extern crate node_primitives;
#[macro_use]
extern crate substrate_service;
extern crate node_executor;
#[macro_use]
extern crate log;
pub use cli::error;
mod chain_spec;
mod service;
use tokio::runtime::Runtime;
pub use service::{Components as ServiceComponents, Service, CustomConfiguration, ServiceFactory};
pub use cli::{VersionInfo, IntoExit};
use substrate_service::{ServiceFactory, Roles as ServiceRoles};
/// The chain specification option.
#[derive(Clone, Debug)]
@@ -49,12 +64,12 @@ pub enum ChainSpec {
/// Get a chain config from a spec setting.
impl ChainSpec {
pub(crate) fn load(self) -> Result<service::ChainSpec, String> {
pub(crate) fn load(self) -> Result<chain_spec::ChainSpec, String> {
Ok(match self {
ChainSpec::BbqBirch => service::chain_spec::bbq_birch_config()?,
ChainSpec::Development => service::chain_spec::development_config(),
ChainSpec::LocalTestnet => service::chain_spec::local_testnet_config(),
ChainSpec::StagingTestnet => service::chain_spec::staging_testnet_config(),
ChainSpec::BbqBirch => chain_spec::bbq_birch_config()?,
ChainSpec::Development => chain_spec::development_config(),
ChainSpec::LocalTestnet => chain_spec::local_testnet_config(),
ChainSpec::StagingTestnet => chain_spec::staging_testnet_config(),
})
}
@@ -69,7 +84,7 @@ impl ChainSpec {
}
}
fn load_spec(id: &str) -> Result<Option<service::ChainSpec>, String> {
fn load_spec(id: &str) -> Result<Option<chain_spec::ChainSpec>, String> {
Ok(match ChainSpec::from(id) {
Some(spec) => Some(spec.load()?),
None => None,
@@ -93,7 +108,7 @@ pub fn run<I, T, E>(args: I, exit: E, version: cli::VersionInfo) -> error::Resul
info!("Roles: {:?}", config.roles);
let mut runtime = Runtime::new()?;
let executor = runtime.executor();
match config.roles == service::Roles::LIGHT {
match config.roles == ServiceRoles::LIGHT {
true => run_until_exit(&mut runtime, service::Factory::new_light(config, executor)?, exit)?,
false => run_until_exit(&mut runtime, service::Factory::new_full(config, executor)?, exit)?,
}
@@ -108,7 +123,7 @@ fn run_until_exit<C, E>(
e: E,
) -> error::Result<()>
where
C: service::Components,
C: substrate_service::Components,
E: IntoExit,
{
let (exit_send, exit) = exit_future::signal();
+133
View File
@@ -0,0 +1,133 @@
// Copyright 2018 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/>.
#![warn(unused_extern_crates)]
//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.
use std::sync::Arc;
use transaction_pool::{self, txpool::{Pool as TransactionPool}};
use node_primitives::Block;
use node_runtime::GenesisConfig;
use node_network::Protocol as DemoProtocol;
use substrate_service::{
FactoryFullConfiguration, LightComponents, FullComponents, FullBackend,
LightBackend, FullExecutor, LightExecutor
};
use network::import_queue::{BasicQueue, BlockOrigin, ImportBlock, Verifier};
use runtime_primitives::{traits::Block as BlockT};
use primitives::AuthorityId;
use node_executor;
// TODO: Remove me, when we have a functional consensus.
/// A verifier that doesn't actually do any checks
pub struct NoneVerifier;
/// This Verifiyer accepts all data as valid
impl<B: BlockT> Verifier<B> for NoneVerifier {
fn verify(
&self,
origin: BlockOrigin,
header: B::Header,
justification: Vec<u8>,
body: Option<Vec<B::Extrinsic>>
) -> Result<(ImportBlock<B>, Option<Vec<AuthorityId>>), String> {
Ok((ImportBlock {
origin,
header,
body,
finalized: true,
external_justification: justification,
internal_justification: vec![],
auxiliary: Vec::new(),
}, None))
}
}
construct_simple_service!(Service);
construct_service_factory! {
struct Factory {
Block = Block,
NetworkProtocol = DemoProtocol { |config| Ok(DemoProtocol::new()) },
RuntimeDispatch = node_executor::Executor,
FullTransactionPoolApi = transaction_pool::ChainApi<FullBackend<Self>, FullExecutor<Self>, Block>
{ |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) },
LightTransactionPoolApi = transaction_pool::ChainApi<LightBackend<Self>, LightExecutor<Self>, Block>
{ |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) },
Genesis = GenesisConfig,
Configuration = (),
FullService = Service<FullComponents<Self>>
{ |config, executor| Service::<FullComponents<Factory>>::new(config, executor) },
LightService = Service<LightComponents<Self>>
{ |config, executor| Service::<LightComponents<Factory>>::new(config, executor) },
ImportQueue = BasicQueue<Block, NoneVerifier>
{ |_, _| Ok(BasicQueue::new(Arc::new(NoneVerifier {}))) }
{ |_, _| Ok(BasicQueue::new(Arc::new(NoneVerifier {}))) },
}
}
#[cfg(test)]
mod tests {
#[cfg(feature = "rhd")]
fn test_sync() {
use {service_test, Factory};
use client::{ImportBlock, BlockOrigin};
let alice: Arc<ed25519::Pair> = Arc::new(Keyring::Alice.into());
let bob: Arc<ed25519::Pair> = Arc::new(Keyring::Bob.into());
let validators = vec![alice.public().0.into(), bob.public().0.into()];
let keys: Vec<&ed25519::Pair> = vec![&*alice, &*bob];
let offline = Arc::new(RwLock::new(OfflineTracker::new()));
let dummy_runtime = ::tokio::runtime::Runtime::new().unwrap();
let block_factory = |service: &<Factory as service::ServiceFactory>::FullService| {
let block_id = BlockId::number(service.client().info().unwrap().chain.best_number);
let parent_header = service.client().header(&block_id).unwrap().unwrap();
let consensus_net = ConsensusNetwork::new(service.network(), service.client().clone());
let proposer_factory = consensus::ProposerFactory {
client: service.client().clone(),
transaction_pool: service.transaction_pool().clone(),
network: consensus_net,
offline: offline.clone(),
force_delay: 0,
handle: dummy_runtime.executor(),
};
let (proposer, _, _) = proposer_factory.init(&parent_header, &validators, alice.clone()).unwrap();
let block = proposer.propose().expect("Error making test block");
ImportBlock {
origin: BlockOrigin::File,
external_justification: Vec::new(),
internal_justification: Vec::new(),
finalized: true,
body: Some(block.extrinsics),
header: block.header,
auxiliary: Vec::new(),
}
};
let extrinsic_factory = |service: &<Factory as service::ServiceFactory>::FullService| {
let payload = (0, Call::Balances(BalancesCall::transfer(RawAddress::Id(bob.public().0.into()), 69.into())), Era::immortal(), service.client().genesis_hash());
let signature = alice.sign(&payload.encode()).into();
let id = alice.public().0.into();
let xt = UncheckedExtrinsic {
signature: Some((RawAddress::Id(id), signature, payload.0, Era::immortal())),
function: payload.1,
}.encode();
let v: Vec<u8> = Decode::decode(&mut xt.as_slice()).unwrap();
OpaqueExtrinsic(v)
};
service_test::sync::<Factory, _, _>(chain_spec::integration_test_config(), block_factory, extrinsic_factory);
}
}