Skip to content

Commit

Permalink
add more context to exception messages and debug logging (hyperledger…
Browse files Browse the repository at this point in the history
…#5066)

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
  • Loading branch information
macfarla authored and ensi321 committed Feb 19, 2023
1 parent 33fa29d commit 26023fa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public void shouldFailToSendToToStrictNodeWithoutChainId() {
strictNode.verify(eth.expectEthSendRawTransactionException(rawTx, "ChainId is required"));
}

@Test
public void shouldFailToSendWithInvalidRlp() {
final String invalidRawTx = "0x5555";
strictNode.verify(eth.expectEthSendRawTransactionException(invalidRawTx, "Invalid params"));
}

@Test
public void shouldSendSuccessfullyWithChainId_lenientNode() {
final TransferTransaction tx = createTransactionWithChainId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcErrorConverter;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcRequestException;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
Expand Down Expand Up @@ -68,13 +69,21 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final Transaction transaction;
try {
transaction = DomainObjectDecodeUtils.decodeRawTransaction(rawTransaction);
} catch (final RLPException | IllegalArgumentException e) {
LOG.trace("Received local transaction {}", transaction);
} catch (final RLPException e) {
LOG.debug("RLPException: {} caused by {}", e.getMessage(), e.getCause());
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS);
} catch (final InvalidJsonRpcRequestException i) {
LOG.debug("InvalidJsonRpcRequestException: {} caused by {}", i.getMessage(), i.getCause());
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS);
} catch (final IllegalArgumentException ill) {
LOG.debug("IllegalArgumentException: {} caused by {}", ill.getMessage(), ill.getCause());
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS);
}

LOG.trace("Received local transaction {}", transaction);

final ValidationResult<TransactionInvalidReason> validationResult =
transactionPool.get().addLocalTransaction(transaction);
return validationResult.either(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ public static Transaction decodeRawTransaction(final String rawTransaction)
Bytes txnBytes = Bytes.fromHexString(rawTransaction);
final boolean isGoQuorumCompatibilityMode = GoQuorumOptions.getGoQuorumCompatibilityMode();
return TransactionDecoder.decodeOpaqueBytes(txnBytes, isGoQuorumCompatibilityMode);
} catch (final IllegalArgumentException | RLPException e) {
} catch (final IllegalArgumentException e) {
throw new InvalidJsonRpcRequestException("Invalid raw transaction hex", e);
} catch (final RLPException r) {
throw new InvalidJsonRpcRequestException("Invalid RLP in raw transaction hex", r);
}
}
}

0 comments on commit 26023fa

Please sign in to comment.