Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

services/horizon: Fix claimable balance query #5200

Conversation

urvisavla
Copy link
Contributor

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've updated the relevant CHANGELOG (here for Horizon) if
    needed with deprecations, added features, breaking changes, and DB schema changes.
  • I've decided if this PR requires a new major/minor version according to
    semver, or if it's mainly a patch change. The PR is targeted at the next
    release branch if it's not a patch change.

What

Explicitly qualify columns with table name/alias in claimable balance db query.

Query before the fix:
SELECT cb.id, cb.claimants, cb.asset, cb.amount, cb.sponsor, cb.last_modified_ledger, cb.flags FROM claimable_balances cb JOIN claimable_balance_claimants ON claimable_balance_claimants.id = cb.id WHERE (last_modified_ledger, id) > ($1, $2) AND claimable_balance_claimants.destination = $3 AND cb.asset = $4 ORDER BY last_modified_ledger ASC, id ASC LIMIT 200

With the fix:
SELECT cb.id, cb.claimants, cb.asset, cb.amount, cb.sponsor, cb.last_modified_ledger, cb.flags FROM claimable_balances cb JOIN claimable_balance_claimants ON claimable_balance_claimants.id = cb.id WHERE (cb.last_modified_ledger, cb.id) > ($1, $2) AND claimable_balance_claimants.destination = $3 AND cb.asset = $4 ORDER BY last_modified_ledger ASC, id ASC LIMIT 200

Why

Resolves Issue #5199

Issue #4907 introduced a join between claimable_balances and claimable_balance_claimants tables which resulted in unqualified columns in claimable balance query with cursor cursor causing database error column reference 'last_modified_ledger' is ambiguous.

Known limitations

@urvisavla urvisavla marked this pull request as ready for review February 7, 2024 06:27
@urvisavla urvisavla force-pushed the 5199/claimable-balance-query-cursor branch from 2ce7811 to 1b07a3d Compare February 7, 2024 06:36
@urvisavla urvisavla merged commit 4ef82e9 into stellar:release-horizon-v2.28.2 Feb 8, 2024
26 checks passed
urvisavla added a commit to urvisavla/go that referenced this pull request Feb 13, 2024
* services/horizon: Fix claimable balance query
* Fix Soroban RPC image incompatibility
urvisavla added a commit to urvisavla/go that referenced this pull request Feb 13, 2024
* services/horizon: Fix claimable balance query
* Fix Soroban RPC image incompatibility
Shaptic pushed a commit to Shaptic/go that referenced this pull request Feb 14, 2024
* services/horizon: Fix claimable balance query
* Fix Soroban RPC image incompatibility
Shaptic pushed a commit to Shaptic/go that referenced this pull request Feb 14, 2024
* services/horizon: Fix claimable balance query
* Fix Soroban RPC image incompatibility
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants