Skip to content

Commit

Permalink
fix: use defaults in opts
Browse files Browse the repository at this point in the history
  • Loading branch information
Alok committed Jul 19, 2024
1 parent eff7bbb commit ea2a59e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 34 deletions.
2 changes: 1 addition & 1 deletion oracle/pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func NewNode(opts *Options) (*Node, error) {

monitorClosed := monitor.Start(ctx)

txnMgr := transactor.NewTransactorWithDefaults(
txnMgr := transactor.NewTransactor(
settlementClient,
monitor,
)
Expand Down
2 changes: 1 addition & 1 deletion p2p/pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func NewNode(opts *Options) (*Node, error) {
srv.RegisterMetricsCollectors(monitor.Metrics()...)

contractsBackend := transactor.NewMetricsWrapper(
transactor.NewTransactorWithDefaults(
transactor.NewTransactor(
contractRPC,
monitor,
),
Expand Down
32 changes: 2 additions & 30 deletions x/contracts/transactor/transactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@ package transactor

import (
"context"
"math/big"
"time"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

const (
txnRetriesLimit = 3
defaultGasLimit = 1_000_000
defaultGasTip = 1_000
)

// Watcher is an interface that is used to manage the lifecycle of a transaction.
Expand All @@ -41,9 +37,8 @@ type Watcher interface {
// of an error, the nonce is put back into the channel so that it can be reused.
type Transactor struct {
bind.ContractBackend
nonceChan chan uint64
watcher Watcher
useDefault bool
nonceChan chan uint64
watcher Watcher
}

func NewTransactor(
Expand All @@ -62,15 +57,6 @@ func NewTransactor(
}
}

func NewTransactorWithDefaults(
backend bind.ContractBackend,
watcher Watcher,
) *Transactor {
t := NewTransactor(backend, watcher)
t.useDefault = true
return t
}

func (t *Transactor) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) {
select {
case <-ctx.Done():
Expand Down Expand Up @@ -133,17 +119,3 @@ func (t *Transactor) SendTransaction(ctx context.Context, tx *types.Transaction)

return nil
}

func (t *Transactor) EstimateGas(ctx context.Context, callMsg ethereum.CallMsg) (gas uint64, err error) {
if t.useDefault {
return defaultGasLimit, nil
}
return t.ContractBackend.EstimateGas(ctx, callMsg)
}

func (t *Transactor) SuggestGasTipCap(ctx context.Context) (tip *big.Int, err error) {
if t.useDefault {
return big.NewInt(defaultGasTip), nil
}
return t.ContractBackend.SuggestGasTipCap(ctx)
}
10 changes: 9 additions & 1 deletion x/keysigner/keystoresigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ func (kss *KeystoreSigner) String() string {
}

func (kss *KeystoreSigner) GetAuth(chainID *big.Int) (*bind.TransactOpts, error) {
return bind.NewKeyStoreTransactorWithChainID(kss.keystore, kss.account, chainID)
opts, err := bind.NewKeyStoreTransactorWithChainID(kss.keystore, kss.account, chainID)
if err != nil {
return nil, err
}

opts.GasLimit = 1_000_000
opts.GasTipCap = big.NewInt(1)
opts.GasFeeCap = big.NewInt(20000000000)
return opts, nil
}

func (kss *KeystoreSigner) GetAuthWithCtx(ctx context.Context, chainID *big.Int) (*bind.TransactOpts, error) {
Expand Down
10 changes: 9 additions & 1 deletion x/keysigner/privatekeysigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ func (pks *PrivateKeySigner) GetPrivateKey() (*ecdsa.PrivateKey, error) {
}

func (pks *PrivateKeySigner) GetAuth(chainID *big.Int) (*bind.TransactOpts, error) {
return bind.NewKeyedTransactorWithChainID(pks.privKey, chainID)
opts, err := bind.NewKeyedTransactorWithChainID(pks.privKey, chainID)
if err != nil {
return nil, err
}

opts.GasLimit = 1_000_000
opts.GasTipCap = big.NewInt(1)
opts.GasFeeCap = big.NewInt(20000000000)
return opts, nil
}

func (pks *PrivateKeySigner) GetAuthWithCtx(ctx context.Context, chainID *big.Int) (*bind.TransactOpts, error) {
Expand Down

0 comments on commit ea2a59e

Please sign in to comment.