Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,7 @@ static RPCHelpMan verifychain()
const int check_depth{request.params[1].isNull() ? DEFAULT_CHECKBLOCKS : request.params[1].get_int()};

const NodeContext& node = EnsureAnyNodeContext(request.context);
CHECK_NONFATAL(node.evodb);

ChainstateManager& chainman = EnsureChainman(node);
LOCK(cs_main);
Expand Down Expand Up @@ -2962,7 +2963,8 @@ static RPCHelpMan dumptxoutset()
FILE* file{fsbridge::fopen(temppath, "wb")};
CAutoFile afile{file, SER_DISK, CLIENT_VERSION};
NodeContext& node = EnsureAnyNodeContext(request.context);
UniValue result = CreateUTXOSnapshot(node, node.chainman->ActiveChainstate(), afile);
const ChainstateManager& chainman = EnsureChainman(node);
UniValue result = CreateUTXOSnapshot(node, chainman.ActiveChainstate(), afile);
fs::rename(temppath, path);

result.pushKV("path", path.string());
Expand Down
4 changes: 3 additions & 1 deletion src/rpc/coinjoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -69,7 +70,8 @@ static RPCHelpMan coinjoin()
}

CTxMemPool& mempool = EnsureMemPool(node);
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"));
}

Expand Down
1 change: 1 addition & 0 deletions src/rpc/evo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,7 @@ static UniValue protx(const JSONRPCRequest& request)
} else if (command == "protxinfo") {
return protx_info(new_request, dmnman, mn_metaman, chainman);
} else if (command == "protxdiff") {
CHECK_NONFATAL(node.llmq_ctx);
return protx_diff(new_request, dmnman, chainman, *node.llmq_ctx);
} else if (command == "protxlistdiff") {
return protx_listdiff(new_request, dmnman, chainman);
Expand Down
26 changes: 22 additions & 4 deletions src/rpc/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -53,6 +54,7 @@ static UniValue gobject_count(const JSONRPCRequest& request)
gobject_count_help(request);

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

Expand Down Expand Up @@ -309,6 +311,8 @@ static UniValue gobject_submit(const JSONRPCRequest& request)
gobject_submit_help(request);

const NodeContext& node = EnsureAnyNodeContext(request.context);
CHECK_NONFATAL(node.dmnman);
CHECK_NONFATAL(node.govman);

if(!node.mn_sync->IsBlockchainSynced()) {
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Must wait for client to sync with masternode network. Try again in a minute or so.");
Expand Down Expand Up @@ -395,11 +399,13 @@ static UniValue gobject_submit(const JSONRPCRequest& request)

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

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();
Expand All @@ -410,6 +416,7 @@ static UniValue VoteWithMasternodes(const JSONRPCRequest& request, const std::ma
vote_outcome_enum_t eVoteOutcome)
{
const NodeContext& node = EnsureAnyNodeContext(request.context);
CHECK_NONFATAL(node.govman);
{
LOCK(node.govman->cs);
const CGovernanceObject *pGovObj = node.govman->FindConstGovernanceObject(hash);
Expand Down Expand Up @@ -450,7 +457,9 @@ static UniValue VoteWithMasternodes(const JSONRPCRequest& request, const std::ma
}

CGovernanceException exception;
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 {
Expand Down Expand Up @@ -493,6 +502,7 @@ static UniValue gobject_vote_many(const JSONRPCRequest& request)
if (!wallet) return NullUniValue;

const NodeContext& node = EnsureAnyNodeContext(request.context);
CHECK_NONFATAL(node.dmnman);

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

const NodeContext& node = EnsureAnyNodeContext(request.context);
CHECK_NONFATAL(node.dmnman);

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

const NodeContext& node = EnsureAnyNodeContext(request.context);
CHECK_NONFATAL(node.dmnman);
CHECK_NONFATAL(node.govman);

return ListObjects(*node.govman, node.dmnman->GetListAtChainTip(), strCachedSignal, strType, 0);
}
Expand Down Expand Up @@ -857,6 +869,7 @@ static UniValue gobject_getcurrentvotes(const JSONRPCRequest& request)

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

LOCK(node.govman->cs);
const CGovernanceObject* pGovObj = node.govman->FindConstGovernanceObject(hash);
Expand Down Expand Up @@ -995,6 +1008,7 @@ static UniValue voteraw(const JSONRPCRequest& request)
}

const NodeContext& node = EnsureAnyNodeContext(request.context);
CHECK_NONFATAL(node.govman);
GovernanceObject govObjType = WITH_LOCK(node.govman->cs, return [&](){
AssertLockHeld(node.govman->cs);
const CGovernanceObject *pGovObj = node.govman->FindConstGovernanceObject(hashGovObj);
Expand Down Expand Up @@ -1032,8 +1046,11 @@ static UniValue voteraw(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INTERNAL_ERROR, "Failure to verify vote.");
}

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());
Expand Down Expand Up @@ -1068,6 +1085,7 @@ static UniValue getgovernanceinfo(const JSONRPCRequest& request)

const NodeContext& node = EnsureAnyNodeContext(request.context);
const ChainstateManager& chainman = EnsureAnyChainman(request.context);
CHECK_NONFATAL(node.dmnman);

const auto* pindex = WITH_LOCK(cs_main, return chainman.ActiveChain().Tip());
int nBlockHeight = pindex->nHeight;
Expand Down
16 changes: 12 additions & 4 deletions src/rpc/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -47,8 +48,10 @@ static RPCHelpMan masternode_connect()
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("Incorrect masternode address %s", strAddress));

const NodeContext& node = EnsureAnyNodeContext(request.context);
node.connman->OpenMasternodeConnection(CAddress(addr, NODE_NETWORK));
if (!node.connman->IsConnected(CAddress(addr, NODE_NETWORK), CConnman::AllNodes))
CConnman& connman = EnsureConnman(node);

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";
Expand Down Expand Up @@ -133,6 +136,7 @@ static RPCHelpMan masternode_winner()
}

const NodeContext& node = EnsureAnyNodeContext(request.context);
CHECK_NONFATAL(node.dmnman);
return GetNextMasternodeForPayment(*node.dmnman, 10);
},
};
Expand All @@ -152,6 +156,7 @@ static RPCHelpMan masternode_current()
}

const NodeContext& node = EnsureAnyNodeContext(request.context);
CHECK_NONFATAL(node.dmnman);
return GetNextMasternodeForPayment(*node.dmnman, 1);
},
};
Expand Down Expand Up @@ -204,6 +209,7 @@ static RPCHelpMan masternode_status()
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
const NodeContext& node = EnsureAnyNodeContext(request.context);
CHECK_NONFATAL(node.dmnman);
if (!node.mn_activeman) {
throw JSONRPCError(RPC_INTERNAL_ERROR, "This node does not run an active masternode.");
}
Expand Down Expand Up @@ -302,6 +308,7 @@ static RPCHelpMan masternode_winners()
int nStartHeight = std::max(nChainTipHeight - nCount, 1);

CHECK_NONFATAL(node.dmnman);
CHECK_NONFATAL(node.govman);

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

CHECK_NONFATAL(node.chain_helper);
CHECK_NONFATAL(node.dmnman);
while (vecPayments.size() < uint64_t(std::abs(nCount)) && pindex != nullptr) {
CBlock block;
if (!ReadBlockFromDisk(block, pindex, Params().GetConsensus())) {
Expand All @@ -407,8 +416,6 @@ static RPCHelpMan masternode_payments()
nBlockFees += nValueIn - tx->GetValueOut();
}

CHECK_NONFATAL(node.chain_helper);

std::vector<CTxOut> voutMasternodePayments, voutDummy;
CMutableTransaction dummyTx;
CAmount blockSubsidy = GetBlockSubsidy(pindex, Params().GetConsensus());
Expand Down Expand Up @@ -548,6 +555,7 @@ static RPCHelpMan masternodelist_helper(bool is_composite)

const NodeContext& node = EnsureAnyNodeContext(request.context);
const ChainstateManager& chainman = EnsureChainman(node);
CHECK_NONFATAL(node.dmnman);

UniValue obj(UniValue::VOBJ);

Expand Down
4 changes: 4 additions & 0 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ static RPCHelpMan generateblock()
block.vtx.insert(block.vtx.end(), txs.begin(), txs.end());

{
CHECK_NONFATAL(node.evodb);

LOCK(cs_main);

BlockValidationState state;
Expand Down Expand Up @@ -704,6 +706,7 @@ static RPCHelpMan getblocktemplate()
}

LLMQContext& llmq_ctx = EnsureLLMQContext(node);
CHECK_NONFATAL(node.evodb);

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

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

Expand Down
3 changes: 3 additions & 0 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ static RPCHelpMan mnsync()
std::string strMode = request.params[0].get_str();

const NodeContext& node = EnsureAnyNodeContext(request.context);
CHECK_NONFATAL(node.mn_sync);
auto& mn_sync = *node.mn_sync;

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

const NodeContext& node = EnsureAnyNodeContext(request.context);
PeerManager& peerman = EnsurePeerman(node);
CHECK_NONFATAL(node.sporkman);

// SPORK VALUE
int64_t nValue = request.params[1].get_int64();
Expand Down
11 changes: 9 additions & 2 deletions src/rpc/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -279,6 +280,9 @@ static RPCHelpMan quorum_dkgstatus()
const NodeContext& node = EnsureAnyNodeContext(request.context);
const ChainstateManager& chainman = EnsureChainman(node);
const LLMQContext& llmq_ctx = EnsureLLMQContext(node);
const CConnman& connman = EnsureConnman(node);
CHECK_NONFATAL(node.dmnman);
CHECK_NONFATAL(node.sporkman);

int detailLevel = 0;
if (!request.params[0].isNull()) {
Expand Down Expand Up @@ -322,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);
Expand Down Expand Up @@ -381,6 +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.dmnman);

uint256 protxHash(ParseHashV(request.params[0], "proTxHash"));
int scanQuorumsCount = -1;
Expand Down Expand Up @@ -747,6 +752,7 @@ static RPCHelpMan quorum_getdata()
const NodeContext& node = EnsureAnyNodeContext(request.context);
const ChainstateManager& chainman = EnsureChainman(node);
const LLMQContext& llmq_ctx = EnsureLLMQContext(node);
CConnman& connman = EnsureConnman(node);

NodeId nodeId = ParseInt64V(request.params[0], "nodeId");
Consensus::LLMQType llmqType = static_cast<Consensus::LLMQType>(ParseInt32V(request.params[1], "llmqType"));
Expand All @@ -768,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);
});
},
Expand All @@ -791,6 +797,7 @@ static RPCHelpMan quorum_rotationinfo()
{
const NodeContext& node = EnsureAnyNodeContext(request.context);
const LLMQContext& llmq_ctx = EnsureLLMQContext(node);
CHECK_NONFATAL(node.dmnman);

llmq::CGetQuorumRotationInfo cmd;
llmq::CQuorumRotationInfo quorumRotationInfoRet;
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ static RPCHelpMan getassetunlockstatuses()
throw JSONRPCError(RPC_INTERNAL_ERROR, "No blocks in chain");
}

CHECK_NONFATAL(node.cpoolman);

std::optional<CCreditPool> poolCL{std::nullopt};
std::optional<CCreditPool> poolOnTip{std::nullopt};
std::optional<int> nSpecificCoreHeight{std::nullopt};
Expand Down