aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2018-02-05 16:16:53 -0500
committerMarcoFalke <falke.marco@gmail.com>2018-02-05 16:17:00 -0500
commit2a30e67d20f76bbcd9a7d445f616f005316e0a1a (patch)
treeb3be886f15812b3a31b93a1547d8ace323964d59 /src
parentd32528e733f2711b34dbc41fbb2bb0f153bf7e9a (diff)
parentc409b1adac59329b78b8c48f131f8ca032988412 (diff)
Merge #12330: Reduce scope of cs_main and cs_wallet locks in listtransactions
c409b1adac [rpc] Reduce scope of cs_main and cs_wallet locks in listtransactions (João Barbosa) Pull request description: Trivial change, no behaviour change. Benchmark done as follow: - run with `-regtest` - wallet with 5000 transactions - measured the time spent with the lock and the total time - times are an average of 100 `listtransactions --count=...` calls | `--count` | lock (ms) | total (ms) | saving | |--:|--:|--:|--:| | 10 | 0.2230 | 0.2510 | 11% | | 100 | 2.5150 | 2.8690 | 12% | | 1000 | 20.0320 | 23.3490 | 14% | | 10000 | 105.2070 | 125.5310 | 16% | Tree-SHA512: ebedfeeb4c8ad75c89128e53cae976a82967dbb5ffd129da0f7204ccf9c3c15070b3d509f3767bebd745512e410200cc546147c836e82409f95fc9b8d14fc3ed
Diffstat (limited to 'src')
-rw-r--r--src/wallet/rpcwallet.cpp29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
index 9364d18d30..33790d3490 100644
--- a/src/wallet/rpcwallet.cpp
+++ b/src/wallet/rpcwallet.cpp
@@ -1794,8 +1794,6 @@ UniValue listtransactions(const JSONRPCRequest& request)
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
- LOCK2(cs_main, pwallet->cs_wallet);
-
std::string strAccount = "*";
if (!request.params[0].isNull())
strAccount = request.params[0].get_str();
@@ -1817,20 +1815,25 @@ UniValue listtransactions(const JSONRPCRequest& request)
UniValue ret(UniValue::VARR);
- const CWallet::TxItems & txOrdered = pwallet->wtxOrdered;
-
- // iterate backwards until we have nCount items to return:
- for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
{
- CWalletTx *const pwtx = (*it).second.first;
- if (pwtx != nullptr)
- ListTransactions(pwallet, *pwtx, strAccount, 0, true, ret, filter);
- CAccountingEntry *const pacentry = (*it).second.second;
- if (pacentry != nullptr)
- AcentryToJSON(*pacentry, strAccount, ret);
+ LOCK2(cs_main, pwallet->cs_wallet);
+
+ const CWallet::TxItems & txOrdered = pwallet->wtxOrdered;
- if ((int)ret.size() >= (nCount+nFrom)) break;
+ // iterate backwards until we have nCount items to return:
+ for (CWallet::TxItems::const_reverse_iterator it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
+ {
+ CWalletTx *const pwtx = (*it).second.first;
+ if (pwtx != nullptr)
+ ListTransactions(pwallet, *pwtx, strAccount, 0, true, ret, filter);
+ CAccountingEntry *const pacentry = (*it).second.second;
+ if (pacentry != nullptr)
+ AcentryToJSON(*pacentry, strAccount, ret);
+
+ if ((int)ret.size() >= (nCount+nFrom)) break;
+ }
}
+
// ret is newest to oldest
if (nFrom > (int)ret.size())