Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interface: Add CallMsg.GasFeeCap,GasTipCap #29

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions accounts/abi/bind/backends/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,16 @@ func (b *BlockchainContractBackend) callContract(call kaia.CallMsg, block *types
if call.AccessList != nil {
accessList = *call.AccessList
}
msg := types.NewMessage(call.From, call.To, 0, call.Value, call.Gas, call.GasPrice, call.Data,
gasPrice := common.Big0
if call.GasPrice != nil && (call.GasFeeCap != nil || call.GasTipCap != nil) {
return nil, errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified")
} else if call.GasPrice != nil {
gasPrice = call.GasPrice
} else if call.GasFeeCap != nil {
gasPrice = call.GasFeeCap
hyeonLewis marked this conversation as resolved.
Show resolved Hide resolved
}

msg := types.NewMessage(call.From, call.To, 0, call.Value, call.Gas, gasPrice, call.Data,
false, intrinsicGas, accessList)

txContext := blockchain.NewEVMTxContext(msg, block.Header(), b.bc.Config())
Expand Down Expand Up @@ -232,7 +241,16 @@ func (b *BlockchainContractBackend) EstimateGas(ctx context.Context, call kaia.C
return res.Failed(), res, nil
}

estimated, err := blockchain.DoEstimateGas(ctx, call.Gas, 0, call.Value, call.GasPrice, balance, executable)
gasPrice := common.Big0
if call.GasPrice != nil && (call.GasFeeCap != nil || call.GasTipCap != nil) {
return 0, errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified")
} else if call.GasPrice != nil {
gasPrice = call.GasPrice
} else if call.GasFeeCap != nil {
gasPrice = call.GasFeeCap
}

estimated, err := blockchain.DoEstimateGas(ctx, call.Gas, 0, call.Value, gasPrice, balance, executable)
return uint64(estimated), err
}

Expand Down
35 changes: 35 additions & 0 deletions accounts/abi/bind/backends/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"encoding/hex"
"errors"
"fmt"
"math/big"
"strings"
"testing"
Expand Down Expand Up @@ -133,6 +134,18 @@ func TestBlockchainCallContract(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, expectedReturn, ret)

// Argument error - both gasPrice and feecap, tipcap
ret, err = c.CallContract(context.Background(), kaia.CallMsg{
From: testAddr,
To: &code1Addr,
Gas: 1000000,
Data: data_receive,
GasPrice: big.NewInt(1),
GasFeeCap: big.NewInt(1),
GasTipCap: big.NewInt(1),
}, nil)
assert.Equal(t, "both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified", err.Error())

// Error outside VM - Intrinsic Gas
ret, err = c.CallContract(context.Background(), kaia.CallMsg{
From: testAddr,
Expand Down Expand Up @@ -226,6 +239,28 @@ func TestBlockChainEstimateGas(t *testing.T) {
})
assert.Contains(t, err.Error(), "insufficient balance for transfer")
assert.Zero(t, gas)

// Error case - simple transfer with high GasPrice
gas, err = c.EstimateGas(context.Background(), kaia.CallMsg{
From: testAddr,
To: &testAddr,
Value: big.NewInt(1),
GasPrice: big.NewInt(1e9),
})
assert.Zero(t, gas)
fmt.Println(gas, err)
blukat29 marked this conversation as resolved.
Show resolved Hide resolved
assert.Contains(t, err.Error(), "gas required exceeds allowance")

// Error case - simple transfer with high GasFeeCap
gas, err = c.EstimateGas(context.Background(), kaia.CallMsg{
From: testAddr,
To: &testAddr,
Value: big.NewInt(1),
GasFeeCap: big.NewInt(1e9),
})
assert.Zero(t, gas)
fmt.Println(gas, err)
assert.Contains(t, err.Error(), "gas required exceeds allowance")
}

func TestBlockChainSendTransaction(t *testing.T) {
Expand Down
25 changes: 20 additions & 5 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,16 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call kaia.CallMsg) (
return res.Failed(), res, nil
}

estimated, err := blockchain.DoEstimateGas(ctx, call.Gas, 0, call.Value, call.GasPrice, balance, executable)
gasPrice := common.Big0
if call.GasPrice != nil && (call.GasFeeCap != nil || call.GasTipCap != nil) {
return 0, errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified")
} else if call.GasPrice != nil {
gasPrice = call.GasPrice
} else if call.GasFeeCap != nil {
gasPrice = call.GasFeeCap
}

estimated, err := blockchain.DoEstimateGas(ctx, call.Gas, 0, call.Value, gasPrice, balance, executable)
if err != nil {
return 0, err
} else {
Expand All @@ -453,9 +462,6 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call kaia.CallMsg) (
// state is modified during execution, make sure to copy it if necessary.
func (b *SimulatedBackend) callContract(_ context.Context, call kaia.CallMsg, block *types.Block, stateDB *state.StateDB) (*blockchain.ExecutionResult, error) {
// Ensure message is initialized properly.
if call.GasPrice == nil {
call.GasPrice = big.NewInt(1)
}
if call.Gas == 0 {
call.Gas = 50000000
}
Expand All @@ -473,7 +479,16 @@ func (b *SimulatedBackend) callContract(_ context.Context, call kaia.CallMsg, bl
if call.AccessList != nil {
accessList = *call.AccessList
}
msg := types.NewMessage(call.From, call.To, nonce, call.Value, call.Gas, call.GasPrice, call.Data, true, intrinsicGas, accessList)
gasPrice := common.Big0
if call.GasPrice != nil && (call.GasFeeCap != nil || call.GasTipCap != nil) {
return nil, errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified")
} else if call.GasPrice != nil {
gasPrice = call.GasPrice
} else if call.GasFeeCap != nil {
gasPrice = call.GasFeeCap
}

msg := types.NewMessage(call.From, call.To, nonce, call.Value, call.Gas, gasPrice, call.Data, true, intrinsicGas, accessList)

txContext := blockchain.NewEVMTxContext(msg, block.Header(), b.config)
blockContext := blockchain.NewEVMBlockContext(block.Header(), b.blockchain, nil)
Expand Down
12 changes: 12 additions & 0 deletions accounts/abi/bind/backends/simulated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,18 @@ func TestSimulatedBackend_EstimateGas(t *testing.T) {
Data: common.Hex2Bytes("50f6fe34"),
}, 0, errors.New("gas required exceeds allowance (100000)"), nil},

{"HighGasPrice", kaia.CallMsg{
From: addr,
To: &addr,
GasPrice: big.NewInt(1e9),
}, 0, errors.New("gas required exceeds allowance (10)"), nil},

{"HighFeeCap", kaia.CallMsg{
From: addr,
To: &addr,
GasFeeCap: big.NewInt(1e9),
}, 0, errors.New("gas required exceeds allowance (10)"), nil},

{"Assert", kaia.CallMsg{
From: addr,
To: &contractAddr,
Expand Down
18 changes: 18 additions & 0 deletions client/kaia_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,15 @@ func toCallArg(msg kaia.CallMsg) interface{} {
if msg.GasPrice != nil {
arg["gasPrice"] = (*hexutil.Big)(msg.GasPrice)
}
if msg.GasFeeCap != nil {
arg["maxFeePerGas"] = (*hexutil.Big)(msg.GasFeeCap)
}
if msg.GasTipCap != nil {
arg["maxPriorityFeePerGas"] = (*hexutil.Big)(msg.GasTipCap)
}
if msg.AccessList != nil {
arg["accessList"] = msg.AccessList
}
return arg
}

Expand All @@ -581,6 +590,12 @@ func toSendTxArgs(msg api.SendTxArgs) interface{} {
if msg.Price != nil {
arg["gasPrice"] = (*hexutil.Big)(msg.Price)
}
if msg.MaxFeePerGas != nil {
blukat29 marked this conversation as resolved.
Show resolved Hide resolved
arg["maxFeePerGas"] = (*hexutil.Big)(msg.MaxFeePerGas)
}
if msg.MaxPriorityFeePerGas != nil {
arg["maxPriorityFeePerGas"] = (*hexutil.Big)(msg.MaxPriorityFeePerGas)
}
if msg.Amount != nil {
arg["value"] = (*hexutil.Big)(msg.Amount)
}
Expand All @@ -590,6 +605,9 @@ func toSendTxArgs(msg api.SendTxArgs) interface{} {
if len(*msg.Payload) > 0 {
arg["input"] = (*hexutil.Bytes)(msg.Payload)
}
if msg.AccessList != nil {
arg["accessList"] = msg.AccessList
}

return arg
}
Expand Down
14 changes: 8 additions & 6 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,14 @@ type ChainSyncReader interface {

// CallMsg contains parameters for contract calls.
type CallMsg struct {
From common.Address // the sender of the 'transaction'
To *common.Address // the destination contract (nil for contract creation)
Gas uint64 // if 0, the call executes with near-infinite gas
GasPrice *big.Int // kei <-> gas exchange ratio
Value *big.Int // amount of kei sent along with the call
Data []byte // input data, usually an ABI-encoded contract method invocation
From common.Address // the sender of the 'transaction'
To *common.Address // the destination contract (nil for contract creation)
Gas uint64 // if 0, the call executes with near-infinite gas
GasPrice *big.Int // kei <-> gas exchange ratio
GasFeeCap *big.Int // EIP-1559 fee cap per gas.
GasTipCap *big.Int // EIP-1559 tip per gas.
blukat29 marked this conversation as resolved.
Show resolved Hide resolved
Value *big.Int // amount of kei sent along with the call
Data []byte // input data, usually an ABI-encoded contract method invocation

// Introduced by AccessListTxType transaction.
AccessList *types.AccessList `json:"accessList,omitempty"`
Expand Down
9 changes: 9 additions & 0 deletions node/sc/remote_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,14 @@ func toCallArg(msg klaytn.CallMsg) interface{} {
if msg.GasPrice != nil {
arg["gasPrice"] = (*hexutil.Big)(msg.GasPrice)
}
if msg.GasFeeCap != nil {
arg["maxFeePerGas"] = (*hexutil.Big)(msg.GasFeeCap)
}
if msg.GasTipCap != nil {
arg["maxPriorityFeePerGas"] = (*hexutil.Big)(msg.GasTipCap)
}
if msg.AccessList != nil {
arg["accessList"] = msg.AccessList
}
return arg
}
Loading