Skip to content

Commit dc9a7b1

Browse files
eth: better error messages for createAccessList
1 parent 55e608d commit dc9a7b1

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

eth/api.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,13 @@ func (api *PrivateDebugAPI) getModifiedAccounts(startBlock, endBlock *types.Bloc
544544
return dirty, nil
545545
}
546546

547-
func (api *PublicDebugAPI) CreateAccessList(blockNrOrHash rpc.BlockNumberOrHash, reexec uint64, args *ethapi.SendTxArgs) (*types.AccessList, error) {
547+
type AccessListResult struct {
548+
Accesslist *types.AccessList
549+
Error string
550+
GasUsed uint64
551+
}
552+
553+
func (api *PublicDebugAPI) CreateAccessList(blockNrOrHash rpc.BlockNumberOrHash, reexec uint64, args *ethapi.SendTxArgs) (*AccessListResult, error) {
548554
ctx := context.Background()
549555
var block *types.Block
550556
if number, ok := blockNrOrHash.Number(); ok {
@@ -562,5 +568,9 @@ func (api *PublicDebugAPI) CreateAccessList(blockNrOrHash rpc.BlockNumberOrHash,
562568
} else {
563569
return nil, errors.New("either block number or block hash must be specified")
564570
}
565-
return api.eth.APIBackend.AccessList(ctx, block, reexec, args)
571+
acl, gasUsed, vmerr, err := api.eth.APIBackend.AccessList(ctx, block, reexec, args)
572+
if err != nil {
573+
return nil, err
574+
}
575+
return &AccessListResult{Accesslist: acl, Error: vmerr.Error(), GasUsed: gasUsed}, nil
566576
}

eth/api_backend.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)