diff --git a/src/rpc/blockchain.h b/src/rpc/blockchain.h --- a/src/rpc/blockchain.h +++ b/src/rpc/blockchain.h @@ -5,6 +5,8 @@ #ifndef BITCOIN_RPC_BLOCKCHAIN_H #define BITCOIN_RPC_BLOCKCHAIN_H +#include + #include class CBlock; @@ -13,6 +15,8 @@ class CTxMemPool; class JSONRPCRequest; +extern RecursiveMutex cs_main; + UniValue getblockchaininfo(const Config &config, const JSONRPCRequest &request); /** @@ -28,7 +32,8 @@ /** Block description to JSON */ UniValue blockToJSON(const CBlock &block, const CBlockIndex *tip, - const CBlockIndex *blockindex, bool txDetails = false); + const CBlockIndex *blockindex, bool txDetails = false) + LOCKS_EXCLUDED(cs_main); /** Mempool information to JSON */ UniValue MempoolInfoToJSON(const CTxMemPool &pool); @@ -38,6 +43,7 @@ /** Block header to JSON */ UniValue blockheaderToJSON(const CBlockIndex *tip, - const CBlockIndex *blockindex); + const CBlockIndex *blockindex) + LOCKS_EXCLUDED(cs_main); #endif // BITCOIN_RPC_BLOCKCHAIN_H diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -86,6 +86,9 @@ const CBlockIndex *blockindex) { // Serialize passed information without accessing chain state of the active // chain! + // For performance reasons + AssertLockNotHeld(cs_main); + UniValue result(UniValue::VOBJ); result.pushKV("hash", blockindex->GetBlockHash().GetHex()); const CBlockIndex *pnext; @@ -117,6 +120,9 @@ const CBlockIndex *blockindex, bool txDetails) { // Serialize passed information without accessing chain state of the active // chain! + // For performance reasons + AssertLockNotHeld(cs_main); + UniValue result(UniValue::VOBJ); result.pushKV("hash", blockindex->GetBlockHash().GetHex()); const CBlockIndex *pnext;