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

XLS-85d: Token-Enabled Escrows #5185

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

Conversation

dangell7
Copy link
Collaborator

@dangell7 dangell7 commented Nov 7, 2024

High Level Overview of Change

XLS: XRPLF/XRPL-Standards#248

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)

@dangell7 dangell7 marked this pull request as ready for review December 2, 2024 20:28
{
testMPTEnablement(features);
// testIOULockup(features);
// testIOURippleState(features);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why these are disabled?

XRPAmount A = (amt1.signum() == -1 ? -(amt1.xrp()) : amt1.xrp());
XRPAmount B = (amt2.signum() == -1 ? -(amt2.xrp()) : amt2.xrp());

XRPAmount finalAmt = A + B;
Copy link
Collaborator

@oleks-rip oleks-rip Feb 24, 2025

Choose a reason for hiding this comment

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

As underlying type of the XRPAmount is signed, this is incorrect (undefined behavior in case of the overflow).
Consider something like

 if( amt1.signum() != amt2.signum()) return true; 
 std::int64_t const A = amt1.xrp().drops();
 std::int64_t const B = (std::int64_t)(((std::uint64_t)A) + ((std::uint64_t)amt2.xrp().drops()));
 return  ((A >= 0) && (B >= A)) || ( (A < 0) && (B <= A)));

A.setIssue(noIssue());
B.setIssue(noIssue());

STAmount lhs = divide((A - B) + B, A, noIssue()) - one;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The logic behind addition / division for STAmount is a bit complicated to guess if this will work. Please add tests for isAddable function to the STAmount_test.cpp.

@dangell7
Copy link
Collaborator Author

@oleks-rip Thank you for the initial review. Right now I'm just focusing on the actual core implementation and how it effects MPT and IOU. I will address the nit changes you requested once the core implementation is done.

auto const balance = STAmount((*sle)[sfBalance]).xrp();
auto const reserve =
ctx_.view().fees().accountReserve((*sle)[sfOwnerCount] + 1);
STAmount const amount{ctx_.tx[sfAmount]};
Copy link
Collaborator

Choose a reason for hiding this comment

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

doApply function has become too big. Please consider to move out some part of it to helper functions.

TER
EscrowFinish::doApply()
{
PaymentSandbox psb(&ctx_.view());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why sandbox introduced here? Is it for rippleCredit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes

Copy link
Collaborator

@oleks-rip oleks-rip Feb 26, 2025

Choose a reason for hiding this comment

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

EscrowCreate and EscrowCancel use rippleCredit too, should they be updated with sandbox too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes we should do that actually

auto const k = keylet::escrow(ctx_.tx[sfOwner], ctx_.tx[sfOfferSequence]);
auto const slep = ctx_.view().peek(k);
auto const slep = psb.peek(k);
Copy link
Collaborator

Choose a reason for hiding this comment

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

doApply function has become too big. Please consider to move out some part of it to helper functions.

Copy link

codecov bot commented Feb 26, 2025

Codecov Report

Attention: Patch coverage is 81.81818% with 80 lines in your changes missing coverage. Please review.

Project coverage is 78.1%. Comparing base (2216e5a) to head (d961dea).

Files with missing lines Patch % Lines
src/xrpld/app/tx/detail/Escrow.cpp 83.2% 62 Missing ⚠️
src/xrpld/ledger/detail/View.cpp 65.5% 10 Missing ⚠️
include/xrpl/protocol/STAmount.h 69.6% 7 Missing ⚠️
src/xrpld/app/tx/detail/SetAccount.cpp 80.0% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop   #5185    +/-   ##
========================================
  Coverage     78.1%   78.1%            
========================================
  Files          790     790            
  Lines        67908   68310   +402     
  Branches      8230    8237     +7     
========================================
+ Hits         53034   53361   +327     
- Misses       14874   14949    +75     
Files with missing lines Coverage Δ
include/xrpl/protocol/Feature.h 100.0% <ø> (ø)
include/xrpl/protocol/TER.h 100.0% <ø> (ø)
include/xrpl/protocol/detail/ledger_entries.macro 100.0% <ø> (ø)
include/xrpl/protocol/detail/transactions.macro 100.0% <ø> (ø)
src/libxrpl/protocol/TER.cpp 100.0% <ø> (ø)
src/xrpld/app/tx/detail/Escrow.h 100.0% <ø> (ø)
src/xrpld/app/tx/detail/InvariantCheck.cpp 89.2% <100.0%> (+0.4%) ⬆️
src/xrpld/ledger/View.h 100.0% <ø> (ø)
src/xrpld/app/tx/detail/SetAccount.cpp 97.9% <80.0%> (-0.3%) ⬇️
include/xrpl/protocol/STAmount.h 91.1% <69.6%> (-4.0%) ⬇️
... and 2 more

... and 5 files 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

auto const reserve =
ctx_.view().fees().accountReserve((*sle)[sfOwnerCount] + 1);
AccountID const issuer = amount.getIssuer();

if (balance < reserve)
if (mSourceBalance < reserve)
Copy link
Collaborator

Choose a reason for hiding this comment

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

mSourceBalance differs from mPriorBalance by Fee. Direct replacement for *sle)[sfBalance]).xrp() will be mPriorBalance . Are you sure mSourceBalance is good here?

std::array<TestAccountData, 8> gwSrcTests = {{
// src > dst && src > issuer && dst no trustline
{Account("gw0"), Account{"alice2"}, false, true},
// // src < dst && src < issuer && dst no trustline
Copy link
Collaborator

Choose a reason for hiding this comment

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

// duplicates

}

std::array<TestAccountData, 4> gwDstTests = {{
// // // // src > dst && src > issuer && dst has trustline
Copy link
Collaborator

Choose a reason for hiding this comment

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

// duplicates

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.

2 participants