From 796217ced1ab27219322c140c1a847495d36bf61 Mon Sep 17 00:00:00 2001 From: Karim TAAM Date: Thu, 17 Jun 2021 11:06:37 +0200 Subject: [PATCH] fix pipeline Signed-off-by: Karim TAAM --- .../fork/frontier/EthCallIntegrationTest.java | 2 +- .../fork/london/EthCallIntegrationTest.java | 1 + .../api/jsonrpc/internal/methods/EthCall.java | 11 +++++++-- .../internal/methods/EthEstimateGas.java | 2 +- .../parameters/JsonCallParameter.java | 2 +- .../eth/eth_call_gasPriceTooHigh_block_8.json | 24 ++++++++++++++++++- .../transaction/TransactionSimulator.java | 7 +++--- .../transaction/TransactionSimulatorTest.java | 17 +++++++++++-- 8 files changed, 54 insertions(+), 12 deletions(-) diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthCallIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthCallIntegrationTest.java index 0e766540600..ec1d9f94e5a 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthCallIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthCallIntegrationTest.java @@ -52,6 +52,7 @@ public class EthCallIntegrationTest { public static void setUpOnce() throws Exception { final String genesisJson = Resources.toString(BlockTestUtil.getTestGenesisUrl(), Charsets.UTF_8); + BLOCKCHAIN = new JsonRpcTestMethodsFactory( new BlockchainImporter(BlockTestUtil.getTestBlockchainUrl(), genesisJson)); @@ -65,7 +66,6 @@ public void setUp() { @Test public void shouldReturnExpectedResultForCallAtLatestBlock() { - final JsonCallParameter callParameter = new JsonCallParameter( Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), 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 168c04e19ea..bdc17e2192d 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 @@ -49,6 +49,7 @@ public class EthCallIntegrationTest { public static void setUpOnce() throws Exception { final String genesisJson = Resources.toString(BlockTestUtil.getTestLondonGenesisUrl(), Charsets.UTF_8); + BLOCKCHAIN = new JsonRpcTestMethodsFactory( new BlockchainImporter(BlockTestUtil.getTestLondonBlockchainUrl(), genesisJson)); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java index 861a06d7dde..61d98ac678c 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCall.java @@ -129,6 +129,12 @@ private JsonCallParameter validateAndGetCallParams(final JsonRpcRequestContext r if (callParams.getTo() == null) { throw new InvalidJsonRpcParameters("Missing \"to\" field in call arguments"); } + if (callParams.getGasPrice() != null + && (callParams.getMaxFeePerGas().isPresent() + || callParams.getMaxPriorityFeePerGas().isPresent())) { + throw new InvalidJsonRpcParameters( + "gasPrice cannot be used with maxFeePerGas or maxPriorityFeePerGas"); + } return callParams; } @@ -141,7 +147,8 @@ private TransactionValidationParams buildTransactionValidationParams( // if it is not set explicitly whether we want a strict check of the balance or not. this will // be decided according to the provided parameters - if (callParams.isStrict().isEmpty()) { + + if (callParams.isMaybeStrict().isEmpty()) { boolean isZeroGasPrice = callParams.getGasPrice() == null || Wei.ZERO.equals(callParams.getGasPrice()); @@ -170,7 +177,7 @@ private TransactionValidationParams buildTransactionValidationParams( }); } else { transactionValidationParams.isAllowExceedingBalance( - !callParams.isStrict().orElse(Boolean.FALSE)); + !callParams.isMaybeStrict().orElse(Boolean.FALSE)); } return transactionValidationParams.build(); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java index 2cf0812faec..3aabf0b7a8a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java @@ -82,7 +82,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { modifiedCallParams, ImmutableTransactionValidationParams.builder() .from(TransactionValidationParams.transactionSimulator()) - .isAllowExceedingBalance(!callParams.isStrict().orElse(Boolean.FALSE)) + .isAllowExceedingBalance(!callParams.isMaybeStrict().orElse(Boolean.FALSE)) .build(), operationTracer, blockHeader.getNumber()) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java index 41732bda0c4..4638af44850 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java @@ -58,7 +58,7 @@ public JsonCallParameter( this.strict = Optional.ofNullable(strict); } - public Optional isStrict() { + public Optional isMaybeStrict() { return strict; } } diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_gasPriceTooHigh_block_8.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_gasPriceTooHigh_block_8.json index 89495202b9d..fe81d9f74d8 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_gasPriceTooHigh_block_8.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_gasPriceTooHigh_block_8.json @@ -8,7 +8,8 @@ { "to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", "from": "a94f5374fce5edbc8e2a8697c15331677e6ebf0b", - "gasPrice": "0x10000000000000" + "gasPrice": "0x10000000000000", + "strict": false }, "0x8" ] @@ -17,6 +18,19 @@ "id": 4, "jsonrpc": "2.0", "method": "eth_call", + "params": [ + { + "to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", + "from": "a94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "gasPrice": "0x10000000000000" + }, + "0x8" + ] + }, + { + "id": 5, + "jsonrpc": "2.0", + "method": "eth_call", "params": [ { "to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", @@ -41,6 +55,14 @@ "code": -32004, "message": "Upfront cost exceeds account balance" } + }, + { + "jsonrpc": "2.0", + "id": 5, + "error": { + "code": -32004, + "message": "Upfront cost exceeds account balance" + } } ], "statusCode": 200 diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java index a68dae007c7..53c0c7f1c53 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java @@ -196,14 +196,13 @@ public Optional process( if (header.getBaseFee().isEmpty()) { transactionBuilder.gasPrice(gasPrice); - } else { - if (protocolSchedule.getChainId().isEmpty()) { - return Optional.empty(); - } + } else if (protocolSchedule.getChainId().isPresent()) { transactionBuilder .chainId(protocolSchedule.getChainId().orElseThrow()) .maxFeePerGas(callParams.getMaxFeePerGas().orElse(gasPrice)) .maxPriorityFeePerGas(callParams.getMaxPriorityFeePerGas().orElse(gasPrice)); + } else { + return Optional.empty(); } transactionBuilder.guessType(); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorTest.java index 1500eed55d2..e261356de12 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulatorTest.java @@ -391,13 +391,14 @@ public void shouldReturnFailureResultWhenProcessingFailsByHash() { public void shouldReturnSuccessfulResultWhenEip1559TransactionProcessingIsSuccessful() { final CallParameter callParameter = eip1559TransactionCallParameter(); - mockBlockchainForBlockHeader(Hash.ZERO, 1L); + mockBlockchainForBlockHeader(Hash.ZERO, 1L, Hash.ZERO, 1L); mockWorldStateForAccount(Hash.ZERO, callParameter.getFrom(), 1L); final Transaction expectedTransaction = Transaction.builder() .nonce(1L) - .gasPrice(callParameter.getGasPrice()) + .chainId(BigInteger.ONE) + .type(TransactionType.EIP1559) .gasLimit(callParameter.getGasLimit()) .maxFeePerGas(callParameter.getMaxFeePerGas().orElseThrow()) .maxPriorityFeePerGas(callParameter.getMaxPriorityFeePerGas().orElseThrow()) @@ -451,12 +452,24 @@ private void mockBlockchainForBlockHeader( final BlockHeader blockHeader = mock(BlockHeader.class); when(blockHeader.getStateRoot()).thenReturn(stateRoot); when(blockHeader.getNumber()).thenReturn(blockNumber); + when(blockHeader.getBaseFee()).thenReturn(Optional.of(0L)); + when(blockchain.getBlockHeader(blockNumber)).thenReturn(Optional.of(blockHeader)); + when(blockchain.getBlockHeader(headerHash)).thenReturn(Optional.of(blockHeader)); + } + + private void mockBlockchainForBlockHeader( + final Hash stateRoot, final long blockNumber, final Hash headerHash, final long baseFee) { + final BlockHeader blockHeader = mock(BlockHeader.class); + when(blockHeader.getStateRoot()).thenReturn(stateRoot); + when(blockHeader.getNumber()).thenReturn(blockNumber); + when(blockHeader.getBaseFee()).thenReturn(Optional.of(baseFee)); when(blockchain.getBlockHeader(blockNumber)).thenReturn(Optional.of(blockHeader)); when(blockchain.getBlockHeader(headerHash)).thenReturn(Optional.of(blockHeader)); } private void mockProcessorStatusForTransaction( final long blockNumber, final Transaction transaction, final Status status) { + when(protocolSchedule.getChainId()).thenReturn(Optional.of(BigInteger.ONE)); when(protocolSchedule.getByBlockNumber(eq(blockNumber))).thenReturn(protocolSpec); when(protocolSpec.getTransactionProcessor()).thenReturn(transactionProcessor); when(protocolSpec.getMiningBeneficiaryCalculator()).thenReturn(BlockHeader::getCoinbase);