storage: fix get_txid for pre-RCT outputs#504
Merged
Boog900 merged 10 commits intoCuprate:mainfrom Jun 7, 2025
Merged
Conversation
hinto-janai
commented
Jun 6, 2025
storage/blockchain/src/ops/output.rs
Outdated
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()) |
Member
Author
There was a problem hiding this comment.
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"
}
]
}
Member
There was a problem hiding this comment.
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)
Member
Author
There was a problem hiding this comment.
Ahh I see how we calculate the index now, my bad
storage/blockchain/src/ops/output.rs
Outdated
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()) |
Member
Author
There was a problem hiding this comment.
@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"
}
]
}
Member
There was a problem hiding this comment.
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
Member
Author
There was a problem hiding this comment.
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.
Boog900
approved these changes
Jun 7, 2025
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
/get_outswas returning the wrong hash, it is fixed by this, including when it needs to return a miner tx hash.