Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Only reply with mnauth to peers that are connected to the address registered in DML #4974

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
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
Loading