Rename cacheSerials to cacheNullifiers and fix tests.
This commit is contained in:
@@ -82,7 +82,7 @@ CCoinsViewCache::~CCoinsViewCache()
|
|||||||
size_t CCoinsViewCache::DynamicMemoryUsage() const {
|
size_t CCoinsViewCache::DynamicMemoryUsage() const {
|
||||||
return memusage::DynamicUsage(cacheCoins) +
|
return memusage::DynamicUsage(cacheCoins) +
|
||||||
memusage::DynamicUsage(cacheAnchors) +
|
memusage::DynamicUsage(cacheAnchors) +
|
||||||
memusage::DynamicUsage(cacheSerials) +
|
memusage::DynamicUsage(cacheNullifiers) +
|
||||||
cachedCoinsUsage;
|
cachedCoinsUsage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,15 +129,15 @@ bool CCoinsViewCache::GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tr
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool CCoinsViewCache::GetNullifier(const uint256 &serial) const {
|
bool CCoinsViewCache::GetNullifier(const uint256 &serial) const {
|
||||||
CNullifiersMap::iterator it = cacheSerials.find(serial);
|
CNullifiersMap::iterator it = cacheNullifiers.find(serial);
|
||||||
if (it != cacheSerials.end())
|
if (it != cacheNullifiers.end())
|
||||||
return it->second.entered;
|
return it->second.entered;
|
||||||
|
|
||||||
CSerialsCacheEntry entry;
|
CSerialsCacheEntry entry;
|
||||||
bool tmp = base->GetNullifier(serial);
|
bool tmp = base->GetNullifier(serial);
|
||||||
entry.entered = tmp;
|
entry.entered = tmp;
|
||||||
|
|
||||||
cacheSerials.insert(std::make_pair(serial, entry));
|
cacheNullifiers.insert(std::make_pair(serial, entry));
|
||||||
|
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
@@ -186,7 +186,7 @@ void CCoinsViewCache::PopAnchor(const uint256 &newrt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CCoinsViewCache::SetNullifier(const uint256 &serial, bool spent) {
|
void CCoinsViewCache::SetNullifier(const uint256 &serial, bool spent) {
|
||||||
std::pair<CNullifiersMap::iterator, bool> ret = cacheSerials.insert(std::make_pair(serial, CSerialsCacheEntry()));
|
std::pair<CNullifiersMap::iterator, bool> ret = cacheNullifiers.insert(std::make_pair(serial, CSerialsCacheEntry()));
|
||||||
ret.first->second.entered = spent;
|
ret.first->second.entered = spent;
|
||||||
ret.first->second.flags |= CSerialsCacheEntry::DIRTY;
|
ret.first->second.flags |= CSerialsCacheEntry::DIRTY;
|
||||||
}
|
}
|
||||||
@@ -329,14 +329,14 @@ bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins,
|
|||||||
for (CNullifiersMap::iterator child_it = mapNullifiers.begin(); child_it != mapNullifiers.end();)
|
for (CNullifiersMap::iterator child_it = mapNullifiers.begin(); child_it != mapNullifiers.end();)
|
||||||
{
|
{
|
||||||
if (child_it->second.flags & CSerialsCacheEntry::DIRTY) { // Ignore non-dirty entries (optimization).
|
if (child_it->second.flags & CSerialsCacheEntry::DIRTY) { // Ignore non-dirty entries (optimization).
|
||||||
CNullifiersMap::iterator parent_it = cacheSerials.find(child_it->first);
|
CNullifiersMap::iterator parent_it = cacheNullifiers.find(child_it->first);
|
||||||
|
|
||||||
if (parent_it == cacheSerials.end()) {
|
if (parent_it == cacheNullifiers.end()) {
|
||||||
if (child_it->second.entered) {
|
if (child_it->second.entered) {
|
||||||
// Parent doesn't have an entry, but child has a SPENT serial.
|
// Parent doesn't have an entry, but child has a SPENT serial.
|
||||||
// Move the spent serial up.
|
// Move the spent serial up.
|
||||||
|
|
||||||
CSerialsCacheEntry& entry = cacheSerials[child_it->first];
|
CSerialsCacheEntry& entry = cacheNullifiers[child_it->first];
|
||||||
entry.entered = true;
|
entry.entered = true;
|
||||||
entry.flags = CSerialsCacheEntry::DIRTY;
|
entry.flags = CSerialsCacheEntry::DIRTY;
|
||||||
}
|
}
|
||||||
@@ -357,10 +357,10 @@ bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool CCoinsViewCache::Flush() {
|
bool CCoinsViewCache::Flush() {
|
||||||
bool fOk = base->BatchWrite(cacheCoins, hashBlock, hashAnchor, cacheAnchors, cacheSerials);
|
bool fOk = base->BatchWrite(cacheCoins, hashBlock, hashAnchor, cacheAnchors, cacheNullifiers);
|
||||||
cacheCoins.clear();
|
cacheCoins.clear();
|
||||||
cacheAnchors.clear();
|
cacheAnchors.clear();
|
||||||
cacheSerials.clear();
|
cacheNullifiers.clear();
|
||||||
cachedCoinsUsage = 0;
|
cachedCoinsUsage = 0;
|
||||||
return fOk;
|
return fOk;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -440,7 +440,7 @@ protected:
|
|||||||
mutable CCoinsMap cacheCoins;
|
mutable CCoinsMap cacheCoins;
|
||||||
mutable uint256 hashAnchor;
|
mutable uint256 hashAnchor;
|
||||||
mutable CAnchorsMap cacheAnchors;
|
mutable CAnchorsMap cacheAnchors;
|
||||||
mutable CNullifiersMap cacheSerials;
|
mutable CNullifiersMap cacheNullifiers;
|
||||||
|
|
||||||
/* Cached dynamic memory usage for the inner CCoins objects. */
|
/* Cached dynamic memory usage for the inner CCoins objects. */
|
||||||
mutable size_t cachedCoinsUsage;
|
mutable size_t cachedCoinsUsage;
|
||||||
|
|||||||
@@ -11,15 +11,15 @@ TEST(checktransaction_tests, check_vpub_not_both_nonzero) {
|
|||||||
tx.nVersion = 2;
|
tx.nVersion = 2;
|
||||||
|
|
||||||
{
|
{
|
||||||
// Ensure that values within the pour are well-formed.
|
// Ensure that values within the joinsplit are well-formed.
|
||||||
CMutableTransaction newTx(tx);
|
CMutableTransaction newTx(tx);
|
||||||
CValidationState state;
|
CValidationState state;
|
||||||
|
|
||||||
newTx.vjoinsplit.push_back(JSDescription());
|
newTx.vjoinsplit.push_back(JSDescription());
|
||||||
|
|
||||||
JSDescription *pourtx = &newTx.vjoinsplit[0];
|
JSDescription *jsdesc = &newTx.vjoinsplit[0];
|
||||||
pourtx->vpub_old = 1;
|
jsdesc->vpub_old = 1;
|
||||||
pourtx->vpub_new = 1;
|
jsdesc->vpub_new = 1;
|
||||||
|
|
||||||
EXPECT_FALSE(CheckTransactionWithoutProofVerification(newTx, state));
|
EXPECT_FALSE(CheckTransactionWithoutProofVerification(newTx, state));
|
||||||
EXPECT_EQ(state.GetRejectReason(), "bad-txns-vpubs-both-nonzero");
|
EXPECT_EQ(state.GetRejectReason(), "bad-txns-vpubs-both-nonzero");
|
||||||
@@ -248,7 +248,7 @@ TEST(checktransaction_tests, bad_txns_inputs_duplicate) {
|
|||||||
CheckTransactionWithoutProofVerification(tx, state);
|
CheckTransactionWithoutProofVerification(tx, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(checktransaction_tests, bad_pours_nullifiers_duplicate_same_pour) {
|
TEST(checktransaction_tests, bad_joinsplits_nullifiers_duplicate_same_joinsplit) {
|
||||||
CMutableTransaction mtx = GetValidTransaction();
|
CMutableTransaction mtx = GetValidTransaction();
|
||||||
mtx.vjoinsplit[0].nullifiers.at(0) = uint256S("0000000000000000000000000000000000000000000000000000000000000000");
|
mtx.vjoinsplit[0].nullifiers.at(0) = uint256S("0000000000000000000000000000000000000000000000000000000000000000");
|
||||||
mtx.vjoinsplit[0].nullifiers.at(1) = uint256S("0000000000000000000000000000000000000000000000000000000000000000");
|
mtx.vjoinsplit[0].nullifiers.at(1) = uint256S("0000000000000000000000000000000000000000000000000000000000000000");
|
||||||
@@ -256,11 +256,11 @@ TEST(checktransaction_tests, bad_pours_nullifiers_duplicate_same_pour) {
|
|||||||
CTransaction tx(mtx);
|
CTransaction tx(mtx);
|
||||||
|
|
||||||
MockCValidationState state;
|
MockCValidationState state;
|
||||||
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-pours-nullifiers-duplicate", false)).Times(1);
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-joinsplits-nullifiers-duplicate", false)).Times(1);
|
||||||
CheckTransactionWithoutProofVerification(tx, state);
|
CheckTransactionWithoutProofVerification(tx, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(checktransaction_tests, bad_pours_nullifiers_duplicate_different_pour) {
|
TEST(checktransaction_tests, bad_joinsplits_nullifiers_duplicate_different_joinsplit) {
|
||||||
CMutableTransaction mtx = GetValidTransaction();
|
CMutableTransaction mtx = GetValidTransaction();
|
||||||
mtx.vjoinsplit[0].nullifiers.at(0) = uint256S("0000000000000000000000000000000000000000000000000000000000000000");
|
mtx.vjoinsplit[0].nullifiers.at(0) = uint256S("0000000000000000000000000000000000000000000000000000000000000000");
|
||||||
mtx.vjoinsplit[1].nullifiers.at(0) = uint256S("0000000000000000000000000000000000000000000000000000000000000000");
|
mtx.vjoinsplit[1].nullifiers.at(0) = uint256S("0000000000000000000000000000000000000000000000000000000000000000");
|
||||||
@@ -268,11 +268,11 @@ TEST(checktransaction_tests, bad_pours_nullifiers_duplicate_different_pour) {
|
|||||||
CTransaction tx(mtx);
|
CTransaction tx(mtx);
|
||||||
|
|
||||||
MockCValidationState state;
|
MockCValidationState state;
|
||||||
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-pours-nullifiers-duplicate", false)).Times(1);
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-joinsplits-nullifiers-duplicate", false)).Times(1);
|
||||||
CheckTransactionWithoutProofVerification(tx, state);
|
CheckTransactionWithoutProofVerification(tx, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(checktransaction_tests, bad_cb_has_pours) {
|
TEST(checktransaction_tests, bad_cb_has_joinsplits) {
|
||||||
CMutableTransaction mtx = GetValidTransaction();
|
CMutableTransaction mtx = GetValidTransaction();
|
||||||
// Make it a coinbase.
|
// Make it a coinbase.
|
||||||
mtx.vin.resize(1);
|
mtx.vin.resize(1);
|
||||||
@@ -284,7 +284,7 @@ TEST(checktransaction_tests, bad_cb_has_pours) {
|
|||||||
EXPECT_TRUE(tx.IsCoinBase());
|
EXPECT_TRUE(tx.IsCoinBase());
|
||||||
|
|
||||||
MockCValidationState state;
|
MockCValidationState state;
|
||||||
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-cb-has-pours", false)).Times(1);
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-cb-has-joinsplits", false)).Times(1);
|
||||||
CheckTransactionWithoutProofVerification(tx, state);
|
CheckTransactionWithoutProofVerification(tx, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ public:
|
|||||||
// Manually recompute the dynamic usage of the whole data, and compare it.
|
// Manually recompute the dynamic usage of the whole data, and compare it.
|
||||||
size_t ret = memusage::DynamicUsage(cacheCoins) +
|
size_t ret = memusage::DynamicUsage(cacheCoins) +
|
||||||
memusage::DynamicUsage(cacheAnchors) +
|
memusage::DynamicUsage(cacheAnchors) +
|
||||||
memusage::DynamicUsage(cacheSerials);
|
memusage::DynamicUsage(cacheNullifiers);
|
||||||
for (CCoinsMap::iterator it = cacheCoins.begin(); it != cacheCoins.end(); it++) {
|
for (CCoinsMap::iterator it = cacheCoins.begin(); it != cacheCoins.end(); it++) {
|
||||||
ret += memusage::DynamicUsage(it->second.coins);
|
ret += memusage::DynamicUsage(it->second.coins);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user