From 516b01532594db9af1a7a3532532b8af8b6b2c13 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 26 Jun 2016 22:02:17 +0200 Subject: [PATCH] Don't mine without --author (#1436) Requires --author to be set before mining is allowed to happen. --- parity/cli.rs | 8 ++++---- parity/configuration.rs | 11 ++++++----- parity/main.rs | 2 +- rpc/src/v1/impls/eth.rs | 12 ++++++++++++ rpc/src/v1/impls/mod.rs | 3 ++- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/parity/cli.rs b/parity/cli.rs index b5d16e92b..29333fe9a 100644 --- a/parity/cli.rs +++ b/parity/cli.rs @@ -128,6 +128,9 @@ API and Console Options: output on start up. This will prevent it. Sealing/Mining Options: + --author ADDRESS Specify the block author (aka "coinbase") address + for sending block rewards from sealed blocks. + NOTE: MINING WILL NOT WORK WITHOUT THIS OPTION. --force-sealing Force the node to author new blocks as if it were always sealing/mining. --usd-per-tx USD Amount of USD to be paid for a basic transaction @@ -141,9 +144,6 @@ Sealing/Mining Options: block [default: 3141592]. --gas-cap GAS A cap on how large we will raise the gas limit per block due to transaction volume [default: 3141592]. - --author ADDRESS Specify the block author (aka "coinbase") address - for sending block rewards from sealed blocks - [default: 0037a6b811ffeb6e072da21179d11b1406371c63]. --extra-data STRING Specify a custom extra-data for authored blocks, no more than 32 characters. --tx-limit LIMIT Limit of transactions kept in the queue (waiting to @@ -283,7 +283,7 @@ pub struct Args { pub flag_signer_path: String, pub flag_no_token: bool, pub flag_force_sealing: bool, - pub flag_author: String, + pub flag_author: Option, pub flag_usd_per_tx: String, pub flag_usd_per_eth: String, pub flag_gas_floor_target: String, diff --git a/parity/configuration.rs b/parity/configuration.rs index 012e41a53..43a7fcd3c 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -67,11 +67,12 @@ impl Configuration { self.args.flag_maxpeers.unwrap_or(self.args.flag_peers) as u32 } - pub fn author(&self) -> Address { - let d = self.args.flag_etherbase.as_ref().unwrap_or(&self.args.flag_author); - Address::from_str(clean_0x(d)).unwrap_or_else(|_| { - die!("{}: Invalid address for --author. Must be 40 hex characters, with or without the 0x at the beginning.", d) - }) + pub fn author(&self) -> Option
{ + self.args.flag_etherbase.as_ref() + .or(self.args.flag_author.as_ref()) + .map(|d| Address::from_str(clean_0x(d)).unwrap_or_else(|_| { + die!("{}: Invalid address for --author. Must be 40 hex characters, with or without the 0x at the beginning.", d) + })) } pub fn gas_floor_target(&self) -> U256 { diff --git a/parity/main.rs b/parity/main.rs index 7d39143cb..cecb0e0a1 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -209,7 +209,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig) // Miner let miner = Miner::with_accounts(conf.args.flag_force_sealing, conf.spec(), account_service.clone()); - miner.set_author(conf.author()); + miner.set_author(conf.author().unwrap_or(Default::default())); miner.set_gas_floor_target(conf.gas_floor_target()); miner.set_gas_ceil_target(conf.gas_ceil_target()); miner.set_extra_data(conf.extra_data()); diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index f3a59b698..9b1f06416 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -225,6 +225,14 @@ fn no_work_err() -> Error { } } +fn no_author_err() -> Error { + Error { + code: ErrorCode::ServerError(error_codes::NO_AUTHOR_CODE), + message: "Author not configured. Run parity with --author to configure.".into(), + data: None + } +} + impl Eth for EthClient where C: MiningBlockChainClient + 'static, S: SyncProvider + 'static, @@ -474,6 +482,10 @@ impl Eth for EthClient where } let miner = take_weak!(self.miner); + if miner.author().is_zero() { + warn!(target: "miner", "Cannot give work package - no author is configured. Use --author to configure!"); + return Err(no_author_err()) + } miner.map_sealing_work(client.deref(), |b| { let pow_hash = b.hash(); let target = Ethash::difficulty_to_boundary(b.block().header().difficulty()); diff --git a/rpc/src/v1/impls/mod.rs b/rpc/src/v1/impls/mod.rs index 66a5b9c58..fdd2de8fa 100644 --- a/rpc/src/v1/impls/mod.rs +++ b/rpc/src/v1/impls/mod.rs @@ -68,7 +68,8 @@ mod error_codes { // NOTE [ToDr] Codes from [-32099, -32000] pub const UNSUPPORTED_REQUEST_CODE: i64 = -32000; pub const NO_WORK_CODE: i64 = -32001; - pub const UNKNOWN_ERROR: i64 = -32002; + pub const NO_AUTHOR_CODE: i64 = -32002; + pub const UNKNOWN_ERROR: i64 = -32009; pub const TRANSACTION_ERROR: i64 = -32010; pub const ACCOUNT_LOCKED: i64 = -32020; pub const SIGNER_DISABLED: i64 = -32030;