Skip to content

Commit

Permalink
Upgrade to v17 instead
Browse files Browse the repository at this point in the history
  • Loading branch information
wezrule committed Jan 16, 2020
1 parent 881ee5e commit 90d5168
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 23 deletions.
51 changes: 38 additions & 13 deletions nano/core_test/block_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1726,6 +1726,43 @@ TEST (mdb_block_store, upgrade_v14_v15)
}

TEST (mdb_block_store, upgrade_v15_v16)
{
auto path (nano::unique_path ());
nano::mdb_val value;
{
nano::genesis genesis;
nano::logger_mt logger;
nano::mdb_store store (logger, path);
nano::stat stats;
nano::ledger ledger (store, stats);
auto transaction (store.tx_begin_write ());
store.initialize (transaction, genesis, ledger.cache);
// The representation table should get removed after, so readd it so that we can later confirm this actually happens
auto txn = store.env.tx (transaction);
ASSERT_FALSE (mdb_dbi_open (txn, "representation", MDB_CREATE, &store.representation));
auto weight = ledger.cache.rep_weights.representation_get (nano::genesis_account);
ASSERT_EQ (MDB_SUCCESS, mdb_put (txn, store.representation, nano::mdb_val (nano::genesis_account), nano::mdb_val (nano::uint128_union (weight)), 0));
// Lower the database to the previous version
store.version_put (transaction, 15);
// Confirm the rep weight exists in the database
ASSERT_EQ (MDB_SUCCESS, mdb_get (store.env.tx (transaction), store.representation, nano::mdb_val (nano::genesis_account), value));
store.confirmation_height_del (transaction, nano::genesis_account);
}

// Now do the upgrade
nano::logger_mt logger;
auto error (false);
nano::mdb_store store (logger, path);
ASSERT_FALSE (error);
auto transaction (store.tx_begin_read ());

// The representation table should now be deleted
auto error_get_representation (mdb_get (store.env.tx (transaction), store.representation, nano::mdb_val (nano::genesis_account), value));
ASSERT_NE (MDB_SUCCESS, error_get_representation);
ASSERT_EQ (store.representation, 0);
}

TEST (mdb_block_store, upgrade_v16_v17)
{
nano::genesis genesis;
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
Expand All @@ -1748,17 +1785,10 @@ TEST (mdb_block_store, upgrade_v15_v16)
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, block1).code);
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, block2).code);
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, block3).code);
// The representation table should get removed after, so readd it so that we can later confirm this actually happens
auto txn = store.env.tx (transaction);
ASSERT_FALSE (mdb_dbi_open (txn, "representation", MDB_CREATE, &store.representation));
auto weight = ledger.cache.rep_weights.representation_get (nano::genesis_account);
ASSERT_EQ (MDB_SUCCESS, mdb_put (txn, store.representation, nano::mdb_val (nano::genesis_account), nano::mdb_val (nano::uint128_union (weight)), 0));
modify_confirmation_height_to_v15 (store, transaction, nano::genesis_account, confirmation_height);

// Lower the database to the previous version
store.version_put (transaction, 15);
// Confirm the rep weight exists in the database
ASSERT_EQ (MDB_SUCCESS, mdb_get (store.env.tx (transaction), store.representation, nano::mdb_val (nano::genesis_account), value));
store.version_put (transaction, 16);
}

// Now do the upgrade
Expand All @@ -1774,11 +1804,6 @@ TEST (mdb_block_store, upgrade_v15_v16)

// Check confirmation height frontier is correct
ASSERT_EQ (confirmation_height_info.frontier, expected_cemented_frontier);

// The representation table should now be deleted
auto error_get_representation (mdb_get (store.env.tx (transaction), store.representation, nano::mdb_val (nano::genesis_account), value));
ASSERT_NE (MDB_SUCCESS, error_get_representation);
ASSERT_EQ (store.representation, 0);
};
// clang-format on

Expand Down
31 changes: 23 additions & 8 deletions nano/node/lmdb/lmdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ txn_tracking_enabled (txn_tracking_config_a.enable)
if (!error)
{
auto is_fully_upgraded (false);
auto is_fresh_db (false);
{
auto transaction (tx_begin_read ());
auto err = mdb_dbi_open (env.tx (transaction), "meta", 0, &meta);
is_fresh_db = err != MDB_SUCCESS;
if (err == MDB_SUCCESS)
{
is_fully_upgraded = (version_get (transaction) == version);
Expand All @@ -64,9 +66,17 @@ txn_tracking_enabled (txn_tracking_config_a.enable)
// (can be a few minutes with the --fast_bootstrap flag for instance)
if (!is_fully_upgraded)
{
if (backup_before_upgrade)
nano::network_constants network_constants;
if (!is_fresh_db)
{
create_backup_file (env, path_a, logger_a);
if (!network_constants.is_test_network ())
{
std::cout << "Upgrade in progress..." << std::endl;
}
if (backup_before_upgrade)
{
create_backup_file (env, path_a, logger_a);
}
}
auto needs_vacuuming = false;
{
Expand All @@ -78,7 +88,6 @@ txn_tracking_enabled (txn_tracking_config_a.enable)
}
}

nano::network_constants network_constants;
if (needs_vacuuming && !network_constants.is_test_network ())
{
logger.always_log ("Preparing vacuum...");
Expand Down Expand Up @@ -187,7 +196,7 @@ void nano::mdb_store::open_databases (bool & error_a, nano::transaction const &

if (version_get (transaction_a) < 16)
{
// The representation database is no longer used, but need opening so that it can be deleted during an upgrade
// The representation database is no longer used, but needs opening so that it can be deleted during an upgrade
error_a |= mdb_dbi_open (env.tx (transaction_a), "representation", flags, &representation) != 0;
}

Expand Down Expand Up @@ -244,6 +253,8 @@ bool nano::mdb_store::do_upgrades (nano::write_transaction & transaction_a, bool
case 15:
upgrade_v15_to_v16 (transaction_a);
case 16:
upgrade_v16_to_v17 (transaction_a);
case 17:
break;
default:
logger.always_log (boost::str (boost::format ("The version of the ledger (%1%) is too high for this node") % version_l));
Expand Down Expand Up @@ -677,10 +688,8 @@ void nano::mdb_store::upgrade_v14_to_v15 (nano::write_transaction & transaction_
logger.always_log ("Finished epoch merge upgrade");
}

void nano::mdb_store::upgrade_v15_to_v16 (nano::write_transaction & transaction_a)
void nano::mdb_store::upgrade_v15_to_v16 (nano::write_transaction const & transaction_a)
{
logger.always_log ("Preparing v15 to v16 upgrade...");

// Representation table is no longer used
assert (representation != 0);
if (representation != 0)
Expand All @@ -689,6 +698,12 @@ void nano::mdb_store::upgrade_v15_to_v16 (nano::write_transaction & transaction_
release_assert (status == MDB_SUCCESS);
representation = 0;
}
version_put (transaction_a, 16);
}

void nano::mdb_store::upgrade_v16_to_v17 (nano::write_transaction const & transaction_a)
{
logger.always_log ("Preparing v16 to v17 upgrade...");

auto account_info_i = latest_begin (transaction_a);
auto account_info_n = latest_end ();
Expand Down Expand Up @@ -763,7 +778,7 @@ void nano::mdb_store::upgrade_v15_to_v16 (nano::write_transaction & transaction_
mdb_put (env.tx (transaction_a), confirmation_height, nano::mdb_val (confirmation_height_info_pair.first), nano::mdb_val (confirmation_height_info_pair.second), MDB_APPEND);
}

version_put (transaction_a, 16);
version_put (transaction_a, 17);
logger.always_log ("Finished upgrading confirmation height frontiers");
}

Expand Down
4 changes: 3 additions & 1 deletion nano/node/lmdb/lmdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ class mdb_store : public block_store_partial<MDB_val, mdb_store>
void upgrade_v12_to_v13 (nano::write_transaction &, size_t);
void upgrade_v13_to_v14 (nano::write_transaction const &);
void upgrade_v14_to_v15 (nano::write_transaction &);
void upgrade_v15_to_v16 (nano::write_transaction &);
void upgrade_v15_to_v16 (nano::write_transaction const &);
void upgrade_v16_to_v17 (nano::write_transaction const &);

void open_databases (bool &, nano::transaction const &, unsigned);

int drop (nano::write_transaction const & transaction_a, tables table_a) override;
Expand Down
2 changes: 1 addition & 1 deletion nano/secure/blockstore_partial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ class block_store_partial : public block_store
nano::network_params network_params;
std::unordered_map<nano::account, std::shared_ptr<nano::vote>> vote_cache_l1;
std::unordered_map<nano::account, std::shared_ptr<nano::vote>> vote_cache_l2;
static int constexpr version{ 16 };
static int constexpr version{ 17 };

template <typename T>
std::shared_ptr<nano::block> block_random (nano::transaction const & transaction_a, tables table_a)
Expand Down

0 comments on commit 90d5168

Please sign in to comment.