Skip to content

Commit fd840c3

Browse files
committed
fix(bridge): filter to outgoing-only txs in crash recovery Horizon lookup
FindPaymentByMemo and FindRefundByReturnHash previously scanned the 200 most recent transactions on the bridge account (incoming + outgoing mixed). In a busy bridge, deposits dominate, leaving few slots for withdrawals. Filter to outgoing only (tx.Account == bridgeAccount) client-side after fetching. This means the 200 limit now covers 200 actual withdrawals/refunds rather than 200 mixed-direction transactions.
1 parent dad601d commit fd840c3

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

bridge/tfchain_bridge/pkg/stellar/stellar.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,11 @@ func (w *StellarWallet) CreateRefundAndReturnSignature(ctx context.Context, targ
199199
return base64.StdEncoding.EncodeToString(signatures[0].Signature), uint64(txn.SequenceNumber()), nil
200200
}
201201

202-
// FindPaymentByMemo searches recent transactions on the bridge account for a
203-
// payment with a matching text memo. This is used during crash recovery to
204-
// determine if a Stellar transaction was already submitted for a given withdraw ID.
202+
// FindPaymentByMemo searches the 200 most recent outgoing transactions from the
203+
// bridge account for one with a matching text memo. Outgoing means the bridge
204+
// account is the source of the transaction; this filters out deposits (incoming
205+
// from users) so the limit covers 200 actual withdrawals rather than mixed traffic.
206+
// Used during crash recovery to detect if a Stellar withdraw was already submitted.
205207
// Returns nil, nil if no matching transaction is found.
206208
func (w *StellarWallet) FindPaymentByMemo(ctx context.Context, memo string) (*hProtocol.Transaction, error) {
207209
client, err := w.getHorizonClient()
@@ -221,6 +223,10 @@ func (w *StellarWallet) FindPaymentByMemo(ctx context.Context, memo string) (*hP
221223
}
222224

223225
for _, tx := range resp.Embedded.Records {
226+
// Only consider outgoing transactions (bridge is the source)
227+
if tx.Account != w.config.StellarBridgeAccount {
228+
continue
229+
}
224230
if tx.MemoType == "text" && tx.Memo == memo {
225231
txCopy := tx
226232
return &txCopy, nil
@@ -251,8 +257,12 @@ func (w *StellarWallet) FindRefundByReturnHash(ctx context.Context, txHash strin
251257
return nil, errors.Wrap(err, "failed to query horizon for refund memo lookup")
252258
}
253259

254-
// MemoReturn stores the hash as hex-encoded in the Horizon API response
260+
// Only consider outgoing transactions (bridge is the source).
261+
// MemoReturn stores the hash as hex-encoded in the Horizon API response.
255262
for _, tx := range resp.Embedded.Records {
263+
if tx.Account != w.config.StellarBridgeAccount {
264+
continue
265+
}
256266
if tx.MemoType == "return" && tx.Memo == txHash {
257267
txCopy := tx
258268
return &txCopy, nil

0 commit comments

Comments
 (0)