| 1142 | } |
| 1143 | |
| 1144 | void static StartSync(const vector<CNode*>& vNodes) { |
| 1145 | CNode* pnodeNewSync = nullptr; |
| 1146 | int64_t nBestScore = 0; |
| 1147 | |
| 1148 | int32_t nBestHeight = GetNodeSignals().GetHeight().get_value_or(0); |
| 1149 | |
| 1150 | // Iterate over all nodes |
| 1151 | for (auto pNode : vNodes) { |
| 1152 | // check preconditions for allowing a sync |
| 1153 | if (!pNode->fClient && !pNode->fOneShot && !pNode->fDisconnect && pNode->fSuccessfullyConnected && |
| 1154 | (pNode->nStartingHeight > |
| 1155 | (nBestHeight - |
| 1156 | 144)) /*&& (pNode->nVersion < NOBLKS_VERSION_START || pNode->nVersion >= NOBLKS_VERSION_END)*/ |
| 1157 | ) { |
| 1158 | // if ok, compare node's score with the best so far |
| 1159 | int64_t nScore = pNode->NodeSyncScore(); |
| 1160 | if (pnodeNewSync == nullptr || nScore > nBestScore) { |
| 1161 | pnodeNewSync = pNode; |
| 1162 | nBestScore = nScore; |
| 1163 | } |
| 1164 | } |
| 1165 | } |
| 1166 | // if a new sync candidate was found, start sync! |
| 1167 | if (pnodeNewSync) { |
| 1168 | pnodeNewSync->fStartSync = true; |
| 1169 | pnodeSync = pnodeNewSync; |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | void ThreadMessageHandler() { |
| 1174 | SetThreadPriority(THREAD_PRIORITY_BELOW_NORMAL); |
no test coverage detected