Skip to content

Commit b7296bc

Browse files
committed
Merge #10550: Don't return stale data from CCoinsViewCache::Cursor()
3ff1fa8 Use override keyword on CCoinsView overrides (Russell Yanofsky) 24e44c3 Don't return stale data from CCoinsViewCache::Cursor() (Russell Yanofsky) Tree-SHA512: 08699dae0925ffb9c018f02612ac6b7eaf73ec331e2f4f934f1fe25a2ce120735fa38596926e924897c203f7470e99f0a99cf70d2ce31ff428b105e16583a861
2 parents ad1a13e + 3ff1fa8 commit b7296bc

File tree

6 files changed

+18
-10
lines changed

6 files changed

+18
-10
lines changed

src/coins.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,14 @@ class CCoinsViewCache : public CCoinsViewBacked
206206
CCoinsViewCache(CCoinsView *baseIn);
207207

208208
// Standard CCoinsView methods
209-
bool GetCoin(const COutPoint &outpoint, Coin &coin) const;
210-
bool HaveCoin(const COutPoint &outpoint) const;
211-
uint256 GetBestBlock() const;
209+
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override;
210+
bool HaveCoin(const COutPoint &outpoint) const override;
211+
uint256 GetBestBlock() const override;
212212
void SetBestBlock(const uint256 &hashBlock);
213-
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock);
213+
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) override;
214+
CCoinsViewCursor* Cursor() const override {
215+
throw std::logic_error("CCoinsViewCache cursor iteration not supported.");
216+
}
214217

215218
/**
216219
* 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
@@ -161,7 +161,6 @@ class CCoinsViewErrorCatcher : public CCoinsViewBacked
161161
// Writes do not need similar protection, as failure to write is handled by the caller.
162162
};
163163

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

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"
@@ -921,7 +922,7 @@ UniValue gettxoutsetinfo(const JSONRPCRequest& request)
921922

922923
CCoinsStats stats;
923924
FlushStateToDisk();
924-
if (GetUTXOStats(pcoinsTip, stats)) {
925+
if (GetUTXOStats(pcoinsdbview, stats)) {
925926
ret.push_back(Pair("height", (int64_t)stats.nHeight));
926927
ret.push_back(Pair("bestblock", stats.hashBlock.GetHex()));
927928
ret.push_back(Pair("transactions", (int64_t)stats.nTransactions));

src/test/coins_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class CCoinsViewTest : public CCoinsView
3636
std::map<COutPoint, Coin> map_;
3737

3838
public:
39-
bool GetCoin(const COutPoint& outpoint, Coin& coin) const
39+
bool GetCoin(const COutPoint& outpoint, Coin& coin) const override
4040
{
4141
std::map<COutPoint, Coin>::const_iterator it = map_.find(outpoint);
4242
if (it == map_.end()) {
@@ -50,15 +50,15 @@ class CCoinsViewTest : public CCoinsView
5050
return true;
5151
}
5252

53-
bool HaveCoin(const COutPoint& outpoint) const
53+
bool HaveCoin(const COutPoint& outpoint) const override
5454
{
5555
Coin coin;
5656
return GetCoin(outpoint, coin);
5757
}
5858

59-
uint256 GetBestBlock() const { return hashBestBlock_; }
59+
uint256 GetBestBlock() const override { return hashBestBlock_; }
6060

61-
bool BatchWrite(CCoinsMap& mapCoins, const uint256& hashBlock)
61+
bool BatchWrite(CCoinsMap& mapCoins, const uint256& hashBlock) override
6262
{
6363
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end(); ) {
6464
if (it->second.flags & CCoinsCacheEntry::DIRTY) {

src/validation.cpp

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

177+
CCoinsViewDB *pcoinsdbview = NULL;
177178
CCoinsViewCache *pcoinsTip = NULL;
178179
CBlockTreeDB *pblocktree = NULL;
179180

src/validation.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class CBlockIndex;
3434
class CBlockTreeDB;
3535
class CBloomFilter;
3636
class CChainParams;
37+
class CCoinsViewDB;
3738
class CInv;
3839
class CConnman;
3940
class CScriptCheck;
@@ -440,6 +441,9 @@ bool ResetBlockFailureFlags(CBlockIndex *pindex);
440441
/** The currently-connected chain of blocks (protected by cs_main). */
441442
extern CChain chainActive;
442443

444+
/** Global variable that points to the coins database (protected by cs_main) */
445+
extern CCoinsViewDB *pcoinsdbview;
446+
443447
/** Global variable that points to the active CCoinsView (protected by cs_main) */
444448
extern CCoinsViewCache *pcoinsTip;
445449

0 commit comments

Comments
 (0)