Skip to content

Commit 6ac317b

Browse files
committed
merge bitcoin#19607: Add Peer struct for per-peer data in net processing
1 parent 63ed87e commit 6ac317b

16 files changed

+110
-121
lines changed

src/coinjoin/client.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ void CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CDataStream&
5454
vRecv >> dsq;
5555

5656
if (dsq.masternodeOutpoint.IsNull() && dsq.m_protxHash.IsNull()) {
57-
LOCK(cs_main);
5857
Misbehaving(peer.GetId(), 100);
5958
return;
6059
}
@@ -64,7 +63,6 @@ void CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CDataStream&
6463
if (auto dmn = mnList.GetValidMN(dsq.m_protxHash)) {
6564
dsq.masternodeOutpoint = dmn->collateralOutpoint;
6665
} else {
67-
LOCK(cs_main);
6866
Misbehaving(peer.GetId(), 10);
6967
return;
7068
}
@@ -100,7 +98,6 @@ void CCoinJoinClientQueueManager::ProcessDSQueue(const CNode& peer, CDataStream&
10098
}
10199

102100
if (!dsq.CheckSignature(dmn->pdmnState->pubKeyOperator.Get())) {
103-
LOCK(cs_main);
104101
Misbehaving(peer.GetId(), 10);
105102
return;
106103
}

src/coinjoin/server.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ void CCoinJoinServer::ProcessDSQUEUE(const CNode& peer, CDataStream& vRecv)
113113
vRecv >> dsq;
114114

115115
if (dsq.masternodeOutpoint.IsNull() && dsq.m_protxHash.IsNull()) {
116-
LOCK(cs_main);
117116
Misbehaving(peer.GetId(), 100);
118117
return;
119118
}
@@ -123,7 +122,6 @@ void CCoinJoinServer::ProcessDSQUEUE(const CNode& peer, CDataStream& vRecv)
123122
if (auto dmn = mnList.GetValidMN(dsq.m_protxHash)) {
124123
dsq.masternodeOutpoint = dmn->collateralOutpoint;
125124
} else {
126-
LOCK(cs_main);
127125
Misbehaving(peer.GetId(), 10);
128126
return;
129127
}
@@ -159,7 +157,6 @@ void CCoinJoinServer::ProcessDSQUEUE(const CNode& peer, CDataStream& vRecv)
159157
}
160158

161159
if (!dsq.CheckSignature(dmn->pdmnState->pubKeyOperator.Get())) {
162-
LOCK(cs_main);
163160
Misbehaving(peer.GetId(), 10);
164161
return;
165162
}

src/evo/mnauth.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,34 +70,29 @@ void CMNAuth::ProcessMessage(CNode& peer, CConnman& connman, std::string_view ms
7070

7171
// only one MNAUTH allowed
7272
if (!peer.GetVerifiedProRegTxHash().IsNull()) {
73-
LOCK(cs_main);
7473
Misbehaving(peer.GetId(), 100, "duplicate mnauth");
7574
return;
7675
}
7776

7877
if ((~peer.nServices) & (NODE_NETWORK | NODE_BLOOM)) {
7978
// either NODE_NETWORK or NODE_BLOOM bit is missing in node's services
80-
LOCK(cs_main);
8179
Misbehaving(peer.GetId(), 100, "mnauth from a node with invalid services");
8280
return;
8381
}
8482

8583
if (mnauth.proRegTxHash.IsNull()) {
86-
LOCK(cs_main);
8784
Misbehaving(peer.GetId(), 100, "empty mnauth proRegTxHash");
8885
return;
8986
}
9087

9188
if (!mnauth.sig.IsValid()) {
92-
LOCK(cs_main);
9389
Misbehaving(peer.GetId(), 100, "invalid mnauth signature");
9490
return;
9591
}
9692

9793
const auto mnList = deterministicMNManager->GetListAtChainTip();
9894
const auto dmn = mnList.GetMN(mnauth.proRegTxHash);
9995
if (!dmn) {
100-
LOCK(cs_main);
10196
// in case node was unlucky and not up to date, just let it be connected as a regular node, which gives it
10297
// a chance to get up-to-date and thus realize that it's not a MN anymore. We still give it a
10398
// low DoS score.
@@ -122,7 +117,6 @@ void CMNAuth::ProcessMessage(CNode& peer, CConnman& connman, std::string_view ms
122117
LogPrint(BCLog::NET_NETCONN, "CMNAuth::%s -- constructed signHash for nVersion %d, peer=%d\n", __func__, peer.nVersion, peer.GetId());
123118

124119
if (!mnauth.sig.VerifyInsecure(dmn->pdmnState->pubKeyOperator.Get(), signHash)) {
125-
LOCK(cs_main);
126120
// Same as above, MN seems to not know its fate yet, so give it a chance to update. If this is a
127121
// malicious node (DoSing us), it'll get banned soon.
128122
Misbehaving(peer.GetId(), 10, "mnauth signature verification failed");

src/governance/governance.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ void CGovernanceManager::ProcessMessage(CNode& peer, CConnman& connman, std::str
219219
} else {
220220
LogPrint(BCLog::GOBJECT, "MNGOVERNANCEOBJECTVOTE -- Rejected vote, error = %s\n", exception.what());
221221
if ((exception.GetNodePenalty() != 0) && ::masternodeSync->IsSynced()) {
222-
LOCK(cs_main);
223222
Misbehaving(peer.GetId(), exception.GetNodePenalty());
224223
}
225224
return;
@@ -625,7 +624,6 @@ void CGovernanceManager::SyncObjects(CNode& peer, CConnman& connman) const
625624
if (netfulfilledman.HasFulfilledRequest(peer.addr, NetMsgType::MNGOVERNANCESYNC)) {
626625
// Asking for the whole list multiple times in a short period of time is no good
627626
LogPrint(BCLog::GOBJECT, "CGovernanceManager::%s -- peer already asked me for the list\n", __func__);
628-
LOCK(cs_main);
629627
Misbehaving(peer.GetId(), 20);
630628
return;
631629
}

src/llmq/blockprocessor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ void CQuorumBlockProcessor::ProcessMessage(const CNode& peer, std::string_view m
5454

5555
if (qc.IsNull()) {
5656
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- null commitment from peer=%d\n", __func__, peer.GetId());
57-
WITH_LOCK(cs_main, Misbehaving(peer.GetId(), 100));
57+
Misbehaving(peer.GetId(), 100);
5858
return;
5959
}
6060

6161
if (!Params().HasLLMQ(qc.llmqType)) {
6262
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- invalid commitment type %d from peer=%d\n", __func__,
6363
uint8_t(qc.llmqType), peer.GetId());
64-
WITH_LOCK(cs_main, Misbehaving(peer.GetId(), 100));
64+
Misbehaving(peer.GetId(), 100);
6565
return;
6666
}
6767
auto type = qc.llmqType;
@@ -124,7 +124,7 @@ void CQuorumBlockProcessor::ProcessMessage(const CNode& peer, std::string_view m
124124
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- commitment for quorum %s:%d is not valid quorumIndex[%d] nversion[%d], peer=%d\n",
125125
__func__, qc.quorumHash.ToString(),
126126
uint8_t(qc.llmqType), qc.quorumIndex, qc.nVersion, peer.GetId());
127-
WITH_LOCK(cs_main, Misbehaving(peer.GetId(), 100));
127+
Misbehaving(peer.GetId(), 100);
128128
return;
129129
}
130130

src/llmq/chainlocks.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ void CChainLocksHandler::ProcessNewChainLock(const NodeId from, const llmq::CCha
125125
if (!llmq::CSigningManager::VerifyRecoveredSig(Params().GetConsensus().llmqTypeChainLocks, *llmq::quorumManager, clsig.getHeight(), requestId, clsig.getBlockHash(), clsig.getSig())) {
126126
LogPrint(BCLog::CHAINLOCKS, "CChainLocksHandler::%s -- invalid CLSIG (%s), peer=%d\n", __func__, clsig.ToString(), from);
127127
if (from != -1) {
128-
LOCK(cs_main);
129128
Misbehaving(from, 10);
130129
}
131130
return;

src/llmq/dkgsessionhandler.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ bool ProcessPendingMessageBatch(CDKGSession& session, CDKGPendingMessages& pendi
408408
if (!p.second) {
409409
LogPrint(BCLog::LLMQ_DKG, "%s -- failed to deserialize message, peer=%d\n", __func__, nodeId);
410410
{
411-
LOCK(cs_main);
412411
Misbehaving(nodeId, 100);
413412
}
414413
continue;
@@ -418,7 +417,6 @@ bool ProcessPendingMessageBatch(CDKGSession& session, CDKGPendingMessages& pendi
418417
if (ban) {
419418
LogPrint(BCLog::LLMQ_DKG, "%s -- banning node due to failed preverification, peer=%d\n", __func__, nodeId);
420419
{
421-
LOCK(cs_main);
422420
Misbehaving(nodeId, 100);
423421
}
424422
}
@@ -449,7 +447,6 @@ bool ProcessPendingMessageBatch(CDKGSession& session, CDKGPendingMessages& pendi
449447
session.ReceiveMessage(*p.second, ban);
450448
if (ban) {
451449
LogPrint(BCLog::LLMQ_DKG, "%s -- banning node after ReceiveMessage failed, peer=%d\n", __func__, nodeId);
452-
LOCK(cs_main);
453450
Misbehaving(nodeId, 100);
454451
badNodes.emplace(nodeId);
455452
}

src/llmq/dkgsessionmgr.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ void CDKGSessionManager::ProcessMessage(CNode& pfrom, const CQuorumManager& quor
184184
}
185185

186186
if (vRecv.empty()) {
187-
LOCK(cs_main);
188187
Misbehaving(pfrom.GetId(), 100);
189188
return;
190189
}
@@ -197,7 +196,6 @@ void CDKGSessionManager::ProcessMessage(CNode& pfrom, const CQuorumManager& quor
197196
vRecv.Rewind(sizeof(uint8_t));
198197

199198
if (!Params().HasLLMQ(llmqType)) {
200-
LOCK(cs_main);
201199
LogPrintf("CDKGSessionManager -- invalid llmqType [%d]\n", uint8_t(llmqType));
202200
Misbehaving(pfrom.GetId(), 100);
203201
return;
@@ -218,15 +216,13 @@ void CDKGSessionManager::ProcessMessage(CNode& pfrom, const CQuorumManager& quor
218216
if (quorumIndex == -1) {
219217
CBlockIndex* pQuorumBaseBlockIndex = WITH_LOCK(cs_main, return LookupBlockIndex(quorumHash));
220218
if (pQuorumBaseBlockIndex == nullptr) {
221-
LOCK(cs_main);
222219
LogPrintf("CDKGSessionManager -- unknown quorumHash %s\n", quorumHash.ToString());
223220
// NOTE: do not insta-ban for this, we might be lagging behind
224221
Misbehaving(pfrom.GetId(), 10);
225222
return;
226223
}
227224

228225
if (!utils::IsQuorumTypeEnabled(llmqType, quorum_manager, pQuorumBaseBlockIndex->pprev)) {
229-
LOCK(cs_main);
230226
LogPrintf("CDKGSessionManager -- llmqType [%d] quorums aren't active\n", uint8_t(llmqType));
231227
Misbehaving(pfrom.GetId(), 100);
232228
return;
@@ -238,14 +234,12 @@ void CDKGSessionManager::ProcessMessage(CNode& pfrom, const CQuorumManager& quor
238234
llmqParams.signingActiveQuorumCount - 1 : 0;
239235

240236
if (quorumIndex > quorumIndexMax) {
241-
LOCK(cs_main);
242237
LogPrintf("CDKGSessionManager -- invalid quorumHash %s\n", quorumHash.ToString());
243238
Misbehaving(pfrom.GetId(), 100);
244239
return;
245240
}
246241

247242
if (!dkgSessionHandlers.count(std::make_pair(llmqType, quorumIndex))) {
248-
LOCK(cs_main);
249243
LogPrintf("CDKGSessionManager -- no session handlers for quorumIndex [%d]\n", quorumIndex);
250244
Misbehaving(pfrom.GetId(), 100);
251245
return;

src/llmq/instantsend.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,6 @@ void CInstantSendManager::ProcessMessageInstantSendLock(const CNode& pfrom, cons
788788
}
789789

790790
if (!islock->TriviallyValid()) {
791-
LOCK(cs_main);
792791
Misbehaving(pfrom.GetId(), 100);
793792
return;
794793
}
@@ -798,14 +797,14 @@ void CInstantSendManager::ProcessMessageInstantSendLock(const CNode& pfrom, cons
798797
const auto blockIndex = WITH_LOCK(cs_main, return LookupBlockIndex(islock->cycleHash));
799798
if (blockIndex == nullptr) {
800799
// Maybe we don't have the block yet or maybe some peer spams invalid values for cycleHash
801-
WITH_LOCK(cs_main, Misbehaving(pfrom.GetId(), 1));
800+
Misbehaving(pfrom.GetId(), 1);
802801
return;
803802
}
804803

805804
// Deterministic islocks MUST use rotation based llmq
806805
auto llmqType = Params().GetConsensus().llmqTypeDIP0024InstantSend;
807806
if (blockIndex->nHeight % GetLLMQParams(llmqType).dkgInterval != 0) {
808-
WITH_LOCK(cs_main, Misbehaving(pfrom.GetId(), 100));
807+
Misbehaving(pfrom.GetId(), 100);
809808
return;
810809
}
811810
}

src/llmq/quorums.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,6 @@ void CQuorumManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, C
610610
auto errorHandler = [&](const std::string& strError, int nScore = 10) {
611611
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- %s: %s, from peer=%d\n", strFunc, msg_type, strError, pfrom.GetId());
612612
if (nScore > 0) {
613-
LOCK(cs_main);
614613
Misbehaving(pfrom.GetId(), nScore);
615614
}
616615
};

0 commit comments

Comments
 (0)