Misbehaving has several coding related issues (ignoring the conceptual issues here for now):
- It is public, but it is not supposed to be called from outside of net_processing. Fix that by making it private and creating a public
UnitTestMisbehavingmethod for unit testing only. - It doesn’t do anything if a
nullptris passed. It would be less confusing to just skip the call instead. Fix that by passingPeer&toMisbehaving(). - It calls
GetPeerRef, causing!m_peer_mutexlock annotations to be propagated. This is harmless, but verbose. Fix it by removing the no longer needed call toGetPeerRefand the no longer needed lock annotations.