From afea4e0057a660535f6e061905835ee381e97c2e Mon Sep 17 00:00:00 2001 From: garyschulte Date: Wed, 1 May 2024 08:14:20 -0700 Subject: [PATCH] Allow API configuration to override supplied gasLimit (#6978) * allow gasLimit configuration for transaction simulation * revise unit test to reflect new behavior of rpcGasCap Signed-off-by: Karim Taam Signed-off-by: garyschulte Co-authored-by: Karim Taam --- .../besu/ethereum/transaction/TransactionSimulator.java | 7 ++----- .../ethereum/transaction/TransactionSimulatorTest.java | 6 ++++-- 2 files changed, 6 insertions(+), 7 deletions(-) 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 c073ac4148c..070c1dcf771 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 @@ -235,11 +235,8 @@ public Optional processWithWorldUpdater( ? callParams.getGasLimit() : blockHeaderToProcess.getGasLimit(); if (rpcGasCap > 0) { - final long gasCap = rpcGasCap; - if (gasCap < gasLimit) { - gasLimit = gasCap; - LOG.info("Capping gasLimit to " + gasCap); - } + gasLimit = rpcGasCap; + LOG.info("Capping gasLimit to " + rpcGasCap); } final Wei value = callParams.getValue() != null ? callParams.getValue() : Wei.ZERO; final Bytes payload = callParams.getPayload() != null ? callParams.getPayload() : Bytes.EMPTY; 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 7142d8830e5..2595284822d 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 @@ -565,8 +565,9 @@ public void shouldCapGasLimitWhenOriginalTransactionExceedsGasCap() { } @Test - public void shouldKeepOriginalGasLimitWhenCapIsHigherThanOriginalValue() { - // generate a transaction with a gas limit that is lower than the gas cap + public void shouldUseRpcGasCapWhenCapIsHigherThanGasLimit() { + // generate a transaction with a gas limit that is lower than the gas cap, + // expect the gas cap to override parameter gas limit final CallParameter callParameter = eip1559TransactionCallParameter(Wei.ZERO, Wei.ZERO, GASCAP - 1); @@ -589,6 +590,7 @@ public void shouldKeepOriginalGasLimitWhenCapIsHigherThanOriginalValue() { .value(callParameter.getValue()) .payload(callParameter.getPayload()) .signature(FAKE_SIGNATURE) + .gasLimit(GASCAP) .build(); // call process with original transaction