MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / StartSync

Function StartSync

src/net.cpp:1144–1171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1142}
1143
1144void 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
1173void ThreadMessageHandler() {
1174 SetThreadPriority(THREAD_PRIORITY_BELOW_NORMAL);

Callers 1

ThreadMessageHandlerFunction · 0.85

Calls 2

NodeSyncScoreMethod · 0.80
GetHeightMethod · 0.45

Tested by

no test coverage detected