Skip to content

Commit 42c8071

Browse files
authored
Merge pull request OffchainLabs#3 from Inphi/eip-4844
ethapi: Fix gas esitmation for blob txs
2 parents 87a4c33 + 08cdb3a commit 42c8071

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

core/types/transaction.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ type Message struct {
755755
isFake bool
756756
}
757757

758-
func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice, gasFeeCap, gasTipCap *big.Int, data []byte, accessList AccessList, isFake bool) Message {
758+
func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice, gasFeeCap, gasTipCap *big.Int, data []byte, accessList AccessList, dataHashes []common.Hash, isFake bool) Message {
759759
return Message{
760760
from: from,
761761
to: to,
@@ -767,6 +767,7 @@ func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *b
767767
gasTipCap: gasTipCap,
768768
data: data,
769769
accessList: accessList,
770+
dataHashes: dataHashes,
770771
isFake: isFake,
771772
}
772773
}

internal/ethapi/transaction_args.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,12 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (t
243243
if args.AccessList != nil {
244244
accessList = *args.AccessList
245245
}
246-
msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, gasFeeCap, gasTipCap, data, accessList, true)
246+
// The values don't matter. Only its cardinality is used for correct gas estimation
247+
var fakeDataHashes []common.Hash
248+
if args.Blobs != nil {
249+
fakeDataHashes = make([]common.Hash, len(args.Blobs))
250+
}
251+
msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, gasFeeCap, gasTipCap, data, accessList, fakeDataHashes, true)
247252
return msg, nil
248253
}
249254

les/odr_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
135135
from := statedb.GetOrNewStateObject(bankAddr)
136136
from.SetBalance(math.MaxBig256)
137137

138-
msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), 100000, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), new(big.Int), data, nil, true)}
138+
msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), 100000, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), new(big.Int), data, nil, nil, true)}
139139

140140
context := core.NewEVMBlockContext(header, bc, nil)
141141
txContext := core.NewEVMTxContext(msg)
@@ -150,7 +150,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
150150
header := lc.GetHeaderByHash(bhash)
151151
state := light.NewState(ctx, header, lc.Odr())
152152
state.SetBalance(bankAddr, math.MaxBig256)
153-
msg := callmsg{types.NewMessage(bankAddr, &testContractAddr, 0, new(big.Int), 100000, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), new(big.Int), data, nil, true)}
153+
msg := callmsg{types.NewMessage(bankAddr, &testContractAddr, 0, new(big.Int), 100000, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), new(big.Int), data, nil, nil, true)}
154154
context := core.NewEVMBlockContext(header, lc, nil)
155155
txContext := core.NewEVMTxContext(msg)
156156
vmenv := vm.NewEVM(context, txContext, state, config, vm.Config{NoBaseFee: true})

light/odr_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, bc *core.BlockChain
194194

195195
// Perform read-only call.
196196
st.SetBalance(testBankAddress, math.MaxBig256)
197-
msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 1000000, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), new(big.Int), data, nil, true)}
197+
msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 1000000, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), new(big.Int), data, nil, nil, true)}
198198
txContext := core.NewEVMTxContext(msg)
199199
context := core.NewEVMBlockContext(header, chain, nil)
200200
vmenv := vm.NewEVM(context, txContext, st, config, vm.Config{NoBaseFee: true})

tests/state_test_util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func (tx *stTransaction) toMessage(ps stPostState, baseFee *big.Int) (core.Messa
359359
}
360360

361361
msg := types.NewMessage(from, to, tx.Nonce, value, gasLimit, gasPrice,
362-
tx.MaxFeePerGas, tx.MaxPriorityFeePerGas, data, accessList, false)
362+
tx.MaxFeePerGas, tx.MaxPriorityFeePerGas, data, accessList, nil, false)
363363
return msg, nil
364364
}
365365

0 commit comments

Comments
 (0)