Rename nullifier caches and maps to indicate sprout nullifiers

This commit is contained in:
Eirik Ogilvie-Wigley
2018-04-25 11:26:38 -06:00
parent cab341e1a8
commit 9669920f75
11 changed files with 43 additions and 38 deletions

View File

@@ -52,7 +52,7 @@ bool CCoinsView::BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock,
const uint256 &hashAnchor,
CAnchorsMap &mapAnchors,
CNullifiersMap &mapNullifiers,
CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers) { return false; }
bool CCoinsView::GetStats(CCoinsStats &stats) const { return false; }
@@ -70,8 +70,8 @@ bool CCoinsViewBacked::BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock,
const uint256 &hashAnchor,
CAnchorsMap &mapAnchors,
CNullifiersMap &mapNullifiers,
CNullifiersMap &mapSaplingNullifiers) { return base->BatchWrite(mapCoins, hashBlock, hashAnchor, mapAnchors, mapNullifiers, mapSaplingNullifiers); }
CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers) { return base->BatchWrite(mapCoins, hashBlock, hashAnchor, mapAnchors, mapSproutNullifiers, mapSaplingNullifiers); }
bool CCoinsViewBacked::GetStats(CCoinsStats &stats) const { return base->GetStats(stats); }
CCoinsKeyHasher::CCoinsKeyHasher() : salt(GetRandHash()) {}
@@ -86,7 +86,7 @@ CCoinsViewCache::~CCoinsViewCache()
size_t CCoinsViewCache::DynamicMemoryUsage() const {
return memusage::DynamicUsage(cacheCoins) +
memusage::DynamicUsage(cacheAnchors) +
memusage::DynamicUsage(cacheNullifiers) +
memusage::DynamicUsage(cacheSproutNullifiers) +
memusage::DynamicUsage(cacheSaplingNullifiers) +
cachedCoinsUsage;
}
@@ -137,7 +137,7 @@ bool CCoinsViewCache::GetNullifier(const uint256 &nullifier, NullifierType type)
CNullifiersMap* cacheToUse;
switch (type) {
case SPROUT_NULLIFIER:
cacheToUse = &cacheNullifiers;
cacheToUse = &cacheSproutNullifiers;
break;
case SAPLING_NULLIFIER:
cacheToUse = &cacheSaplingNullifiers;
@@ -213,7 +213,7 @@ void CCoinsViewCache::PopAnchor(const uint256 &newrt) {
void CCoinsViewCache::SetNullifiers(const CTransaction& tx, bool spent) {
for (const JSDescription &joinsplit : tx.vjoinsplit) {
for (const uint256 &nullifier : joinsplit.nullifiers) {
std::pair<CNullifiersMap::iterator, bool> ret = cacheNullifiers.insert(std::make_pair(nullifier, CNullifiersCacheEntry()));
std::pair<CNullifiersMap::iterator, bool> ret = cacheSproutNullifiers.insert(std::make_pair(nullifier, CNullifiersCacheEntry()));
ret.first->second.entered = spent;
ret.first->second.flags |= CNullifiersCacheEntry::DIRTY;
}
@@ -316,7 +316,7 @@ bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlockIn,
const uint256 &hashAnchorIn,
CAnchorsMap &mapAnchors,
CNullifiersMap &mapNullifiers,
CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers) {
assert(!hasModifier);
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) {
@@ -379,7 +379,7 @@ bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins,
mapAnchors.erase(itOld);
}
::BatchWriteNullifiers(mapNullifiers, cacheNullifiers);
::BatchWriteNullifiers(mapSproutNullifiers, cacheSproutNullifiers);
::BatchWriteNullifiers(mapSaplingNullifiers, cacheSaplingNullifiers);
hashAnchor = hashAnchorIn;
@@ -388,10 +388,10 @@ bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins,
}
bool CCoinsViewCache::Flush() {
bool fOk = base->BatchWrite(cacheCoins, hashBlock, hashAnchor, cacheAnchors, cacheNullifiers, cacheSaplingNullifiers);
bool fOk = base->BatchWrite(cacheCoins, hashBlock, hashAnchor, cacheAnchors, cacheSproutNullifiers, cacheSaplingNullifiers);
cacheCoins.clear();
cacheAnchors.clear();
cacheNullifiers.clear();
cacheSproutNullifiers.clear();
cacheSaplingNullifiers.clear();
cachedCoinsUsage = 0;
return fOk;

View File

@@ -351,7 +351,7 @@ public:
const uint256 &hashBlock,
const uint256 &hashAnchor,
CAnchorsMap &mapAnchors,
CNullifiersMap &mapNullifiers,
CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers);
//! Calculate statistics about the unspent transaction output set
@@ -381,7 +381,7 @@ public:
const uint256 &hashBlock,
const uint256 &hashAnchor,
CAnchorsMap &mapAnchors,
CNullifiersMap &mapNullifiers,
CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers);
bool GetStats(CCoinsStats &stats) const;
};
@@ -425,7 +425,7 @@ protected:
mutable CCoinsMap cacheCoins;
mutable uint256 hashAnchor;
mutable CAnchorsMap cacheAnchors;
mutable CNullifiersMap cacheNullifiers;
mutable CNullifiersMap cacheSproutNullifiers;
mutable CNullifiersMap cacheSaplingNullifiers;
/* Cached dynamic memory usage for the inner CCoins objects. */
@@ -447,7 +447,7 @@ public:
const uint256 &hashBlock,
const uint256 &hashAnchor,
CAnchorsMap &mapAnchors,
CNullifiersMap &mapNullifiers,
CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers);
@@ -459,7 +459,7 @@ public:
// the new current root.
void PopAnchor(const uint256 &rt);
// Marks a nullifiers for a given transaction as spent or not.
// Marks nullifiers for a given transaction as spent or not.
void SetNullifiers(const CTransaction& tx, bool spent);
/**

View File

@@ -56,7 +56,7 @@ public:
const uint256 &hashBlock,
const uint256 &hashAnchor,
CAnchorsMap &mapAnchors,
CNullifiersMap &mapNullifiers,
CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers) {
return false;
}

View File

@@ -51,7 +51,7 @@ public:
const uint256 &hashBlock,
const uint256 &hashAnchor,
CAnchorsMap &mapAnchors,
CNullifiersMap &mapNullifiers,
CNullifiersMap &mapSproutNullifiers,
CNullifiersMap saplingNullifiersMap) {
return false;
}

View File

@@ -1270,13 +1270,15 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
}
BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) {
BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) {
if (pool.nullifierExists(nf, SPROUT_NULLIFIER))
if (pool.nullifierExists(nf, SPROUT_NULLIFIER)) {
return false;
}
}
}
for (const SpendDescription &spendDescription : tx.vShieldedSpend) {
if (pool.nullifierExists(spendDescription.nullifier, SAPLING_NULLIFIER))
if (pool.nullifierExists(spendDescription.nullifier, SAPLING_NULLIFIER)) {
return false;
}
}
}

View File

@@ -28,7 +28,7 @@ class CCoinsViewTest : public CCoinsView
uint256 hashBestAnchor_;
std::map<uint256, CCoins> map_;
std::map<uint256, ZCIncrementalMerkleTree> mapAnchors_;
std::map<uint256, bool> mapNullifiers_;
std::map<uint256, bool> mapSproutNullifiers_;
std::map<uint256, bool> mapSaplingNullifiers_;
public:
@@ -57,7 +57,7 @@ public:
const std::map<uint256, bool>* mapToUse;
switch (type) {
case SPROUT_NULLIFIER:
mapToUse = &mapNullifiers_;
mapToUse = &mapSproutNullifiers_;
break;
case SAPLING_NULLIFIER:
mapToUse = &mapSaplingNullifiers_;
@@ -116,7 +116,7 @@ public:
const uint256& hashBlock,
const uint256& hashAnchor,
CAnchorsMap& mapAnchors,
CNullifiersMap& mapNullifiers,
CNullifiersMap& mapSproutNullifiers,
CNullifiersMap& mapSaplingNullifiers)
{
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end(); ) {
@@ -139,7 +139,7 @@ public:
mapAnchors.erase(it++);
}
BatchWriteNullifiers(mapNullifiers, mapNullifiers_);
BatchWriteNullifiers(mapSproutNullifiers, mapSproutNullifiers_);
BatchWriteNullifiers(mapSaplingNullifiers, mapSaplingNullifiers_);
mapCoins.clear();
@@ -162,7 +162,7 @@ public:
// Manually recompute the dynamic usage of the whole data, and compare it.
size_t ret = memusage::DynamicUsage(cacheCoins) +
memusage::DynamicUsage(cacheAnchors) +
memusage::DynamicUsage(cacheNullifiers) +
memusage::DynamicUsage(cacheSproutNullifiers) +
memusage::DynamicUsage(cacheSaplingNullifiers);
for (CCoinsMap::iterator it = cacheCoins.begin(); it != cacheCoins.end(); it++) {
ret += it->second.coins.DynamicMemoryUsage();

View File

@@ -109,7 +109,7 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock,
const uint256 &hashAnchor,
CAnchorsMap &mapAnchors,
CNullifiersMap &mapNullifiers,
CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers) {
CDBBatch batch(db);
size_t count = 0;
@@ -140,7 +140,7 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins,
mapAnchors.erase(itOld);
}
::BatchWriteNullifiers(batch, mapNullifiers, DB_NULLIFIER);
::BatchWriteNullifiers(batch, mapSproutNullifiers, DB_NULLIFIER);
::BatchWriteNullifiers(batch, mapSaplingNullifiers, DB_SAPLING_NULLIFIER);
if (!hashBlock.IsNull())

View File

@@ -45,7 +45,7 @@ public:
const uint256 &hashBlock,
const uint256 &hashAnchor,
CAnchorsMap &mapAnchors,
CNullifiersMap &mapNullifiers,
CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers);
bool GetStats(CCoinsStats &stats) const;
};

View File

@@ -107,7 +107,7 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,
mapNextTx[tx.vin[i].prevout] = CInPoint(&tx, i);
BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) {
BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) {
mapNullifiers[nf] = &tx;
mapSproutNullifiers[nf] = &tx;
}
}
for (const SpendDescription &spendDescription : tx.vShieldedSpend) {
@@ -121,6 +121,7 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,
return true;
}
void CTxMemPool::remove(const CTransaction &origTx, std::list<CTransaction>& removed, bool fRecursive)
{
// Remove transaction from memory pool
@@ -159,7 +160,7 @@ void CTxMemPool::remove(const CTransaction &origTx, std::list<CTransaction>& rem
mapNextTx.erase(txin.prevout);
BOOST_FOREACH(const JSDescription& joinsplit, tx.vjoinsplit) {
BOOST_FOREACH(const uint256& nf, joinsplit.nullifiers) {
mapNullifiers.erase(nf);
mapSproutNullifiers.erase(nf);
}
}
for (const SpendDescription &spendDescription : tx.vShieldedSpend) {
@@ -248,11 +249,12 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>
BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) {
BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) {
std::map<uint256, const CTransaction*>::iterator it = mapNullifiers.find(nf);
if (it != mapNullifiers.end()) {
std::map<uint256, const CTransaction*>::iterator it = mapSproutNullifiers.find(nf);
if (it != mapSproutNullifiers.end()) {
const CTransaction &txConflict = *it->second;
if (txConflict != tx)
if (txConflict != tx) {
remove(txConflict, removed, true);
}
}
}
}
@@ -260,8 +262,9 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>
std::map<uint256, const CTransaction*>::iterator it = mapSaplingNullifiers.find(spendDescription.nullifier);
if (it != mapSaplingNullifiers.end()) {
const CTransaction &txConflict = *it->second;
if (txConflict != tx)
if (txConflict != tx) {
remove(txConflict, removed, true);
}
}
}
}
@@ -461,7 +464,7 @@ void CTxMemPool::checkNullifiers(NullifierType type) const
const std::map<uint256, const CTransaction*>* mapToUse;
switch (type) {
case SPROUT_NULLIFIER:
mapToUse = &mapNullifiers;
mapToUse = &mapSproutNullifiers;
break;
case SAPLING_NULLIFIER:
mapToUse = &mapSaplingNullifiers;
@@ -583,7 +586,7 @@ bool CTxMemPool::nullifierExists(const uint256& nullifier, NullifierType type) c
{
switch (type) {
case SPROUT_NULLIFIER:
return mapNullifiers.count(nullifier);
return mapSproutNullifiers.count(nullifier);
case SAPLING_NULLIFIER:
return mapSaplingNullifiers.count(nullifier);
default:

View File

@@ -131,7 +131,7 @@ private:
uint64_t totalTxSize = 0; //! sum of all mempool tx' byte sizes
uint64_t cachedInnerUsage; //! sum of dynamic memory usage of all the map elements (NOT the maps themselves)
std::map<uint256, const CTransaction*> mapNullifiers;
std::map<uint256, const CTransaction*> mapSproutNullifiers;
std::map<uint256, const CTransaction*> mapSaplingNullifiers;
void checkNullifiers(NullifierType type) const;
@@ -154,7 +154,7 @@ public:
indexed_transaction_set mapTx;
std::map<COutPoint, CInPoint> mapNextTx;
std::map<uint256, std::pair<double, CAmount> > mapDeltas;
CTxMemPool(const CFeeRate& _minRelayFee);
~CTxMemPool();

View File

@@ -382,7 +382,7 @@ public:
const uint256 &hashBlock,
const uint256 &hashAnchor,
CAnchorsMap &mapAnchors,
CNullifiersMap &mapNullifiers,
CNullifiersMap &mapSproutNullifiers,
CNullifiersMap& mapSaplingNullifiers) {
return false;
}