Fix v3/v4 db conversion

This commit is contained in:
moneromooo-monero 2019-02-14 22:56:51 +00:00 committed by wowario
parent ebb1580493
commit f94c615fc3
No known key found for this signature in database
GPG Key ID: 24DCBE762DE9C111
2 changed files with 8 additions and 2 deletions

View File

@ -4434,6 +4434,9 @@ void BlockchainLMDB::migrate_3_4()
result = mdb_cursor_open(txn, o_block_info, &c_old); result = mdb_cursor_open(txn, o_block_info, &c_old);
if (result) if (result)
throw0(DB_ERROR(lmdb_error("Failed to open a cursor for block_info: ", result).c_str())); throw0(DB_ERROR(lmdb_error("Failed to open a cursor for block_info: ", result).c_str()));
result = mdb_cursor_open(txn, m_blocks, &c_blocks);
if (result)
throw0(DB_ERROR(lmdb_error("Failed to open a cursor for blocks: ", result).c_str()));
if (!i) { if (!i) {
MDB_stat db_stat; MDB_stat db_stat;
result = mdb_stat(txn, m_block_info, &db_stats); result = mdb_stat(txn, m_block_info, &db_stats);
@ -4462,8 +4465,9 @@ void BlockchainLMDB::migrate_3_4()
// get block major version to determine which rule is in place // get block major version to determine which rule is in place
if (!past_long_term_weight) if (!past_long_term_weight)
{ {
MDB_val kb, vb; MDB_val_copy<uint64_t> kb(bi.bi_height);
result = mdb_cursor_get(c_blocks, &k, &v, MDB_NEXT); MDB_val vb;
result = mdb_cursor_get(c_blocks, &kb, &vb, MDB_SET);
if (result) if (result)
throw0(DB_ERROR(lmdb_error("Failed to query m_blocks: ", result).c_str())); throw0(DB_ERROR(lmdb_error("Failed to query m_blocks: ", result).c_str()));
if (vb.mv_size == 0) if (vb.mv_size == 0)

View File

@ -504,6 +504,8 @@ bool Blockchain::init(BlockchainDB* db, const network_type nettype, bool offline
{ {
m_long_term_block_weights.push_front(db_height - 1 - m_long_term_block_weights.size()); m_long_term_block_weights.push_front(db_height - 1 - m_long_term_block_weights.size());
} }
if (!m_long_term_block_weights.empty())
m_long_term_block_weights.pop_back();
update_next_cumulative_weight_limit(); update_next_cumulative_weight_limit();
return true; return true;