Skip to content

Commit 1836d4a

Browse files
authored
Fix gas limit calculation in eth simulate (#9663)
* Fix gas limit calculation * Small fix * Try fix * revert flag * Subtract * known tests * fix failing tests file
1 parent 3db054f commit 1836d4a

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

scripts/known-failing-hive-tests.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ eth_getStorageAt/get-storage-invalid-key-too-large (nethermind)
55
eth_createAccessList/create-al-abi-revert (nethermind)
66
eth_sendRawTransaction/send-blob-tx (nethermind)
77
eth_simulateV1/ethSimulate-instrict-gas-38013 (nethermind)
8-
eth_simulateV1/ethSimulate-run-gas-spending (nethermind)
9-
eth_simulateV1/ethSimulate-run-out-of-gas-in-block-38015 (nethermind)
108
eth_simulateV1/ethSimulate-two-blocks-with-complete-eth-sends (nethermind)
119
eth_simulateV1/ethSimulate-use-as-many-features-as-possible (nethermind)
1210

src/Nethermind/Nethermind.Facade/Simulate/SimulateBridgeHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private void Simulate<TTrace>(BlockHeader parent,
106106
IWorldState stateProvider = env.WorldState;
107107
parent = GetParent(parent, payload, blockTree);
108108

109-
env.SimulateRequestState.TotalGasLeft = long.Min(parent.GasLimit, gasCapLimit);
109+
env.SimulateRequestState.TotalGasLeft = gasCapLimit;
110110

111111
if (payload.BlockStateCalls is not null)
112112
{
@@ -118,6 +118,7 @@ private void Simulate<TTrace>(BlockHeader parent,
118118
nonceCache.Clear();
119119

120120
(BlockHeader callHeader, IReleaseSpec spec) = GetCallHeader(env.SpecProvider, blockCall, parent, payload.Validation);
121+
env.SimulateRequestState.BlockGasLeft = callHeader.GasLimit;
121122
callHeader.Hash = callHeader.CalculateHash();
122123

123124
TransactionWithSourceDetails[] calls = blockCall.Calls ?? [];

src/Nethermind/Nethermind.Facade/Simulate/SimulateRequestState.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ public class SimulateRequestState
1010
public bool Validate { get; set; }
1111
public UInt256? BlobBaseFeeOverride { get; set; }
1212
public long TotalGasLeft { get; set; }
13+
public long BlockGasLeft { get; set; }
1314
public bool[] TxsWithExplicitGas { get; set; }
1415
}

src/Nethermind/Nethermind.Facade/Simulate/SimulateTransactionProcessorAdapter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ public TransactionResult Execute(Transaction transaction, ITxTracer txTracer)
1818
// The gas limit per tx go down as the block is processed.
1919
if (!simulateRequestState.TxsWithExplicitGas[_currentTxIndex])
2020
{
21-
transaction.GasLimit = simulateRequestState.TotalGasLeft;
21+
transaction.GasLimit = long.Min(simulateRequestState.BlockGasLeft, simulateRequestState.TotalGasLeft);
2222
}
2323
transaction.Hash = transaction.CalculateHash();
2424

2525
TransactionResult result = simulateRequestState.Validate ? transactionProcessor.Execute(transaction, txTracer) : transactionProcessor.Trace(transaction, txTracer);
2626

2727
// Keep track of gas left
2828
simulateRequestState.TotalGasLeft -= transaction.SpentGas;
29+
simulateRequestState.BlockGasLeft -= transaction.SpentGas;
2930
_currentTxIndex++;
3031
return result;
3132
}

0 commit comments

Comments
 (0)