Skip to content

Commit 26cfbb0

Browse files
5dde8e7 merge bitcoin#25109: Strengthen AssertLockNotHeld assertions (Kittywhiskers Van Gogh) a1f005e merge bitcoin#24157: Replace RecursiveMutex cs_totalBytesSent with Mutex and rename it (Kittywhiskers Van Gogh) de4b4bf merge bitcoin#24108: Replace RecursiveMutex cs_addrLocal with Mutex, and rename it (Kittywhiskers Van Gogh) 2f7a138 merge bitcoin#24079: replace RecursiveMutex cs_SubVer with Mutex (and rename) (Kittywhiskers Van Gogh) 23b152c merge bitcoin#22829: various RecursiveMutex replacements in CConnman (Kittywhiskers Van Gogh) 362e310 merge bitcoin#21943: Dedup and RAII-fy the creation of a copy of CConnman::vNodes (Kittywhiskers Van Gogh) bf98ad6 merge bitcoin#22782: Remove unused MaybeSetAddrName (Kittywhiskers Van Gogh) 2b65526 merge bitcoin#21167: make CNode::m_inbound_onion public, initialize explicitly (Kittywhiskers Van Gogh) Pull request description: ## Additional Information * Dependent on dashpay#6001 * Dependency for dashpay#6018 * Partially reverts ff69e0d from dashpay#5336 due to `Span<CNode*>`'s incompatibility with `CConnman::NodesSnapshot::Snap()` (returning `const std::vector<CNode*>&`) ``` masternode/sync.cpp:147:18: error: no matching member function for call to 'RequestGovernanceObjectVotes' m_govman.RequestGovernanceObjectVotes(snap.Nodes(), connman); ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~ ./governance/governance.h:360:9: note: candidate function not viable: no known conversion from 'const std::vector<CNode *>' to 'CNode &' for 1st argument int RequestGovernanceObjectVotes(CNode& peer, CConnman& connman) const; ^ ./governance/governance.h:361:9: note: candidate function not viable: no known conversion from 'const std::vector<CNode *>' to 'Span<CNode *>' for 1st argument int RequestGovernanceObjectVotes(Span<CNode*> vNodesCopy, CConnman& connman) const; ^ 1 error generated. ``` * Dash already implements its own `CNode*` iteration logic in [dash#1382](dashpay#1382) and implemented additional capabilities in [dash#1575](dashpay#1575), which meant backporting [bitcoin#21943](bitcoin#21943) involved migrating Dash-specific code to upstream logic that needed to be modified to implement expected functionality. * Unlike Bitcoin, Dash maintains a map of every raw `SOCKET` corresponding to a pointer of their `CNode` instance and uses it to translate socket sets to their corresponding `CNode*` sets. This is done to accommodate for edge-triggered modes which have an event-socket relationship, as opposed to level-triggered modes, which have a socket-event relationship. This means that `CConnman::SocketHandlerConnected()` doesn't require access to a vector of all `CNode` pointers and therefore, the argument `nodes` has been omitted. ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas **(note: N/A)** - [x] I have added or updated relevant unit/integration/functional/e2e tests **(note: N/A)** - [x] I have made corresponding changes to the documentation **(note: N/A)** - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: PastaPastaPasta: utACK 5dde8e7 Tree-SHA512: 5685d8ebb4fa1f10d018e60d9b0efc3100ea13ac437e7892a09ad3f86d6ac6756e4b5a08ebe70de2eabb27740678e10b975d319f2d553ae5b27dafa71dba0a9f
2 parents 6028e37 + 5dde8e7 commit 26cfbb0

27 files changed

+595
-448
lines changed

src/checkqueue.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class CCheckQueue
6565
bool m_request_stop GUARDED_BY(m_mutex){false};
6666

6767
/** Internal function that does bulk of the verification work. */
68-
bool Loop(bool fMaster)
68+
bool Loop(bool fMaster) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
6969
{
7070
std::condition_variable& cond = fMaster ? m_master_cv : m_worker_cv;
7171
std::vector<T> vChecks;
@@ -139,7 +139,7 @@ class CCheckQueue
139139
}
140140

141141
//! Create a pool of new worker threads.
142-
void StartWorkerThreads(const int threads_num)
142+
void StartWorkerThreads(const int threads_num) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
143143
{
144144
{
145145
LOCK(m_mutex);
@@ -157,13 +157,13 @@ class CCheckQueue
157157
}
158158

159159
//! Wait until execution finishes, and return whether all evaluations were successful.
160-
bool Wait()
160+
bool Wait() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
161161
{
162162
return Loop(true /* master thread */);
163163
}
164164

165165
//! Add a batch of checks to the queue
166-
void Add(std::vector<T>& vChecks)
166+
void Add(std::vector<T>& vChecks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
167167
{
168168
if (vChecks.empty()) {
169169
return;
@@ -186,7 +186,7 @@ class CCheckQueue
186186
}
187187

188188
//! Stop all of the worker threads.
189-
void StopWorkerThreads()
189+
void StopWorkerThreads() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
190190
{
191191
WITH_LOCK(m_mutex, m_request_stop = true);
192192
m_worker_cv.notify_all();

src/coinjoin/coinjoin.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,22 @@ class CDSTXManager
368368
void AddDSTX(const CCoinJoinBroadcastTx& dstx) EXCLUSIVE_LOCKS_REQUIRED(!cs_mapdstx);
369369
CCoinJoinBroadcastTx GetDSTX(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(!cs_mapdstx);
370370

371-
void UpdatedBlockTip(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler, const CMasternodeSync& mn_sync);
372-
void NotifyChainLock(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler, const CMasternodeSync& mn_sync);
371+
void UpdatedBlockTip(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler,
372+
const CMasternodeSync& mn_sync)
373+
EXCLUSIVE_LOCKS_REQUIRED(!cs_mapdstx);
374+
void NotifyChainLock(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler,
375+
const CMasternodeSync& mn_sync)
376+
EXCLUSIVE_LOCKS_REQUIRED(!cs_mapdstx);
373377

374378
void TransactionAddedToMempool(const CTransactionRef& tx) EXCLUSIVE_LOCKS_REQUIRED(!cs_mapdstx);
375-
void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(!cs_mapdstx);
376-
void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex*) EXCLUSIVE_LOCKS_REQUIRED(!cs_mapdstx);
379+
void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex)
380+
EXCLUSIVE_LOCKS_REQUIRED(!cs_mapdstx);
381+
void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex*)
382+
EXCLUSIVE_LOCKS_REQUIRED(!cs_mapdstx);
377383

378384
private:
379-
void CheckDSTXes(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler);
385+
void CheckDSTXes(const CBlockIndex* pindex, const llmq::CChainLocksHandler& clhandler)
386+
EXCLUSIVE_LOCKS_REQUIRED(!cs_mapdstx);
380387
void UpdateDSTXConfirmedHeight(const CTransactionRef& tx, std::optional<int> nHeight);
381388

382389
};

src/governance/governance.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,11 +1223,11 @@ void CGovernanceManager::RequestGovernanceObject(CNode* pfrom, const uint256& nH
12231223

12241224
int CGovernanceManager::RequestGovernanceObjectVotes(CNode& peer, CConnman& connman) const
12251225
{
1226-
std::array<CNode*, 1> nodeCopy{&peer};
1227-
return RequestGovernanceObjectVotes(nodeCopy, connman);
1226+
const std::vector<CNode*> vNodeCopy{&peer};
1227+
return RequestGovernanceObjectVotes(vNodeCopy, connman);
12281228
}
12291229

1230-
int CGovernanceManager::RequestGovernanceObjectVotes(Span<CNode*> vNodesCopy, CConnman& connman) const
1230+
int CGovernanceManager::RequestGovernanceObjectVotes(const std::vector<CNode*>& vNodesCopy, CConnman& connman) const
12311231
{
12321232
static std::map<uint256, std::map<CService, int64_t> > mapAskedRecently;
12331233

@@ -1501,7 +1501,7 @@ void CGovernanceManager::UpdatedBlockTip(const CBlockIndex* pindex, CConnman& co
15011501

15021502
void CGovernanceManager::RequestOrphanObjects(CConnman& connman)
15031503
{
1504-
std::vector<CNode*> vNodesCopy = connman.CopyNodeVector(CConnman::FullyConnectedOnly);
1504+
const CConnman::NodesSnapshot snap{connman, /* filter = */ CConnman::FullyConnectedOnly};
15051505

15061506
std::vector<uint256> vecHashesFiltered;
15071507
{
@@ -1517,15 +1517,13 @@ void CGovernanceManager::RequestOrphanObjects(CConnman& connman)
15171517

15181518
LogPrint(BCLog::GOBJECT, "CGovernanceObject::RequestOrphanObjects -- number objects = %d\n", vecHashesFiltered.size());
15191519
for (const uint256& nHash : vecHashesFiltered) {
1520-
for (CNode* pnode : vNodesCopy) {
1520+
for (CNode* pnode : snap.Nodes()) {
15211521
if (!pnode->CanRelay()) {
15221522
continue;
15231523
}
15241524
RequestGovernanceObject(pnode, nHash, connman);
15251525
}
15261526
}
1527-
1528-
connman.ReleaseNodeVector(vNodesCopy);
15291527
}
15301528

15311529
void CGovernanceManager::CleanOrphanObjects()

src/governance/governance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ class CGovernanceManager : public GovernanceStore
358358
void InitOnLoad();
359359

360360
int RequestGovernanceObjectVotes(CNode& peer, CConnman& connman) const;
361-
int RequestGovernanceObjectVotes(Span<CNode*> vNodesCopy, CConnman& connman) const;
361+
int RequestGovernanceObjectVotes(const std::vector<CNode*>& vNodesCopy, CConnman& connman) const;
362362

363363
/*
364364
* Trigger Management (formerly CGovernanceTriggerManager)

src/httpserver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class WorkQueue
8383
{
8484
}
8585
/** Enqueue a work item */
86-
bool Enqueue(WorkItem* item)
86+
bool Enqueue(WorkItem* item) EXCLUSIVE_LOCKS_REQUIRED(!cs)
8787
{
8888
LOCK(cs);
8989
if (!running || queue.size() >= maxDepth) {
@@ -94,7 +94,7 @@ class WorkQueue
9494
return true;
9595
}
9696
/** Thread function */
97-
void Run()
97+
void Run() EXCLUSIVE_LOCKS_REQUIRED(!cs)
9898
{
9999
while (true) {
100100
std::unique_ptr<WorkItem> i;
@@ -111,7 +111,7 @@ class WorkQueue
111111
}
112112
}
113113
/** Interrupt and exit loops */
114-
void Interrupt()
114+
void Interrupt() EXCLUSIVE_LOCKS_REQUIRED(!cs)
115115
{
116116
LOCK(cs);
117117
running = false;

src/i2p.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class Session
8484
* to the listening socket and address.
8585
* @return true on success
8686
*/
87-
bool Listen(Connection& conn);
87+
bool Listen(Connection& conn) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
8888

8989
/**
9090
* Wait for and accept a new incoming connection.
@@ -103,7 +103,7 @@ class Session
103103
* it is set to `false`. Only set if `false` is returned.
104104
* @return true on success
105105
*/
106-
bool Connect(const CService& to, Connection& conn, bool& proxy_error);
106+
bool Connect(const CService& to, Connection& conn, bool& proxy_error) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
107107

108108
private:
109109
/**
@@ -172,7 +172,7 @@ class Session
172172
/**
173173
* Check the control socket for errors and possibly disconnect.
174174
*/
175-
void CheckControlSock();
175+
void CheckControlSock() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
176176

177177
/**
178178
* Generate a new destination with the SAM proxy and set `m_private_key` to it.

src/index/blockfilterindex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class BlockFilterIndex final : public BaseIndex
6363
bool LookupFilter(const CBlockIndex* block_index, BlockFilter& filter_out) const;
6464

6565
/** Get a single filter header by block. */
66-
bool LookupFilterHeader(const CBlockIndex* block_index, uint256& header_out);
66+
bool LookupFilterHeader(const CBlockIndex* block_index, uint256& header_out) EXCLUSIVE_LOCKS_REQUIRED(!m_cs_headers_cache);
6767

6868
/** Get a range of filters between two heights on a chain. */
6969
bool LookupFilterRange(int start_height, const CBlockIndex* stop_index,

src/llmq/dkgsession.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ void CDKGSession::RelayInvToParticipants(const CInv& inv) const
13361336
if (pnode->GetVerifiedProRegTxHash().IsNull()) {
13371337
logger.Batch("node[%d:%s] not mn",
13381338
pnode->GetId(),
1339-
pnode->GetAddrName());
1339+
pnode->m_addr_name);
13401340
} else if (relayMembers.count(pnode->GetVerifiedProRegTxHash()) == 0) {
13411341
ss2 << pnode->GetVerifiedProRegTxHash().ToString().substr(0, 4) << " | ";
13421342
}

src/llmq/signing_shares.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,14 +1092,13 @@ bool CSigSharesManager::SendMessages()
10921092
return session->sendSessionId;
10931093
};
10941094

1095-
std::vector<CNode*> vNodesCopy = connman.CopyNodeVector(CConnman::FullyConnectedOnly);
1096-
1095+
const CConnman::NodesSnapshot snap{connman, /* filter = */ CConnman::FullyConnectedOnly};
10971096
{
10981097
LOCK(cs);
10991098
CollectSigSharesToRequest(sigSharesToRequest);
11001099
CollectSigSharesToSend(sigShareBatchesToSend);
11011100
CollectSigSharesToAnnounce(sigSharesToAnnounce);
1102-
CollectSigSharesToSendConcentrated(sigSharesToSend, vNodesCopy);
1101+
CollectSigSharesToSendConcentrated(sigSharesToSend, snap.Nodes());
11031102

11041103
for (auto& [nodeId, sigShareMap] : sigSharesToRequest) {
11051104
for (auto& [hash, sigShareInv] : sigShareMap) {
@@ -1120,7 +1119,7 @@ bool CSigSharesManager::SendMessages()
11201119

11211120
bool didSend = false;
11221121

1123-
for (auto& pnode : vNodesCopy) {
1122+
for (auto& pnode : snap.Nodes()) {
11241123
CNetMsgMaker msgMaker(pnode->GetCommonVersion());
11251124

11261125
if (const auto it1 = sigSessionAnnouncements.find(pnode->GetId()); it1 != sigSessionAnnouncements.end()) {
@@ -1222,9 +1221,6 @@ bool CSigSharesManager::SendMessages()
12221221
}
12231222
}
12241223

1225-
// looped through all nodes, release them
1226-
connman.ReleaseNodeVector(vNodesCopy);
1227-
12281224
return didSend;
12291225
}
12301226

src/masternode/sync.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,11 @@ void CMasternodeSync::ProcessTick()
140140
}
141141

142142
nTimeLastProcess = GetTime();
143-
std::vector<CNode*> vNodesCopy = connman.CopyNodeVector(CConnman::FullyConnectedOnly);
143+
const CConnman::NodesSnapshot snap{connman, /* filter = */ CConnman::FullyConnectedOnly};
144144

145145
// gradually request the rest of the votes after sync finished
146146
if(IsSynced()) {
147-
m_govman.RequestGovernanceObjectVotes(vNodesCopy, connman);
148-
connman.ReleaseNodeVector(vNodesCopy);
147+
m_govman.RequestGovernanceObjectVotes(snap.Nodes(), connman);
149148
return;
150149
}
151150

@@ -154,7 +153,7 @@ void CMasternodeSync::ProcessTick()
154153
LogPrint(BCLog::MNSYNC, "CMasternodeSync::ProcessTick -- nTick %d nCurrentAsset %d nTriedPeerCount %d nSyncProgress %f\n", nTick, nCurrentAsset, nTriedPeerCount, nSyncProgress);
155154
uiInterface.NotifyAdditionalDataSyncProgressChanged(nSyncProgress);
156155

157-
for (auto& pnode : vNodesCopy)
156+
for (auto& pnode : snap.Nodes())
158157
{
159158
CNetMsgMaker msgMaker(pnode->GetCommonVersion());
160159

@@ -189,7 +188,7 @@ void CMasternodeSync::ProcessTick()
189188
}
190189

191190
if (nCurrentAsset == MASTERNODE_SYNC_BLOCKCHAIN) {
192-
int64_t nTimeSyncTimeout = vNodesCopy.size() > 3 ? MASTERNODE_SYNC_TICK_SECONDS : MASTERNODE_SYNC_TIMEOUT_SECONDS;
191+
int64_t nTimeSyncTimeout = snap.Nodes().size() > 3 ? MASTERNODE_SYNC_TICK_SECONDS : MASTERNODE_SYNC_TIMEOUT_SECONDS;
193192
if (fReachedBestHeader && (GetTime() - nTimeLastBumped > nTimeSyncTimeout)) {
194193
// At this point we know that:
195194
// a) there are peers (because we are looping on at least one of them);
@@ -205,7 +204,7 @@ void CMasternodeSync::ProcessTick()
205204

206205
if (gArgs.GetBoolArg("-syncmempool", DEFAULT_SYNC_MEMPOOL)) {
207206
// Now that the blockchain is synced request the mempool from the connected outbound nodes if possible
208-
for (auto pNodeTmp : vNodesCopy) {
207+
for (auto pNodeTmp : snap.Nodes()) {
209208
bool fRequestedEarlier = m_netfulfilledman.HasFulfilledRequest(pNodeTmp->addr, "mempool-sync");
210209
if (pNodeTmp->nVersion >= 70216 && !pNodeTmp->IsInboundConn() && !fRequestedEarlier && !pNodeTmp->IsBlockRelayOnly()) {
211210
m_netfulfilledman.AddFulfilledRequest(pNodeTmp->addr, "mempool-sync");
@@ -222,7 +221,6 @@ void CMasternodeSync::ProcessTick()
222221
if(nCurrentAsset == MASTERNODE_SYNC_GOVERNANCE) {
223222
if (!m_govman.IsValid()) {
224223
SwitchToNextAsset();
225-
connman.ReleaseNodeVector(vNodesCopy);
226224
return;
227225
}
228226
LogPrint(BCLog::GOBJECT, "CMasternodeSync::ProcessTick -- nTick %d nCurrentAsset %d nTimeLastBumped %lld GetTime() %lld diff %lld\n", nTick, nCurrentAsset, nTimeLastBumped, GetTime(), GetTime() - nTimeLastBumped);
@@ -235,7 +233,6 @@ void CMasternodeSync::ProcessTick()
235233
// it's kind of ok to skip this for now, hopefully we'll catch up later?
236234
}
237235
SwitchToNextAsset();
238-
connman.ReleaseNodeVector(vNodesCopy);
239236
return;
240237
}
241238

@@ -259,12 +256,11 @@ void CMasternodeSync::ProcessTick()
259256

260257
if (nCurrentAsset != MASTERNODE_SYNC_GOVERNANCE) {
261258
// looped through all nodes and not syncing governance yet/already, release them
262-
connman.ReleaseNodeVector(vNodesCopy);
263259
return;
264260
}
265261

266262
// request votes on per-obj basis from each node
267-
for (const auto& pnode : vNodesCopy) {
263+
for (const auto& pnode : snap.Nodes()) {
268264
if(!m_netfulfilledman.HasFulfilledRequest(pnode->addr, "governance-sync")) {
269265
continue; // to early for this node
270266
}
@@ -291,16 +287,12 @@ void CMasternodeSync::ProcessTick()
291287
// reset nTimeNoObjectsLeft to be able to use the same condition on resync
292288
nTimeNoObjectsLeft = 0;
293289
SwitchToNextAsset();
294-
connman.ReleaseNodeVector(vNodesCopy);
295290
return;
296291
}
297292
nLastTick = nTick;
298293
nLastVotes = m_govman.GetVoteCount();
299294
}
300295
}
301-
302-
// looped through all nodes, release them
303-
connman.ReleaseNodeVector(vNodesCopy);
304296
}
305297

306298
void CMasternodeSync::SendGovernanceSyncRequest(CNode* pnode) const

0 commit comments

Comments
 (0)