Skip to content

Commit

Permalink
Remove sequenceNumber from checkTxAlreadyExists
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya1702 committed Sep 12, 2023
1 parent bcb5d82 commit c257fff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions services/horizon/internal/txsub/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ func txResultFromHistory(tx history.Transaction) (history.Transaction, error) {
// queries execute on different ledgers. In this case, txsub can mistakenly respond with a bad_seq error
// because the first query occurs when the tx is not yet ingested and the second query occurs when the tx
// is ingested.
func checkTxAlreadyExists(ctx context.Context, db HorizonDB, hash, sourceAddress string) (history.Transaction, uint64, error) {
func checkTxAlreadyExists(ctx context.Context, db HorizonDB, hash, sourceAddress string) (history.Transaction, error) {
err := db.BeginTx(ctx, &sql.TxOptions{
Isolation: sql.LevelRepeatableRead,
ReadOnly: true,
})
if err != nil {
return history.Transaction{}, 0, errors.Wrap(err, "cannot start repeatable read tx")
return history.Transaction{}, errors.Wrap(err, "cannot start repeatable read tx")
}
defer db.Rollback()

Expand All @@ -70,14 +70,14 @@ func checkTxAlreadyExists(ctx context.Context, db HorizonDB, hash, sourceAddress
var sequenceNumbers map[string]uint64
sequenceNumbers, err = db.GetSequenceNumbers(ctx, []string{sourceAddress})
if err != nil {
return tx, 0, errors.Wrapf(err, "cannot fetch sequence number for %v", sourceAddress)
return tx, errors.Wrapf(err, "cannot fetch sequence number for %v", sourceAddress)
}

num, ok := sequenceNumbers[sourceAddress]
_, ok := sequenceNumbers[sourceAddress]
if !ok {
return tx, 0, ErrNoAccount
return tx, ErrNoAccount
}
return tx, num, ErrNoResults
return tx, ErrNoResults
}
return tx, 0, err
return tx, err
}
2 changes: 1 addition & 1 deletion services/horizon/internal/txsub/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (sys *System) Submit(
return
}

tx, _, err := checkTxAlreadyExists(ctx, db, hash, sourceAddress)
tx, err := checkTxAlreadyExists(ctx, db, hash, sourceAddress)
if err == nil {
sys.Log.Ctx(ctx).WithField("hash", hash).Info("Found submission result in a DB")
sys.finish(ctx, hash, resultCh, Result{Transaction: tx})
Expand Down

0 comments on commit c257fff

Please sign in to comment.