aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2018-10-08 13:02:32 +0200
committerRiccardo Spagni <ric@spagni.net>2018-10-08 13:02:33 +0200
commit3f2bfe87f7ebcb5a5f5a62abec55480e93fcc82e (patch)
treed9a0d4d57c5702789c507059a3551c0e86e9d44d
parentMerge pull request #4036 (diff)
parentblockchain_blackball: fix stats double counting (diff)
downloadmonero-3f2bfe87f7ebcb5a5f5a62abec55480e93fcc82e.tar.xz
Merge pull request #4514
85e58cb2 blockchain_blackball: fix stats double counting (moneromooo-monero)
Diffstat (limited to '')
-rw-r--r--src/blockchain_utilities/blockchain_blackball.cpp33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/blockchain_utilities/blockchain_blackball.cpp b/src/blockchain_utilities/blockchain_blackball.cpp
index 5eb2acc79..00baad7f0 100644
--- a/src/blockchain_utilities/blockchain_blackball.cpp
+++ b/src/blockchain_utilities/blockchain_blackball.cpp
@@ -536,12 +536,15 @@ static uint64_t get_num_spent_outputs()
return count;
}
-static void add_spent_output(MDB_cursor *cur, const output_data &od)
+static bool add_spent_output(MDB_cursor *cur, const output_data &od)
{
MDB_val k = {sizeof(od.amount), (void*)&od.amount};
MDB_val v = {sizeof(od.offset), (void*)&od.offset};
- int dbr = mdb_cursor_put(cur, &k, &v, 0);
- CHECK_AND_ASSERT_THROW_MES(!dbr || dbr == MDB_KEYEXIST, "Failed to add spent output: " + std::string(mdb_strerror(dbr)));
+ int dbr = mdb_cursor_put(cur, &k, &v, MDB_NODUPDATA);
+ if (dbr == MDB_KEYEXIST)
+ return false;
+ CHECK_AND_ASSERT_THROW_MES(!dbr, "Failed to add spent output: " + std::string(mdb_strerror(dbr)));
+ return true;
}
static bool is_output_spent(MDB_cursor *cur, const output_data &od)
@@ -1153,8 +1156,8 @@ int main(int argc, char* argv[])
if (!is_output_spent(cur, output_data(output.first, output.second)))
{
blackballs.push_back(output);
- add_spent_output(cur, output_data(output.first, output.second));
- inc_stat(txn, output.first ? "pre-rct-extra" : "rct-ring-extra");
+ if (add_spent_output(cur, output_data(output.first, output.second)))
+ inc_stat(txn, output.first ? "pre-rct-extra" : "rct-ring-extra");
}
}
if (!blackballs.empty())
@@ -1216,8 +1219,8 @@ int main(int argc, char* argv[])
std::cout << "\r" << start_idx << "/" << n_txes << " \r" << std::flush;
}
blackballs.push_back(output);
- add_spent_output(cur, output_data(txin.amount, absolute[0]));
- inc_stat(txn, txin.amount ? "pre-rct-ring-size-1" : "rct-ring-size-1");
+ if (add_spent_output(cur, output_data(txin.amount, absolute[0])))
+ inc_stat(txn, txin.amount ? "pre-rct-ring-size-1" : "rct-ring-size-1");
}
else if (n == 0 && instances == new_ring.size())
{
@@ -1230,8 +1233,8 @@ int main(int argc, char* argv[])
std::cout << "\r" << start_idx << "/" << n_txes << " \r" << std::flush;
}
blackballs.push_back(output);
- add_spent_output(cur, output_data(txin.amount, absolute[o]));
- inc_stat(txn, txin.amount ? "pre-rct-duplicate-rings" : "rct-duplicate-rings");
+ if (!add_spent_output(cur, output_data(txin.amount, absolute[o])))
+ inc_stat(txn, txin.amount ? "pre-rct-duplicate-rings" : "rct-duplicate-rings");
}
}
else if (n == 0 && opt_check_subsets && get_ring_subset_instances(txn, txin.amount, new_ring) >= new_ring.size())
@@ -1245,8 +1248,8 @@ int main(int argc, char* argv[])
std::cout << "\r" << start_idx << "/" << n_txes << " \r" << std::flush;
}
blackballs.push_back(output);
- add_spent_output(cur, output_data(txin.amount, absolute[o]));
- inc_stat(txn, txin.amount ? "pre-rct-subset-rings" : "rct-subset-rings");
+ if (add_spent_output(cur, output_data(txin.amount, absolute[o])))
+ inc_stat(txn, txin.amount ? "pre-rct-subset-rings" : "rct-subset-rings");
}
}
else if (n > 0 && get_relative_ring(txn, txin.k_image, relative_ring))
@@ -1281,8 +1284,8 @@ int main(int argc, char* argv[])
std::cout << "\r" << start_idx << "/" << n_txes << " \r" << std::flush;
}
blackballs.push_back(output);
- add_spent_output(cur, output_data(txin.amount, common[0]));
- inc_stat(txn, txin.amount ? "pre-rct-key-image-attack" : "rct-key-image-attack");
+ if (add_spent_output(cur, output_data(txin.amount, common[0])))
+ inc_stat(txn, txin.amount ? "pre-rct-key-image-attack" : "rct-key-image-attack");
}
else
{
@@ -1393,9 +1396,9 @@ int main(int argc, char* argv[])
absolute.size() << "-ring where all other outputs are known to be spent");
}
blackballs.push_back(output);
- add_spent_output(cur, output_data(od.amount, last_unknown));
+ if (add_spent_output(cur, output_data(od.amount, last_unknown)))
+ inc_stat(txn, od.amount ? "pre-rct-chain-reaction" : "rct-chain-reaction");
work_spent.push_back(output_data(od.amount, last_unknown));
- inc_stat(txn, od.amount ? "pre-rct-chain-reaction" : "rct-chain-reaction");
}
}