Merge pull request #4514

85e58cb2 blockchain_blackball: fix stats double counting (moneromooo-monero)
This commit is contained in:
Riccardo Spagni 2018-10-08 13:02:32 +02:00
commit 3f2bfe87f7
No known key found for this signature in database
GPG Key ID: 55432DF31CCD4FCD
1 changed files with 18 additions and 15 deletions

View File

@ -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,7 +1156,7 @@ 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));
if (add_spent_output(cur, output_data(output.first, output.second)))
inc_stat(txn, output.first ? "pre-rct-extra" : "rct-ring-extra");
}
}
@ -1216,7 +1219,7 @@ 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]));
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,7 +1233,7 @@ 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]));
if (!add_spent_output(cur, output_data(txin.amount, absolute[o])))
inc_stat(txn, txin.amount ? "pre-rct-duplicate-rings" : "rct-duplicate-rings");
}
}
@ -1245,7 +1248,7 @@ 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]));
if (add_spent_output(cur, output_data(txin.amount, absolute[o])))
inc_stat(txn, txin.amount ? "pre-rct-subset-rings" : "rct-subset-rings");
}
}
@ -1281,7 +1284,7 @@ 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]));
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));
work_spent.push_back(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));
}
}