Skip to content

Commit 767bb7d

Browse files
committed
Merge #21270: [Bundle 4/n] Prune g_chainman usage in validation-adjacent modules
a67983c net_processing: Add review-only assertion to PeerManager (Carl Dong) 272d993 scripted-diff: net_processing: Use existing chainman (Carl Dong) 021a04a net_processing: Move some static functions to PeerManager (Carl Dong) 91c5b68 node/ifaces: ChainImpl: Use existing NodeContext member (Carl Dong) 8a1d580 node/ifaces: NodeImpl: Use existing NodeContext member (Carl Dong) 4cde4a7 node: Use existing NodeContext (Carl Dong) 106bcd4 node/coinstats: Pass in BlockManager to GetUTXOStats (Carl Dong) 2c3ba00 miner: Pass in blockman to ::RegenerateCommitments (Carl Dong) 2afcf24 miner: Remove old CreateNewBlock w/o chainstate param (Carl Dong) 46b7f29 scripted-diff: Invoke CreateNewBlock with chainstate (Carl Dong) d0de61b miner: Pass in chainstate to BlockAssembler::CreateNewBlock (Carl Dong) a04aac4 validation: Remove extraneous LoadGenesisBlock function prototype (Carl Dong) Pull request description: Overall PR: #20158 (tree-wide: De-globalize ChainstateManager) Based on: - [x] #21055 | [Bundle 3/n] Prune g_chainman usage in mempool-related validation functions Note to reviewers: 1. This bundle may _apparently_ introduce usage of `g_chainman` or `::Chain(state|)Active()` globals, but these are resolved later on in the overall PR. [Commits of overall PR](https://github.com/bitcoin/bitcoin/pull/20158/commits) 2. There may be seemingly obvious local references to `ChainstateManager` or other validation objects which are not being used in callers of the current function in question, this is done intentionally to **_keep each commit centered around one function/method_** to ease review and to make the overall change systematic. We don't assume anything about our callers. Rest assured that once we are considering that particular caller in later commits, we will use the obvious local references. [Commits of overall PR](https://github.com/bitcoin/bitcoin/pull/20158/commits) 3. When changing a function/method that has many callers (e.g. `LookupBlockIndex` with 55 callers), it is sometimes easier (and less error-prone) to use a scripted-diff. When doing so, there will be 3 commits in sequence so that every commit compiles like so: 1. Add `new_function`, make `old_function` a wrapper of `new_function`, divert all calls to `old_function` to `new_function` **in the local module only** 2. Scripted-diff to divert all calls to `old_function` to `new_function` **in the rest of the codebase** 3. Remove `old_function` ACKs for top commit: laanwj: Code review ACK a67983c ryanofsky: Code review ACK a67983c. Only change since last review new first commit fixing header declaration, and rebase glozow: code review ACK a67983c Tree-SHA512: dce182a18b88be80cbf50978d4ba8fa6ab0f01e861d09bae0ae9364051bb78f9334859d164b185b07f1d70a583e739557fab6d820cac8c37b3855b85c2a6771b
2 parents 63314b8 + a67983c commit 767bb7d

18 files changed

+228
-184
lines changed

src/miner.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParam
3939
return nNewTime - nOldTime;
4040
}
4141

42-
void RegenerateCommitments(CBlock& block)
42+
void RegenerateCommitments(CBlock& block, BlockManager& blockman)
4343
{
4444
CMutableTransaction tx{*block.vtx.at(0)};
4545
tx.vout.erase(tx.vout.begin() + GetWitnessCommitmentIndex(block));
4646
block.vtx.at(0) = MakeTransactionRef(tx);
4747

48-
GenerateCoinbaseCommitment(block, WITH_LOCK(cs_main, return g_chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock)), Params().GetConsensus());
48+
GenerateCoinbaseCommitment(block, WITH_LOCK(::cs_main, assert(std::addressof(g_chainman.m_blockman) == std::addressof(blockman)); return blockman.LookupBlockIndex(block.hashPrevBlock)), Params().GetConsensus());
4949

5050
block.hashMerkleRoot = BlockMerkleRoot(block);
5151
}
@@ -99,7 +99,7 @@ void BlockAssembler::resetBlock()
9999
Optional<int64_t> BlockAssembler::m_last_block_num_txs{nullopt};
100100
Optional<int64_t> BlockAssembler::m_last_block_weight{nullopt};
101101

102-
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn)
102+
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(CChainState& chainstate, const CScript& scriptPubKeyIn)
103103
{
104104
int64_t nTimeStart = GetTimeMicros();
105105

@@ -117,7 +117,8 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
117117
pblocktemplate->vTxSigOpsCost.push_back(-1); // updated at end
118118

119119
LOCK2(cs_main, m_mempool.cs);
120-
CBlockIndex* pindexPrev = ::ChainActive().Tip();
120+
assert(std::addressof(*::ChainActive().Tip()) == std::addressof(*chainstate.m_chain.Tip()));
121+
CBlockIndex* pindexPrev = chainstate.m_chain.Tip();
121122
assert(pindexPrev != nullptr);
122123
nHeight = pindexPrev->nHeight + 1;
123124

@@ -176,7 +177,8 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
176177
pblocktemplate->vTxSigOpsCost[0] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount(*pblock->vtx[0]);
177178

178179
BlockValidationState state;
179-
if (!TestBlockValidity(state, chainparams, ::ChainstateActive(), *pblock, pindexPrev, false, false)) {
180+
assert(std::addressof(::ChainstateActive()) == std::addressof(chainstate));
181+
if (!TestBlockValidity(state, chainparams, chainstate, *pblock, pindexPrev, false, false)) {
180182
throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", __func__, state.ToString()));
181183
}
182184
int64_t nTime2 = GetTimeMicros();

src/miner.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class BlockAssembler
158158
explicit BlockAssembler(const CTxMemPool& mempool, const CChainParams& params, const Options& options);
159159

160160
/** Construct a new block template with coinbase to scriptPubKeyIn */
161-
std::unique_ptr<CBlockTemplate> CreateNewBlock(const CScript& scriptPubKeyIn);
161+
std::unique_ptr<CBlockTemplate> CreateNewBlock(CChainState& chainstate, const CScript& scriptPubKeyIn);
162162

163163
static Optional<int64_t> m_last_block_num_txs;
164164
static Optional<int64_t> m_last_block_weight;
@@ -202,6 +202,6 @@ void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned
202202
int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev);
203203

204204
/** Update an old GenerateCoinbaseCommitment from CreateNewBlock after the block txs have changed */
205-
void RegenerateCommitments(CBlock& block);
205+
void RegenerateCommitments(CBlock& block, BlockManager& blockman);
206206

207207
#endif // BITCOIN_MINER_H

src/net_processing.cpp

Lines changed: 130 additions & 112 deletions
Large diffs are not rendered by default.

src/node/coin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ void FindCoins(const NodeContext& node, std::map<COutPoint, Coin>& coins)
1212
{
1313
assert(node.mempool);
1414
LOCK2(cs_main, node.mempool->cs);
15-
CCoinsViewCache& chain_view = ::ChainstateActive().CoinsTip();
15+
assert(std::addressof(::ChainstateActive()) == std::addressof(node.chainman->ActiveChainstate()));
16+
CCoinsViewCache& chain_view = node.chainman->ActiveChainstate().CoinsTip();
1617
CCoinsViewMemPool mempool_view(&chain_view, *node.mempool);
1718
for (auto& coin : coins) {
1819
if (!mempool_view.GetCoin(coin.first, coin.second)) {

src/node/coinstats.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static void ApplyStats(CCoinsStats& stats, T& hash_obj, const uint256& hash, con
8383

8484
//! Calculate statistics about the unspent transaction output set
8585
template <typename T>
86-
static bool GetUTXOStats(CCoinsView* view, CCoinsStats& stats, T hash_obj, const std::function<void()>& interruption_point)
86+
static bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, T hash_obj, const std::function<void()>& interruption_point)
8787
{
8888
stats = CCoinsStats();
8989
std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor());
@@ -92,7 +92,8 @@ static bool GetUTXOStats(CCoinsView* view, CCoinsStats& stats, T hash_obj, const
9292
stats.hashBlock = pcursor->GetBestBlock();
9393
{
9494
LOCK(cs_main);
95-
stats.nHeight = g_chainman.m_blockman.LookupBlockIndex(stats.hashBlock)->nHeight;
95+
assert(std::addressof(g_chainman.m_blockman) == std::addressof(blockman));
96+
stats.nHeight = blockman.LookupBlockIndex(stats.hashBlock)->nHeight;
9697
}
9798

9899
PrepareHash(hash_obj, stats);
@@ -126,19 +127,19 @@ static bool GetUTXOStats(CCoinsView* view, CCoinsStats& stats, T hash_obj, const
126127
return true;
127128
}
128129

129-
bool GetUTXOStats(CCoinsView* view, CCoinsStats& stats, CoinStatsHashType hash_type, const std::function<void()>& interruption_point)
130+
bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, CoinStatsHashType hash_type, const std::function<void()>& interruption_point)
130131
{
131132
switch (hash_type) {
132133
case(CoinStatsHashType::HASH_SERIALIZED): {
133134
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
134-
return GetUTXOStats(view, stats, ss, interruption_point);
135+
return GetUTXOStats(view, blockman, stats, ss, interruption_point);
135136
}
136137
case(CoinStatsHashType::MUHASH): {
137138
MuHash3072 muhash;
138-
return GetUTXOStats(view, stats, muhash, interruption_point);
139+
return GetUTXOStats(view, blockman, stats, muhash, interruption_point);
139140
}
140141
case(CoinStatsHashType::NONE): {
141-
return GetUTXOStats(view, stats, nullptr, interruption_point);
142+
return GetUTXOStats(view, blockman, stats, nullptr, interruption_point);
142143
}
143144
} // no default case, so the compiler can warn about missing cases
144145
assert(false);

src/node/coinstats.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <amount.h>
1010
#include <uint256.h>
11+
#include <validation.h>
1112

1213
#include <cstdint>
1314
#include <functional>
@@ -36,6 +37,6 @@ struct CCoinsStats
3637
};
3738

3839
//! Calculate statistics about the unspent transaction output set
39-
bool GetUTXOStats(CCoinsView* view, CCoinsStats& stats, const CoinStatsHashType hash_type, const std::function<void()>& interruption_point = {});
40+
bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, const CoinStatsHashType hash_type, const std::function<void()>& interruption_point = {});
4041

4142
#endif // BITCOIN_NODE_COINSTATS_H

src/node/interfaces.cpp

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,21 @@ class NodeImpl : public Node
182182
int getNumBlocks() override
183183
{
184184
LOCK(::cs_main);
185-
return ::ChainActive().Height();
185+
assert(std::addressof(::ChainActive()) == std::addressof(m_context->chainman->ActiveChain()));
186+
return m_context->chainman->ActiveChain().Height();
186187
}
187188
uint256 getBestBlockHash() override
188189
{
189-
const CBlockIndex* tip = WITH_LOCK(::cs_main, return ::ChainActive().Tip());
190+
assert(std::addressof(::ChainActive()) == std::addressof(m_context->chainman->ActiveChain()));
191+
const CBlockIndex* tip = WITH_LOCK(::cs_main, return m_context->chainman->ActiveChain().Tip());
190192
return tip ? tip->GetBlockHash() : Params().GenesisBlock().GetHash();
191193
}
192194
int64_t getLastBlockTime() override
193195
{
194196
LOCK(::cs_main);
195-
if (::ChainActive().Tip()) {
196-
return ::ChainActive().Tip()->GetBlockTime();
197+
assert(std::addressof(::ChainActive()) == std::addressof(m_context->chainman->ActiveChain()));
198+
if (m_context->chainman->ActiveChain().Tip()) {
199+
return m_context->chainman->ActiveChain().Tip()->GetBlockTime();
197200
}
198201
return Params().GenesisBlock().GetBlockTime(); // Genesis block's time of current network
199202
}
@@ -202,11 +205,15 @@ class NodeImpl : public Node
202205
const CBlockIndex* tip;
203206
{
204207
LOCK(::cs_main);
205-
tip = ::ChainActive().Tip();
208+
assert(std::addressof(::ChainActive()) == std::addressof(m_context->chainman->ActiveChain()));
209+
tip = m_context->chainman->ActiveChain().Tip();
206210
}
207211
return GuessVerificationProgress(Params().TxData(), tip);
208212
}
209-
bool isInitialBlockDownload() override { return ::ChainstateActive().IsInitialBlockDownload(); }
213+
bool isInitialBlockDownload() override {
214+
assert(std::addressof(::ChainstateActive()) == std::addressof(m_context->chainman->ActiveChainstate()));
215+
return m_context->chainman->ActiveChainstate().IsInitialBlockDownload();
216+
}
210217
bool getReindex() override { return ::fReindex; }
211218
bool getImporting() override { return ::fImporting; }
212219
void setNetworkActive(bool active) override
@@ -231,7 +238,8 @@ class NodeImpl : public Node
231238
bool getUnspentOutput(const COutPoint& output, Coin& coin) override
232239
{
233240
LOCK(::cs_main);
234-
return ::ChainstateActive().CoinsTip().GetCoin(output, coin);
241+
assert(std::addressof(::ChainstateActive()) == std::addressof(m_context->chainman->ActiveChainstate()));
242+
return m_context->chainman->ActiveChainstate().CoinsTip().GetCoin(output, coin);
235243
}
236244
WalletClient& walletClient() override
237245
{
@@ -441,13 +449,15 @@ class ChainImpl : public Chain
441449
bool checkFinalTx(const CTransaction& tx) override
442450
{
443451
LOCK(cs_main);
444-
return CheckFinalTx(::ChainActive().Tip(), tx);
452+
assert(std::addressof(::ChainActive()) == std::addressof(m_node.chainman->ActiveChain()));
453+
return CheckFinalTx(m_node.chainman->ActiveChain().Tip(), tx);
445454
}
446455
Optional<int> findLocatorFork(const CBlockLocator& locator) override
447456
{
448457
LOCK(cs_main);
449458
const CChain& active = Assert(m_node.chainman)->ActiveChain();
450-
if (CBlockIndex* fork = g_chainman.m_blockman.FindForkInGlobalIndex(active, locator)) {
459+
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
460+
if (CBlockIndex* fork = m_node.chainman->m_blockman.FindForkInGlobalIndex(active, locator)) {
451461
return fork->nHeight;
452462
}
453463
return nullopt;
@@ -456,7 +466,8 @@ class ChainImpl : public Chain
456466
{
457467
WAIT_LOCK(cs_main, lock);
458468
const CChain& active = Assert(m_node.chainman)->ActiveChain();
459-
return FillBlock(g_chainman.m_blockman.LookupBlockIndex(hash), block, lock, active);
469+
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
470+
return FillBlock(m_node.chainman->m_blockman.LookupBlockIndex(hash), block, lock, active);
460471
}
461472
bool findFirstBlockWithTimeAndHeight(int64_t min_time, int min_height, const FoundBlock& block) override
462473
{
@@ -468,7 +479,8 @@ class ChainImpl : public Chain
468479
{
469480
WAIT_LOCK(cs_main, lock);
470481
const CChain& active = Assert(m_node.chainman)->ActiveChain();
471-
if (const CBlockIndex* block = g_chainman.m_blockman.LookupBlockIndex(block_hash)) {
482+
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
483+
if (const CBlockIndex* block = m_node.chainman->m_blockman.LookupBlockIndex(block_hash)) {
472484
if (const CBlockIndex* ancestor = block->GetAncestor(ancestor_height)) {
473485
return FillBlock(ancestor, ancestor_out, lock, active);
474486
}
@@ -479,17 +491,21 @@ class ChainImpl : public Chain
479491
{
480492
WAIT_LOCK(cs_main, lock);
481493
const CChain& active = Assert(m_node.chainman)->ActiveChain();
482-
const CBlockIndex* block = g_chainman.m_blockman.LookupBlockIndex(block_hash);
483-
const CBlockIndex* ancestor = g_chainman.m_blockman.LookupBlockIndex(ancestor_hash);
494+
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
495+
const CBlockIndex* block = m_node.chainman->m_blockman.LookupBlockIndex(block_hash);
496+
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
497+
const CBlockIndex* ancestor = m_node.chainman->m_blockman.LookupBlockIndex(ancestor_hash);
484498
if (block && ancestor && block->GetAncestor(ancestor->nHeight) != ancestor) ancestor = nullptr;
485499
return FillBlock(ancestor, ancestor_out, lock, active);
486500
}
487501
bool findCommonAncestor(const uint256& block_hash1, const uint256& block_hash2, const FoundBlock& ancestor_out, const FoundBlock& block1_out, const FoundBlock& block2_out) override
488502
{
489503
WAIT_LOCK(cs_main, lock);
490504
const CChain& active = Assert(m_node.chainman)->ActiveChain();
491-
const CBlockIndex* block1 = g_chainman.m_blockman.LookupBlockIndex(block_hash1);
492-
const CBlockIndex* block2 = g_chainman.m_blockman.LookupBlockIndex(block_hash2);
505+
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
506+
const CBlockIndex* block1 = m_node.chainman->m_blockman.LookupBlockIndex(block_hash1);
507+
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
508+
const CBlockIndex* block2 = m_node.chainman->m_blockman.LookupBlockIndex(block_hash2);
493509
const CBlockIndex* ancestor = block1 && block2 ? LastCommonAncestor(block1, block2) : nullptr;
494510
// Using & instead of && below to avoid short circuiting and leaving
495511
// output uninitialized.
@@ -499,7 +515,8 @@ class ChainImpl : public Chain
499515
double guessVerificationProgress(const uint256& block_hash) override
500516
{
501517
LOCK(cs_main);
502-
return GuessVerificationProgress(Params().TxData(), g_chainman.m_blockman.LookupBlockIndex(block_hash));
518+
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
519+
return GuessVerificationProgress(Params().TxData(), m_node.chainman->m_blockman.LookupBlockIndex(block_hash));
503520
}
504521
bool hasBlocks(const uint256& block_hash, int min_height, Optional<int> max_height) override
505522
{
@@ -511,7 +528,8 @@ class ChainImpl : public Chain
511528
// used to limit the range, and passing min_height that's too low or
512529
// max_height that's too high will not crash or change the result.
513530
LOCK(::cs_main);
514-
if (CBlockIndex* block = g_chainman.m_blockman.LookupBlockIndex(block_hash)) {
531+
assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman));
532+
if (CBlockIndex* block = m_node.chainman->m_blockman.LookupBlockIndex(block_hash)) {
515533
if (max_height && block->nHeight >= *max_height) block = block->GetAncestor(*max_height);
516534
for (; block->nStatus & BLOCK_HAVE_DATA; block = block->pprev) {
517535
// Check pprev to not segfault if min_height is too low
@@ -601,7 +619,10 @@ class ChainImpl : public Chain
601619
return ::fHavePruned;
602620
}
603621
bool isReadyToBroadcast() override { return !::fImporting && !::fReindex && !isInitialBlockDownload(); }
604-
bool isInitialBlockDownload() override { return ::ChainstateActive().IsInitialBlockDownload(); }
622+
bool isInitialBlockDownload() override {
623+
assert(std::addressof(::ChainstateActive()) == std::addressof(m_node.chainman->ActiveChainstate()));
624+
return m_node.chainman->ActiveChainstate().IsInitialBlockDownload();
625+
}
605626
bool shutdownRequested() override { return ShutdownRequested(); }
606627
int64_t getAdjustedTime() override { return GetAdjustedTime(); }
607628
void initMessage(const std::string& message) override { ::uiInterface.InitMessage(message); }

src/node/transaction.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
3939

4040
{ // cs_main scope
4141
LOCK(cs_main);
42+
assert(std::addressof(::ChainstateActive()) == std::addressof(node.chainman->ActiveChainstate()));
4243
// If the transaction is already confirmed in the chain, don't do anything
4344
// and return early.
44-
CCoinsViewCache &view = ::ChainstateActive().CoinsTip();
45+
CCoinsViewCache &view = node.chainman->ActiveChainstate().CoinsTip();
4546
for (size_t o = 0; o < tx->vout.size(); o++) {
4647
const Coin& existingCoin = view.AccessCoin(COutPoint(hashTx, o));
4748
// IsSpent doesn't mean the coin is spent, it means the output doesn't exist.
@@ -53,7 +54,7 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
5354
if (max_tx_fee > 0) {
5455
// First, call ATMP with test_accept and check the fee. If ATMP
5556
// fails here, return error immediately.
56-
const MempoolAcceptResult result = AcceptToMemoryPool(::ChainstateActive(), *node.mempool, tx, false /* bypass_limits */,
57+
const MempoolAcceptResult result = AcceptToMemoryPool(node.chainman->ActiveChainstate(), *node.mempool, tx, false /* bypass_limits */,
5758
true /* test_accept */);
5859
if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
5960
return HandleATMPError(result.m_state, err_string);
@@ -62,7 +63,7 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
6263
}
6364
}
6465
// Try to submit the transaction to the mempool.
65-
const MempoolAcceptResult result = AcceptToMemoryPool(::ChainstateActive(), *node.mempool, tx, false /* bypass_limits */,
66+
const MempoolAcceptResult result = AcceptToMemoryPool(node.chainman->ActiveChainstate(), *node.mempool, tx, false /* bypass_limits */,
6667
false /* test_accept */);
6768
if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
6869
return HandleATMPError(result.m_state, err_string);

src/rpc/blockchain.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,9 +1073,9 @@ static RPCHelpMan gettxoutsetinfo()
10731073

10741074
const CoinStatsHashType hash_type{request.params[0].isNull() ? CoinStatsHashType::HASH_SERIALIZED : ParseHashType(request.params[0].get_str())};
10751075

1076-
CCoinsView* coins_view = WITH_LOCK(cs_main, return &ChainstateActive().CoinsDB());
1076+
CCoinsView* coins_view = WITH_LOCK(::cs_main, return &::ChainstateActive().CoinsDB());
10771077
NodeContext& node = EnsureNodeContext(request.context);
1078-
if (GetUTXOStats(coins_view, stats, hash_type, node.rpc_interruption_point)) {
1078+
if (GetUTXOStats(coins_view, WITH_LOCK(::cs_main, return std::ref(g_chainman.m_blockman)), stats, hash_type, node.rpc_interruption_point)) {
10791079
ret.pushKV("height", (int64_t)stats.nHeight);
10801080
ret.pushKV("bestblock", stats.hashBlock.GetHex());
10811081
ret.pushKV("transactions", (int64_t)stats.nTransactions);
@@ -2444,7 +2444,7 @@ UniValue CreateUTXOSnapshot(NodeContext& node, CChainState& chainstate, CAutoFil
24442444

24452445
chainstate.ForceFlushStateToDisk();
24462446

2447-
if (!GetUTXOStats(&chainstate.CoinsDB(), stats, CoinStatsHashType::NONE, node.rpc_interruption_point)) {
2447+
if (!GetUTXOStats(&chainstate.CoinsDB(), chainstate.m_blockman, stats, CoinStatsHashType::NONE, node.rpc_interruption_point)) {
24482448
throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read UTXO set");
24492449
}
24502450

0 commit comments

Comments
 (0)