mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01:00
[net processing] Improve documentation for Peer destruction/locking
Suggested here: - https://github.com/bitcoin/bitcoin/pull/19607#discussion_r467071878 - https://github.com/bitcoin/bitcoin/pull/19829#discussion_r546116786
This commit is contained in:
@@ -791,6 +791,11 @@ void PeerManager::FinalizeNode(const CNode& node, bool& fUpdateConnectionTime) {
|
||||
LOCK(cs_main);
|
||||
int misbehavior{0};
|
||||
{
|
||||
// We remove the PeerRef from g_peer_map here, but we don't always
|
||||
// destruct the Peer. Sometimes another thread is still holding a
|
||||
// PeerRef, so the refcount is >= 1. Be careful not to do any
|
||||
// processing here that assumes Peer won't be changed before it's
|
||||
// destructed.
|
||||
PeerRef peer = RemovePeer(nodeid);
|
||||
assert(peer != nullptr);
|
||||
misbehavior = WITH_LOCK(peer->m_misbehavior_mutex, return peer->m_misbehavior_score);
|
||||
|
||||
Reference in New Issue
Block a user