refactor: use EnsureConnman and EnsurePeerman when possible

This commit is contained in:
Konstantin Akimov 2024-06-17 23:17:28 +07:00
parent dc01f07f74
commit dc15420470
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524
4 changed files with 23 additions and 19 deletions

View File

@ -7,6 +7,7 @@
#include <coinjoin/context.h>
#include <coinjoin/server.h>
#include <rpc/blockchain.h>
#include <rpc/net.h>
#include <rpc/server.h>
#include <rpc/util.h>
#include <util/strencodings.h>
@ -69,8 +70,8 @@ static RPCHelpMan coinjoin()
}
CTxMemPool& mempool = EnsureMemPool(node);
CHECK_NONFATAL(node.connman);
bool result = cj_clientman->DoAutomaticDenominating(*node.connman, mempool);
CConnman& connman = EnsureConnman(node);
bool result = cj_clientman->DoAutomaticDenominating(connman, mempool);
return "Mixing " + (result ? "started successfully" : ("start failed: " + cj_clientman->GetStatuses().original + ", will retry"));
}

View File

@ -16,6 +16,7 @@
#include <node/context.h>
#include <net.h>
#include <rpc/blockchain.h>
#include <rpc/net.h>
#include <rpc/server.h>
#include <rpc/util.h>
#include <governance/common.h>
@ -398,13 +399,13 @@ static UniValue gobject_submit(const JSONRPCRequest& request)
LogPrintf("gobject(submit) -- Adding locally created governance object - %s\n", strHash);
CHECK_NONFATAL(node.peerman);
PeerManager& peerman = EnsurePeerman(node);
if (fMissingConfirmations) {
CHECK_NONFATAL(node.mn_sync);
node.govman->AddPostponedObject(govobj);
govobj.Relay(*node.peerman, *node.mn_sync);
govobj.Relay(peerman, *node.mn_sync);
} else {
node.govman->AddGovernanceObject(govobj, *node.peerman);
node.govman->AddGovernanceObject(govobj, peerman);
}
return govobj.GetHash().ToString();
@ -456,9 +457,9 @@ static UniValue VoteWithMasternodes(const JSONRPCRequest& request, const std::ma
}
CGovernanceException exception;
CHECK_NONFATAL(node.connman);
CHECK_NONFATAL(node.peerman);
if (node.govman->ProcessVoteAndRelay(vote, exception, *node.connman, *node.peerman)) {
CConnman& connman = EnsureConnman(node);
PeerManager& peerman = EnsurePeerman(node);
if (node.govman->ProcessVoteAndRelay(vote, exception, connman, peerman)) {
nSuccessful++;
statusObj.pushKV("result", "success");
} else {
@ -1045,11 +1046,11 @@ static UniValue voteraw(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INTERNAL_ERROR, "Failure to verify vote.");
}
CHECK_NONFATAL(node.connman);
CHECK_NONFATAL(node.peerman);
CConnman& connman = EnsureConnman(node);
PeerManager& peerman = EnsurePeerman(node);
CGovernanceException exception;
if (node.govman->ProcessVoteAndRelay(vote, exception, *node.connman, *node.peerman)) {
if (node.govman->ProcessVoteAndRelay(vote, exception, connman, peerman)) {
return "Voted successfully";
} else {
throw JSONRPCError(RPC_INTERNAL_ERROR, "Error voting : " + exception.GetMessage());

View File

@ -15,6 +15,7 @@
#include <net.h>
#include <netbase.h>
#include <rpc/blockchain.h>
#include <rpc/net.h>
#include <rpc/server.h>
#include <rpc/util.h>
#include <univalue.h>
@ -47,10 +48,10 @@ static RPCHelpMan masternode_connect()
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("Incorrect masternode address %s", strAddress));
const NodeContext& node = EnsureAnyNodeContext(request.context);
CHECK_NONFATAL(node.connman);
CConnman& connman = EnsureConnman(node);
node.connman->OpenMasternodeConnection(CAddress(addr, NODE_NETWORK));
if (!node.connman->IsConnected(CAddress(addr, NODE_NETWORK), CConnman::AllNodes))
connman.OpenMasternodeConnection(CAddress(addr, NODE_NETWORK));
if (!connman.IsConnected(CAddress(addr, NODE_NETWORK), CConnman::AllNodes))
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("Couldn't connect to masternode %s", strAddress));
return "successfully connected";

View File

@ -7,6 +7,7 @@
#include <index/txindex.h>
#include <node/context.h>
#include <rpc/blockchain.h>
#include <rpc/net.h>
#include <rpc/server.h>
#include <rpc/util.h>
#include <validation.h>
@ -279,7 +280,7 @@ static RPCHelpMan quorum_dkgstatus()
const NodeContext& node = EnsureAnyNodeContext(request.context);
const ChainstateManager& chainman = EnsureChainman(node);
const LLMQContext& llmq_ctx = EnsureLLMQContext(node);
CHECK_NONFATAL(node.connman);
const CConnman& connman = EnsureConnman(node);
CHECK_NONFATAL(node.dmnman);
CHECK_NONFATAL(node.sporkman);
@ -325,7 +326,7 @@ static RPCHelpMan quorum_dkgstatus()
auto allConnections = llmq::utils::GetQuorumConnections(llmq_params, *node.dmnman, *node.sporkman, pQuorumBaseBlockIndex, proTxHash, false);
auto outboundConnections = llmq::utils::GetQuorumConnections(llmq_params, *node.dmnman, *node.sporkman, pQuorumBaseBlockIndex, proTxHash, true);
std::map<uint256, CAddress> foundConnections;
node.connman->ForEachNode([&](const CNode* pnode) {
connman.ForEachNode([&](const CNode* pnode) {
auto verifiedProRegTxHash = pnode->GetVerifiedProRegTxHash();
if (!verifiedProRegTxHash.IsNull() && allConnections.count(verifiedProRegTxHash)) {
foundConnections.emplace(verifiedProRegTxHash, pnode->addr);
@ -384,7 +385,7 @@ static RPCHelpMan quorum_memberof()
const NodeContext& node = EnsureAnyNodeContext(request.context);
const ChainstateManager& chainman = EnsureChainman(node);
const LLMQContext& llmq_ctx = EnsureLLMQContext(node);
CHECK_NONFATAL(node.connman);
CHECK_NONFATAL(node.dmnman);
uint256 protxHash(ParseHashV(request.params[0], "proTxHash"));
int scanQuorumsCount = -1;
@ -751,7 +752,7 @@ static RPCHelpMan quorum_getdata()
const NodeContext& node = EnsureAnyNodeContext(request.context);
const ChainstateManager& chainman = EnsureChainman(node);
const LLMQContext& llmq_ctx = EnsureLLMQContext(node);
CHECK_NONFATAL(node.connman);
CConnman& connman = EnsureConnman(node);
NodeId nodeId = ParseInt64V(request.params[0], "nodeId");
Consensus::LLMQType llmqType = static_cast<Consensus::LLMQType>(ParseInt32V(request.params[1], "llmqType"));
@ -773,7 +774,7 @@ static RPCHelpMan quorum_getdata()
const CBlockIndex* pQuorumBaseBlockIndex = WITH_LOCK(cs_main, return chainman.m_blockman.LookupBlockIndex(quorumHash));
return node.connman->ForNode(nodeId, [&](CNode* pNode) {
return connman.ForNode(nodeId, [&](CNode* pNode) {
return llmq_ctx.qman->RequestQuorumData(pNode, llmqType, pQuorumBaseBlockIndex, nDataMask, proTxHash);
});
},