diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthSendRawTransactionTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthSendRawTransactionTest.java index 53c7d96f0d0..c16ce22e493 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthSendRawTransactionTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/jsonrpc/EthSendRawTransactionTest.java @@ -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(); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java index 847d019bb4b..0282bbeeaab 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java @@ -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; @@ -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 validationResult = transactionPool.get().addLocalTransaction(transaction); return validationResult.either( diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtils.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtils.java index 5d3d1bb752b..31e4abebb9e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtils.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtils.java @@ -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); } } }