Sponsored Content
Skip to content

fix: Fix wrong hybrid offer orderbook placement and update LedgerStateFix to amend ExchangeRate meta - #7087

Merged
bthomee merged 18 commits into
XRPLF:developfrom
shawnxie999:fix-pdex-ratio
May 21, 2026
Merged

fix: Fix wrong hybrid offer orderbook placement and update LedgerStateFix to amend ExchangeRate meta#7087
bthomee merged 18 commits into
XRPLF:developfrom
shawnxie999:fix-pdex-ratio

Conversation

@shawnxie999

@shawnxie999 shawnxie999 commented May 6, 2026

Copy link
Copy Markdown
Contributor

High Level Overview of Change

1. Fix hybrid offer placement

For hybrid offers, sfBookDirectory points to the permissioned domain book, and sfAdditionalBooks[0].sfBookDirectory points to the open book.

This fixes OfferCreate so the open-book directory in sfAdditionalBooks uses the original offer quality after partial crossing, instead of the post-crossing quality.

2. Add legacy repair support

Adds LedgerStateFix support to repair legacy book-directory sfExchangeRate metadata when it does not match the quality encoded in the directory key.

Also adds invariant coverage for new book directories to make sure ExchangeRate meta matches the real quality

API Impact

  • Public API: New feature (new methods and/or new fields)
  • Public API: Breaking change (in general, breaking changes should only impact the next api_version)
  • libxrpl change (any change that may affect libxrpl or dependents of libxrpl)
  • Peer protocol change (must be backward compatible or bump the peer protocol version)

@shawnxie999
shawnxie999 marked this pull request as ready for review May 6, 2026 20:41
@shawnxie999 shawnxie999 changed the title Fix pdex ratio fix: fix wrong hybrid offer orderbook placement and update LedgerStateFix to amend ExchangeRate meta May 6, 2026
@shawnxie999 shawnxie999 changed the title fix: fix wrong hybrid offer orderbook placement and update LedgerStateFix to amend ExchangeRate meta fix: Fix wrong hybrid offer orderbook placement and update LedgerStateFix to amend ExchangeRate meta May 6, 2026
@codecov

codecov Bot commented May 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.1%. Comparing base (a830ab1) to head (c53d114).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           develop   #7087   +/-   ##
=======================================
  Coverage     82.1%   82.1%           
=======================================
  Files         1010    1011    +1     
  Lines        76268   76343   +75     
  Branches      7412    7412           
=======================================
+ Hits         62610   62683   +73     
- Misses       13658   13660    +2     
Files with missing lines Coverage Δ
include/xrpl/protocol/detail/transactions.macro 100.0% <ø> (ø)
...rpl/protocol_autogen/transactions/LedgerStateFix.h 100.0% <100.0%> (ø)
include/xrpl/tx/invariants/InvariantCheck.h 100.0% <ø> (ø)
include/xrpl/tx/transactors/dex/OfferCreate.h 100.0% <ø> (ø)
...nclude/xrpl/tx/transactors/system/LedgerStateFix.h 100.0% <ø> (ø)
src/libxrpl/tx/invariants/DirectoryInvariant.cpp 100.0% <100.0%> (ø)
src/libxrpl/tx/transactors/dex/OfferCreate.cpp 93.3% <100.0%> (+0.1%) ⬆️
...c/libxrpl/tx/transactors/system/LedgerStateFix.cpp 100.0% <100.0%> (ø)

... and 1 file with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shawnxie999 shawnxie999 added this to the 3.2.0 milestone May 6, 2026
Comment thread src/libxrpl/tx/transactors/dex/OfferCreate.cpp Outdated
Comment thread src/libxrpl/tx/transactors/dex/OfferCreate.cpp Outdated
Comment thread src/libxrpl/tx/transactors/system/LedgerStateFix.cpp
@github-actions

Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

@gregtatcam gregtatcam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 LGTM

I left two minor comments for your consideration.

Comment thread src/libxrpl/tx/invariants/DirectoryInvariant.cpp Outdated
Comment thread src/libxrpl/tx/invariants/DirectoryInvariant.cpp Outdated
@github-actions

Copy link
Copy Markdown

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

@Kassaking7 Kassaking7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Comment thread src/libxrpl/tx/transactors/system/LedgerStateFix.cpp

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a legacy hybrid-offer placement bug where the open-book directory key quality could diverge from the directory’s sfExchangeRate metadata after partial crossing, and adds tooling + invariants to detect/repair mismatched book-directory exchange-rate metadata.

Changes:

  • Adjust OfferCreate hybrid placement so the open-book directory uses the original placement rate (post-fixCleanup3_2_0) instead of a post-crossing-derived rate.
  • Extend LedgerStateFix with a new BookExchangeRate fix type to repair sfExchangeRate on existing book root directory pages.
  • Add a new invariant (ValidBookDirectory) to enforce sfExchangeRate metadata consistency for newly-created book directories, plus add/extend tests and jtx helpers.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/libxrpl/tx/transactors/dex/OfferCreate.cpp Uses feature-gated openRate for hybrid open-book directory placement to prevent key/metadata divergence.
include/xrpl/tx/transactors/dex/OfferCreate.h Updates applyHybrid signature to accept the precomputed open-book quality rate.
src/libxrpl/tx/transactors/system/LedgerStateFix.cpp Adds preflight/preclaim/doApply handling for FixType::BookExchangeRate.
include/xrpl/tx/transactors/system/LedgerStateFix.h Adds FixType::BookExchangeRate enum value (public header change).
include/xrpl/protocol/detail/transactions.macro Adds optional sfBookDirectory field to LedgerStateFix transaction format.
include/xrpl/protocol_autogen/transactions/LedgerStateFix.h Autogen wrapper/builder support for optional sfBookDirectory.
src/tests/libxrpl/protocol_autogen/transactions/LedgerStateFixTests.cpp Extends round-trip tests to cover sfBookDirectory.
src/test/jtx/ledgerStateFix.h Adds jtx helper declaration for bookExchangeRate.
src/test/jtx/impl/ledgerStateFixes.cpp Implements ledgerStateFix::bookExchangeRate JSON constructor.
src/libxrpl/tx/invariants/DirectoryInvariant.cpp Introduces ValidBookDirectory invariant implementation.
include/xrpl/tx/invariants/DirectoryInvariant.h Declares ValidBookDirectory invariant class.
include/xrpl/tx/invariants/InvariantCheck.h Registers ValidBookDirectory in the invariant tuple.
src/test/app/Invariants_test.cpp Adds invariant tests for book-directory exchange rate consistency and legacy tolerance.
src/test/app/PermissionedDEX_test.cpp Adds regression test for hybrid crossing quality + LedgerStateFix repair-path test.
src/test/app/FixNFTokenPageLinks_test.cpp Adds negative test ensuring fix-type-specific fields are rejected.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/libxrpl/tx/invariants/DirectoryInvariant.cpp
Comment thread include/xrpl/tx/transactors/system/LedgerStateFix.h
@github-actions

Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

@github-actions

Copy link
Copy Markdown

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

@PeterChen13579

Copy link
Copy Markdown
Contributor

/ai-review

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues.

Review by Claude Opus 4.6 · Prompt: V15

@bthomee
bthomee added this pull request to the merge queue May 21, 2026
Merged via the queue into XRPLF:develop with commit 28cc20c May 21, 2026
3 checks passed

@ximinez ximinez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@shawnxie999 @bthomee The below issue needs to be resolved before the release. You should also add some test cases that delete an order book directory entry with the bad value to ensure you don't get any false hits in the invariant.

Comment on lines +52 to +53
if (badBookDirectory_ || before || !after || after->getType() != ltDIR_NODE)
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You should probably also return early if isDelete is true.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ximinez I have addressed the comments and added test here: #7312

Kassaking7 pushed a commit to Kassaking7/rippled that referenced this pull request Jun 2, 2026
…teFix` to amend `ExchangeRate` meta (XRPLF#7087)

Co-authored-by: Peter Chen <ychen@ripple.com>
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.

8 participants