@@ -24,6 +24,7 @@ import (
2424
2525 "github.com/ethereum/go-ethereum/accounts"
2626 "github.com/ethereum/go-ethereum/common"
27+ "github.com/ethereum/go-ethereum/common/hexutil"
2728 "github.com/ethereum/go-ethereum/consensus"
2829 "github.com/ethereum/go-ethereum/core"
2930 "github.com/ethereum/go-ethereum/core/bloombits"
@@ -347,17 +348,23 @@ func (b *EthAPIBackend) StateAtTransaction(ctx context.Context, block *types.Blo
347348 return b .eth .stateAtTransaction (block , txIndex , reexec )
348349}
349350
350- func (b * EthAPIBackend ) AccessList (ctx context.Context , block * types.Block , reexec uint64 , args * ethapi.SendTxArgs ) (* types.AccessList , error ) {
351+ // AccessList creates an access list for the given transaction.
352+ // If the accesslist creation fails an error is returned.
353+ // If the transaction itself fails, an vmErr is returned.
354+ func (b * EthAPIBackend ) AccessList (ctx context.Context , block * types.Block , reexec uint64 , args * ethapi.SendTxArgs ) (acl * types.AccessList , gasUsed uint64 , vmErr error , err error ) {
351355 if block == nil {
352356 block = b .CurrentBlock ()
353357 }
354358 db , release , err := b .eth .stateAtBlock (block , reexec )
355359 defer release ()
356360 if err != nil {
357- return nil , err
361+ return nil , 0 , nil , err
358362 }
359363 if err := args .SetDefaults (ctx , b ); err != nil {
360- return nil , err
364+ // most likely an error in gas estimation, set gas to max gas
365+ log .Warn ("Setting defaults failed" , "error" , err )
366+ maxGas := hexutil .Uint64 (b .RPCGasCap ())
367+ args .Gas = & maxGas
361368 }
362369 var (
363370 gas uint64
@@ -381,15 +388,15 @@ func (b *EthAPIBackend) AccessList(ctx context.Context, block *types.Block, reex
381388 vmenv := vm .NewEVM (context , core .NewEVMTxContext (msg ), statedb , b .eth .blockchain .Config (), config )
382389 res , err := core .ApplyMessage (vmenv , msg , new (core.GasPool ).AddGas (msg .Gas ()))
383390 if err != nil {
384- return nil , fmt .Errorf ("failed to apply transaction: %v err: %v" , args .ToTransaction ().Hash (), err )
391+ return nil , 0 , nil , fmt .Errorf ("failed to apply transaction: %v err: %v" , args .ToTransaction ().Hash (), err )
385392 }
386393 if res .UsedGas == gas {
387394 acl := tracer .GetUnpreparedAccessList (args .From , args .To , vmenv .ActivePrecompiles ())
388- return acl , nil
395+ return acl , res . UsedGas , res . Err , nil
389396 }
390397 accessList = tracer .GetAccessList ()
391398 gas = res .UsedGas
392399 }
393400
394- return accessList , errors .New ("failed to create accesslist" )
401+ return accessList , 0 , nil , errors .New ("failed to create accesslist" )
395402}
0 commit comments