diff --git a/src/coins.cpp b/src/coins.cpp index d177b8eef..2e68a8ea1 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -386,6 +386,8 @@ CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx) const bool CCoinsViewCache::HavePourRequirements(const CTransaction& tx) const { + boost::unordered_map intermediates; + BOOST_FOREACH(const CPourTx &pour, tx.vpour) { BOOST_FOREACH(const uint256& serial, pour.serials) @@ -398,11 +400,19 @@ bool CCoinsViewCache::HavePourRequirements(const CTransaction& tx) const } ZCIncrementalMerkleTree tree; - if (!GetAnchorAt(pour.anchor, tree)) { - // If we do not have the anchor for the pour, - // it is invalid. + auto it = intermediates.find(pour.anchor); + if (it != intermediates.end()) { + tree = it->second; + } else if (!GetAnchorAt(pour.anchor, tree)) { return false; } + + BOOST_FOREACH(const uint256& commitment, pour.commitments) + { + tree.append(commitment); + } + + intermediates.insert(std::make_pair(tree.root(), tree)); } return true;