Skip to content

Commit

Permalink
replace all context.TODO()s (#11313)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 authored Nov 16, 2023
1 parent 01fbf8e commit 101d5de
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 21 deletions.
8 changes: 4 additions & 4 deletions common/txmgr/confirmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) mar
// This operates completely orthogonal to the normal Confirmer and can result in untracked attempts!
// Only for emergency usage.
// This is in case of some unforeseen scenario where the node is refusing to release the lock. KISS.
func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) ForceRebroadcast(seqs []SEQ, fee FEE, address ADDR, overrideGasLimit uint32) error {
func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) ForceRebroadcast(ctx context.Context, seqs []SEQ, fee FEE, address ADDR, overrideGasLimit uint32) error {
if len(seqs) == 0 {
ec.lggr.Infof("ForceRebroadcast: No sequences provided. Skipping")
return nil
Expand All @@ -1034,13 +1034,13 @@ func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) For

for _, seq := range seqs {

etx, err := ec.txStore.FindTxWithSequence(context.TODO(), address, seq)
etx, err := ec.txStore.FindTxWithSequence(ctx, address, seq)
if err != nil {
return errors.Wrap(err, "ForceRebroadcast failed")
}
if etx == nil {
ec.lggr.Debugf("ForceRebroadcast: no tx found with sequence %s, will rebroadcast empty transaction", seq)
hashStr, err := ec.sendEmptyTransaction(context.TODO(), address, seq, overrideGasLimit, fee)
hashStr, err := ec.sendEmptyTransaction(ctx, address, seq, overrideGasLimit, fee)
if err != nil {
ec.lggr.Errorw("ForceRebroadcast: failed to send empty transaction", "sequence", seq, "err", err)
continue
Expand All @@ -1058,7 +1058,7 @@ func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) For
}
attempt.Tx = *etx // for logging
ec.lggr.Debugw("Sending transaction", "txAttemptID", attempt.ID, "txHash", attempt.Hash, "err", err, "meta", etx.Meta, "feeLimit", etx.FeeLimit, "attempt", attempt)
if errCode, err := ec.client.SendTransactionReturnCode(context.TODO(), *etx, attempt, ec.lggr); errCode != client.Successful && err != nil {
if errCode, err := ec.client.SendTransactionReturnCode(ctx, *etx, attempt, ec.lggr); errCode != client.Successful && err != nil {
ec.lggr.Errorw(fmt.Sprintf("ForceRebroadcast: failed to rebroadcast tx %v with sequence %v and gas limit %v: %s", etx.ID, *etx.Sequence, etx.FeeLimit, err.Error()), "err", err, "fee", attempt.TxFee)
continue
}
Expand Down
10 changes: 5 additions & 5 deletions core/chains/evm/txmgr/confirmer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2819,7 +2819,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) {
tx.To().String() == etx1.ToAddress.String()
}), mock.Anything).Return(commonclient.Successful, nil).Once()

require.NoError(t, ec.ForceRebroadcast([]evmtypes.Nonce{1}, gasPriceWei, fromAddress, overrideGasLimit))
require.NoError(t, ec.ForceRebroadcast(testutils.Context(t), []evmtypes.Nonce{1}, gasPriceWei, fromAddress, overrideGasLimit))
})

t.Run("uses default gas limit if overrideGasLimit is 0", func(t *testing.T) {
Expand All @@ -2834,7 +2834,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) {
tx.To().String() == etx1.ToAddress.String()
}), mock.Anything).Return(commonclient.Successful, nil).Once()

require.NoError(t, ec.ForceRebroadcast([]evmtypes.Nonce{(1)}, gasPriceWei, fromAddress, 0))
require.NoError(t, ec.ForceRebroadcast(testutils.Context(t), []evmtypes.Nonce{(1)}, gasPriceWei, fromAddress, 0))
})

t.Run("rebroadcasts several eth_txes in nonce range", func(t *testing.T) {
Expand All @@ -2848,7 +2848,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) {
return tx.Nonce() == uint64(*etx2.Sequence) && tx.GasPrice().Int64() == gasPriceWei.Legacy.Int64() && tx.Gas() == uint64(overrideGasLimit)
}), mock.Anything).Return(commonclient.Successful, nil).Once()

require.NoError(t, ec.ForceRebroadcast([]evmtypes.Nonce{(1), (2)}, gasPriceWei, fromAddress, overrideGasLimit))
require.NoError(t, ec.ForceRebroadcast(testutils.Context(t), []evmtypes.Nonce{(1), (2)}, gasPriceWei, fromAddress, overrideGasLimit))
})

t.Run("broadcasts zero transactions if eth_tx doesn't exist for that nonce", func(t *testing.T) {
Expand All @@ -2874,7 +2874,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) {
}
nonces := []evmtypes.Nonce{(1), (2), (3), (4), (5)}

require.NoError(t, ec.ForceRebroadcast(nonces, gasPriceWei, fromAddress, overrideGasLimit))
require.NoError(t, ec.ForceRebroadcast(testutils.Context(t), nonces, gasPriceWei, fromAddress, overrideGasLimit))
})

t.Run("zero transactions use default gas limit if override wasn't specified", func(t *testing.T) {
Expand All @@ -2885,7 +2885,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) {
return tx.Nonce() == uint64(0) && tx.GasPrice().Int64() == gasPriceWei.Legacy.Int64() && uint32(tx.Gas()) == config.EVM().GasEstimator().LimitDefault()
}), mock.Anything).Return(commonclient.Successful, nil).Once()

require.NoError(t, ec.ForceRebroadcast([]evmtypes.Nonce{(0)}, gasPriceWei, fromAddress, 0))
require.NoError(t, ec.ForceRebroadcast(testutils.Context(t), []evmtypes.Nonce{(0)}, gasPriceWei, fromAddress, 0))
})
}

Expand Down
7 changes: 4 additions & 3 deletions core/cmd/shell_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ func checkFilePermissions(lggr logger.Logger, rootDir string) error {
// RebroadcastTransactions run locally to force manual rebroadcasting of
// transactions in a given nonce range.
func (s *Shell) RebroadcastTransactions(c *cli.Context) (err error) {
ctx := s.ctx()
beginningNonce := c.Int64("beginningNonce")
endingNonce := c.Int64("endingNonce")
gasPriceWei := c.Uint64("gasPriceWei")
Expand Down Expand Up @@ -587,7 +588,7 @@ func (s *Shell) RebroadcastTransactions(c *cli.Context) (err error) {
}
defer lggr.ErrorIfFn(db.Close, "Error closing db")

app, err := s.AppFactory.NewApplication(context.TODO(), s.Config, lggr, db)
app, err := s.AppFactory.NewApplication(ctx, s.Config, lggr, db)
if err != nil {
return s.errorOut(errors.Wrap(err, "fatal error instantiating application"))
}
Expand All @@ -603,7 +604,7 @@ func (s *Shell) RebroadcastTransactions(c *cli.Context) (err error) {

ethClient := chain.Client()

err = ethClient.Dial(context.TODO())
err = ethClient.Dial(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -642,7 +643,7 @@ func (s *Shell) RebroadcastTransactions(c *cli.Context) (err error) {
for i := int64(0); i < totalNonces; i++ {
nonces[i] = evmtypes.Nonce(beginningNonce + i)
}
err = ec.ForceRebroadcast(nonces, gas.EvmFee{Legacy: assets.NewWeiI(int64(gasPriceWei))}, address, uint32(overrideGasLimit))
err = ec.ForceRebroadcast(ctx, nonces, gas.EvmFee{Legacy: assets.NewWeiI(int64(gasPriceWei))}, address, uint32(overrideGasLimit))
return s.errorOut(err)
}

Expand Down
1 change: 1 addition & 0 deletions core/internal/cltest/cltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/urfave/cli"

"github.com/jmoiron/sqlx"

ocrtypes "github.com/smartcontractkit/libocr/offchainreporting/types"

"github.com/smartcontractkit/chainlink-relay/pkg/loop"
Expand Down
2 changes: 1 addition & 1 deletion core/services/chainlink/relayer_chain_interoperators.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func InitEVM(ctx context.Context, factory RelayerFactory, config EVMFactoryConfi
// InitCosmos is a option for instantiating Cosmos relayers
func InitCosmos(ctx context.Context, factory RelayerFactory, config CosmosFactoryConfig) CoreRelayerChainInitFunc {
return func(op *CoreRelayerChainInteroperators) (err error) {
adapters, err2 := factory.NewCosmos(ctx, config)
adapters, err2 := factory.NewCosmos(config)
if err2 != nil {
return fmt.Errorf("failed to setup Cosmos relayer: %w", err2)
}
Expand Down
2 changes: 1 addition & 1 deletion core/services/chainlink/relayer_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (c CosmosFactoryConfig) Validate() error {
return err
}

func (r *RelayerFactory) NewCosmos(ctx context.Context, config CosmosFactoryConfig) (map[relay.ID]CosmosLoopRelayerChainer, error) {
func (r *RelayerFactory) NewCosmos(config CosmosFactoryConfig) (map[relay.ID]CosmosLoopRelayerChainer, error) {
err := config.Validate()
if err != nil {
return nil, fmt.Errorf("cannot create Cosmos relayer: %w", err)
Expand Down
14 changes: 7 additions & 7 deletions core/services/ocr2/plugins/dkg/persistence/db_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package persistence

import (
"context"
"fmt"
"math/big"
"testing"

"github.com/ethereum/go-ethereum/crypto"
"github.com/jmoiron/sqlx"
ocr2vrftypes "github.com/smartcontractkit/ocr2vrf/types"
"github.com/smartcontractkit/ocr2vrf/types/hash"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

ocr2vrftypes "github.com/smartcontractkit/ocr2vrf/types"
"github.com/smartcontractkit/ocr2vrf/types/hash"

"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
"github.com/smartcontractkit/chainlink/v2/core/logger"
Expand Down Expand Up @@ -50,7 +50,7 @@ func TestShareDB_WriteShareRecords(t *testing.T) {
expectedRecords = append(expectedRecords, rec)
}

err := shareDB.WriteShareRecords(context.TODO(), configDigest, keyID, expectedRecords)
err := shareDB.WriteShareRecords(testutils.Context(t), configDigest, keyID, expectedRecords)
require.NoError(tt, err)

rows, err := db.Query(`SELECT COUNT(*) AS count FROM dkg_shares`)
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestShareDB_WriteShareRecords(t *testing.T) {
}

// no error, but there will be no rows inserted in the db
err = shareDB.WriteShareRecords(context.TODO(), configDigest, keyID, records)
err = shareDB.WriteShareRecords(testutils.Context(t), configDigest, keyID, records)
require.NoError(tt, err)

rows, err := db.Query(`SELECT COUNT(*) AS count FROM dkg_shares`)
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestShareDB_WriteShareRecords(t *testing.T) {
records = append(records, rec)
}

err := shareDB.WriteShareRecords(context.TODO(), configDigest, keyID, records)
err := shareDB.WriteShareRecords(testutils.Context(t), configDigest, keyID, records)
require.Error(tt, err)

// no rows should have been inserted
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestShareDBE2E(t *testing.T) {
expectedRecordsMap[*playerIdx] = rec
}

err := shareDB.WriteShareRecords(context.TODO(), configDigest, keyID, expectedRecords)
err := shareDB.WriteShareRecords(testutils.Context(t), configDigest, keyID, expectedRecords)
require.NoError(t, err)

actualRecords, err := shareDB.ReadShareRecords(configDigest, keyID)
Expand Down

0 comments on commit 101d5de

Please sign in to comment.