Skip to content

Commit

Permalink
Report 0 hashrate when the mining coordinator doesn't support mining (P…
Browse files Browse the repository at this point in the history
…egaSysEng#1744)

Fixes compatibility with ethstats.net reporting for PoA networks (specifically Görli).
  • Loading branch information
ajsutton committed Jul 25, 2019
1 parent 7f6e729 commit 7a1e75b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ default Optional<Address> getCoinbase() {
}

default Optional<Long> hashesPerSecond() {
throw new UnsupportedOperationException(
"Current consensus mechanism prevents querying of hashrate.");
return Optional.empty();
}

default Optional<EthHashSolverInputs> getWorkDefinition() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import tech.pegasys.pantheon.ethereum.blockcreation.MiningCoordinator;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcMethod;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.results.Quantity;
Expand All @@ -38,11 +36,7 @@ public String getName() {

@Override
public JsonRpcResponse response(final JsonRpcRequest req) {
try {
final Optional<Long> hashesPerSecond = miningCoordinator.hashesPerSecond();
return new JsonRpcSuccessResponse(req.getId(), Quantity.create(hashesPerSecond.orElse(0L)));
} catch (final UnsupportedOperationException ex) {
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.INVALID_REQUEST);
}
final Optional<Long> hashesPerSecond = miningCoordinator.hashesPerSecond();
return new JsonRpcSuccessResponse(req.getId(), Quantity.create(hashesPerSecond.orElse(0L)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

import tech.pegasys.pantheon.ethereum.blockcreation.EthHashMiningCoordinator;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;

Expand Down Expand Up @@ -68,17 +66,6 @@ public void shouldReturnZeroWhenMiningCoordinatorDoesNotHaveHashes() {
assertThat(actualResponse).isEqualToComparingFieldByField(expectedResponse);
}

@Test
public void shouldReturnErrorWhenMiningCoordinatorDoesNotSupportHashing() {
final JsonRpcRequest request = requestWithParams();
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(request.getId(), JsonRpcError.INVALID_REQUEST);
when(miningCoordinator.hashesPerSecond()).thenThrow(UnsupportedOperationException.class);

final JsonRpcResponse actualResponse = method.response(request);
assertThat(actualResponse).isEqualToComparingFieldByField(expectedResponse);
}

private JsonRpcRequest requestWithParams() {
return new JsonRpcRequest(JSON_RPC_VERSION, ETH_METHOD, new Object[] {});
}
Expand Down

0 comments on commit 7a1e75b

Please sign in to comment.