Skip to content

Commit dc01f07

Browse files
committed
fix: add missing checks for not nullptr in rpc for dash specific code
1 parent 30381ac commit dc01f07

File tree

9 files changed

+46
-3
lines changed

9 files changed

+46
-3
lines changed

src/rpc/blockchain.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,7 @@ static RPCHelpMan verifychain()
16051605
const int check_depth{request.params[1].isNull() ? DEFAULT_CHECKBLOCKS : request.params[1].get_int()};
16061606

16071607
const NodeContext& node = EnsureAnyNodeContext(request.context);
1608+
CHECK_NONFATAL(node.evodb);
16081609

16091610
ChainstateManager& chainman = EnsureChainman(node);
16101611
LOCK(cs_main);
@@ -2962,7 +2963,8 @@ static RPCHelpMan dumptxoutset()
29622963
FILE* file{fsbridge::fopen(temppath, "wb")};
29632964
CAutoFile afile{file, SER_DISK, CLIENT_VERSION};
29642965
NodeContext& node = EnsureAnyNodeContext(request.context);
2965-
UniValue result = CreateUTXOSnapshot(node, node.chainman->ActiveChainstate(), afile);
2966+
const ChainstateManager& chainman = EnsureChainman(node);
2967+
UniValue result = CreateUTXOSnapshot(node, chainman.ActiveChainstate(), afile);
29662968
fs::rename(temppath, path);
29672969

29682970
result.pushKV("path", path.string());

src/rpc/coinjoin.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ static RPCHelpMan coinjoin()
6969
}
7070

7171
CTxMemPool& mempool = EnsureMemPool(node);
72+
CHECK_NONFATAL(node.connman);
7273
bool result = cj_clientman->DoAutomaticDenominating(*node.connman, mempool);
7374
return "Mixing " + (result ? "started successfully" : ("start failed: " + cj_clientman->GetStatuses().original + ", will retry"));
7475
}

src/rpc/evo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,6 +1697,7 @@ static UniValue protx(const JSONRPCRequest& request)
16971697
} else if (command == "protxinfo") {
16981698
return protx_info(new_request, dmnman, mn_metaman, chainman);
16991699
} else if (command == "protxdiff") {
1700+
CHECK_NONFATAL(node.llmq_ctx);
17001701
return protx_diff(new_request, dmnman, chainman, *node.llmq_ctx);
17011702
} else if (command == "protxlistdiff") {
17021703
return protx_listdiff(new_request, dmnman, chainman);

src/rpc/governance.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ static UniValue gobject_count(const JSONRPCRequest& request)
5353
gobject_count_help(request);
5454

5555
const NodeContext& node = EnsureAnyNodeContext(request.context);
56+
CHECK_NONFATAL(node.govman);
5657
return strMode == "json" ? node.govman->ToJson() : node.govman->ToString();
5758
}
5859

@@ -309,6 +310,8 @@ static UniValue gobject_submit(const JSONRPCRequest& request)
309310
gobject_submit_help(request);
310311

311312
const NodeContext& node = EnsureAnyNodeContext(request.context);
313+
CHECK_NONFATAL(node.dmnman);
314+
CHECK_NONFATAL(node.govman);
312315

313316
if(!node.mn_sync->IsBlockchainSynced()) {
314317
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Must wait for client to sync with masternode network. Try again in a minute or so.");
@@ -395,7 +398,9 @@ static UniValue gobject_submit(const JSONRPCRequest& request)
395398

396399
LogPrintf("gobject(submit) -- Adding locally created governance object - %s\n", strHash);
397400

401+
CHECK_NONFATAL(node.peerman);
398402
if (fMissingConfirmations) {
403+
CHECK_NONFATAL(node.mn_sync);
399404
node.govman->AddPostponedObject(govobj);
400405
govobj.Relay(*node.peerman, *node.mn_sync);
401406
} else {
@@ -410,6 +415,7 @@ static UniValue VoteWithMasternodes(const JSONRPCRequest& request, const std::ma
410415
vote_outcome_enum_t eVoteOutcome)
411416
{
412417
const NodeContext& node = EnsureAnyNodeContext(request.context);
418+
CHECK_NONFATAL(node.govman);
413419
{
414420
LOCK(node.govman->cs);
415421
const CGovernanceObject *pGovObj = node.govman->FindConstGovernanceObject(hash);
@@ -450,6 +456,8 @@ static UniValue VoteWithMasternodes(const JSONRPCRequest& request, const std::ma
450456
}
451457

452458
CGovernanceException exception;
459+
CHECK_NONFATAL(node.connman);
460+
CHECK_NONFATAL(node.peerman);
453461
if (node.govman->ProcessVoteAndRelay(vote, exception, *node.connman, *node.peerman)) {
454462
nSuccessful++;
455463
statusObj.pushKV("result", "success");
@@ -493,6 +501,7 @@ static UniValue gobject_vote_many(const JSONRPCRequest& request)
493501
if (!wallet) return NullUniValue;
494502

495503
const NodeContext& node = EnsureAnyNodeContext(request.context);
504+
CHECK_NONFATAL(node.dmnman);
496505

497506
uint256 hash(ParseHashV(request.params[0], "Object hash"));
498507
std::string strVoteSignal = request.params[1].get_str();
@@ -554,6 +563,7 @@ static UniValue gobject_vote_alias(const JSONRPCRequest& request)
554563
if (!wallet) return NullUniValue;
555564

556565
const NodeContext& node = EnsureAnyNodeContext(request.context);
566+
CHECK_NONFATAL(node.dmnman);
557567

558568
uint256 hash(ParseHashV(request.params[0], "Object hash"));
559569
std::string strVoteSignal = request.params[1].get_str();
@@ -690,6 +700,7 @@ static UniValue gobject_list(const JSONRPCRequest& request)
690700

691701
const NodeContext& node = EnsureAnyNodeContext(request.context);
692702
CHECK_NONFATAL(node.dmnman);
703+
CHECK_NONFATAL(node.govman);
693704

694705
return ListObjects(*node.govman, node.dmnman->GetListAtChainTip(), strCachedSignal, strType, 0);
695706
}
@@ -857,6 +868,7 @@ static UniValue gobject_getcurrentvotes(const JSONRPCRequest& request)
857868

858869
// FIND OBJECT USER IS LOOKING FOR
859870
const NodeContext& node = EnsureAnyNodeContext(request.context);
871+
CHECK_NONFATAL(node.govman);
860872

861873
LOCK(node.govman->cs);
862874
const CGovernanceObject* pGovObj = node.govman->FindConstGovernanceObject(hash);
@@ -995,6 +1007,7 @@ static UniValue voteraw(const JSONRPCRequest& request)
9951007
}
9961008

9971009
const NodeContext& node = EnsureAnyNodeContext(request.context);
1010+
CHECK_NONFATAL(node.govman);
9981011
GovernanceObject govObjType = WITH_LOCK(node.govman->cs, return [&](){
9991012
AssertLockHeld(node.govman->cs);
10001013
const CGovernanceObject *pGovObj = node.govman->FindConstGovernanceObject(hashGovObj);
@@ -1032,6 +1045,9 @@ static UniValue voteraw(const JSONRPCRequest& request)
10321045
throw JSONRPCError(RPC_INTERNAL_ERROR, "Failure to verify vote.");
10331046
}
10341047

1048+
CHECK_NONFATAL(node.connman);
1049+
CHECK_NONFATAL(node.peerman);
1050+
10351051
CGovernanceException exception;
10361052
if (node.govman->ProcessVoteAndRelay(vote, exception, *node.connman, *node.peerman)) {
10371053
return "Voted successfully";
@@ -1068,6 +1084,7 @@ static UniValue getgovernanceinfo(const JSONRPCRequest& request)
10681084

10691085
const NodeContext& node = EnsureAnyNodeContext(request.context);
10701086
const ChainstateManager& chainman = EnsureAnyChainman(request.context);
1087+
CHECK_NONFATAL(node.dmnman);
10711088

10721089
const auto* pindex = WITH_LOCK(cs_main, return chainman.ActiveChain().Tip());
10731090
int nBlockHeight = pindex->nHeight;

src/rpc/masternode.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ static RPCHelpMan masternode_connect()
4747
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("Incorrect masternode address %s", strAddress));
4848

4949
const NodeContext& node = EnsureAnyNodeContext(request.context);
50+
CHECK_NONFATAL(node.connman);
51+
5052
node.connman->OpenMasternodeConnection(CAddress(addr, NODE_NETWORK));
5153
if (!node.connman->IsConnected(CAddress(addr, NODE_NETWORK), CConnman::AllNodes))
5254
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("Couldn't connect to masternode %s", strAddress));
@@ -133,6 +135,7 @@ static RPCHelpMan masternode_winner()
133135
}
134136

135137
const NodeContext& node = EnsureAnyNodeContext(request.context);
138+
CHECK_NONFATAL(node.dmnman);
136139
return GetNextMasternodeForPayment(*node.dmnman, 10);
137140
},
138141
};
@@ -152,6 +155,7 @@ static RPCHelpMan masternode_current()
152155
}
153156

154157
const NodeContext& node = EnsureAnyNodeContext(request.context);
158+
CHECK_NONFATAL(node.dmnman);
155159
return GetNextMasternodeForPayment(*node.dmnman, 1);
156160
},
157161
};
@@ -204,6 +208,7 @@ static RPCHelpMan masternode_status()
204208
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
205209
{
206210
const NodeContext& node = EnsureAnyNodeContext(request.context);
211+
CHECK_NONFATAL(node.dmnman);
207212
if (!node.mn_activeman) {
208213
throw JSONRPCError(RPC_INTERNAL_ERROR, "This node does not run an active masternode.");
209214
}
@@ -302,6 +307,7 @@ static RPCHelpMan masternode_winners()
302307
int nStartHeight = std::max(nChainTipHeight - nCount, 1);
303308

304309
CHECK_NONFATAL(node.dmnman);
310+
CHECK_NONFATAL(node.govman);
305311

306312
const auto tip_mn_list = node.dmnman->GetListAtChainTip();
307313
for (int h = nStartHeight; h <= nChainTipHeight; h++) {
@@ -384,6 +390,8 @@ static RPCHelpMan masternode_payments()
384390
// A temporary vector which is used to sort results properly (there is no "reverse" in/for UniValue)
385391
std::vector<UniValue> vecPayments;
386392

393+
CHECK_NONFATAL(node.chain_helper);
394+
CHECK_NONFATAL(node.dmnman);
387395
while (vecPayments.size() < uint64_t(std::abs(nCount)) && pindex != nullptr) {
388396
CBlock block;
389397
if (!ReadBlockFromDisk(block, pindex, Params().GetConsensus())) {
@@ -407,8 +415,6 @@ static RPCHelpMan masternode_payments()
407415
nBlockFees += nValueIn - tx->GetValueOut();
408416
}
409417

410-
CHECK_NONFATAL(node.chain_helper);
411-
412418
std::vector<CTxOut> voutMasternodePayments, voutDummy;
413419
CMutableTransaction dummyTx;
414420
CAmount blockSubsidy = GetBlockSubsidy(pindex, Params().GetConsensus());
@@ -548,6 +554,7 @@ static RPCHelpMan masternodelist_helper(bool is_composite)
548554

549555
const NodeContext& node = EnsureAnyNodeContext(request.context);
550556
const ChainstateManager& chainman = EnsureChainman(node);
557+
CHECK_NONFATAL(node.dmnman);
551558

552559
UniValue obj(UniValue::VOBJ);
553560

src/rpc/mining.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ static RPCHelpMan generateblock()
393393
block.vtx.insert(block.vtx.end(), txs.begin(), txs.end());
394394

395395
{
396+
CHECK_NONFATAL(node.evodb);
397+
396398
LOCK(cs_main);
397399

398400
BlockValidationState state;
@@ -704,6 +706,7 @@ static RPCHelpMan getblocktemplate()
704706
}
705707

706708
LLMQContext& llmq_ctx = EnsureLLMQContext(node);
709+
CHECK_NONFATAL(node.evodb);
707710

708711
CBlockIndex* const pindexPrev = active_chain.Tip();
709712
// TestBlockValidity only supports blocks built on the current Tip
@@ -733,6 +736,7 @@ static RPCHelpMan getblocktemplate()
733736
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
734737

735738
const CConnman& connman = EnsureConnman(node);
739+
CHECK_NONFATAL(node.sporkman);
736740
if (connman.GetNodeCount(ConnectionDirection::Both) == 0)
737741
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, PACKAGE_NAME " is not connected!");
738742

src/rpc/misc.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ static RPCHelpMan mnsync()
108108
std::string strMode = request.params[0].get_str();
109109

110110
const NodeContext& node = EnsureAnyNodeContext(request.context);
111+
CHECK_NONFATAL(node.mn_sync);
111112
auto& mn_sync = *node.mn_sync;
112113

113114
if(strMode == "status") {
@@ -170,6 +171,7 @@ static RPCHelpMan spork()
170171
// basic mode, show info
171172
std:: string strCommand = request.params[0].get_str();
172173
const NodeContext& node = EnsureAnyNodeContext(request.context);
174+
CHECK_NONFATAL(node.sporkman);
173175
if (strCommand == "show") {
174176
UniValue ret(UniValue::VOBJ);
175177
for (const auto& sporkDef : sporkDefs) {
@@ -215,6 +217,7 @@ static RPCHelpMan sporkupdate()
215217

216218
const NodeContext& node = EnsureAnyNodeContext(request.context);
217219
PeerManager& peerman = EnsurePeerman(node);
220+
CHECK_NONFATAL(node.sporkman);
218221

219222
// SPORK VALUE
220223
int64_t nValue = request.params[1].get_int64();

src/rpc/quorums.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ static RPCHelpMan quorum_dkgstatus()
279279
const NodeContext& node = EnsureAnyNodeContext(request.context);
280280
const ChainstateManager& chainman = EnsureChainman(node);
281281
const LLMQContext& llmq_ctx = EnsureLLMQContext(node);
282+
CHECK_NONFATAL(node.connman);
283+
CHECK_NONFATAL(node.dmnman);
284+
CHECK_NONFATAL(node.sporkman);
282285

283286
int detailLevel = 0;
284287
if (!request.params[0].isNull()) {
@@ -381,6 +384,7 @@ static RPCHelpMan quorum_memberof()
381384
const NodeContext& node = EnsureAnyNodeContext(request.context);
382385
const ChainstateManager& chainman = EnsureChainman(node);
383386
const LLMQContext& llmq_ctx = EnsureLLMQContext(node);
387+
CHECK_NONFATAL(node.connman);
384388

385389
uint256 protxHash(ParseHashV(request.params[0], "proTxHash"));
386390
int scanQuorumsCount = -1;
@@ -747,6 +751,7 @@ static RPCHelpMan quorum_getdata()
747751
const NodeContext& node = EnsureAnyNodeContext(request.context);
748752
const ChainstateManager& chainman = EnsureChainman(node);
749753
const LLMQContext& llmq_ctx = EnsureLLMQContext(node);
754+
CHECK_NONFATAL(node.connman);
750755

751756
NodeId nodeId = ParseInt64V(request.params[0], "nodeId");
752757
Consensus::LLMQType llmqType = static_cast<Consensus::LLMQType>(ParseInt32V(request.params[1], "llmqType"));
@@ -791,6 +796,7 @@ static RPCHelpMan quorum_rotationinfo()
791796
{
792797
const NodeContext& node = EnsureAnyNodeContext(request.context);
793798
const LLMQContext& llmq_ctx = EnsureLLMQContext(node);
799+
CHECK_NONFATAL(node.dmnman);
794800

795801
llmq::CGetQuorumRotationInfo cmd;
796802
llmq::CQuorumRotationInfo quorumRotationInfoRet;

src/rpc/rawtransaction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,8 @@ static RPCHelpMan getassetunlockstatuses()
490490
throw JSONRPCError(RPC_INTERNAL_ERROR, "No blocks in chain");
491491
}
492492

493+
CHECK_NONFATAL(node.cpoolman);
494+
493495
std::optional<CCreditPool> poolCL{std::nullopt};
494496
std::optional<CCreditPool> poolOnTip{std::nullopt};
495497
std::optional<int> nSpecificCoreHeight{std::nullopt};

0 commit comments

Comments
 (0)