Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid params - add some error detail #5066

Merged
merged 3 commits into from
Feb 16, 2023
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 @@ -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);
}
}
}