mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-23 10:37:37 -07:00
Fixes a bug with getting output metadata from BlockchainDB
Thanks to moneromooo-monero for spotting the bug.
This commit is contained in:
parent
c3fa07b44b
commit
c50cd95674
@ -1208,6 +1208,35 @@ tx_out BlockchainLMDB::get_output(const uint64_t& index) const
|
||||
return output_from_blob(b);
|
||||
}
|
||||
|
||||
tx_out_index BlockchainLMDB::get_output_tx_and_index_from_global(const uint64_t& index) const
|
||||
{
|
||||
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
||||
check_open();
|
||||
|
||||
txn_safe txn;
|
||||
if (mdb_txn_begin(m_env, NULL, MDB_RDONLY, txn))
|
||||
throw0(DB_ERROR("Failed to create a transaction for the db"));
|
||||
|
||||
MDB_val_copy<uint64_t> k(index);
|
||||
MDB_val v;
|
||||
|
||||
auto get_result = mdb_get(txn, m_output_txs, &k, &v);
|
||||
if (get_result == MDB_NOTFOUND)
|
||||
throw1(OUTPUT_DNE("output with given index not in db"));
|
||||
else if (get_result)
|
||||
throw0(DB_ERROR("DB error attempting to fetch output tx hash"));
|
||||
|
||||
crypto::hash tx_hash = *(crypto::hash*)v.mv_data;
|
||||
|
||||
get_result = mdb_get(txn, m_output_indices, &k, &v);
|
||||
if (get_result == MDB_NOTFOUND)
|
||||
throw1(OUTPUT_DNE("output with given index not in db"));
|
||||
else if (get_result)
|
||||
throw0(DB_ERROR("DB error attempting to fetch output tx index"));
|
||||
|
||||
return tx_out_index(tx_hash, *(const uint64_t *)v.mv_data);
|
||||
}
|
||||
|
||||
tx_out_index BlockchainLMDB::get_output_tx_and_index(const uint64_t& amount, const uint64_t& index) const
|
||||
{
|
||||
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
||||
@ -1249,24 +1278,9 @@ tx_out_index BlockchainLMDB::get_output_tx_and_index(const uint64_t& amount, con
|
||||
|
||||
cur.close();
|
||||
|
||||
k = MDB_val_copy<uint64_t>(glob_index);
|
||||
auto get_result = mdb_get(txn, m_output_txs, &k, &v);
|
||||
if (get_result == MDB_NOTFOUND)
|
||||
throw1(OUTPUT_DNE("output with given index not in db"));
|
||||
else if (get_result)
|
||||
throw0(DB_ERROR("DB error attempting to fetch output tx hash"));
|
||||
|
||||
crypto::hash tx_hash = *(crypto::hash*)v.mv_data;
|
||||
|
||||
get_result = mdb_get(txn, m_output_indices, &k, &v);
|
||||
if (get_result == MDB_NOTFOUND)
|
||||
throw1(OUTPUT_DNE("output with given index not in db"));
|
||||
else if (get_result)
|
||||
throw0(DB_ERROR("DB error attempting to fetch output tx index"));
|
||||
|
||||
txn.commit();
|
||||
|
||||
return tx_out_index(tx_hash, *(const uint64_t *)v.mv_data);
|
||||
return get_output_tx_and_index_from_global(glob_index);
|
||||
}
|
||||
|
||||
std::vector<uint64_t> BlockchainLMDB::get_tx_output_indices(const crypto::hash& h) const
|
||||
|
@ -161,6 +161,8 @@ public:
|
||||
*/
|
||||
tx_out get_output(const uint64_t& index) const;
|
||||
|
||||
virtual tx_out_index get_output_tx_and_index_from_global(const uint64_t& index) const;
|
||||
|
||||
virtual tx_out_index get_output_tx_and_index(const uint64_t& amount, const uint64_t& index) const;
|
||||
|
||||
virtual std::vector<uint64_t> get_tx_output_indices(const crypto::hash& h) const;
|
||||
|
@ -170,7 +170,7 @@ bool Blockchain::scan_outputkeys_for_indexes(const txin_to_key& tx_in_to_key, vi
|
||||
try
|
||||
{
|
||||
// get tx hash and output index for output
|
||||
auto output_index = m_db->get_output_tx_and_index(tx_in_to_key.amount, i);
|
||||
auto output_index = m_db->get_output_tx_and_index_from_global(i);
|
||||
|
||||
// get tx that output is from
|
||||
auto tx = m_db->get_tx(output_index.first);
|
||||
|
@ -107,6 +107,7 @@
|
||||
* uint64_t get_num_outputs(amount)
|
||||
* pub_key get_output_key(amount, index)
|
||||
* tx_out get_output(tx_hash, index)
|
||||
* hash,index get_output_tx_and_index_from_global(index)
|
||||
* hash,index get_output_tx_and_index(amount, index)
|
||||
* vec<uint64> get_tx_output_indices(tx_hash)
|
||||
*
|
||||
@ -441,6 +442,9 @@ public:
|
||||
// returns the output indexed by <index> in the transaction with hash <h>
|
||||
virtual tx_out get_output(const crypto::hash& h, const uint64_t& index) const = 0;
|
||||
|
||||
// returns the tx hash associated with an output, referenced by global output index
|
||||
virtual tx_out_index get_output_tx_and_index_from_global(const uint64_t& index) const = 0;
|
||||
|
||||
// returns the transaction-local reference for the output with <amount> at <index>
|
||||
// return type is pair of tx hash and index
|
||||
virtual tx_out_index get_output_tx_and_index(const uint64_t& amount, const uint64_t& index) const = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user