Skip to content

Commit

Permalink
feat: allow to bump the gas limit higher than returned from estimate …
Browse files Browse the repository at this point in the history
…gas (#36)
  • Loading branch information
minh-bq authored Apr 17, 2023
1 parent 4bfcaa1 commit 8258b81
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
3 changes: 2 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ type LsConfig struct {

// MaxProcessingTasks is used to specify max processing tasks allowed while processing tasks
// if number of tasks reaches this number, it waits until this number decrease
MaxProcessingTasks int `json:"maxProcessingTasks"`
MaxProcessingTasks int `json:"maxProcessingTasks"`
GasLimitBumpRatio uint64 `json:"gasLimitBumpRatio"`
}

type Secret struct {
Expand Down
27 changes: 22 additions & 5 deletions utils/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
"golang.org/x/crypto/sha3"
"math/big"
"os"
"reflect"
"sync"

"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
"golang.org/x/crypto/sha3"

kmsUtils "github.com/axieinfinity/ronin-kms-client/utils"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
Expand All @@ -26,6 +27,8 @@ import (
"golang.org/x/text/language"
)

const Percentage = 100

// hasherPool holds LegacyKeccak256 hashers for rlpHash.
var hasherPool = sync.Pool{
New: func() interface{} { return sha3.NewLegacyKeccak256() },
Expand All @@ -50,7 +53,7 @@ type Utils interface {
UnpackToInterface(a abi.ABI, name string, data []byte, isInput bool, v interface{}) error
Title(text string) string
NewEthClient(url string) (EthClient, error)
SendContractTransaction(signMethod ISign, chainId *big.Int, fn func(opts *bind.TransactOpts) (*types.Transaction, error)) (*types.Transaction, error)
SendContractTransaction(signMethod ISign, chainId *big.Int, gasLimitBumpRatio uint64, fn func(opts *bind.TransactOpts) (*types.Transaction, error)) (*types.Transaction, error)
SignTypedData(typedData core.TypedData, signMethod ISign) (hexutil.Bytes, error)
FilterLogs(client EthClient, opts *bind.FilterOpts, contractAddresses []common.Address, filteredMethods map[*abi.ABI]map[string]struct{}) ([]types.Log, error)
RlpHash(x interface{}) (h common.Hash)
Expand Down Expand Up @@ -178,11 +181,25 @@ func newKeyedTransactorWithChainID(signMethod ISign, chainID *big.Int) (*bind.Tr
}, nil
}

func (u *utils) SendContractTransaction(signMethod ISign, chainId *big.Int, fn func(opts *bind.TransactOpts) (*types.Transaction, error)) (*types.Transaction, error) {
func (u *utils) SendContractTransaction(
signMethod ISign,
chainId *big.Int,
gasLimitBumpRatio uint64,
fn func(opts *bind.TransactOpts) (*types.Transaction, error),
) (*types.Transaction, error) {
opts, err := newKeyedTransactorWithChainID(signMethod, chainId)
if err != nil {
return nil, err
}
// Estimate gas
opts.NoSend = true
tx, err := fn(opts)
if err != nil {
return nil, err
}

opts.NoSend = false
opts.GasLimit = tx.Gas() * gasLimitBumpRatio / Percentage
return fn(opts)
}

Expand Down

0 comments on commit 8258b81

Please sign in to comment.