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

Add MPTIssue to STIssue #5200

Merged
merged 13 commits into from
Dec 16, 2024
Merged

Add MPTIssue to STIssue #5200

merged 13 commits into from
Dec 16, 2024

Conversation

gregtatcam
Copy link
Collaborator

High Level Overview of Change

Replace Issue in STIssue with Asset.
In this change, STIssue with MPTIssue is unused anywhere except in MPT tests.
It is intended for use in Vault and in transactions with STIssue fields once
MPT is integrated into DEX.

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

Test Plan

Extend MPTTest to test that AMMClawback, MMDeposit, AMMWithdraw, AMMDelete, AMMVote transactions don't support MPTIssue in Asset and Asset2.

Copy link

codecov bot commented Nov 22, 2024

Codecov Report

Attention: Patch coverage is 97.67442% with 2 lines in your changes missing coverage. Please review.

Project coverage is 77.9%. Comparing base (ea1fffe) to head (166d638).
Report is 4 commits behind head on develop.

Files with missing lines Patch % Lines
src/xrpld/app/ledger/OrderBookDB.cpp 0.0% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           develop   #5200   +/-   ##
=======================================
  Coverage     77.9%   77.9%           
=======================================
  Files          783     783           
  Lines        66677   66705   +28     
  Branches      8108    8105    -3     
=======================================
+ Hits         51921   51959   +38     
+ Misses       14756   14746   -10     
Files with missing lines Coverage Δ
include/xrpl/protocol/Asset.h 94.7% <ø> (-0.3%) ⬇️
include/xrpl/protocol/Indexes.h 100.0% <ø> (ø)
include/xrpl/protocol/Issue.h 100.0% <ø> (ø)
include/xrpl/protocol/MPTIssue.h 100.0% <ø> (ø)
include/xrpl/protocol/SOTemplate.h 96.8% <ø> (ø)
include/xrpl/protocol/STAmount.h 95.1% <ø> (ø)
include/xrpl/protocol/STIssue.h 100.0% <100.0%> (+20.0%) ⬆️
include/xrpl/protocol/STXChainBridge.h 97.7% <100.0%> (ø)
src/libxrpl/protocol/Indexes.cpp 98.0% <100.0%> (+<0.1%) ⬆️
src/libxrpl/protocol/STIssue.cpp 100.0% <100.0%> (+5.7%) ⬆️
... and 10 more

... and 5 files with indirect coverage changes

Impacted file tree graph

@@ -157,6 +167,21 @@ operator!=(Asset const& lhs, Asset const& rhs)
return !(lhs == rhs);
}

constexpr bool
operator<(Asset const& lhs, Asset const& rhs)
Copy link
Collaborator

@Bronek Bronek Dec 9, 2024

Choose a reason for hiding this comment

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

Can you pls replace this with operator<=> ? It could look like this

    friend constexpr auto
    operator<=>(Asset const& lhs, Asset const& rhs)
    {
        return std::visit(
            [&]<typename TLhs, typename TRhs>(
                TLhs const& issLhs, TRhs const& issRhs) -> std::weak_ordering {
                if constexpr (std::is_same_v<TLhs, TRhs>)
                    return issLhs <=> issRhs;
                else
                    return lhs.issue_.index() <=> rhs.issue_.index();
            },
            lhs.issue_,
            rhs.issue_);
    }

Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be great if we could give std::strong_ordering to operator<=>(Issue const& lhs, Issue const& rhs) but I wouldn't want that change in this PR even if it is correct one (and I am not assuming that it is)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, will do. I actually added it in MPT-V2 (still a long way from release).

bool
STIssue::holds() const
{
return std::holds_alternative<TIss>(asset_.value());
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be return asset_.holds<TIss>();

return std::weak_ordering::greater;
else
return std::weak_ordering::less;
},
Copy link
Collaborator

@Bronek Bronek Dec 10, 2024

Choose a reason for hiding this comment

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

this is correct as long as we have exactly these two types i.e. Issue, MPTIssue inside issue_. As soon as that changes it will be no longer correct, meaning that this code is brittle. This is why I would prefer index comparison instead.

@@ -116,19 +144,19 @@ operator!=(STIssue const& lhs, STIssue const& rhs)
inline bool
operator<(STIssue const& lhs, STIssue const& rhs)
Copy link
Collaborator

@Bronek Bronek Dec 11, 2024

Choose a reason for hiding this comment

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

could we replace this with friend std::weak_ordering operator<=> as well ? Also, we should not need operator!= anymore

}

inline bool
operator<(STIssue const& lhs, Issue const& rhs)
operator<(STIssue const& lhs, Asset const& rhs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

also replace with friend std::weak_ordering operator<=>

@@ -89,7 +132,7 @@ STIssue::isEquivalent(const STBase& t) const
bool
STIssue::isDefault() const
{
return issue_ == xrpIssue();
return holds<Issue>() && asset_.get<Issue>() == xrpIssue();
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice

Co-authored-by: Bronek Kozicki <brok@incorrekt.com>
src/libxrpl/protocol/STIssue.cpp Outdated Show resolved Hide resolved
src/libxrpl/protocol/STIssue.cpp Show resolved Hide resolved
Copy link
Collaborator

@Bronek Bronek left a comment

Choose a reason for hiding this comment

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

All good, just please try to expand unit tests a little, as per https://app.codecov.io/gh/XRPLF/rippled/pull/5200

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

Choose a reason for hiding this comment

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

nice, thank you !

@Bronek Bronek self-requested a review December 12, 2024 11:41
@Bronek Bronek self-requested a review December 12, 2024 13:18
@gregtatcam gregtatcam added the Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required. label Dec 16, 2024
@ximinez ximinez merged commit 5cd72f2 into XRPLF:develop Dec 16, 2024
9 checks passed
@ximinez ximinez mentioned this pull request Dec 17, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants