Skip to content

Commit

Permalink
remove redundant sig update
Browse files Browse the repository at this point in the history
  • Loading branch information
Farber98 committed Nov 30, 2024
1 parent 2b29c33 commit a6ce47b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 47 deletions.
40 changes: 1 addition & 39 deletions pkg/solana/txm/pendingtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ type PendingTxContext interface {
TrimFinalizedErroredTxs() int
// GetSignatureInfo returns the transaction ID and TxState for the provided signature
GetSignatureInfo(sig solana.Signature) (txInfo, error)
// UpdateSignatureStatus updates the status of the provided signature within sigToTxInfo map
UpdateSignatureStatus(sig solana.Signature, newStatus TxState) (string, error)
// OnReorg resets the transaction state to Broadcasted for the given signature and returns the pendingTx.
// OnReorg resets the transaction state to Broadcasted for the given signature and returns the pendingTx for retrying.
OnReorg(sig solana.Signature) (pendingTx, error)
}

Expand Down Expand Up @@ -580,38 +578,6 @@ func (c *pendingTxContext) GetSignatureInfo(sig solana.Signature) (txInfo, error
return info, nil
}

func (c *pendingTxContext) UpdateSignatureStatus(sig solana.Signature, newStatus TxState) (string, error) {
// First, acquire a read lock to check if the signature exists and needs to be updated
err := c.withReadLock(func() error {
info, exists := c.sigToTxInfo[sig]
if !exists {
return ErrSigDoesNotExist
}
if info.state == newStatus {
return ErrAlreadyInExpectedState
}
return nil
})
if err != nil {
return "", err
}

// Upgrade to a write lock to perform the update
return c.withWriteLock(func() (string, error) {
info, exists := c.sigToTxInfo[sig]
if !exists {
return "", ErrSigDoesNotExist
}
if info.state == newStatus {
// no action needed
return "", ErrAlreadyInExpectedState
}
info.state = newStatus
c.sigToTxInfo[sig] = info
return "", nil
})
}

func (c *pendingTxContext) OnReorg(sig solana.Signature) (pendingTx, error) {
// Acquire a read lock to check if the signature exists and needs to be reset
err := c.withReadLock(func() error {
Expand Down Expand Up @@ -801,10 +767,6 @@ func (c *pendingTxContextWithProm) GetSignatureInfo(sig solana.Signature) (txInf
return c.pendingTx.GetSignatureInfo(sig)
}

func (c *pendingTxContextWithProm) UpdateSignatureStatus(sig solana.Signature, newStatus TxState) (string, error) {
return c.pendingTx.UpdateSignatureStatus(sig, newStatus)
}

func (c *pendingTxContextWithProm) OnReorg(sig solana.Signature) (pendingTx, error) {
return c.pendingTx.OnReorg(sig)
}
13 changes: 5 additions & 8 deletions pkg/solana/txm/txm.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,21 +544,18 @@ func (txm *Txm) handleReorg(ctx context.Context, sig solanaGo.Signature, status
currentTxState := convertStatus(status)
if isStatusRegression(txInfo.state, currentTxState) {
txm.lggr.Warnw("potential re-org detected for transaction", "txID", txInfo.id, "signature", sig, "previousStatus", txInfo.state, "currentStatus", currentTxState)
// Update status for the tx associated to this sig in our in-memory layer with last seen on-chain status.
_, err = txm.txs.UpdateSignatureStatus(sig, currentTxState)
if err != nil {
txm.lggr.Errorw("failed to update signature status", "signature", sig, "error", err)
return err
}

// Handle reorg in our in memory layer and retry transaction
pTx, err := txm.txs.OnReorg(sig)
if err != nil {
txm.lggr.Errorw("failed to handle potential re-org", "signature", sig, "id", pTx.id, "error", err)
return err
}
retryCtx, _ := context.WithTimeout(ctx, pTx.cfg.Timeout) // TODO: Ask here. How should we handle the ctx?
txm.retryTx(retryCtx, pTx, pTx.tx, sig)
txm.done.Add(1)
go func() {
defer txm.done.Done()
txm.retryTx(retryCtx, pTx, pTx.tx, sig)
}()
}

return nil
Expand Down

0 comments on commit a6ce47b

Please sign in to comment.