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

exp/orderbook: Fix bug in CalculatePoolExpectation() #5541

Merged
merged 3 commits into from
Dec 4, 2024

Conversation

tamirms
Copy link
Contributor

@tamirms tamirms commented Dec 3, 2024

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 reviewed the changes in this PR and if I consider them worthwhile for being mentioned on release notes then I have updated the relevant CHANGELOG.md within the component folder structure. For example, if I changed horizon, then I updated (services/horizon/CHANGELOG.md. I add a new line item describing the change and reference to this PR. If I don't update a CHANGELOG, I acknowledge this PR's change may not be mentioned in future release notes.
  • 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

Fixes #5143

This commit fixes three inconsistencies with how liquidity pool payouts / expectations are calculated in core vs horizon:

  1. When calculating how much we need to deposit into a pool in order to receive a desired payout we need to consider that the calculated deposit may overflow the reserves, see https://github.com/stellar/stellar-core/blob/fdd833d57c86cfe0c5057da5b2319953ab841de0/src/transactions/OfferExchange.cpp#L1361-L1363
  2. We should rule out trades that will result in a payout of 0, see https://github.com/stellar/stellar-core/blob/fdd833d57c86cfe0c5057da5b2319953ab841de0/src/transactions/OfferExchange.cpp#L1325-L1327
  3. Fees that are greater than or equal to 100% are illegal, see https://github.com/stellar/stellar-core/blob/fdd833d57c86cfe0c5057da5b2319953ab841de0/src/transactions/OfferExchange.cpp#L1254-L1259

(2) and (3) do not affect the output of the horizon path finding endpoint because those corner cases are excluded from consideration in the path finding algorithm.

However, (1) results in horizon returning incorrect paths which attempt to trade against liquidity pools in a way that would overflow the liquidity pool reserves. When users try to submit path payments using these incorrect paths, core is not able to execute the trades and that results in a op_too_few_offers error.

Known limitations

[N/A]

@tamirms tamirms requested a review from a team December 3, 2024 08:35
Copy link
Contributor

@Shaptic Shaptic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just a coupla comments below ⬇️ really thorough investigation and fix, though 👏

exp/orderbook/pools.go Show resolved Hide resolved
exp/orderbook/pools.go Show resolved Hide resolved
exp/orderbook/pools.go Show resolved Hide resolved
@tamirms tamirms enabled auto-merge (squash) December 4, 2024 08:57
@tamirms tamirms merged commit 6a46ec2 into stellar:master Dec 4, 2024
31 checks passed
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.

Strict-receive pathfinder returns invalid paths
2 participants