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

PaychanAndEscrowForTokens: Token-Enabled Escrows and Payment Channels support (XLS-34d+) #4396

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

Conversation

dangell7
Copy link
Collaborator

@dangell7 dangell7 commented Jan 23, 2023

High Level Overview of Change

The proposed amendment to the XRPL protocol, XLS-34d: Token-Enabled Escrows and Payment Channels, would introduce changes to the ledger objects, transactions, and rpc methods to enable Escrows and PayChannels to use Trustline balances.

Context of Change

The proposed changes would include modifications to the following ledger objects;

RippleState
PayChannel
Escrow

The proposed changes would include modifications to the following transactions;

PaymentChannelCreate
PaymentChannelFund
PaymentChannelClaim
EscrowCreate

The proposed changes would include modifications to the following RPC methods;

account_lines
account_channels
account_objects
channel_authorize
channel_verify

Type of Change

  • New feature (non-breaking change which adds functionality)

Test Plan

PaychanAndEscrowForTokens unit tests are added for all core functionality features.

Future Tasks

@dangell7 dangell7 closed this Jan 23, 2023
@dangell7 dangell7 changed the title started amendment Introduce Token-Enabled Escrows and Payment Channels support (XLS-34d) Jan 23, 2023
@dangell7 dangell7 reopened this Jan 23, 2023
@intelliot intelliot changed the title Introduce Token-Enabled Escrows and Payment Channels support (XLS-34d) PaychanAndEscrowForTokens: Token-Enabled Escrows and Payment Channels support (XLS-34d) Jan 24, 2023
@dangell7 dangell7 force-pushed the icv2-squash branch 3 times, most recently from 809ca07 to 99b7700 Compare January 24, 2023 02:29
@RichardAH
Copy link
Collaborator

Wondering if @ximinez and/or @scottschurr might be able to do a review of this amendment

@ximinez
Copy link
Collaborator

ximinez commented Jan 24, 2023

Wondering if @ximinez and/or @scottschurr might be able to do a review of this amendment

I'd love to, but it'll be some time before I can get to it.

@dangell7 dangell7 force-pushed the icv2-squash branch 3 times, most recently from c6a49a4 to 02ee58b Compare January 24, 2023 22:36
@intelliot
Copy link
Collaborator

For context, what is motivating this feature addition? Who will use it?

@RichardAH
Copy link
Collaborator

RichardAH commented Jan 25, 2023

For context, what is motivating this feature addition? Who will use it?

There's a problem statement in the XLS here: XRPLF/XRPL-Standards#88 copied below for reference

The XRPL supports several types of on-ledger negotiable Instruments, namely: Escows, PayChannels and Checks. While each of these instruments is implemented as a first-class on-ledger object, only the Check object supports the use of Trustline balances. PayChannels and Escrows support only the native asset XRP. This limitation is a barrier to wider-spread use of these Instruments for reasons including:

  1. Regulatory compliance.
  2. Unwillingness to hold a counter-party-free asset (i.e. XRP).
  3. Volatility and exchange-rate risk.

XRPLF/XRPL-Standards#88

started amendment

escrow trustline code finished, untested not compiling

compiling

fix invariants for IOU escrows/paychans

prevent trustlines being spent below spendable balance

bug fixes for IOU escrows

preliminary paychan IOU support, compiling, not tested

bug fixes, testing

move all trustline lock and unlock logic to view, untested

more refactoring

compiling

debugging, bug fixes

templates

major refactor templates for trustTransfer and lock

fix logging to use journals

escrow bug fixes, escrow create/finish/cancel working

update claim serialization format

add sfLockCount and isAddable

add error message, address isAddable xrp edgecases

bug fixes

add lockedbalance and lockcount to account_lines rpc

update error handling & fix xrp issue

fix: format error

change check from xrp to native + error handle

add IC to tecUNFUNDED

add ic signClaim

fix amount bug

comment unused variable

tests

escrow tests

change error type

add paychan tests

enable test w/ features

fix account_channels resp

cont. paychan tests

escrow tests cont. + lint/clean

update rpc auth + verify

enable disallowXRP test (escrow)

paychan tests tests; rpc, disallow & abusetl

fix disalllow XRP bug

lint

fix disallow XRP tests

fix consequences test

fixup consequences test

update rpc call `value/currency/issuer`

fix paychan marker

cleanup and fix rpc call test

add gateway feature

clang-format

fix no-line bug

add pre test

fix test name

remove invariant test

clang-format

nit

clang-format

clang-format

add transfer rate

todo: fix this failing test

nit

nit

nit

update insuficient funds error

clang-format

clang-format

precision paychan test

bad currency guard

fix finalAmount + guard dest Issuer

fix final dest amount

finish tests

clang-format
@intelliot intelliot added this to the 2024 release milestone Sep 25, 2023
@ximinez
Copy link
Collaborator

ximinez commented Sep 28, 2023

I started an idea / pre-standard proposal over at XRPLF/XRPL-Standards#133

I know that what we have in this PR is a fully functional implementation, but I have serious qualms about it (outlined at the above link), that I would like to discuss before this PR moves forward.

This is not a veto. This solution might be the right way to go, but I'm not convinced of that.

@RichardAH
Copy link
Collaborator

Just a PSA: We're not actively promoting or defending XLS34 for merge into mainnet. We think it's the correct approach and it's what we're using on Xahau. If Ripple engineers want to (or don't want to) merge it into mainnet that's completely up to them.

@intelliot intelliot requested review from kennyzlei and removed request for ledhed2222 October 17, 2023 01:11
@outrum
Copy link

outrum commented Jan 4, 2024

Great work on XLS-34d! This functionality is essential for most XRPL tokens, in my view. Appreciating the complexities involved, I just wanted to express my support and eagerness to see this feature go live. Your efforts in pushing this forward are invaluable. Thanks for all the hard work!

@intelliot intelliot removed this from the 2.1.0 (Mar 2024) milestone Feb 2, 2024
@dangell7 dangell7 changed the title PaychanAndEscrowForTokens: Token-Enabled Escrows and Payment Channels support (XLS-34d) PaychanAndEscrowForTokens: Token-Enabled Escrows and Payment Channels support (XLS-34d+) Jul 21, 2024
@dangell7
Copy link
Collaborator Author

dangell7 commented Jul 21, 2024

This PR has been updated to reflect the concerns address by @ximinez

XRPLF/XRPL-Standards#133

  • trustAdjustLockedBalance -> transferToEntry: The balance is no longer "locked" on the trustline, but the sfAmount is "moved" from the source and stored on the entry object.
  • trustTransferLockedBalance -> transferFromEntry: The LockedBalance is no longer transferred from LockedBalance, but now the sfAmount on the entry object is "moved" from the entry object to the destination.
  • LockedBalance is removed
  • LockedCount is removed

Copy link

codecov bot commented Jul 21, 2024

Codecov Report

Attention: Patch coverage is 83.38509% with 107 lines in your changes missing coverage. Please review.

Project coverage is 71.4%. Comparing base (f3bcc65) to head (1806df0).
Report is 41 commits behind head on develop.

Files with missing lines Patch % Lines
src/xrpld/ledger/View.h 78.1% 37 Missing ⚠️
src/xrpld/app/tx/detail/PayChan.cpp 85.7% 27 Missing ⚠️
src/xrpld/app/tx/detail/Escrow.cpp 87.1% 16 Missing ⚠️
src/xrpld/ledger/detail/View.cpp 65.4% 9 Missing ⚠️
include/xrpl/protocol/STAmount.h 73.1% 7 Missing ⚠️
include/xrpl/protocol/PayChan.h 68.8% 5 Missing ⚠️
src/xrpld/net/detail/RPCCall.cpp 89.5% 4 Missing ⚠️
src/xrpld/rpc/handlers/PayChanClaim.cpp 93.8% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #4396     +/-   ##
=========================================
+ Coverage     71.3%   71.4%   +0.1%     
=========================================
  Files          796     796             
  Lines        67031   67582    +551     
  Branches     10885   10899     +14     
=========================================
+ Hits         47808   48281    +473     
- Misses       19223   19301     +78     
Files with missing lines Coverage Δ
include/xrpl/protocol/Feature.h 100.0% <ø> (ø)
include/xrpl/protocol/TER.h 100.0% <ø> (ø)
include/xrpl/protocol/UintTypes.h 100.0% <100.0%> (ø)
src/libxrpl/protocol/Feature.cpp 94.6% <ø> (ø)
src/libxrpl/protocol/Indexes.cpp 97.6% <100.0%> (ø)
src/libxrpl/protocol/LedgerFormats.cpp 100.0% <ø> (ø)
src/libxrpl/protocol/SField.cpp 77.5% <ø> (ø)
src/libxrpl/protocol/TER.cpp 100.0% <ø> (ø)
src/xrpld/app/tx/detail/InvariantCheck.cpp 87.7% <100.0%> (+0.7%) ⬆️
src/xrpld/rpc/handlers/AccountChannels.cpp 82.0% <100.0%> (+0.2%) ⬆️
... and 9 more

... and 10 files with indirect coverage changes

Impacted file tree graph

@ximinez
Copy link
Collaborator

ximinez commented Oct 3, 2024

This PR has been updated to reflect the concerns address by @ximinez

XRPLF/XRPL-Standards#133

* `trustAdjustLockedBalance` -> `transferToEntry`: The balance is no longer "locked" on the trustline, but the `sfAmount` is "moved" from the source and stored on the entry object.
* `trustTransferLockedBalance` -> `transferFromEntry`: The `LockedBalance` is no longer transferred from `LockedBalance`, but now the `sfAmount` on the entry object is "moved" from the entry object to the destination.
* `LockedBalance` is removed
* `LockedCount` is removed

I appreciate the work you've been doing here. Unfortunately, I haven't had a chance to review the code changes themselves, and probably won't for a while. I dug up the message I sent you a while back where I outlined my ideas for the steps needed to implement token support:

  1. A one-way account flag for issuers to opt in to the feature.
  2. Add an optional sfIssuerNode field to the Escrow and Paychan Objects - similar to the sfOwnerNode and sfDestinationNode.
  3. sfAmount is already the right type - the only restrictions on it being an IOU are in the logic, so change that logic.
  4. When an Escrow/PayChan is created, subtract the amount from the TrustLine, and set the amount in the new object - just like we do with XRP, except that it would probably need to account for rounding, Unlike a TrustLine, the amount will always be positive. There's no need to worry about high/low, because the abstraction is different (Owner, Destination, Issuer). Also, add the new object to the Issuer's directory.
  5. When the Escrow/PayChan is redeemed, move the funds the other way around. If the TrustLine doesn't exist, it can only be created if the recipient is the one the initiated the transaction.

From your description here, it looks like you've implemented items 3, 4, and maybe 5. That leaves items 1 and 2. Where are you on those?

Also, what do you think about splitting these changes into two PRs: One for Escrows and one for Payment Channels to possibly make code review easier?

@dangell7
Copy link
Collaborator Author

dangell7 commented Oct 3, 2024

This PR has been updated to reflect the concerns address by @ximinez
XRPLF/XRPL-Standards#133

* `trustAdjustLockedBalance` -> `transferToEntry`: The balance is no longer "locked" on the trustline, but the `sfAmount` is "moved" from the source and stored on the entry object.
* `trustTransferLockedBalance` -> `transferFromEntry`: The `LockedBalance` is no longer transferred from `LockedBalance`, but now the `sfAmount` on the entry object is "moved" from the entry object to the destination.
* `LockedBalance` is removed
* `LockedCount` is removed

I appreciate the work you've been doing here. Unfortunately, I haven't had a chance to review the code changes themselves, and probably won't for a while. I dug up the message I sent you a while back where I outlined my ideas for the steps needed to implement token support:

  1. A one-way account flag for issuers to opt in to the feature.
  2. Add an optional sfIssuerNode field to the Escrow and Paychan Objects - similar to the sfOwnerNode and sfDestinationNode.
  3. sfAmount is already the right type - the only restrictions on it being an IOU are in the logic, so change that logic.
  4. When an Escrow/PayChan is created, subtract the amount from the TrustLine, and set the amount in the new object - just like we do with XRP, except that it would probably need to account for rounding, Unlike a TrustLine, the amount will always be positive. There's no need to worry about high/low, because the abstraction is different (Owner, Destination, Issuer). Also, add the new object to the Issuer's directory.
  5. When the Escrow/PayChan is redeemed, move the funds the other way around. If the TrustLine doesn't exist, it can only be created if the recipient is the one the initiated the transaction.

From your description here, it looks like you've implemented items 3, 4, and maybe 5. That leaves items 1 and 2. Where are you on those?

Also, what do you think about splitting these changes into two PRs: One for Escrows and one for Payment Channels to possibly make code review easier?

You're right I did skip 1 & 2 but that shouldn't be too hard to implement. Will add that now.

I can split them into 2 PR's no problem. I will go ahead and do that now as well. Thanks for taking a look.

@dangell7 dangell7 closed this Oct 3, 2024
@dangell7 dangell7 reopened this Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 📋 Backlog
Development

Successfully merging this pull request may close these issues.

10 participants