mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-28 10:05:36 +02:00
rest/getutxos: Don't construct empty mempool
...just don't try to consult it at all when fCheckMemPool is false
This commit is contained in:
10
src/rest.cpp
10
src/rest.cpp
@@ -799,10 +799,10 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
|
|||||||
if (!maybe_chainman) return false;
|
if (!maybe_chainman) return false;
|
||||||
ChainstateManager& chainman = *maybe_chainman;
|
ChainstateManager& chainman = *maybe_chainman;
|
||||||
{
|
{
|
||||||
auto process_utxos = [&vOutPoints, &outs, &hits](const CCoinsView& view, const CTxMemPool& mempool) {
|
auto process_utxos = [&vOutPoints, &outs, &hits](const CCoinsView& view, const CTxMemPool* mempool) {
|
||||||
for (const COutPoint& vOutPoint : vOutPoints) {
|
for (const COutPoint& vOutPoint : vOutPoints) {
|
||||||
Coin coin;
|
Coin coin;
|
||||||
bool hit = !mempool.isSpent(vOutPoint) && view.GetCoin(vOutPoint, coin);
|
bool hit = (!mempool || !mempool->isSpent(vOutPoint)) && view.GetCoin(vOutPoint, coin);
|
||||||
hits.push_back(hit);
|
hits.push_back(hit);
|
||||||
if (hit) outs.emplace_back(std::move(coin));
|
if (hit) outs.emplace_back(std::move(coin));
|
||||||
}
|
}
|
||||||
@@ -815,10 +815,10 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
|
|||||||
LOCK2(cs_main, mempool->cs);
|
LOCK2(cs_main, mempool->cs);
|
||||||
CCoinsViewCache& viewChain = chainman.ActiveChainstate().CoinsTip();
|
CCoinsViewCache& viewChain = chainman.ActiveChainstate().CoinsTip();
|
||||||
CCoinsViewMemPool viewMempool(&viewChain, *mempool);
|
CCoinsViewMemPool viewMempool(&viewChain, *mempool);
|
||||||
process_utxos(viewMempool, *mempool);
|
process_utxos(viewMempool, mempool);
|
||||||
} else {
|
} else {
|
||||||
LOCK(cs_main); // no need to lock mempool!
|
LOCK(cs_main);
|
||||||
process_utxos(chainman.ActiveChainstate().CoinsTip(), CTxMemPool());
|
process_utxos(chainman.ActiveChainstate().CoinsTip(), nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < hits.size(); ++i) {
|
for (size_t i = 0; i < hits.size(); ++i) {
|
||||||
|
Reference in New Issue
Block a user