mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 18:01:03 +00:00
Polkadot service (#82)
* Block import notifications * Build fix * Consensus messages supported in the networking * Started consensus service * BFT service * Transaction propagation * Polkadot service * CLI integration * Build fix * Added signatures validation * Removed executor argument * Refactored steam loops; Queue size increased * Limit queue size * Fixed doc comment * Fixed wasm build * Fixed wasm build * Check id properly
This commit is contained in:
committed by
Robert Habermeier
parent
96fb93b09c
commit
471761f4b6
@@ -30,10 +30,8 @@ extern crate substrate_rpc_servers as rpc;
|
||||
extern crate polkadot_primitives;
|
||||
extern crate polkadot_executor;
|
||||
extern crate polkadot_runtime;
|
||||
extern crate polkadot_keystore as keystore;
|
||||
extern crate polkadot_service as service;
|
||||
|
||||
#[macro_use]
|
||||
extern crate hex_literal;
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
#[macro_use]
|
||||
@@ -45,11 +43,6 @@ pub mod error;
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use codec::Slicable;
|
||||
use polkadot_runtime::genesismap::{additional_storage_with_genesis, GenesisConfig};
|
||||
use client::genesis;
|
||||
use keystore::Store as Keystore;
|
||||
|
||||
/// Parse command line arguments and start the node.
|
||||
///
|
||||
/// IANA unassigned port ranges that we could use:
|
||||
@@ -69,52 +62,33 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
|
||||
let log_pattern = matches.value_of("log").unwrap_or("");
|
||||
init_logger(log_pattern);
|
||||
|
||||
// Create client
|
||||
let executor = polkadot_executor::Executor::new();
|
||||
let mut storage = Default::default();
|
||||
let god_key = hex!["3d866ec8a9190c8343c2fc593d21d8a6d0c5c4763aaab2349de3a6111d64d124"];
|
||||
let mut config = service::Configuration::default();
|
||||
|
||||
let genesis_config = GenesisConfig {
|
||||
validators: vec![god_key.clone()],
|
||||
authorities: vec![god_key.clone()],
|
||||
balances: vec![(god_key.clone(), 1u64 << 63)].into_iter().collect(),
|
||||
block_time: 5, // 5 second block time.
|
||||
session_length: 720, // that's 1 hour per session.
|
||||
sessions_per_era: 24, // 24 hours per era.
|
||||
bonding_duration: 90, // 90 days per bond.
|
||||
approval_ratio: 667, // 66.7% approvals required for legislation.
|
||||
};
|
||||
|
||||
let prepare_genesis = || {
|
||||
storage = genesis_config.genesis_map();
|
||||
let block = genesis::construct_genesis_block(&storage);
|
||||
storage.extend(additional_storage_with_genesis(&block));
|
||||
(primitives::block::Header::decode(&mut block.header.encode().as_ref()).expect("to_vec() always gives a valid serialisation; qed"), storage.into_iter().collect())
|
||||
};
|
||||
|
||||
let keystore_path = matches.value_of("keystore")
|
||||
config.keystore_path = matches.value_of("keystore")
|
||||
.map(|x| Path::new(x).to_owned())
|
||||
.unwrap_or_else(default_keystore_path);
|
||||
|
||||
let _keystore = Keystore::open(keystore_path).map_err(::error::ErrorKind::Keystore)?;
|
||||
let client = client::new_in_mem(executor, prepare_genesis)?;
|
||||
|
||||
let address = "127.0.0.1:9933".parse().unwrap();
|
||||
let handler = rpc::rpc_handler(client);
|
||||
let server = rpc::start_http(&address, handler)?;
|
||||
.unwrap_or_else(default_keystore_path)
|
||||
.to_string_lossy()
|
||||
.into();
|
||||
|
||||
let mut role = service::Role::FULL;
|
||||
if let Some(_) = matches.subcommand_matches("collator") {
|
||||
info!("Starting collator.");
|
||||
server.wait();
|
||||
return Ok(());
|
||||
role = service::Role::COLLATOR;
|
||||
}
|
||||
|
||||
if let Some(_) = matches.subcommand_matches("validator") {
|
||||
else if let Some(_) = matches.subcommand_matches("validator") {
|
||||
info!("Starting validator.");
|
||||
server.wait();
|
||||
return Ok(());
|
||||
role = service::Role::VALIDATOR;
|
||||
}
|
||||
|
||||
config.roles = role;
|
||||
|
||||
let service = service::Service::new(config)?;
|
||||
|
||||
let address = "127.0.0.1:9933".parse().unwrap();
|
||||
let handler = rpc::rpc_handler(service.client());
|
||||
let server = rpc::start_http(&address, handler)?;
|
||||
|
||||
server.wait();
|
||||
println!("No command given.\n");
|
||||
let _ = clap::App::from_yaml(yaml).print_long_help();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user