mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-15 12:51:00 +02:00
Merge branch 'master' into elem-23.3.1-rc1
This commit is contained in:
commit
38cbe9282d
40 changed files with 3809 additions and 213 deletions
|
|
@ -222,6 +222,10 @@ struct Peer {
|
|||
* Most peers use headers-first syncing, which doesn't use this mechanism */
|
||||
uint256 m_continuation_block GUARDED_BY(m_block_inv_mutex) {};
|
||||
|
||||
Mutex m_msgproc_mutex;
|
||||
/** Set to true once initial VERSION message was sent (only relevant for outbound peers). */
|
||||
bool m_outbound_version_message_sent GUARDED_BY(m_msgproc_mutex){false};
|
||||
|
||||
/** This peer's reported block height when we connected */
|
||||
std::atomic<int> m_starting_height{-1};
|
||||
|
||||
|
|
@ -312,7 +316,7 @@ public:
|
|||
void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) override;
|
||||
|
||||
/** Implement NetEventsInterface */
|
||||
void InitializeNode(CNode* pnode) override;
|
||||
void InitializeNode(const CNode* pnode) override;
|
||||
void FinalizeNode(const CNode& node) override;
|
||||
bool ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt) override;
|
||||
bool SendMessages(CNode* pto) override EXCLUSIVE_LOCKS_REQUIRED(pto->cs_sendProcessing);
|
||||
|
|
@ -1198,7 +1202,7 @@ void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds)
|
|||
if (state) state->m_last_block_announcement = time_in_seconds;
|
||||
}
|
||||
|
||||
void PeerManagerImpl::InitializeNode(CNode *pnode)
|
||||
void PeerManagerImpl::InitializeNode(const CNode *pnode)
|
||||
{
|
||||
NodeId nodeid = pnode->GetId();
|
||||
{
|
||||
|
|
@ -1211,9 +1215,6 @@ void PeerManagerImpl::InitializeNode(CNode *pnode)
|
|||
LOCK(m_peer_mutex);
|
||||
m_peer_map.emplace_hint(m_peer_map.end(), nodeid, std::move(peer));
|
||||
}
|
||||
if (!pnode->IsInboundConn()) {
|
||||
PushNodeVersion(*pnode);
|
||||
}
|
||||
}
|
||||
|
||||
void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler)
|
||||
|
|
@ -4215,6 +4216,10 @@ bool PeerManagerImpl::ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt
|
|||
PeerRef peer = GetPeerRef(pfrom->GetId());
|
||||
if (peer == nullptr) return false;
|
||||
|
||||
// For outbound connections, ensure that the initial VERSION message
|
||||
// has been sent first before processing any incoming messages
|
||||
if (!pfrom->IsInboundConn() && WITH_LOCK(peer->m_msgproc_mutex, return !peer->m_outbound_version_message_sent)) return false;
|
||||
|
||||
{
|
||||
LOCK(peer->m_getdata_requests_mutex);
|
||||
if (!peer->m_getdata_requests.empty()) {
|
||||
|
|
@ -4674,6 +4679,13 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
|
|||
// disconnect misbehaving peers even before the version handshake is complete.
|
||||
if (MaybeDiscourageAndDisconnect(*pto, *peer)) return true;
|
||||
|
||||
// Initiate version handshake for outbound connections
|
||||
if (!pto->IsInboundConn() && WITH_LOCK(peer->m_msgproc_mutex, return !peer->m_outbound_version_message_sent)) {
|
||||
LOCK(peer->m_msgproc_mutex);
|
||||
PushNodeVersion(*pto);
|
||||
peer->m_outbound_version_message_sent = true;
|
||||
}
|
||||
|
||||
// Don't send anything until the version handshake is complete
|
||||
if (!pto->fSuccessfullyConnected || pto->fDisconnect)
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue