Skip to content

Commit e67b9f5

Browse files
authored
storage: fix get_txid for pre-RCT outputs (#504)
* apply * apply * apply * apply * revert * apply * reduce diffs * apply * apply * fix
1 parent d4caf95 commit e67b9f5

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

storage/blockchain/src/ops/output.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22
33
//---------------------------------------------------------------------------------------------------- Import
44
use curve25519_dalek::edwards::CompressedEdwardsY;
5-
use monero_serai::transaction::{Timelock, Transaction};
5+
use monero_serai::transaction::Timelock;
66

77
use cuprate_database::{
88
DbResult, RuntimeError, {DatabaseRo, DatabaseRw},
99
};
10-
use cuprate_helper::{cast::u32_to_usize, crypto::compute_zero_commitment};
11-
use cuprate_helper::{cast::u64_to_usize, map::u64_to_timelock};
10+
use cuprate_helper::{
11+
cast::{u32_to_usize, u64_to_usize},
12+
crypto::compute_zero_commitment,
13+
map::u64_to_timelock,
14+
};
1215
use cuprate_types::OutputOnChain;
1316

1417
use crate::{
15-
ops::macros::{doc_add_block_inner_invariant, doc_error},
18+
ops::{
19+
macros::{doc_add_block_inner_invariant, doc_error},
20+
tx::get_tx_from_id,
21+
},
1622
tables::{
1723
BlockInfos, BlockTxsHashes, Outputs, RctOutputs, Tables, TablesMut, TxBlobs, TxUnlockTime,
1824
},
@@ -175,14 +181,16 @@ pub fn output_to_output_on_chain(
175181

176182
let txid = if get_txid {
177183
let height = u32_to_usize(output.height);
178-
let tx_idx = u64_to_usize(output.tx_idx);
179-
let txid = if let Some(hash) = table_block_txs_hashes.get(&height)?.get(tx_idx) {
180-
*hash
184+
185+
let miner_tx_id = table_block_infos.get(&height)?.mining_tx_index;
186+
187+
let txid = if miner_tx_id == output.tx_idx {
188+
get_tx_from_id(&miner_tx_id, table_tx_blobs)?.hash()
181189
} else {
182-
let miner_tx_id = table_block_infos.get(&height)?.mining_tx_index;
183-
let tx_blob = table_tx_blobs.get(&miner_tx_id)?;
184-
Transaction::read(&mut tx_blob.0.as_slice())?.hash()
190+
let idx = u64_to_usize(output.tx_idx - miner_tx_id - 1);
191+
table_block_txs_hashes.get(&height)?[idx]
185192
};
193+
186194
Some(txid)
187195
} else {
188196
None
@@ -234,8 +242,7 @@ pub fn rct_output_to_output_on_chain(
234242
let miner_tx_id = table_block_infos.get(&height)?.mining_tx_index;
235243

236244
let txid = if miner_tx_id == rct_output.tx_idx {
237-
let tx_blob = table_tx_blobs.get(&miner_tx_id)?;
238-
Transaction::read(&mut tx_blob.0.as_slice())?.hash()
245+
get_tx_from_id(&miner_tx_id, table_tx_blobs)?.hash()
239246
} else {
240247
let idx = u64_to_usize(rct_output.tx_idx - miner_tx_id - 1);
241248
table_block_txs_hashes.get(&height)?[idx]

0 commit comments

Comments
 (0)