Skip to content

Commit

Permalink
Fixed linting
Browse files Browse the repository at this point in the history
  • Loading branch information
amit-momin committed Sep 12, 2024
1 parent 39616c3 commit 914876f
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 88 deletions.
6 changes: 1 addition & 5 deletions common/txmgr/confirmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,7 @@ func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) Pro

// Mark transactions as unconfirmed, mark attempts as in-progress, and delete receipts since they do not apply to the new chain
// This may revert some fatal error transactions to unconfirmed if terminally stuck transactions purge attempts get re-org'd
if err := ec.txStore.UpdateTxForRebroadcast(ctx, etxIDs, attemptIDs); err != nil {
return err
}

return nil
return ec.txStore.UpdateTxForRebroadcast(ctx, etxIDs, attemptIDs)
}

func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) ProcessIncludedTxs(ctx context.Context, includedTxs []*txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], head types.Head[BLOCK_HASH]) error {
Expand Down
16 changes: 8 additions & 8 deletions common/txmgr/types/mocks/tx_store.go

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

2 changes: 1 addition & 1 deletion common/txmgr/types/tx_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type TransactionStore[
UpdateBroadcastAts(ctx context.Context, now time.Time, etxIDs []int64) error
UpdateTxAttemptInProgressToBroadcast(ctx context.Context, etx *Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], attempt TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], NewAttemptState TxAttemptState) error
// UpdateTxCallbackCompleted updates tx to mark that its callback has been signaled
UpdateTxCallbackCompleted(ctx context.Context, pipelineTaskRunRid uuid.UUID, chainId CHAIN_ID) error
UpdateTxCallbackCompleted(ctx context.Context, pipelineTaskRunRid uuid.UUID, chainID CHAIN_ID) error
// UpdateTxConfirmed updates transaction states to confirmed
UpdateTxConfirmed(ctx context.Context, etxIDs []int64) error
// UpdateTxFatalErrorAndDeleteAttempts updates transaction states to fatal error, deletes attempts, and clears broadcast info and sequence
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/txmgr/confirmer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,8 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) {
ethKeyStore := cltest.NewKeyStore(t, db).Eth()
_, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore)
etx := mustInsertUnconfirmedEthTxWithBroadcastDynamicFeeAttempt(t, txStore, 0, fromAddress)
txStore.UpdateTxAttemptBroadcastBeforeBlockNum(ctx, etx.ID, uint(25))
err := txStore.UpdateTxAttemptBroadcastBeforeBlockNum(ctx, etx.ID, uint(25))
require.NoError(t, err)
ec := newEthConfirmer(t, txStore, ethClient, cfg, newCfg, ethKeyStore, nil)

ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool {
Expand All @@ -1277,7 +1278,6 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) {

// Do it
require.NoError(t, ec.RebroadcastWhereNecessary(ctx, currentHead))
var err error
etx, err = txStore.FindTxWithAttempts(ctx, etx.ID)
require.NoError(t, err)
assert.Equal(t, txmgrcommon.TxUnconfirmed, etx.State)
Expand Down
20 changes: 10 additions & 10 deletions core/chains/evm/txmgr/evm_tx_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type EvmTxStore interface {
FindTxesPendingCallback(ctx context.Context, blockNum int64, chainID *big.Int) (receiptsPlus []ReceiptPlus, err error)
FindTxesByIDs(ctx context.Context, etxIDs []int64, chainID *big.Int) (etxs []*Tx, err error)
SaveFetchedReceipts(ctx context.Context, r []*evmtypes.Receipt, chainID *big.Int) (err error)
UpdateTxStatesToFinalizedUsingTxHashes(ctx context.Context, txHashes []common.Hash, chainId *big.Int) error
UpdateTxStatesToFinalizedUsingTxHashes(ctx context.Context, txHashes []common.Hash, chainID *big.Int) error
}

// TxStoreWebApi encapsulates the methods that are not used by the txmgr and only used by the various web controllers, readers, or evm specific components
Expand Down Expand Up @@ -996,23 +996,23 @@ func (o *evmTxStore) FindTxesPendingCallback(ctx context.Context, blockNum int64
}

// Update tx to mark that its callback has been signaled
func (o *evmTxStore) UpdateTxCallbackCompleted(ctx context.Context, pipelineTaskRunId uuid.UUID, chainId *big.Int) error {
func (o *evmTxStore) UpdateTxCallbackCompleted(ctx context.Context, pipelineTaskRunId uuid.UUID, chainID *big.Int) error {

Check failure on line 999 in core/chains/evm/txmgr/evm_tx_store.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: method parameter pipelineTaskRunId should be pipelineTaskRunID (revive)
var cancel context.CancelFunc
ctx, cancel = o.stopCh.Ctx(ctx)
defer cancel()
_, err := o.q.ExecContext(ctx, `UPDATE evm.txes SET callback_completed = TRUE WHERE pipeline_task_run_id = $1 AND evm_chain_id = $2`, pipelineTaskRunId, chainId.String())
_, err := o.q.ExecContext(ctx, `UPDATE evm.txes SET callback_completed = TRUE WHERE pipeline_task_run_id = $1 AND evm_chain_id = $2`, pipelineTaskRunId, chainID.String())
if err != nil {
return fmt.Errorf("failed to mark callback completed for transaction: %w", err)
}
return nil
}

func (o *evmTxStore) FindLatestSequence(ctx context.Context, fromAddress common.Address, chainId *big.Int) (nonce evmtypes.Nonce, err error) {
func (o *evmTxStore) FindLatestSequence(ctx context.Context, fromAddress common.Address, chainID *big.Int) (nonce evmtypes.Nonce, err error) {
var cancel context.CancelFunc
ctx, cancel = o.stopCh.Ctx(ctx)
defer cancel()
sql := `SELECT nonce FROM evm.txes WHERE from_address = $1 AND evm_chain_id = $2 AND nonce IS NOT NULL ORDER BY nonce DESC LIMIT 1`
err = o.q.GetContext(ctx, &nonce, sql, fromAddress, chainId.String())
err = o.q.GetContext(ctx, &nonce, sql, fromAddress, chainID.String())
return
}

Expand Down Expand Up @@ -1944,7 +1944,7 @@ func (o *evmTxStore) FindConfirmedTxesReceipts(ctx context.Context, finalizedBlo
}

// Mark transactions corresponding to attempt hashes as finalized
func (o *evmTxStore) UpdateTxStatesToFinalizedUsingTxHashes(ctx context.Context, txHashes []common.Hash, chainId *big.Int) error {
func (o *evmTxStore) UpdateTxStatesToFinalizedUsingTxHashes(ctx context.Context, txHashes []common.Hash, chainID *big.Int) error {
if len(txHashes) == 0 {
return nil
}
Expand All @@ -1960,21 +1960,21 @@ UPDATE evm.txes SET state = 'finalized' WHERE evm.txes.evm_chain_id = $1 AND evm
INNER JOIN evm.tx_attempts ON evm.tx_attempts.eth_tx_id = evm.txes.id
WHERE evm.tx_attempts.hash = ANY($2))
`
_, err := o.q.ExecContext(ctx, sql, chainId.String(), txHashBytea)
_, err := o.q.ExecContext(ctx, sql, chainID.String(), txHashBytea)
return err
}

// FindReorgOrIncludedTxs finds transactions that have either been re-org'd or included on-chain based on the mined transaction count
// If the mined transaction count receeds, transactions could have beeen re-org'd
// If it proceeds, transactions could have been included
func (o *evmTxStore) FindReorgOrIncludedTxs(ctx context.Context, fromAddress common.Address, minedTxCount evmtypes.Nonce, chainId *big.Int) (reorgTxs []*Tx, includedTxs []*Tx, err error) {
func (o *evmTxStore) FindReorgOrIncludedTxs(ctx context.Context, fromAddress common.Address, minedTxCount evmtypes.Nonce, chainID *big.Int) (reorgTxs []*Tx, includedTxs []*Tx, err error) {
var cancel context.CancelFunc
ctx, cancel = o.stopCh.Ctx(ctx)
defer cancel()
err = o.Transact(ctx, true, func(orm *evmTxStore) error {
var dbReOrgEtxs []DbEthTx
query := `SELECT * FROM evm.txes WHERE from_address = $1 AND state IN ('confirmed', 'confirmed_missing_receipt', 'fatal_error', 'finalized') AND nonce >= $2 AND evm_chain_id = $3`
err = o.q.SelectContext(ctx, &dbReOrgEtxs, query, fromAddress, minedTxCount.Int64(), chainId.String())
err = o.q.SelectContext(ctx, &dbReOrgEtxs, query, fromAddress, minedTxCount.Int64(), chainID.String())
// If re-org'd transactions found, populate them with attempts and partial receipts, then return since new transactions could not have been included
if len(dbReOrgEtxs) > 0 {
reorgTxs = make([]*Tx, len(dbReOrgEtxs))
Expand All @@ -1991,7 +1991,7 @@ func (o *evmTxStore) FindReorgOrIncludedTxs(ctx context.Context, fromAddress com
// If re-org'd transactions not found, find unconfirmed transactions could have been included and populate with attempts
var dbIncludedEtxs []DbEthTx
query = `SELECT * FROM evm.txes WHERE state = 'unconfirmed' AND from_address = $1 AND nonce < $2 AND evm_chain_id = $3`
err = o.q.SelectContext(ctx, &dbIncludedEtxs, query, fromAddress, minedTxCount.Int64(), chainId.String())
err = o.q.SelectContext(ctx, &dbIncludedEtxs, query, fromAddress, minedTxCount.Int64(), chainID.String())
includedTxs = make([]*Tx, len(dbIncludedEtxs))
dbEthTxsToEvmEthTxPtrs(dbIncludedEtxs, includedTxs)
if err = orm.LoadTxesAttempts(ctx, includedTxs); err != nil {
Expand Down
Loading

0 comments on commit 914876f

Please sign in to comment.