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

Introduce MPT V1 support (XLS-33d) #5108

Closed
wants to merge 5 commits into from

Conversation

gregtatcam
Copy link
Collaborator

@gregtatcam gregtatcam commented Aug 27, 2024

High Level Overview of Change

New Transactions:

  • MPTokenIssuanceCreate
  • MPTokenIssuanceDestory
  • MPTokenIssuanceSet
  • MPTokenAuthorize

Modified Transactions:

  • Payment
  • Clawback

New Objects:

  • MPTokenIssuance
  • MPToken

API updates:

  • ledger_entry
  • account_objects
  • ledger_data

Refactor:

  • Add new types STMPTAmount, MPTIssue, MPTAmount to define MPT amount.
  • Add STEitherAmount as a variant of STAmount and STMPTAmount. STEitherAmount
    replaces STAmount as a serializable type for amount fields.
  • Add TypedVariantField and OptionaledVariantField to represent generic serializable variant type.
  • Add SOElement constructor overload to describe the amount fields, which may have MPT amount (currently only sfAmount). The constructors are used in TxFormats to define fields supporting MPT.
  • Add STObject::operator[] overload for *VariantField to return alternate type, held by a variant field.

Context of Change

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking change that only restructures code)
  • Performance (increase or change in throughput and/or latency)
  • Tests (you added tests for code that already exists, or your new feature included in this PR)
  • Documentation update
  • Chore (no impact to binary, e.g. .gitignore, formatting, dropping support for older tooling)
  • Release

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)

Test Plan

Added test for new feature:

  • MPT

Future Tasks

Integrate MPT into XRPL DEX.

@shawnxie999 shawnxie999 changed the title Introduce MPT support (XLS-33d) Introduce MPT V1 support (XLS-33d) Aug 27, 2024
Copy link

codecov bot commented Aug 27, 2024

Codecov Report

Attention: Patch coverage is 83.46401% with 232 lines in your changes missing coverage. Please review.

Project coverage is 76.2%. Comparing base (2f432e8) to head (6364440).
Report is 11 commits behind head on develop.

Files with missing lines Patch % Lines
src/xrpld/rpc/handlers/LedgerEntry.cpp 5.9% 32 Missing ⚠️
src/xrpld/app/tx/detail/InvariantCheck.cpp 68.8% 30 Missing ⚠️
src/libxrpl/protocol/STEitherAmount.cpp 84.1% 29 Missing ⚠️
src/xrpld/app/tx/detail/Payment.cpp 84.7% 24 Missing ⚠️
src/libxrpl/basics/MPTAmount.cpp 8.3% 22 Missing ⚠️
src/libxrpl/protocol/STMPTAmount.cpp 78.0% 18 Missing ⚠️
src/xrpld/ledger/detail/View.cpp 91.3% 11 Missing ⚠️
include/xrpl/protocol/STEitherAmount.h 68.8% 10 Missing ⚠️
src/xrpld/app/tx/detail/MPTokenAuthorize.cpp 92.5% 8 Missing ⚠️
src/libxrpl/protocol/STParsedJSON.cpp 57.1% 6 Missing ⚠️
... and 17 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #5108     +/-   ##
=========================================
+ Coverage     76.2%   76.2%   +0.1%     
=========================================
  Files          760     777     +17     
  Lines        61489   62682   +1193     
  Branches      8115    8220    +105     
=========================================
+ Hits         46832   47778    +946     
- Misses       14657   14904    +247     
Files with missing lines Coverage Δ
include/xrpl/basics/MPTAmount.h 100.0% <100.0%> (ø)
include/xrpl/basics/Number.h 100.0% <ø> (ø)
include/xrpl/basics/base_uint.h 96.6% <ø> (ø)
include/xrpl/protocol/Feature.h 100.0% <ø> (ø)
include/xrpl/protocol/Indexes.h 100.0% <100.0%> (ø)
include/xrpl/protocol/Issue.h 100.0% <ø> (ø)
include/xrpl/protocol/MPTIssue.h 100.0% <100.0%> (ø)
include/xrpl/protocol/Rate.h 100.0% <ø> (ø)
include/xrpl/protocol/SField.h 100.0% <100.0%> (ø)
include/xrpl/protocol/SOTemplate.h 96.7% <100.0%> (+1.7%) ⬆️
... and 72 more

... and 33 files with indirect coverage changes

Impacted file tree graph

New Transactions:
- MPTokenIssuanceCreate
- MPTokenIssuanceDestory
- MPTokenIssuanceSet
- MPTokenAuthorize

Modified Transactions:
- Payment
- Clawback

New Objects:
- MPTokenIssuance
- MPTokenAuthorize

API updates:
- ledger_entry
- account_objects
- ledger_data

Read full spec: https://github.com/XRPLF/XRPL-Standards/tree/master/XLS-0033d-multi-purpose-tokens

---------

Co-authored-by: Shawn Xie <shawnxie920@gmail.com>
Co-authored-by: Howard Hinnant <howard.hinnant@gmail.com>
r -= 1;
}
if (r > std::numeric_limits<MPTAmount::value_type>::max())
Throw<std::overflow_error>("XRP mulRatio overflow");
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: Overflow message should be MPT or MPTAmount instead of XRP.

std::size_t constexpr maxMPTokenMetadataLength = 1024;

/** The maximum amount of MPTokenIssuance */
std::uint64_t constexpr maxMPTokenAmount = 0x7FFFFFFFFFFFFFFFull;
Copy link
Contributor

Choose a reason for hiding this comment

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

Stylistic: I had to put in ' every four digits to convince myself that there was the proper number of Fs.

std::uint64_t constexpr maxMPTokenAmount = 0x7FFF'FFFF'FFFF'FFFFull;

@HowardHinnant
Copy link
Contributor

List of warnings flagged by clang. None of these are caused by this commit. The first warning has already made its way onto develop. The rest are not yet on develop.

rippled/src/xrpld/app/misc/NetworkOPs.cpp:2754:1: warning: function 'getAccounts' is not needed and will not be emitted [-Wunneeded-internal-declaration]
getAccounts(Json::Value const& jvObj, std::vector<AccountID>& accounts)
^

rippled/src/xrpld/app/tx/detail/XChainBridge.cpp:1745:16: warning: unused variable 'otherChainAmount' [-Wunused-variable]
    auto const otherChainAmount = [&]() -> STAmount {
               ^

rippled/src/test/app/ReducedOffer_test.cpp:141:36: warning: unused variable 'bobGot' [-Wunused-variable]
                    STAmount const bobGot =
                                   ^

rippled/src/test/app/ReducedOffer_test.cpp:122:32: warning: unused variable 'bobFinalBalance' [-Wunused-variable]
                STAmount const bobFinalBalance = env.balance(bob);
                               ^

rippled/src/test/app/ReducedOffer_test.cpp:299:36: warning: unused variable 'aliceGot' [-Wunused-variable]
                    STAmount const aliceGot =
                                   ^

rippled/src/test/app/ReducedOffer_test.cpp:275:32: warning: unused variable 'aliceFinalBalance' [-Wunused-variable]
                STAmount const aliceFinalBalance = env.balance(alice);
                               ^

rippled/src/test/app/XChain_test.cpp:1697:28: warning: unused variable 'split_reward_' [-Wunused-variable]
            STAmount const split_reward_ =
                           ^

rippled/src/test/app/XChain_test.cpp:3960:24: warning: unused variable 'amt_plus_reward' [-Wunused-variable]
            auto const amt_plus_reward = amt + reward;
                       ^

STAmount{
std::get<Issue>(issue), mantissa, exponent, native, negative}};
while (exponent-- > 0)
mantissa *= 10;
Copy link
Contributor

Choose a reason for hiding this comment

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

What if mantissa > maxMPTokenAmount prior to entering this loop, or becomes so after the *= 10 but before exponent == 0?

Unless there is other logic to prevent this I think we need to guard against mantissa *= 10 overflowing the uint64_t. This is only guaranteed if mantissa <= maxMPTokenAmount prior to the *= 10.

}

while (exponent-- > 0)
mantissa *= 10;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need overflow checks here?

* add issuance not found code

* add issuance check to start of func

* uses `exists()`
* fix maximum amt

* add if check to return tecMPT_ISSUANCE_NOT_FOUND
* MPT amount base 10

* add assert

* revert formatting

* test

* add test for maxamt

* clang

* parse as base 10 for all mpt amounts
@gregtatcam
Copy link
Collaborator Author

Replaced with #5143

@gregtatcam gregtatcam closed this Sep 19, 2024
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.

3 participants