aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2015-12-25 21:48:48 +0200
committerRiccardo Spagni <ric@spagni.net>2015-12-25 21:48:51 +0200
commit6f71918a12b74cac7a745fe4be86d78cd42b1aab (patch)
treee1ac736a0aa84614117d7184869e37b60a3abeaa /src
parentMerge pull request #557 (diff)
parentBlockchainLMDB: When removing, find amount output index fast by starting at end (diff)
downloadmonero-6f71918a12b74cac7a745fe4be86d78cd42b1aab.tar.xz
Merge pull request #561
ffcf6bd BlockchainLMDB: When removing, find amount output index fast by starting at end (warptangent) f11def0 BlockchainLMDB: Remove tx outputs in reverse order (warptangent)
Diffstat (limited to 'src')
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index 4a4550179..f64cd75b1 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -722,15 +722,15 @@ void BlockchainLMDB::remove_tx_outputs(const crypto::hash& tx_hash, const transa
size_t num_elems = 0;
mdb_cursor_count(cur, &num_elems);
- mdb_cursor_get(cur, &k, &v, MDB_FIRST_DUP);
+ mdb_cursor_get(cur, &k, &v, MDB_LAST_DUP);
- for (uint64_t i = 0; i < num_elems; ++i)
+ 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(*(const uint64_t*)v.mv_data, tx_output.amount);
- if (i < num_elems - 1)
+ if (i > 1)
{
- mdb_cursor_get(cur, &k, &v, MDB_NEXT_DUP);
+ mdb_cursor_get(cur, &k, &v, MDB_PREV_DUP);
}
}
}
@@ -806,22 +806,23 @@ void BlockchainLMDB::remove_amount_output_index(const uint64_t amount, const uin
size_t num_elems = 0;
mdb_cursor_count(cur, &num_elems);
- mdb_cursor_get(cur, &k, &v, MDB_FIRST_DUP);
+ mdb_cursor_get(cur, &k, &v, MDB_LAST_DUP);
uint64_t amount_output_index = 0;
uint64_t goi = 0;
bool found_index = false;
- for (uint64_t i = 0; i < num_elems; ++i)
+ for (uint64_t i = num_elems; i > 0; --i)
{
mdb_cursor_get(cur, &k, &v, MDB_GET_CURRENT);
goi = *(const uint64_t *)v.mv_data;
if (goi == global_output_index)
{
- amount_output_index = i;
+ amount_output_index = i-1;
found_index = true;
break;
}
- mdb_cursor_get(cur, &k, &v, MDB_NEXT_DUP);
+ if (i > 1)
+ mdb_cursor_get(cur, &k, &v, MDB_PREV_DUP);
}
if (found_index)
{