mirror of
https://github.com/monero-project/monero.git
synced 2024-12-25 13:09:24 +00:00
BlockchainBDB: Remove tx outputs in reverse order
Data should be removed in the reverse order it was added.
This matches the order of removal in
blockchain_storage::pop_transaction_from_global_index.
See f11def012f
This commit is contained in:
parent
60b064c759
commit
1a5c3fa729
1 changed files with 14 additions and 4 deletions
|
@ -419,16 +419,26 @@ void BlockchainBDB::remove_tx_outputs(const crypto::hash& tx_hash, const transac
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
result = cur->get(&k, &v, DB_NEXT_NODUP);
|
||||||
|
if (result != 0 && result != DB_NOTFOUND)
|
||||||
|
throw0(DB_ERROR("DB error attempting to get next non-duplicate tx hash"));
|
||||||
|
|
||||||
|
if (result == 0)
|
||||||
|
result = cur->get(&k, &v, DB_PREV);
|
||||||
|
else if (result == DB_NOTFOUND)
|
||||||
|
result = cur->get(&k, &v, DB_LAST);
|
||||||
|
|
||||||
db_recno_t num_elems = 0;
|
db_recno_t num_elems = 0;
|
||||||
cur->count(&num_elems, 0);
|
cur->count(&num_elems, 0);
|
||||||
|
|
||||||
for (uint64_t i = 0; i < num_elems; ++i)
|
// remove in order: from newest to oldest
|
||||||
|
for (uint64_t i = num_elems; i > 0; --i)
|
||||||
{
|
{
|
||||||
const tx_out tx_output = tx.vout[i];
|
const tx_out tx_output = tx.vout[i-1];
|
||||||
remove_output(v, tx_output.amount);
|
remove_output(v, tx_output.amount);
|
||||||
if (i < num_elems - 1)
|
if (i > 1)
|
||||||
{
|
{
|
||||||
cur->get(&k, &v, DB_NEXT_DUP);
|
cur->get(&k, &v, DB_PREV_DUP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue