fix tx gaslimit and type default

This commit is contained in:
Sina Mahmoodi 2023-09-20 18:54:43 +02:00
parent 3df0fec8e2
commit 760f5e5b24
3 changed files with 19 additions and 19 deletions

View file

@ -449,7 +449,7 @@ func (s *PersonalAccountAPI) signTransaction(ctx context.Context, args *Transact
return nil, err
}
// Assemble the transaction and sign with the wallet
tx := args.toTransaction()
tx := args.toTransaction(false)
return wallet.SignTxWithPassphrase(account, passwd, tx, s.b.ChainConfig().ChainID)
}
@ -492,7 +492,7 @@ func (s *PersonalAccountAPI) SignTransaction(ctx context.Context, args Transacti
return nil, errors.New("nonce not specified")
}
// Before actually signing the transaction, ensure the transaction fee is reasonable.
tx := args.toTransaction()
tx := args.toTransaction(false)
if err := checkTxFee(tx.GasPrice(), tx.Gas(), s.b.RPCTxFeeCap()); err != nil {
return nil, err
}
@ -1299,7 +1299,7 @@ func (s *BlockChainAPI) MulticallV1(ctx context.Context, opts multicallOpts, blo
if blockContext.Random != nil {
results[bi].PrevRandao = *blockContext.Random
}
gasUsed := uint64(0)
var gasUsed uint64
for i, call := range block.Calls {
// setDefaults will consult txpool's nonce tracker. Work around that.
if call.Nonce == nil {
@ -1308,8 +1308,8 @@ func (s *BlockChainAPI) MulticallV1(ctx context.Context, opts multicallOpts, blo
}
// Let the call run wild unless explicitly specified.
if call.Gas == nil {
leftGas := gp.Gas()
call.Gas = (*hexutil.Uint64)(&leftGas)
remaining := blockContext.GasLimit - gasUsed
call.Gas = (*hexutil.Uint64)(&remaining)
}
if call.GasPrice == nil && call.MaxFeePerGas == nil && call.MaxPriorityFeePerGas == nil {
call.GasPrice = (*hexutil.Big)(big.NewInt(0))
@ -1318,7 +1318,7 @@ func (s *BlockChainAPI) MulticallV1(ctx context.Context, opts multicallOpts, blo
if err := call.setDefaults(ctx, s.b); err != nil {
return nil, err
}
tx := call.ToTransaction()
tx := call.ToTransaction(true)
vmConfig := &vm.Config{
NoBaseFee: true,
Tracer: newTracer(opts.TraceTransfers, blockContext.BlockNumber.Uint64(), hash, tx.Hash(), uint(i)),
@ -1853,7 +1853,7 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH
vmenv, _ := b.GetEVM(ctx, msg, statedb, header, &config, nil)
res, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.GasLimit))
if err != nil {
return nil, 0, nil, fmt.Errorf("failed to apply transaction: %v err: %v", args.toTransaction().Hash(), err)
return nil, 0, nil, fmt.Errorf("failed to apply transaction: %v err: %v", args.toTransaction(false).Hash(), err)
}
if tracer.Equal(prevTracer) {
return accessList, res.UsedGas, res.Err, nil
@ -2121,7 +2121,7 @@ func (s *TransactionAPI) SendTransaction(ctx context.Context, args TransactionAr
return common.Hash{}, err
}
// Assemble the transaction and sign with the wallet
tx := args.toTransaction()
tx := args.toTransaction(false)
signed, err := wallet.SignTx(account, tx, s.b.ChainConfig().ChainID)
if err != nil {
@ -2139,7 +2139,7 @@ func (s *TransactionAPI) FillTransaction(ctx context.Context, args TransactionAr
return nil, err
}
// Assemble the transaction and obtain rlp
tx := args.toTransaction()
tx := args.toTransaction(false)
data, err := tx.MarshalBinary()
if err != nil {
return nil, err
@ -2205,7 +2205,7 @@ func (s *TransactionAPI) SignTransaction(ctx context.Context, args TransactionAr
return nil, err
}
// Before actually sign the transaction, ensure the transaction fee is reasonable.
tx := args.toTransaction()
tx := args.toTransaction(false)
if err := checkTxFee(tx.GasPrice(), tx.Gas(), s.b.RPCTxFeeCap()); err != nil {
return nil, err
}
@ -2253,7 +2253,7 @@ func (s *TransactionAPI) Resend(ctx context.Context, sendArgs TransactionArgs, g
if err := sendArgs.setDefaults(ctx, s.b); err != nil {
return common.Hash{}, err
}
matchTx := sendArgs.toTransaction()
matchTx := sendArgs.toTransaction(false)
// Before replacing the old transaction, ensure the _new_ transaction fee is reasonable.
var price = matchTx.GasPrice()
@ -2283,7 +2283,7 @@ func (s *TransactionAPI) Resend(ctx context.Context, sendArgs TransactionArgs, g
if gasLimit != nil && *gasLimit != 0 {
sendArgs.Gas = gasLimit
}
signedTx, err := s.sign(sendArgs.from(), sendArgs.toTransaction())
signedTx, err := s.sign(sendArgs.from(), sendArgs.toTransaction(false))
if err != nil {
return common.Hash{}, err
}

View file

@ -992,7 +992,7 @@ func TestMulticallV1(t *testing.T) {
Index hexutil.Uint `json:"logIndex"`
}
type callRes struct {
ReturnValue string `json:"return"`
ReturnValue string `json:"returnData"`
Error string
Logs []log
GasUsed string
@ -1123,7 +1123,7 @@ func TestMulticallV1(t *testing.T) {
GasUsed: "0x0",
Logs: []log{},
Status: "0x0",
Error: fmt.Sprintf("err: insufficient funds for gas * price + value: address %s have 0 want 1000 (supplied gas 9937000)", randomAccounts[3].addr.String()),
Error: fmt.Sprintf("err: insufficient funds for gas * price + value: address %s have 0 want 1000 (supplied gas 4691388)", randomAccounts[3].addr.String()),
}},
}},
}, {
@ -1574,7 +1574,7 @@ func TestMulticallV1(t *testing.T) {
GasUsed: "0x0",
Logs: []log{},
Status: "0x0",
Error: fmt.Sprintf("err: nonce too high: address %s, tx: 2 state: 0 (supplied gas 10000000)", accounts[2].addr),
Error: fmt.Sprintf("err: nonce too high: address %s, tx: 2 state: 0 (supplied gas 4712388)", accounts[2].addr),
}},
}},
},

View file

@ -286,10 +286,10 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int, sk
// toTransaction converts the arguments to a transaction.
// This assumes that setDefaults has been called.
func (args *TransactionArgs) toTransaction() *types.Transaction {
func (args *TransactionArgs) toTransaction(type2 bool) *types.Transaction {
var data types.TxData
switch {
case args.MaxFeePerGas != nil:
case args.MaxFeePerGas != nil || type2:
al := types.AccessList{}
if args.AccessList != nil {
al = *args.AccessList
@ -331,6 +331,6 @@ func (args *TransactionArgs) toTransaction() *types.Transaction {
// ToTransaction converts the arguments to a transaction.
// This assumes that setDefaults has been called.
func (args *TransactionArgs) ToTransaction() *types.Transaction {
return args.toTransaction()
func (args *TransactionArgs) ToTransaction(type2 bool) *types.Transaction {
return args.toTransaction(type2)
}