CardanoSolutions / kupo

🐹 Fast, lightweight & configurable chain-index for Cardano.
https://cardanosolutions.github.io/kupo/
Mozilla Public License 2.0
119 stars 29 forks source link

Incorrect output_index stored for return collaterals #101

Closed jy14898 closed 1 year ago

jy14898 commented 1 year ago

What Git revision / release tag are you using?

v2.2.0

Describe what the problem is?

Submitting a transaction which will fail phase 2 validation, with the is_valid field of the transaction set to false to allow submission, results in ~the outputs of such a transaction being indexed~ the collateral return outputs of such a transaction being incorrectly indexed in the matches endpoint. This results in unspendable utxos being listed in wallets, for example

What should be the expected behavior?

When is_valid is set to false, outputs should not be listed. I have not checked, but additionally we should verify the behaviour of collateral, ie that it should be marked as spent and collateral return outputs be indexed.

If applicable, what are the logs from the server around the occurence of the problem?

KtorZ commented 1 year ago

Hi, do you have an example of such a scenario? Are you sure that the indexed outputs do not correspond to a collateral change output resulting from the collateral consumption?

jy14898 commented 1 year ago

Hmm, I'll check. It's possible it could be collateral return, but I was having trouble spending these outputs via ogmios.

jy14898 commented 1 year ago

I think it is a collateral return, but blockfrost vs kupo return different tx and output indexes:

https://cardano-preview.blockfrost.io/api/v0/addresses/addr_test1vr69f80dfrmrfp77xg55zqzwfc4lf5pk65fxtnue2m3ffrspkhx6a/utxos
[
  {
    "address": "addr_test1vr69f80dfrmrfp77xg55zqzwfc4lf5pk65fxtnue2m3ffrspkhx6a",
    "tx_hash": "a9bd09c6191167dcc4362b23264684f2bd596cbd2f196af5aea1715e8badb7af",
    "tx_index": 1,
    "output_index": 1,
    "amount": [
      {
        "unit": "lovelace",
        "quantity": "5000000"
      }
    ],
    "block": "0f868b414cb5549fd0fcb41c3ab616c33f9f47ae51ce8500c925a2561c699029",
    "data_hash": null,
    "inline_datum": null,
    "reference_script_hash": null
  }
]
https://KUPO_INSTANCE/matches/addr_test1vr69f80dfrmrfp77xg55zqzwfc4lf5pk65fxtnue2m3ffrspkhx6a?unspent
[
  {
    "transaction_index": 3,
    "transaction_id": "a9bd09c6191167dcc4362b23264684f2bd596cbd2f196af5aea1715e8badb7af",
    "output_index": 0,
    "address": "addr_test1vr69f80dfrmrfp77xg55zqzwfc4lf5pk65fxtnue2m3ffrspkhx6a",
    "value": {
      "coins": 5000000,
      "assets": {}
    },
    "datum_hash": null,
    "script_hash": null,
    "created_at": {
      "slot_no": 6356319,
      "header_hash": "0f868b414cb5549fd0fcb41c3ab616c33f9f47ae51ce8500c925a2561c699029"
    },
    "spent_at": null
  }
]
jy14898 commented 1 year ago

I think blockfrost's tx_index is wrong here, so maybe ignore that.

jy14898 commented 1 year ago

Also to confirm kupos output index is wrong:

$ cardano-cli query utxo --address addr_test1vr69f80dfrmrfp77xg55zqzwfc4lf5pk65fxtnue2m3ffrspkhx6a --testnet-magic 2
                           TxHash                                 TxIx        Amount
--------------------------------------------------------------------------------------
a9bd09c6191167dcc4362b23264684f2bd596cbd2f196af5aea1715e8badb7af     1        5000000 lovelace + TxOutDatumNone
KtorZ commented 1 year ago

Ho, I see. The index is off because collateral return aren't indexes from zero, but as if they were a continuation of the existing output set.

Thanks for catching that, will fix asap.