Errors & warnings for inappropriate RPCs (#6029)

* Clarify function name

Function checks if sealing is currently underway, not to be confused
with checking whether the engine performs internal sealing.

* Error when work called on internal sealing engine

* Error submitting work for internal sealing engine

* Fix inverted bool and style grumbles

* Add can_produce_work_package to TestMinerService

* Error when setting engine signer on PoW chain

* Unit tests for engine signing

Setting engine signer should fail if chain does not seal internally
or client lacks account provider.

* Tweak TestMinerService

* Fix minor style grumbles
This commit is contained in:
Joseph Mark
2017-07-12 13:52:18 +07:00
committed by Gav Wood
parent 02f2c611d4
commit 0fca4f95d6
8 changed files with 75 additions and 13 deletions

View File

@@ -28,6 +28,7 @@ mod codes {
pub const NO_WORK: i64 = -32001;
pub const NO_AUTHOR: i64 = -32002;
pub const NO_NEW_WORK: i64 = -32003;
pub const NO_WORK_REQUIRED: i64 = -32004;
pub const UNKNOWN_ERROR: i64 = -32009;
pub const TRANSACTION_ERROR: i64 = -32010;
pub const EXECUTION_ERROR: i64 = -32015;
@@ -133,7 +134,7 @@ pub fn state_pruned() -> Error {
Error {
code: ErrorCode::ServerError(codes::UNSUPPORTED_REQUEST),
message: "This request is not supported because your node is running with state pruning. Run with --pruning=archive.".into(),
data: None
data: None,
}
}
@@ -145,7 +146,7 @@ pub fn exceptional() -> Error {
Error {
code: ErrorCode::ServerError(codes::EXCEPTION_ERROR),
message: "The execution failed due to an exception.".into(),
data: None
data: None,
}
}
@@ -153,7 +154,7 @@ pub fn no_work() -> Error {
Error {
code: ErrorCode::ServerError(codes::NO_WORK),
message: "Still syncing.".into(),
data: None
data: None,
}
}
@@ -161,7 +162,7 @@ pub fn no_new_work() -> Error {
Error {
code: ErrorCode::ServerError(codes::NO_NEW_WORK),
message: "Work has not changed.".into(),
data: None
data: None,
}
}
@@ -169,7 +170,15 @@ pub fn no_author() -> Error {
Error {
code: ErrorCode::ServerError(codes::NO_AUTHOR),
message: "Author not configured. Run Parity with --author to configure.".into(),
data: None
data: None,
}
}
pub fn no_work_required() -> Error {
Error {
code: ErrorCode::ServerError(codes::NO_WORK_REQUIRED),
message: "External work is only required for Proof of Work engines.".into(),
data: None,
}
}

View File

@@ -332,7 +332,7 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
}
fn is_mining(&self) -> Result<bool, Error> {
Ok(self.miner.is_sealing())
Ok(self.miner.is_currently_sealing())
}
fn hashrate(&self) -> Result<RpcU256, Error> {
@@ -553,6 +553,11 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
}
fn work(&self, no_new_work_timeout: Trailing<u64>) -> Result<Work, Error> {
if !self.miner.can_produce_work_package() {
warn!(target: "miner", "Cannot give work package - engine seals internally.");
return Err(errors::no_work_required())
}
let no_new_work_timeout = no_new_work_timeout.unwrap_or_default();
// check if we're still syncing and return empty strings in that case
@@ -602,6 +607,11 @@ impl<C, SN: ?Sized, S: ?Sized, M, EM> Eth for EthClient<C, SN, S, M, EM> where
}
fn submit_work(&self, nonce: RpcH64, pow_hash: RpcH256, mix_hash: RpcH256) -> Result<bool, Error> {
if !self.miner.can_produce_work_package() {
warn!(target: "miner", "Cannot submit work - engine seals internally.");
return Err(errors::no_work_required())
}
let nonce: H64 = nonce.into();
let pow_hash: H256 = pow_hash.into();
let mix_hash: H256 = mix_hash.into();

View File

@@ -207,6 +207,11 @@ impl MinerService for TestMinerService {
unimplemented!();
}
/// PoW chain - can produce work package
fn can_produce_work_package(&self) -> bool {
true
}
/// New chain head event. Restart mining operation.
fn update_sealing(&self, _chain: &MiningBlockChainClient) {
unimplemented!();
@@ -265,7 +270,7 @@ impl MinerService for TestMinerService {
self.last_nonces.read().get(address).cloned()
}
fn is_sealing(&self) -> bool {
fn is_currently_sealing(&self) -> bool {
false
}