Merge branch 'master' into miner-no-default
Conflicts: ethcore/src/miner/miner.rs parity/main.rs
This commit is contained in:
@@ -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<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
C: MiningBlockChainClient + 'static,
|
||||
S: SyncProvider + 'static,
|
||||
@@ -474,6 +482,10 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> 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());
|
||||
|
||||
@@ -72,6 +72,10 @@ impl<C, M> Ethcore for EthcoreClient<C, M> where M: MinerService + 'static, C: M
|
||||
to_value(&take_weak!(self.miner).gas_floor_target())
|
||||
}
|
||||
|
||||
fn gas_ceil_target(&self, _: Params) -> Result<Value, Error> {
|
||||
to_value(&take_weak!(self.miner).gas_ceil_target())
|
||||
}
|
||||
|
||||
fn dev_logs(&self, _params: Params) -> Result<Value, Error> {
|
||||
let logs = self.logger.logs();
|
||||
to_value(&logs.deref().as_slice())
|
||||
|
||||
@@ -52,8 +52,15 @@ impl<M> EthcoreSet for EthcoreSetClient<M> where M: MinerService + 'static {
|
||||
}
|
||||
|
||||
fn set_gas_floor_target(&self, params: Params) -> Result<Value, Error> {
|
||||
from_params::<(U256,)>(params).and_then(|(gas_floor_target,)| {
|
||||
take_weak!(self.miner).set_gas_floor_target(gas_floor_target);
|
||||
from_params::<(U256,)>(params).and_then(|(target,)| {
|
||||
take_weak!(self.miner).set_gas_floor_target(target);
|
||||
to_value(&true)
|
||||
})
|
||||
}
|
||||
|
||||
fn set_gas_ceil_target(&self, params: Params) -> Result<Value, Error> {
|
||||
from_params::<(U256,)>(params).and_then(|(target,)| {
|
||||
take_weak!(self.miner).set_gas_ceil_target(target);
|
||||
to_value(&true)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -39,7 +39,7 @@ pub struct TestMinerService {
|
||||
pub last_nonces: RwLock<HashMap<Address, U256>>,
|
||||
|
||||
min_gas_price: RwLock<U256>,
|
||||
gas_floor_target: RwLock<U256>,
|
||||
gas_range_target: RwLock<(U256, U256)>,
|
||||
author: RwLock<Address>,
|
||||
extra_data: RwLock<Bytes>,
|
||||
limit: RwLock<usize>,
|
||||
@@ -54,7 +54,7 @@ impl Default for TestMinerService {
|
||||
pending_receipts: Mutex::new(BTreeMap::new()),
|
||||
last_nonces: RwLock::new(HashMap::new()),
|
||||
min_gas_price: RwLock::new(U256::from(20_000_000)),
|
||||
gas_floor_target: RwLock::new(U256::from(12345)),
|
||||
gas_range_target: RwLock::new((U256::from(12345), U256::from(54321))),
|
||||
author: RwLock::new(Address::zero()),
|
||||
extra_data: RwLock::new(vec![1, 2, 3, 4]),
|
||||
limit: RwLock::new(1024),
|
||||
@@ -81,9 +81,14 @@ impl MinerService for TestMinerService {
|
||||
*self.extra_data.write().unwrap() = extra_data;
|
||||
}
|
||||
|
||||
/// Set the gas limit we wish to target when sealing a new block.
|
||||
/// Set the lower gas limit we wish to target when sealing a new block.
|
||||
fn set_gas_floor_target(&self, target: U256) {
|
||||
*self.gas_floor_target.write().unwrap() = target;
|
||||
self.gas_range_target.write().unwrap().0 = target;
|
||||
}
|
||||
|
||||
/// Set the upper gas limit we wish to target when sealing a new block.
|
||||
fn set_gas_ceil_target(&self, target: U256) {
|
||||
self.gas_range_target.write().unwrap().1 = target;
|
||||
}
|
||||
|
||||
fn set_minimal_gas_price(&self, min_gas_price: U256) {
|
||||
@@ -111,7 +116,11 @@ impl MinerService for TestMinerService {
|
||||
}
|
||||
|
||||
fn gas_floor_target(&self) -> U256 {
|
||||
*self.gas_floor_target.read().unwrap()
|
||||
self.gas_range_target.read().unwrap().0
|
||||
}
|
||||
|
||||
fn gas_ceil_target(&self) -> U256 {
|
||||
self.gas_range_target.read().unwrap().1
|
||||
}
|
||||
|
||||
/// Imports transactions to transaction queue.
|
||||
|
||||
@@ -30,6 +30,9 @@ pub trait Ethcore: Sized + Send + Sync + 'static {
|
||||
/// Returns mining gas floor target.
|
||||
fn gas_floor_target(&self, _: Params) -> Result<Value, Error>;
|
||||
|
||||
/// Returns mining gas floor cap.
|
||||
fn gas_ceil_target(&self, _: Params) -> Result<Value, Error>;
|
||||
|
||||
/// Returns minimal gas price for transaction to be included in queue.
|
||||
fn min_gas_price(&self, _: Params) -> Result<Value, Error>;
|
||||
|
||||
@@ -70,6 +73,7 @@ pub trait Ethcore: Sized + Send + Sync + 'static {
|
||||
|
||||
delegate.add_method("ethcore_extraData", Ethcore::extra_data);
|
||||
delegate.add_method("ethcore_gasFloorTarget", Ethcore::gas_floor_target);
|
||||
delegate.add_method("ethcore_gasCeilTarget", Ethcore::gas_ceil_target);
|
||||
delegate.add_method("ethcore_minGasPrice", Ethcore::min_gas_price);
|
||||
delegate.add_method("ethcore_transactionsLimit", Ethcore::transactions_limit);
|
||||
delegate.add_method("ethcore_devLogs", Ethcore::dev_logs);
|
||||
|
||||
@@ -28,6 +28,9 @@ pub trait EthcoreSet: Sized + Send + Sync + 'static {
|
||||
/// Sets new gas floor target for mined blocks.
|
||||
fn set_gas_floor_target(&self, _: Params) -> Result<Value, Error>;
|
||||
|
||||
/// Sets new gas ceiling target for mined blocks.
|
||||
fn set_gas_ceil_target(&self, _: Params) -> Result<Value, Error>;
|
||||
|
||||
/// Sets new extra data for mined blocks.
|
||||
fn set_extra_data(&self, _: Params) -> Result<Value, Error>;
|
||||
|
||||
@@ -54,6 +57,7 @@ pub trait EthcoreSet: Sized + Send + Sync + 'static {
|
||||
let mut delegate = IoDelegate::new(Arc::new(self));
|
||||
delegate.add_method("ethcore_setMinGasPrice", EthcoreSet::set_min_gas_price);
|
||||
delegate.add_method("ethcore_setGasFloorTarget", EthcoreSet::set_gas_floor_target);
|
||||
delegate.add_method("ethcore_setGasCeilTarget", EthcoreSet::set_gas_ceil_target);
|
||||
delegate.add_method("ethcore_setExtraData", EthcoreSet::set_extra_data);
|
||||
delegate.add_method("ethcore_setAuthor", EthcoreSet::set_author);
|
||||
delegate.add_method("ethcore_setTransactionsLimit", EthcoreSet::set_transactions_limit);
|
||||
|
||||
Reference in New Issue
Block a user