Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

masternode-utils.cpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2020 The Dash Core developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
6 
7 #include <init.h>
9 #ifdef ENABLE_WALLET
11 #endif
12 #include <validation.h>
13 
15 {
16  bool operator()(const std::pair<arith_uint256, const CDeterministicMNCPtr&>& t1,
17  const std::pair<arith_uint256, const CDeterministicMNCPtr&>& t2) const
18  {
19  return (t1.first != t2.first) ? (t1.first < t2.first) : (t1.second->collateralOutpoint < t2.second->collateralOutpoint);
20  }
21 };
22 
24 {
25  std::vector<CDeterministicMNCPtr> vecDmns; // will be empty when no wallet
26 #ifdef ENABLE_WALLET
28 #endif // ENABLE_WALLET
29 
30  // Don't disconnect masternode connections when we have less then the desired amount of outbound nodes
31  int nonMasternodeCount = 0;
32  connman.ForEachNode(CConnman::AllNodes, [&](CNode* pnode) {
33  if (!pnode->fInbound && !pnode->fFeeler && !pnode->m_manual_connection && !pnode->fMasternode && !pnode->fMasternodeProbe) {
34  nonMasternodeCount++;
35  }
36  });
37  if (nonMasternodeCount < connman.GetMaxOutboundNodeCount()) {
38  return;
39  }
40 
41  connman.ForEachNode(CConnman::AllNodes, [&](CNode* pnode) {
42  // we're only disconnecting fMasternode connections
43  if (!pnode->fMasternode) return;
44  // we're only disconnecting outbound connections
45  if (pnode->fInbound) return;
46  // we're not disconnecting LLMQ connections
47  if (connman.IsMasternodeQuorumNode(pnode)) return;
48  // we're not disconnecting masternode probes for at least a few seconds
49  if (pnode->fMasternodeProbe && GetSystemTimeInSeconds() - pnode->nTimeConnected < 5) return;
50 
51 #ifdef ENABLE_WALLET
52  bool fFound = false;
53  for (const auto& dmn : vecDmns) {
54  if (pnode->addr == dmn->pdmnState->addr) {
55  fFound = true;
56  break;
57  }
58  }
59  if (fFound) return; // do NOT disconnect mixing masternodes
60 #endif // ENABLE_WALLET
61  if (fLogIPs) {
62  LogPrintf("Closing Masternode connection: peer=%d, addr=%s\n", pnode->GetId(), pnode->addr.ToString());
63  } else {
64  LogPrintf("Closing Masternode connection: peer=%d\n", pnode->GetId());
65  }
66  pnode->fDisconnect = true;
67  });
68 }
69 
71 {
73  return;
74 
75  static unsigned int nTick = 0;
76 
77  nTick++;
78 
79  if(nTick % 60 == 0) {
81  }
82 }
83 
bool operator()(const std::pair< arith_uint256, const CDeterministicMNCPtr &> &t1, const std::pair< arith_uint256, const CDeterministicMNCPtr &> &t2) const
static constexpr const CAllNodes AllNodes
Definition: net.h:225
CMasternodeSync masternodeSync
std::string ToString(bool fUseGetnameinfo=true) const
Definition: netaddress.cpp:581
bool ShutdownRequested()
Definition: init.cpp:179
size_t GetMaxOutboundNodeCount()
Definition: net.cpp:3425
static void DoMaintenance(CConnman &connman)
bool fMasternode
Definition: net.h:864
bool IsBlockchainSynced()
void ForEachNode(const Condition &cond, Callable &&func)
Definition: net.h:288
bool IsMasternodeQuorumNode(const CNode *pnode)
Definition: net.cpp:3372
#define LogPrintf(...)
Definition: util.h:203
int64_t GetSystemTimeInSeconds()
Returns the system time (not mockable)
Definition: utiltime.cpp:70
bool m_manual_connection
Definition: net.h:848
Definition: net.h:136
bool fMasternodeProbe
Definition: net.h:866
NodeId GetId() const
Definition: net.h:973
std::atomic_bool fDisconnect
Definition: net.h:853
const CAddress addr
Definition: net.h:834
const int64_t nTimeConnected
Definition: net.h:828
bool fLogIPs
Definition: util.cpp:115
bool fFeeler
Definition: net.h:846
const bool fInbound
Definition: net.h:851
CPrivateSendClientManager privateSendClient
bool GetMixingMasternodesInfo(std::vector< CDeterministicMNCPtr > &vecDmnsRet) const
Information about a peer.
Definition: net.h:800
static void ProcessMasternodeConnections(CConnman &connman)
Released under the MIT license