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%.
Reduce cs_main lock in listunspent #12639
pull promag wants to merge 2 commits into bitcoin:master from promag:2018-03-reduce-cs_main_lock-listunspent changing 1 files +10 −5-
promag commented at 9:01 pm on March 7, 2018: memberOn my system, where the wallet has 10000 unspents, the
-
fanquake added the label RPC/REST/ZMQ on Mar 7, 2018
-
MarcoFalke commented at 3:31 pm on March 8, 2018: memberNeeds rebase to fix travis (sorry)
-
promag force-pushed on Mar 11, 2018
-
promag commented at 10:26 pm on March 11, 2018: memberRebased.
-
conscott commented at 4:40 am on March 17, 2018: contributor
Nice.
Test ACK efbc070c5cb176b0f79801e9e6d5f5a52578edc1
-
jonasschnelli commented at 3:05 am on March 19, 2018: contributorGeneral Concept ACK. There is tiny risk that bitcoind spits out utxos that are already spent due the unlocking between
AvailableCoins
and the return output generation…. okay IMO. -
promag commented at 10:48 am on March 19, 2018: member@jonasschnelli yeah, the same can happen between the user receives the response and tries to use an unspent that was spent in between.
-
sipa commented at 9:40 pm on March 22, 2018: memberConcept ACK, needs rebase.
-
promag force-pushed on Mar 22, 2018
-
promag commented at 11:35 pm on March 22, 2018: memberRebased and replaced 3
mapAddressBook
lookups with 1 lookup. -
in src/wallet/rpcwallet.cpp:3155 in 4c33ef6ffe outdated
3012@@ -3013,9 +3013,11 @@ UniValue listunspent(const JSONRPCRequest& request) 3013 3014 UniValue results(UniValue::VARR); 3015 std::vector<COutput> vecOutputs; 3016- LOCK2(cs_main, pwallet->cs_wallet); 3017+ { 3018+ LOCK2(cs_main, pwallet->cs_wallet); 3019+ pwallet->AvailableCoins(vecOutputs, !include_unsafe, nullptr, nMinimumAmount, nMaximumAmount, nMinimumSumAmount, nMaximumCount, nMinDepth, nMaxDepth); 3020+ }
promag commented at 11:37 pm on March 22, 2018:I thought taking a copy of the address book in the above block to avoid locking the wallet bellow. Thoughts?
laanwj commented at 2:30 pm on April 17, 2018:As it contains an entry for every key, the address book can be quite a big data structure. I don’t think making a copy is a good trade-off.
promag commented at 2:34 pm on April 17, 2018:Agree.in src/wallet/rpcwallet.cpp:3037 in 4c33ef6ffe outdated
3032@@ -3031,9 +3033,13 @@ UniValue listunspent(const JSONRPCRequest& request) 3033 if (fValidAddress) { 3034 entry.pushKV("address", EncodeDestination(address)); 3035 3036- if (pwallet->mapAddressBook.count(address)) { 3037- entry.pushKV("label", pwallet->mapAddressBook[address].name); 3038- entry.pushKV("account", pwallet->mapAddressBook[address].name); 3039+ { 3040+ LOCK(pwallet->cs_wallet);
laanwj commented at 2:39 pm on April 17, 2018:Depends on the relative overhead of locking/unlocking for every look-up here. If that is negligible, it’s preferable to lock/unlock with the small granularity like you have now.
promag commented at 2:51 pm on April 17, 2018:This PR aims to reduce
cs_main
and that is already accomplished.Keeping the wallet locked for the whole loop is no worse than the previous implementation. Overhead aside, this implementation is more susceptible to an unspent being spent, so I would say to lock the whole loop to minimise that.
promag force-pushed on May 3, 2018rpc: Reduce cs_main lock in listunspent d76962e056refactor: Avoid extra lookups of mapAddressBook in listunspent RPC a59dac35abpromag force-pushed on May 3, 2018promag commented at 11:53 am on May 3, 2018: memberRebased and split in 2 commits: the change in locks and the lookup refactor.laanwj commented at 1:36 pm on May 3, 2018: memberutACK a59dac35abf64d5af4d499bc3397b3369eb76edalaanwj merged this on May 3, 2018laanwj closed this on May 3, 2018
laanwj referenced this in commit 7eb7076f70 on May 3, 2018promag deleted the branch on May 3, 2018jasonbcox referenced this in commit b03fb98a32 on Dec 6, 2019jonspock referenced this in commit 4006008efd on Sep 29, 2020jonspock referenced this in commit 6c3e00d159 on Sep 29, 2020jonspock referenced this in commit 48cb79b339 on Oct 10, 2020LarryRuane referenced this in commit 6554788057 on Mar 22, 2021LarryRuane referenced this in commit 302231e998 on Mar 22, 2021LarryRuane referenced this in commit e0115b06f8 on Apr 26, 2021LarryRuane referenced this in commit f29a46de71 on Apr 26, 2021UdjinM6 referenced this in commit 47cc03552f on May 21, 2021UdjinM6 referenced this in commit dcd6c1df3c on May 25, 2021LarryRuane referenced this in commit 15dca59349 on May 27, 2021LarryRuane referenced this in commit 93a71c68a4 on May 27, 2021TheArbitrator referenced this in commit 33c613de2d on Jun 7, 2021TheArbitrator referenced this in commit 0d7bfd146b on Jun 7, 2021MarcoFalke locked this on Sep 8, 2021
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-18 18:12 UTC
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-18 18:12 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me
More mirrored repositories can be found on mirror.b10c.me