Skip to content

Commit

Permalink
address feedback + remove redundant impl
Browse files Browse the repository at this point in the history
  • Loading branch information
Farber98 committed Nov 22, 2024
1 parent 6e982c0 commit 477efc3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pkg/solana/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ func (c *chain) sendTx(ctx context.Context, from, to string, amount *big.Int, ba
toKey,
).Build(),
},
blockhash.Value.Blockhash, // Will be override if needed within sendWithRetry txm function.
blockhash.Value.Blockhash,
solanago.TransactionPayer(fromKey),
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/solana/transmitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (c *Transmitter) Transmit(
[]solana.Instruction{
solana.NewInstruction(c.programID, accounts, data.Bytes()),
},
blockhash.Value.Blockhash, // Will be override if needed within sendWithRetry txm function.
blockhash.Value.Blockhash,
solana.TransactionPayer(c.transmissionSigner),
)
if err != nil {
Expand Down
20 changes: 1 addition & 19 deletions pkg/solana/txm/pendingtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ type PendingTxContext interface {
ListAll() []solana.Signature
// ListAllExpiredBroadcastedTxs returns all the txes that are in broadcasted state and have expired for given slot height compared against their lastValidBlockHeight.
ListAllExpiredBroadcastedTxs(currHeight uint64) []pendingTx
// ListAllBroadcastedTxs returns all the txes that are in broadcasted state.
ListAllBroadcastedTxs() []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
Expand Down Expand Up @@ -218,6 +216,7 @@ func (c *pendingTxContext) ListAll() []solana.Signature {
}

// ListAllExpiredBroadcastedTxs returns all the txes that are in broadcasted state and have expired for given slot height compared against their lastValidBlockHeight.
// Passing maxUint64 as currHeight will return all broadcasted txes.
func (c *pendingTxContext) ListAllExpiredBroadcastedTxs(currHeight uint64) []pendingTx {
c.lock.RLock()
defer c.lock.RUnlock()
Expand All @@ -230,19 +229,6 @@ func (c *pendingTxContext) ListAllExpiredBroadcastedTxs(currHeight uint64) []pen
return broadcastedTxes
}

// ListAllBroadcastedTxs returns all the txes that are in broadcasted state.
func (c *pendingTxContext) ListAllBroadcastedTxs() []pendingTx {
c.lock.RLock()
defer c.lock.RUnlock()
broadcastedTxes := make([]pendingTx, 0, len(c.broadcastedProcessedTxs)) // worst case, all of them
for _, tx := range c.broadcastedProcessedTxs {
if tx.state == Broadcasted {
broadcastedTxes = append(broadcastedTxes, tx)
}
}
return broadcastedTxes
}

// Expired returns if the timeout for trying to confirm a signature has been reached
func (c *pendingTxContext) Expired(sig solana.Signature, confirmationTimeout time.Duration) bool {
c.lock.RLock()
Expand Down Expand Up @@ -653,7 +639,3 @@ func (c *pendingTxContextWithProm) TrimFinalizedErroredTxs() {
func (c *pendingTxContextWithProm) GetTxRebroadcastCount(id string) (int, error) {
return c.pendingTx.GetTxRebroadcastCount(id)
}

func (c *pendingTxContextWithProm) ListAllBroadcastedTxs() []pendingTx {
return c.pendingTx.ListAllBroadcastedTxs()
}
4 changes: 3 additions & 1 deletion pkg/solana/txm/txm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"math"
"math/big"
"strings"
"sync"
Expand Down Expand Up @@ -395,7 +396,8 @@ func (txm *Txm) confirm() {

// In case all txes where confirmed and there's nothing to rebroadcast.
// This check saves making 2 RPC calls (slot height + blockhash) when there's nothing to process.
if len(txm.txs.ListAllBroadcastedTxs()) == 0 {
// Passing MaxUint64 as currHeight to ListAllExpiredBroadcastedTxs will return all broadcasted txs.
if len(txm.txs.ListAllExpiredBroadcastedTxs(math.MaxUint64)) == 0 {
break
}
if txm.cfg.TxExpirationRebroadcast() {
Expand Down

0 comments on commit 477efc3

Please sign in to comment.