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 DeliverMax (alias for Amount) in Payment transactions #4733

Merged
merged 26 commits into from
Oct 23, 2023

Conversation

Bronek
Copy link
Collaborator

@Bronek Bronek commented Sep 28, 2023

Add DeliverMax alias to Amount, remove Amount from API ver 2.

Context of Change

Resolve #3484

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)
  • Tests (You added tests for code that already exists, or your new feature included in this PR)
  • Documentation Updates
  • Release

@Bronek Bronek changed the title Feature/partial payment fieldname Add DeliverMax alias to Amount, remove Amount from API ver 2. Sep 28, 2023
@Bronek Bronek changed the title Add DeliverMax alias to Amount, remove Amount from API ver 2. WIP: Add DeliverMax alias to Amount, remove Amount from API ver 2. Sep 28, 2023
@Bronek Bronek changed the title WIP: Add DeliverMax alias to Amount, remove Amount from API ver 2. [DRAFT] Add DeliverMax alias to Amount, remove Amount from API ver 2. Sep 28, 2023
@Bronek Bronek force-pushed the feature/partial-payment-fieldname branch 2 times, most recently from b7f9bc1 to f7355e3 Compare October 2, 2023 12:04
@Bronek Bronek force-pushed the feature/partial-payment-fieldname branch 2 times, most recently from 836dd87 to 1cbc61e Compare October 2, 2023 18:51
@Bronek Bronek force-pushed the feature/partial-payment-fieldname branch from 1cbc61e to 4b3c895 Compare October 3, 2023 19:37
@Bronek
Copy link
Collaborator Author

Bronek commented Oct 4, 2023

Scope of the change.

I want to:

  1. add handling of DeliverMax as an alias to Amount for all API operations taking tx_json on input. The operations I've identified are:
  • sign (obsolete, but could be used)
  • submit (in sign-and-submit mode, see above)
  • submit_multisigned
  • sign_for
  1. add DeliverMax (and optionally remove Amount for API ver. 2) on output of all API operations that may publish transactions. The operations I've identified are:
  • ledger
  • tx
  • tx_history
  • account_tx
  • transaction_entry
  1. add DeliverMax to published transactions stream https://xrpl.org/subscribe.html#transaction-streams (and optionally remove Amount for API ver. 2) for API operation
  • subscribe
  1. For clarity, the following API operations do not publish transactions, hence are unaffected:
  • ledger_entry (only show objects stored on the ledger https://xrpl.org/ledger_entry.html , not transactions)
  • ledger_data (similar to ledger_entry)
  • account_objects (similar to ledger_data)
  • ledger_request (only shows ledger info/state)
  • ledger_closed (only shows ledger info/state)
  • ledger_current (only shows ledger info/state)
  • path_find (only publishes paths, not transactions)
  1. In all cases where API takes tx_json on input, or shows it on output, the relevant transaction type where the change applies is:
  • payment (and that's all)

@Bronek
Copy link
Collaborator Author

Bronek commented Oct 5, 2023

I realised the old version of this draft was updating meta json element (which is where delivered_amount is), but it should instead update transaction json element (not necessarily under this name - we are unfortunately inconsistent), because that's where Amount is. New version of this PR fixes this.

@Bronek Bronek force-pushed the feature/partial-payment-fieldname branch from c4f997a to 4d9a594 Compare October 5, 2023 16:05
@Bronek
Copy link
Collaborator Author

Bronek commented Oct 5, 2023

Also found that I missed proposed transactions and proposed account transaction, this is fixed now. I am considering some refactoring of my changes in NetworkOPs.cpp to improve cohesion and reduce coupling - i.e. the way I added virtually identical non-trivial block of code in several functions, while missing proposed transactions. So that will be probably next commit and then of course badly needed unit tests.

@Bronek Bronek force-pushed the feature/partial-payment-fieldname branch 7 times, most recently from 1e0a5f3 to 17e39bb Compare October 6, 2023 16:33
@Bronek
Copy link
Collaborator Author

Bronek commented Oct 6, 2023

Note, as seen in Add test for TransactionSign.cpp commit, using DeliverMax instead of Amount does not affect the transaction signature: both tests "Invalid Amount in submit_multisigned Payment." and "Invalid DeliverMax in submit_multisigned Payment." have the same signature. Also the error in the latter test refers to Amount and not DeliverMax field. This is consequence of the fact that DeliverMax is an alias to Amount.

@Bronek Bronek force-pushed the feature/partial-payment-fieldname branch from a738132 to cf0798a Compare October 20, 2023 21:07
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.

Just a couple of minor things.

BTW, please stop force pushing. I'd rather have 20 tweak commits than have to figure out what changed since the last time I looked.

src/ripple/app/misc/NetworkOPs.cpp Outdated Show resolved Hide resolved
src/ripple/app/misc/DeliverMax.h Outdated Show resolved Hide resolved
src/ripple/json/MultivarJson.h Outdated Show resolved Hide resolved
@intelliot intelliot assigned Bronek and unassigned ximinez and arihantkothari Oct 23, 2023
@Bronek Bronek force-pushed the feature/partial-payment-fieldname branch from 1cb93ec to 5e7fa7c Compare October 23, 2023 14:38
@Bronek
Copy link
Collaborator Author

Bronek commented Oct 23, 2023

@ximinez thanks for very generous input - I addressed all your comments. I added one more test to 'MultivarJson_test.cpp` which required an extra line for levelization, but I think that should be OK.

static_assert(
apiVersionSelector(RPC::apiBetaVersion)() + 1 //
== MultiApiJson::size);
for (unsigned apiVersion = RPC::apiMinimumSupportedVersion,
Copy link
Collaborator

@arihantkothari arihantkothari Oct 23, 2023

Choose a reason for hiding this comment

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

For the intentions of looping over the apiVersions from minimumSupported to beta. I actually made a helper function long time back - may/ may not be useful :) [Now I feel, that the helper can be improved and is too strict. But I'll leave as it is.]
#4611

Copy link
Collaborator

Choose a reason for hiding this comment

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

That function is cool, but as written, it's only for tests.

Copy link
Collaborator

@arihantkothari arihantkothari Oct 23, 2023

Choose a reason for hiding this comment

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

oh shoot, my bad - sorry about that. I did not notice this was not for tests 😆

Copy link
Collaborator

Choose a reason for hiding this comment

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

No worries

Bronek added a commit to Bronek/rippled that referenced this pull request Oct 23, 2023
@@ -135,6 +135,7 @@ test.csf > ripple.protocol
test.csf > test.jtx
test.json > ripple.beast
test.json > ripple.json
test.json > ripple.rpc
Copy link
Collaborator

Choose a reason for hiding this comment

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

Adding lines to the ordering file is great, as long as it follows the existing rules (which this does). It would be a problem if the line was added to loops.txt, or if the dependency didn't "fit" the existing order.

@intelliot
Copy link
Collaborator

Suggested commit message:

APIv2(DeliverMax): add alias for Amount in Payment transactions (#4733)

Using the "Amount" field in Payment transactions can cause incorrect
interpretation. There continue to be problems from the use of this
field. "Amount" is rarely the correct field to use; instead,
"delivered_amount" (or "DeliveredAmount") should be used.

Rename the "Amount" field to "DeliverMax", a less misleading name. With
api_version: 2, remove the "Amount" field from Payment transactions.

- Input: "DeliverMax" in `tx_json` is an alias for "Amount"
  - sign
  - submit (in sign-and-submit mode)
  - submit_multisigned
  - sign_for
- Output: Add "DeliverMax" where transactions are provided by the API
  - ledger
  - tx
  - tx_history
  - account_tx
  - transaction_entry
  - subscribe (transactions stream)
- Output: Remove "Amount" from API version 2

Fix #3484

Fix #3902

@intelliot intelliot changed the title Add DeliverMax alias to Amount, remove Amount from API ver 2. APIv2(DeliverMax): add alias for Amount in Payment transactions Oct 23, 2023
@Bronek
Copy link
Collaborator Author

Bronek commented Oct 23, 2023

This is ready for merge

@intelliot intelliot merged commit 3972683 into XRPLF:develop Oct 23, 2023
16 checks passed
@intelliot intelliot mentioned this pull request Oct 23, 2023
1 task
@intelliot intelliot changed the title APIv2(DeliverMax): add alias for Amount in Payment transactions Add DeliverMax (alias for Amount) in Payment transactions Oct 24, 2023
@zgrguric
Copy link

Is "Amount" removed from output on Payment transactions?

@ximinez
Copy link
Collaborator

ximinez commented Jan 10, 2024

Is "Amount" removed from output on Payment transactions?

Only in API v2.

sophiax851 pushed a commit to sophiax851/rippled that referenced this pull request Jun 12, 2024
…F#4733)

Using the "Amount" field in Payment transactions can cause incorrect
interpretation. There continue to be problems from the use of this
field. "Amount" is rarely the correct field to use; instead,
"delivered_amount" (or "DeliveredAmount") should be used.

Rename the "Amount" field to "DeliverMax", a less misleading name. With
api_version: 2, remove the "Amount" field from Payment transactions.

- Input: "DeliverMax" in `tx_json` is an alias for "Amount"
  - sign
  - submit (in sign-and-submit mode)
  - submit_multisigned
  - sign_for
- Output: Add "DeliverMax" where transactions are provided by the API
  - ledger
  - tx
  - tx_history
  - account_tx
  - transaction_entry
  - subscribe (transactions stream)
- Output: Remove "Amount" from API version 2

Fix XRPLF#3484

Fix XRPLF#3902
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Rename Amount Field to DeliverMax (to prevent incorrect handling of Partial Payments)
7 participants