Merge #12639: Reduce cs_main lock in listunspent
a59dac3
refactor: Avoid extra lookups of mapAddressBook in listunspent RPC (João Barbosa)d76962e
rpc: Reduce cs_main lock in listunspent (João Barbosa) Pull request description: On my system, where the wallet has 10000 unspents, the `cs_main` lock duration changed from 191ms to 36ms. The loop that generates the response takes around 155ms. So, the lock duration is reduced to around 20%. Tree-SHA512: ddaae591f39da59a9d1a8e9ffe773d857687789476f566ca273d310ad531da6dacff80cac69f3334c601c251ac7c5ed4136656c725aa3d611c6bbf734111946e
This commit is contained in:
commit
7eb7076f70
1 changed files with 10 additions and 5 deletions
|
@ -3149,9 +3149,13 @@ UniValue listunspent(const JSONRPCRequest& request)
|
||||||
|
|
||||||
UniValue results(UniValue::VARR);
|
UniValue results(UniValue::VARR);
|
||||||
std::vector<COutput> vecOutputs;
|
std::vector<COutput> vecOutputs;
|
||||||
LOCK2(cs_main, pwallet->cs_wallet);
|
{
|
||||||
|
LOCK2(cs_main, pwallet->cs_wallet);
|
||||||
|
pwallet->AvailableCoins(vecOutputs, !include_unsafe, nullptr, nMinimumAmount, nMaximumAmount, nMinimumSumAmount, nMaximumCount, nMinDepth, nMaxDepth);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOCK(pwallet->cs_wallet);
|
||||||
|
|
||||||
pwallet->AvailableCoins(vecOutputs, !include_unsafe, nullptr, nMinimumAmount, nMaximumAmount, nMinimumSumAmount, nMaximumCount, nMinDepth, nMaxDepth);
|
|
||||||
for (const COutput& out : vecOutputs) {
|
for (const COutput& out : vecOutputs) {
|
||||||
CTxDestination address;
|
CTxDestination address;
|
||||||
const CScript& scriptPubKey = out.tx->tx->vout[out.i].scriptPubKey;
|
const CScript& scriptPubKey = out.tx->tx->vout[out.i].scriptPubKey;
|
||||||
|
@ -3167,10 +3171,11 @@ UniValue listunspent(const JSONRPCRequest& request)
|
||||||
if (fValidAddress) {
|
if (fValidAddress) {
|
||||||
entry.pushKV("address", EncodeDestination(address));
|
entry.pushKV("address", EncodeDestination(address));
|
||||||
|
|
||||||
if (pwallet->mapAddressBook.count(address)) {
|
auto i = pwallet->mapAddressBook.find(address);
|
||||||
entry.pushKV("label", pwallet->mapAddressBook[address].name);
|
if (i != pwallet->mapAddressBook.end()) {
|
||||||
|
entry.pushKV("label", i->second.name);
|
||||||
if (IsDeprecatedRPCEnabled("accounts")) {
|
if (IsDeprecatedRPCEnabled("accounts")) {
|
||||||
entry.pushKV("account", pwallet->mapAddressBook[address].name);
|
entry.pushKV("account", i->second.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue