From a6ce47b714c71b4f5ef28dcaf78753e1b64a1a4a Mon Sep 17 00:00:00 2001 From: Farber98 Date: Sat, 30 Nov 2024 13:54:25 -0300 Subject: [PATCH] remove redundant sig update --- pkg/solana/txm/pendingtx.go | 40 +------------------------------------ pkg/solana/txm/txm.go | 13 +++++------- 2 files changed, 6 insertions(+), 47 deletions(-) diff --git a/pkg/solana/txm/pendingtx.go b/pkg/solana/txm/pendingtx.go index 7c950e9c6..cba91c52f 100644 --- a/pkg/solana/txm/pendingtx.go +++ b/pkg/solana/txm/pendingtx.go @@ -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) } @@ -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 { @@ -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) } diff --git a/pkg/solana/txm/txm.go b/pkg/solana/txm/txm.go index 66bb3ddf6..0da1576c9 100644 --- a/pkg/solana/txm/txm.go +++ b/pkg/solana/txm/txm.go @@ -544,13 +544,6 @@ 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 { @@ -558,7 +551,11 @@ func (txm *Txm) handleReorg(ctx context.Context, sig solanaGo.Signature, status 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