Browse Source

rpc: make `gettxoutsettinfo` run lock-free

For leveldb "An iterator operates on a snapshot of the database taken
when the iterator is created". This means that it is unnecessary to
lock out other threads while computing statistics, and neither to hold
cs_main for the whole time. Let the thread run free.
0.13
Wladimir J. van der Laan 10 years ago
parent
commit
57092ed9e7
  1. 2
      src/rpcblockchain.cpp
  2. 5
      src/txdb.cpp

2
src/rpcblockchain.cpp

@ -345,8 +345,6 @@ UniValue gettxoutsetinfo(const UniValue& params, bool fHelp)
+ HelpExampleRpc("gettxoutsetinfo", "") + HelpExampleRpc("gettxoutsetinfo", "")
); );
LOCK(cs_main);
UniValue ret(UniValue::VOBJ); UniValue ret(UniValue::VOBJ);
CCoinsStats stats; CCoinsStats stats;

5
src/txdb.cpp

@ -147,7 +147,10 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) const {
return error("%s: Deserialize or I/O error - %s", __func__, e.what()); return error("%s: Deserialize or I/O error - %s", __func__, e.what());
} }
} }
stats.nHeight = mapBlockIndex.find(GetBestBlock())->second->nHeight; {
LOCK(cs_main);
stats.nHeight = mapBlockIndex.find(stats.hashBlock)->second->nHeight;
}
stats.hashSerialized = ss.GetHash(); stats.hashSerialized = ss.GetHash();
stats.nTotalAmount = nTotalAmount; stats.nTotalAmount = nTotalAmount;
return true; return true;

Loading…
Cancel
Save