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

move tfClawTwoAssets check to preflight #5201

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

yinyiqian1
Copy link
Collaborator

High Level Overview of Change

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)

src/xrpld/app/tx/detail/AMMClawback.cpp Show resolved Hide resolved
src/xrpld/app/tx/detail/AMMClawback.cpp Outdated Show resolved Hide resolved
src/xrpld/app/tx/detail/AMMClawback.cpp Show resolved Hide resolved
src/xrpld/app/tx/detail/AMMClawback.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@gregtatcam gregtatcam left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

codecov bot commented Nov 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.9%. Comparing base (f419c18) to head (b54d85d).
Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           develop   #5201   +/-   ##
=======================================
  Coverage     77.9%   77.9%           
=======================================
  Files          784     784           
  Lines        66680   66681    +1     
  Branches      8138    8140    +2     
=======================================
+ Hits         51942   51948    +6     
+ Misses       14738   14733    -5     
Files with missing lines Coverage Δ
src/xrpld/app/tx/detail/AMMClawback.cpp 100.0% <100.0%> (ø)

... and 4 files with indirect coverage changes

Impacted file tree graph

Copy link
Collaborator

@shawnxie999 shawnxie999 left a comment

Choose a reason for hiding this comment

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

Although changing to temMALFORMED works, I personally prefer using temINVALID_FLAG since it gives clearer message to the client on which part of the transaction might be wrong. However I don't see this as a blocker so you could decide at your discretion.

JLOG(ctx.j.trace())
<< "AMMClawback: tfClawTwoAssets can only be enabled when two "
"assets in the AMM pool are both issued by the issuer";
return temMALFORMED;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could maybe consider to return temINVALID_FLAG maybe?

Copy link
Collaborator Author

@yinyiqian1 yinyiqian1 Nov 22, 2024

Choose a reason for hiding this comment

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

It should be temMALFORMED. The flag is valid but the issuer is not the same.

I used temINVALID_FLAG in my first commit, @gregtatcam adviced to change from temINVALID_FLAG to temMALFORMED.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is what the requestor of this issue suggested. I'm fine with temINVALID_FLAG. How about temBAD_ISSUER? After all this is what it's pretty much is.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But if we change this to temBAD_ISSUER then I think we should change to the same error this check

if (asset.account != issuer)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have to disagree here. We really should get away from using what I've been calling "redundant" error codes. tem means malformed, so temMALFORMED means "malformed malformed". (And before anyone points it out, I know it's used in a ton of places in the existing code, but that doesn't mean it's correct here.) This is especially true when there are other good options that already exist.

  • temINVALID_FLAG has already been mentioned. It makes sense because you're not allowed to use that flag when the AMM has assets from two different issuers. One way to look at it is that tfClawTwoAssets is a flag defined for a very specific special case - when the AMM has two different assets from the same issuer and the issuer wants to get both of them, instead of the default behavior of just one. Thus, it is invalid to use the flag when the issuers are different.
    • The two assets are properties of the AMM. They're not going to change. If the AMM was created with assets from two different issuers, then there is nothing you can change about the transaction to work with that AMM and use tfClawTwoAssets.
  • temBAD_AMM_TOKENS could be considered, though the error message would need to be updated. The transaction can't be processed with the given flags because the tokens are not compatible with it.
  • temBAD_ISSUER is another option. The flag can not be used with the issuer of asset2.
  • temINVALID_ACCOUNT_ID is a stretch, but it could be considered invalid to specify that an asset2 account ID that is not the same as asset.

Of these four options, though, I think temINVALID_FLAG is the best, and is better than temMALFORMED because at least it communicates some information about the problem.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK. Since everyone agrees on temINVALID_FLAG, I changed the return error to 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.

@gregtatcam From my perspective, the flag can only be set if the issuer of the two assets are the same. So the flag would be considered as "invalid" if the issuers are different. I believe I did something similar in MPTokenIssuanceSet, where I returned temINVALID_FLAG if both flags are set. I don't believe there is a written rule that says we can only return this error code when the flag mask is invalid.

And we may not want to introduce additional error codes like temBAD_ISSUER since there is an upper limit to the total number of err codes.

Just my 2 cents

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good.

temBAD_ISSUER is an existing error.

@kennyzlei kennyzlei added this to the 2.3.0 (Nov 2024) milestone Nov 22, 2024
Copy link
Collaborator

@shawnxie999 shawnxie999 left a comment

Choose a reason for hiding this comment

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

Thanks for bearing the suggestions! :)

@yinyiqian1
Copy link
Collaborator Author

yinyiqian1 commented Nov 22, 2024

@ximinez Pipeline failed with some unit test errors, but it's transient because the error is RR:Env Env::close() failed: no response from server. Running the tests locally is fine. Do you want to rerun it?

Move tfClawTwoAssets check to preflight and return
error temINVALID_FLAG

---------

Co-authored-by: yinyiqian1 <yqian@ripple.com>
@intelliot intelliot merged commit b54d85d into XRPLF:develop Nov 25, 2024
7 of 8 checks passed
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