Skip to content

Commit

Permalink
Rename SequenceAt (#14855)
Browse files Browse the repository at this point in the history
* Rename SequenceAt

* More changes

* Add changeset

* Return uint64 instead of nonce

* Fixes

* Disable G115
  • Loading branch information
dimriou authored Oct 21, 2024
1 parent 84bcbe0 commit 7cd384b
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 106 deletions.
5 changes: 5 additions & 0 deletions .changeset/two-snails-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

Rename SequenceAt to NonceAt #internal
6 changes: 3 additions & 3 deletions core/chains/evm/client/chain_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type Client interface {
CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)
PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
SequenceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (evmtypes.Nonce, error)
NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
TransactionByHash(ctx context.Context, txHash common.Hash) (*types.Transaction, error)
TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
Expand Down Expand Up @@ -397,12 +397,12 @@ func (c *chainClient) SendTransactionReturnCode(ctx context.Context, tx *types.T
return returnCode, err
}

func (c *chainClient) SequenceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (evmtypes.Nonce, error) {
func (c *chainClient) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) {
r, err := c.multiNode.SelectRPC()
if err != nil {
return 0, err
}
return r.SequenceAt(ctx, account, blockNumber)
return r.NonceAt(ctx, account, blockNumber)
}

func (c *chainClient) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (s ethereum.Subscription, err error) {
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/client/chain_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ func TestEthClient_ErroringClient(t *testing.T) {
require.Equal(t, code, commonclient.Unknown)
require.Equal(t, err, txSenderNotStarted)

_, err = erroringClient.SequenceAt(ctx, common.Address{}, nil)
_, err = erroringClient.NonceAt(ctx, common.Address{}, nil)
require.Equal(t, err, commonclient.ErroringNodeError)

_, err = erroringClient.SubscribeFilterLogs(ctx, ethereum.FilterQuery{}, nil)
Expand Down
116 changes: 58 additions & 58 deletions core/chains/evm/client/mocks/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions core/chains/evm/client/null_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ func (nc *NullClient) PendingNonceAt(ctx context.Context, account common.Address
return 0, nil
}

func (nc *NullClient) SequenceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (evmtypes.Nonce, error) {
nc.lggr.Debug("SequenceAt")
func (nc *NullClient) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) {
nc.lggr.Debug("NonceAt")
return 0, nil
}

Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/client/null_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ func TestNullClient(t *testing.T) {
require.Zero(t, n)
require.Equal(t, 1, logs.FilterMessage("PendingNonceAt").Len())

s, err := nc.SequenceAt(ctx, common.Address{}, nil)
s, err := nc.NonceAt(ctx, common.Address{}, nil)
require.NoError(t, err)
require.Zero(t, s)
require.Equal(t, 1, logs.FilterMessage("SequenceAt").Len())
require.Equal(t, 1, logs.FilterMessage("NonceAt").Len())

r, err := nc.TransactionReceipt(ctx, common.Hash{})
require.NoError(t, err)
Expand Down
11 changes: 4 additions & 7 deletions core/chains/evm/client/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,24 +854,21 @@ func (r *RPCClient) PendingSequenceAt(ctx context.Context, account common.Addres
return
}

// SequenceAt is a bit of a misnomer. You might expect it to return the highest
// NonceAt is a bit of a misnomer. You might expect it to return the highest
// mined nonce at the given block number, but it actually returns the total
// transaction count which is the highest mined nonce + 1
func (r *RPCClient) SequenceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (nonce evmtypes.Nonce, err error) {
func (r *RPCClient) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (nonce uint64, err error) {
ctx, cancel, ws, http := r.makeLiveQueryCtxAndSafeGetClients(ctx, r.rpcTimeout)
defer cancel()
lggr := r.newRqLggr().With("account", account, "blockNumber", blockNumber)

lggr.Debug("RPC call: evmclient.Client#NonceAt")
start := time.Now()
var n uint64
if http != nil {
n, err = http.geth.NonceAt(ctx, account, blockNumber)
nonce = evmtypes.Nonce(int64(n))
nonce, err = http.geth.NonceAt(ctx, account, blockNumber)
err = r.wrapHTTP(err)
} else {
n, err = ws.geth.NonceAt(ctx, account, blockNumber)
nonce = evmtypes.Nonce(int64(n))
nonce, err = ws.geth.NonceAt(ctx, account, blockNumber)
err = r.wrapWS(err)
}
duration := time.Since(start)
Expand Down
5 changes: 2 additions & 3 deletions core/chains/evm/client/simulated_backend_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,8 @@ func (c *SimulatedBackendClient) PendingNonceAt(ctx context.Context, account com
}

// NonceAt gets nonce as of a specified block.
func (c *SimulatedBackendClient) SequenceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (evmtypes.Nonce, error) {
nonce, err := c.b.NonceAt(ctx, account, blockNumber)
return evmtypes.Nonce(nonce), err
func (c *SimulatedBackendClient) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) {
return c.b.NonceAt(ctx, account, blockNumber)
}

// BalanceAt gets balance as of a specified block.
Expand Down
8 changes: 4 additions & 4 deletions core/chains/evm/txmgr/broadcaster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1904,7 +1904,7 @@ func TestEthBroadcaster_HederaBroadcastValidation(t *testing.T) {
ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool {
return tx.Nonce() == localNonce
}), fromAddress).Return(commonclient.Successful, nil).Once()
ethClient.On("SequenceAt", mock.Anything, fromAddress, mock.Anything).Return(evmtypes.Nonce(1), nil).Once()
ethClient.On("NonceAt", mock.Anything, fromAddress, mock.Anything).Return(uint64(1), nil).Once()

mustInsertInProgressEthTxWithAttempt(t, txStore, evmtypes.Nonce(localNonce), fromAddress)
nonceTracker := txmgr.NewNonceTracker(lggr, txStore, txmgr.NewEvmTxmClient(ethClient, nil))
Expand All @@ -1924,8 +1924,8 @@ func TestEthBroadcaster_HederaBroadcastValidation(t *testing.T) {
ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool {
return tx.Nonce() == localNonce
}), fromAddress).Return(commonclient.Successful, nil).Twice()
ethClient.On("SequenceAt", mock.Anything, fromAddress, mock.Anything).Return(evmtypes.Nonce(0), nil).Once()
ethClient.On("SequenceAt", mock.Anything, fromAddress, mock.Anything).Return(evmtypes.Nonce(1), nil).Once()
ethClient.On("NonceAt", mock.Anything, fromAddress, mock.Anything).Return(uint64(0), nil).Once()
ethClient.On("NonceAt", mock.Anything, fromAddress, mock.Anything).Return(uint64(1), nil).Once()

mustInsertInProgressEthTxWithAttempt(t, txStore, evmtypes.Nonce(localNonce), fromAddress)
nonceTracker := txmgr.NewNonceTracker(lggr, txStore, txmgr.NewEvmTxmClient(ethClient, nil))
Expand All @@ -1946,7 +1946,7 @@ func TestEthBroadcaster_HederaBroadcastValidation(t *testing.T) {
ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool {
return tx.Nonce() == localNonce
}), fromAddress).Return(commonclient.Successful, nil).Times(4)
ethClient.On("SequenceAt", mock.Anything, fromAddress, mock.Anything).Return(evmtypes.Nonce(0), nil).Times(4)
ethClient.On("NonceAt", mock.Anything, fromAddress, mock.Anything).Return(uint64(0), nil).Times(4)

etx := mustInsertInProgressEthTxWithAttempt(t, txStore, evmtypes.Nonce(localNonce), fromAddress)
nonceTracker := txmgr.NewNonceTracker(lggr, txStore, txmgr.NewEvmTxmClient(ethClient, nil))
Expand Down
7 changes: 6 additions & 1 deletion core/chains/evm/txmgr/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ func (c *evmTxmClient) PendingNonceAt(ctx context.Context, fromAddress common.Ad
}

func (c *evmTxmClient) SequenceAt(ctx context.Context, addr common.Address, blockNum *big.Int) (evmtypes.Nonce, error) {
return c.client.SequenceAt(ctx, addr, blockNum)
nonce, err := c.client.NonceAt(ctx, addr, blockNum)
if nonce > math.MaxInt64 {
return 0, fmt.Errorf("overflow for nonce: %d", nonce)
}
//nolint:gosec // disable G115
return evmtypes.Nonce(nonce), err
}

func (c *evmTxmClient) BatchGetReceipts(ctx context.Context, attempts []TxAttempt) (txReceipt []*evmtypes.Receipt, txErr []error, funcErr error) {
Expand Down
Loading

0 comments on commit 7cd384b

Please sign in to comment.