diff --git a/pkg/solana/txm/pendingtx.go b/pkg/solana/txm/pendingtx.go index 9230b99db..13547416d 100644 --- a/pkg/solana/txm/pendingtx.go +++ b/pkg/solana/txm/pendingtx.go @@ -28,9 +28,9 @@ type PendingTxContext interface { Remove(id string) (string, error) // ListAllSigs returns all of the signatures being tracked for all transactions not yet finalized or errored ListAllSigs() []solana.Signature - // ListAllExpiredBroadcastedTxs returns all the txes that are in broadcasted state and have expired for given block height compared against their lastValidBlockHeight. - // Passing maxUint64 as currHeight will return all broadcasted txes. - ListAllExpiredBroadcastedTxs(currBlockHeight uint64) []pendingTx + // ListAllExpiredBroadcastedTxs returns all the txes that are in broadcasted state and have expired for given block number compared against lastValidBlockHeight (last valid block number) + // Passing maxUint64 as currBlockNumber will return all broadcasted txes. + ListAllExpiredBroadcastedTxs(currBlockNumber uint64) []pendingTx // Expired returns whether or not confirmation timeout amount of time has passed since creation Expired(sig solana.Signature, confirmationTimeout time.Duration) bool // OnProcessed marks transactions as Processed @@ -57,7 +57,7 @@ type pendingTx struct { id string createTs time.Time state TxState - lastValidBlockHeight uint64 // to track expiration + lastValidBlockHeight uint64 // to track expiration, equivalent to last valid block number. } // finishedTx is used to store minimal info specifically for finalized or errored transactions for external status checks @@ -212,18 +212,18 @@ func (c *pendingTxContext) ListAllSigs() []solana.Signature { return maps.Keys(c.sigToID) } -// ListAllExpiredBroadcastedTxs returns all the txes that are in broadcasted state and have expired for given block height compared against their lastValidBlockHeight. -// Passing maxUint64 as currHeight will return all broadcasted txes. -func (c *pendingTxContext) ListAllExpiredBroadcastedTxs(currBlockHeight uint64) []pendingTx { +// ListAllExpiredBroadcastedTxs returns all the txes that are in broadcasted state and have expired for given block number compared against lastValidBlockHeight (last valid block number) +// Passing maxUint64 as currBlockNumber will return all broadcasted txes. +func (c *pendingTxContext) ListAllExpiredBroadcastedTxs(currBlockNumber uint64) []pendingTx { c.lock.RLock() defer c.lock.RUnlock() - broadcastedTxes := make([]pendingTx, 0, len(c.broadcastedProcessedTxs)) // worst case, all of them + expiredBroadcastedTxs := make([]pendingTx, 0, len(c.broadcastedProcessedTxs)) // worst case, all of them for _, tx := range c.broadcastedProcessedTxs { - if tx.state == Broadcasted && tx.lastValidBlockHeight < currBlockHeight { - broadcastedTxes = append(broadcastedTxes, tx) + if tx.state == Broadcasted && tx.lastValidBlockHeight < currBlockNumber { + expiredBroadcastedTxs = append(expiredBroadcastedTxs, tx) } } - return broadcastedTxes + return expiredBroadcastedTxs } // Expired returns if the timeout for trying to confirm a signature has been reached @@ -614,8 +614,8 @@ func (c *pendingTxContextWithProm) ListAllSigs() []solana.Signature { return sigs } -func (c *pendingTxContextWithProm) ListAllExpiredBroadcastedTxs(currBlockHeight uint64) []pendingTx { - return c.pendingTx.ListAllExpiredBroadcastedTxs(currBlockHeight) +func (c *pendingTxContextWithProm) ListAllExpiredBroadcastedTxs(currBlockNumber uint64) []pendingTx { + return c.pendingTx.ListAllExpiredBroadcastedTxs(currBlockNumber) } func (c *pendingTxContextWithProm) Expired(sig solana.Signature, lifespan time.Duration) bool { diff --git a/pkg/solana/txm/txm.go b/pkg/solana/txm/txm.go index ac2bed40f..8605b1811 100644 --- a/pkg/solana/txm/txm.go +++ b/pkg/solana/txm/txm.go @@ -183,7 +183,7 @@ func (txm *Txm) run() { // It builds, signs and sends the initial tx with a new valid blockhash, and starts a retry routine with fee bumping if needed. // The function returns the signed transaction, its ID, and the initial signature for use in simulation. func (txm *Txm) sendWithRetry(ctx context.Context, msg pendingTx) (solanaGo.Transaction, string, solanaGo.Signature, error) { - // Assign new blockhash and lastValidBlockHeight to the transaction + // Assign new blockhash and lastValidBlockHeight (last valid block number) to the transaction // This is essential for tracking transaction rebroadcast // Only the initial transaction should be sent with the updated blockhash client, err := txm.client.Get() @@ -567,7 +567,7 @@ func (txm *Txm) handleFinalizedSignatureStatus(sig solanaGo.Signature) { } // rebroadcastExpiredTxs attempts to rebroadcast all transactions that are in broadcasted state and have expired. -// An expired tx is one where it's blockhash lastValidBlockHeight is smaller than the current slot height. +// An expired tx is one where it's blockhash lastValidBlockHeight (last valid block number) is smaller than the current block height (block number). // If any error occurs during rebroadcast attempt, they are discarded, and the function continues with the next transaction. func (txm *Txm) rebroadcastExpiredTxs(ctx context.Context, client client.ReaderWriter) { currBlock, err := client.GetLatestBlock(ctx) @@ -575,7 +575,7 @@ func (txm *Txm) rebroadcastExpiredTxs(ctx context.Context, client client.ReaderW txm.lggr.Errorw("failed to get current block height", "error", err) return } - // Rebroadcast all expired txes + // Rebroadcast all expired txes using currBlockHeight (current block number) for _, tx := range txm.txs.ListAllExpiredBroadcastedTxs(*currBlock.BlockHeight) { txm.lggr.Debugw("transaction expired, rebroadcasting", "id", tx.id, "signature", tx.signatures, "lastValidBlockHeight", tx.lastValidBlockHeight, "currentBlockHeight", *currBlock.BlockHeight) // Removes all signatures associated to tx and cancels context.