diff --git a/ethereum/blockcreation/src/main/java/tech/pegasys/pantheon/ethereum/blockcreation/MiningCoordinator.java b/ethereum/blockcreation/src/main/java/tech/pegasys/pantheon/ethereum/blockcreation/MiningCoordinator.java index 6d46e26b6b..95f552d212 100644 --- a/ethereum/blockcreation/src/main/java/tech/pegasys/pantheon/ethereum/blockcreation/MiningCoordinator.java +++ b/ethereum/blockcreation/src/main/java/tech/pegasys/pantheon/ethereum/blockcreation/MiningCoordinator.java @@ -43,8 +43,7 @@ public interface MiningCoordinator { } default Optional hashesPerSecond() { - throw new UnsupportedOperationException( - "Current consensus mechanism prevents querying of hashrate."); + return Optional.empty(); } default Optional getWorkDefinition() { diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthHashrate.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthHashrate.java index eaef2942ce..8225c23575 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthHashrate.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthHashrate.java @@ -15,8 +15,6 @@ package tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods; 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; @@ -38,11 +36,7 @@ public class EthHashrate implements JsonRpcMethod { @Override public JsonRpcResponse response(final JsonRpcRequest req) { - try { - final Optional 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 hashesPerSecond = miningCoordinator.hashesPerSecond(); + return new JsonRpcSuccessResponse(req.getId(), Quantity.create(hashesPerSecond.orElse(0L))); } } diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthHashrateTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthHashrateTest.java index b91b8a850c..874700fe60 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthHashrateTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/EthHashrateTest.java @@ -17,8 +17,6 @@ import static org.mockito.Mockito.when; 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; @@ -68,17 +66,6 @@ public class EthHashrateTest { 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[] {}); }