Skip to content

Commit dc15420

Browse files
committed
refactor: use EnsureConnman and EnsurePeerman when possible
1 parent dc01f07 commit dc15420

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

src/rpc/coinjoin.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <coinjoin/context.h>
88
#include <coinjoin/server.h>
99
#include <rpc/blockchain.h>
10+
#include <rpc/net.h>
1011
#include <rpc/server.h>
1112
#include <rpc/util.h>
1213
#include <util/strencodings.h>
@@ -69,8 +70,8 @@ static RPCHelpMan coinjoin()
6970
}
7071

7172
CTxMemPool& mempool = EnsureMemPool(node);
72-
CHECK_NONFATAL(node.connman);
73-
bool result = cj_clientman->DoAutomaticDenominating(*node.connman, mempool);
73+
CConnman& connman = EnsureConnman(node);
74+
bool result = cj_clientman->DoAutomaticDenominating(connman, mempool);
7475
return "Mixing " + (result ? "started successfully" : ("start failed: " + cj_clientman->GetStatuses().original + ", will retry"));
7576
}
7677

src/rpc/governance.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <node/context.h>
1717
#include <net.h>
1818
#include <rpc/blockchain.h>
19+
#include <rpc/net.h>
1920
#include <rpc/server.h>
2021
#include <rpc/util.h>
2122
#include <governance/common.h>
@@ -398,13 +399,13 @@ static UniValue gobject_submit(const JSONRPCRequest& request)
398399

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

401-
CHECK_NONFATAL(node.peerman);
402+
PeerManager& peerman = EnsurePeerman(node);
402403
if (fMissingConfirmations) {
403404
CHECK_NONFATAL(node.mn_sync);
404405
node.govman->AddPostponedObject(govobj);
405-
govobj.Relay(*node.peerman, *node.mn_sync);
406+
govobj.Relay(peerman, *node.mn_sync);
406407
} else {
407-
node.govman->AddGovernanceObject(govobj, *node.peerman);
408+
node.govman->AddGovernanceObject(govobj, peerman);
408409
}
409410

410411
return govobj.GetHash().ToString();
@@ -456,9 +457,9 @@ static UniValue VoteWithMasternodes(const JSONRPCRequest& request, const std::ma
456457
}
457458

458459
CGovernanceException exception;
459-
CHECK_NONFATAL(node.connman);
460-
CHECK_NONFATAL(node.peerman);
461-
if (node.govman->ProcessVoteAndRelay(vote, exception, *node.connman, *node.peerman)) {
460+
CConnman& connman = EnsureConnman(node);
461+
PeerManager& peerman = EnsurePeerman(node);
462+
if (node.govman->ProcessVoteAndRelay(vote, exception, connman, peerman)) {
462463
nSuccessful++;
463464
statusObj.pushKV("result", "success");
464465
} else {
@@ -1045,11 +1046,11 @@ static UniValue voteraw(const JSONRPCRequest& request)
10451046
throw JSONRPCError(RPC_INTERNAL_ERROR, "Failure to verify vote.");
10461047
}
10471048

1048-
CHECK_NONFATAL(node.connman);
1049-
CHECK_NONFATAL(node.peerman);
1049+
CConnman& connman = EnsureConnman(node);
1050+
PeerManager& peerman = EnsurePeerman(node);
10501051

10511052
CGovernanceException exception;
1052-
if (node.govman->ProcessVoteAndRelay(vote, exception, *node.connman, *node.peerman)) {
1053+
if (node.govman->ProcessVoteAndRelay(vote, exception, connman, peerman)) {
10531054
return "Voted successfully";
10541055
} else {
10551056
throw JSONRPCError(RPC_INTERNAL_ERROR, "Error voting : " + exception.GetMessage());

src/rpc/masternode.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <net.h>
1616
#include <netbase.h>
1717
#include <rpc/blockchain.h>
18+
#include <rpc/net.h>
1819
#include <rpc/server.h>
1920
#include <rpc/util.h>
2021
#include <univalue.h>
@@ -47,10 +48,10 @@ static RPCHelpMan masternode_connect()
4748
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("Incorrect masternode address %s", strAddress));
4849

4950
const NodeContext& node = EnsureAnyNodeContext(request.context);
50-
CHECK_NONFATAL(node.connman);
51+
CConnman& connman = EnsureConnman(node);
5152

52-
node.connman->OpenMasternodeConnection(CAddress(addr, NODE_NETWORK));
53-
if (!node.connman->IsConnected(CAddress(addr, NODE_NETWORK), CConnman::AllNodes))
53+
connman.OpenMasternodeConnection(CAddress(addr, NODE_NETWORK));
54+
if (!connman.IsConnected(CAddress(addr, NODE_NETWORK), CConnman::AllNodes))
5455
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("Couldn't connect to masternode %s", strAddress));
5556

5657
return "successfully connected";

src/rpc/quorums.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <index/txindex.h>
88
#include <node/context.h>
99
#include <rpc/blockchain.h>
10+
#include <rpc/net.h>
1011
#include <rpc/server.h>
1112
#include <rpc/util.h>
1213
#include <validation.h>
@@ -279,7 +280,7 @@ static RPCHelpMan quorum_dkgstatus()
279280
const NodeContext& node = EnsureAnyNodeContext(request.context);
280281
const ChainstateManager& chainman = EnsureChainman(node);
281282
const LLMQContext& llmq_ctx = EnsureLLMQContext(node);
282-
CHECK_NONFATAL(node.connman);
283+
const CConnman& connman = EnsureConnman(node);
283284
CHECK_NONFATAL(node.dmnman);
284285
CHECK_NONFATAL(node.sporkman);
285286

@@ -325,7 +326,7 @@ static RPCHelpMan quorum_dkgstatus()
325326
auto allConnections = llmq::utils::GetQuorumConnections(llmq_params, *node.dmnman, *node.sporkman, pQuorumBaseBlockIndex, proTxHash, false);
326327
auto outboundConnections = llmq::utils::GetQuorumConnections(llmq_params, *node.dmnman, *node.sporkman, pQuorumBaseBlockIndex, proTxHash, true);
327328
std::map<uint256, CAddress> foundConnections;
328-
node.connman->ForEachNode([&](const CNode* pnode) {
329+
connman.ForEachNode([&](const CNode* pnode) {
329330
auto verifiedProRegTxHash = pnode->GetVerifiedProRegTxHash();
330331
if (!verifiedProRegTxHash.IsNull() && allConnections.count(verifiedProRegTxHash)) {
331332
foundConnections.emplace(verifiedProRegTxHash, pnode->addr);
@@ -384,7 +385,7 @@ static RPCHelpMan quorum_memberof()
384385
const NodeContext& node = EnsureAnyNodeContext(request.context);
385386
const ChainstateManager& chainman = EnsureChainman(node);
386387
const LLMQContext& llmq_ctx = EnsureLLMQContext(node);
387-
CHECK_NONFATAL(node.connman);
388+
CHECK_NONFATAL(node.dmnman);
388389

389390
uint256 protxHash(ParseHashV(request.params[0], "proTxHash"));
390391
int scanQuorumsCount = -1;
@@ -751,7 +752,7 @@ static RPCHelpMan quorum_getdata()
751752
const NodeContext& node = EnsureAnyNodeContext(request.context);
752753
const ChainstateManager& chainman = EnsureChainman(node);
753754
const LLMQContext& llmq_ctx = EnsureLLMQContext(node);
754-
CHECK_NONFATAL(node.connman);
755+
CConnman& connman = EnsureConnman(node);
755756

756757
NodeId nodeId = ParseInt64V(request.params[0], "nodeId");
757758
Consensus::LLMQType llmqType = static_cast<Consensus::LLMQType>(ParseInt32V(request.params[1], "llmqType"));
@@ -773,7 +774,7 @@ static RPCHelpMan quorum_getdata()
773774

774775
const CBlockIndex* pQuorumBaseBlockIndex = WITH_LOCK(cs_main, return chainman.m_blockman.LookupBlockIndex(quorumHash));
775776

776-
return node.connman->ForNode(nodeId, [&](CNode* pNode) {
777+
return connman.ForNode(nodeId, [&](CNode* pNode) {
777778
return llmq_ctx.qman->RequestQuorumData(pNode, llmqType, pQuorumBaseBlockIndex, nDataMask, proTxHash);
778779
});
779780
},

0 commit comments

Comments
 (0)