mirror of
https://github.com/vacp2p/linea-besu.git
synced 2026-01-09 21:17:54 -05:00
Report 0 hashrate when the mining coordinator doesn't support mining (#1744)
Fixes compatibility with ethstats.net reporting for PoA networks (specifically Görli). Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
This commit is contained in:
@@ -43,8 +43,7 @@ public interface MiningCoordinator {
|
||||
}
|
||||
|
||||
default Optional<Long> hashesPerSecond() {
|
||||
throw new UnsupportedOperationException(
|
||||
"Current consensus mechanism prevents querying of hashrate.");
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
default Optional<EthHashSolverInputs> getWorkDefinition() {
|
||||
|
||||
@@ -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<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)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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[] {});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user