Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

BFT gossip #106

Merged
merged 5 commits into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 4 additions & 58 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion polkadot/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ log = "0.3"
hex-literal = "0.1"
triehash = "0.1"
ed25519 = { path = "../../substrate/ed25519" }
app_dirs = "1.1"
app_dirs = "1.2"
substrate-client = { path = "../../substrate/client" }
substrate-codec = { path = "../../substrate/codec" }
substrate-runtime-io = { path = "../../substrate/runtime-io" }
Expand Down
43 changes: 38 additions & 5 deletions polkadot/cli/src/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,48 @@ about: Polkadot Node Rust Implementation
args:
- log:
short: l
long: log
value_name: LOG_PATTERN
help: Sets a custom logging filter
takes_value: true
- base-path:
long: base-path
short: d
value_name: PATH
help: Specify custom base path
takes_value: true
- keystore-path:
value_name: KEYSTORE_PATH
help: specify custom keystore path
long: keystore-path
value_name: PATH
help: Specify custom keystore path
takes_value: true
- key:
long: key
value_name: STRING
help: Specify additional key seed
takes_value: true
subcommands:
- collator:
about: Run collator node
long: collator
help: Enable collator mode
takes_value: false
- validator:
about: Run validator node
long: validator
help: Enable validator mode
takes_value: false
- port:
long: port
value_name: PORT
help: Specify p2p protocol TCP port
takes_value: true
- rpc-port:
long: rpc-port
value_name: PORT
help: Specify RPC server TCP port
takes_value: true
- bootnodes:
long: bootnodes
value_name: URL
help: Specify a list of bootnodes
takes_value: true
multiple: true
subcommands:
61 changes: 49 additions & 12 deletions polkadot/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ extern crate log;
pub mod error;

use std::path::{Path, PathBuf};
use std::net::SocketAddr;

/// Parse command line arguments and start the node.
///
Expand All @@ -56,60 +57,96 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
T: Into<std::ffi::OsString> + Clone,
{
let yaml = load_yaml!("./cli.yml");
let matches = clap::App::from_yaml(yaml).version(crate_version!()).get_matches_from_safe(args)?;
let matches = match clap::App::from_yaml(yaml).version(crate_version!()).get_matches_from_safe(args) {
Ok(m) => m,
Err(ref e) if e.kind == clap::ErrorKind::VersionDisplayed => return Ok(()),
Err(ref e) if e.kind == clap::ErrorKind::HelpDisplayed || e.kind == clap::ErrorKind::VersionDisplayed => {
let _ = clap::App::from_yaml(yaml).print_long_help();
return Ok(());
}
Err(e) => return Err(e.into()),
};

// TODO [ToDr] Split parameters parsing from actual execution.
let log_pattern = matches.value_of("log").unwrap_or("");
init_logger(log_pattern);

let mut config = service::Configuration::default();

let base_path = matches.value_of("base-path")
.map(|x| Path::new(x).to_owned())
.unwrap_or_else(default_base_path);

config.keystore_path = matches.value_of("keystore")
.map(|x| Path::new(x).to_owned())
.unwrap_or_else(default_keystore_path)
.unwrap_or_else(|| keystore_path(&base_path))
.to_string_lossy()
.into();

let mut role = service::Role::FULL;
if let Some(_) = matches.subcommand_matches("collator") {
if matches.is_present("collator") {
info!("Starting collator.");
role = service::Role::COLLATOR;
}
else if let Some(_) = matches.subcommand_matches("validator") {
else if matches.is_present("validator") {
info!("Starting validator.");
role = service::Role::VALIDATOR;
}

config.roles = role;
config.network.boot_nodes = matches
.values_of("bootnodes")
.map_or(Default::default(), |v| v.map(|n| n.to_owned()).collect());
config.network.config_path = Some(network_path(&base_path).to_string_lossy().into());
config.network.net_config_path = config.network.config_path.clone();

let port = match matches.value_of("port") {
Some(port) => port.parse().expect("Invalid p2p port value specified."),
None => 30333,
};
config.network.listen_address = Some(SocketAddr::new("0.0.0.0".parse().unwrap(), port));

config.keys = matches.values_of("key").unwrap_or_default().map(str::to_owned).collect();

let service = service::Service::new(config)?;

let address = "127.0.0.1:9933".parse().unwrap();
let mut address: SocketAddr = "127.0.0.1:9933".parse().unwrap();
if let Some(port) = matches.value_of("rpc-port") {
let rpc_port: u16 = port.parse().expect("Invalid RPC port value specified.");
address.set_port(rpc_port);
}
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();

Ok(())
}

fn default_keystore_path() -> PathBuf {
fn keystore_path(base_path: &Path) -> PathBuf {
let mut path = base_path.to_owned();
path.push("keystore");
path
}

fn network_path(base_path: &Path) -> PathBuf {
let mut path = base_path.to_owned();
path.push("network");
path
}

fn default_base_path() -> PathBuf {
use app_dirs::{AppInfo, AppDataType};

let app_info = AppInfo {
name: "Polkadot",
author: "Parity Technologies",
};

app_dirs::get_app_dir(
app_dirs::get_app_root(
AppDataType::UserData,
&app_info,
"keystore",
).expect("app directories exist on all supported platforms; qed")
}

fn init_logger(pattern: &str) {
let mut builder = env_logger::LogBuilder::new();
// Disable info logging by default for some modules:
Expand Down
11 changes: 7 additions & 4 deletions polkadot/consensus/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use parking_lot::Mutex;
use substrate_network as net;
use tokio_core::reactor;
use client::BlockchainEvents;
use substrate_keyring::Keyring;
use primitives::{Hash, AuthorityId};
use primitives::block::{Id as BlockId, HeaderHash, Header};
use polkadot_primitives::parachain::{BlockData, Extrinsic, CandidateReceipt};
Expand Down Expand Up @@ -136,14 +135,18 @@ struct Network(Arc<net::ConsensusService>);

impl Service {
/// Create and start a new instance.
pub fn new<C>(client: Arc<C>, network: Arc<net::ConsensusService>, transaction_pool: Arc<Mutex<TransactionPool>>, best_header: &Header) -> Service
pub fn new<C>(
client: Arc<C>,
network: Arc<net::ConsensusService>,
transaction_pool: Arc<Mutex<TransactionPool>>,
key: ed25519::Pair,
best_header: &Header) -> Service
where C: BlockchainEvents + bft::BlockImport + bft::Authorities + PolkadotApi + Send + Sync + 'static
{

let best_header = best_header.clone();
let thread = thread::spawn(move || {
let mut core = reactor::Core::new().expect("tokio::Core could not be created");
let key = Arc::new(Keyring::One.into());
let key = Arc::new(key);
let factory = ProposerFactory {
client: client.clone(),
transaction_pool: transaction_pool.clone(),
Expand Down
Loading