Browse Source

Don't return stale data from CCoinsViewCache::Cursor()

CCoinsViewCache doesn't actually support cursor iteration returning the
current contents of the cache, so raise an error when the cursor method is
called instead of returning a cursor that iterates over stale data.

Also update the gettxoutsetinfo RPC which was relying on the old behavior to be
explicit about which view it is returning data about.
0.15
Russell Yanofsky 7 years ago
parent
commit
24e44c354d
  1. 3
      src/coins.h
  2. 1
      src/init.cpp
  3. 3
      src/rpc/blockchain.cpp
  4. 1
      src/validation.cpp
  5. 4
      src/validation.h

3
src/coins.h

@ -212,6 +212,9 @@ public:
uint256 GetBestBlock() const; uint256 GetBestBlock() const;
void SetBestBlock(const uint256 &hashBlock); void SetBestBlock(const uint256 &hashBlock);
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock); bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock);
CCoinsViewCursor* Cursor() const {
throw std::logic_error("CCoinsViewCache cursor iteration not supported.");
}
/** /**
* Check if we have the given utxo already loaded in this cache. * Check if we have the given utxo already loaded in this cache.

1
src/init.cpp

@ -162,7 +162,6 @@ public:
// Writes do not need similar protection, as failure to write is handled by the caller. // Writes do not need similar protection, as failure to write is handled by the caller.
}; };
static CCoinsViewDB *pcoinsdbview = NULL;
static CCoinsViewErrorCatcher *pcoinscatcher = NULL; static CCoinsViewErrorCatcher *pcoinscatcher = NULL;
static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle; static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle;

3
src/rpc/blockchain.cpp

@ -19,6 +19,7 @@
#include "rpc/server.h" #include "rpc/server.h"
#include "streams.h" #include "streams.h"
#include "sync.h" #include "sync.h"
#include "txdb.h"
#include "txmempool.h" #include "txmempool.h"
#include "util.h" #include "util.h"
#include "utilstrencodings.h" #include "utilstrencodings.h"
@ -917,7 +918,7 @@ UniValue gettxoutsetinfo(const JSONRPCRequest& request)
CCoinsStats stats; CCoinsStats stats;
FlushStateToDisk(); FlushStateToDisk();
if (GetUTXOStats(pcoinsTip, stats)) { if (GetUTXOStats(pcoinsdbview, stats)) {
ret.push_back(Pair("height", (int64_t)stats.nHeight)); ret.push_back(Pair("height", (int64_t)stats.nHeight));
ret.push_back(Pair("bestblock", stats.hashBlock.GetHex())); ret.push_back(Pair("bestblock", stats.hashBlock.GetHex()));
ret.push_back(Pair("transactions", (int64_t)stats.nTransactions)); ret.push_back(Pair("transactions", (int64_t)stats.nTransactions));

1
src/validation.cpp

@ -175,6 +175,7 @@ CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& loc
return chain.Genesis(); return chain.Genesis();
} }
CCoinsViewDB *pcoinsdbview = NULL;
CCoinsViewCache *pcoinsTip = NULL; CCoinsViewCache *pcoinsTip = NULL;
CBlockTreeDB *pblocktree = NULL; CBlockTreeDB *pblocktree = NULL;

4
src/validation.h

@ -36,6 +36,7 @@ class CBlockIndex;
class CBlockTreeDB; class CBlockTreeDB;
class CBloomFilter; class CBloomFilter;
class CChainParams; class CChainParams;
class CCoinsViewDB;
class CInv; class CInv;
class CConnman; class CConnman;
class CScriptCheck; class CScriptCheck;
@ -482,6 +483,9 @@ bool ResetBlockFailureFlags(CBlockIndex *pindex);
/** The currently-connected chain of blocks (protected by cs_main). */ /** The currently-connected chain of blocks (protected by cs_main). */
extern CChain chainActive; extern CChain chainActive;
/** Global variable that points to the coins database (protected by cs_main) */
extern CCoinsViewDB *pcoinsdbview;
/** Global variable that points to the active CCoinsView (protected by cs_main) */ /** Global variable that points to the active CCoinsView (protected by cs_main) */
extern CCoinsViewCache *pcoinsTip; extern CCoinsViewCache *pcoinsTip;

Loading…
Cancel
Save