diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 96d452512e..0db5c0e002 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2766,7 +2766,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer, // the received headers. We can still get ahead by up to a single maximum-sized // headers message here, but never further, so that's fine. if (m_chainman.m_best_header) { - int64_t headers_ahead = m_chainman.m_best_header->nHeight - m_chainman.ActiveHeight(); + int64_t headers_ahead = m_chainman.m_best_header->nHeight - WITH_LOCK(::cs_main, return m_chainman.ActiveHeight()); bool too_far_ahead = node::fTrimHeaders && (headers_ahead >= node::nHeaderDownloadBuffer); if (too_far_ahead) { LOCK(cs_main); diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 0b7cc8c90e..45550b6524 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -1100,7 +1100,8 @@ static RPCHelpMan getnewblockhex() // Construct proposed parameter entry, if any DynaFedParamEntry proposed; if (!request.params[1].isNull()) { - if (!DeploymentActiveAfter(chainman.ActiveChain().Tip(), chainman, Consensus::DEPLOYMENT_DYNA_FED)) { + auto tip = WITH_LOCK(::cs_main, return chainman.ActiveChain().Tip()); + if (!DeploymentActiveAfter(tip, chainman, Consensus::DEPLOYMENT_DYNA_FED)) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Dynamic federations is not active on this network. Proposed parameters are not needed."); } diff --git a/src/rpc/node.cpp b/src/rpc/node.cpp index 8856669dac..0f7b1c96db 100644 --- a/src/rpc/node.cpp +++ b/src/rpc/node.cpp @@ -452,7 +452,8 @@ static RPCHelpMan tweakfedpegscript() } ChainstateManager& chainman = EnsureAnyChainman(request.context); - CScript fedpegscript = GetValidFedpegScripts(chainman.ActiveChain().Tip(), Params().GetConsensus(), true /* nextblock_validation */).front().second; + auto tip = WITH_LOCK(::cs_main, return chainman.ActiveChain().Tip()); + CScript fedpegscript = GetValidFedpegScripts(tip, Params().GetConsensus(), true /* nextblock_validation */).front().second; if (!request.params[1].isNull()) { if (IsHex(request.params[1].get_str())) { diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index c607271c3e..e6b348ea3a 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -365,7 +365,8 @@ static RPCHelpMan createrawtransaction() if (!request.params[3].isNull()) { rbf = request.params[3].isTrue(); } - CMutableTransaction rawTx = ConstructTransaction(request.params[0], request.params[1], request.params[2], rbf, chainman.ActiveChain().Tip()); + auto tip = WITH_LOCK(::cs_main, return chainman.ActiveChain().Tip()); + CMutableTransaction rawTx = ConstructTransaction(request.params[0], request.params[1], request.params[2], rbf, tip); return EncodeHexTx(CTransaction(rawTx)); }, @@ -746,7 +747,8 @@ static RPCHelpMan signrawtransactionwithkey() ParsePrevouts(request.params[2], &keystore, coins); UniValue result(UniValue::VOBJ); - SignTransaction(mtx, &keystore, coins, request.params[3], result, chainman.ActiveChain().Tip()); + auto tip = WITH_LOCK(::cs_main, return chainman.ActiveChain().Tip()); + SignTransaction(mtx, &keystore, coins, request.params[3], result, tip); return result; }, }; @@ -1894,7 +1896,8 @@ static RPCHelpMan createpsbt() rbf = request.params[3].isTrue(); } std::map psbt_outs; - CMutableTransaction rawTx = ConstructTransaction(request.params[0], request.params[1], request.params[2], rbf, chainman.ActiveChain().Tip(), &psbt_outs, true /* allow_peg_in */, true /* allow_issuance */); + auto tip = WITH_LOCK(::cs_main, return chainman.ActiveChain().Tip()); + CMutableTransaction rawTx = ConstructTransaction(request.params[0], request.params[1], request.params[2], rbf, tip, &psbt_outs, true /* allow_peg_in */, true /* allow_issuance */); // Make a blank psbt uint32_t psbt_version = 2; @@ -2523,7 +2526,8 @@ static RPCHelpMan rawblindrawtransaction() "Invalid parameter: one (potentially empty) input asset blind for each input must be provided"); } - const auto& fedpegscripts = GetValidFedpegScripts(chainman.ActiveChain().Tip(), Params().GetConsensus(), true /* nextblock_validation */); + auto tip = WITH_LOCK(::cs_main, return chainman.ActiveChain().Tip()); + const auto& fedpegscripts = GetValidFedpegScripts(tip, Params().GetConsensus(), true /* nextblock_validation */); std::vector input_amounts; std::vector input_blinds;