Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: make m_peer_mutex a SharedMutex #6468

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ class PeerManagerImpl final : public PeerManager

/** Protects m_peer_map. This mutex must not be locked while holding a lock
* on any of the mutexes inside a Peer object. */
mutable Mutex m_peer_mutex;
mutable SharedMutex m_peer_mutex;
/**
* Map of all Peer objects, keyed by peer id. This map is protected
* by the m_peer_mutex. Once a shared pointer reference is
Expand Down Expand Up @@ -1692,7 +1692,7 @@ void PeerManagerImpl::FinalizeNode(const CNode& node) {

PeerRef PeerManagerImpl::GetPeerRef(NodeId id) const
{
LOCK(m_peer_mutex);
READ_LOCK(m_peer_mutex);
auto it = m_peer_map.find(id);
return it != m_peer_map.end() ? it->second : nullptr;
}
Expand Down Expand Up @@ -2262,7 +2262,7 @@ bool PeerManagerImpl::AlreadyHaveBlock(const uint256& block_hash)

void PeerManagerImpl::SendPings()
{
LOCK(m_peer_mutex);
READ_LOCK(m_peer_mutex);
for(auto& it : m_peer_map) it.second->m_ping_queued = true;
}

Expand All @@ -2272,7 +2272,7 @@ void PeerManagerImpl::AskPeersForTransaction(const uint256& txid, bool is_master
peersToAsk.reserve(4);

{
LOCK(m_peer_mutex);
READ_LOCK(m_peer_mutex);
// TODO consider prioritizing MNs again, once that flag is moved into Peer
for (const auto& [_, peer] : m_peer_map) {
if (peersToAsk.size() >= 4) {
Expand Down Expand Up @@ -2337,7 +2337,7 @@ void PeerManagerImpl::RelayInv(CInv &inv, const int minProtoVersion)

void PeerManagerImpl::RelayInv(CInv &inv)
{
LOCK(m_peer_mutex);
READ_LOCK(m_peer_mutex);
for (const auto& [_, peer] : m_peer_map) {
if (!peer->GetInvRelay()) continue;
PushInv(*peer, inv);
Expand All @@ -2349,7 +2349,7 @@ void PeerManagerImpl::RelayDSQ(const CCoinJoinQueue& queue)
CInv inv{MSG_DSQ, queue.GetHash()};
std::vector<NodeId> nodes_send_all;
{
LOCK(m_peer_mutex);
READ_LOCK(m_peer_mutex);
for (const auto& [nodeid, peer] : m_peer_map) {
switch (peer->m_wants_dsq) {
case Peer::WantsDSQ::NONE:
Expand Down Expand Up @@ -2425,7 +2425,7 @@ void PeerManagerImpl::RelayInvFiltered(CInv &inv, const uint256& relatedTxHash,
void PeerManagerImpl::RelayTransaction(const uint256& txid)
{
const CInv inv{m_cj_ctx->dstxman->GetDSTX(txid) ? MSG_DSTX : MSG_TX, txid};
LOCK(m_peer_mutex);
READ_LOCK(m_peer_mutex);
for(auto& it : m_peer_map) {
Peer& peer = *it.second;
auto tx_relay = peer.GetTxRelay();
Expand All @@ -2438,7 +2438,7 @@ void PeerManagerImpl::RelayTransaction(const uint256& txid)
void PeerManagerImpl::RelayRecoveredSig(const uint256& sigHash)
{
const CInv inv{MSG_QUORUM_RECOVERED_SIG, sigHash};
LOCK(m_peer_mutex);
READ_LOCK(m_peer_mutex);
for (const auto& [_, peer] : m_peer_map) {
if (peer->m_wants_recsigs) {
PushInv(*peer, inv);
Expand Down Expand Up @@ -2471,7 +2471,7 @@ void PeerManagerImpl::RelayAddress(NodeId originator,
std::array<std::pair<uint64_t, Peer*>, 2> best{{{0, nullptr}, {0, nullptr}}};
assert(nRelayNodes <= best.size());

LOCK(m_peer_mutex);
READ_LOCK(m_peer_mutex);

for (auto& [id, peer] : m_peer_map) {
if (peer->m_addr_relay_enabled && id != originator && IsAddrCompatible(*peer, addr)) {
Expand Down
Loading