Merge pull request #448 from paritytech/a5-improve-help

Default to default logging sync=info
This commit is contained in:
Svyatoslav Nikolsky 2017-09-01 16:23:22 +03:00 committed by GitHub
commit 5a20710066
5 changed files with 95 additions and 91 deletions

111
README.md
View File

@ -1,6 +1,4 @@
# parity-bitcoin # The Parity Bitcoin client.
The Parity Bitcoin client
[![Build Status][travis-image]][travis-url] [![Snap Status](https://build.snapcraft.io/badge/paritytech/parity-bitcoin.svg)](https://build.snapcraft.io/user/paritytech/parity-bitcoin) [![Build Status][travis-image]][travis-url] [![Snap Status](https://build.snapcraft.io/badge/paritytech/parity-bitcoin.svg)](https://build.snapcraft.io/user/paritytech/parity-bitcoin)
@ -39,7 +37,7 @@ Minimal supported version is `rustc 1.16.0 (30cf806ef 2017-03-10)`
#### Install rustc and cargo #### Install rustc and cargo
Both `rustc` and `cargo` are a part of rust toolchain. Both `rustc` and `cargo` are a part of rust tool-chain.
An easy way to install the stable binaries for Linux and Mac is to run this in your shell: An easy way to install the stable binaries for Linux and Mac is to run this in your shell:
@ -51,7 +49,7 @@ Windows binaries can be downloaded from [rust-lang website](https://www.rust-lan
#### Install C and C++ compilers #### Install C and C++ compilers
You will need the cc and gcc compilers to build some of the dependencies You will need the cc and gcc compilers to build some of the dependencies.
``` ```
sudo apt-get update sudo apt-get update
@ -60,14 +58,14 @@ sudo apt-get install build-essential
#### Clone and build pbtc #### Clone and build pbtc
Now let's clone `pbtc` and enter it's directory Now let's clone `pbtc` and enter it's directory:
``` ```
git clone https://github.com/paritytech/parity-bitcoin git clone https://github.com/paritytech/parity-bitcoin
cd parity-bitcoin cd parity-bitcoin
``` ```
`pbtc` can be build in two modes. `--debug` and `--release`. Debug is the default `pbtc` can be build in two modes. `--debug` and `--release`. Debug is the default.
``` ```
# builds pbtc in debug mode # builds pbtc in debug mode
@ -79,7 +77,7 @@ cargo build -p pbtc
cargo build -p pbtc --release cargo build -p pbtc --release
``` ```
`pbtc` is now available at either `./target/debug/pbtc` or `./target/release/pbtc` `pbtc` is now available at either `./target/debug/pbtc` or `./target/release/pbtc`.
## Installing the snap ## Installing the snap
@ -91,11 +89,11 @@ sudo snap install parity-bitcoin --edge
## Running tests ## Running tests
`pbtc` has internal unit tests and it conforms to external integration tests `pbtc` has internal unit tests and it conforms to external integration tests.
#### Running unit tests #### Running unit tests
Assuming that repo is already cloned, we can run unit tests with this command: Assuming that repository is already cloned, we can run unit tests with this command:
``` ```
./tools/test.sh ./tools/test.sh
@ -103,19 +101,19 @@ Assuming that repo is already cloned, we can run unit tests with this command:
#### Running external integration tests #### Running external integration tests
Running integration tests is automated, as regtests repo is one of the submodules. Let's download it first: Running integration tests is automated, as the regtests repository is one of the submodules. Let's download it first:
``` ```
git submodule update --init git submodule update --init
``` ```
Now we can run them Now we can run them:
``` ```
./tools/regtests.sh ./tools/regtests.sh
``` ```
It's also possible to run regtests manually It's also possible to run regtests manually:
``` ```
# let's start pbtc in regtest compatible mode # let's start pbtc in regtest compatible mode
@ -131,78 +129,83 @@ java -jar pull-tests-f56eec3.jar
## Going online ## Going online
By default parity connects to bitcoind seednodes. Full list is [here](./pbtc/seednodes.rs) By default parity connects to bitcoind-seednodes. Full list is [here](./pbtc/seednodes.rs).
To start syncing the mainnet, just start the client To start syncing the main network, just start the client:
``` ```
./target/release/pbtc ./target/release/pbtc
``` ```
To start syncing the testnet To start syncing the testnet:
``` ```
./target/release/pbtc --testnet ./target/release/pbtc --testnet
``` ```
To print syncing progress add `--print-to-console` flag To not print any syncing progress add `--quiet` flag:
``` ```
./target/release/pbtc --print-to-console ./target/release/pbtc --quiet
``` ```
## Importing bitcoind database ## Importing bitcoind database
It it is possible to import existing bitcoind database: It it is possible to import existing `bitcoind` database:
``` ```
# where $BITCOIND_DB is path to your bitcoind database eg. "/Users/marek/Library/Application Support" # where $BITCOIND_DB is path to your bitcoind database, e.g., "/Users/user/Library/Application Support"
./target/release/pbtc --print-to-console import "$BITCOIND_DB/Bitcoin/blocks" ./target/release/pbtc import "$BITCOIND_DB/Bitcoin/blocks"
``` ```
By default import verifies imported the blocks. You can disable this, by adding `--skip-verification flag. By default import verifies imported the blocks. You can disable this, by adding `--skip-verification` flag.
``` ```
./target/release/pbtc --print-to-console import "#BITCOIND_DB/Bitcoin/blocks" --skip-verification ./target/release/pbtc import "#BITCOIND_DB/Bitcoin/blocks" --skip-verification
``` ```
## Command line interface ## Command line interface
Full list of cli options, which is available under `pbtc --help` Full list of CLI options, which is available under `pbtc --help`:
``` ```
pbtc 0.1.0 pbtc 0.1.0
Parity Technologies <admin@parity.io> Parity Technologies <info@parity.io>
Parity bitcoin client Parity Bitcoin client
USAGE: USAGE:
pbtc [FLAGS] [OPTIONS] [SUBCOMMAND] pbtc [FLAGS] [OPTIONS] [SUBCOMMAND]
FLAGS: FLAGS:
-h, --help Prints help information --bitcoin-cash Use Bitcoin Cash verification rules.
--no-jsonrpc Disable the JSON-RPC API server -h, --help Prints help information
--print-to-console Send sync info to console --no-jsonrpc Disable the JSON-RPC API server.
--regtest Use private network for regtest -q, --quiet Do not show any synchronization information in the console.
--testnet Use the test network --regtest Use a private network for regression tests.
-V, --version Prints version information --segwit2x Enable SegWit2x verification rules.
--testnet Use the test network (Testnet3).
-V, --version Prints version information
OPTIONS: OPTIONS:
--blocknotify <command> Execute command when the best block changes (%s in cmd is replaced by block hash) --blocknotify <COMMAND> Execute COMMAND when the best block changes (%s in COMMAND is replaced by the block hash).
-c, --connect <IP> Connect only to the specified node -c, --connect <IP> Connect only to the specified node.
-d, --data-dir <PATH> Specify the database & configuration directory PATH -d, --data-dir <PATH> Specify the database and configuration directory PATH.
--db-cache <SIZE> Sets db cache size --db-cache <SIZE> Sets the database cache size.
--jsonrpc-apis <APIS> Specify the APIs available through the JSONRPC interface. APIS is a comma-delimited list of API name. Available APIs are blockchain, network, miner, raw. --jsonrpc-apis <APIS> Specify the APIs available through the JSONRPC interface. APIS is a comma-delimited list of API names.
--jsonrpc-cors <URL> Specify CORS header for JSON-RPC API responses --jsonrpc-cors <URL> Specify CORS header for JSON-RPC API responses.
--jsonrpc-hosts <HOSTS> List of allowed Host header values --jsonrpc-hosts <HOSTS> List of allowed Host header values.
--jsonrpc-interface <INTERFACE> The hostname portion of the JSONRPC API server --jsonrpc-interface <INTERFACE> The hostname portion of the JSONRPC API server.
--jsonrpc-port <PORT> The port portion of the JSONRPC API server --jsonrpc-port <PORT> Specify the PORT for the JSONRPC API server.
--only-net <NET> Only connect to nodes in network <NET> (ipv4 or ipv6) --only-net <NET> Only connect to nodes in network version <NET> (ipv4 or ipv6).
--port <PORT> Listen for connections on PORT --port <PORT> Listen for connections on PORT.
-s, --seednode <IP> Connect to a node to retrieve peer addresses, and disconnect -s, --seednode <IP> Connect to a seed-node to retrieve peer addresses, and disconnect.
--verification-edge <BLOCK> Non-default verification-level is applied until a block with given hash is met.
--verification-level <LEVEL> Sets the Blocks verification level to full (default), header (scripts are not verified), or none (no verification at all).
SUBCOMMANDS: SUBCOMMANDS:
help Prints this message or the help of the given subcommand(s) help Prints this message or the help of the given subcommand(s)
import Import blocks from bitcoin core database import Import blocks from a Bitcoin Core database.
rollback Rollback the database to given canonical-chain block.
``` ```
## JSON-RPC ## JSON-RPC
@ -328,19 +331,15 @@ Adds transaction to the memory pool && relays it to the peers.
## Logging ## Logging
This is a section only for dev / power users. This is a section only for developers and power users.
You can enable detailed client logging by setting env variable `RUST_LOG` You can enable detailed client logging by setting the environment variable `RUST_LOG`, e.g.,
eg.
``` ```
RUST_LOG=verification=info ./target/release/pbtc RUST_LOG=verification=info ./target/release/pbtc
``` ```
`pbtc` started with this env variable will print all logs comming from `verification` module with verbosity `info` or higher `pbtc` started with this environment variable will print all logs coming from `verification` module with verbosity `info` or higher. Available log levels are:
Available log levels:
- `error` - `error`
- `warn` - `warn`
@ -348,14 +347,12 @@ Available log levels:
- `debug` - `debug`
- `trace` - `trace`
It's also possible to start logging from multiple modules in the same time It's also possible to start logging from multiple modules in the same time:
``` ```
RUST_LOG=sync=trace,p2p=trace,verification=trace,db=trace RUST_LOG=sync=trace,p2p=trace,verification=trace,db=trace ./target/release/pbtc
``` ```
*note* `RUST_LOG` does not work together with command line option `--print-to-console`
## Internal documentation ## Internal documentation
Once released, `pbtc` documentation will be available [here][doc-url]. Meanwhile it's only possible to build it locally: Once released, `pbtc` documentation will be available [here][doc-url]. Meanwhile it's only possible to build it locally:

View File

@ -3,6 +3,7 @@ extern crate log;
extern crate env_logger; extern crate env_logger;
extern crate time; extern crate time;
use std::env;
use ansi_term::Colour as Color; use ansi_term::Colour as Color;
use log::{LogRecord, LogLevel}; use log::{LogRecord, LogLevel};
use env_logger::LogBuilder; use env_logger::LogBuilder;
@ -46,7 +47,12 @@ impl LogFormatter for DateAndColorLogFormatter {
pub fn init<T>(filters: &str, formatter: T) where T: LogFormatter { pub fn init<T>(filters: &str, formatter: T) where T: LogFormatter {
let mut builder = LogBuilder::new(); let mut builder = LogBuilder::new();
builder.parse(filters); let filters = match env::var("RUST_LOG") {
Ok(env_filters) => format!("{},{}", env_filters, filters),
Err(_) => filters.into(),
};
builder.parse(&filters);
builder.format(move |record| formatter.format(record)); builder.format(move |record| formatter.format(record));
builder.init().expect("Logger can be initialized only once"); builder.init().expect("Logger can be initialized only once");
} }

View File

@ -1,109 +1,110 @@
name: pbtc name: pbtc
version: "0.1.0" version: "0.1.0"
author: Parity Technologies <admin@parity.io> author: Parity Technologies <info@parity.io>
about: Parity bitcoin client about: Parity Bitcoin client
args: args:
- testnet: - testnet:
long: testnet long: testnet
help: Use the test network help: Use the test network (Testnet3).
- regtest: - regtest:
long: regtest long: regtest
help: Use private network for regtest help: Use a private network for regression tests.
- segwit2x: - segwit2x:
long: segwit2x long: segwit2x
help: Enable SegWit2x verification rules help: Enable SegWit2x verification rules.
- bitcoin-cash: - bitcoin-cash:
long: bitcoin-cash long: bitcoin-cash
help: Use Bitcoin Cash verification rules help: Use Bitcoin Cash verification rules.
- connect: - connect:
short: c short: c
long: connect long: connect
value_name: IP value_name: IP
help: Connect only to the specified node help: Connect only to the specified node.
takes_value: true takes_value: true
- seednode: - seednode:
short: s short: s
long: seednode long: seednode
value_name: IP value_name: IP
help: Connect to a node to retrieve peer addresses, and disconnect help: Connect to a seed-node to retrieve peer addresses, and disconnect.
takes_value: true takes_value: true
- port: - port:
long: port long: port
value_name: PORT value_name: PORT
help: Listen for connections on PORT help: Listen for connections on PORT.
takes_value: true takes_value: true
- print-to-console: - quiet:
long: print-to-console short: q
help: Send sync info to console long: quiet
help: Do not show any synchronization information in the console.
- data-dir: - data-dir:
short: d short: d
long: data-dir long: data-dir
value_name: PATH value_name: PATH
help: Specify the database & configuration directory PATH help: Specify the database and configuration directory PATH.
takes_value: true takes_value: true
- db-cache: - db-cache:
long: db-cache long: db-cache
value_name: SIZE value_name: SIZE
help: Sets db cache size help: Sets the database cache size.
takes_value: true takes_value: true
- only-net: - only-net:
long: only-net long: only-net
value_name: NET value_name: NET
help: Only connect to nodes in network <NET> (ipv4 or ipv6) help: Only connect to nodes in network version <NET> (ipv4 or ipv6).
takes_value: true takes_value: true
- no-jsonrpc: - no-jsonrpc:
long: no-jsonrpc long: no-jsonrpc
help: Disable the JSON-RPC API server help: Disable the JSON-RPC API server.
- jsonrpc-port: - jsonrpc-port:
long: jsonrpc-port long: jsonrpc-port
help: The port portion of the JSONRPC API server help: Specify the PORT for the JSONRPC API server.
takes_value: true takes_value: true
value_name: PORT value_name: PORT
- jsonrpc-interface: - jsonrpc-interface:
long: jsonrpc-interface long: jsonrpc-interface
help: The hostname portion of the JSONRPC API server help: The hostname portion of the JSONRPC API server.
takes_value: true takes_value: true
value_name: INTERFACE value_name: INTERFACE
- jsonrpc-cors: - jsonrpc-cors:
long: jsonrpc-cors long: jsonrpc-cors
help: Specify CORS header for JSON-RPC API responses help: Specify CORS header for JSON-RPC API responses.
takes_value: true takes_value: true
value_name: URL value_name: URL
- jsonrpc-apis: - jsonrpc-apis:
long: jsonrpc-apis long: jsonrpc-apis
help: Specify the APIs available through the JSONRPC interface. APIS is a comma-delimited list of API name. Available APIs are blockchain, network, miner, raw. help: Specify the APIs available through the JSONRPC interface. APIS is a comma-delimited list of API names. Available APIs are blockchain, network, miner, raw.
takes_value: true takes_value: true
value_name: APIS value_name: APIS
- jsonrpc-hosts: - jsonrpc-hosts:
long: jsonrpc-hosts long: jsonrpc-hosts
help: List of allowed Host header values help: List of allowed Host header values.
takes_value: true takes_value: true
value_name: HOSTS value_name: HOSTS
- blocknotify: - blocknotify:
long: blocknotify long: blocknotify
help: Execute command when the best block changes (%s in cmd is replaced by block hash) help: Execute COMMAND when the best block changes (%s in COMMAND is replaced by the block hash).
takes_value: true takes_value: true
value_name: command value_name: COMMAND
- verification-level: - verification-level:
long: verification-level long: verification-level
help: Blocks verification level - full (default), header (scripts are not verified), none (no verification at all) help: Sets the Blocks verification level to full (default), header (scripts are not verified), or none (no verification at all).
takes_value: true takes_value: true
value_name: LEVEL value_name: LEVEL
- verification-edge: - verification-edge:
long: verification-edge long: verification-edge
help: Non-default verification-level is applied until block with given hash is met. help: Non-default verification-level is applied until a block with given hash is met.
takes_value: true takes_value: true
value_name: BLOCK value_name: BLOCK
subcommands: subcommands:
- import: - import:
about: Import blocks from bitcoin core database about: Import blocks from a Bitcoin Core database.
args: args:
- PATH: - PATH:
required: true required: true
help: Path of the bitcoin core database help: Path of the Bitcoin Core database.
- rollback: - rollback:
about: Rollback database to given canon-chain block about: Rollback the database to given canonical-chain block.
args: args:
- BLOCK: - BLOCK:
required: true required: true
help: Either block hash, or block number help: Either block hash, or block number.

View File

@ -18,7 +18,7 @@ pub struct Config {
pub port: u16, pub port: u16,
pub connect: Option<net::SocketAddr>, pub connect: Option<net::SocketAddr>,
pub seednodes: Vec<String>, pub seednodes: Vec<String>,
pub print_to_console: bool, pub quiet: bool,
pub inbound_connections: u32, pub inbound_connections: u32,
pub outbound_connections: u32, pub outbound_connections: u32,
pub p2p_threads: usize, pub p2p_threads: usize,
@ -34,7 +34,7 @@ pub struct Config {
pub const DEFAULT_DB_CACHE: usize = 512; pub const DEFAULT_DB_CACHE: usize = 512;
pub fn parse(matches: &clap::ArgMatches) -> Result<Config, String> { pub fn parse(matches: &clap::ArgMatches) -> Result<Config, String> {
let print_to_console = matches.is_present("print-to-console"); let quiet = matches.is_present("quiet");
let magic = match (matches.is_present("testnet"), matches.is_present("regtest")) { let magic = match (matches.is_present("testnet"), matches.is_present("regtest")) {
(true, false) => Magic::Testnet, (true, false) => Magic::Testnet,
(false, true) => Magic::Regtest, (false, true) => Magic::Regtest,
@ -139,7 +139,7 @@ pub fn parse(matches: &clap::ArgMatches) -> Result<Config, String> {
}; };
let config = Config { let config = Config {
print_to_console: print_to_console, quiet: quiet,
magic: magic, magic: magic,
consensus: consensus, consensus: consensus,
services: services, services: services,

View File

@ -52,7 +52,7 @@ fn run() -> Result<(), String> {
let matches = clap::App::from_yaml(yaml).get_matches(); let matches = clap::App::from_yaml(yaml).get_matches();
let cfg = try!(config::parse(&matches)); let cfg = try!(config::parse(&matches));
if cfg.print_to_console { if !cfg.quiet {
if cfg!(windows) { if cfg!(windows) {
logs::init(LOG_INFO, logs::DateLogFormatter); logs::init(LOG_INFO, logs::DateLogFormatter);
} else { } else {