Skip to content

Commit

Permalink
Merge with develop
Browse files Browse the repository at this point in the history
  • Loading branch information
wezrule committed Jan 3, 2020
2 parents 8e11f24 + d13ab81 commit 8941353
Show file tree
Hide file tree
Showing 22 changed files with 238 additions and 216 deletions.
82 changes: 32 additions & 50 deletions nano/core_test/block_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,9 @@ TEST (block_store, genesis)
ASSERT_TRUE (!store->init_error ());
nano::genesis genesis;
auto hash (genesis.hash ());
nano::rep_weights rep_weights;
std::atomic<uint64_t> cemented_count{ 0 };
std::atomic<uint64_t> block_count_cache{ 0 };
nano::ledger_cache ledger_cache;
auto transaction (store->tx_begin_write ());
store->initialize (transaction, genesis, rep_weights, cemented_count, block_count_cache);
store->initialize (transaction, genesis, ledger_cache);
nano::account_info info;
ASSERT_FALSE (store->account_get (transaction, nano::genesis_account, info));
ASSERT_EQ (hash, info.head);
Expand Down Expand Up @@ -757,11 +755,9 @@ TEST (block_store, cemented_count_cache)
ASSERT_TRUE (!store->init_error ());
auto transaction (store->tx_begin_write ());
nano::genesis genesis;
nano::rep_weights rep_weights;
std::atomic<uint64_t> cemented_count{ 0 };
std::atomic<uint64_t> block_count_cache{ 0 };
store->initialize (transaction, genesis, rep_weights, cemented_count, block_count_cache);
ASSERT_EQ (1, cemented_count);
nano::ledger_cache ledger_cache;
store->initialize (transaction, genesis, ledger_cache);
ASSERT_EQ (1, ledger_cache.cemented_count);
}

TEST (block_store, sequence_increment)
Expand Down Expand Up @@ -808,18 +804,18 @@ TEST (mdb_block_store, upgrade_v2_v3)
auto hash (genesis.hash ());
nano::stat stats;
nano::ledger ledger (store, stats);
store.initialize (transaction, genesis, ledger.rep_weights, ledger.cemented_count, ledger.block_count_cache);
store.initialize (transaction, genesis, ledger.cache);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::change_block change (hash, key1.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *pool.generate (hash));
change_hash = change.hash ();
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, change).code);
ASSERT_EQ (0, ledger.weight (nano::test_genesis_key.pub));
ASSERT_EQ (nano::genesis_amount, ledger.weight (key1.pub));
store.version_put (transaction, 2);
ledger.rep_weights.representation_put (key1.pub, 7);
ledger.cache.rep_weights.representation_put (key1.pub, 7);
ASSERT_EQ (7, ledger.weight (key1.pub));
ASSERT_EQ (2, store.version_get (transaction));
ledger.rep_weights.representation_put (key2.pub, 6);
ledger.cache.rep_weights.representation_put (key2.pub, 6);
ASSERT_EQ (6, ledger.weight (key2.pub));
nano::account_info info;
ASSERT_FALSE (store.account_get (transaction, nano::test_genesis_key.pub, info));
Expand Down Expand Up @@ -888,7 +884,7 @@ TEST (mdb_block_store, upgrade_v4_v5)
nano::genesis genesis;
nano::stat stats;
nano::ledger ledger (store, stats);
store.initialize (transaction, genesis, ledger.rep_weights, ledger.cemented_count, ledger.block_count_cache);
store.initialize (transaction, genesis, ledger.cache);
store.version_put (transaction, 4);
nano::account_info info;
ASSERT_FALSE (store.account_get (transaction, nano::test_genesis_key.pub, info));
Expand Down Expand Up @@ -920,11 +916,9 @@ TEST (block_store, block_random)
ASSERT_TRUE (!store->init_error ());
nano::genesis genesis;
{
nano::rep_weights rep_weights;
std::atomic<uint64_t> cemented_count{ 0 };
std::atomic<uint64_t> block_count_cache{ 0 };
nano::ledger_cache ledger_cache;
auto transaction (store->tx_begin_write ());
store->initialize (transaction, genesis, rep_weights, cemented_count, block_count_cache);
store->initialize (transaction, genesis, ledger_cache);
}
auto transaction (store->tx_begin_read ());
auto block (store->block_random (transaction));
Expand All @@ -941,10 +935,8 @@ TEST (mdb_block_store, upgrade_v5_v6)
ASSERT_FALSE (store.init_error ());
auto transaction (store.tx_begin_write ());
nano::genesis genesis;
nano::rep_weights rep_weights;
std::atomic<uint64_t> cemented_count{ 0 };
std::atomic<uint64_t> block_count_cache{ 0 };
store.initialize (transaction, genesis, rep_weights, cemented_count, block_count_cache);
nano::ledger_cache ledger_cache;
store.initialize (transaction, genesis, ledger_cache);
store.version_put (transaction, 5);
modify_genesis_account_info_to_v5 (store, transaction);
}
Expand All @@ -966,10 +958,8 @@ TEST (mdb_block_store, upgrade_v6_v7)
ASSERT_FALSE (store.init_error ());
auto transaction (store.tx_begin_write ());
nano::genesis genesis;
nano::rep_weights rep_weights;
std::atomic<uint64_t> cemented_count{ 0 };
std::atomic<uint64_t> block_count_cache{ 0 };
store.initialize (transaction, genesis, rep_weights, cemented_count, block_count_cache);
nano::ledger_cache ledger_cache;
store.initialize (transaction, genesis, ledger_cache);
store.version_put (transaction, 6);
modify_account_info_to_v13 (store, transaction, nano::genesis_account, genesis.open->hash ());
auto send1 (std::make_shared<nano::send_block> (0, 0, 0, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0));
Expand Down Expand Up @@ -1129,11 +1119,9 @@ TEST (block_store, state_block)
nano::keypair key1;
nano::state_block block1 (1, genesis.hash (), 3, 4, 6, key1.prv, key1.pub, 7);
{
nano::ledger_cache ledger_cache;
auto transaction (store->tx_begin_write ());
nano::rep_weights rep_weights;
std::atomic<uint64_t> cemented_count{ 0 };
std::atomic<uint64_t> block_count_cache{ 0 };
store->initialize (transaction, genesis, rep_weights, cemented_count, block_count_cache);
store->initialize (transaction, genesis, ledger_cache);
ASSERT_EQ (nano::block_type::state, block1.type ());
nano::block_sideband sideband1 (nano::block_type::state, 0, 0, 0, 0, 0, nano::epoch::epoch_0);
store->block_put (transaction, block1.hash (), block1, sideband1);
Expand Down Expand Up @@ -1164,10 +1152,8 @@ TEST (mdb_block_store, upgrade_sideband_genesis)
ASSERT_FALSE (store.init_error ());
auto transaction (store.tx_begin_write ());
store.version_put (transaction, 11);
nano::rep_weights rep_weights;
std::atomic<uint64_t> cemented_count{ 0 };
std::atomic<uint64_t> block_count_cache{ 0 };
store.initialize (transaction, genesis, rep_weights, cemented_count, block_count_cache);
nano::ledger_cache ledger_cache;
store.initialize (transaction, genesis, ledger_cache);
modify_account_info_to_v13 (store, transaction, nano::genesis_account, genesis.open->hash ());
nano::block_sideband sideband;
auto genesis_block (store.block_get (transaction, genesis.hash (), &sideband));
Expand Down Expand Up @@ -1204,7 +1190,7 @@ TEST (mdb_block_store, upgrade_sideband_two_blocks)
nano::ledger ledger (store, stat);
auto transaction (store.tx_begin_write ());
store.version_put (transaction, 11);
store.initialize (transaction, genesis, ledger.rep_weights, ledger.cemented_count, ledger.block_count_cache);
store.initialize (transaction, genesis, ledger.cache);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::state_block block (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *pool.generate (genesis.hash ()));
hash2 = block.hash ();
Expand Down Expand Up @@ -1247,7 +1233,7 @@ TEST (mdb_block_store, upgrade_sideband_two_accounts)
nano::ledger ledger (store, stat);
auto transaction (store.tx_begin_write ());
store.version_put (transaction, 11);
store.initialize (transaction, genesis, ledger.rep_weights, ledger.cemented_count, ledger.block_count_cache);
store.initialize (transaction, genesis, ledger.cache);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::state_block block1 (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *pool.generate (genesis.hash ()));
hash2 = block1.hash ();
Expand Down Expand Up @@ -1294,7 +1280,7 @@ TEST (mdb_block_store, insert_after_legacy)
nano::ledger ledger (store, stat);
auto transaction (store.tx_begin_write ());
store.version_put (transaction, 11);
store.initialize (transaction, genesis, ledger.rep_weights, ledger.cemented_count, ledger.block_count_cache);
store.initialize (transaction, genesis, ledger.cache);
mdb_dbi_open (store.env.tx (transaction), "state_v1", MDB_CREATE, &store.state_blocks_v1);
write_sideband_v12 (store, transaction, *genesis.open, 0, store.open_blocks);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
Expand All @@ -1312,7 +1298,7 @@ TEST (mdb_block_store, legacy_account_computed)
nano::ledger ledger (store, stats);
nano::genesis genesis;
auto transaction (store.tx_begin_write ());
store.initialize (transaction, genesis, ledger.rep_weights, ledger.cemented_count, ledger.block_count_cache);
store.initialize (transaction, genesis, ledger.cache);
store.version_put (transaction, 11);
mdb_dbi_open (store.env.tx (transaction), "state_v1", MDB_CREATE, &store.state_blocks_v1);
write_sideband_v12 (store, transaction, *genesis.open, 0, store.open_blocks);
Expand All @@ -1334,7 +1320,7 @@ TEST (mdb_block_store, upgrade_sideband_epoch)
nano::ledger ledger (store, stat);
auto transaction (store.tx_begin_write ());
store.version_put (transaction, 11);
store.initialize (transaction, genesis, ledger.rep_weights, ledger.cemented_count, ledger.block_count_cache);
store.initialize (transaction, genesis, ledger.cache);
nano::state_block block1 (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount, ledger.epoch_link (nano::epoch::epoch_1), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *pool.generate (genesis.hash ()));
hash2 = block1.hash ();
ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "state_v1", MDB_CREATE, &store.state_blocks_v1));
Expand Down Expand Up @@ -1381,7 +1367,7 @@ TEST (mdb_block_store, sideband_height)
nano::stat stat;
nano::ledger ledger (store, stat);
auto transaction (store.tx_begin_write ());
store.initialize (transaction, genesis, ledger.rep_weights, ledger.cemented_count, ledger.block_count_cache);
store.initialize (transaction, genesis, ledger.cache);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::send_block send (genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *pool.generate (genesis.hash ()));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, send).code);
Expand Down Expand Up @@ -1577,10 +1563,8 @@ TEST (mdb_block_store, upgrade_v13_v14)
nano::genesis genesis;
nano::mdb_store store (logger, path);
auto transaction (store.tx_begin_write ());
nano::rep_weights rep_weights;
std::atomic<uint64_t> cemented_count{ 0 };
std::atomic<uint64_t> block_count_cache{ 0 };
store.initialize (transaction, genesis, rep_weights, cemented_count, block_count_cache);
nano::ledger_cache ledger_cache;
store.initialize (transaction, genesis, ledger_cache);
nano::account_info account_info;
ASSERT_FALSE (store.account_get (transaction, nano::genesis_account, account_info));
uint64_t confirmation_height;
Expand Down Expand Up @@ -1638,7 +1622,7 @@ TEST (mdb_block_store, upgrade_v14_v15)
nano::stat stats;
nano::ledger ledger (store, stats);
auto transaction (store.tx_begin_write ());
store.initialize (transaction, genesis, ledger.rep_weights, ledger.cemented_count, ledger.block_count_cache);
store.initialize (transaction, genesis, ledger.cache);
nano::account_info account_info;
ASSERT_FALSE (store.account_get (transaction, nano::genesis_account, account_info));
uint64_t confirmation_height;
Expand Down Expand Up @@ -1737,11 +1721,11 @@ TEST (mdb_block_store, upgrade_v15_v16)
nano::stat stats;
nano::ledger ledger (store, stats);
auto transaction (store.tx_begin_write ());
store.initialize (transaction, genesis, ledger.rep_weights, ledger.cemented_count, ledger.block_count_cache);
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.rep_weights.representation_get (nano::genesis_account);
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);
Expand Down Expand Up @@ -1852,10 +1836,8 @@ TEST (mdb_block_store, upgrade_confirmation_height_many)
ASSERT_FALSE (error);
auto transaction (store.tx_begin_write ());
store.version_put (transaction, 13);
nano::rep_weights rep_weights;
std::atomic<uint64_t> cemented_count{ 0 };
std::atomic<uint64_t> block_count_cache{ 0 };
store.initialize (transaction, genesis, rep_weights, cemented_count, block_count_cache);
nano::ledger_cache ledger_cache;
store.initialize (transaction, genesis, ledger_cache);
modify_account_info_to_v13 (store, transaction, nano::genesis_account, genesis.open->hash ());

// Add many accounts
Expand Down
8 changes: 4 additions & 4 deletions nano/core_test/confirmation_height.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ TEST (confirmation_height, send_receive_between_2_accounts)

ASSERT_EQ (10, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in));
ASSERT_EQ (10, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out));
ASSERT_EQ (11, node->ledger.cemented_count);
ASSERT_EQ (11, node->ledger.cache.cemented_count);
}

TEST (confirmation_height, send_receive_self)
Expand Down Expand Up @@ -485,7 +485,7 @@ TEST (confirmation_height, send_receive_self)
ASSERT_EQ (8, account_info.block_count);
ASSERT_EQ (6, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in));
ASSERT_EQ (6, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out));
ASSERT_EQ (confirmation_height, node->ledger.cemented_count);
ASSERT_EQ (confirmation_height, node->ledger.cache.cemented_count);
}

TEST (confirmation_height, all_block_types)
Expand Down Expand Up @@ -590,7 +590,7 @@ TEST (confirmation_height, all_block_types)

ASSERT_EQ (15, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in));
ASSERT_EQ (15, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out));
ASSERT_EQ (16, node->ledger.cemented_count);
ASSERT_EQ (16, node->ledger.cache.cemented_count);
}

/* Bulk of the this test was taken from the node.fork_flip test */
Expand Down Expand Up @@ -772,7 +772,7 @@ TEST (confirmation_height, pending_observer_callbacks)
// Confirm the callback is not called under this circumstance
ASSERT_EQ (2, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in));
ASSERT_EQ (0, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out));
ASSERT_EQ (3, node->ledger.cemented_count);
ASSERT_EQ (3, node->ledger.cache.cemented_count);
}

TEST (confirmation_height, prioritize_frontiers)
Expand Down
Loading

0 comments on commit 8941353

Please sign in to comment.