Skip to content

Commit 6ffc745

Browse files
knstPastaPastaPasta
authored andcommitted
refactor: evo/mnauth no more depends on net_processing
1 parent 3e31f29 commit 6ffc745

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

src/evo/mnauth.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <masternode/node.h>
1515
#include <masternode/sync.h>
1616
#include <net.h>
17-
#include <net_processing.h>
17+
#include <net_types.h>
1818
#include <netmessagemaker.h>
1919
#include <util/time.h>
2020
#include <validation.h>
@@ -58,37 +58,33 @@ void CMNAuth::PushMNAUTH(CNode& peer, CConnman& connman, const CBlockIndex* tip)
5858
connman.PushMessage(&peer, CNetMsgMaker(peer.GetSendVersion()).Make(NetMsgType::MNAUTH, mnauth));
5959
}
6060

61-
void CMNAuth::ProcessMessage(CNode& peer, PeerManager& peerman, CConnman& connman, std::string_view msg_type, CDataStream& vRecv)
61+
PeerMsgRet CMNAuth::ProcessMessage(CNode& peer, CConnman& connman, std::string_view msg_type, CDataStream& vRecv)
6262
{
6363
if (msg_type != NetMsgType::MNAUTH || !::masternodeSync->IsBlockchainSynced()) {
6464
// we can't verify MNAUTH messages when we don't have the latest MN list
65-
return;
65+
return {};
6666
}
6767

6868
CMNAuth mnauth;
6969
vRecv >> mnauth;
7070

7171
// only one MNAUTH allowed
7272
if (!peer.GetVerifiedProRegTxHash().IsNull()) {
73-
peerman.Misbehaving(peer.GetId(), 100, "duplicate mnauth");
74-
return;
73+
return tl::unexpected{MisbehavingError{100, "duplicate mnauth"}};
7574
}
7675

7776
if ((~peer.nServices) & (NODE_NETWORK | NODE_BLOOM)) {
7877
// either NODE_NETWORK or NODE_BLOOM bit is missing in node's services
79-
peerman.Misbehaving(peer.GetId(), 100, "mnauth from a node with invalid services");
80-
return;
78+
return tl::unexpected{MisbehavingError{100, "mnauth from a node with invalid services"}};
8179
}
8280

8381
if (mnauth.proRegTxHash.IsNull()) {
84-
peerman.Misbehaving(peer.GetId(), 100, "empty mnauth proRegTxHash");
85-
return;
82+
return tl::unexpected{MisbehavingError{100, "empty mnauth proRegTxHash"}};
8683
}
8784

8885
if (!mnauth.sig.IsValid()) {
89-
peerman.Misbehaving(peer.GetId(), 100, "invalid mnauth signature");
9086
LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- invalid mnauth for protx=%s with sig=%s\n", mnauth.proRegTxHash.ToString(), mnauth.sig.ToString());
91-
return;
87+
return tl::unexpected{MisbehavingError{100, "invalid mnauth signature"}};
9288
}
9389

9490
const auto mnList = deterministicMNManager->GetListAtChainTip();
@@ -97,8 +93,7 @@ void CMNAuth::ProcessMessage(CNode& peer, PeerManager& peerman, CConnman& connma
9793
// in case node was unlucky and not up to date, just let it be connected as a regular node, which gives it
9894
// a chance to get up-to-date and thus realize that it's not a MN anymore. We still give it a
9995
// low DoS score.
100-
peerman.Misbehaving(peer.GetId(), 10, "missing mnauth masternode");
101-
return;
96+
return tl::unexpected{MisbehavingError{10, "missing mnauth masternode"}};
10297
}
10398

10499
uint256 signHash;
@@ -120,8 +115,7 @@ void CMNAuth::ProcessMessage(CNode& peer, PeerManager& peerman, CConnman& connma
120115
if (!mnauth.sig.VerifyInsecure(dmn->pdmnState->pubKeyOperator.Get(), signHash)) {
121116
// Same as above, MN seems to not know its fate yet, so give it a chance to update. If this is a
122117
// malicious node (DoSing us), it'll get banned soon.
123-
peerman.Misbehaving(peer.GetId(), 10, "mnauth signature verification failed");
124-
return;
118+
return tl::unexpected{MisbehavingError{10, "mnauth signature verification failed"}};
125119
}
126120

127121
if (!peer.IsInboundConn()) {
@@ -130,7 +124,7 @@ void CMNAuth::ProcessMessage(CNode& peer, PeerManager& peerman, CConnman& connma
130124
LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- Masternode probe successful for %s, disconnecting. peer=%d\n",
131125
mnauth.proRegTxHash.ToString(), peer.GetId());
132126
peer.fDisconnect = true;
133-
return;
127+
return {};
134128
}
135129
}
136130

@@ -175,7 +169,7 @@ void CMNAuth::ProcessMessage(CNode& peer, PeerManager& peerman, CConnman& connma
175169
});
176170

177171
if (peer.fDisconnect) {
178-
return;
172+
return {};
179173
}
180174

181175
peer.SetVerifiedProRegTxHash(mnauth.proRegTxHash);
@@ -192,6 +186,7 @@ void CMNAuth::ProcessMessage(CNode& peer, PeerManager& peerman, CConnman& connma
192186
}
193187

194188
LogPrint(BCLog::NET_NETCONN, "CMNAuth::%s -- Valid MNAUTH for %s, peer=%d\n", __func__, mnauth.proRegTxHash.ToString(), peer.GetId());
189+
return {};
195190
}
196191

197192
void CMNAuth::NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff, CConnman& connman)

src/evo/mnauth.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define BITCOIN_EVO_MNAUTH_H
77

88
#include <bls/bls.h>
9+
#include <net_types.h>
910
#include <serialize.h>
1011

1112
class CBlockIndex;
@@ -15,7 +16,6 @@ class CDeterministicMN;
1516
class CDeterministicMNList;
1617
class CDeterministicMNListDiff;
1718
class CNode;
18-
class PeerManager;
1919

2020
class UniValue;
2121

@@ -48,7 +48,7 @@ class CMNAuth
4848
}
4949

5050
static void PushMNAUTH(CNode& peer, CConnman& connman, const CBlockIndex* tip);
51-
static void ProcessMessage(CNode& peer, PeerManager& peerman, CConnman& connman, std::string_view msg_type, CDataStream& vRecv);
51+
static PeerMsgRet ProcessMessage(CNode& peer, CConnman& connman, std::string_view msg_type, CDataStream& vRecv);
5252
static void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff, CConnman& connman);
5353
};
5454

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4351,7 +4351,7 @@ void PeerManagerImpl::ProcessMessage(
43514351
ProcessPeerMsgRet(sporkManager->ProcessMessage(pfrom, m_connman, msg_type, vRecv), pfrom);
43524352
::masternodeSync->ProcessMessage(pfrom, msg_type, vRecv);
43534353
ProcessPeerMsgRet(m_govman.ProcessMessage(pfrom, m_connman, msg_type, vRecv), pfrom);
4354-
CMNAuth::ProcessMessage(pfrom, *this, m_connman, msg_type, vRecv);
4354+
ProcessPeerMsgRet(CMNAuth::ProcessMessage(pfrom, m_connman, msg_type, vRecv), pfrom);
43554355
m_llmq_ctx->quorum_block_processor->ProcessMessage(pfrom, msg_type, vRecv);
43564356
m_llmq_ctx->qdkgsman->ProcessMessage(pfrom, *m_llmq_ctx->qman, msg_type, vRecv);
43574357
m_llmq_ctx->qman->ProcessMessage(pfrom, msg_type, vRecv);

0 commit comments

Comments
 (0)