Generalize the PopAnchor implementation behavior.
This commit is contained in:
@@ -187,8 +187,15 @@ void CCoinsViewCache::PushSproutAnchor(const ZCIncrementalMerkleTree &tree) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCoinsViewCache::PopAnchor(const uint256 &newrt) {
|
template<typename Tree, typename Cache, typename CacheEntry>
|
||||||
auto currentRoot = GetBestAnchor(SPROUT);
|
void CCoinsViewCache::AbstractPopAnchor(
|
||||||
|
const uint256 &newrt,
|
||||||
|
ShieldedType type,
|
||||||
|
Cache &cacheAnchors,
|
||||||
|
uint256 &hash
|
||||||
|
)
|
||||||
|
{
|
||||||
|
auto currentRoot = GetBestAnchor(type);
|
||||||
|
|
||||||
// Blocks might not change the commitment tree, in which
|
// Blocks might not change the commitment tree, in which
|
||||||
// case restoring the "old" anchor during a reorg must
|
// case restoring the "old" anchor during a reorg must
|
||||||
@@ -197,21 +204,40 @@ void CCoinsViewCache::PopAnchor(const uint256 &newrt) {
|
|||||||
// Bring the current best anchor into our local cache
|
// Bring the current best anchor into our local cache
|
||||||
// so that its tree exists in memory.
|
// so that its tree exists in memory.
|
||||||
{
|
{
|
||||||
ZCIncrementalMerkleTree tree;
|
Tree tree;
|
||||||
assert(GetSproutAnchorAt(currentRoot, tree));
|
switch (type) {
|
||||||
|
case SPROUT:
|
||||||
|
assert(GetSproutAnchorAt(currentRoot, tree));
|
||||||
|
break;
|
||||||
|
case SAPLING:
|
||||||
|
// TODO
|
||||||
|
assert(false);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw std::runtime_error("Unknown shielded type " + type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark the anchor as unentered, removing it from view
|
// Mark the anchor as unentered, removing it from view
|
||||||
cacheSproutAnchors[currentRoot].entered = false;
|
cacheAnchors[currentRoot].entered = false;
|
||||||
|
|
||||||
// Mark the cache entry as dirty so it's propagated
|
// Mark the cache entry as dirty so it's propagated
|
||||||
cacheSproutAnchors[currentRoot].flags = CAnchorsSproutCacheEntry::DIRTY;
|
cacheAnchors[currentRoot].flags = CacheEntry::DIRTY;
|
||||||
|
|
||||||
// Mark the new root as the best anchor
|
// Mark the new root as the best anchor
|
||||||
hashSproutAnchor = newrt;
|
hash = newrt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCoinsViewCache::PopAnchor(const uint256 &newrt) {
|
||||||
|
AbstractPopAnchor<ZCIncrementalMerkleTree, CAnchorsSproutMap, CAnchorsSproutCacheEntry>(
|
||||||
|
newrt,
|
||||||
|
SPROUT,
|
||||||
|
cacheSproutAnchors,
|
||||||
|
hashSproutAnchor
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void CCoinsViewCache::SetNullifiers(const CTransaction& tx, bool spent) {
|
void CCoinsViewCache::SetNullifiers(const CTransaction& tx, bool spent) {
|
||||||
for (const JSDescription &joinsplit : tx.vjoinsplit) {
|
for (const JSDescription &joinsplit : tx.vjoinsplit) {
|
||||||
for (const uint256 &nullifier : joinsplit.nullifiers) {
|
for (const uint256 &nullifier : joinsplit.nullifiers) {
|
||||||
|
|||||||
@@ -524,6 +524,15 @@ private:
|
|||||||
* By making the copy constructor private, we prevent accidentally using it when one intends to create a cache on top of a base cache.
|
* By making the copy constructor private, we prevent accidentally using it when one intends to create a cache on top of a base cache.
|
||||||
*/
|
*/
|
||||||
CCoinsViewCache(const CCoinsViewCache &);
|
CCoinsViewCache(const CCoinsViewCache &);
|
||||||
|
|
||||||
|
//! Generalized interface for popping anchors
|
||||||
|
template<typename Tree, typename Cache, typename CacheEntry>
|
||||||
|
void AbstractPopAnchor(
|
||||||
|
const uint256 &newrt,
|
||||||
|
ShieldedType type,
|
||||||
|
Cache &cacheAnchors,
|
||||||
|
uint256 &hash
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BITCOIN_COINS_H
|
#endif // BITCOIN_COINS_H
|
||||||
|
|||||||
Reference in New Issue
Block a user