Skip to content

Commit

Permalink
handle unchecked errors (#10964)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 authored Oct 16, 2023
1 parent 96155bc commit a2c91ae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
29 changes: 16 additions & 13 deletions common/txmgr/txmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package txmgr
import (
"context"
"database/sql"
"errors"
"fmt"
"math/big"
"sync"
"time"

"github.com/google/uuid"
"github.com/pkg/errors"
pkgerrors "github.com/pkg/errors"

feetypes "github.com/smartcontractkit/chainlink/v2/common/fee/types"
txmgrtypes "github.com/smartcontractkit/chainlink/v2/common/txmgr/types"
Expand Down Expand Up @@ -164,14 +165,14 @@ func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) Start(ctx
return b.StartOnce("Txm", func() error {
var ms services.MultiStart
if err := ms.Start(ctx, b.broadcaster); err != nil {
return errors.Wrap(err, "Txm: Broadcaster failed to start")
return pkgerrors.Wrap(err, "Txm: Broadcaster failed to start")
}
if err := ms.Start(ctx, b.confirmer); err != nil {
return errors.Wrap(err, "Txm: Confirmer failed to start")
return pkgerrors.Wrap(err, "Txm: Confirmer failed to start")
}

if err := ms.Start(ctx, b.txAttemptBuilder); err != nil {
return errors.Wrap(err, "Txm: Estimator failed to start")
return pkgerrors.Wrap(err, "Txm: Estimator failed to start")
}

b.wg.Add(1)
Expand All @@ -188,7 +189,7 @@ func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) Start(ctx

if b.fwdMgr != nil {
if err := ms.Start(ctx, b.fwdMgr); err != nil {
return errors.Wrap(err, "Txm: ForwarderManager failed to start")
return pkgerrors.Wrap(err, "Txm: ForwarderManager failed to start")
}
}

Expand Down Expand Up @@ -222,7 +223,7 @@ func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) abandon(ad
ctx, cancel := utils.StopChan(b.chStop).NewCtx()
defer cancel()
err = b.txStore.Abandon(ctx, b.chainID, addr)
return errors.Wrapf(err, "abandon failed to update txes for key %s", addr.String())
return pkgerrors.Wrapf(err, "abandon failed to update txes for key %s", addr.String())
}

func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) Close() (merr error) {
Expand All @@ -239,13 +240,15 @@ func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) Close() (m
}
if b.fwdMgr != nil {
if err := b.fwdMgr.Close(); err != nil {
return errors.Wrap(err, "Txm: failed to stop ForwarderManager")
merr = errors.Join(merr, pkgerrors.Wrap(err, "Txm: failed to stop ForwarderManager"))
}
}

b.wg.Wait()

b.txAttemptBuilder.Close()
if err := b.txAttemptBuilder.Close(); err != nil {
merr = errors.Join(merr, pkgerrors.Wrap(err, "Txm: failed to close TxAttemptBuilder"))
}

return nil
})
Expand Down Expand Up @@ -440,7 +443,7 @@ func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) CreateTran
var existingTx *txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]
existingTx, err = b.txStore.FindTxWithIdempotencyKey(ctx, *txRequest.IdempotencyKey, b.chainID)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
return tx, errors.Wrap(err, "Failed to search for transaction with IdempotencyKey")
return tx, pkgerrors.Wrap(err, "Failed to search for transaction with IdempotencyKey")
}
if existingTx != nil {
b.logger.Infow("Found a Tx with IdempotencyKey. Returning existing Tx without creating a new one.", "IdempotencyKey", *txRequest.IdempotencyKey)
Expand Down Expand Up @@ -472,7 +475,7 @@ func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) CreateTran

err = b.txStore.CheckTxQueueCapacity(ctx, txRequest.FromAddress, b.txConfig.MaxQueued(), b.chainID)
if err != nil {
return tx, errors.Wrap(err, "Txm#CreateTransaction")
return tx, pkgerrors.Wrap(err, "Txm#CreateTransaction")
}

tx, err = b.txStore.CreateTransaction(ctx, txRequest, b.chainID)
Expand All @@ -482,15 +485,15 @@ func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) CreateTran
// Calls forwarderMgr to get a proper forwarder for a given EOA.
func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) GetForwarderForEOA(eoa ADDR) (forwarder ADDR, err error) {
if !b.txConfig.ForwardersEnabled() {
return forwarder, errors.Errorf("Forwarding is not enabled, to enable set Transactions.ForwardersEnabled =true")
return forwarder, pkgerrors.Errorf("Forwarding is not enabled, to enable set Transactions.ForwardersEnabled =true")
}
forwarder, err = b.fwdMgr.ForwarderFor(eoa)
return
}

func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) checkEnabled(addr ADDR) error {
err := b.keyStore.CheckEnabled(addr, b.chainID)
return errors.Wrapf(err, "cannot send transaction from %s on chain ID %s", addr, b.chainID.String())
return pkgerrors.Wrapf(err, "cannot send transaction from %s on chain ID %s", addr, b.chainID.String())
}

// SendNativeToken creates a transaction that transfers the given value of native tokens
Expand All @@ -507,7 +510,7 @@ func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) SendNative
Strategy: NewSendEveryStrategy(),
}
etx, err = b.txStore.CreateTransaction(ctx, txRequest, chainID)
return etx, errors.Wrap(err, "SendNativeToken failed to insert tx")
return etx, pkgerrors.Wrap(err, "SendNativeToken failed to insert tx")
}

type NullTxManager[
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/testsetups/ocr.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/rs/zerolog"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/libocr/gethwrappers/offchainaggregator"

"github.com/smartcontractkit/chainlink-env/environment"
"github.com/smartcontractkit/chainlink-env/pkg/helm/chainlink"
"github.com/smartcontractkit/chainlink-env/pkg/helm/ethereum"
Expand All @@ -34,7 +36,6 @@ import (
"github.com/smartcontractkit/chainlink-testing-framework/logging"
"github.com/smartcontractkit/chainlink-testing-framework/networks"
reportModel "github.com/smartcontractkit/chainlink-testing-framework/testreporters"
"github.com/smartcontractkit/libocr/gethwrappers/offchainaggregator"

"github.com/smartcontractkit/chainlink/integration-tests/actions"
"github.com/smartcontractkit/chainlink/integration-tests/client"
Expand Down Expand Up @@ -120,8 +121,7 @@ func NewOCRSoakTest(t *testing.T, forwarderFlow bool) (*OCRSoakTest, error) {
ocrRoundStates: make([]*testreporters.OCRRoundState, 0),
ocrInstanceMap: make(map[string]contracts.OffchainAggregator),
}
test.ensureInputValues()
return test, nil
return test, test.ensureInputValues()
}

// DeployEnvironment deploys the test environment, starting all Chainlink nodes and other components for the test
Expand Down

0 comments on commit a2c91ae

Please sign in to comment.