Skip to content

Commit 3d53afa

Browse files
committed
fix: hold cs_main to for consistent state when fetching GovernanceInfo
1 parent a5ae10c commit 3d53afa

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

src/node/interfaces.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,24 +285,21 @@ class GOVImpl : public GOV
285285
GovernanceInfo getGovernanceInfo() override
286286
{
287287
GovernanceInfo info;
288-
const NodeContext& ctx = context();
289288
const Consensus::Params& consensusParams = Params().GetConsensus();
290-
291-
if (ctx.chainman) {
292-
CSuperblock::GetNearestSuperblocksHeights(ctx.chainman->ActiveHeight(), info.lastsuperblock, info.nextsuperblock);
289+
if (context().chainman) {
290+
LOCK(::cs_main);
291+
CSuperblock::GetNearestSuperblocksHeights(context().chainman->ActiveHeight(), info.lastsuperblock, info.nextsuperblock);
292+
info.governancebudget = CSuperblock::GetPaymentsLimit(context().chainman->ActiveChain(), info.nextsuperblock);
293+
if (context().dmnman) {
294+
info.fundingthreshold = context().dmnman->GetListAtChainTip().GetValidWeightedMNsCount() / 10;
295+
}
293296
}
294297
info.proposalfee = GOVERNANCE_PROPOSAL_FEE_TX;
295298
info.superblockcycle = consensusParams.nSuperblockCycle;
296299
info.superblockmaturitywindow = consensusParams.nSuperblockMaturityWindow;
297300
info.targetSpacing = consensusParams.nPowTargetSpacing;
298301
info.relayRequiredConfs = GOVERNANCE_MIN_RELAY_FEE_CONFIRMATIONS;
299302
info.requiredConfs = GOVERNANCE_FEE_CONFIRMATIONS;
300-
if (ctx.dmnman) {
301-
info.fundingthreshold = ctx.dmnman->GetListAtChainTip().GetValidWeightedMNsCount() / 10;
302-
}
303-
if (ctx.chainman) {
304-
info.governancebudget = CSuperblock::GetPaymentsLimit(ctx.chainman->ActiveChain(), info.nextsuperblock);
305-
}
306303
return info;
307304
}
308305
std::optional<int32_t> getProposalFundedHeight(const uint256& proposal_hash) override

0 commit comments

Comments
 (0)