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
pull/12359/merge
MarcoFalke 7 years ago
commit 2a30e67d20
No known key found for this signature in database
GPG Key ID: D2EA4850E7528B25

@ -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,6 +1815,9 @@ UniValue listtransactions(const JSONRPCRequest& request)
UniValue ret(UniValue::VARR);
{
LOCK2(cs_main, pwallet->cs_wallet);
const CWallet::TxItems & txOrdered = pwallet->wtxOrdered;
// iterate backwards until we have nCount items to return:
@ -1831,6 +1832,8 @@ UniValue listtransactions(const JSONRPCRequest& request)
if ((int)ret.size() >= (nCount+nFrom)) break;
}
}
// ret is newest to oldest
if (nFrom > (int)ret.size())

Loading…
Cancel
Save