Skip to content

Commit

Permalink
chore: Remove test code from EthGetLogs.java
Browse files Browse the repository at this point in the history
Removed temporary test code that was accidentally left in EthGetLogs.java.
This code was not intended for the final implementation.

Issue: hyperledger#5589
PR: hyperledger#7469
Signed-off-by: Ade Lucas <ade.lucas@consensys.net>
  • Loading branch information
cloudspores committed Aug 26, 2024
1 parent 0dffe63 commit 4da2f6d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 14 deletions.
12 changes: 12 additions & 0 deletions .run/Besu Debug.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Besu Debug" type="Application" factoryName="Application" activateToolWindowBeforeRun="false">
<envs>
<env name="LOG_LEVEL" value="INFO" />
</envs>
<option name="MAIN_CLASS_NAME" value="org.hyperledger.besu.Besu" />
<module name="besu.main" />
<option name="PROGRAM_PARAMETERS" value="--data-path=data --genesis-file=../genesis.json --rpc-http-enabled --rpc-http-api=ETH,NET,IBFT,WEB3,TXPOOL,ADMIN --host-allowlist=&quot;*&quot; --rpc-http-cors-origins=&quot;all&quot; --min-gas-price=0" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/../../hyperledger-besu/IBFT-Network/Node-1" />
<method v="2" />
</configuration>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

import java.io.IOException;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.opentelemetry.api.trace.Tracer;
Expand All @@ -34,6 +37,9 @@
public class JsonRpcExecutorHandler {
private static final Logger LOG = LoggerFactory.getLogger(JsonRpcExecutorHandler.class);

// Default timeout for RPC calls in seconds
private static final long DEFAULT_TIMEOUT_SECONDS = 30;

private JsonRpcExecutorHandler() {}

public static Handler<RoutingContext> handler(
Expand All @@ -45,23 +51,44 @@ public static Handler<RoutingContext> handler(
}

public static Handler<RoutingContext> handler(
final JsonRpcExecutor jsonRpcExecutor,
final Tracer tracer,
final JsonRpcConfiguration jsonRpcConfiguration) {
final JsonRpcExecutor jsonRpcExecutor,
final Tracer tracer,
final JsonRpcConfiguration jsonRpcConfiguration) {
return ctx -> {
try {
createExecutor(jsonRpcExecutor, tracer, ctx, jsonRpcConfiguration)
.ifPresentOrElse(
executor -> {
try {
executor.execute();
} catch (IOException e) {
final String method = executor.getRpcMethodName(ctx);
LOG.error("{} - Error streaming JSON-RPC response", method, e);
handleJsonRpcError(ctx, null, RpcErrorType.INTERNAL_ERROR);
}
},
() -> handleJsonRpcError(ctx, null, RpcErrorType.PARSE_ERROR));
.ifPresentOrElse(
executor -> {
CompletableFuture<Void> future = new CompletableFuture<>();

// Run the executor in a separate thread
CompletableFuture.runAsync(() -> {
try {
executor.execute();
future.complete(null);
} catch (IOException e) {
future.completeExceptionally(e);
}
});

// Set a timeout for the future
long timeoutMillis = TimeUnit.SECONDS.toMillis(DEFAULT_TIMEOUT_SECONDS);
future.orTimeout(timeoutMillis, TimeUnit.MILLISECONDS)
.whenComplete((result, throwable) -> {
if (throwable != null) {
if (throwable instanceof TimeoutException) {
handleJsonRpcError(ctx, null, RpcErrorType.TIMEOUT_ERROR);
} else {
final String method = executor.getRpcMethodName(ctx);
LOG.error("{} - Error streaming JSON-RPC response", method, throwable);
handleJsonRpcError(ctx, null, RpcErrorType.INTERNAL_ERROR);
}
} else {
LOG.debug("JSON-RPC execution completed successfully");
}
});
},
() -> handleJsonRpcError(ctx, null, RpcErrorType.PARSE_ERROR));
} catch (final RuntimeException e) {
final String method = ctx.get(ContextKey.REQUEST_BODY_AS_JSON_OBJECT.name());
LOG.error("Unhandled exception in JSON-RPC executor for method {}", method, e);
Expand Down

0 comments on commit 4da2f6d

Please sign in to comment.