Skip to content

Commit dc8263b

Browse files
sameh-faroukclaude
andauthored
perf(bridge): fetch transaction operations once in processTransaction (#1098)
When a Stellar transaction credited the bridge account more than once, processTransaction called getOperationEffect(tx.Hash) once per matching account_credited effect, refetching identical operation data from Horizon each time and slowing down processing. Fetch the operations lazily at most once per transaction and reuse the result across all matching effects. The fetch still happens only when a matching TFT credit is present (no extra call for unrelated transactions), and per-effect MintEvent emission is unchanged, so behaviour is preserved. Closes #1051 Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 9dac2ed commit dc8263b

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

bridge/tfchain_bridge/pkg/stellar/stellar.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,13 @@ func (w *StellarWallet) processTransaction(tx hProtocol.Transaction) ([]MintEven
502502
asset := w.getAssetCodeAndIssuer()
503503

504504
var mintEvents []MintEvent
505+
// A transaction's operations are identical no matter how many times the bridge
506+
// account is credited within it, so fetch them at most once and reuse the result
507+
// across all matching account_credited effects. Previously this Horizon call was
508+
// made once per matching effect, refetching the same data when a single
509+
// transaction credited the bridge more than once (#1051).
510+
var ops operations.OperationsPage
511+
opsFetched := false
505512
for _, effect := range effects.Embedded.Records {
506513
if effect.GetAccount() != w.config.StellarBridgeAccount {
507514
continue
@@ -520,9 +527,12 @@ func (w *StellarWallet) processTransaction(tx hProtocol.Transaction) ([]MintEven
520527
continue
521528
}
522529

523-
ops, err := w.getOperationEffect(tx.Hash)
524-
if err != nil {
525-
continue
530+
if !opsFetched {
531+
ops, err = w.getOperationEffect(tx.Hash)
532+
if err != nil {
533+
continue
534+
}
535+
opsFetched = true
526536
}
527537

528538
senders := make(map[string]*big.Int)

0 commit comments

Comments
 (0)