Skip to content

Commit

Permalink
fix: Only reply with mnauth to peers that are connected to the addr…
Browse files Browse the repository at this point in the history
…ess registered in DML (reworked)

A node can be bound to multiple addresses. Send `mnauth` to nodes connected to the right address only to avoid confusion.
  • Loading branch information
UdjinM6 committed Nov 16, 2023
1 parent a81310a commit 4ddda42
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/evo/mnauth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <masternode/node.h>
#include <masternode/sync.h>
#include <net.h>
#include <netbase.h>
#include <net_processing.h>
#include <netmessagemaker.h>
#include <util/time.h>
Expand All @@ -25,6 +26,21 @@ void CMNAuth::PushMNAUTH(CNode& peer, CConnman& connman, const CBlockIndex* tip)
return;
}

// NOTE: this relies on the fact that:
// - regtest masternodes are all 127.0.0.1,
// - non-regtest masternodes must have routable IPs
CNetAddr addrLocalHost;
bool ok = LookupHost("127.0.0.1", addrLocalHost, false);
assert(ok);
CNetAddr addrLocal = activeMasternodeInfo.service.IsRoutable()
? static_cast<CNetAddr>(peer.GetAddrLocal())
: addrLocalHost;
if (addrLocal != static_cast<CNetAddr>(activeMasternodeInfo.service)) {
LogPrint(BCLog::NET_NETCONN, "CMNAuth::%s -- Our IP reported by the peer and IP we were registered with in DML are different (%s != %s), not sending MNAUTH, peer=%d\n",
__func__, addrLocal.ToStringIP(), activeMasternodeInfo.service.ToStringIP(), peer.GetId());
return;
}

uint256 signHash;
const auto receivedMNAuthChallenge = peer.GetReceivedMNAuthChallenge();
if (receivedMNAuthChallenge.IsNull()) {
Expand Down

0 comments on commit 4ddda42

Please sign in to comment.