From 85822bdb7e15ac8b9c4a318d88c492c98501e112 Mon Sep 17 00:00:00 2001 From: davidkngo <32287546+davidkngo@users.noreply.github.com> Date: Fri, 21 Jul 2023 16:29:20 +0700 Subject: [PATCH] Revert "RPC - default to internal error not invalid params (#5506)" This reverts commit df1a34a33dd5168ddd5741dd530f531d737d95e5. --- .../acceptance/privacy/PrivCallAcceptanceTest.java | 2 +- .../methods/fork/london/EthCallIntegrationTest.java | 4 ++-- .../ethereum/api/jsonrpc/JsonRpcErrorConverter.java | 10 +--------- .../api/jsonrpc/internal/response/JsonRpcError.java | 5 +---- .../privacy/methods/eea/EeaSendRawTransactionTest.java | 7 +++---- .../RestrictedFlexibleEeaSendRawTransactionTest.java | 6 ++---- .../RestrictedOffchainEeaSendRawTransactionTest.java | 6 ++---- .../ethereum/transaction/TransactionInvalidReason.java | 2 -- 8 files changed, 12 insertions(+), 30 deletions(-) diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/privacy/PrivCallAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/privacy/PrivCallAcceptanceTest.java index c42075d48d2..e037a801ed6 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/privacy/PrivCallAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/privacy/PrivCallAcceptanceTest.java @@ -200,7 +200,7 @@ public void mustNotSucceedWithWronglyEncodedFunction() throws IOException { privCall(privacyGroupId, eventEmitter, true, false, false); final String errorMessage = priv_call.send().getError().getMessage(); - assertThat(errorMessage).isEqualTo("Private transaction failed"); + assertThat(errorMessage).isEqualTo("Invalid params"); } @Test diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthCallIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthCallIntegrationTest.java index 05698c199f6..bae0ef6b639 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthCallIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthCallIntegrationTest.java @@ -148,7 +148,7 @@ public void shouldReturnErrorWithGasPriceLessThanCurrentBaseFee() { null); final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = - new JsonRpcErrorResponse(null, JsonRpcError.GAS_PRICE_BELOW_CURRENT_BASE_FEE); + new JsonRpcErrorResponse(null, JsonRpcError.INVALID_PARAMS); final JsonRpcResponse response = method.response(request); @@ -219,7 +219,7 @@ public void shouldReturnErrorWithValidMaxFeePerGasLessThanCurrentBaseFee() { null); final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = - new JsonRpcErrorResponse(null, JsonRpcError.GAS_PRICE_BELOW_CURRENT_BASE_FEE); + new JsonRpcErrorResponse(null, JsonRpcError.INVALID_PARAMS); final JsonRpcResponse response = method.response(request); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcErrorConverter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcErrorConverter.java index 15bb5196fd9..1d1b69f9ce7 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcErrorConverter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcErrorConverter.java @@ -45,18 +45,10 @@ public static JsonRpcError convertTransactionInvalidReason( case TX_SENDER_NOT_AUTHORIZED: return JsonRpcError.TX_SENDER_NOT_AUTHORIZED; // Private Transaction Invalid Reasons - case PRIVATE_TRANSACTION_INVALID: - return JsonRpcError.PRIVATE_TRANSACTION_INVALID; - case PRIVATE_TRANSACTION_FAILED: - return JsonRpcError.PRIVATE_TRANSACTION_FAILED; - case PRIVATE_UNIMPLEMENTED_TRANSACTION_TYPE: - return JsonRpcError.UNSUPPORTED_PRIVATE_TRANSACTION_TYPE; case CHAIN_HEAD_WORLD_STATE_NOT_AVAILABLE: return JsonRpcError.CHAIN_HEAD_WORLD_STATE_NOT_AVAILABLE; case GAS_PRICE_TOO_LOW: return JsonRpcError.GAS_PRICE_TOO_LOW; - case GAS_PRICE_BELOW_CURRENT_BASE_FEE: - return JsonRpcError.GAS_PRICE_BELOW_CURRENT_BASE_FEE; case TX_FEECAP_EXCEEDED: return JsonRpcError.TX_FEECAP_EXCEEDED; case MAX_PRIORITY_FEE_PER_GAS_EXCEEDS_MAX_FEE_PER_GAS: @@ -76,7 +68,7 @@ public static JsonRpcError convertTransactionInvalidReason( case TOTAL_DATA_GAS_TOO_HIGH: return JsonRpcError.TOTAL_DATA_GAS_TOO_HIGH; default: - return JsonRpcError.INTERNAL_ERROR; + return JsonRpcError.INVALID_PARAMS; } } } 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 fd705066bd2..8b7da6bb7a6 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 @@ -65,7 +65,6 @@ public enum JsonRpcError { TX_SENDER_NOT_AUTHORIZED(-32007, "Sender account not authorized to send transactions"), CHAIN_HEAD_WORLD_STATE_NOT_AVAILABLE(-32008, "Initial sync is still in progress"), GAS_PRICE_TOO_LOW(-32009, "Gas price below configured minimum gas price"), - GAS_PRICE_BELOW_CURRENT_BASE_FEE(-32009, "Gas price below current base fee"), WRONG_CHAIN_ID(-32000, "Wrong chainId"), REPLAY_PROTECTED_SIGNATURES_NOT_SUPPORTED(-32000, "ChainId not supported"), REPLAY_PROTECTED_SIGNATURE_REQUIRED(-32000, "ChainId is required"), @@ -140,7 +139,7 @@ public enum JsonRpcError { // Private transaction errors ENCLAVE_ERROR(-50100, "Error communicating with enclave"), - UNSUPPORTED_PRIVATE_TRANSACTION_TYPE(-50100, "Unsupported private transaction type"), + UNIMPLEMENTED_PRIVATE_TRANSACTION_TYPE(-50100, "Unimplemented private transaction type"), PRIVACY_NOT_ENABLED(-50100, "Privacy is not enabled"), CREATE_PRIVACY_GROUP_ERROR(-50100, "Error creating privacy group"), DECODE_ERROR(-50100, "Unable to decode the private signed raw transaction"), @@ -161,8 +160,6 @@ public enum JsonRpcError { PRIVATE_FROM_DOES_NOT_MATCH_ENCLAVE_PUBLIC_KEY( -50100, "Private from does not match enclave public key"), VALUE_NOT_ZERO(-50100, "We cannot transfer ether in a private transaction yet."), - PRIVATE_TRANSACTION_INVALID(-50100, "Private transaction invalid"), - PRIVATE_TRANSACTION_FAILED(-50100, "Private transaction failed"), CANT_CONNECT_TO_LOCAL_PEER(-32100, "Cannot add local node as peer."), CANT_RESOLVE_PEER_ENODE_DNS(-32100, "Cannot resolve enode DNS hostname"), 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 4ad29c1931c..cd903cf4acc 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 @@ -16,7 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.PRIVATE_TRANSACTION_INVALID; +import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.PRIVATE_TRANSACTION_FAILED; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.never; @@ -139,12 +139,11 @@ public void invalidTransactionWithoutPrivateFromFieldFailsWithDecodeError() { @Test public void invalidTransactionIsNotSentToEnclaveAndIsNotAddedToTransactionPool() { when(privacyController.validatePrivateTransaction(any(), anyString())) - .thenReturn(ValidationResult.invalid(PRIVATE_TRANSACTION_INVALID)); + .thenReturn(ValidationResult.invalid(PRIVATE_TRANSACTION_FAILED)); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse( - validPrivateForTransactionRequest.getRequest().getId(), - JsonRpcError.PRIVATE_TRANSACTION_INVALID); + validPrivateForTransactionRequest.getRequest().getId(), JsonRpcError.INVALID_PARAMS); final JsonRpcResponse actualResponse = method.response(validPrivateForTransactionRequest); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedFlexibleEeaSendRawTransactionTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedFlexibleEeaSendRawTransactionTest.java index 7d11084308e..76fe542f4f8 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedFlexibleEeaSendRawTransactionTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedFlexibleEeaSendRawTransactionTest.java @@ -139,8 +139,7 @@ public void flexiblePrivacyGroupTransactionFailsWhenGroupDoesNotExist() { final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse( - validPrivacyGroupTransactionRequest.getRequest().getId(), - JsonRpcError.UNSUPPORTED_PRIVATE_TRANSACTION_TYPE); + validPrivacyGroupTransactionRequest.getRequest().getId(), JsonRpcError.INVALID_PARAMS); assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); } @@ -153,8 +152,7 @@ public void flexiblePrivacyGroupTransactionFailsWhenGroupDoesNotExist() { final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse( - validPrivacyGroupTransactionRequest.getRequest().getId(), - JsonRpcError.UNSUPPORTED_PRIVATE_TRANSACTION_TYPE); + validPrivacyGroupTransactionRequest.getRequest().getId(), JsonRpcError.INVALID_PARAMS); assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOffchainEeaSendRawTransactionTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOffchainEeaSendRawTransactionTest.java index 897346620f4..5d6bdd8e0ce 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOffchainEeaSendRawTransactionTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/RestrictedOffchainEeaSendRawTransactionTest.java @@ -107,8 +107,7 @@ public void validPantheonPrivacyGroupTransactionIsSentToTransactionPool() { final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse( - validPrivacyGroupTransactionRequest.getRequest().getId(), - JsonRpcError.UNSUPPORTED_PRIVATE_TRANSACTION_TYPE); + validPrivacyGroupTransactionRequest.getRequest().getId(), JsonRpcError.INVALID_PARAMS); assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); } @@ -121,8 +120,7 @@ public void validPantheonPrivacyGroupTransactionIsSentToTransactionPool() { final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse( - validPrivacyGroupTransactionRequest.getRequest().getId(), - JsonRpcError.UNSUPPORTED_PRIVATE_TRANSACTION_TYPE); + validPrivacyGroupTransactionRequest.getRequest().getId(), JsonRpcError.INVALID_PARAMS); assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionInvalidReason.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionInvalidReason.java index d62e0e87ac4..84487d6bfb4 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionInvalidReason.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionInvalidReason.java @@ -43,12 +43,10 @@ public enum TransactionInvalidReason { TOTAL_DATA_GAS_TOO_HIGH, GAS_PRICE_TOO_LOW, GAS_PRICE_BELOW_CURRENT_BASE_FEE, - MAX_FEE_PER_GAS_BELOW_CURRENT_BASE_FEE, TX_FEECAP_EXCEEDED, INTERNAL_ERROR, // Private Transaction Invalid Reasons - PRIVATE_TRANSACTION_INVALID, PRIVATE_TRANSACTION_FAILED, PRIVATE_NONCE_TOO_LOW, OFFCHAIN_PRIVACY_GROUP_DOES_NOT_EXIST,