diff --git a/src/coins.cpp b/src/coins.cpp index 602d153ec..03b046a70 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2012-2014 The Bitcoin Core developers -// Copyright (c) 2019 The Hush developers +// Copyright (c) 2019-2020 The Hush developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -65,7 +65,6 @@ bool CCoins::Spend(uint32_t nPos) Cleanup(); return true; } -bool CCoinsView::GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const { return false; } bool CCoinsView::GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const { return false; } bool CCoinsView::GetNullifier(const uint256 &nullifier, ShieldedType type) const { return false; } bool CCoinsView::GetCoins(const uint256 &txid, CCoins &coins) const { return false; } @@ -85,7 +84,6 @@ bool CCoinsView::GetStats(CCoinsStats &stats) const { return false; } CCoinsViewBacked::CCoinsViewBacked(CCoinsView *viewIn) : base(viewIn) { } -bool CCoinsViewBacked::GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const { return base->GetSproutAnchorAt(rt, tree); } bool CCoinsViewBacked::GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const { return base->GetSaplingAnchorAt(rt, tree); } bool CCoinsViewBacked::GetNullifier(const uint256 &nullifier, ShieldedType type) const { return base->GetNullifier(nullifier, type); } bool CCoinsViewBacked::GetCoins(const uint256 &txid, CCoins &coins) const { return base->GetCoins(txid, coins); } @@ -139,30 +137,6 @@ CCoinsMap::const_iterator CCoinsViewCache::FetchCoins(const uint256 &txid) const return ret; } - -bool CCoinsViewCache::GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const { - CAnchorsSproutMap::const_iterator it = cacheSproutAnchors.find(rt); - if (it != cacheSproutAnchors.end()) { - if (it->second.entered) { - tree = it->second.tree; - return true; - } else { - return false; - } - } - - if (!base->GetSproutAnchorAt(rt, tree)) { - return false; - } - - CAnchorsSproutMap::iterator ret = cacheSproutAnchors.insert(std::make_pair(rt, CAnchorsSproutCacheEntry())).first; - ret->second.entered = true; - ret->second.tree = tree; - cachedCoinsUsage += ret->second.tree.DynamicMemoryUsage(); - - return true; -} - bool CCoinsViewCache::GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const { CAnchorsSaplingMap::const_iterator it = cacheSaplingAnchors.find(rt); if (it != cacheSaplingAnchors.end()) { @@ -271,7 +245,6 @@ void CCoinsViewCache::BringBestAnchorIntoCache( SproutMerkleTree &tree ) { - assert(GetSproutAnchorAt(currentRoot, tree)); } template<> @@ -550,9 +523,9 @@ bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins, bool CCoinsViewCache::Flush() { bool fOk = base->BatchWrite(cacheCoins, hashBlock, hashSproutAnchor, hashSaplingAnchor, cacheSproutAnchors, cacheSaplingAnchors, cacheSproutNullifiers, cacheSaplingNullifiers); cacheCoins.clear(); - cacheSproutAnchors.clear(); + //cacheSproutAnchors.clear(); cacheSaplingAnchors.clear(); - cacheSproutNullifiers.clear(); + //cacheSproutNullifiers.clear(); cacheSaplingNullifiers.clear(); cachedCoinsUsage = 0; return fOk; diff --git a/src/coins.h b/src/coins.h index 1211e7e07..3e8f674fb 100644 --- a/src/coins.h +++ b/src/coins.h @@ -372,9 +372,6 @@ struct CCoinsStats class CCoinsView { public: - //! Retrieve the tree (Sprout) at a particular anchored root in the chain - virtual bool GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const; - //! Retrieve the tree (Sapling) at a particular anchored root in the chain virtual bool GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const; @@ -421,7 +418,6 @@ protected: public: CCoinsViewBacked(CCoinsView *viewIn); - bool GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const; bool GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const; bool GetNullifier(const uint256 &nullifier, ShieldedType type) const; bool GetCoins(const uint256 &txid, CCoins &coins) const; @@ -493,7 +489,6 @@ public: CNullifiersMap getNullifiers(); // Standard CCoinsView methods - bool GetSproutAnchorAt(const uint256 &rt, SproutMerkleTree &tree) const; bool GetSaplingAnchorAt(const uint256 &rt, SaplingMerkleTree &tree) const; bool GetNullifier(const uint256 &nullifier, ShieldedType type) const; bool GetCoins(const uint256 &txid, CCoins &coins) const; diff --git a/src/main.cpp b/src/main.cpp index 2532dd2b1..6ca7b68a2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3493,13 +3493,13 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin // This should never fail: we should always be able to get the root // that is on the tip of our chain - assert(view.GetSproutAnchorAt(old_sprout_tree_root, sprout_tree)); + //assert(view.GetSproutAnchorAt(old_sprout_tree_root, sprout_tree)); - { + //{ // Consistency check: the root of the tree we're given should // match what we asked for. - assert(sprout_tree.root() == old_sprout_tree_root); - } + //assert(sprout_tree.root() == old_sprout_tree_root); + //} SaplingMerkleTree sapling_tree; assert(view.GetSaplingAnchorAt(view.GetBestAnchor(SAPLING), sapling_tree)); @@ -3636,6 +3636,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin } UpdateCoins(tx, view, i == 0 ? undoDummy : blockundo.vtxundo.back(), pindex->GetHeight()); + /* BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { BOOST_FOREACH(const uint256 ¬e_commitment, joinsplit.commitments) { // Insert the note commitments into our temporary tree. @@ -3643,6 +3644,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin sprout_tree.append(note_commitment); } } + */ BOOST_FOREACH(const OutputDescription &outputDescription, tx.vShieldedOutput) { sapling_tree.append(outputDescription.cm); @@ -3652,7 +3654,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION); } - view.PushAnchor(sprout_tree); + //view.PushAnchor(sprout_tree); view.PushAnchor(sapling_tree); if (!fJustCheck) { pindex->hashFinalSproutRoot = sprout_tree.root(); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 76375b80c..faed5b957 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1668,9 +1668,10 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp, const CPubKey& my obj.push_back(Pair("chainwork", chainActive.LastTip()->chainPower.chainWork.GetHex())); obj.push_back(Pair("pruned", fPruneMode)); - SproutMerkleTree tree; - pcoinsTip->GetSproutAnchorAt(pcoinsTip->GetBestAnchor(SPROUT), tree); - obj.push_back(Pair("commitments", static_cast(tree.size()))); + //SproutMerkleTree tree; + //pcoinsTip->GetSproutAnchorAt(pcoinsTip->GetBestAnchor(SPROUT), tree); + //obj.push_back(Pair("commitments", static_cast(tree.size()))); + obj.push_back(Pair("commitments", 0)); CBlockIndex* tip = chainActive.LastTip(); UniValue valuePools(UniValue::VARR); diff --git a/src/txmempool.cpp b/src/txmempool.cpp index ca0ed7f51..2f10856d4 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -644,8 +644,9 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const i++; } - boost::unordered_map intermediates; + /* + boost::unordered_map intermediates; BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) { assert(!pcoins->GetNullifier(nf, SPROUT)); @@ -666,6 +667,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const intermediates.insert(std::make_pair(tree.root(), tree)); } + */ for (const SpendDescription &spendDescription : tx.vShieldedSpend) { SaplingMerkleTree tree; diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp index 799a60ceb..44b5115d6 100644 --- a/src/validationinterface.cpp +++ b/src/validationinterface.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2019-2020 The Hush developers // Distributed under the MIT software license, see the accompanying // file COPYING or https://www.opensource.org/licenses/mit-license.php . @@ -138,7 +139,8 @@ void ThreadNotifyWallets(CBlockIndex *pindexLastTip) while (pindex && pindex != pindexFork) { // Get the Sprout commitment tree as of the start of this block. SproutMerkleTree oldSproutTree; - assert(pcoinsTip->GetSproutAnchorAt(pindex->hashSproutAnchor, oldSproutTree)); + //TODO: how important is oldSproutTree ? + //assert(pcoinsTip->GetSproutAnchorAt(pindex->hashSproutAnchor, oldSproutTree)); // Get the Sapling commitment tree as of the start of this block. // We can get this from the `hashFinalSaplingRoot` of the last block diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 725f04764..b492ee8a2 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2334,57 +2334,6 @@ void CWallet::WitnessNoteCommitment(std::vector commitments, std::vector>& witnesses, uint256 &final_anchor) { - witnesses.resize(commitments.size()); - CBlockIndex* pindex = chainActive.Genesis(); - SproutMerkleTree tree; - - while (pindex) { - CBlock block; - ReadBlockFromDisk(block, pindex,1); - - BOOST_FOREACH(const CTransaction& tx, block.vtx) - { - BOOST_FOREACH(const JSDescription& jsdesc, tx.vjoinsplit) - { - BOOST_FOREACH(const uint256 ¬e_commitment, jsdesc.commitments) - { - tree.append(note_commitment); - - BOOST_FOREACH(boost::optional& wit, witnesses) { - if (wit) { - wit->append(note_commitment); - } - } - - size_t i = 0; - BOOST_FOREACH(uint256& commitment, commitments) { - if (note_commitment == commitment) { - witnesses.at(i) = tree.witness(); - } - i++; - } - } - } - } - - uint256 current_anchor = tree.root(); - - // Consistency check: we should be able to find the current tree - // in our CCoins view. - SproutMerkleTree dummy_tree; - assert(pcoinsTip->GetSproutAnchorAt(current_anchor, dummy_tree)); - - pindex = chainActive.Next(pindex); - } - - // TODO: #93; Select a root via some heuristic. - final_anchor = tree.root(); - - BOOST_FOREACH(boost::optional& wit, witnesses) { - if (wit) { - assert(final_anchor == wit->root()); - } - } } /** @@ -2697,11 +2646,11 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) } } - SproutMerkleTree sproutTree; + //SproutMerkleTree sproutTree; SaplingMerkleTree saplingTree; // This should never fail: we should always be able to get the tree // state on the path to the tip of our chain - assert(pcoinsTip->GetSproutAnchorAt(pindex->hashSproutAnchor, sproutTree)); + //assert(pcoinsTip->GetSproutAnchorAt(pindex->hashSproutAnchor, sproutTree)); if (pindex->pprev) { if (NetworkUpgradeActive(pindex->pprev->GetHeight(), Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) { assert(pcoinsTip->GetSaplingAnchorAt(pindex->pprev->hashFinalSaplingRoot, saplingTree));