-
Notifications
You must be signed in to change notification settings - Fork 49
storage: fix get_txid for pre-RCT outputs
#504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
storage/blockchain/src/ops/output.rs
Outdated
| 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()) |
There was a problem hiding this comment.
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"
}
]
}There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
storage/blockchain/src/ops/output.rs
Outdated
| 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()) |
There was a problem hiding this comment.
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"
}
]
}There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
* apply * apply * apply * apply * revert * apply * reduce diffs * apply * apply * fix
* apply * apply * apply * apply * revert * apply * reduce diffs * apply * apply * fix
What
/get_outswas returning the wrong hash, it is fixed by this, including when it needs to return a miner tx hash.