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 support (XLS-33d): #5143

Open
wants to merge 47 commits into
base: develop
Choose a base branch
from

Conversation

gregtatcam
Copy link
Collaborator

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 Asset, MPTIssue, MPTAmount to handle MPT amount.
  • 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.

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.

Copy link

codecov bot commented Sep 19, 2024

Codecov Report

Attention: Patch coverage is 86.42534% with 180 lines in your changes missing coverage. Please review.

Project coverage is 77.5%. Comparing base (63209c2) to head (e4009c8).

Files with missing lines Patch % Lines
src/libxrpl/protocol/STAmount.cpp 80.0% 34 Missing ⚠️
src/xrpld/app/tx/detail/InvariantCheck.cpp 66.3% 30 Missing ⚠️
src/xrpld/ledger/detail/View.cpp 88.7% 20 Missing ⚠️
src/libxrpl/protocol/MPTIssue.cpp 46.7% 16 Missing ⚠️
src/libxrpl/basics/MPTAmount.cpp 12.5% 14 Missing ⚠️
src/xrpld/rpc/handlers/LedgerEntry.cpp 68.6% 11 Missing ⚠️
src/xrpld/app/tx/detail/MPTokenAuthorize.cpp 92.3% 9 Missing ⚠️
src/libxrpl/protocol/Asset.cpp 71.4% 6 Missing ⚠️
src/libxrpl/protocol/STParsedJSON.cpp 62.5% 6 Missing ⚠️
src/xrpld/app/tx/detail/Payment.cpp 95.5% 6 Missing ⚠️
... and 12 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #5143     +/-   ##
=========================================
+ Coverage     76.1%   77.5%   +1.4%     
=========================================
  Files          762     777     +15     
  Lines        61469   65832   +4363     
  Branches      8121    8187     +66     
=========================================
+ Hits         46807   51020   +4213     
- Misses       14662   14812    +150     
Files with missing lines Coverage Δ
include/xrpl/basics/MPTAmount.h 100.0% <100.0%> (ø)
include/xrpl/basics/Number.h 100.0% <100.0%> (ø)
include/xrpl/basics/XRPAmount.h 98.8% <ø> (+<0.1%) ⬆️
include/xrpl/basics/base_uint.h 96.8% <ø> (+0.1%) ⬆️
include/xrpl/protocol/AmountConversions.h 87.7% <100.0%> (+0.2%) ⬆️
include/xrpl/protocol/Feature.h 100.0% <ø> (ø)
include/xrpl/protocol/Indexes.h 100.0% <ø> (ø)
include/xrpl/protocol/Issue.h 100.0% <100.0%> (ø)
include/xrpl/protocol/MPTIssue.h 100.0% <100.0%> (ø)
include/xrpl/protocol/Rate.h 100.0% <ø> (ø)
... and 56 more

... and 530 files with indirect coverage changes

Impacted file tree graph

@gregtatcam gregtatcam force-pushed the feature/mpt-v1-var-issues branch 2 times, most recently from 4ca85a2 to ba5f67c Compare September 19, 2024 14:22
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:/XRPLF/XRPL-Standards/tree/master/XLS-0033d-multi-purpose-tokens

---------

Co-authored-by: Shawn Xie <[email protected]>
Co-authored-by: Howard Hinnant <[email protected]>
lsfMPTCanClawback = 0x00000040,

// ltMPTOKEN
lsfMPTAuthorized = 0x00000002,
Copy link
Contributor

Choose a reason for hiding this comment

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

lsfMPTLocked, lsfMPTCanLock and lsfMPTAuthorized do not have unique values within this enum. Is that on purpose?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The LedgerSpecificFlags enum is really just a way to define a bunch of constants. The flags are unique per ledger object type. Those are divided by the comment / label before each one. It might be worthwhile to split them into one per object type, but that's probably beyond the scope of this PR.

Copy link
Collaborator

@thejohnfreeman thejohnfreeman left a comment

Choose a reason for hiding this comment

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

Submitting the first phase of my review, a complete review of the changes to libxrpl.

include/xrpl/basics/MPTAmount.h Outdated Show resolved Hide resolved
include/xrpl/basics/MPTAmount.h Outdated Show resolved Hide resolved
include/xrpl/basics/MPTAmount.h Outdated Show resolved Hide resolved
include/xrpl/protocol/Asset.h Show resolved Hide resolved
include/xrpl/protocol/UintTypes.h Outdated Show resolved Hide resolved
src/libxrpl/protocol/LedgerFormats.cpp Outdated Show resolved Hide resolved
src/libxrpl/protocol/LedgerFormats.cpp Outdated Show resolved Hide resolved
src/libxrpl/protocol/LedgerFormats.cpp Outdated Show resolved Hide resolved
src/libxrpl/protocol/LedgerFormats.cpp Outdated Show resolved Hide resolved
src/libxrpl/protocol/STTx.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@ximinez ximinez left a comment

Choose a reason for hiding this comment

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

Partial review:

include/xrpl/basics/MPTAmount.h Outdated Show resolved Hide resolved
src/test/jtx/impl/mpt.cpp Outdated Show resolved Hide resolved
include/xrpl/basics/MPTAmount.h Outdated Show resolved Hide resolved
include/xrpl/protocol/Asset.h Show resolved Hide resolved
include/xrpl/protocol/LedgerFormats.h Outdated Show resolved Hide resolved
include/xrpl/protocol/SOTemplate.h Outdated Show resolved Hide resolved
include/xrpl/protocol/SOTemplate.h Outdated Show resolved Hide resolved
src/libxrpl/protocol/STAmount.cpp Outdated Show resolved Hide resolved
src/libxrpl/protocol/STAmount.cpp Show resolved Hide resolved
src/libxrpl/protocol/STAmount.cpp Outdated Show resolved Hide resolved
gregtatcam and others added 3 commits October 1, 2024 13:25
Update MPT Payment errors to be consistent with IOU Payment.
Copy link
Collaborator

@ximinez ximinez left a comment

Choose a reason for hiding this comment

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

Partial review


namespace ripple {

class MPTAmount : private boost::totally_ordered<MPTAmount>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seeing how similar MPTAmount is to XRPAmount it's a pity that they aren't implemented with common code. I.e. through a base class, or a template or something. Rather than diving down the potential rabbit hole of implementing it, I'm just going to leave this note here for someone else or for future reference.

Copy link
Collaborator

Choose a reason for hiding this comment

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

My opinion:

  • They should be called MPTNumber and XRPNumber because they represent quantities, while STAmount represents a quantity plus an asset / issue / unit (however you want to think of it). These are more like Number, and convert directly to and from it.
  • All of the arithmetic is moving to Number after the switchover anyway. In due time, when we retire that amendment, effectively locking it in permanently, then I think we can remove MPTAmount and XRPAmount.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should IOUAmount change too? I think that Amount better communicates what the value is. I don't think you'd say number when talking about tokens or currencies even if the values don't have associate unit. And XRPAmount doesn't need an issue, it's implicit. Also doesn't seem like this refactoring has to be done in MPT PR. But this is just my opinion. I'll change if everyone thinks Number is better. There are over 300 instances of XRPAmount, MPTAmount, IOUAmount.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I created a ticket to refactor MPTAmount and XRPAmount to use a common code + renaming.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I'm not asking it to be done here, or at all even. Was just stating my position. My opinion is that IOUAmount should be renamed too (in an ideal world), and my only reason for these renames is that STAmount has quantity + issue, while these {XRP,IOU,MPT}Amounts only have quantity, like Number, which is their common representation. The alternative fix is to rename STAmount to a different suffix, but I think that would be even more disruptive, especially to external projects.

include/xrpl/protocol/STAmount.h Show resolved Hide resolved
include/xrpl/protocol/STAmount.h Outdated Show resolved Hide resolved
include/xrpl/protocol/STAmount.h Outdated Show resolved Hide resolved
src/xrpld/app/misc/NetworkOPs.cpp Show resolved Hide resolved
src/libxrpl/protocol/LedgerFormats.cpp Outdated Show resolved Hide resolved
src/libxrpl/protocol/LedgerFormats.cpp Outdated Show resolved Hide resolved
src/libxrpl/protocol/MPTIssue.cpp Outdated Show resolved Hide resolved
src/libxrpl/protocol/STAmount.cpp Outdated Show resolved Hide resolved
src/xrpld/ledger/detail/View.cpp Outdated Show resolved Hide resolved
Comment on lines 33 to 37
/* Asset is a variant of Issue (XRP and IOU) and MPTIssue (MPT).
* It enables handling of different issues when either one is expected.
* For instance, it extends STAmount class to support either issue
* in a general way. It handles specifics such arithmetics and serialization
* depending on specific issue type held by Asset.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find it odd that you think of this as "either one" (of two, Issue or MPTIssue) instead of "any one" (of three, XRP, IOU, or MPT). Don't we want our abstract ledger functions to think in terms of 3 issue types instead of 2 specific implementations?

I find the example (STAmount) a little hard to understand, too. The "it" at the beginning of the last sentence refers to STAmount, while the "it" in the sentence before is Asset? I don't think "extends" is the right word either. Is the example just trying to convey that STAmount uses Asset to abstract arithmetic and serialization operations over all 3 issue types?

I'm left wondering why we have this Asset instead of making Issue support 3 issue types. STAmount has a native() -> bool method. Can Asset have that too? Issue has a getIssuer() -> AccountID method. Can Asset have that too? Why does Asset exist if it's not going to offer any helper methods? With no helpers, it could just be a type alias for std::variant.


namespace ripple {

class MPTAmount : private boost::totally_ordered<MPTAmount>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

My opinion:

  • They should be called MPTNumber and XRPNumber because they represent quantities, while STAmount represents a quantity plus an asset / issue / unit (however you want to think of it). These are more like Number, and convert directly to and from it.
  • All of the arithmetic is moving to Number after the switchover anyway. In due time, when we retire that amendment, effectively locking it in permanently, then I think we can remove MPTAmount and XRPAmount.

Comment on lines 91 to 93
friend std::istream&
operator>>(std::istream& s, MPTAmount& val);

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this was left behind.

Suggested change
friend std::istream&
operator>>(std::istream& s, MPTAmount& val);

Comment on lines 354 to 356
MPTID
makeMptID(AccountID const& account, std::uint32_t sequence);

Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you think of putting sequence first in the parameter list? (Here and in the overload of mptIssuance(), and maybe elsewhere.)

mptoken(MPTID const& issuanceID, AccountID const& holder) noexcept;

inline Keylet
mptoken(uint256 const& issuanceKey)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This parameter should be mptokenKey right? I think I confused you with my earlier comment on the other parameters. I was just saying that the issuance parameter name should end with Key like issuanceKey and mptokenKey.

include/xrpl/protocol/MPTIssue.h Show resolved Hide resolved
Comment on lines 100 to 101
JSS(MPTokenIssuance); // ledger type.
JSS(MPTokenIssuanceCreate); // transaction type.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's worth it so we don't get radical re-formatting every time a few strings are added. We want the change set to highlight meaningful changes. GitHub's whitespace exclusion can hide these changes, but it can mask unwanted changes too. It's fine to restore the previous formatting so that this changeset has only the added strings.

src/libxrpl/protocol/STTx.cpp Show resolved Hide resolved
include/xrpl/protocol/UintTypes.h Show resolved Hide resolved
Copy link
Collaborator

@ximinez ximinez left a comment

Choose a reason for hiding this comment

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

Partial review

src/libxrpl/protocol/STAmount.cpp Outdated Show resolved Hide resolved
src/libxrpl/protocol/STAmount.cpp Outdated Show resolved Hide resolved
src/libxrpl/protocol/STAmount.cpp Outdated Show resolved Hide resolved
src/libxrpl/protocol/STAmount.cpp Outdated Show resolved Hide resolved
src/libxrpl/protocol/STAmount.cpp Outdated Show resolved Hide resolved
src/libxrpl/protocol/STAmount.cpp Outdated Show resolved Hide resolved
src/libxrpl/protocol/STAmount.cpp Outdated Show resolved Hide resolved
src/libxrpl/protocol/STAmount.cpp Outdated Show resolved Hide resolved
src/libxrpl/protocol/STAmount.cpp Outdated Show resolved Hide resolved
* Refactor getSNValue/getMPTValue
* Use std::min, std::max
* Fix min/max values for MPT
Comment on lines +207 to +218
// MPTokenIssuanceCreate flags:
constexpr std::uint32_t const tfMPTokenIssuanceCreateMask =
~(tfMPTCanLock | tfMPTRequireAuth | tfMPTCanEscrow | tfMPTCanTrade | tfMPTCanTransfer | tfMPTCanClawback | tfUniversal);

// MPTokenIssuanceDestroy flags:
constexpr std::uint32_t const tfMPTokenIssuanceDestroyMask = ~tfUniversal;

// MPTokenAuthorize flags:
constexpr std::uint32_t const tfMPTokenAuthorizeMask = ~(tfMPTUnauthorize | tfUniversal);

// MPTokenIssuanceSet flags:
constexpr std::uint32_t const tfMPTokenIssuanceSetMask = ~(tfMPTLock | tfMPTUnlock | tfUniversal);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please move the masks next to their flags, like the pattern for AMM, and please put tfUniversal first in the sequences.

* Fix paths comments in Payment
* Refactor View
Copy link
Collaborator

@ximinez ximinez left a comment

Choose a reason for hiding this comment

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

Partial feedback review. I forgot to post this first comment last week, so I'll share these now, and continue reviewing.

src/xrpld/ledger/detail/View.cpp Outdated Show resolved Hide resolved
src/xrpld/ledger/detail/View.cpp Outdated Show resolved Hide resolved
src/xrpld/ledger/detail/View.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@ximinez ximinez left a comment

Choose a reason for hiding this comment

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

Partial review

src/test/protocol/STTx_test.cpp Outdated Show resolved Hide resolved
shawnxie999 and others added 3 commits October 15, 2024 09:59
* Simplify updating some MPT fields in View
* ledger_entry test

* remove unneed line
include/xrpl/protocol/STObject.h Outdated Show resolved Hide resolved
src/test/protocol/STTx_test.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@ximinez ximinez left a comment

Choose a reason for hiding this comment

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

Partial review

src/test/jtx/mpt.h Outdated Show resolved Hide resolved
src/test/jtx/mpt.h Outdated Show resolved Hide resolved
src/test/jtx/mpt.h Show resolved Hide resolved
src/test/jtx/mpt.h Outdated Show resolved Hide resolved
src/test/jtx/mpt.h Outdated Show resolved Hide resolved
src/test/jtx/mpt.h Outdated Show resolved Hide resolved
src/test/jtx/mpt.h Outdated Show resolved Hide resolved
src/test/jtx/mpt.h Outdated Show resolved Hide resolved
@XRPLF XRPLF deleted a comment from Speedtraders48 Oct 16, 2024
TER
doApply() override;

static TER
Copy link
Collaborator

Choose a reason for hiding this comment

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

In my vault branch, I make this method return Expected<MPTID, TER>. Can you please make that change here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we necessarily need to make this change in this PR. These refactors could be done at a later time when needed (perhaps include the refactor you open the vault PR).

Comment on lines +80 to +82
if (args.priorBalance <
view.fees().accountReserve((*acct)[sfOwnerCount] + 1))
return tecINSUFFICIENT_RESERVE;
Copy link
Collaborator

Choose a reason for hiding this comment

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

In my vault branch, I move this check out of this function and into its (for now) only caller.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto


struct MPTCreateArgs
{
XRPAmount const& priorBalance;
Copy link
Collaborator

Choose a reason for hiding this comment

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

In my branch, this field is removed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

include/xrpl/protocol/TER.h Outdated Show resolved Hide resolved
Comment on lines +49 to +61
// Concept to constrain STVar constructors, which
// instantiate ST* types from SerializedTypeID
// clang-format off
template <typename... Args>
concept ValidConstructSTArgs =
(std::is_same_v<
std::tuple<std::remove_cvref_t<Args>...>,
std::tuple<SField>> ||
std::is_same_v<
std::tuple<std::remove_cvref_t<Args>...>,
std::tuple<SerialIter, SField>>);
// clang-format on

Copy link
Collaborator

Choose a reason for hiding this comment

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

This declaration of ValidConstructSTArgs, and the one below of constructST, don't need to be in this header. They are only used in STVar.cpp, where they are defined. This header doesn't need the new includes, then, either, but STVar.cpp might.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you mean to make it non-member function defined in STVar.cpp? It calls private STVar::construct().

src/libxrpl/protocol/Rate2.cpp Show resolved Hide resolved
src/libxrpl/protocol/STAmount.cpp Show resolved Hide resolved
@@ -278,7 +276,7 @@ STAmount::xrp() const
IOUAmount
STAmount::iou() const
{
if (native() || holds<MPTIssue>())
if (native() || !holds<Issue>())
Throw<std::logic_error>("Cannot return native STAmount as IOUAmount");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Throw<std::logic_error>("Cannot return native STAmount as IOUAmount");
Throw<std::logic_error>("Cannot return non-IOU STAmount as IOUAmount");

src/test/jtx/impl/mpt.cpp Outdated Show resolved Hide resolved
src/xrpld/app/tx/detail/MPTokenAuthorize.h Show resolved Hide resolved
[[nodiscard]] bool
isGlobalFrozen(ReadView const& view, AccountID const& issuer);

[[nodiscard]] bool
isGlobalFrozen(ReadView const& view, MPTIssue const& mptIssue);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please add isGlobalFrozen, isIndividualFrozen, and isFrozen overloads for Asset?

@@ -209,6 +237,9 @@ forEachItemAfter(
[[nodiscard]] Rate
transferRate(ReadView const& view, AccountID const& issuer);

[[nodiscard]] Rate
transferRate(ReadView const& view, MPTID const& issuanceID);
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's no docstring for either of the overloads. Can you add one, please?

bool bCheckIssuer,
beast::Journal j);

[[nodiscard]] TER
rippleCreditMPT(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unlike the others, which accept Issue vs MPTIssue, there is no type difference in the parameter list to distinguish these "overloads". What do you think of renaming the original function and all existing callers rippleCreditIOU? Could then add a function rippleCredit that takes an STAmount and works for any asset by delegating to the other overloads. Similar for accountSend.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good. Let me give it a try.

Comment on lines +35 to +47
bool
canHaveMPTokenIssuanceID(
std::shared_ptr<STTx const> const& serializedTx,
TxMeta const& transactionMeta);

std::optional<uint192>
getIDFromCreatedIssuance(TxMeta const& transactionMeta);

void
insertMPTokenIssuanceID(
Json::Value& response,
std::shared_ptr<STTx const> const& transaction,
TxMeta const& transactionMeta);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add some comments explaining why these functions exist, when they should be used, etc.

Copy link
Collaborator

Choose a reason for hiding this comment

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

added in fixed in gregtatcam#43

Json::Value& response,
std::shared_ptr<STTx const> const& transaction,
TxMeta const& transactionMeta);
/** @} */
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is going on this line?

Suggested change
/** @} */

Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldve been a comment, added in gregtatcam#43

MPTIssue const& mptIssue);

[[nodiscard]] bool
isFrozen(ReadView const& view, AccountID const& account, Asset const& asset)
Copy link
Contributor

Choose a reason for hiding this comment

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

ld: warning: ignoring duplicate libraries: '-lc++'
duplicate symbol 'ripple::isFrozen(ripple::ReadView const&, ripple::base_uint<160ul, ripple::detail::AccountIDTag> const&, ripple::Asset const&)'

Missing inline.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have already pushed a fix.

* Add static functions rippleCredit[MPT/IOU]() and accountSend[MPT/IOU]()
* Change rippleCredit() and accountSend() to work for any asset by calling the static versions
Copy link
Contributor

@HowardHinnant HowardHinnant left a comment

Choose a reason for hiding this comment

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

This is a partial review. Here is the list of files I've reviewed:

AmountConversions.h
Asset.h
base_uint.h
Feature.h
LedgerFormats.h
MPTAmount.h
MPTAmount.cpp
MPTIssue.h
MPTIssue.cpp
MPTokenIssuanceSet.h
Number.h
Number.cpp
Protocol.h
Serializer.h
STAmount.h
STAmount.cpp
STBitString.h
STInteger.cpp
View.h
XRPAmount.h

All comments I have made have been resolved.

All unit tests pass.

Copy link
Collaborator

@ximinez ximinez left a comment

Choose a reason for hiding this comment

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

Not as much progress today, but pointed out a couple of small issues.

include/xrpl/protocol/detail/transactions.macro Outdated Show resolved Hide resolved
include/xrpl/protocol/jss.h Outdated Show resolved Hide resolved
to_string(Asset const& asset);

bool
validJSONAsset(Json::Value const& jv);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please write an assetFromJson? You may want to delegate to issueFromJson (which exists) and mptIssueFromJson (which does not exist). I need in the stissue branch, in STParsedJSON.cpp, in the case for STI_ISSUE (which right now calls issueFromJson).

gregtatcam and others added 3 commits October 18, 2024 09:39
* Add assetFromJson, mptIssueFromJson
* Minor refactoring
* removed unused declarations

* comments
Copy link
Collaborator

@ximinez ximinez left a comment

Choose a reason for hiding this comment

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

Partial review. Left off at testMPTInvalidInTx in MPToken_test.cpp.

A couple of general points

  • I tagged a bunch of asserts with suggested rewrites. We really want to avoid asserts in test code unless there's absolutely no other way to do it. If I missed any, please rewrite those, too.
  • I haven't tagged any more copyright date issues, but some remain. Please take care of those.

"mptIssueFromJson, MPTIssue should not have currency or issuer");
}

Json::Value const idStr = v[jss::mpt_issuance_id];
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think idStr can be a const ref

Suggested change
Json::Value const idStr = v[jss::mpt_issuance_id];
Json::Value const& idStr = v[jss::mpt_issuance_id];

Comment on lines +243 to +244
std::unordered_map<std::string, Account>
makeHolders(std::vector<Account> const& holders);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking at it again, makeHolders should be static.

Comment on lines +123 to +127
else
{
assert(id_);
jv[sfMPTokenIssuanceID] = to_string(*id_);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
else
{
assert(id_);
jv[sfMPTokenIssuanceID] = to_string(*id_);
}
else if (env_.test.BEAST_EXPECT(id_))
{
jv[sfMPTokenIssuanceID] = to_string(*id_);
}

If id_ is undefined, the transaction will be generated without one, and will fail, which is good.

Comment on lines +109 to +110
else if (arg.flags)
env_.require(mptflags(*this, *arg.flags));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
else if (arg.flags)
env_.require(mptflags(*this, *arg.flags));
else
env_.require(mptflags(*this, arg.flags.value_or(0)));

This ensures the Issuance is created regardless, and that no unwanted flags are set.

Comment on lines +136 to +138
assert(it != holders_.cend());
if (it == holders_.cend())
Throw<std::runtime_error>("Holder is not found");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
assert(it != holders_.cend());
if (it == holders_.cend())
Throw<std::runtime_error>("Holder is not found");
if (it == holders_.cend())
Throw<std::runtime_error>("Holder is not found");

Get rid of the assert so that other runners aren't affected, but the Throw will still cause the test suite to fail.

Comment on lines +285 to +300
// Check that bob cannot delete MPToken when his balance is
// non-zero
{
// alice pays bob 100 tokens
mptAlice.pay(alice, bob, 100);

// bob tries to delete his MPToken, but fails since he still
// holds tokens
mptAlice.authorize(
{.account = bob,
.flags = tfMPTUnauthorize,
.err = tecHAS_OBLIGATIONS});

// bob pays back alice 100 tokens
mptAlice.pay(bob, alice, 100);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: These {} are redundant, since nothing was created inside the scope.

Comment on lines +359 to +363
MPTTester mptAlice1(
env,
alice,
{.holders = {bob},
.xrpHolders = acctReserve + XRP(1).value().xrp()});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
MPTTester mptAlice1(
env,
alice,
{.holders = {bob},
.xrpHolders = acctReserve + XRP(1).value().xrp()});
// 1 drop
BEAST_EXPECT(incReserve > XRPAmount(1));
MPTTester mptAlice1(
env,
alice,
{.holders = {bob},
.xrpHolders = acctReserve + (incReserve - 1)});

Comment on lines +486 to +490
// test invalid flag
mptAlice.set(
{.account = alice,
.flags = 0x00000008,
.err = temINVALID_FLAG});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// test invalid flag
mptAlice.set(
{.account = alice,
.flags = 0x00000008,
.err = temINVALID_FLAG});
// test invalid flag - only valid flags are tfMPTLock (1) and Unlock (2)
mptAlice.set(
{.account = alice,
.flags = 0x00000008,
.err = temINVALID_FLAG});

Comment on lines +669 to +670
jv[jss::tx_json][jss::Fee] = to_string(env.current()->fees().base);
jv[jss::tx_json] = pay(alice, carol, mpt);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will overwrite Fee.

Suggested change
jv[jss::tx_json][jss::Fee] = to_string(env.current()->fees().base);
jv[jss::tx_json] = pay(alice, carol, mpt);
jv[jss::tx_json] = pay(alice, carol, mpt);
jv[jss::tx_json][jss::Fee] = to_string(env.current()->fees().base);

Comment on lines +773 to +775
mptAlice.pay(alice, bob, -1, temBAD_AMOUNT);

env(pay(alice, bob, MPT(10)), sendmax(MPT(-1)), ter(temBAD_AMOUNT));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add a few more cases here with bob trying to pay another holder (carol), and bob trying to pay back to alice. That'll probably require alice sending a valid amount to bob first.

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.

6 participants