Skip to content

Conversation

@hinto-janai
Copy link
Member

@hinto-janai hinto-janai commented Jun 6, 2025

What

/get_outs was returning the wrong hash, it is fixed by this, including when it needs to return a miner tx hash.

@hinto-janai hinto-janai added the C-fix Category: PRs that fixes code, or issues documenting a fix. label Jun 6, 2025
@github-actions github-actions bot added the A-storage Area: Related to storage. label Jun 6, 2025
Comment on lines 177 to 175
let height = u32_to_usize(output.height);
let tx_idx = u64_to_usize(output.tx_idx);
let txid = if let Some(hash) = table_block_txs_hashes.get(&height)?.get(tx_idx) {
*hash
} else {
let miner_tx_id = table_block_infos.get(&height)?.mining_tx_index;
let tx_blob = table_tx_blobs.get(&miner_tx_id)?;
Transaction::read(&mut tx_blob.0.as_slice())?.hash()
};
Some(txid)
Some(get_tx_from_id(&output.tx_idx, table_tx_blobs)?.hash())
Copy link
Member Author

Choose a reason for hiding this comment

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

miner tx

curl http://127.0.0.1:18081/get_outs \
    -H 'Content-Type: application/json' \
    -d '{"outputs":[{"amount":80000000000,"index":60385}],"get_txid":true}'
// monerod
{
  "credits": 0,
  "outs": [
    {
      "height": 91193,
      "key": "5370b2523a1c39775a75b5ca73492299979f8285d3f2fd4d3ab7288453714054",
      "mask": "5accfd162279a51c8b3bd5d3679e918967a264ea063d37dff5e3457ec307d457",
      "txid": "288f39a2660e332414625506d7be064ee0b40bcde2c61dc2433d3f838b224a99",
      "unlocked": true
    }
  ],
  "status": "OK",
  "top_hash": "",
  "untrusted": false
}
// cuprated
{
  "status": "OK",
  "untrusted": false,
  "outs": [
    {
      "key": "5370b2523a1c39775a75b5ca73492299979f8285d3f2fd4d3ab7288453714054",
      "mask": "5accfd162279a51c8b3bd5d3679e918967a264ea063d37dff5e3457ec307d457",
      "unlocked": true,
      "height": 91193,
      "txid": "288f39a2660e332414625506d7be064ee0b40bcde2c61dc2433d3f838b224a99"
    }
  ]
}

non-miner tx

curl http://127.0.0.1:18081/get_outs \
    -H 'Content-Type: application/json' \
    -d '{"outputs":[{"amount":20000000000,"index":168569}],"get_txid":true}'
// monerod
{
  "credits": 0,
  "outs": [
    {
      "height": 91193,
      "key": "2313a3c085da9a75db205d85309bb5129a33c225e03bfade60558117081620f9",
      "mask": "09baed9a3c44b22285a0aea4148ca7de9bea963cf69623b683445c0a10a58677",
      "txid": "d42bf55232707c8c82866e5f0fbb5200a225fd9af6d91113a4f4071fe90dde93",
      "unlocked": true
    }
  ],
  "status": "OK",
  "top_hash": "",
  "untrusted": false
}
// cuprated
{
  "status": "OK",
  "untrusted": false,
  "outs": [
    {
      "key": "2313a3c085da9a75db205d85309bb5129a33c225e03bfade60558117081620f9",
      "mask": "09baed9a3c44b22285a0aea4148ca7de9bea963cf69623b683445c0a10a58677",
      "unlocked": true,
      "height": 91193,
      "txid": "d42bf55232707c8c82866e5f0fbb5200a225fd9af6d91113a4f4071fe90dde93"
    }
  ]
}

Copy link
Member

Choose a reason for hiding this comment

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

I think you should just be able to copy the section from the RCT function to fix this instead of needing to has every tx:

       let height = u32_to_usize(output.height);

        let miner_tx_id = table_block_infos.get(&height)?.mining_tx_index;

        let txid = if miner_tx_id == output.tx_idx {
            let tx_blob = table_tx_blobs.get(&miner_tx_id)?;
            Transaction::read(&mut tx_blob.0.as_slice())?.hash()
        } else {
            let idx = u64_to_usize(output.tx_idx - miner_tx_id - 1);
            table_block_txs_hashes.get(&height)?[idx]
        };

        Some(txid)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh I see how we calculate the index now, my bad

Comment on lines 232 to 219
let height = u32_to_usize(rct_output.height);

let miner_tx_id = table_block_infos.get(&height)?.mining_tx_index;

let txid = if miner_tx_id == rct_output.tx_idx {
let tx_blob = table_tx_blobs.get(&miner_tx_id)?;
Transaction::read(&mut tx_blob.0.as_slice())?.hash()
} else {
let idx = u64_to_usize(rct_output.tx_idx - miner_tx_id - 1);
table_block_txs_hashes.get(&height)?[idx]
};

Some(txid)
Some(get_tx_from_id(&rct_output.tx_idx, table_tx_blobs)?.hash())
Copy link
Member Author

Choose a reason for hiding this comment

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

@Boog900 #355 (comment) I think RctOutput::tx_idx is good to use here?

rct miner tx

curl http://127.0.0.1:18081/get_outs \
    -H 'Content-Type: application/json' \
    -d '{"outputs":[{"amount":0,"index":58544}],"get_txid":true}'
// monerod
{
  "credits": 0,
  "outs": [
    {
      "height": 1230000,
      "key": "b2eae36de54cc2617cfca966fa565b5910ed13a4aa78875b61ce5e2b9cdacf71",
      "mask": "8b1311e49f6ff95d03bcf090a090a827ea33339ca646d6fa755925429cef5af1",
      "txid": "d2a8017920990f4c4d92f33468dcae638d4272f0a38eef34caf2a85471b77336",
      "unlocked": true
    }
  ],
  "status": "OK",
  "top_hash": "",
  "untrusted": false
}
// cuprated
{
  "status": "OK",
  "untrusted": false,
  "outs": [
    {
      "key": "b2eae36de54cc2617cfca966fa565b5910ed13a4aa78875b61ce5e2b9cdacf71",
      "mask": "8b1311e49f6ff95d03bcf090a090a827ea33339ca646d6fa755925429cef5af1",
      "unlocked": true,
      "height": 1230000,
      "txid": "d2a8017920990f4c4d92f33468dcae638d4272f0a38eef34caf2a85471b77336"
    }
  ]
}

rct non-miner tx

curl http://127.0.0.1:18081/get_outs \
    -H 'Content-Type: application/json' \
    -d '{"outputs":[{"amount":0,"index":58551}],"get_txid":true}'
// monerod
{
  "credits": 0,
  "outs": [
    {
      "height": 1230000,
      "key": "ce61f6c346b26fc5a47beda32ce3bff6bffc28d4fef56cf4eed2967a250858e3",
      "mask": "e80e86c9d45025b0cfe41a8df7dbb7467e13d4db0d2813ca9a5a909a5cec2596",
      "txid": "2c3976ac03ef2b12fd6285a00e2e064ab877ac0302fc5051002c9832f84bb5bb",
      "unlocked": true
    }
  ],
  "status": "OK",
  "top_hash": "",
  "untrusted": false
}
// cuprated
{
  "status": "OK",
  "untrusted": false,
  "outs": [
    {
      "key": "ce61f6c346b26fc5a47beda32ce3bff6bffc28d4fef56cf4eed2967a250858e3",
      "mask": "e80e86c9d45025b0cfe41a8df7dbb7467e13d4db0d2813ca9a5a909a5cec2596",
      "unlocked": true,
      "height": 1230000,
      "txid": "2c3976ac03ef2b12fd6285a00e2e064ab877ac0302fc5051002c9832f84bb5bb"
    }
  ]
}

Copy link
Member

@Boog900 Boog900 Jun 6, 2025

Choose a reason for hiding this comment

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

Why did this function have to change - I don't like needing to hash the tx for every output where the tx_id is got

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah my bad, not entirely intended.

Btw random access perf seemed on-par with monerod, it's 1.2x~1.5 faster without tx hash each time.

@hinto-janai hinto-janai marked this pull request as ready for review June 6, 2025 01:49
@hinto-janai hinto-janai requested a review from Boog900 June 6, 2025 01:50
@Boog900 Boog900 merged commit e67b9f5 into Cuprate:main Jun 7, 2025
17 checks passed
@hinto-janai hinto-janai deleted the fix-get-txid branch June 9, 2025 22:03
SyntheticBird45 pushed a commit that referenced this pull request Jun 10, 2025
* apply

* apply

* apply

* apply

* revert

* apply

* reduce diffs

* apply

* apply

* fix
SyntheticBird45 pushed a commit that referenced this pull request Jun 10, 2025
* apply

* apply

* apply

* apply

* revert

* apply

* reduce diffs

* apply

* apply

* fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-storage Area: Related to storage. C-fix Category: PRs that fixes code, or issues documenting a fix.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants