From 1a1c23f8d40116741f0e26cdf22688fd91c923fc Mon Sep 17 00:00:00 2001 From: John Newbery Date: Mon, 15 Jun 2020 10:15:08 -0400 Subject: [PATCH] [net processing] Change cs_main TRY_LOCK to LOCK in SendMessages() This was changed to TRY_LOCK in #1117 to fix a potential deadlock between cs_main and cs_vSend. cs_vSend was split into cs_vSend and cs_sendProcessing in #9535 (and cs_sendProcessing was changed from a TRY_LOCK to a LOCK in the same PR). Since cs_vSend can no longer be taken before cs_main, revert this to a LOCK(). This commit leaves part of the code with bad indentation. That is fixed by the next (whitespace change only) commit. --- src/net_processing.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 8ef79cd719..f5cff6297d 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -3838,7 +3838,7 @@ public: bool PeerLogicValidation::SendMessages(CNode* pto) { const Consensus::Params& consensusParams = Params().GetConsensus(); - { + // Don't send anything until the version handshake is complete if (!pto->fSuccessfullyConnected || pto->fDisconnect) return true; @@ -3875,9 +3875,8 @@ bool PeerLogicValidation::SendMessages(CNode* pto) } } - TRY_LOCK(cs_main, lockMain); - if (!lockMain) - return true; + { + LOCK(cs_main); if (MaybeDiscourageAndDisconnect(*pto)) return true; @@ -4416,7 +4415,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto) pto->m_tx_relay->nextSendTimeFeeFilter = timeNow + GetRandInt(MAX_FEEFILTER_CHANGE_DELAY) * 1000000; } } - } + } // release cs_main return true; }