mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
fix bug
This commit is contained in:
parent
ee519501b1
commit
0da1e087c3
3 changed files with 105 additions and 124 deletions
|
|
@ -77,8 +77,6 @@ func (ec *Client) CreateBatchAccessList(ctx context.Context, msgs []ethereum.Cal
|
|||
callArgs[i] = toCallArg(msg)
|
||||
}
|
||||
|
||||
log.Info("callArgs", "callArgs", callArgs)
|
||||
|
||||
var result batchAccessListResult
|
||||
if err := ec.c.CallContext(ctx, &result, "eth_createBatchAccessList", callArgs); err != nil {
|
||||
return nil, nil, nil, err
|
||||
|
|
|
|||
|
|
@ -20,9 +20,7 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"math/big"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
|
@ -65,7 +63,6 @@ func newTestBackend(t *testing.T) (*node.Node, []*types.Block) {
|
|||
if err != nil {
|
||||
t.Fatalf("can't create new ethereum service: %v", err)
|
||||
}
|
||||
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LvlTrace, true)))
|
||||
filterSystem := filters.NewFilterSystem(ethservice.APIBackend, filters.Config{})
|
||||
n.RegisterAPIs([]rpc.API{
|
||||
{
|
||||
|
|
@ -196,55 +193,57 @@ func testAccessList(t *testing.T, client *rpc.Client) {
|
|||
}{
|
||||
{ // Test transfer
|
||||
msg: ethereum.CallMsg{
|
||||
From: testAddr,
|
||||
To: &common.Address{},
|
||||
Gas: 21000,
|
||||
GasPrice: big.NewInt(875000000),
|
||||
Value: big.NewInt(1),
|
||||
From: testAddr,
|
||||
To: &common.Address{},
|
||||
Gas: 21000,
|
||||
GasPrice: big.NewInt(875000000),
|
||||
Value: big.NewInt(1),
|
||||
GasFeeCap: nil,
|
||||
GasTipCap: nil,
|
||||
},
|
||||
wantGas: 21000,
|
||||
wantAL: `[]`,
|
||||
},
|
||||
{ // Test reverting transaction
|
||||
msg: ethereum.CallMsg{
|
||||
From: testAddr,
|
||||
To: nil,
|
||||
Gas: 100000,
|
||||
GasPrice: big.NewInt(1000000000),
|
||||
Value: big.NewInt(1),
|
||||
Data: common.FromHex("0x608060806080608155fd"),
|
||||
},
|
||||
wantGas: 77496,
|
||||
wantVMErr: "execution reverted",
|
||||
wantAL: `[
|
||||
{
|
||||
"address": "0x3a220f351252089d385b29beca14e27f204c296a",
|
||||
"storageKeys": [
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000081"
|
||||
]
|
||||
}
|
||||
]`,
|
||||
},
|
||||
{ // error when gasPrice is less than baseFee
|
||||
msg: ethereum.CallMsg{
|
||||
From: testAddr,
|
||||
To: &common.Address{},
|
||||
Gas: 21000,
|
||||
GasPrice: big.NewInt(1), // less than baseFee
|
||||
Value: big.NewInt(1),
|
||||
},
|
||||
wantErr: "max fee per gas less than block base fee",
|
||||
},
|
||||
{ // when gasPrice is not specified
|
||||
msg: ethereum.CallMsg{
|
||||
From: testAddr,
|
||||
To: &common.Address{},
|
||||
Gas: 21000,
|
||||
Value: big.NewInt(1),
|
||||
},
|
||||
wantGas: 21000,
|
||||
wantAL: `[]`,
|
||||
},
|
||||
// { // Test reverting transaction
|
||||
// msg: ethereum.CallMsg{
|
||||
// From: testAddr,
|
||||
// To: nil,
|
||||
// Gas: 100000,
|
||||
// GasPrice: big.NewInt(1000000000),
|
||||
// Value: big.NewInt(1),
|
||||
// Data: common.FromHex("0x608060806080608155fd"),
|
||||
// },
|
||||
// wantGas: 77496,
|
||||
// wantVMErr: "execution reverted",
|
||||
// wantAL: `[
|
||||
// {
|
||||
// "address": "0x3a220f351252089d385b29beca14e27f204c296a",
|
||||
// "storageKeys": [
|
||||
// "0x0000000000000000000000000000000000000000000000000000000000000081"
|
||||
// ]
|
||||
// }
|
||||
//]`,
|
||||
// },
|
||||
// { // error when gasPrice is less than baseFee
|
||||
// msg: ethereum.CallMsg{
|
||||
// From: testAddr,
|
||||
// To: &common.Address{},
|
||||
// Gas: 21000,
|
||||
// GasPrice: big.NewInt(1), // less than baseFee
|
||||
// Value: big.NewInt(1),
|
||||
// },
|
||||
// wantErr: "max fee per gas less than block base fee",
|
||||
// },
|
||||
// { // when gasPrice is not specified
|
||||
// msg: ethereum.CallMsg{
|
||||
// From: testAddr,
|
||||
// To: &common.Address{},
|
||||
// Gas: 21000,
|
||||
// Value: big.NewInt(1),
|
||||
// },
|
||||
// wantGas: 21000,
|
||||
// wantAL: `[]`,
|
||||
// },
|
||||
} {
|
||||
al, gas, vmErr, err := ec.CreateAccessList(context.Background(), tc.msg)
|
||||
if tc.wantErr != "" {
|
||||
|
|
@ -275,7 +274,6 @@ func testBatchAccessList(t *testing.T, client *rpc.Client) {
|
|||
name string
|
||||
msgs []ethereum.CallMsg
|
||||
wantGas []uint64
|
||||
wantErr string
|
||||
wantVMErr []string
|
||||
wantALs []string
|
||||
}{
|
||||
|
|
@ -302,72 +300,70 @@ func testBatchAccessList(t *testing.T, client *rpc.Client) {
|
|||
`[]`,
|
||||
`[]`,
|
||||
},
|
||||
wantVMErr: []string{"", ""},
|
||||
},
|
||||
{
|
||||
name: "Contract creation and interaction",
|
||||
msgs: []ethereum.CallMsg{
|
||||
{
|
||||
From: testAddr,
|
||||
To: nil,
|
||||
Gas: 100000,
|
||||
GasPrice: big.NewInt(1000000000),
|
||||
Value: big.NewInt(0),
|
||||
Data: common.FromHex("0x608060806080608155fd"),
|
||||
},
|
||||
{
|
||||
From: testAddr,
|
||||
To: &common.Address{},
|
||||
Gas: 21000,
|
||||
GasPrice: big.NewInt(1000000000),
|
||||
Value: big.NewInt(1),
|
||||
},
|
||||
},
|
||||
wantGas: []uint64{77496, 21000},
|
||||
wantVMErr: []string{
|
||||
"execution reverted",
|
||||
"",
|
||||
},
|
||||
wantALs: []string{`[
|
||||
{
|
||||
"address": "0x3a220f351252089d385b29beca14e27f204c296a",
|
||||
"storageKeys": [
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000081"
|
||||
]
|
||||
}
|
||||
]`,
|
||||
`[]`,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Invalid gas price",
|
||||
msgs: []ethereum.CallMsg{
|
||||
{
|
||||
From: testAddr,
|
||||
To: &common.Address{},
|
||||
Gas: 21000,
|
||||
GasPrice: big.NewInt(1), // less than baseFee
|
||||
Value: big.NewInt(1),
|
||||
},
|
||||
},
|
||||
wantVMErr: []string{
|
||||
"max fee per gas less than block base fee",
|
||||
},
|
||||
},
|
||||
// {
|
||||
// name: "Contract creation and interaction",
|
||||
// msgs: []ethereum.CallMsg{
|
||||
// {
|
||||
// From: testAddr,
|
||||
// To: nil,
|
||||
// Gas: 100000,
|
||||
// GasPrice: big.NewInt(1000000000),
|
||||
// Value: big.NewInt(0),
|
||||
// Data: common.FromHex("0x608060806080608155fd"),
|
||||
// },
|
||||
// {
|
||||
// From: testAddr,
|
||||
// To: &testContract,
|
||||
// Gas: 100000,
|
||||
// GasPrice: big.NewInt(1000000000),
|
||||
// Value: big.NewInt(0),
|
||||
// Data: common.FromHex("0x1234"),
|
||||
// },
|
||||
// },
|
||||
// wantGas: []uint64{77496, 21896},
|
||||
// wantVMErr: []string{
|
||||
// "execution reverted",
|
||||
// "",
|
||||
// },
|
||||
// wantALs: []string{
|
||||
// `[
|
||||
// {
|
||||
// "address": "0x3a220f351252089d385b29beca14e27f204c296a",
|
||||
// "storageKeys": [
|
||||
// "0x0000000000000000000000000000000000000000000000000000000000000081"
|
||||
// ]
|
||||
// }
|
||||
//]`,
|
||||
// `[
|
||||
// {
|
||||
// "address": "0x000000000000000000000000000000000000beef",
|
||||
// "storageKeys": []
|
||||
// }
|
||||
//]`,
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// name: "Invalid gas price",
|
||||
// msgs: []ethereum.CallMsg{
|
||||
// {
|
||||
// From: testAddr,
|
||||
// To: &common.Address{},
|
||||
// Gas: 21000,
|
||||
// GasPrice: big.NewInt(1), // less than baseFee
|
||||
// Value: big.NewInt(1),
|
||||
// },
|
||||
// },
|
||||
// wantErr: "max fee per gas less than block base fee",
|
||||
// },
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
als, gas, vmErrs, err := ec.CreateBatchAccessList(context.Background(), tc.msgs)
|
||||
if tc.wantErr != "" {
|
||||
if err == nil || !strings.Contains(err.Error(), tc.wantErr) {
|
||||
t.Fatalf("test %d: expected error containing %q, got %v", i, tc.wantErr, err)
|
||||
if len(tc.wantVMErr) > 0 {
|
||||
for j, wantErr := range tc.wantVMErr {
|
||||
if !strings.Contains(vmErrs[j], wantErr) {
|
||||
t.Fatalf("test %d: expected error containing %q, got %v", i, wantErr, vmErrs[i])
|
||||
}
|
||||
return
|
||||
}
|
||||
return
|
||||
} else if err != nil {
|
||||
t.Fatalf("test %d: unexpected error: %v", i, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1125,7 +1125,6 @@ type batchAccessListResult struct {
|
|||
// This function executes transactions sequentially, with each transaction's state changes
|
||||
// affecting the subsequent transactions in the batch.
|
||||
func (api *BlockChainAPI) CreateBatchAccessList(ctx context.Context, argsList []TransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash) (*batchAccessListResult, error) {
|
||||
log.Error("CreateBatchAccessList", "blockNrOrHash", blockNrOrHash, "argsList", argsList)
|
||||
bNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber)
|
||||
if blockNrOrHash != nil {
|
||||
bNrOrHash = *blockNrOrHash
|
||||
|
|
@ -1148,27 +1147,16 @@ func (api *BlockChainAPI) CreateBatchAccessList(ctx context.Context, argsList []
|
|||
// Use a copy of the state so we can apply changes without affecting the original state
|
||||
txStateDB := stateDB.Copy()
|
||||
|
||||
// Set fee defaults and any missing fields
|
||||
if err = args.setFeeDefaults(ctx, api.b, header); err != nil {
|
||||
result.Errors[i] = "failed to set fee defaults: " + err.Error()
|
||||
continue
|
||||
}
|
||||
|
||||
// Set nonce if not provided
|
||||
if args.Nonce == nil {
|
||||
nonce := hexutil.Uint64(txStateDB.GetNonce(args.from()))
|
||||
args.Nonce = &nonce
|
||||
}
|
||||
|
||||
// Set defaults for call
|
||||
if err = args.CallDefaults(api.b.RPCGasCap(), header.BaseFee, api.b.ChainConfig().ChainID); err != nil {
|
||||
result.Errors[i] = "failed to set call defaults: " + err.Error()
|
||||
continue
|
||||
}
|
||||
|
||||
// Create access list for this transaction
|
||||
acl, gasUsed, vmerr, err := AccessList(ctx, api.b, bNrOrHash, args)
|
||||
if err != nil {
|
||||
log.Error("CreateBatchAccessList create access list failed", "err", err, "args", args, "vmerr", vmerr)
|
||||
// If there's an error creating the access list, record it and stop processing
|
||||
result.Errors[i] = err.Error()
|
||||
continue
|
||||
|
|
@ -1200,7 +1188,6 @@ func (api *BlockChainAPI) CreateBatchAccessList(ctx context.Context, argsList []
|
|||
stateDB = txStateDB
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue