diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 1fed2ca05..8dcd80635 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -534,6 +534,9 @@ UniValue getblockdeltas(const UniValue& params, bool fHelp, const CPubKey& mypk) if (fHelp || params.size() != 1) throw runtime_error(""); + // mapBlockIndex and chainActive (read here and in blockToDeltasJSON) are guarded by cs_main. + LOCK(cs_main); + std::string strHash = params[0].get_str(); uint256 hash(uint256S(strHash)); @@ -602,11 +605,20 @@ UniValue getblockhashes(const UniValue& params, bool fHelp, const CPubKey& mypk) std::vector > blockHashes; - if (fActiveOnly) - LOCK(cs_main); - - if (!GetTimestampIndex(high, low, fActiveOnly, blockHashes)) { - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for block hashes"); + { + // With noOrphans, GetTimestampIndex checks every row against mapBlockIndex/chainActive, so + // cs_main must span the call (the old unbraced "if (fActiveOnly) LOCK(cs_main);" released it + // on the same line). Without noOrphans it only walks the LevelDB index, so no lock is taken: + // holding cs_main over a wide range would stall block validation for the whole scan. + bool fFound; + if (fActiveOnly) { + LOCK(cs_main); + fFound = GetTimestampIndex(high, low, fActiveOnly, blockHashes); + } else { + fFound = GetTimestampIndex(high, low, fActiveOnly, blockHashes); + } + if (!fFound) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for block hashes"); } UniValue result(UniValue::VARR); @@ -877,6 +889,9 @@ UniValue getblockmerkletree(const UniValue& params, bool fHelp, const CPubKey& m + HelpExampleRpc("getblockmerkletree", "290000") ); + // chainActive and pcoinsTip (whose anchor cache inserts on a miss) are guarded by cs_main. + LOCK(cs_main); + CBlockIndex* phushblockindex; uint256 blockRoot; SaplingMerkleTree tree; diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 7eb29e42c..eca170f02 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -299,7 +299,9 @@ UniValue importprivkey(const UniValue& params, bool fHelp, const CPubKey& mypk) bool fRescan = true; if (params.size() > 2) fRescan = params[2].get_bool(); - if ( fRescan && params.size() == 4 ) + // '> 3', not '== 4': with the optional 5th (secret_key) argument the height was silently + // dropped and the rescan started from genesis. + if ( fRescan && params.size() > 3 ) height = params[3].get_int();