Browse Source

Rename GetAnchorAt to GetSproutAnchorAt.

pull/4/head
Sean Bowe 6 years ago
parent
commit
008f4ee8e7
  1. 12
      src/coins.cpp
  2. 6
      src/coins.h
  3. 2
      src/gtest/test_mempool.cpp
  4. 2
      src/gtest/test_validation.cpp
  5. 6
      src/main.cpp
  6. 2
      src/rpcblockchain.cpp
  7. 36
      src/test/coins_tests.cpp
  8. 2
      src/txdb.cpp
  9. 2
      src/txdb.h
  10. 2
      src/txmempool.cpp
  11. 2
      src/wallet/asyncrpcoperation_mergetoaddress.cpp
  12. 2
      src/wallet/asyncrpcoperation_sendmany.cpp
  13. 4
      src/wallet/wallet.cpp

12
src/coins.cpp

@ -42,7 +42,7 @@ bool CCoins::Spend(uint32_t nPos)
Cleanup();
return true;
}
bool CCoinsView::GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const { return false; }
bool CCoinsView::GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &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; }
bool CCoinsView::HaveCoins(const uint256 &txid) const { return false; }
@ -59,7 +59,7 @@ bool CCoinsView::GetStats(CCoinsStats &stats) const { return false; }
CCoinsViewBacked::CCoinsViewBacked(CCoinsView *viewIn) : base(viewIn) { }
bool CCoinsViewBacked::GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const { return base->GetAnchorAt(rt, tree); }
bool CCoinsViewBacked::GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const { return base->GetSproutAnchorAt(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); }
bool CCoinsViewBacked::HaveCoins(const uint256 &txid) const { return base->HaveCoins(txid); }
@ -110,7 +110,7 @@ CCoinsMap::const_iterator CCoinsViewCache::FetchCoins(const uint256 &txid) const
}
bool CCoinsViewCache::GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const {
bool CCoinsViewCache::GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const {
CAnchorsSproutMap::const_iterator it = cacheSproutAnchors.find(rt);
if (it != cacheSproutAnchors.end()) {
if (it->second.entered) {
@ -121,7 +121,7 @@ bool CCoinsViewCache::GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tr
}
}
if (!base->GetAnchorAt(rt, tree)) {
if (!base->GetSproutAnchorAt(rt, tree)) {
return false;
}
@ -196,7 +196,7 @@ void CCoinsViewCache::PopAnchor(const uint256 &newrt) {
// so that its tree exists in memory.
{
ZCIncrementalMerkleTree tree;
assert(GetAnchorAt(currentRoot, tree));
assert(GetSproutAnchorAt(currentRoot, tree));
}
// Mark the anchor as unentered, removing it from view
@ -441,7 +441,7 @@ bool CCoinsViewCache::HaveJoinSplitRequirements(const CTransaction& tx) const
auto it = intermediates.find(joinsplit.anchor);
if (it != intermediates.end()) {
tree = it->second;
} else if (!GetAnchorAt(joinsplit.anchor, tree)) {
} else if (!GetSproutAnchorAt(joinsplit.anchor, tree)) {
return false;
}

6
src/coins.h

@ -327,7 +327,7 @@ class CCoinsView
{
public:
//! Retrieve the tree at a particular anchored root in the chain
virtual bool GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const;
virtual bool GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const;
//! Determine whether a nullifier is spent or not
virtual bool GetNullifier(const uint256 &nullifier, ShieldedType type) const;
@ -370,7 +370,7 @@ protected:
public:
CCoinsViewBacked(CCoinsView *viewIn);
bool GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const;
bool GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const;
bool GetNullifier(const uint256 &nullifier, ShieldedType type) const;
bool GetCoins(const uint256 &txid, CCoins &coins) const;
bool HaveCoins(const uint256 &txid) const;
@ -436,7 +436,7 @@ public:
~CCoinsViewCache();
// Standard CCoinsView methods
bool GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const;
bool GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const;
bool GetNullifier(const uint256 &nullifier, ShieldedType type) const;
bool GetCoins(const uint256 &txid, CCoins &coins) const;
bool HaveCoins(const uint256 &txid) const;

2
src/gtest/test_mempool.cpp

@ -19,7 +19,7 @@ class FakeCoinsViewDB : public CCoinsView {
public:
FakeCoinsViewDB() {}
bool GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const {
bool GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const {
return false;
}

2
src/gtest/test_validation.cpp

@ -21,7 +21,7 @@ class FakeCoinsViewDB : public CCoinsView {
public:
FakeCoinsViewDB() {}
bool GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const {
bool GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const {
return false;
}

6
src/main.cpp

@ -2338,7 +2338,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
ZCIncrementalMerkleTree tree;
// This should never fail: we should always be able to get the root
// that is on the tip of our chain
assert(view.GetAnchorAt(old_tree_root, tree));
assert(view.GetSproutAnchorAt(old_tree_root, tree));
{
// Consistency check: the root of the tree we're given should
@ -2692,7 +2692,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
UpdateTip(pindexDelete->pprev);
// Get the current commitment tree
ZCIncrementalMerkleTree newTree;
assert(pcoinsTip->GetAnchorAt(pcoinsTip->GetBestAnchor(), newTree));
assert(pcoinsTip->GetSproutAnchorAt(pcoinsTip->GetBestAnchor(), newTree));
// Let wallets know transactions went from 1-confirmed to
// 0-confirmed or conflicted:
BOOST_FOREACH(const CTransaction &tx, block.vtx) {
@ -2726,7 +2726,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
}
// Get the current commitment tree
ZCIncrementalMerkleTree oldTree;
assert(pcoinsTip->GetAnchorAt(pcoinsTip->GetBestAnchor(), oldTree));
assert(pcoinsTip->GetSproutAnchorAt(pcoinsTip->GetBestAnchor(), oldTree));
// Apply the block atomically to the chain state.
int64_t nTime2 = GetTimeMicros(); nTimeReadFromDisk += nTime2 - nTime1;
int64_t nTime3;

2
src/rpcblockchain.cpp

@ -770,7 +770,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
obj.push_back(Pair("pruned", fPruneMode));
ZCIncrementalMerkleTree tree;
pcoinsTip->GetAnchorAt(pcoinsTip->GetBestAnchor(), tree);
pcoinsTip->GetSproutAnchorAt(pcoinsTip->GetBestAnchor(), tree);
obj.push_back(Pair("commitments", static_cast<uint64_t>(tree.size())));
CBlockIndex* tip = chainActive.Tip();

36
src/test/coins_tests.cpp

@ -36,7 +36,7 @@ public:
hashBestSproutAnchor_ = ZCIncrementalMerkleTree::empty_root();
}
bool GetAnchorAt(const uint256& rt, ZCIncrementalMerkleTree &tree) const {
bool GetSproutAnchorAt(const uint256& rt, ZCIncrementalMerkleTree &tree) const {
if (rt == ZCIncrementalMerkleTree::empty_root()) {
ZCIncrementalMerkleTree new_tree;
tree = new_tree;
@ -339,7 +339,7 @@ BOOST_AUTO_TEST_CASE(anchor_pop_regression_test)
// The base contains the anchor, of course!
{
ZCIncrementalMerkleTree checktree;
BOOST_CHECK(cache1.GetAnchorAt(tree.root(), checktree));
BOOST_CHECK(cache1.GetSproutAnchorAt(tree.root(), checktree));
BOOST_CHECK(checktree.root() == tree.root());
}
}
@ -372,7 +372,7 @@ BOOST_AUTO_TEST_CASE(anchor_pop_regression_test)
// treestate...
{
ZCIncrementalMerkleTree checktree;
BOOST_CHECK(cache1.GetAnchorAt(tree.root(), checktree));
BOOST_CHECK(cache1.GetSproutAnchorAt(tree.root(), checktree));
BOOST_CHECK(checktree.root() == tree.root()); // Oh, shucks.
}
@ -381,7 +381,7 @@ BOOST_AUTO_TEST_CASE(anchor_pop_regression_test)
cache1.Flush();
{
ZCIncrementalMerkleTree checktree;
BOOST_CHECK(cache1.GetAnchorAt(tree.root(), checktree));
BOOST_CHECK(cache1.GetSproutAnchorAt(tree.root(), checktree));
BOOST_CHECK(checktree.root() == tree.root()); // Oh, shucks.
}
}
@ -403,7 +403,7 @@ BOOST_AUTO_TEST_CASE(anchor_regression_test)
cache1.PopAnchor(ZCIncrementalMerkleTree::empty_root());
BOOST_CHECK(cache1.GetBestAnchor() == ZCIncrementalMerkleTree::empty_root());
BOOST_CHECK(!cache1.GetAnchorAt(tree.root(), tree));
BOOST_CHECK(!cache1.GetSproutAnchorAt(tree.root(), tree));
}
// Also correct behavior:
@ -421,7 +421,7 @@ BOOST_AUTO_TEST_CASE(anchor_regression_test)
cache1.PopAnchor(ZCIncrementalMerkleTree::empty_root());
cache1.Flush();
BOOST_CHECK(cache1.GetBestAnchor() == ZCIncrementalMerkleTree::empty_root());
BOOST_CHECK(!cache1.GetAnchorAt(tree.root(), tree));
BOOST_CHECK(!cache1.GetSproutAnchorAt(tree.root(), tree));
}
// Works because we bring the anchor in from parent cache.
@ -439,13 +439,13 @@ BOOST_AUTO_TEST_CASE(anchor_regression_test)
{
// Pop anchor.
CCoinsViewCacheTest cache2(&cache1);
BOOST_CHECK(cache2.GetAnchorAt(tree.root(), tree));
BOOST_CHECK(cache2.GetSproutAnchorAt(tree.root(), tree));
cache2.PopAnchor(ZCIncrementalMerkleTree::empty_root());
cache2.Flush();
}
BOOST_CHECK(cache1.GetBestAnchor() == ZCIncrementalMerkleTree::empty_root());
BOOST_CHECK(!cache1.GetAnchorAt(tree.root(), tree));
BOOST_CHECK(!cache1.GetSproutAnchorAt(tree.root(), tree));
}
// Was broken:
@ -468,7 +468,7 @@ BOOST_AUTO_TEST_CASE(anchor_regression_test)
}
BOOST_CHECK(cache1.GetBestAnchor() == ZCIncrementalMerkleTree::empty_root());
BOOST_CHECK(!cache1.GetAnchorAt(tree.root(), tree));
BOOST_CHECK(!cache1.GetSproutAnchorAt(tree.root(), tree));
}
}
@ -502,7 +502,7 @@ BOOST_AUTO_TEST_CASE(anchors_flush_test)
{
CCoinsViewCacheTest cache(&base);
ZCIncrementalMerkleTree tree;
BOOST_CHECK(cache.GetAnchorAt(cache.GetBestAnchor(), tree));
BOOST_CHECK(cache.GetSproutAnchorAt(cache.GetBestAnchor(), tree));
appendRandomCommitment(tree);
newrt = tree.root();
@ -514,10 +514,10 @@ BOOST_AUTO_TEST_CASE(anchors_flush_test)
{
CCoinsViewCacheTest cache(&base);
ZCIncrementalMerkleTree tree;
BOOST_CHECK(cache.GetAnchorAt(cache.GetBestAnchor(), tree));
BOOST_CHECK(cache.GetSproutAnchorAt(cache.GetBestAnchor(), tree));
// Get the cached entry.
BOOST_CHECK(cache.GetAnchorAt(cache.GetBestAnchor(), tree));
BOOST_CHECK(cache.GetSproutAnchorAt(cache.GetBestAnchor(), tree));
uint256 check_rt = tree.root();
@ -615,7 +615,7 @@ BOOST_AUTO_TEST_CASE(anchors_test)
{
ZCIncrementalMerkleTree tree;
BOOST_CHECK(cache.GetAnchorAt(cache.GetBestAnchor(), tree));
BOOST_CHECK(cache.GetSproutAnchorAt(cache.GetBestAnchor(), tree));
BOOST_CHECK(cache.GetBestAnchor() == tree.root());
appendRandomCommitment(tree);
appendRandomCommitment(tree);
@ -636,7 +636,7 @@ BOOST_AUTO_TEST_CASE(anchors_test)
{
ZCIncrementalMerkleTree confirm_same;
BOOST_CHECK(cache.GetAnchorAt(cache.GetBestAnchor(), confirm_same));
BOOST_CHECK(cache.GetSproutAnchorAt(cache.GetBestAnchor(), confirm_same));
BOOST_CHECK(confirm_same.root() == newrt);
}
@ -650,13 +650,13 @@ BOOST_AUTO_TEST_CASE(anchors_test)
BOOST_CHECK(cache.GetBestAnchor() == newrt2);
ZCIncrementalMerkleTree test_tree;
BOOST_CHECK(cache.GetAnchorAt(cache.GetBestAnchor(), test_tree));
BOOST_CHECK(cache.GetSproutAnchorAt(cache.GetBestAnchor(), test_tree));
BOOST_CHECK(tree.root() == test_tree.root());
{
ZCIncrementalMerkleTree test_tree2;
cache.GetAnchorAt(newrt, test_tree2);
cache.GetSproutAnchorAt(newrt, test_tree2);
BOOST_CHECK(test_tree2.root() == newrt);
}
@ -664,8 +664,8 @@ BOOST_AUTO_TEST_CASE(anchors_test)
{
cache.PopAnchor(newrt);
ZCIncrementalMerkleTree obtain_tree;
assert(!cache.GetAnchorAt(newrt2, obtain_tree)); // should have been popped off
assert(cache.GetAnchorAt(newrt, obtain_tree));
assert(!cache.GetSproutAnchorAt(newrt2, obtain_tree)); // should have been popped off
assert(cache.GetSproutAnchorAt(newrt, obtain_tree));
assert(obtain_tree.root() == newrt);
}

2
src/txdb.cpp

@ -40,7 +40,7 @@ CCoinsViewDB::CCoinsViewDB(size_t nCacheSize, bool fMemory, bool fWipe) : db(Get
}
bool CCoinsViewDB::GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const {
bool CCoinsViewDB::GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const {
if (rt == ZCIncrementalMerkleTree::empty_root()) {
ZCIncrementalMerkleTree new_tree;
tree = new_tree;

2
src/txdb.h

@ -35,7 +35,7 @@ protected:
public:
CCoinsViewDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
bool GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const;
bool GetSproutAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const;
bool GetNullifier(const uint256 &nf, ShieldedType type) const;
bool GetCoins(const uint256 &txid, CCoins &coins) const;
bool HaveCoins(const uint256 &txid) const;

2
src/txmempool.cpp

@ -402,7 +402,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
if (it != intermediates.end()) {
tree = it->second;
} else {
assert(pcoins->GetAnchorAt(joinsplit.anchor, tree));
assert(pcoins->GetSproutAnchorAt(joinsplit.anchor, tree));
}
BOOST_FOREACH(const uint256& commitment, joinsplit.commitments)

2
src/wallet/asyncrpcoperation_mergetoaddress.cpp

@ -429,7 +429,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
auto it = intermediates.find(prevJoinSplit.anchor);
if (it != intermediates.end()) {
tree = it->second;
} else if (!pcoinsTip->GetAnchorAt(prevJoinSplit.anchor, tree)) {
} else if (!pcoinsTip->GetSproutAnchorAt(prevJoinSplit.anchor, tree)) {
throw JSONRPCError(RPC_WALLET_ERROR, "Could not find previous JoinSplit anchor");
}

2
src/wallet/asyncrpcoperation_sendmany.cpp

@ -545,7 +545,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
auto it = intermediates.find(prevJoinSplit.anchor);
if (it != intermediates.end()) {
tree = it->second;
} else if (!pcoinsTip->GetAnchorAt(prevJoinSplit.anchor, tree)) {
} else if (!pcoinsTip->GetSproutAnchorAt(prevJoinSplit.anchor, tree)) {
throw JSONRPCError(RPC_WALLET_ERROR, "Could not find previous JoinSplit anchor");
}

4
src/wallet/wallet.cpp

@ -1765,7 +1765,7 @@ void CWallet::WitnessNoteCommitment(std::vector<uint256> commitments,
// Consistency check: we should be able to find the current tree
// in our CCoins view.
ZCIncrementalMerkleTree dummy_tree;
assert(pcoinsTip->GetAnchorAt(current_anchor, dummy_tree));
assert(pcoinsTip->GetSproutAnchorAt(current_anchor, dummy_tree));
pindex = chainActive.Next(pindex);
}
@ -1819,7 +1819,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
ZCIncrementalMerkleTree tree;
// 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->GetAnchorAt(pindex->hashSproutAnchor, tree));
assert(pcoinsTip->GetSproutAnchorAt(pindex->hashSproutAnchor, tree));
// Increment note witness caches
IncrementNoteWitnesses(pindex, &block, tree);

Loading…
Cancel
Save