Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Report 0 hashrate when the mining coordinator doesn't support mining #1757

Merged
merged 2 commits into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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