Skip to content

Let's try this again#712

Open
a-noni-mousse wants to merge 25 commits intoXahau:devfrom
a-noni-mousse:dev2
Open

Let's try this again#712
a-noni-mousse wants to merge 25 commits intoXahau:devfrom
a-noni-mousse:dev2

Conversation

@a-noni-mousse
Copy link
Copy Markdown
Contributor

This brings back some of the proposed changes from #665:

Some initial improvements to the code. Many of these are based on code by @nbougalis, before he left from Ripple, that aimed to improve the performance of the code but were never merged. I had cloned his repo before he deleted it and now I am taking those changes and updating them and merging them to xahaud.

The most significant new change included here involves base_uint which now uses 64-bit unsigned integers as the limb type when the requested number of bits is a multiple of 64, which improves performance on modern processors.

The changes to the Json code from 665 aren't included here and will come in a separate commit, after these changes are merged.

a-noni-mousse and others added 12 commits December 28, 2025 08:17
- Fix unlikely edge case in setCurrentThreadName
    setCurrentThreadName accepts a std::string_view parameter, which is
    not guaranteed to include a null terminator, which it then forwards
    to OS-specific APIs that expect null-terminated C strings.
- Fix several compilation warnings
- Fix header includes
- Fix unnecessarily verbose logging
- Simplify code using inline lambdas instead of std::bind
- Modernize the Beast "lexical cast" framework
- Use boost::asio types instead of legacy Beast type wrappers
- Clean up LogicError, custom exception throwing and termination handling
- Clean up and modernize PublicKey, SecretKey and Seed
    Simplify construction, buffer iteration and comparisons by leveraging
    modern C++ features.
- Clean up and modernize RFC1751 code
    Turn static-member-only class into namespace, thin out the public API
    and make code noexcept and constexpr. Verify internal data at compile
    time.
- Clean up CSPRNG engine
- Clean up rngfill function, eliminating GCC false-positive warning.
- Improve Slice comparison using C++ operator<=> and operator synthesis.
 - Add function-based spinlock API
 - Properly use compare_exchange_strong for try_lock
 - Improve comments

Co-authored-by: Nikolaos D. Bougalis <nikb@bougalis.net>
 - Improve the slab allocator public interfaces
 - Support construction of slab allocators at compile time
 - Improve declaration of slab allocators
 - Reduce impact of thrashing around slab boundaries
 - Reduce overhead of locking and increase parallelization

Co-authored-by: Nikolaos D. Bougalis <nikb@bougalis.net>
Remove unused dynamic thread count adjustment and reduce indirection
layers. Retains lock-free design while improving code clarity and
reducing internal latency.

Co-authored-by: Nikolaos D. Bougalis <nikb@bougalis.net>
Co-authored-by: Chenna Keshava B S <ckbs.keshava56@gmail.com>
This commit cleans up and modernizes the JobQueue but does not change
the queueing logic. It focuses on simplifying the code by eliminating
awkward code constructs, like "invalid jobs" and the need for default
constructors.

It leverages modern C++ to initialize tables and data structures at
compile time and replaces `std:map` instances with directly indexed
arrays.

Lastly, it restructures the load tracking infrastructure and reduces
the need for dynamic memory allocations by supporting move semantics
and value types.

Co-authored-by: Nikolaos D. Bougalis <nikb@bougalis.net>
This commit makes several changes to the base_uint class, which was
originally taken from Bitcoin and has already been heavily modified
by Ripple engineers.

It introduces conditional widening of the internal limb type, going
from 32 to 64 bits if the requested number of bits is a multiple of
64. This change alone halves iteration counts for common operations
and, combined with use of add-with-carry compiler intrinsics, helps
leverage modern processor resources more effectively.

Other changes include:

 - Extracting the arithmetic operations into free helper functions
   which operate on the limb array directly.
 - Replacing the SFINAE-based is_contiguous_container trait with a
   byte_copy_source concept.
 - Rewriting the hex parsing around a consteval lookup table and a
   simple left-to-right loop, replacing the old shift-based nibble
   accumulator.
 - Using memmove instead of memcpy when copying to avoid UB in the
   unlikely case where the source and destination buffers overlap.
 - Eliminating a workaround in operator<=> to handle MacOS quirks.
 - Removing redundant parseHex overloads and introducing from_hex
   as a factory function.
 - Introducing a tagless_compare() for cross-tag comparison.
 - Adding noexcept, [[nodiscard]], and constexpr throughout.
* Add AMM bid/create/deposit/swap/withdraw/vote invariants:
  - Deposit, Withdrawal invariants: `sqrt(asset1Balance * asset2Balance) >= LPTokens`.
  - Bid: `sqrt(asset1Balance * asset2Balance) > LPTokens` and the pool balances don't change.
  - Create: `sqrt(asset1Balance * assetBalance2) == LPTokens`.
  - Swap: `asset1BalanceAfter * asset2BalanceAfter >= asset1BalanceBefore * asset2BalanceBefore`
     and `LPTokens` don't change.
  - Vote: `LPTokens` and pool balances don't change.
  - All AMM and swap transactions: amounts and tokens are greater than zero, except on withdrawal if all tokens
    are withdrawn.
* Add AMM deposit and withdraw rounding to ensure AMM invariant:
  - On deposit, tokens out are rounded downward and deposit amount is rounded upward.
  - On withdrawal, tokens in are rounded upward and withdrawal amount is rounded downward.
* Add Order Book Offer invariant to verify consumed amounts. Consumed amounts are less than the offer.
* Fix Bid validation. `AuthAccount` can't have duplicate accounts or the submitter account.
Due to rounding, the LPTokenBalance of the last LP might not match the LP's trustline balance. This was fixed for `AMMWithdraw` in `fixAMMv1_1` by adjusting the LPTokenBalance to be the same as the trustline balance. Since `AMMClawback` is also performing a withdrawal, we need to adjust LPTokenBalance as well in `AMMClawback.`

This change includes:
1. Refactored `verifyAndAdjustLPTokenBalance` function in `AMMUtils`, which both`AMMWithdraw` and `AMMClawback` call to adjust LPTokenBalance.
2. Added the unit test `testLastHolderLPTokenBalance` to test the scenario.
3. Modify the existing unit tests for `fixAMMClawbackRounding`.
@sublimator
Copy link
Copy Markdown
Collaborator

@tequdev

Do you know where these commits stand vis a vis 2.5 ?

@a-noni-mousse
Copy link
Copy Markdown
Contributor Author

@tequdev

Do you know where these commits stand vis a vis 2.5 ?

I'd expect some conflicts. The repos have diverged enough that I think upstream pulls don't make sense anymore. The gains (DID, cross-chain) aren't worth the integration cost.

@a-noni-mousse
Copy link
Copy Markdown
Contributor Author

I must admit that I am a bit confused about the merge commits and the state of this branch as well as the process by which a PR gets merged. Can someone explain? Also, I think it's best for me to resbumit these as more limited pull requests which are tighter in scope for better review, so I will close this, unless @RichardAH things its ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants