@@ -21,11 +21,11 @@ class CConnman;
2121void NetGovernance::Schedule (CScheduler& scheduler, CConnman& connman)
2222{
2323 scheduler.scheduleEvery (
24- [this , &connman]() -> void {
25- if (ShutdownRequested ()) return ;
26- ProcessTick (connman);
27- },
28- std::chrono::seconds{1 });
24+ [this , &connman]() -> void {
25+ if (ShutdownRequested ()) return ;
26+ ProcessTick (connman);
27+ },
28+ std::chrono::seconds{1 });
2929
3030 // Code below is meant to be running only if governance validation is enabled
3131 if (!m_gov_manager.IsValid ()) return ;
@@ -72,13 +72,13 @@ void NetGovernance::ProcessTick(CConnman& connman)
7272 // reset the sync process if the last call to this function was more than 60 minutes ago (client was in sleep mode)
7373 static int64_t nTimeLastProcess = GetTime ();
7474 if (!Params ().IsMockableChain () && GetTime () - nTimeLastProcess > 60 * 60 && !connman.IsActiveMasternode ()) {
75- LogPrintf (" NetGovernance::ProcessTick -- WARNING: no actions for too long, restarting sync...\n " );
75+ LogPrintf (" Sync Tick -- WARNING: no actions for too long, restarting sync...\n " );
7676 m_node_sync.Reset (true );
7777 nTimeLastProcess = GetTime ();
7878 return ;
7979 }
8080
81- if (GetTime () - nTimeLastProcess < MASTERNODE_SYNC_TICK_SECONDS) {
81+ if (GetTime () - nTimeLastProcess < MASTERNODE_SYNC_TICK_SECONDS) {
8282 // too early, nothing to do here
8383 return ;
8484 }
@@ -87,20 +87,20 @@ void NetGovernance::ProcessTick(CConnman& connman)
8787 const CConnman::NodesSnapshot snap{connman, /* cond = */ CConnman::FullyConnectedOnly};
8888
8989 // gradually request the rest of the votes after sync finished
90- if (m_node_sync.IsSynced ()) {
90+ if (m_node_sync.IsSynced ()) {
9191 m_gov_manager.RequestGovernanceObjectVotes (snap.Nodes (), connman, m_peer_manager);
9292 return ;
9393 }
9494
9595 // Calculate "progress" for LOG reporting / GUI notification
9696 int attempt = m_node_sync.GetAttempt ();
9797 int asset_id = m_node_sync.GetAssetID ();
98- double nSyncProgress = double (attempt + (asset_id - 1 ) * 8 ) / (8 *4 );
99- LogPrint (BCLog::MNSYNC, " CMasternodeSync::ProcessTick -- nTick %d asset_id %d nTriedPeerCount %d nSyncProgress %f\n " , nTick, asset_id, attempt, nSyncProgress);
98+ double nSyncProgress = double (attempt + (asset_id - 1 ) * 8 ) / (8 * 4 );
99+ LogPrint (BCLog::MNSYNC, " Sync Tick -- nTick %d asset_id %d nTriedPeerCount %d nSyncProgress %f\n " , nTick, asset_id,
100+ attempt, nSyncProgress);
100101 uiInterface.NotifyAdditionalDataSyncProgressChanged (nSyncProgress);
101102
102- for (auto & pnode : snap.Nodes ())
103- {
103+ for (auto & pnode : snap.Nodes ()) {
104104 CNetMsgMaker msgMaker (pnode->GetCommonVersion ());
105105
106106 // Don't try to sync any data from outbound non-relay "masternode" connections.
@@ -109,32 +109,35 @@ void NetGovernance::ProcessTick(CConnman& connman)
109109 if (!pnode->CanRelay () || (connman.IsActiveMasternode () && pnode->IsInboundConn ())) continue ;
110110
111111 {
112- if ((pnode->HasPermission (NetPermissionFlags::NoBan) || pnode->IsManualConn ()) && !m_netfulfilledman.HasFulfilledRequest (pnode->addr , strAllow)) {
112+ if ((pnode->HasPermission (NetPermissionFlags::NoBan) || pnode->IsManualConn ()) &&
113+ !m_netfulfilledman.HasFulfilledRequest (pnode->addr , strAllow)) {
113114 m_netfulfilledman.RemoveAllFulfilledRequests (pnode->addr );
114115 m_netfulfilledman.AddFulfilledRequest (pnode->addr , strAllow);
115- LogPrintf (" CMasternodeSync::ProcessTick -- skipping mnsync restrictions for peer=%d\n " , pnode->GetId ());
116+ LogPrintf (" Sync Tick -- skipping mnsync restrictions for peer=%d\n " , pnode->GetId ());
116117 }
117118
118- if (m_netfulfilledman.HasFulfilledRequest (pnode->addr , " full-sync" )) {
119+ if (m_netfulfilledman.HasFulfilledRequest (pnode->addr , " full-sync" )) {
119120 // We already fully synced from this node recently,
120121 // disconnect to free this connection slot for another peer.
121122 pnode->fDisconnect = true ;
122- LogPrintf (" CMasternodeSync::ProcessTick -- disconnecting from recently synced peer=%d\n " , pnode->GetId ());
123+ LogPrintf (" Sync Tick -- disconnecting from recently synced peer=%d\n " , pnode->GetId ());
123124 continue ;
124125 }
125126
126127 // SPORK : ALWAYS ASK FOR SPORKS AS WE SYNC
127128
128- if (!m_netfulfilledman.HasFulfilledRequest (pnode->addr , " spork-sync" )) {
129+ if (!m_netfulfilledman.HasFulfilledRequest (pnode->addr , " spork-sync" )) {
129130 // always get sporks first, only request once from each peer
130131 m_netfulfilledman.AddFulfilledRequest (pnode->addr , " spork-sync" );
131132 // get current network sporks
132133 connman.PushMessage (pnode, msgMaker.Make (NetMsgType::GETSPORKS));
133- LogPrint (BCLog::MNSYNC, " CMasternodeSync::ProcessTick -- nTick %d asset_id %d -- requesting sporks from peer=%d\n " , nTick, asset_id, pnode->GetId ());
134+ LogPrint (BCLog::MNSYNC, " Sync Tick -- nTick %d asset_id %d -- requesting sporks from peer=%d\n " , nTick,
135+ asset_id, pnode->GetId ());
134136 }
135137
136138 if (asset_id == MASTERNODE_SYNC_BLOCKCHAIN) {
137- int64_t nTimeSyncTimeout = snap.Nodes ().size () > 3 ? MASTERNODE_SYNC_TICK_SECONDS : MASTERNODE_SYNC_TIMEOUT_SECONDS;
139+ int64_t nTimeSyncTimeout = snap.Nodes ().size () > 3 ? MASTERNODE_SYNC_TICK_SECONDS
140+ : MASTERNODE_SYNC_TIMEOUT_SECONDS;
138141 if (m_node_sync.IsReachedBestHeader () && (GetTime () - m_node_sync.GetLastBump () > nTimeSyncTimeout)) {
139142 // At this point we know that:
140143 // a) there are peers (because we are looping on at least one of them);
@@ -151,11 +154,14 @@ void NetGovernance::ProcessTick(CConnman& connman)
151154 if (gArgs .GetBoolArg (" -syncmempool" , DEFAULT_SYNC_MEMPOOL)) {
152155 // Now that the blockchain is synced request the mempool from the connected outbound nodes if possible
153156 for (auto pNodeTmp : snap.Nodes ()) {
154- bool fRequestedEarlier = m_netfulfilledman.HasFulfilledRequest (pNodeTmp->addr , " mempool-sync" );
157+ bool fRequestedEarlier = m_netfulfilledman.HasFulfilledRequest (pNodeTmp->addr ,
158+ " mempool-sync" );
155159 if (!pNodeTmp->IsInboundConn () && !fRequestedEarlier && !pNodeTmp->IsBlockRelayOnly ()) {
156160 m_netfulfilledman.AddFulfilledRequest (pNodeTmp->addr , " mempool-sync" );
157161 connman.PushMessage (pNodeTmp, msgMaker.Make (NetMsgType::MEMPOOL));
158- LogPrint (BCLog::MNSYNC, " CMasternodeSync::ProcessTick -- nTick %d asset_id %d -- syncing mempool from peer=%d\n " , nTick, asset_id, pNodeTmp->GetId ());
162+ LogPrint (BCLog::MNSYNC, /* Continued */
163+ " Sync Tick -- nTick %d asset_id %d -- syncing mempool from peer=%d\n " , nTick,
164+ asset_id, pNodeTmp->GetId ());
159165 }
160166 }
161167 }
@@ -164,26 +170,27 @@ void NetGovernance::ProcessTick(CConnman& connman)
164170
165171 // GOVOBJ : SYNC GOVERNANCE ITEMS FROM OUR PEERS
166172
167- if (asset_id == MASTERNODE_SYNC_GOVERNANCE) {
173+ if (asset_id == MASTERNODE_SYNC_GOVERNANCE) {
168174 if (!m_gov_manager.IsValid ()) {
169175 m_node_sync.SwitchToNextAsset ();
170176 return ;
171177 }
172- LogPrint (BCLog::GOBJECT, " CMasternodeSync::ProcessTick -- nTick %d asset_id %d last_bump %lld GetTime() %lld diff %lld\n " , nTick, asset_id, m_node_sync.GetLastBump (), GetTime (), GetTime () - m_node_sync.GetLastBump ());
178+ LogPrint (BCLog::GOBJECT, " Sync Tick -- nTick %d asset_id %d last_bump %lld GetTime() %lld diff %lld\n " ,
179+ nTick, asset_id, m_node_sync.GetLastBump (), GetTime (), GetTime () - m_node_sync.GetLastBump ());
173180
174181 // check for timeout first
175- if (GetTime () - m_node_sync.GetLastBump () > MASTERNODE_SYNC_TIMEOUT_SECONDS) {
176- LogPrint (BCLog::MNSYNC, " CMasternodeSync::ProcessTick -- nTick %d asset_id %d -- timeout\n " , nTick, asset_id);
177- if (attempt == 0 ) {
178- LogPrintf (" CMasternodeSync::ProcessTick -- WARNING: failed to sync %s\n " , m_node_sync.GetAssetName ());
182+ if (GetTime () - m_node_sync.GetLastBump () > MASTERNODE_SYNC_TIMEOUT_SECONDS) {
183+ LogPrint (BCLog::MNSYNC, " Sync Tick -- nTick %d asset_id %d -- timeout\n " , nTick, asset_id);
184+ if (attempt == 0 ) {
185+ LogPrintf (" Sync Tick -- WARNING: failed to sync %s\n " , m_node_sync.GetAssetName ());
179186 // it's kind of ok to skip this for now, hopefully we'll catch up later?
180187 }
181188 m_node_sync.SwitchToNextAsset ();
182189 return ;
183190 }
184191
185192 // only request obj sync once from each peer
186- if (m_netfulfilledman.HasFulfilledRequest (pnode->addr , " governance-sync" )) {
193+ if (m_netfulfilledman.HasFulfilledRequest (pnode->addr , " governance-sync" )) {
187194 // will request votes on per-obj basis from each node in a separate loop below
188195 // to avoid deadlocks here
189196 continue ;
@@ -194,7 +201,7 @@ void NetGovernance::ProcessTick(CConnman& connman)
194201
195202 SendGovernanceSyncRequest (pnode, connman);
196203
197- break ; // this will cause each peer to get one request each six seconds for the various assets we need
204+ break ; // this will cause each peer to get one request each six seconds for the various assets we need
198205 }
199206 }
200207 }
@@ -207,28 +214,30 @@ void NetGovernance::ProcessTick(CConnman& connman)
207214
208215 // request votes on per-obj basis from each node
209216 for (const auto & pnode : snap.Nodes ()) {
210- if (!m_netfulfilledman.HasFulfilledRequest (pnode->addr , " governance-sync" )) {
217+ if (!m_netfulfilledman.HasFulfilledRequest (pnode->addr , " governance-sync" )) {
211218 continue ; // to early for this node
212219 }
213220 int nObjsLeftToAsk = m_gov_manager.RequestGovernanceObjectVotes (*pnode, connman, m_peer_manager);
214221 // check for data
215- if (nObjsLeftToAsk == 0 ) {
222+ if (nObjsLeftToAsk == 0 ) {
216223 static int64_t nTimeNoObjectsLeft = 0 ;
217224 static int nLastTick = 0 ;
218225 static int nLastVotes = 0 ;
219- if (nTimeNoObjectsLeft == 0 ) {
226+ if (nTimeNoObjectsLeft == 0 ) {
220227 // asked all objects for votes for the first time
221228 nTimeNoObjectsLeft = GetTime ();
222229 }
223230 // make sure the condition below is checked only once per tick
224- if (nLastTick == nTick) continue ;
231+ if (nLastTick == nTick) continue ;
225232 if (GetTime () - nTimeNoObjectsLeft > MASTERNODE_SYNC_TIMEOUT_SECONDS &&
226- m_gov_manager.GetVoteCount () - nLastVotes < std::max (int (0.0001 * nLastVotes), MASTERNODE_SYNC_TICK_SECONDS)) {
233+ m_gov_manager.GetVoteCount () - nLastVotes <
234+ std::max (int (0.0001 * nLastVotes), MASTERNODE_SYNC_TICK_SECONDS)) {
227235 // We already asked for all objects, waited for MASTERNODE_SYNC_TIMEOUT_SECONDS
228236 // after that and less then 0.01% or MASTERNODE_SYNC_TICK_SECONDS
229237 // (i.e. 1 per second) votes were received during the last tick.
230238 // We can be pretty sure that we are done syncing.
231- LogPrintf (" CMasternodeSync::ProcessTick -- nTick %d asset_id %d -- asked for all objects, nothing to do\n " , nTick, MASTERNODE_SYNC_GOVERNANCE);
239+ LogPrintf (" Sync Tick -- nTick %d asset_id %d -- asked for all objects, nothing to do\n " , nTick,
240+ MASTERNODE_SYNC_GOVERNANCE);
232241 // reset nTimeNoObjectsLeft to be able to use the same condition on resync
233242 nTimeNoObjectsLeft = 0 ;
234243 m_node_sync.SwitchToNextAsset ();
0 commit comments