Skip to content

Commit

Permalink
Merge pull request #45 from siburu/use-latest-nonce
Browse files Browse the repository at this point in the history
Set the latest nonce to TransactOpts.Nonce to avoid piling up pending txs
  • Loading branch information
siburu authored May 28, 2024
2 parents 1db9ee9 + ee8d08f commit 70a0219
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions pkg/relay/ethereum/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,25 @@ func (chain *Chain) CallOpts(ctx context.Context, height int64) *bind.CallOpts {
return opts
}

func (chain *Chain) TxOpts(ctx context.Context) (*bind.TransactOpts, error) {
func (chain *Chain) TxOpts(ctx context.Context, useLatestNonce bool) (*bind.TransactOpts, error) {
addr := chain.signer.Address()

txOpts := &bind.TransactOpts{
From: chain.signer.Address(),
From: addr,
Signer: chain.signer.Sign,
}

if err := NewGasFeeCalculator(chain.client, &chain.config).Apply(ctx, txOpts); err != nil {
return nil, err
}

if useLatestNonce {
if nonce, err := chain.client.NonceAt(ctx, addr, nil); err != nil {
return nil, err
} else {
txOpts.Nonce = new(big.Int).SetUint64(nonce)
}
}

return txOpts, nil
}
2 changes: 1 addition & 1 deletion pkg/relay/ethereum/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (c *Chain) SendMsgs(msgs []sdk.Msg) ([]core.MsgID, error) {
logAttrMsgType, fmt.Sprintf("%T", msg),
)}

opts, err := c.TxOpts(ctx)
opts, err := c.TxOpts(ctx, true)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 70a0219

Please sign in to comment.