From ce031f19739698c149ea638849f5309d16d6da73 Mon Sep 17 00:00:00 2001 From: Stefan Pingel <16143240+pinges@users.noreply.github.com> Date: Wed, 1 Apr 2020 11:52:21 +1000 Subject: [PATCH] Fix the error retrurned when the PMT fails because the intrinsic gas exeeds the gas limit. (#616) * Fix the error retrurned when the PMT cannot be added to the transaction pool because the intrinsic gas exeeds the gas limit. Signed-off-by: Stefan Pingel --- .../privacy/methods/eea/EeaSendRawTransaction.java | 12 ++++++++++-- .../api/jsonrpc/internal/response/JsonRpcError.java | 5 ++++- .../methods/eea/EeaSendRawTransactionTest.java | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransaction.java index 3c5f1028b3..e02889e79d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransaction.java @@ -28,6 +28,7 @@ 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.methods.JsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.EnclavePublicKeyProvider; +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; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; @@ -146,8 +147,7 @@ public class EeaSendRawTransaction implements JsonRpcMethod { .addLocalTransaction(privacyMarkerTransaction) .either( () -> new JsonRpcSuccessResponse(id, privacyMarkerTransaction.getHash().toString()), - errorReason -> - new JsonRpcErrorResponse(id, convertTransactionInvalidReason(errorReason))); + errorReason -> getJsonRpcErrorResponse(id, errorReason)); } catch (final MultiTenancyValidationException e) { LOG.error("Unauthorized privacy multi-tenancy rpc request. {}", e.getMessage()); return new JsonRpcErrorResponse(id, ENCLAVE_ERROR); @@ -158,6 +158,14 @@ public class EeaSendRawTransaction implements JsonRpcMethod { } } + JsonRpcErrorResponse getJsonRpcErrorResponse( + final Object id, final TransactionInvalidReason errorReason) { + if (errorReason.equals(TransactionInvalidReason.INTRINSIC_GAS_EXCEEDS_GAS_LIMIT)) { + return new JsonRpcErrorResponse(id, JsonRpcError.PMT_FAILED_INTRINSIC_GAS_EXCEEDS_LIMIT); + } + return new JsonRpcErrorResponse(id, convertTransactionInvalidReason(errorReason)); + } + private String buildCompoundKey( final String enclaveKey, final Optional addPayloadEnclaveKey) { return addPayloadEnclaveKey.isPresent() diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/JsonRpcError.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/JsonRpcError.java index 033b536b89..0c45e45ab7 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/JsonRpcError.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/JsonRpcError.java @@ -112,13 +112,16 @@ public enum JsonRpcError { DELETE_PRIVACY_GROUP_ERROR(-50100, "Error deleting privacy group"), FIND_PRIVACY_GROUP_ERROR(-50100, "Error finding privacy group"), FIND_ON_CHAIN_PRIVACY_GROUP_ERROR(-50100, "Error finding on-chain privacy group"), - VALUE_NOT_ZERO(-50100, "We cannot transfer ether in private transaction yet."), + VALUE_NOT_ZERO(-50100, "We cannot transfer ether in a private transaction yet."), DECODE_ERROR(-50100, "Unable to decode the private signed raw transaction"), GET_PRIVATE_TRANSACTION_NONCE_ERROR(-50100, "Unable to determine nonce for account in group."), PRIVACY_GROUP_DOES_NOT_EXIST(-50100, "Privacy group does not exist."), ONCHAIN_PRIVACY_GROUP_NOT_ENABLED(-50100, "Onchain privacy groups not enabled."), OFFCHAIN_PRIVACY_GROUP_NOT_ENABLED( -50100, "Offchain privacy group can't be used with Onchain privacy groups enabled."), + PMT_FAILED_INTRINSIC_GAS_EXCEEDS_LIMIT( + -50100, + "Private Marker Transaction failed due to intrinsic gas exeeding the limit. Gas limit used from the Private Transaction."), CANT_CONNECT_TO_LOCAL_PEER(-32100, "Cannot add local node as peer."), diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransactionTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransactionTest.java index 5728b38921..a398fae1f5 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransactionTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransactionTest.java @@ -450,7 +450,7 @@ public class EeaSendRawTransactionTest { public void transactionWithIntrinsicGasExceedingGasLimitIsRejected() { verifyErrorForInvalidTransaction( TransactionInvalidReason.INTRINSIC_GAS_EXCEEDS_GAS_LIMIT, - JsonRpcError.INTRINSIC_GAS_EXCEEDS_LIMIT); + JsonRpcError.PMT_FAILED_INTRINSIC_GAS_EXCEEDS_LIMIT); } @Test