Skip to content

Commit

Permalink
mn_net: store local DMN protxhash instead of access the activeMnManag…
Browse files Browse the repository at this point in the history
…er object.

Removing the following circular dependency:
"activemasternode -> net -> tiertwo/net_masternodes -> activemasternode"
  • Loading branch information
furszy committed Jan 17, 2022
1 parent 6015d90 commit 693bff6
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/activemasternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "messagesigner.h"
#include "netbase.h"
#include "protocol.h"
#include "tiertwo/net_masternodes.h"
#include "tiertwo/tiertwo_sync_state.h"
#include "validation.h"

Expand Down Expand Up @@ -133,6 +134,7 @@ void CActiveDeterministicMasternodeManager::Init(const CBlockIndex* pindexTip)
LogPrintf("%s: proTxHash=%s, proTx=%s\n", __func__, dmn->proTxHash.ToString(), dmn->ToString());

info.proTxHash = dmn->proTxHash;
g_connman->GetTierTwoConnMan()->setLocalDMN(info.proTxHash);

if (info.service != dmn->pdmnState->addr) {
state = MASTERNODE_ERROR;
Expand Down
1 change: 0 additions & 1 deletion src/activemasternode.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "key.h"
#include "evo/deterministicmns.h"
#include "net.h"
#include "operationresult.h"
#include "sync.h"
#include "validationinterface.h"
Expand Down
5 changes: 3 additions & 2 deletions src/evo/mnauth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
#include "activemasternode.h"
#include "chainparams.h"
#include "consensus/validation.h"
#include "tiertwo/masternode_meta_manager.h"
#include "net.h" // for CSerializedNetMsg
#include "netmessagemaker.h"
#include "llmq/quorums_utils.h"
#include "util/system.h" // for fMasternode and gArgs access
#include "tiertwo/masternode_meta_manager.h"
#include "tiertwo/net_masternodes.h"
#include "tiertwo/tiertwo_sync_state.h"
#include "util/system.h" // for fMasternode and gArgs access

#include "version.h" // for MNAUTH_NODE_VER_VERSION

Expand Down
4 changes: 2 additions & 2 deletions src/tiertwo/net_masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

#include "tiertwo/net_masternodes.h"

#include "activemasternode.h"
#include "chainparams.h"
#include "evo/deterministicmns.h"
#include "scheduler.h"
#include "tiertwo/masternode_meta_manager.h" // for g_mmetaman
#include "tiertwo/tiertwo_sync_state.h"
#include "net.h"
#include "netmessagemaker.h"

TierTwoConnMan::TierTwoConnMan(CConnman* _connman) : connman(_connman) {}
Expand Down Expand Up @@ -237,7 +237,7 @@ void TierTwoConnMan::ThreadOpenMasternodeConnections()
}

// Don't try to connect to ourselves
if (activeMasternodeManager && activeMasternodeManager->GetInfo()->proTxHash == proRegTxHash) {
if (WITH_LOCK(cs_vPendingMasternodes, return local_dmn_pro_tx_hash && *local_dmn_pro_tx_hash == proRegTxHash)) {
continue;
}

Expand Down
6 changes: 6 additions & 0 deletions src/tiertwo/net_masternodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class TierTwoConnMan
// Adds the DMNs to the pending to probe list
void addPendingProbeConnections(const std::set<uint256>& proTxHashes);

// Set the local DMN so the node does not try to connect to himself
void setLocalDMN(const uint256& pro_tx_hash) { WITH_LOCK(cs_vPendingMasternodes, local_dmn_pro_tx_hash = pro_tx_hash;); }

// Manages the MN connections
void ThreadOpenMasternodeConnections();
void start(CScheduler& scheduler, const TierTwoConnMan::Options& options);
Expand All @@ -72,6 +75,9 @@ class TierTwoConnMan
std::map<QuorumTypeAndHash, std::set<uint256>> masternodeQuorumRelayMembers GUARDED_BY(cs_vPendingMasternodes);
std::set<uint256> masternodePendingProbes GUARDED_BY(cs_vPendingMasternodes);

// The local DMN
Optional<uint256> local_dmn_pro_tx_hash GUARDED_BY(cs_vPendingMasternodes){nullopt};

// parent connections manager
CConnman* connman;

Expand Down
2 changes: 2 additions & 0 deletions test/lint/lint-circular-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
"masternode-payments -> validation -> masternode-payments"
"masternode-sync -> masternodeman -> masternode-sync"
"masternodeman -> validation -> masternodeman"
"net -> tiertwo/net_masternodes -> net"
"policy/fees -> txmempool -> policy/fees"
"policy/policy -> validation -> policy/policy"
"qt/pivx/addresseswidget -> qt/pivx/pivxgui -> qt/pivx/addresseswidget"
Expand Down Expand Up @@ -55,6 +56,7 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
"chain -> legacy/stakemodifier -> validation -> undo -> chain"
"chain -> legacy/stakemodifier -> validation -> pow -> chain"
"evo/deterministicmns -> masternodeman -> validation -> validationinterface -> evo/deterministicmns"
"evo/deterministicmns -> llmq/quorums_utils -> net -> tiertwo/net_masternodes -> evo/deterministicmns"
)

EXIT_CODE=0
Expand Down

0 comments on commit 693bff6

Please sign in to comment.