XRPLF / rippled

Decentralized cryptocurrency blockchain daemon implementing the XRP Ledger protocol in C++
https://xrpl.org
ISC License
4.52k stars 1.47k forks source link

path_find has confusing error dstAmountMalformed (Version: 1.9.4) #4369

Open mDuo13 opened 1 year ago

mDuo13 commented 1 year ago

Issue Description

The path_find command returns the error dstAmtMalformed when I add a send_max value to a request that otherwise works fine.

Steps to Reproduce

The following path_find returns a set of paths as expected:

{
    "id": "path_find_without_send_max",
    "command": "path_find",
    "subcommand": "create",
    "source_account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
    "destination_account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
    "destination_amount": {
        "value": "0.001",
        "currency": "USD",
        "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
    }
}

(WebSocket Tool Link))

But adding the a send_max field to it, which should be valid, causes the command to fail.

Request:

{
    "id": "path_find_with_send_max",
    "command": "path_find",
    "subcommand": "create",
    "source_account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
    "destination_account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
    "destination_amount": {
        "value": "0.001",
        "currency": "USD",
        "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
    },
    "send_max": "500000"
}

(WebSocket Tool Link)

Expected Result

The result should include only paths that spend up to the specified amount of whatever source currency was specified (in this case, XRP—which the successful path find result without send_max confirmed was a valid source currency!).

If there is an error, the error message should at least point at the correct field. It should not tell me that the destination_amount field is invalid if it's valid when I omit send_max.

Actual Result

The result is the following error:

{
  "error": "dstAmtMalformed",
  "error_code": 51,
  "error_message": "Destination amount/currency/issuer is malformed.",
  "id": "path_find_with_send_max",
  "request": {
    "command": "path_find",
    "destination_account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
    "destination_amount": {
      "currency": "USD",
      "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
      "value": "0.001"
    },
    "id": "path_find_with_send_max",
    "send_max": "500000",
    "source_account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
    "subcommand": "create"
  },
  "status": "error",
  "type": "response"
}

Environment

Confirmed using the WebSocket tool connected to s1 and xrplcluster.

ximinez commented 1 year ago

I believe the relevant check is at: https://github.com/XRPLF/rippled/blob/develop/src/ripple/app/paths/PathRequest.cpp#L177-L182

It is documented at https://xrpl.org/path_find.html#request-format in the descriptions for the destination_amount and send_max fields, though it isn't entirely clear that mixing them in this way is not allowed.

scjundev commented 1 year ago

Hello - I'm a beginner that would like to work on this issue. Could you assign it to me please? @ximinez @intelliot

intelliot commented 1 year ago

@scjundev please go ahead and work on this issue - and open a PR when ready.

There's no need to have the issue assigned to you, but I've gone ahead and done so anyway :)