go icon indicating copy to clipboard operation
go copied to clipboard

Inconsistent responses from /paths

Open bartekn opened this issue 3 years ago • 2 comments

What version are you using?

Horizon v2.19.0 vs Horizon v2.20.0.

What did you do?

Running a shiny new goreplay middleware comparing two responses between two versions and found a inconsistent responses in /paths/* which look like a rounding error. Unfortunately I wasn't logging response headers so there is no Latest-Ledger header but I'm adding request times below and also I was ignoring diffs if Latest-Ledger header value did not match between responses.

Note, that v2.20.0 was compiled with go1.19 and v2.19.0 used go1.17.9 so maybe there's an obscure bug somewhere...

strict-send example 1 (10-7 diff)

Request time: 2022-08-16T10:09:49.796744+00:00

Request path:

/paths/strict-send?source_asset_type=credit_alphanum4&source_amount=445.0000000&source_asset_code=yXLM&source_asset_issuer=GARDNV3Q7YGT4AKSDF25LT32YSCCW4EV22Y2TV3I2PU2MMXJTEDL5T55&destination_assets=native

v2.19.0 response:

{
  "_embedded": {
    "records": [
      {
        "source_asset_type": "credit_alphanum4",
        "source_asset_code": "yXLM",
        "source_asset_issuer": "GARDNV3Q7YGT4AKSDF25LT32YSCCW4EV22Y2TV3I2PU2MMXJTEDL5T55",
        "source_amount": "445.0000000",
        "destination_asset_type": "native",
        "destination_amount": "444.9377665",
        "path": []
      }
    ]
  }
}

v2.20.0 response:

{
  "_embedded": {
    "records": [
      {
        "source_asset_type": "credit_alphanum4",
        "source_asset_code": "yXLM",
        "source_asset_issuer": "GARDNV3Q7YGT4AKSDF25LT32YSCCW4EV22Y2TV3I2PU2MMXJTEDL5T55",
        "source_amount": "445.0000000",
        "destination_asset_type": "native",
        "destination_amount": "444.9377664",
        "path": []
      }
    ]
  }
}
strict-send example 2 (larger diff)

Request time: 2022-08-16T08:41:08.447697+00:00

Request path:

/paths/strict-send?source_asset_type=native&source_amount=64&destination_assets=StellarNFT%3AGALZZQF5JXHPHGI5A2ZW2EPL76DU4DWSYYGTPLOAMMEQEEECFSSRIOZJ

v2.19.0 response:

{
  "_embedded": {
    "records": [
      {
        "source_asset_type": "native",
        "source_amount": "64.0000000",
        "destination_asset_type": "credit_alphanum12",
        "destination_asset_code": "StellarNFT",
        "destination_asset_issuer": "GALZZQF5JXHPHGI5A2ZW2EPL76DU4DWSYYGTPLOAMMEQEEECFSSRIOZJ",
        "destination_amount": "4274288.2463335",
        "path": []
      }
    ]
  }
}

v2.20.0 response:

{
  "_embedded": {
    "records": [
      {
        "source_asset_type": "native",
        "source_amount": "64.0000000",
        "destination_asset_type": "credit_alphanum12",
        "destination_asset_code": "StellarNFT",
        "destination_asset_issuer": "GALZZQF5JXHPHGI5A2ZW2EPL76DU4DWSYYGTPLOAMMEQEEECFSSRIOZJ",
        "destination_amount": "4274288.2530120",
        "path": []
      }
    ]
  }
}
strict-receive example 1 (10-7 diff)

Request time: 2022-08-15T12:08:34.038Z

Request path:

/paths/strict-receive?source_assets=yXLM%3AGARDNV3Q7YGT4AKSDF25LT32YSCCW4EV22Y2TV3I2PU2MMXJTEDL5T55&destination_amount=300&destination_asset_type=native

v2.19.0 response:

{
  "_embedded": {
    "records": [
      {
        "source_asset_type": "credit_alphanum4",
        "source_asset_code": "yXLM",
        "source_asset_issuer": "GARDNV3Q7YGT4AKSDF25LT32YSCCW4EV22Y2TV3I2PU2MMXJTEDL5T55",
        "source_amount": "300.0053371",
        "destination_asset_type": "native",
        "destination_amount": "300.0000000",
        "path": []
      }
    ]
  }
}

v2.20.0 response:

{
  "_embedded": {
    "records": [
      {
        "source_asset_type": "credit_alphanum4",
        "source_asset_code": "yXLM",
        "source_asset_issuer": "GARDNV3Q7YGT4AKSDF25LT32YSCCW4EV22Y2TV3I2PU2MMXJTEDL5T55",
        "source_amount": "300.0053372",
        "destination_asset_type": "native",
        "destination_amount": "300.0000000",
        "path": []
      }
    ]
  }
}

bartekn avatar Aug 16 '22 11:08 bartekn

Hi,

Following discussion on Stellar Dev discord.

We could see that a /paths/strict-receive. give a high return rate between yXLM and XLM using BRK token as intermediary path. This path never complete using pathPaymentStrictReceive. We can see that the yXLM/BRK offer uses a very small price 1/110000000.

If you look at the SDEX, you can sell 11.2784198 yXLM for 1 240 626 178 BRK. You can sell 1 240 626 178 BRK for 0.6203476 XLM. (there is no pool with BRK)

I get that path-receive will try to fulfil other SDEX orders, but I tried to perform the path payment and it fails, I also tried to buy the BRK and sell it through path payment and the value does not match the path-receive.

These requests are from time 2022-08-23T14:15:00 UTC strict-receive.txt offers-selling.txt offer-buying.txt

vinamogit avatar Aug 23 '22 14:08 vinamogit

Hello,

Is this still open? In our application we want to give the user the possibility to swap assets. Unfortunately using horizon.stellar.org or our custom horizon returns for example for the request:

https://horizon.stellar.org/paths/strict-receive?destination_amount=1000&source_assets=yXLM:GARDNV3Q7YGT4AKSDF25LT32YSCCW4EV22Y2TV3I2PU2MMXJTEDL5T55&destination_asset_type=native

the following result were the first two paths are way from possible and can never be executed:

{
    "_embedded": {
        "records": [
            {
                "source_asset_type": "credit_alphanum4",
                "source_asset_code": "yXLM",
                "source_asset_issuer": "GARDNV3Q7YGT4AKSDF25LT32YSCCW4EV22Y2TV3I2PU2MMXJTEDL5T55",
                "source_amount": "18.9303058",
                "destination_asset_type": "native",
                "destination_amount": "1000.0000000",
                "path": [
                    {
                        "asset_type": "credit_alphanum4",
                        "asset_code": "XRP",
                        "asset_issuer": "GBXRPL45NPHCVMFFAYZVUVFFVKSIZ362ZXFP7I2ETNQ3QKZMFLPRDTD5"
                    },
                    {
                        "asset_type": "credit_alphanum4",
                        "asset_code": "UAB",
                        "asset_issuer": "GAPNJVEAEBVC237BBE7FUMZWQDNCLZJBK3EJOO22DC7P2PQUFLYHMVDB"
                    }
                ]
            },
            {
                "source_asset_type": "credit_alphanum4",
                "source_asset_code": "yXLM",
                "source_asset_issuer": "GARDNV3Q7YGT4AKSDF25LT32YSCCW4EV22Y2TV3I2PU2MMXJTEDL5T55",
                "source_amount": "599.5342391",
                "destination_asset_type": "native",
                "destination_amount": "1000.0000000",
                "path": [
                    {
                        "asset_type": "credit_alphanum4",
                        "asset_code": "SGB",
                        "asset_issuer": "GAME5YNKHIPRSMN2BI3HLS3OYD4NE6FQ2WKUUJPYYM6GU4MRDUBPHN6B"
                    }
                ]
            },
            {
                "source_asset_type": "credit_alphanum4",
                "source_asset_code": "yXLM",
                "source_asset_issuer": "GARDNV3Q7YGT4AKSDF25LT32YSCCW4EV22Y2TV3I2PU2MMXJTEDL5T55",
                "source_amount": "1000.1392095",
                "destination_asset_type": "native",
                "destination_amount": "1000.0000000",
                "path": []
            }
        ]
    }
}

dirtydozen1234 avatar Dec 23 '22 13:12 dirtydozen1234