mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
Merge pull request #4407
43a06350
ringdb: use cursors to be a bit faster (moneromooo-monero)
This commit is contained in:
commit
9d0b177720
2 changed files with 32 additions and 7 deletions
|
@ -398,6 +398,8 @@ bool ringdb::blackball_worker(const std::vector<std::pair<uint64_t, uint64_t>> &
|
||||||
epee::misc_utils::auto_scope_leave_caller txn_dtor = epee::misc_utils::create_scope_leave_handler([&](){if (tx_active) mdb_txn_abort(txn);});
|
epee::misc_utils::auto_scope_leave_caller txn_dtor = epee::misc_utils::create_scope_leave_handler([&](){if (tx_active) mdb_txn_abort(txn);});
|
||||||
tx_active = true;
|
tx_active = true;
|
||||||
|
|
||||||
|
dbr = mdb_cursor_open(txn, dbi_blackballs, &cursor);
|
||||||
|
THROW_WALLET_EXCEPTION_IF(dbr, tools::error::wallet_internal_error, "Failed to create cursor for blackballs table: " + std::string(mdb_strerror(dbr)));
|
||||||
|
|
||||||
MDB_val key, data;
|
MDB_val key, data;
|
||||||
for (const std::pair<uint64_t, uint64_t> &output: outputs)
|
for (const std::pair<uint64_t, uint64_t> &output: outputs)
|
||||||
|
@ -411,25 +413,22 @@ bool ringdb::blackball_worker(const std::vector<std::pair<uint64_t, uint64_t>> &
|
||||||
{
|
{
|
||||||
case BLACKBALL_BLACKBALL:
|
case BLACKBALL_BLACKBALL:
|
||||||
MDEBUG("Blackballing output " << output.first << "/" << output.second);
|
MDEBUG("Blackballing output " << output.first << "/" << output.second);
|
||||||
dbr = mdb_put(txn, dbi_blackballs, &key, &data, MDB_APPENDDUP);
|
dbr = mdb_cursor_put(cursor, &key, &data, MDB_APPENDDUP);
|
||||||
if (dbr == MDB_KEYEXIST)
|
if (dbr == MDB_KEYEXIST)
|
||||||
dbr = 0;
|
dbr = 0;
|
||||||
break;
|
break;
|
||||||
case BLACKBALL_UNBLACKBALL:
|
case BLACKBALL_UNBLACKBALL:
|
||||||
MDEBUG("Unblackballing output " << output.first << "/" << output.second);
|
MDEBUG("Unblackballing output " << output.first << "/" << output.second);
|
||||||
dbr = mdb_del(txn, dbi_blackballs, &key, &data);
|
dbr = mdb_cursor_get(cursor, &key, &data, MDB_GET_BOTH);
|
||||||
if (dbr == MDB_NOTFOUND)
|
if (dbr == 0)
|
||||||
dbr = 0;
|
dbr = mdb_cursor_del(cursor, 0);
|
||||||
break;
|
break;
|
||||||
case BLACKBALL_QUERY:
|
case BLACKBALL_QUERY:
|
||||||
dbr = mdb_cursor_open(txn, dbi_blackballs, &cursor);
|
|
||||||
THROW_WALLET_EXCEPTION_IF(dbr, tools::error::wallet_internal_error, "Failed to create cursor for blackballs table: " + std::string(mdb_strerror(dbr)));
|
|
||||||
dbr = mdb_cursor_get(cursor, &key, &data, MDB_GET_BOTH);
|
dbr = mdb_cursor_get(cursor, &key, &data, MDB_GET_BOTH);
|
||||||
THROW_WALLET_EXCEPTION_IF(dbr && dbr != MDB_NOTFOUND, tools::error::wallet_internal_error, "Failed to lookup in blackballs table: " + std::string(mdb_strerror(dbr)));
|
THROW_WALLET_EXCEPTION_IF(dbr && dbr != MDB_NOTFOUND, tools::error::wallet_internal_error, "Failed to lookup in blackballs table: " + std::string(mdb_strerror(dbr)));
|
||||||
ret = dbr != MDB_NOTFOUND;
|
ret = dbr != MDB_NOTFOUND;
|
||||||
if (dbr == MDB_NOTFOUND)
|
if (dbr == MDB_NOTFOUND)
|
||||||
dbr = 0;
|
dbr = 0;
|
||||||
mdb_cursor_close(cursor);
|
|
||||||
break;
|
break;
|
||||||
case BLACKBALL_CLEAR:
|
case BLACKBALL_CLEAR:
|
||||||
break;
|
break;
|
||||||
|
@ -439,6 +438,8 @@ bool ringdb::blackball_worker(const std::vector<std::pair<uint64_t, uint64_t>> &
|
||||||
THROW_WALLET_EXCEPTION_IF(dbr, tools::error::wallet_internal_error, "Failed to query blackballs table: " + std::string(mdb_strerror(dbr)));
|
THROW_WALLET_EXCEPTION_IF(dbr, tools::error::wallet_internal_error, "Failed to query blackballs table: " + std::string(mdb_strerror(dbr)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mdb_cursor_close(cursor);
|
||||||
|
|
||||||
if (op == BLACKBALL_CLEAR)
|
if (op == BLACKBALL_CLEAR)
|
||||||
{
|
{
|
||||||
dbr = mdb_drop(txn, dbi_blackballs, 0);
|
dbr = mdb_drop(txn, dbi_blackballs, 0);
|
||||||
|
|
|
@ -150,6 +150,30 @@ TEST(blackball, found)
|
||||||
ASSERT_TRUE(ringdb.blackballed(OUTPUT_1));
|
ASSERT_TRUE(ringdb.blackballed(OUTPUT_1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(blackball, vector)
|
||||||
|
{
|
||||||
|
RingDB ringdb;
|
||||||
|
std::vector<std::pair<uint64_t, uint64_t>> outputs;
|
||||||
|
outputs.push_back(std::make_pair(0, 1));
|
||||||
|
outputs.push_back(std::make_pair(10, 3));
|
||||||
|
outputs.push_back(std::make_pair(10, 4));
|
||||||
|
outputs.push_back(std::make_pair(10, 8));
|
||||||
|
outputs.push_back(std::make_pair(20, 0));
|
||||||
|
outputs.push_back(std::make_pair(20, 1));
|
||||||
|
outputs.push_back(std::make_pair(30, 5));
|
||||||
|
ASSERT_TRUE(ringdb.blackball(outputs));
|
||||||
|
ASSERT_TRUE(ringdb.blackballed(std::make_pair(0, 1)));
|
||||||
|
ASSERT_FALSE(ringdb.blackballed(std::make_pair(10, 2)));
|
||||||
|
ASSERT_TRUE(ringdb.blackballed(std::make_pair(10, 3)));
|
||||||
|
ASSERT_TRUE(ringdb.blackballed(std::make_pair(10, 4)));
|
||||||
|
ASSERT_FALSE(ringdb.blackballed(std::make_pair(10, 5)));
|
||||||
|
ASSERT_TRUE(ringdb.blackballed(std::make_pair(10, 8)));
|
||||||
|
ASSERT_TRUE(ringdb.blackballed(std::make_pair(20, 0)));
|
||||||
|
ASSERT_TRUE(ringdb.blackballed(std::make_pair(20, 1)));
|
||||||
|
ASSERT_FALSE(ringdb.blackballed(std::make_pair(20, 2)));
|
||||||
|
ASSERT_TRUE(ringdb.blackballed(std::make_pair(30, 5)));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(blackball, unblackball)
|
TEST(blackball, unblackball)
|
||||||
{
|
{
|
||||||
RingDB ringdb;
|
RingDB ringdb;
|
||||||
|
|
Loading…
Reference in a new issue