Skip to content

Commit 319f0ce

Browse files
committed
rest/getutxos: Don't construct empty mempool
...just don't try to consult it at all when fCheckMemPool is false
1 parent 03574b9 commit 319f0ce

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/rest.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -799,10 +799,10 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
799799
if (!maybe_chainman) return false;
800800
ChainstateManager& chainman = *maybe_chainman;
801801
{
802-
auto process_utxos = [&vOutPoints, &outs, &hits](const CCoinsView& view, const CTxMemPool& mempool) {
802+
auto process_utxos = [&vOutPoints, &outs, &hits](const CCoinsView& view, const CTxMemPool* mempool) {
803803
for (const COutPoint& vOutPoint : vOutPoints) {
804804
Coin coin;
805-
bool hit = !mempool.isSpent(vOutPoint) && view.GetCoin(vOutPoint, coin);
805+
bool hit = (!mempool || !mempool->isSpent(vOutPoint)) && view.GetCoin(vOutPoint, coin);
806806
hits.push_back(hit);
807807
if (hit) outs.emplace_back(std::move(coin));
808808
}
@@ -815,10 +815,10 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
815815
LOCK2(cs_main, mempool->cs);
816816
CCoinsViewCache& viewChain = chainman.ActiveChainstate().CoinsTip();
817817
CCoinsViewMemPool viewMempool(&viewChain, *mempool);
818-
process_utxos(viewMempool, *mempool);
818+
process_utxos(viewMempool, mempool);
819819
} else {
820-
LOCK(cs_main); // no need to lock mempool!
821-
process_utxos(chainman.ActiveChainstate().CoinsTip(), CTxMemPool());
820+
LOCK(cs_main);
821+
process_utxos(chainman.ActiveChainstate().CoinsTip(), nullptr);
822822
}
823823

824824
for (size_t i = 0; i < hits.size(); ++i) {

0 commit comments

Comments
 (0)