@@ -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
306298void CMasternodeSync::SendGovernanceSyncRequest (CNode* pnode) const
0 commit comments