Commit c8800437 authored by Georgios Konstantopoulos's avatar Georgios Konstantopoulos Committed by GitHub

fix(l2geth): do not throw an error when estimating gas for txs with nil data (#940)

* fix(l2geth): do not throw an error when estimating gas for txs with nil data

* chore: add changeset
parent 467d6cb6
---
'@eth-optimism/l2geth': patch
---
Fix gas estimation logic for simple ETH transfers
......@@ -301,6 +301,14 @@ describe('Basic RPC tests', () => {
})
describe('eth_estimateGas (returns the fee)', () => {
it('should return a gas estimate for txs with empty data', async () => {
const estimate = await l2Provider.estimateGas({
to: DEFAULT_TRANSACTION.to,
value: 0,
})
expect(estimate).to.be.eq(21000)
})
it('should return a gas estimate that grows with the size of data', async () => {
const dataLen = [0, 2, 8, 64, 256]
const l1GasPrice = await env.l1Wallet.provider.getGasPrice()
......
......@@ -1032,10 +1032,6 @@ func (s *PublicBlockChainAPI) Call(ctx context.Context, args CallArgs, blockNrOr
// fees can compensate for the additional costs the sequencer pays for publishing the
// transaction calldata
func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, gasCap *big.Int) (hexutil.Uint64, error) {
if args.Data == nil {
return 0, errors.New("transaction data cannot be nil")
}
// 1. get the gas that would be used by the transaction
gasUsed, err := legacyDoEstimateGas(ctx, b, args, blockNrOrHash, gasCap)
if err != nil {
......@@ -1056,7 +1052,13 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash
}
// 3. calculate the fee and normalize by the default gas price
fee := core.CalculateRollupFee(*args.Data, uint64(gasUsed), dataPrice, executionPrice).Uint64() / defaultGasPrice
var data []byte
if args.Data == nil {
data = []byte{}
} else {
data = *args.Data
}
fee := core.CalculateRollupFee(data, uint64(gasUsed), dataPrice, executionPrice).Uint64() / defaultGasPrice
if fee < 21000 {
fee = 21000
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment