Skip to content

Commit

Permalink
refactors after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Farber98 committed Nov 26, 2024
1 parent 9e606bc commit 19336a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions pkg/solana/txm/pendingtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,9 @@ func (c *pendingTxContext) OnFinalized(sig solana.Signature, retentionTimeout ti
return id, nil
}
finalizedTx := finishedTx{
state: Finalized,
retentionTs: time.Now().Add(retentionTimeout),
state: Finalized,
retentionTs: time.Now().Add(retentionTimeout),
rebroadcastCount: tx.rebroadcastCount,
}
// move transaction from confirmed to finalized map
c.finalizedErroredTxs[id] = finalizedTx
Expand Down Expand Up @@ -434,7 +435,8 @@ func (c *pendingTxContext) OnPrebroadcastError(id string, retentionTimeout time.

// upgrade to write lock if id does not exist in other maps and is not in expected state already
_, err = c.withWriteLock(func() (string, error) {
if tx, exists := c.finalizedErroredTxs[id]; exists && tx.state == txState {
tx, exists := c.finalizedErroredTxs[id]
if exists && tx.state == txState {
return "", ErrAlreadyInExpectedState
}
_, broadcastedExists := c.broadcastedTxs[id]
Expand All @@ -443,8 +445,9 @@ func (c *pendingTxContext) OnPrebroadcastError(id string, retentionTimeout time.
return "", ErrIDAlreadyExists
}
erroredTx := finishedTx{
state: txState,
retentionTs: time.Now().Add(retentionTimeout),
state: txState,
retentionTs: time.Now().Add(retentionTimeout),
rebroadcastCount: tx.rebroadcastCount,
}
// add transaction to error map
c.finalizedErroredTxs[id] = erroredTx
Expand Down Expand Up @@ -509,8 +512,9 @@ func (c *pendingTxContext) OnError(sig solana.Signature, retentionTimeout time.D
return id, nil
}
erroredTx := finishedTx{
state: txState,
retentionTs: time.Now().Add(retentionTimeout),
state: txState,
retentionTs: time.Now().Add(retentionTimeout),
rebroadcastCount: tx.rebroadcastCount,
}
// move transaction from broadcasted to error map
c.finalizedErroredTxs[id] = erroredTx
Expand Down
2 changes: 1 addition & 1 deletion pkg/solana/txm/txm_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ func TestTxm_disabled_confirm_timeout_with_retention(t *testing.T) {
LastValidBlockHeight: 100,
Blockhash: solana.Hash{},
},
}, nil).Once()
}, nil)

t.Run("happyPath", func(t *testing.T) {
// Test tx is not discarded due to confirm timeout and tracked to finalization
Expand Down

0 comments on commit 19336a5

Please sign in to comment.