Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting epoch tag to an enum class instead of a uint8_t. #1014

Merged
merged 4 commits into from
Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions rai/core_test/block_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@ TEST (block_store, pending_iterator)
ASSERT_TRUE (!init);
rai::transaction transaction (store.environment, nullptr, true);
ASSERT_EQ (store.pending_end (), store.pending_begin (transaction));
store.pending_put (transaction, rai::pending_key (1, 2), { 2, 3, 1 });
store.pending_put (transaction, rai::pending_key (1, 2), { 2, 3, rai::epoch::epoch_1 });
auto current (store.pending_begin (transaction));
ASSERT_NE (store.pending_end (), current);
rai::pending_key key1 (current->first);
ASSERT_EQ (rai::account (1), key1.account);
ASSERT_EQ (rai::block_hash (2), key1.hash);
rai::pending_info pending (current->second, current->from_secondary_store);
rai::pending_info pending (current->second, current->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0);
ASSERT_EQ (rai::account (2), pending.source);
ASSERT_EQ (rai::amount (3), pending.amount);
ASSERT_EQ (1, pending.min_version);
ASSERT_EQ (rai::epoch::epoch_1, pending.epoch);
}

TEST (block_store, genesis)
Expand Down Expand Up @@ -314,7 +314,7 @@ TEST (block_store, frontier_retrieval)
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::account account1 (0);
rai::account_info info1 (0, 0, 0, 0, 0, 0, 0);
rai::account_info info1 (0, 0, 0, 0, 0, 0, rai::epoch::epoch_0);
rai::transaction transaction (store.environment, nullptr, true);
store.account_put (transaction, account1, info1);
rai::account_info info2;
Expand All @@ -330,12 +330,12 @@ TEST (block_store, one_account)
rai::account account (0);
rai::block_hash hash (0);
rai::transaction transaction (store.environment, nullptr, true);
store.account_put (transaction, account, { hash, account, hash, 42, 100, 200, 0 });
store.account_put (transaction, account, { hash, account, hash, 42, 100, 200, rai::epoch::epoch_0 });
auto begin (store.latest_begin (transaction));
auto end (store.latest_end ());
ASSERT_NE (end, begin);
ASSERT_EQ (account, begin->first.uint256 ());
rai::account_info info (begin->second, begin->from_secondary_store);
rai::account_info info (begin->second, begin->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0);
ASSERT_EQ (hash, info.head);
ASSERT_EQ (42, info.balance.number ());
ASSERT_EQ (100, info.modified);
Expand Down Expand Up @@ -375,21 +375,21 @@ TEST (block_store, two_account)
rai::account account2 (3);
rai::block_hash hash2 (4);
rai::transaction transaction (store.environment, nullptr, true);
store.account_put (transaction, account1, { hash1, account1, hash1, 42, 100, 300, 0 });
store.account_put (transaction, account2, { hash2, account2, hash2, 84, 200, 400, 0 });
store.account_put (transaction, account1, { hash1, account1, hash1, 42, 100, 300, rai::epoch::epoch_0 });
store.account_put (transaction, account2, { hash2, account2, hash2, 84, 200, 400, rai::epoch::epoch_0 });
auto begin (store.latest_begin (transaction));
auto end (store.latest_end ());
ASSERT_NE (end, begin);
ASSERT_EQ (account1, begin->first.uint256 ());
rai::account_info info1 (begin->second, begin->from_secondary_store);
rai::account_info info1 (begin->second, begin->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0);
ASSERT_EQ (hash1, info1.head);
ASSERT_EQ (42, info1.balance.number ());
ASSERT_EQ (100, info1.modified);
ASSERT_EQ (300, info1.block_count);
++begin;
ASSERT_NE (end, begin);
ASSERT_EQ (account2, begin->first.uint256 ());
rai::account_info info2 (begin->second, begin->from_secondary_store);
rai::account_info info2 (begin->second, begin->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0);
ASSERT_EQ (hash2, info2.head);
ASSERT_EQ (84, info2.balance.number ());
ASSERT_EQ (200, info2.modified);
Expand All @@ -408,8 +408,8 @@ TEST (block_store, latest_find)
rai::account account2 (3);
rai::block_hash hash2 (4);
rai::transaction transaction (store.environment, nullptr, true);
store.account_put (transaction, account1, { hash1, account1, hash1, 100, 0, 300, 0 });
store.account_put (transaction, account2, { hash2, account2, hash2, 200, 0, 400, 0 });
store.account_put (transaction, account1, { hash1, account1, hash1, 100, 0, 300, rai::epoch::epoch_0 });
store.account_put (transaction, account2, { hash2, account2, hash2, 200, 0, 400, rai::epoch::epoch_0 });
auto first (store.latest_begin (transaction));
auto second (store.latest_begin (transaction));
++second;
Expand Down Expand Up @@ -667,7 +667,7 @@ TEST (block_store, upgrade_v3_v4)
ASSERT_FALSE (error);
ASSERT_EQ (key1.pub, info.source);
ASSERT_EQ (rai::amount (100), info.amount);
ASSERT_EQ (0, info.min_version);
ASSERT_EQ (rai::epoch::epoch_0, info.epoch);
}

TEST (block_store, upgrade_v4_v5)
Expand Down
12 changes: 6 additions & 6 deletions rai/core_test/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2285,13 +2285,13 @@ TEST (ledger, epoch_blocks_general)
ASSERT_EQ (rai::process_result::block_position, ledger.process (transaction, epoch2).code);
rai::account_info genesis_info;
ASSERT_FALSE (ledger.store.account_get (transaction, rai::genesis_account, genesis_info));
ASSERT_EQ (genesis_info.version, 1);
ASSERT_EQ (genesis_info.epoch, rai::epoch::epoch_1);
ledger.rollback (transaction, epoch1.hash ());
ASSERT_FALSE (ledger.store.account_get (transaction, rai::genesis_account, genesis_info));
ASSERT_EQ (genesis_info.version, 0);
ASSERT_EQ (genesis_info.epoch, rai::epoch::epoch_0);
ASSERT_EQ (rai::process_result::progress, ledger.process (transaction, epoch1).code);
ASSERT_FALSE (ledger.store.account_get (transaction, rai::genesis_account, genesis_info));
ASSERT_EQ (genesis_info.version, 1);
ASSERT_EQ (genesis_info.epoch, rai::epoch::epoch_1);
rai::change_block change1 (epoch1.hash (), rai::genesis_account, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0);
ASSERT_EQ (rai::process_result::block_position, ledger.process (transaction, change1).code);
rai::state_block send1 (rai::genesis_account, epoch1.hash (), rai::genesis_account, rai::genesis_amount - rai::Gxrb_ratio, destination.pub, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0);
Expand Down Expand Up @@ -2339,13 +2339,13 @@ TEST (ledger, epoch_blocks_receive_upgrade)
ASSERT_EQ (rai::process_result::progress, ledger.process (transaction, receive2).code);
rai::account_info destination_info;
ASSERT_FALSE (ledger.store.account_get (transaction, destination.pub, destination_info));
ASSERT_EQ (destination_info.version, 1);
ASSERT_EQ (destination_info.epoch, rai::epoch::epoch_1);
ledger.rollback (transaction, receive2.hash ());
ASSERT_FALSE (ledger.store.account_get (transaction, destination.pub, destination_info));
ASSERT_EQ (destination_info.version, 0);
ASSERT_EQ (destination_info.epoch, rai::epoch::epoch_0);
ASSERT_EQ (rai::process_result::progress, ledger.process (transaction, receive2).code);
ASSERT_FALSE (ledger.store.account_get (transaction, destination.pub, destination_info));
ASSERT_EQ (destination_info.version, 1);
ASSERT_EQ (destination_info.epoch, rai::epoch::epoch_1);
rai::keypair destination2;
rai::state_block send3 (destination.pub, receive2.hash (), destination.pub, rai::Gxrb_ratio, destination2.pub, destination.prv, destination.pub, 0);
ASSERT_EQ (rai::process_result::progress, ledger.process (transaction, send3).code);
Expand Down
6 changes: 3 additions & 3 deletions rai/core_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ TEST (rpc, frontier)
{
rai::keypair key;
source[key.pub] = key.prv.data;
system.nodes[0]->store.account_put (transaction, key.pub, rai::account_info (key.prv.data, 0, 0, 0, 0, 0, 0));
system.nodes[0]->store.account_put (transaction, key.pub, rai::account_info (key.prv.data, 0, 0, 0, 0, 0, rai::epoch::epoch_0));
}
}
rai::keypair key;
Expand Down Expand Up @@ -859,7 +859,7 @@ TEST (rpc, frontier_limited)
{
rai::keypair key;
source[key.pub] = key.prv.data;
system.nodes[0]->store.account_put (transaction, key.pub, rai::account_info (key.prv.data, 0, 0, 0, 0, 0, 0));
system.nodes[0]->store.account_put (transaction, key.pub, rai::account_info (key.prv.data, 0, 0, 0, 0, 0, rai::epoch::epoch_0));
}
}
rai::keypair key;
Expand Down Expand Up @@ -889,7 +889,7 @@ TEST (rpc, frontier_startpoint)
{
rai::keypair key;
source[key.pub] = key.prv.data;
system.nodes[0]->store.account_put (transaction, key.pub, rai::account_info (key.prv.data, 0, 0, 0, 0, 0, 0));
system.nodes[0]->store.account_put (transaction, key.pub, rai::account_info (key.prv.data, 0, 0, 0, 0, 0, rai::epoch::epoch_0));
}
}
rai::keypair key;
Expand Down
6 changes: 3 additions & 3 deletions rai/node/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ void rai::frontier_req_client::next (MDB_txn * transaction_a)
if (iterator != connection->node->store.latest_end ())
{
current = rai::account (iterator->first.uint256 ());
info = rai::account_info (iterator->second, iterator->from_secondary_store);
info = rai::account_info (iterator->second, iterator->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0);
}
else
{
Expand Down Expand Up @@ -2039,7 +2039,7 @@ void rai::bulk_push_server::received_block (boost::system::error_code const & ec
rai::frontier_req_server::frontier_req_server (std::shared_ptr<rai::bootstrap_server> const & connection_a, std::unique_ptr<rai::frontier_req> request_a) :
connection (connection_a),
current (request_a->start.number () - 1),
info (0, 0, 0, 0, 0, 0, 0),
info (0, 0, 0, 0, 0, 0, rai::epoch::epoch_0),
request (std::move (request_a)),
send_buffer (std::make_shared<std::vector<uint8_t>> ())
{
Expand Down Expand Up @@ -2141,7 +2141,7 @@ void rai::frontier_req_server::next ()
if (iterator != connection->node->store.latest_end ())
{
current = rai::uint256_union (iterator->first.uint256 ());
info = rai::account_info (iterator->second, iterator->from_secondary_store);
info = rai::account_info (iterator->second, iterator->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0);
}
else
{
Expand Down
22 changes: 11 additions & 11 deletions rai/node/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ void rai::rpc_handler::account_info ()
response_l.put ("balance", balance);
response_l.put ("modified_timestamp", std::to_string (info.modified));
response_l.put ("block_count", std::to_string (info.block_count));
response_l.put ("account_version", std::to_string (info.version));
response_l.put ("account_version", info.epoch == rai::epoch::epoch_1 ? "1" : "0");
if (representative)
{
auto block (node.store.block_get (transaction, info.rep_block));
Expand Down Expand Up @@ -848,7 +848,7 @@ void rai::rpc_handler::accounts_pending ()
}
else
{
rai::pending_info info (i->second, i->from_secondary_store);
rai::pending_info info (i->second, i->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0);
if (info.amount.number () >= threshold.number ())
{
if (source)
Expand Down Expand Up @@ -1579,7 +1579,7 @@ void rai::rpc_handler::delegators ()
rai::transaction transaction (node.store.environment, nullptr, false);
for (auto i (node.store.latest_begin (transaction)), n (node.store.latest_end ()); i != n; ++i)
{
rai::account_info info (i->second, i->from_secondary_store);
rai::account_info info (i->second, i->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0);
auto block (node.store.block_get (transaction, info.rep_block));
assert (block != nullptr);
if (block->representative () == account)
Expand Down Expand Up @@ -1609,7 +1609,7 @@ void rai::rpc_handler::delegators_count ()
rai::transaction transaction (node.store.environment, nullptr, false);
for (auto i (node.store.latest_begin (transaction)), n (node.store.latest_end ()); i != n; ++i)
{
rai::account_info info (i->second, i->from_secondary_store);
rai::account_info info (i->second, i->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0);
auto block (node.store.block_get (transaction, info.rep_block));
assert (block != nullptr);
if (block->representative () == account)
Expand Down Expand Up @@ -1679,7 +1679,7 @@ void rai::rpc_handler::frontiers ()
rai::transaction transaction (node.store.environment, nullptr, false);
for (auto i (node.store.latest_begin (transaction, start)), n (node.store.latest_end ()); i != n && frontiers.size () < count; ++i)
{
frontiers.put (rai::account (i->first.uint256 ()).to_account (), rai::account_info (i->second, i->from_secondary_store).head.to_string ());
frontiers.put (rai::account (i->first.uint256 ()).to_account (), rai::account_info (i->second, i->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0).head.to_string ());
}
response_l.add_child ("frontiers", frontiers);
response (response_l);
Expand Down Expand Up @@ -2041,7 +2041,7 @@ void rai::rpc_handler::ledger ()
{
for (auto i (node.store.latest_begin (transaction, start)), n (node.store.latest_end ()); i != n && accounts.size () < count; ++i)
{
rai::account_info info (i->second, i->from_secondary_store);
rai::account_info info (i->second, i->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0);
if (info.modified >= modified_since)
{
rai::account account (i->first.uint256 ());
Expand Down Expand Up @@ -2079,7 +2079,7 @@ void rai::rpc_handler::ledger ()
std::vector<std::pair<rai::uint128_union, rai::account>> ledger_l;
for (auto i (node.store.latest_begin (transaction, start)), n (node.store.latest_end ()); i != n; ++i)
{
rai::account_info info (i->second, i->from_secondary_store);
rai::account_info info (i->second, i->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0);
rai::uint128_union balance (info.balance);
if (info.modified >= modified_since)
{
Expand Down Expand Up @@ -2366,7 +2366,7 @@ void rai::rpc_handler::pending ()
}
else
{
rai::pending_info info (i->second, i->from_secondary_store);
rai::pending_info info (i->second, i->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0);
if (info.amount.number () >= threshold.number ())
{
if (source || min_version)
Expand All @@ -2379,7 +2379,7 @@ void rai::rpc_handler::pending ()
}
if (min_version)
{
pending_tree.put ("min_version", std::to_string (info.min_version));
pending_tree.put ("min_version", info.epoch == rai::epoch::epoch_1 ? "1" : "0");
}
peers_l.add_child (key.hash.to_string (), pending_tree);
}
Expand Down Expand Up @@ -4060,7 +4060,7 @@ void rai::rpc_handler::wallet_pending ()
}
else
{
rai::pending_info info (ii->second, ii->from_secondary_store);
rai::pending_info info (ii->second, ii->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0);
if (info.amount.number () >= threshold.number ())
{
if (source || min_version)
Expand All @@ -4073,7 +4073,7 @@ void rai::rpc_handler::wallet_pending ()
}
if (min_version)
{
pending_tree.put ("min_version", std::to_string (info.min_version));
pending_tree.put ("min_version", info.epoch == rai::epoch::epoch_1 ? "1" : "0");
}
peers_l.add_child (key.hash.to_string (), pending_tree);
}
Expand Down
2 changes: 1 addition & 1 deletion rai/node/testing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void rai::system::generate_receive (rai::node & node_a)
if (i != node_a.store.pending_end ())
{
rai::pending_key send_hash (i->first);
rai::pending_info info (i->second, i->from_secondary_store);
rai::pending_info info (i->second, i->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0);
send_block = node_a.store.block_get (transaction, send_hash.hash);
}
}
Expand Down
2 changes: 1 addition & 1 deletion rai/node/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ bool rai::wallet::search_pending ()
{
rai::pending_key key (j->first);
auto hash (key.hash);
rai::pending_info pending (j->second, j->from_secondary_store);
rai::pending_info pending (j->second, j->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0);
auto amount (pending.amount.number ());
if (node.config.receive_minimum.number () <= amount)
{
Expand Down
2 changes: 1 addition & 1 deletion rai/qt/qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,7 @@ void rai_qt::advanced_actions::refresh_ledger ()
{
QList<QStandardItem *> items;
items.push_back (new QStandardItem (QString (rai::block_hash (i->first.uint256 ()).to_account ().c_str ())));
rai::account_info info (i->second, i->from_secondary_store);
rai::account_info info (i->second, i->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0);
std::string balance;
rai::amount (info.balance.number () / wallet.rendering_ratio).encode_dec (balance);
items.push_back (new QStandardItem (QString (balance.c_str ())));
Expand Down
2 changes: 1 addition & 1 deletion rai/rai_node/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int main (int argc, char * const * argv)
std::map<rai::account, rai::uint128_t> calculated;
for (auto i (node.node->store.latest_begin (transaction)), n (node.node->store.latest_end ()); i != n; ++i)
{
rai::account_info info (i->second, i->from_secondary_store);
rai::account_info info (i->second, i->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0);
rai::block_hash rep_block (node.node->ledger.representative_calculated (transaction, info.head));
std::unique_ptr<rai::block> block (node.node->store.block_get (transaction, rep_block));
calculated[block->representative ()] += info.balance.number ();
Expand Down
Loading