asan: lock cs_main for calls to chainman

This commit is contained in:
Byron Hambly 2025-01-06 13:58:28 +02:00
parent ffa0c01a17
commit c794f76ea8
No known key found for this signature in database
GPG key ID: DE8F6EA20A661697
4 changed files with 13 additions and 7 deletions

View file

@ -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);

View file

@ -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.");
}

View file

@ -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())) {

View file

@ -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<CTxOut, PSBTOutput> 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<CAmount> input_amounts;
std::vector<uint256> input_blinds;