MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / ThreadSync

Method ThreadSync

src/index/base.cpp:84–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82}
83
84void BaseIndex::ThreadSync()
85{
86 const CBlockIndex* pindex = m_best_block_index.load();
87 if (!m_synced) {
88 auto& consensus_params = Params().GetConsensus();
89
90 int64_t last_log_time = 0;
91 int64_t last_locator_write_time = 0;
92 while (true) {
93 if (m_interrupt) {
94 WriteBestBlock(pindex);
95 return;
96 }
97
98 {
99 LOCK(cs_main);
100 const CBlockIndex* pindex_next = NextSyncBlock(pindex);
101 if (!pindex_next) {
102 WriteBestBlock(pindex);
103 m_best_block_index = pindex;
104 m_synced = true;
105 break;
106 }
107 pindex = pindex_next;
108 }
109
110 int64_t current_time = GetTime();
111 if (last_log_time + SYNC_LOG_INTERVAL < current_time) {
112 LogPrintf("Syncing %s with block chain from height %d\n",
113 GetName(), pindex->nHeight);
114 last_log_time = current_time;
115 }
116
117 if (last_locator_write_time + SYNC_LOCATOR_WRITE_INTERVAL < current_time) {
118 WriteBestBlock(pindex);
119 last_locator_write_time = current_time;
120 }
121
122 CBlock block;
123 if (!ReadBlockFromDisk(block, pindex, consensus_params)) {
124 FatalError("%s: Failed to read block %s from disk",
125 __func__, pindex->GetBlockHash().ToString());
126 return;
127 }
128 if (!WriteBlock(block, pindex)) {
129 FatalError("%s: Failed to write block %s to index database",
130 __func__, pindex->GetBlockHash().ToString());
131 return;
132 }
133 }
134 }
135
136 if (pindex) {
137 LogPrintf("%s is enabled at height %d\n", GetName(), pindex->nHeight);
138 } else {
139 LogPrintf("%s is enabled\n", GetName());
140 }
141}

Callers

nothing calls this directly

Calls 7

NextSyncBlockFunction · 0.85
GetTimeFunction · 0.85
ReadBlockFromDiskFunction · 0.85
FatalErrorFunction · 0.85
ParamsClass · 0.50
ToStringMethod · 0.45
GetBlockHashMethod · 0.45

Tested by

no test coverage detected