| 184 | } |
| 185 | |
| 186 | BlockChainState::BlockChainState(logging::ILogger &log, const Config &config, const Currency ¤cy, bool read_only) |
| 187 | : BlockChain(log, config, currency, read_only) |
| 188 | , m_max_pool_size(config.max_pool_size) |
| 189 | , m_log_redo_block_timestamp(std::chrono::steady_clock::now()) { |
| 190 | std::string version; |
| 191 | m_db.get("$version", version); |
| 192 | if (version == "B" || version == "1" || version == "2" || version == "3" || version == "4" || version == "5" || |
| 193 | version == "6" || version == "7") { |
| 194 | start_internal_import(); |
| 195 | version = version_current; |
| 196 | m_db.put("$version", version, false); |
| 197 | db_commit(); |
| 198 | } |
| 199 | // Upgrades from 5 should restart internal import if m_internal_import_chain is not empty |
| 200 | if (version != version_current) |
| 201 | throw Exception("Blockchain database format too new (version=" + version + "), please delete " + |
| 202 | config.get_data_folder() + "/blockchain"); |
| 203 | if (get_tip_height() == (Height)-1) { |
| 204 | // Block genesis_block; |
| 205 | // genesis_block.header = currency.genesis_block_template; |
| 206 | RawBlock raw_block; |
| 207 | raw_block.block = seria::to_binary(currency.genesis_block_template); |
| 208 | // invariant(genesis_block.to_raw_block(raw_block), "Genesis block failed to convert into raw block"); |
| 209 | PreparedBlock pb{std::move(raw_block), m_currency, nullptr}; |
| 210 | api::BlockHeader info; |
| 211 | invariant(add_block(pb, &info, false, std::string{}), "Genesis block failed to add"); |
| 212 | } |
| 213 | BlockChainState::tip_changed(); |
| 214 | m_log(logging::INFO) << "height=" << get_tip_height() << " bid=" << get_tip_bid() |
| 215 | << " cumulative_difficulty=" << get_tip_cumulative_difficulty(); |
| 216 | build_blods(); |
| 217 | DB::Cursor cur2 = m_db.rbegin(DIN_PREFIX); |
| 218 | m_next_nz_input_index = |
| 219 | cur2.end() ? 0 : common::integer_cast<size_t>(common::read_varint_sqlite4(cur2.get_suffix())) + 1; |
| 220 | DB::Cursor cur3 = m_db.rbegin(OUTPUT_PREFIX); |
| 221 | m_next_global_key_output_index = |
| 222 | cur3.end() ? 0 : common::integer_cast<size_t>(common::read_varint_sqlite4(cur3.get_suffix())) + 1; |
| 223 | // m_db.debug_print_index_size(KEYIMAGE_PREFIX); |
| 224 | // m_db.debug_print_index_size(AMOUNT_OUTPUT_PREFIX); |
| 225 | // m_db.debug_print_index_size(OUTPUT_PREFIX); |
| 226 | // m_db.debug_print_index_size(DIN_PREFIX); |
| 227 | } |
| 228 | |
| 229 | void BlockChainState::check_consensus( |
| 230 | const PreparedBlock &pb, api::BlockHeader *info, const api::BlockHeader &prev_info, bool check_pow) const { |
nothing calls this directly
no test coverage detected