MCPcopy Create free account
hub / github.com/bcndev/bytecoin / import_blocks

Method import_blocks

src/Core/BlockChainFileFormat.cpp:153–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

151}
152
153bool LegacyBlockChainReader::import_blocks(BlockChainState *block_chain) {
154 try {
155 auto idea_start = std::chrono::high_resolution_clock::now();
156 // size_t bs_count = std::min(block_chain.get_tip_height() + 1 + count, get_block_count());
157 while (block_chain->get_tip_height() + 1 < get_block_count()) {
158 BinaryArray rba = get_block_data_by_index(block_chain->get_tip_height() + 1);
159 PreparedBlock pb{std::move(rba), m_currency, nullptr};
160 api::BlockHeader info;
161 if (!block_chain->add_block(pb, &info, false, "blocks_file")) {
162 std::cout << "block_chain.add_block !BROADCAST_ALL block=" << block_chain->get_tip_height() + 1
163 << std::endl;
164 block_chain->db_commit();
165 return false;
166 }
167 auto idea_ms = std::chrono::duration_cast<std::chrono::milliseconds>(
168 std::chrono::high_resolution_clock::now() - idea_start);
169 if (idea_ms.count() > 200) // import in chunks of 0.2 seconds
170 break;
171 }
172 } catch (const std::exception &ex) {
173 std::cout << "Exception while importing blockchain file, what=" << common::what(ex) << std::endl;
174 return false;
175 } catch (...) {
176 std::cout << "Unknown exception while importing blockchain file" << std::endl;
177 return false;
178 }
179 return block_chain->get_tip_height() + 1 < get_block_count(); // Not finished
180}
181
182bool LegacyBlockChainReader::import_blockchain2(const std::string &index_file_name, const std::string &item_file_name,
183 BlockChainState *block_chain, Height max_height) {

Callers

nothing calls this directly

Calls 3

get_tip_heightMethod · 0.45
add_blockMethod · 0.45
db_commitMethod · 0.45

Tested by

no test coverage detected