Skip to content

Commit

Permalink
Use LockAssertion utility class instead of AssertLockHeld()
Browse files Browse the repository at this point in the history
Summary:
This change prepares for upcoming commit "Do not hide compile-time
thread safety warnings" by replacing AssertLockHeld() with
LockAssertion() where needed.

This is a backport of [[bitcoin/bitcoin#19668 | core#19668]] [1/5]
bitcoin/bitcoin@af9ea55

Backport notse:

  - We do not have a lock in RelayTransaction because we did not backport [[bitcoin/bitcoin#18044 | core#18044]] (commit ac88e2eb619821ad7ae1d45d4b40be69051d3999)
  - This change is partially reverted in D10172 after D10171 makes it possible to annotate the lambda functions with `EXCLUSIVE_LOCKS_REQUIRED`

Test Plan:
With TSAN:
`ninja check check-functional`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10161
  • Loading branch information
hebasto authored and PiRK committed Sep 22, 2021
1 parent 64f1961 commit 8ea2e27
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,15 +821,14 @@ static void MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid,
}
}
connman.ForNode(nodeid, [&connman](CNode *pfrom) {
AssertLockHeld(cs_main);
LockAssertion lock(::cs_main);
uint64_t nCMPCTBLOCKVersion = 1;
if (lNodesAnnouncingHeaderAndIDs.size() >= 3) {
// As per BIP152, we only get 3 of our peers to announce
// blocks using compact encodings.
connman.ForNode(
lNodesAnnouncingHeaderAndIDs.front(),
[&connman, nCMPCTBLOCKVersion](CNode *pnodeStop) {
AssertLockHeld(cs_main);
connman.PushMessage(
pnodeStop, CNetMsgMaker(pnodeStop->GetCommonVersion())
.Make(NetMsgType::SENDCMPCT,
Expand Down Expand Up @@ -1668,7 +1667,7 @@ void PeerManager::NewPoWValidBlock(

m_connman.ForEachNode([this, &pcmpctblock, pindex, &msgMaker,
&hashBlock](CNode *pnode) {
AssertLockHeld(cs_main);
LockAssertion lock(::cs_main);

// TODO: Avoid the repeated-serialization here
if (pnode->GetCommonVersion() < INVALID_CB_NO_BAN_VERSION ||
Expand Down Expand Up @@ -5025,7 +5024,7 @@ void PeerManager::EvictExtraOutboundPeers(int64_t time_in_seconds) {
int64_t oldest_block_announcement = std::numeric_limits<int64_t>::max();

m_connman.ForEachNode([&](CNode *pnode) {
AssertLockHeld(cs_main);
LockAssertion lock(::cs_main);

// Ignore non-outbound peers, or nodes marked for disconnect already
if (!pnode->IsOutboundOrBlockRelayConn() || pnode->fDisconnect) {
Expand Down Expand Up @@ -5058,7 +5057,7 @@ void PeerManager::EvictExtraOutboundPeers(int64_t time_in_seconds) {
}

bool disconnected = m_connman.ForNode(worst_peer, [&](CNode *pnode) {
AssertLockHeld(cs_main);
LockAssertion lock(::cs_main);

// Only disconnect a peer that has been connected to us for some
// reasonable fraction of our check-frequency, to give it time for new
Expand Down

0 comments on commit 8ea2e27

Please sign in to comment.