mirror of
https://github.com/vacp2p/linea-besu.git
synced 2026-01-09 15:37:54 -05:00
fix selection of receive RPC (#2197)
* fix selection of receive RPC Signed-off-by: Stefan Pingel <stefan.pingel@consensys.net>
This commit is contained in:
@@ -17,6 +17,7 @@ package org.hyperledger.besu.enclave;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -52,7 +53,8 @@ public class GoQuorumEnclaveTest {
|
||||
|
||||
@Test
|
||||
public void upCheck() {
|
||||
when(vertxTransmitter.get(any(), any(), ArgumentMatchers.contains("/upcheck"), any()))
|
||||
when(vertxTransmitter.get(
|
||||
any(), any(), ArgumentMatchers.contains("/upcheck"), any(), anyBoolean()))
|
||||
.thenReturn("I'm up!");
|
||||
|
||||
assertThat(enclave.upCheck()).isTrue();
|
||||
@@ -60,7 +62,8 @@ public class GoQuorumEnclaveTest {
|
||||
|
||||
@Test
|
||||
public void receiveThrowsWhenPayloadDoesNotExist() {
|
||||
when(vertxTransmitter.get(any(), any(), ArgumentMatchers.contains("/transaction"), any()))
|
||||
when(vertxTransmitter.get(
|
||||
any(), any(), ArgumentMatchers.contains("/transaction"), any(), anyBoolean()))
|
||||
.thenThrow(
|
||||
new EnclaveClientException(404, "Message with hash " + MOCK_KEY + " was not found"));
|
||||
|
||||
@@ -72,7 +75,8 @@ public class GoQuorumEnclaveTest {
|
||||
@Test
|
||||
public void sendAndReceive() {
|
||||
when(vertxTransmitter.post(any(), any(), any(), any())).thenReturn(new SendResponse(KEY));
|
||||
when(vertxTransmitter.get(any(), any(), ArgumentMatchers.contains("/transaction"), any()))
|
||||
when(vertxTransmitter.get(
|
||||
any(), any(), ArgumentMatchers.contains("/transaction"), any(), anyBoolean()))
|
||||
.thenReturn(new GoQuorumReceiveResponse(PAYLOAD, 0, null, null));
|
||||
|
||||
final List<String> publicKeys = Arrays.asList("/+UuD63zItL1EbjxkKUljMgG8Z1w0AJ8pNOR4iq2yQc=");
|
||||
|
||||
@@ -49,7 +49,7 @@ public class Enclave {
|
||||
public boolean upCheck() {
|
||||
try {
|
||||
final String upcheckResponse =
|
||||
requestTransmitter.get(null, null, "/upcheck", this::handleRawResponse);
|
||||
requestTransmitter.get(null, null, "/upcheck", this::handleRawResponse, false);
|
||||
return upcheckResponse.equals("I'm up!");
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class GoQuorumEnclave {
|
||||
public boolean upCheck() {
|
||||
try {
|
||||
final String upcheckResponse =
|
||||
requestTransmitter.get(null, null, "/upcheck", this::handleRawResponse);
|
||||
requestTransmitter.get(null, null, "/upcheck", this::handleRawResponse, false);
|
||||
return upcheckResponse.equals("I'm up!");
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
@@ -99,7 +99,6 @@ public class GoQuorumEnclave {
|
||||
} catch (final JsonProcessingException e) {
|
||||
throw new EnclaveClientException(400, "Unable to serialize request.");
|
||||
}
|
||||
|
||||
return requestTransmitter.post(mediaType, bodyText, endpoint, responseBodyHandler);
|
||||
}
|
||||
|
||||
@@ -107,7 +106,7 @@ public class GoQuorumEnclave {
|
||||
final String mediaType,
|
||||
final String endpoint,
|
||||
final ResponseBodyHandler<T> responseBodyHandler) {
|
||||
final T t = requestTransmitter.get(mediaType, null, endpoint, responseBodyHandler);
|
||||
final T t = requestTransmitter.get(mediaType, null, endpoint, responseBodyHandler, true);
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,5 +31,6 @@ public interface RequestTransmitter {
|
||||
String mediaType,
|
||||
String content,
|
||||
String endpoint,
|
||||
ResponseBodyHandler<T> responseBodyHandler);
|
||||
ResponseBodyHandler<T> responseBodyHandler,
|
||||
final boolean withAcceptJsonHeader);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
||||
import io.vertx.core.http.HttpClient;
|
||||
import io.vertx.core.http.HttpClientRequest;
|
||||
import io.vertx.core.http.HttpClientResponse;
|
||||
@@ -26,6 +27,7 @@ import io.vertx.core.http.HttpMethod;
|
||||
|
||||
public class VertxRequestTransmitter implements RequestTransmitter {
|
||||
|
||||
private static final String APPLICATION_JSON = "application/json";
|
||||
private final HttpClient client;
|
||||
private static final long REQUEST_TIMEOUT_MS = 5000L;
|
||||
|
||||
@@ -40,7 +42,12 @@ public class VertxRequestTransmitter implements RequestTransmitter {
|
||||
final String endpoint,
|
||||
final ResponseBodyHandler<T> responseHandler) {
|
||||
return sendRequest(
|
||||
HttpMethod.POST, Optional.of(contentType), Optional.of(content), endpoint, responseHandler);
|
||||
HttpMethod.POST,
|
||||
Optional.of(contentType),
|
||||
Optional.of(content),
|
||||
endpoint,
|
||||
responseHandler,
|
||||
false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,13 +55,15 @@ public class VertxRequestTransmitter implements RequestTransmitter {
|
||||
final String contentType,
|
||||
final String content,
|
||||
final String endpoint,
|
||||
final ResponseBodyHandler<T> responseHandler) {
|
||||
final ResponseBodyHandler<T> responseHandler,
|
||||
final boolean withAcceptJsonHeader) {
|
||||
return sendRequest(
|
||||
HttpMethod.GET,
|
||||
Optional.ofNullable(contentType),
|
||||
Optional.ofNullable(content),
|
||||
endpoint,
|
||||
responseHandler);
|
||||
responseHandler,
|
||||
withAcceptJsonHeader);
|
||||
}
|
||||
|
||||
protected <T> T sendRequest(
|
||||
@@ -62,7 +71,8 @@ public class VertxRequestTransmitter implements RequestTransmitter {
|
||||
final Optional<String> contentType,
|
||||
final Optional<String> content,
|
||||
final String endpoint,
|
||||
final ResponseBodyHandler<T> responseHandler) {
|
||||
final ResponseBodyHandler<T> responseHandler,
|
||||
final boolean withAcceptJsonHeader) {
|
||||
try {
|
||||
final CompletableFuture<T> result = new CompletableFuture<>();
|
||||
final HttpClientRequest request =
|
||||
@@ -72,6 +82,10 @@ public class VertxRequestTransmitter implements RequestTransmitter {
|
||||
.setTimeout(REQUEST_TIMEOUT_MS)
|
||||
.exceptionHandler(result::completeExceptionally)
|
||||
.setChunked(false);
|
||||
if (withAcceptJsonHeader) {
|
||||
// this is needed when using Tessera GET /transaction/{hash} to choose the right RPC
|
||||
request.putHeader(HttpHeaderNames.ACCEPT, APPLICATION_JSON);
|
||||
}
|
||||
contentType.ifPresent(ct -> request.putHeader(HttpHeaders.CONTENT_TYPE, ct));
|
||||
if (content.isPresent()) {
|
||||
request.end(content.get());
|
||||
|
||||
Reference in New Issue
Block a user