Rename hashAnchor to hashSproutAnchor.

This commit is contained in:
Sean Bowe
2018-04-25 19:15:30 -06:00
parent d455828fdc
commit 08f0728884
11 changed files with 44 additions and 44 deletions

View File

@@ -152,10 +152,10 @@ public:
boost::optional<uint32_t> nCachedBranchId; boost::optional<uint32_t> nCachedBranchId;
//! The anchor for the tree state up to the start of this block //! The anchor for the tree state up to the start of this block
uint256 hashAnchor; uint256 hashSproutAnchor;
//! (memory only) The anchor for the tree state up to the end of this block //! (memory only) The anchor for the tree state up to the end of this block
uint256 hashAnchorEnd; uint256 hashSproutAnchorEnd;
//! Change in value held by the Sprout circuit over this block. //! Change in value held by the Sprout circuit over this block.
//! Will be boost::none for older blocks on old nodes until a reindex has taken place. //! Will be boost::none for older blocks on old nodes until a reindex has taken place.
@@ -192,8 +192,8 @@ public:
nChainTx = 0; nChainTx = 0;
nStatus = 0; nStatus = 0;
nCachedBranchId = boost::none; nCachedBranchId = boost::none;
hashAnchor = uint256(); hashSproutAnchor = uint256();
hashAnchorEnd = uint256(); hashSproutAnchorEnd = uint256();
nSequenceId = 0; nSequenceId = 0;
nSproutValue = boost::none; nSproutValue = boost::none;
nChainSproutValue = boost::none; nChainSproutValue = boost::none;
@@ -366,7 +366,7 @@ public:
READWRITE(branchId); READWRITE(branchId);
} }
} }
READWRITE(hashAnchor); READWRITE(hashSproutAnchor);
// block header // block header
READWRITE(this->nVersion); READWRITE(this->nVersion);

View File

@@ -50,7 +50,7 @@ uint256 CCoinsView::GetBestBlock() const { return uint256(); }
uint256 CCoinsView::GetBestAnchor() const { return uint256(); }; uint256 CCoinsView::GetBestAnchor() const { return uint256(); };
bool CCoinsView::BatchWrite(CCoinsMap &mapCoins, bool CCoinsView::BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock, const uint256 &hashBlock,
const uint256 &hashAnchor, const uint256 &hashSproutAnchor,
CAnchorsSproutMap &mapSproutAnchors, CAnchorsSproutMap &mapSproutAnchors,
CNullifiersMap &mapSproutNullifiers, CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers) { return false; } CNullifiersMap &mapSaplingNullifiers) { return false; }
@@ -68,10 +68,10 @@ uint256 CCoinsViewBacked::GetBestAnchor() const { return base->GetBestAnchor();
void CCoinsViewBacked::SetBackend(CCoinsView &viewIn) { base = &viewIn; } void CCoinsViewBacked::SetBackend(CCoinsView &viewIn) { base = &viewIn; }
bool CCoinsViewBacked::BatchWrite(CCoinsMap &mapCoins, bool CCoinsViewBacked::BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock, const uint256 &hashBlock,
const uint256 &hashAnchor, const uint256 &hashSproutAnchor,
CAnchorsSproutMap &mapSproutAnchors, CAnchorsSproutMap &mapSproutAnchors,
CNullifiersMap &mapSproutNullifiers, CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers) { return base->BatchWrite(mapCoins, hashBlock, hashAnchor, mapSproutAnchors, mapSproutNullifiers, mapSaplingNullifiers); } CNullifiersMap &mapSaplingNullifiers) { return base->BatchWrite(mapCoins, hashBlock, hashSproutAnchor, mapSproutAnchors, mapSproutNullifiers, mapSaplingNullifiers); }
bool CCoinsViewBacked::GetStats(CCoinsStats &stats) const { return base->GetStats(stats); } bool CCoinsViewBacked::GetStats(CCoinsStats &stats) const { return base->GetStats(stats); }
CCoinsKeyHasher::CCoinsKeyHasher() : salt(GetRandHash()) {} CCoinsKeyHasher::CCoinsKeyHasher() : salt(GetRandHash()) {}
@@ -181,7 +181,7 @@ void CCoinsViewCache::PushAnchor(const ZCIncrementalMerkleTree &tree) {
cachedCoinsUsage += ret->second.tree.DynamicMemoryUsage(); cachedCoinsUsage += ret->second.tree.DynamicMemoryUsage();
} }
hashAnchor = newrt; hashSproutAnchor = newrt;
} }
} }
@@ -206,7 +206,7 @@ void CCoinsViewCache::PopAnchor(const uint256 &newrt) {
cacheSproutAnchors[currentRoot].flags = CAnchorsSproutCacheEntry::DIRTY; cacheSproutAnchors[currentRoot].flags = CAnchorsSproutCacheEntry::DIRTY;
// Mark the new root as the best anchor // Mark the new root as the best anchor
hashAnchor = newrt; hashSproutAnchor = newrt;
} }
} }
@@ -281,9 +281,9 @@ uint256 CCoinsViewCache::GetBestBlock() const {
uint256 CCoinsViewCache::GetBestAnchor() const { uint256 CCoinsViewCache::GetBestAnchor() const {
if (hashAnchor.IsNull()) if (hashSproutAnchor.IsNull())
hashAnchor = base->GetBestAnchor(); hashSproutAnchor = base->GetBestAnchor();
return hashAnchor; return hashSproutAnchor;
} }
void CCoinsViewCache::SetBestBlock(const uint256 &hashBlockIn) { void CCoinsViewCache::SetBestBlock(const uint256 &hashBlockIn) {
@@ -314,7 +314,7 @@ void BatchWriteNullifiers(CNullifiersMap &mapNullifiers, CNullifiersMap &cacheNu
bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins, bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlockIn, const uint256 &hashBlockIn,
const uint256 &hashAnchorIn, const uint256 &hashSproutAnchorIn,
CAnchorsSproutMap &mapSproutAnchors, CAnchorsSproutMap &mapSproutAnchors,
CNullifiersMap &mapSproutNullifiers, CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers) { CNullifiersMap &mapSaplingNullifiers) {
@@ -382,13 +382,13 @@ bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins,
::BatchWriteNullifiers(mapSproutNullifiers, cacheSproutNullifiers); ::BatchWriteNullifiers(mapSproutNullifiers, cacheSproutNullifiers);
::BatchWriteNullifiers(mapSaplingNullifiers, cacheSaplingNullifiers); ::BatchWriteNullifiers(mapSaplingNullifiers, cacheSaplingNullifiers);
hashAnchor = hashAnchorIn; hashSproutAnchor = hashSproutAnchorIn;
hashBlock = hashBlockIn; hashBlock = hashBlockIn;
return true; return true;
} }
bool CCoinsViewCache::Flush() { bool CCoinsViewCache::Flush() {
bool fOk = base->BatchWrite(cacheCoins, hashBlock, hashAnchor, cacheSproutAnchors, cacheSproutNullifiers, cacheSaplingNullifiers); bool fOk = base->BatchWrite(cacheCoins, hashBlock, hashSproutAnchor, cacheSproutAnchors, cacheSproutNullifiers, cacheSaplingNullifiers);
cacheCoins.clear(); cacheCoins.clear();
cacheSproutAnchors.clear(); cacheSproutAnchors.clear();
cacheSproutNullifiers.clear(); cacheSproutNullifiers.clear();

View File

@@ -349,7 +349,7 @@ public:
//! The passed mapCoins can be modified. //! The passed mapCoins can be modified.
virtual bool BatchWrite(CCoinsMap &mapCoins, virtual bool BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock, const uint256 &hashBlock,
const uint256 &hashAnchor, const uint256 &hashSproutAnchor,
CAnchorsSproutMap &mapSproutAnchors, CAnchorsSproutMap &mapSproutAnchors,
CNullifiersMap &mapSproutNullifiers, CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers); CNullifiersMap &mapSaplingNullifiers);
@@ -379,7 +379,7 @@ public:
void SetBackend(CCoinsView &viewIn); void SetBackend(CCoinsView &viewIn);
bool BatchWrite(CCoinsMap &mapCoins, bool BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock, const uint256 &hashBlock,
const uint256 &hashAnchor, const uint256 &hashSproutAnchor,
CAnchorsSproutMap &mapSproutAnchors, CAnchorsSproutMap &mapSproutAnchors,
CNullifiersMap &mapSproutNullifiers, CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers); CNullifiersMap &mapSaplingNullifiers);
@@ -423,7 +423,7 @@ protected:
*/ */
mutable uint256 hashBlock; mutable uint256 hashBlock;
mutable CCoinsMap cacheCoins; mutable CCoinsMap cacheCoins;
mutable uint256 hashAnchor; mutable uint256 hashSproutAnchor;
mutable CAnchorsSproutMap cacheSproutAnchors; mutable CAnchorsSproutMap cacheSproutAnchors;
mutable CNullifiersMap cacheSproutNullifiers; mutable CNullifiersMap cacheSproutNullifiers;
mutable CNullifiersMap cacheSaplingNullifiers; mutable CNullifiersMap cacheSaplingNullifiers;
@@ -445,7 +445,7 @@ public:
void SetBestBlock(const uint256 &hashBlock); void SetBestBlock(const uint256 &hashBlock);
bool BatchWrite(CCoinsMap &mapCoins, bool BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock, const uint256 &hashBlock,
const uint256 &hashAnchor, const uint256 &hashSproutAnchor,
CAnchorsSproutMap &mapSproutAnchors, CAnchorsSproutMap &mapSproutAnchors,
CNullifiersMap &mapSproutNullifiers, CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers); CNullifiersMap &mapSaplingNullifiers);

View File

@@ -54,7 +54,7 @@ public:
bool BatchWrite(CCoinsMap &mapCoins, bool BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock, const uint256 &hashBlock,
const uint256 &hashAnchor, const uint256 &hashSproutAnchor,
CAnchorsSproutMap &mapSproutAnchors, CAnchorsSproutMap &mapSproutAnchors,
CNullifiersMap &mapSproutNullifiers, CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers) { CNullifiersMap &mapSaplingNullifiers) {

View File

@@ -49,7 +49,7 @@ public:
bool BatchWrite(CCoinsMap &mapCoins, bool BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock, const uint256 &hashBlock,
const uint256 &hashAnchor, const uint256 &hashSproutAnchor,
CAnchorsSproutMap &mapSproutAnchors, CAnchorsSproutMap &mapSproutAnchors,
CNullifiersMap &mapSproutNullifiers, CNullifiersMap &mapSproutNullifiers,
CNullifiersMap saplingNullifiersMap) { CNullifiersMap saplingNullifiersMap) {

View File

@@ -2295,9 +2295,9 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
view.SetBestBlock(pindex->GetBlockHash()); view.SetBestBlock(pindex->GetBlockHash());
// Before the genesis block, there was an empty tree // Before the genesis block, there was an empty tree
ZCIncrementalMerkleTree tree; ZCIncrementalMerkleTree tree;
pindex->hashAnchor = tree.root(); pindex->hashSproutAnchor = tree.root();
// The genesis block contained no JoinSplits // The genesis block contained no JoinSplits
pindex->hashAnchorEnd = pindex->hashAnchor; pindex->hashSproutAnchorEnd = pindex->hashSproutAnchor;
} }
return true; return true;
} }
@@ -2333,7 +2333,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
auto old_tree_root = view.GetBestAnchor(); auto old_tree_root = view.GetBestAnchor();
// saving the top anchor in the block index as we go. // saving the top anchor in the block index as we go.
if (!fJustCheck) { if (!fJustCheck) {
pindex->hashAnchor = old_tree_root; pindex->hashSproutAnchor = old_tree_root;
} }
ZCIncrementalMerkleTree tree; ZCIncrementalMerkleTree tree;
// This should never fail: we should always be able to get the root // This should never fail: we should always be able to get the root
@@ -2413,7 +2413,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
view.PushAnchor(tree); view.PushAnchor(tree);
if (!fJustCheck) { if (!fJustCheck) {
pindex->hashAnchorEnd = tree.root(); pindex->hashSproutAnchorEnd = tree.root();
} }
blockundo.old_tree_root = old_tree_root; blockundo.old_tree_root = old_tree_root;
@@ -3927,12 +3927,12 @@ bool static LoadBlockIndexDB()
{ {
CBlockIndex* pindex = item.second; CBlockIndex* pindex = item.second;
// - This relationship will always be true even if pprev has multiple // - This relationship will always be true even if pprev has multiple
// children, because hashAnchor is technically a property of pprev, // children, because hashSproutAnchor is technically a property of pprev,
// not its children. // not its children.
// - This will miss chain tips; we handle the best tip below, and other // - This will miss chain tips; we handle the best tip below, and other
// tips will be handled by ConnectTip during a re-org. // tips will be handled by ConnectTip during a re-org.
if (pindex->pprev) { if (pindex->pprev) {
pindex->pprev->hashAnchorEnd = pindex->hashAnchor; pindex->pprev->hashSproutAnchorEnd = pindex->hashSproutAnchor;
} }
} }
@@ -3941,8 +3941,8 @@ bool static LoadBlockIndexDB()
if (it == mapBlockIndex.end()) if (it == mapBlockIndex.end())
return true; return true;
chainActive.SetTip(it->second); chainActive.SetTip(it->second);
// Set hashAnchorEnd for the end of best chain // Set hashSproutAnchorEnd for the end of best chain
it->second->hashAnchorEnd = pcoinsTip->GetBestAnchor(); it->second->hashSproutAnchorEnd = pcoinsTip->GetBestAnchor();
PruneBlockIndexCandidates(); PruneBlockIndexCandidates();

View File

@@ -155,7 +155,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
result.push_back(Pair("bits", strprintf("%08x", block.nBits))); result.push_back(Pair("bits", strprintf("%08x", block.nBits)));
result.push_back(Pair("difficulty", GetDifficulty(blockindex))); result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex())); result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex()));
result.push_back(Pair("anchor", blockindex->hashAnchorEnd.GetHex())); result.push_back(Pair("anchor", blockindex->hashSproutAnchorEnd.GetHex()));
UniValue valuePools(UniValue::VARR); UniValue valuePools(UniValue::VARR);
valuePools.push_back(ValuePoolDesc("sprout", blockindex->nChainSproutValue, blockindex->nSproutValue)); valuePools.push_back(ValuePoolDesc("sprout", blockindex->nChainSproutValue, blockindex->nSproutValue));

View File

@@ -25,7 +25,7 @@ namespace
class CCoinsViewTest : public CCoinsView class CCoinsViewTest : public CCoinsView
{ {
uint256 hashBestBlock_; uint256 hashBestBlock_;
uint256 hashBestAnchor_; uint256 hashBestSproutAnchor_;
std::map<uint256, CCoins> map_; std::map<uint256, CCoins> map_;
std::map<uint256, ZCIncrementalMerkleTree> mapSproutAnchors_; std::map<uint256, ZCIncrementalMerkleTree> mapSproutAnchors_;
std::map<uint256, bool> mapSproutNullifiers_; std::map<uint256, bool> mapSproutNullifiers_;
@@ -33,7 +33,7 @@ class CCoinsViewTest : public CCoinsView
public: public:
CCoinsViewTest() { CCoinsViewTest() {
hashBestAnchor_ = ZCIncrementalMerkleTree::empty_root(); hashBestSproutAnchor_ = ZCIncrementalMerkleTree::empty_root();
} }
bool GetAnchorAt(const uint256& rt, ZCIncrementalMerkleTree &tree) const { bool GetAnchorAt(const uint256& rt, ZCIncrementalMerkleTree &tree) const {
@@ -75,7 +75,7 @@ public:
} }
} }
uint256 GetBestAnchor() const { return hashBestAnchor_; } uint256 GetBestAnchor() const { return hashBestSproutAnchor_; }
bool GetCoins(const uint256& txid, CCoins& coins) const bool GetCoins(const uint256& txid, CCoins& coins) const
{ {
@@ -114,7 +114,7 @@ public:
bool BatchWrite(CCoinsMap& mapCoins, bool BatchWrite(CCoinsMap& mapCoins,
const uint256& hashBlock, const uint256& hashBlock,
const uint256& hashAnchor, const uint256& hashSproutAnchor,
CAnchorsSproutMap& mapSproutAnchors, CAnchorsSproutMap& mapSproutAnchors,
CNullifiersMap& mapSproutNullifiers, CNullifiersMap& mapSproutNullifiers,
CNullifiersMap& mapSaplingNullifiers) CNullifiersMap& mapSaplingNullifiers)
@@ -145,7 +145,7 @@ public:
mapCoins.clear(); mapCoins.clear();
mapSproutAnchors.clear(); mapSproutAnchors.clear();
hashBestBlock_ = hashBlock; hashBestBlock_ = hashBlock;
hashBestAnchor_ = hashAnchor; hashBestSproutAnchor_ = hashSproutAnchor;
return true; return true;
} }

View File

@@ -26,7 +26,7 @@ static const char DB_TXINDEX = 't';
static const char DB_BLOCK_INDEX = 'b'; static const char DB_BLOCK_INDEX = 'b';
static const char DB_BEST_BLOCK = 'B'; static const char DB_BEST_BLOCK = 'B';
static const char DB_BEST_ANCHOR = 'a'; static const char DB_BEST_SPROUT_ANCHOR = 'a';
static const char DB_FLAG = 'F'; static const char DB_FLAG = 'F';
static const char DB_REINDEX_FLAG = 'R'; static const char DB_REINDEX_FLAG = 'R';
static const char DB_LAST_BLOCK = 'l'; static const char DB_LAST_BLOCK = 'l';
@@ -85,7 +85,7 @@ uint256 CCoinsViewDB::GetBestBlock() const {
uint256 CCoinsViewDB::GetBestAnchor() const { uint256 CCoinsViewDB::GetBestAnchor() const {
uint256 hashBestAnchor; uint256 hashBestAnchor;
if (!db.Read(DB_BEST_ANCHOR, hashBestAnchor)) if (!db.Read(DB_BEST_SPROUT_ANCHOR, hashBestAnchor))
return ZCIncrementalMerkleTree::empty_root(); return ZCIncrementalMerkleTree::empty_root();
return hashBestAnchor; return hashBestAnchor;
} }
@@ -107,7 +107,7 @@ void BatchWriteNullifiers(CDBBatch& batch, CNullifiersMap& mapToUse, const char&
bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock, const uint256 &hashBlock,
const uint256 &hashAnchor, const uint256 &hashSproutAnchor,
CAnchorsSproutMap &mapSproutAnchors, CAnchorsSproutMap &mapSproutAnchors,
CNullifiersMap &mapSproutNullifiers, CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers) { CNullifiersMap &mapSaplingNullifiers) {
@@ -145,8 +145,8 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins,
if (!hashBlock.IsNull()) if (!hashBlock.IsNull())
batch.Write(DB_BEST_BLOCK, hashBlock); batch.Write(DB_BEST_BLOCK, hashBlock);
if (!hashAnchor.IsNull()) if (!hashSproutAnchor.IsNull())
batch.Write(DB_BEST_ANCHOR, hashAnchor); batch.Write(DB_BEST_SPROUT_ANCHOR, hashSproutAnchor);
LogPrint("coindb", "Committing %u changed transactions (out of %u) to coin database...\n", (unsigned int)changed, (unsigned int)count); LogPrint("coindb", "Committing %u changed transactions (out of %u) to coin database...\n", (unsigned int)changed, (unsigned int)count);
return db.WriteBatch(batch); return db.WriteBatch(batch);
@@ -284,7 +284,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts()
pindexNew->nFile = diskindex.nFile; pindexNew->nFile = diskindex.nFile;
pindexNew->nDataPos = diskindex.nDataPos; pindexNew->nDataPos = diskindex.nDataPos;
pindexNew->nUndoPos = diskindex.nUndoPos; pindexNew->nUndoPos = diskindex.nUndoPos;
pindexNew->hashAnchor = diskindex.hashAnchor; pindexNew->hashSproutAnchor = diskindex.hashSproutAnchor;
pindexNew->nVersion = diskindex.nVersion; pindexNew->nVersion = diskindex.nVersion;
pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot; pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot;
pindexNew->hashReserved = diskindex.hashReserved; pindexNew->hashReserved = diskindex.hashReserved;

View File

@@ -43,7 +43,7 @@ public:
uint256 GetBestAnchor() const; uint256 GetBestAnchor() const;
bool BatchWrite(CCoinsMap &mapCoins, bool BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock, const uint256 &hashBlock,
const uint256 &hashAnchor, const uint256 &hashSproutAnchor,
CAnchorsSproutMap &mapSproutAnchors, CAnchorsSproutMap &mapSproutAnchors,
CNullifiersMap &mapSproutNullifiers, CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers); CNullifiersMap &mapSaplingNullifiers);

View File

@@ -1819,7 +1819,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
ZCIncrementalMerkleTree tree; ZCIncrementalMerkleTree tree;
// This should never fail: we should always be able to get the tree // This should never fail: we should always be able to get the tree
// state on the path to the tip of our chain // state on the path to the tip of our chain
assert(pcoinsTip->GetAnchorAt(pindex->hashAnchor, tree)); assert(pcoinsTip->GetAnchorAt(pindex->hashSproutAnchor, tree));
// Increment note witness caches // Increment note witness caches
IncrementNoteWitnesses(pindex, &block, tree); IncrementNoteWitnesses(pindex, &block, tree);