Skip to content

Commit 24e44c3

Browse files
committed
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.
1 parent bea5b00 commit 24e44c3

File tree

5 files changed

+10
-2
lines changed

5 files changed

+10
-2
lines changed

src/coins.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ class CCoinsViewCache : public CCoinsViewBacked
212212
uint256 GetBestBlock() const;
213213
void SetBestBlock(const uint256 &hashBlock);
214214
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock);
215+
CCoinsViewCursor* Cursor() const {
216+
throw std::logic_error("CCoinsViewCache cursor iteration not supported.");
217+
}
215218

216219
/**
217220
* Check if we have the given utxo already loaded in this cache.

src/init.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ class CCoinsViewErrorCatcher : public CCoinsViewBacked
162162
// Writes do not need similar protection, as failure to write is handled by the caller.
163163
};
164164

165-
static CCoinsViewDB *pcoinsdbview = NULL;
166165
static CCoinsViewErrorCatcher *pcoinscatcher = NULL;
167166
static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle;
168167

src/rpc/blockchain.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "rpc/server.h"
2020
#include "streams.h"
2121
#include "sync.h"
22+
#include "txdb.h"
2223
#include "txmempool.h"
2324
#include "util.h"
2425
#include "utilstrencodings.h"
@@ -917,7 +918,7 @@ UniValue gettxoutsetinfo(const JSONRPCRequest& request)
917918

918919
CCoinsStats stats;
919920
FlushStateToDisk();
920-
if (GetUTXOStats(pcoinsTip, stats)) {
921+
if (GetUTXOStats(pcoinsdbview, stats)) {
921922
ret.push_back(Pair("height", (int64_t)stats.nHeight));
922923
ret.push_back(Pair("bestblock", stats.hashBlock.GetHex()));
923924
ret.push_back(Pair("transactions", (int64_t)stats.nTransactions));

src/validation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& loc
175175
return chain.Genesis();
176176
}
177177

178+
CCoinsViewDB *pcoinsdbview = NULL;
178179
CCoinsViewCache *pcoinsTip = NULL;
179180
CBlockTreeDB *pblocktree = NULL;
180181

src/validation.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class CBlockIndex;
3636
class CBlockTreeDB;
3737
class CBloomFilter;
3838
class CChainParams;
39+
class CCoinsViewDB;
3940
class CInv;
4041
class CConnman;
4142
class CScriptCheck;
@@ -482,6 +483,9 @@ bool ResetBlockFailureFlags(CBlockIndex *pindex);
482483
/** The currently-connected chain of blocks (protected by cs_main). */
483484
extern CChain chainActive;
484485

486+
/** Global variable that points to the coins database (protected by cs_main) */
487+
extern CCoinsViewDB *pcoinsdbview;
488+
485489
/** Global variable that points to the active CCoinsView (protected by cs_main) */
486490
extern CCoinsViewCache *pcoinsTip;
487491

0 commit comments

Comments
 (0)