Add function ledger::account_info which encapsulates direct calls to account_store::get.

Rather than directly accessing the block store, users should use the ledger interface to query for this information.

Result is returned as an std::optional instead of the less-obvious way it's currently reported through an error code.

Most though not all of the account_store::get references have been updated to use ledger::account_info.
This commit is contained in:
clemahieu 2023-01-26 20:08:56 +00:00
commit 0d30fbed9b
11 changed files with 265 additions and 263 deletions

View file

@ -1677,8 +1677,8 @@ namespace lmdb
nano::ledger ledger (store, stats, nano::dev::constants);
auto transaction (store.tx_begin_write ());
store.initialize (transaction, ledger.cache, nano::dev::constants);
nano::account_info account_info;
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis->account (), account_info));
auto account_info = ledger.account_info (transaction, nano::dev::genesis->account ());
ASSERT_TRUE (account_info);
nano::confirmation_height_info confirmation_height_info;
ASSERT_FALSE (store.confirmation_height.get (transaction, nano::dev::genesis->account (),
confirmation_height_info));

View file

@ -249,31 +249,34 @@ TEST (confirmation_height, multiple_accounts)
ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 10);
nano::account_info account_info;
nano::confirmation_height_info confirmation_height_info;
auto & store = node->store;
auto transaction = node->store.tx_begin_read ();
ASSERT_TRUE (node->ledger.block_confirmed (transaction, receive3->hash ()));
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis_key.pub, account_info));
auto account_info = node->ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (account_info);
ASSERT_FALSE (node->store.confirmation_height.get (transaction, nano::dev::genesis_key.pub, confirmation_height_info));
ASSERT_EQ (4, confirmation_height_info.height);
ASSERT_EQ (send3->hash (), confirmation_height_info.frontier);
ASSERT_EQ (4, account_info.block_count);
ASSERT_FALSE (store.account.get (transaction, key1.pub, account_info));
ASSERT_EQ (4, account_info->block_count);
account_info = node->ledger.account_info (transaction, key1.pub);
ASSERT_TRUE (account_info);
ASSERT_FALSE (node->store.confirmation_height.get (transaction, key1.pub, confirmation_height_info));
ASSERT_EQ (2, confirmation_height_info.height);
ASSERT_EQ (send4->hash (), confirmation_height_info.frontier);
ASSERT_EQ (3, account_info.block_count);
ASSERT_FALSE (store.account.get (transaction, key2.pub, account_info));
ASSERT_EQ (3, account_info->block_count);
account_info = node->ledger.account_info (transaction, key2.pub);
ASSERT_TRUE (account_info);
ASSERT_FALSE (node->store.confirmation_height.get (transaction, key2.pub, confirmation_height_info));
ASSERT_EQ (3, confirmation_height_info.height);
ASSERT_EQ (send6->hash (), confirmation_height_info.frontier);
ASSERT_EQ (4, account_info.block_count);
ASSERT_FALSE (store.account.get (transaction, key3.pub, account_info));
ASSERT_EQ (4, account_info->block_count);
account_info = node->ledger.account_info (transaction, key3.pub);
ASSERT_TRUE (account_info);
ASSERT_FALSE (node->store.confirmation_height.get (transaction, key3.pub, confirmation_height_info));
ASSERT_EQ (2, confirmation_height_info.height);
ASSERT_EQ (receive3->hash (), confirmation_height_info.frontier);
ASSERT_EQ (2, account_info.block_count);
ASSERT_EQ (2, account_info->block_count);
// The accounts for key1 and key2 have 1 more block in the chain than is confirmed.
// So this can be rolled back, but the one before that cannot. Check that this is the case
@ -697,19 +700,20 @@ TEST (confirmation_height, send_receive_between_2_accounts)
auto transaction (node->store.tx_begin_read ());
ASSERT_TRUE (node->ledger.block_confirmed (transaction, receive4->hash ()));
nano::account_info account_info;
nano::confirmation_height_info confirmation_height_info;
ASSERT_FALSE (node->store.account.get (transaction, nano::dev::genesis_key.pub, account_info));
auto account_info = node->ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (account_info);
ASSERT_FALSE (node->store.confirmation_height.get (transaction, nano::dev::genesis_key.pub, confirmation_height_info));
ASSERT_EQ (6, confirmation_height_info.height);
ASSERT_EQ (send5->hash (), confirmation_height_info.frontier);
ASSERT_EQ (7, account_info.block_count);
ASSERT_EQ (7, account_info->block_count);
ASSERT_FALSE (node->store.account.get (transaction, key1.pub, account_info));
account_info = node->ledger.account_info (transaction, key1.pub);
ASSERT_TRUE (account_info);
ASSERT_FALSE (node->store.confirmation_height.get (transaction, key1.pub, confirmation_height_info));
ASSERT_EQ (5, confirmation_height_info.height);
ASSERT_EQ (receive4->hash (), confirmation_height_info.frontier);
ASSERT_EQ (5, account_info.block_count);
ASSERT_EQ (5, account_info->block_count);
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::confirmation_height, get_stats_detail (mode_a), nano::stat::dir::in));
@ -814,13 +818,13 @@ TEST (confirmation_height, send_receive_self)
auto transaction (node->store.tx_begin_read ());
ASSERT_TRUE (node->ledger.block_confirmed (transaction, receive3->hash ()));
nano::account_info account_info;
ASSERT_FALSE (node->store.account.get (transaction, nano::dev::genesis_key.pub, account_info));
auto account_info = node->ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (account_info);
nano::confirmation_height_info confirmation_height_info;
ASSERT_FALSE (node->store.confirmation_height.get (transaction, nano::dev::genesis_key.pub, confirmation_height_info));
ASSERT_EQ (7, confirmation_height_info.height);
ASSERT_EQ (receive3->hash (), confirmation_height_info.frontier);
ASSERT_EQ (8, account_info.block_count);
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::confirmation_height, get_stats_detail (mode_a), nano::stat::dir::in));
ASSERT_EQ (6, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out));
@ -1060,25 +1064,27 @@ TEST (confirmation_height, all_block_types)
auto transaction (node->store.tx_begin_read ());
ASSERT_TRUE (node->ledger.block_confirmed (transaction, state_send2->hash ()));
nano::account_info account_info;
nano::confirmation_height_info confirmation_height_info;
ASSERT_FALSE (node->store.account.get (transaction, nano::dev::genesis_key.pub, account_info));
auto account_info = node->ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (account_info);
ASSERT_FALSE (node->store.confirmation_height.get (transaction, nano::dev::genesis_key.pub, confirmation_height_info));
ASSERT_EQ (3, confirmation_height_info.height);
ASSERT_EQ (send1->hash (), confirmation_height_info.frontier);
ASSERT_LE (4, account_info.block_count);
ASSERT_LE (4, account_info->block_count);
ASSERT_FALSE (node->store.account.get (transaction, key1.pub, account_info));
account_info = node->ledger.account_info (transaction, key1.pub);
ASSERT_TRUE (account_info);
ASSERT_FALSE (node->store.confirmation_height.get (transaction, key1.pub, confirmation_height_info));
ASSERT_EQ (state_send1->hash (), confirmation_height_info.frontier);
ASSERT_EQ (6, confirmation_height_info.height);
ASSERT_LE (7, account_info.block_count);
ASSERT_LE (7, account_info->block_count);
ASSERT_FALSE (node->store.account.get (transaction, key2.pub, account_info));
account_info = node->ledger.account_info (transaction, key2.pub);
ASSERT_TRUE (account_info);
ASSERT_FALSE (node->store.confirmation_height.get (transaction, key2.pub, confirmation_height_info));
ASSERT_EQ (7, confirmation_height_info.height);
ASSERT_EQ (state_send2->hash (), confirmation_height_info.frontier);
ASSERT_LE (8, account_info.block_count);
ASSERT_LE (8, account_info->block_count);
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::confirmation_height, get_stats_detail (mode_a), nano::stat::dir::in));

View file

@ -45,12 +45,12 @@ TEST (ledger, genesis_balance)
ASSERT_EQ (nano::dev::constants.genesis_amount, balance);
auto amount = ledger.amount (transaction, nano::dev::genesis->account ());
ASSERT_EQ (nano::dev::constants.genesis_amount, amount);
nano::account_info info;
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis->account (), info));
auto info = ledger.account_info (transaction, nano::dev::genesis->account ());
ASSERT_TRUE (info);
ASSERT_EQ (1, ledger.cache.account_count);
// Frontier time should have been updated when genesis balance was added
ASSERT_GE (nano::seconds_since_epoch (), info.modified);
ASSERT_LT (nano::seconds_since_epoch () - info.modified, 10);
ASSERT_GE (nano::seconds_since_epoch (), info->modified);
ASSERT_LT (nano::seconds_since_epoch () - info->modified, 10);
// Genesis block should be confirmed by default
nano::confirmation_height_info confirmation_height_info;
ASSERT_FALSE (store.confirmation_height.get (transaction, nano::dev::genesis->account (), confirmation_height_info));
@ -87,36 +87,36 @@ TEST (ledger, process_send)
auto & store = ctx.store ();
auto transaction = store.tx_begin_write ();
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::account_info info1;
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis_key.pub, info1));
auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info1);
nano::keypair key2;
nano::block_builder builder;
auto send = builder
.send ()
.previous (info1.head)
.previous (info1->head)
.destination (key2.pub)
.balance (50)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*pool.generate (info1.head))
.work (*pool.generate (info1->head))
.build ();
nano::block_hash hash1 = send->hash ();
ASSERT_EQ (nano::dev::genesis_key.pub, store.frontier.get (transaction, info1.head));
ASSERT_EQ (1, info1.block_count);
ASSERT_EQ (nano::dev::genesis_key.pub, store.frontier.get (transaction, info1->head));
ASSERT_EQ (1, info1->block_count);
// This was a valid block, it should progress.
auto return1 = ledger.process (transaction, *send);
ASSERT_EQ (nano::dev::genesis_key.pub, send->sideband ().account);
ASSERT_EQ (2, send->sideband ().height);
ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.amount (transaction, hash1));
ASSERT_TRUE (store.frontier.get (transaction, info1.head).is_zero ());
ASSERT_TRUE (store.frontier.get (transaction, info1->head).is_zero ());
ASSERT_EQ (nano::dev::genesis_key.pub, store.frontier.get (transaction, hash1));
ASSERT_EQ (nano::process_result::progress, return1.code);
ASSERT_EQ (nano::dev::genesis_key.pub, store.block.account_calculated (*send));
ASSERT_EQ (50, ledger.account_balance (transaction, nano::dev::genesis_key.pub));
ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.account_receivable (transaction, key2.pub));
nano::account_info info2;
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis_key.pub, info2));
ASSERT_EQ (2, info2.block_count);
auto latest6 = store.block.get (transaction, info2.head);
auto info2 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info2);
ASSERT_EQ (2, info2->block_count);
auto latest6 = store.block.get (transaction, info2->head);
ASSERT_NE (nullptr, latest6);
auto latest7 = dynamic_cast<nano::send_block *> (latest6.get ());
ASSERT_NE (nullptr, latest7);
@ -146,24 +146,24 @@ TEST (ledger, process_send)
ASSERT_EQ (0, ledger.account_receivable (transaction, key2.pub));
ASSERT_EQ (50, ledger.weight (nano::dev::genesis_key.pub));
ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.weight (key2.pub));
nano::account_info info3;
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis_key.pub, info3));
auto latest2 = store.block.get (transaction, info3.head);
auto info3 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info3);
auto latest2 = store.block.get (transaction, info3->head);
ASSERT_NE (nullptr, latest2);
auto latest3 = dynamic_cast<nano::send_block *> (latest2.get ());
ASSERT_NE (nullptr, latest3);
ASSERT_EQ (*send, *latest3);
nano::account_info info4;
ASSERT_FALSE (store.account.get (transaction, key2.pub, info4));
auto latest4 = store.block.get (transaction, info4.head);
auto info4 = ledger.account_info (transaction, key2.pub);
ASSERT_TRUE (info4);
auto latest4 = store.block.get (transaction, info4->head);
ASSERT_NE (nullptr, latest4);
auto latest5 = dynamic_cast<nano::open_block *> (latest4.get ());
ASSERT_NE (nullptr, latest5);
ASSERT_EQ (*open, *latest5);
ASSERT_FALSE (ledger.rollback (transaction, hash2));
ASSERT_TRUE (store.frontier.get (transaction, hash2).is_zero ());
nano::account_info info5;
ASSERT_TRUE (ledger.store.account.get (transaction, key2.pub, info5));
auto info5 = ledger.account_info (transaction, key2.pub);
ASSERT_FALSE (info5);
nano::pending_info pending1;
ASSERT_FALSE (ledger.store.pending.get (transaction, nano::pending_key (key2.pub, hash1), pending1));
ASSERT_EQ (nano::dev::genesis_key.pub, pending1.source);
@ -173,17 +173,17 @@ TEST (ledger, process_send)
ASSERT_EQ (50, ledger.account_balance (transaction, nano::dev::genesis_key.pub));
ASSERT_EQ (50, ledger.weight (nano::dev::genesis_key.pub));
ASSERT_EQ (0, ledger.weight (key2.pub));
nano::account_info info6;
ASSERT_FALSE (ledger.store.account.get (transaction, nano::dev::genesis_key.pub, info6));
ASSERT_EQ (hash1, info6.head);
ASSERT_FALSE (ledger.rollback (transaction, info6.head));
auto info6 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info6);
ASSERT_EQ (hash1, info6->head);
ASSERT_FALSE (ledger.rollback (transaction, info6->head));
ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub));
ASSERT_EQ (nano::dev::genesis_key.pub, store.frontier.get (transaction, info1.head));
ASSERT_EQ (nano::dev::genesis_key.pub, store.frontier.get (transaction, info1->head));
ASSERT_TRUE (store.frontier.get (transaction, hash1).is_zero ());
nano::account_info info7;
ASSERT_FALSE (ledger.store.account.get (transaction, nano::dev::genesis_key.pub, info7));
ASSERT_EQ (1, info7.block_count);
ASSERT_EQ (info1.head, info7.head);
auto info7 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info7);
ASSERT_EQ (1, info7->block_count);
ASSERT_EQ (info1->head, info7->head);
nano::pending_info pending2;
ASSERT_TRUE (ledger.store.pending.get (transaction, nano::pending_key (key2.pub, hash1), pending2));
ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis_key.pub));
@ -198,17 +198,17 @@ TEST (ledger, process_receive)
auto & store = ctx.store ();
auto transaction = store.tx_begin_write ();
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::account_info info1;
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis_key.pub, info1));
auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info1);
nano::keypair key2;
nano::block_builder builder;
auto send = builder
.send ()
.previous (info1.head)
.previous (info1->head)
.destination (key2.pub)
.balance (50)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*pool.generate (info1.head))
.work (*pool.generate (info1->head))
.build ();
nano::block_hash hash1 (send->hash ());
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *send).code);
@ -286,17 +286,17 @@ TEST (ledger, rollback_receiver)
auto & store = ctx.store ();
auto transaction = store.tx_begin_write ();
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::account_info info1;
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis_key.pub, info1));
auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info1);
nano::keypair key2;
nano::block_builder builder;
auto send = builder
.send ()
.previous (info1.head)
.previous (info1->head)
.destination (key2.pub)
.balance (50)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*pool.generate (info1.head))
.work (*pool.generate (info1->head))
.build ();
nano::block_hash hash1 (send->hash ());
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *send).code);
@ -323,11 +323,10 @@ TEST (ledger, rollback_receiver)
ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub));
ASSERT_EQ (0, ledger.weight (key2.pub));
ASSERT_EQ (0, ledger.weight (key3.pub));
nano::account_info info2;
ASSERT_TRUE (store.account.get (transaction, key2.pub, info2));
ASSERT_FALSE (ledger.account_info (transaction, key2.pub));
ASSERT_EQ (store.account.count (transaction), ledger.cache.account_count);
nano::pending_info pending1;
ASSERT_TRUE (store.pending.get (transaction, nano::pending_key{ key2.pub, info2.head }, pending1));
ASSERT_TRUE (store.pending.get (transaction, nano::pending_key{ key2.pub, hash1 }, pending1));
}
TEST (ledger, rollback_representation)
@ -395,13 +394,13 @@ TEST (ledger, rollback_representation)
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *receive1).code);
ASSERT_EQ (1, ledger.weight (key3.pub));
ASSERT_EQ (nano::dev::constants.genesis_amount - 1, ledger.weight (key4.pub));
nano::account_info info1;
ASSERT_FALSE (store.account.get (transaction, key2.pub, info1));
ASSERT_EQ (key4.pub, info1.representative);
auto info1 = ledger.account_info (transaction, key2.pub);
ASSERT_TRUE (info1);
ASSERT_EQ (key4.pub, info1->representative);
ASSERT_FALSE (ledger.rollback (transaction, receive1->hash ()));
nano::account_info info2;
ASSERT_FALSE (store.account.get (transaction, key2.pub, info2));
ASSERT_EQ (key4.pub, info2.representative);
auto info2 = ledger.account_info (transaction, key2.pub);
ASSERT_TRUE (info2);
ASSERT_EQ (key4.pub, info2->representative);
ASSERT_EQ (0, ledger.weight (key2.pub));
ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.weight (key4.pub));
ASSERT_FALSE (ledger.rollback (transaction, open->hash ()));
@ -409,13 +408,13 @@ TEST (ledger, rollback_representation)
ASSERT_EQ (0, ledger.weight (key4.pub));
ledger.rollback (transaction, send1->hash ());
ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (key3.pub));
nano::account_info info3;
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis_key.pub, info3));
ASSERT_EQ (key3.pub, info3.representative);
auto info3 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info3);
ASSERT_EQ (key3.pub, info3->representative);
ASSERT_FALSE (ledger.rollback (transaction, change2->hash ()));
nano::account_info info4;
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis_key.pub, info4));
ASSERT_EQ (key5.pub, info4.representative);
auto info4 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info4);
ASSERT_EQ (key5.pub, info4->representative);
ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (key5.pub));
ASSERT_EQ (0, ledger.weight (key3.pub));
}
@ -455,17 +454,17 @@ TEST (ledger, process_duplicate)
auto & store = ctx.store ();
auto transaction = store.tx_begin_write ();
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::account_info info1;
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis_key.pub, info1));
auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info1);
nano::keypair key2;
nano::block_builder builder;
auto send = builder
.send ()
.previous (info1.head)
.previous (info1->head)
.destination (key2.pub)
.balance (50)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*pool.generate (info1.head))
.work (*pool.generate (info1->head))
.build ();
nano::block_hash hash1 (send->hash ());
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *send).code);
@ -510,34 +509,34 @@ TEST (ledger, representative_change)
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub));
ASSERT_EQ (0, ledger.weight (key2.pub));
nano::account_info info1;
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis_key.pub, info1));
auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info1);
nano::block_builder builder;
auto block = builder
.change ()
.previous (info1.head)
.previous (info1->head)
.representative (key2.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*pool.generate (info1.head))
.work (*pool.generate (info1->head))
.build ();
ASSERT_EQ (nano::dev::genesis_key.pub, store.frontier.get (transaction, info1.head));
ASSERT_EQ (nano::dev::genesis_key.pub, store.frontier.get (transaction, info1->head));
auto return1 (ledger.process (transaction, *block));
ASSERT_EQ (0, ledger.amount (transaction, block->hash ()));
ASSERT_TRUE (store.frontier.get (transaction, info1.head).is_zero ());
ASSERT_TRUE (store.frontier.get (transaction, info1->head).is_zero ());
ASSERT_EQ (nano::dev::genesis_key.pub, store.frontier.get (transaction, block->hash ()));
ASSERT_EQ (nano::process_result::progress, return1.code);
ASSERT_EQ (nano::dev::genesis_key.pub, store.block.account_calculated (*block));
ASSERT_EQ (0, ledger.weight (nano::dev::genesis_key.pub));
ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (key2.pub));
nano::account_info info2;
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis_key.pub, info2));
ASSERT_EQ (block->hash (), info2.head);
ASSERT_FALSE (ledger.rollback (transaction, info2.head));
ASSERT_EQ (nano::dev::genesis_key.pub, store.frontier.get (transaction, info1.head));
auto info2 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info2);
ASSERT_EQ (block->hash (), info2->head);
ASSERT_FALSE (ledger.rollback (transaction, info2->head));
ASSERT_EQ (nano::dev::genesis_key.pub, store.frontier.get (transaction, info1->head));
ASSERT_TRUE (store.frontier.get (transaction, block->hash ()).is_zero ());
nano::account_info info3;
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis_key.pub, info3));
ASSERT_EQ (info1.head, info3.head);
auto info3 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info3);
ASSERT_EQ (info1->head, info3->head);
ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub));
ASSERT_EQ (0, ledger.weight (key2.pub));
}
@ -551,25 +550,25 @@ TEST (ledger, send_fork)
nano::keypair key3;
auto transaction = store.tx_begin_write ();
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::account_info info1;
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis_key.pub, info1));
auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info1);
nano::block_builder builder;
auto block = builder
.send ()
.previous (info1.head)
.previous (info1->head)
.destination (key2.pub)
.balance (100)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*pool.generate (info1.head))
.work (*pool.generate (info1->head))
.build ();
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *block).code);
auto block2 = builder
.send ()
.previous (info1.head)
.previous (info1->head)
.destination (key3.pub)
.balance (0)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*pool.generate (info1.head))
.work (*pool.generate (info1->head))
.build ();
ASSERT_EQ (nano::process_result::fork, ledger.process (transaction, *block2).code);
}
@ -583,16 +582,16 @@ TEST (ledger, receive_fork)
nano::keypair key3;
auto transaction = store.tx_begin_write ();
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::account_info info1;
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis_key.pub, info1));
auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info1);
nano::block_builder builder;
auto block = builder
.send ()
.previous (info1.head)
.previous (info1->head)
.destination (key2.pub)
.balance (100)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*pool.generate (info1.head))
.work (*pool.generate (info1->head))
.build ();
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *block).code);
auto block2 = builder
@ -640,16 +639,16 @@ TEST (ledger, open_fork)
nano::keypair key3;
auto transaction = store.tx_begin_write ();
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::account_info info1;
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis_key.pub, info1));
auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info1);
nano::block_builder builder;
auto block = builder
.send ()
.previous (info1.head)
.previous (info1->head)
.destination (key2.pub)
.balance (100)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*pool.generate (info1.head))
.work (*pool.generate (info1->head))
.build ();
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *block).code);
auto block2 = builder
@ -2076,17 +2075,17 @@ TEST (ledger, send_open_receive_rollback)
auto & store = ctx.store ();
auto transaction = store.tx_begin_write ();
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::account_info info1;
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis_key.pub, info1));
auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info1);
nano::keypair key1;
nano::block_builder builder;
auto send1 = builder
.send ()
.previous (info1.head)
.previous (info1->head)
.destination (key1.pub)
.balance (nano::dev::constants.genesis_amount - 50)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*pool.generate (info1.head))
.work (*pool.generate (info1->head))
.build ();
auto return1 = ledger.process (transaction, *send1);
ASSERT_EQ (nano::process_result::progress, return1.code);
@ -2163,20 +2162,20 @@ TEST (ledger, bootstrap_rep_weight)
auto ctx = nano::test::context::ledger_empty ();
auto & ledger = ctx.ledger ();
auto & store = ctx.store ();
nano::account_info info1;
nano::keypair key2;
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
{
auto transaction = store.tx_begin_write ();
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis_key.pub, info1));
auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info1);
nano::block_builder builder;
auto send = builder
.send ()
.previous (info1.head)
.previous (info1->head)
.destination (key2.pub)
.balance (std::numeric_limits<nano::uint128_t>::max () - 50)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*pool.generate (info1.head))
.work (*pool.generate (info1->head))
.build ();
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *send).code);
}
@ -2188,15 +2187,16 @@ TEST (ledger, bootstrap_rep_weight)
}
{
auto transaction = store.tx_begin_write ();
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis_key.pub, info1));
auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info1);
nano::block_builder builder;
auto send = builder
.send ()
.previous (info1.head)
.previous (info1->head)
.destination (key2.pub)
.balance (std::numeric_limits<nano::uint128_t>::max () - 100)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*pool.generate (info1.head))
.work (*pool.generate (info1->head))
.build ();
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *send).code);
}
@ -3369,15 +3369,17 @@ TEST (ledger, epoch_blocks_v1_general)
.work (*pool.generate (epoch1->hash ()))
.build ();
ASSERT_EQ (nano::process_result::block_position, ledger.process (transaction, *epoch2).code);
nano::account_info genesis_info;
ASSERT_FALSE (ledger.store.account.get (transaction, nano::dev::genesis->account (), genesis_info));
ASSERT_EQ (genesis_info.epoch (), nano::epoch::epoch_1);
auto genesis_info = ledger.account_info (transaction, nano::dev::genesis->account ());
ASSERT_TRUE (genesis_info);
ASSERT_EQ (genesis_info->epoch (), nano::epoch::epoch_1);
ASSERT_FALSE (ledger.rollback (transaction, epoch1->hash ()));
ASSERT_FALSE (ledger.store.account.get (transaction, nano::dev::genesis->account (), genesis_info));
ASSERT_EQ (genesis_info.epoch (), nano::epoch::epoch_0);
genesis_info = ledger.account_info (transaction, nano::dev::genesis->account ());
ASSERT_TRUE (genesis_info);
ASSERT_EQ (genesis_info->epoch (), nano::epoch::epoch_0);
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *epoch1).code);
ASSERT_FALSE (ledger.store.account.get (transaction, nano::dev::genesis->account (), genesis_info));
ASSERT_EQ (genesis_info.epoch (), nano::epoch::epoch_1);
genesis_info = ledger.account_info (transaction, nano::dev::genesis->account ());
ASSERT_TRUE (genesis_info);
ASSERT_EQ (genesis_info->epoch (), nano::epoch::epoch_1);
ASSERT_FALSE (epoch1->sideband ().details.is_send);
ASSERT_FALSE (epoch1->sideband ().details.is_receive);
ASSERT_TRUE (epoch1->sideband ().details.is_epoch);
@ -3533,15 +3535,17 @@ TEST (ledger, epoch_blocks_v2_general)
.work (*pool.generate (epoch2->hash ()))
.build ();
ASSERT_EQ (nano::process_result::block_position, ledger.process (transaction, *epoch3).code);
nano::account_info genesis_info;
ASSERT_FALSE (ledger.store.account.get (transaction, nano::dev::genesis->account (), genesis_info));
ASSERT_EQ (genesis_info.epoch (), nano::epoch::epoch_2);
auto genesis_info = ledger.account_info (transaction, nano::dev::genesis->account ());
ASSERT_TRUE (genesis_info);
ASSERT_EQ (genesis_info->epoch (), nano::epoch::epoch_2);
ASSERT_FALSE (ledger.rollback (transaction, epoch1->hash ()));
ASSERT_FALSE (ledger.store.account.get (transaction, nano::dev::genesis->account (), genesis_info));
ASSERT_EQ (genesis_info.epoch (), nano::epoch::epoch_0);
genesis_info = ledger.account_info (transaction, nano::dev::genesis->account ());
ASSERT_TRUE (genesis_info);
ASSERT_EQ (genesis_info->epoch (), nano::epoch::epoch_0);
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *epoch1).code);
ASSERT_FALSE (ledger.store.account.get (transaction, nano::dev::genesis->account (), genesis_info));
ASSERT_EQ (genesis_info.epoch (), nano::epoch::epoch_1);
genesis_info = ledger.account_info (transaction, nano::dev::genesis->account ());
ASSERT_TRUE (genesis_info);
ASSERT_EQ (genesis_info->epoch (), nano::epoch::epoch_1);
auto change1 = builder
.change ()
.previous (epoch1->hash ())
@ -3713,12 +3717,13 @@ TEST (ledger, epoch_blocks_receive_upgrade)
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *receive2).code);
ASSERT_EQ (nano::epoch::epoch_1, receive2->sideband ().details.epoch);
ASSERT_EQ (nano::epoch::epoch_1, receive2->sideband ().source_epoch);
nano::account_info destination_info;
ASSERT_FALSE (ledger.store.account.get (transaction, destination.pub, destination_info));
ASSERT_EQ (destination_info.epoch (), nano::epoch::epoch_1);
auto destination_info = ledger.account_info (transaction, destination.pub);
ASSERT_TRUE (destination_info);
ASSERT_EQ (destination_info->epoch (), nano::epoch::epoch_1);
ASSERT_FALSE (ledger.rollback (transaction, receive2->hash ()));
ASSERT_FALSE (ledger.store.account.get (transaction, destination.pub, destination_info));
ASSERT_EQ (destination_info.epoch (), nano::epoch::epoch_0);
destination_info = ledger.account_info (transaction, destination.pub);
ASSERT_TRUE (destination_info);
ASSERT_EQ (destination_info->epoch (), nano::epoch::epoch_0);
nano::pending_info pending_send2;
ASSERT_FALSE (ledger.store.pending.get (transaction, nano::pending_key (destination.pub, send2->hash ()), pending_send2));
ASSERT_EQ (nano::dev::genesis_key.pub, pending_send2.source);
@ -3727,8 +3732,9 @@ TEST (ledger, epoch_blocks_receive_upgrade)
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *receive2).code);
ASSERT_EQ (nano::epoch::epoch_1, receive2->sideband ().details.epoch);
ASSERT_EQ (nano::epoch::epoch_1, receive2->sideband ().source_epoch);
ASSERT_FALSE (ledger.store.account.get (transaction, destination.pub, destination_info));
ASSERT_EQ (destination_info.epoch (), nano::epoch::epoch_1);
destination_info = ledger.account_info (transaction, destination.pub);
ASSERT_TRUE (destination_info);
ASSERT_EQ (destination_info->epoch (), nano::epoch::epoch_1);
nano::keypair destination2;
auto send3 = builder
.state ()
@ -3795,8 +3801,9 @@ TEST (ledger, epoch_blocks_receive_upgrade)
.work (*pool.generate (send4->hash ()))
.build ();
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *send5).code);
ASSERT_FALSE (ledger.store.account.get (transaction, destination.pub, destination_info));
ASSERT_EQ (destination_info.epoch (), nano::epoch::epoch_1);
destination_info = ledger.account_info (transaction, destination.pub);
ASSERT_TRUE (destination_info);
ASSERT_EQ (destination_info->epoch (), nano::epoch::epoch_1);
auto receive3 = builder
.state ()
.account (destination.pub)
@ -3810,8 +3817,9 @@ TEST (ledger, epoch_blocks_receive_upgrade)
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *receive3).code);
ASSERT_EQ (nano::epoch::epoch_2, receive3->sideband ().details.epoch);
ASSERT_EQ (nano::epoch::epoch_2, receive3->sideband ().source_epoch);
ASSERT_FALSE (ledger.store.account.get (transaction, destination.pub, destination_info));
ASSERT_EQ (destination_info.epoch (), nano::epoch::epoch_2);
destination_info = ledger.account_info (transaction, destination.pub);
ASSERT_TRUE (destination_info);
ASSERT_EQ (destination_info->epoch (), nano::epoch::epoch_2);
// Upgrade an unopened account straight to epoch 2
nano::keypair destination4;
auto send6 = builder
@ -4297,9 +4305,9 @@ TEST (ledger, unchecked_epoch)
{
// Waits for the last blocks to pass through block_processor and unchecked.put queues
ASSERT_TIMELY (10s, 0 == node1.unchecked.count (node1.store.tx_begin_read ()));
nano::account_info info{};
ASSERT_FALSE (node1.store.account.get (node1.store.tx_begin_read (), destination.pub, info));
ASSERT_EQ (info.epoch (), nano::epoch::epoch_1);
auto info = node1.ledger.account_info (node1.store.tx_begin_read (), destination.pub);
ASSERT_TRUE (info);
ASSERT_EQ (info->epoch (), nano::epoch::epoch_1);
}
}
@ -4375,9 +4383,9 @@ TEST (ledger, unchecked_epoch_invalid)
auto unchecked_count = node1.unchecked.count (transaction);
ASSERT_EQ (unchecked_count, 0);
ASSERT_EQ (unchecked_count, node1.unchecked.count (transaction));
nano::account_info info{};
ASSERT_FALSE (node1.store.account.get (transaction, destination.pub, info));
ASSERT_NE (info.epoch (), nano::epoch::epoch_1);
auto info = node1.ledger.account_info (transaction, destination.pub);
ASSERT_TRUE (info);
ASSERT_NE (info->epoch (), nano::epoch::epoch_1);
auto epoch2_store = node1.store.block.get (transaction, epoch2->hash ());
ASSERT_NE (nullptr, epoch2_store);
ASSERT_EQ (nano::epoch::epoch_0, epoch2_store->sideband ().details.epoch);
@ -4516,17 +4524,17 @@ TEST (ledger, confirmation_height_not_updated)
auto & store = ctx.store ();
auto transaction = store.tx_begin_write ();
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::account_info account_info;
ASSERT_FALSE (store.account.get (transaction, nano::dev::genesis_key.pub, account_info));
auto account_info = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (account_info);
nano::keypair key;
nano::block_builder builder;
auto send1 = builder
.send ()
.previous (account_info.head)
.previous (account_info->head)
.destination (key.pub)
.balance (50)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*pool.generate (account_info.head))
.work (*pool.generate (account_info->head))
.build ();
nano::confirmation_height_info confirmation_height_info;
ASSERT_FALSE (store.confirmation_height.get (transaction, nano::dev::genesis->account (), confirmation_height_info));

View file

@ -64,10 +64,10 @@ TEST (ledger_walker, genesis_account_longer)
};
auto const transaction = node->ledger.store.tx_begin_read ();
nano::account_info genesis_account_info{};
ASSERT_FALSE (node->ledger.store.account.get (transaction, nano::dev::genesis_key.pub, genesis_account_info));
EXPECT_EQ (get_number_of_walked_blocks (genesis_account_info.open_block), 1);
EXPECT_EQ (get_number_of_walked_blocks (genesis_account_info.head), 1);
auto genesis_account_info = node->ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (genesis_account_info);
EXPECT_EQ (get_number_of_walked_blocks (genesis_account_info->open_block), 1);
EXPECT_EQ (get_number_of_walked_blocks (genesis_account_info->head), 1);
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
for (auto itr = 1; itr <= 5; ++itr)
@ -76,7 +76,7 @@ TEST (ledger_walker, genesis_account_longer)
ASSERT_TRUE (send);
EXPECT_EQ (get_number_of_walked_blocks (send->hash ()), 1 + itr * 2 - 1);
ASSERT_TIMELY (3s, 1 + itr * 2 == node->ledger.cache.cemented_count);
ASSERT_FALSE (node->ledger.store.account.get (transaction, nano::dev::genesis_key.pub, genesis_account_info));
ASSERT_TRUE (node->ledger.account_info (transaction, nano::dev::genesis_key.pub));
// TODO: check issue with account head
// EXPECT_EQ(get_number_of_walked_blocks (genesis_account_info.head), 1 + itr * 2);
}
@ -107,8 +107,8 @@ TEST (ledger_walker, cross_account)
ASSERT_TIMELY (3s, 5 == node->ledger.cache.cemented_count);
auto const transaction = node->ledger.store.tx_begin_read ();
nano::account_info account_info{};
ASSERT_FALSE (node->ledger.store.account.get (transaction, key.pub, account_info));
auto account_info = node->ledger.account_info (transaction, key.pub);
ASSERT_TRUE (account_info);
// TODO: check issue with account head
// auto const first = node->ledger.store.block.get_no_sideband(transaction, account_info.head);
@ -174,9 +174,8 @@ TEST (ledger_walker, DISABLED_ladder_geometry)
}
ASSERT_TRUE (last_destination);
nano::account_info last_destination_info{};
auto const last_destination_read_error = node->ledger.store.account.get (node->ledger.store.tx_begin_read (), *last_destination, last_destination_info);
ASSERT_FALSE (last_destination_read_error);
auto last_destination_info = node->ledger.account_info (node->ledger.store.tx_begin_read (), *last_destination);
ASSERT_TRUE (last_destination_info);
// This is how we expect chains to look like (for 3 accounts and 10 amounts to be sent)
// k1: 1000 SEND 3 SEND 6 SEND 9 SEND
@ -187,7 +186,7 @@ TEST (ledger_walker, DISABLED_ladder_geometry)
auto amounts_expected_backwards_itr = amounts_expected_backwards.cbegin ();
nano::ledger_walker ledger_walker{ node->ledger };
ledger_walker.walk_backward (last_destination_info.head,
ledger_walker.walk_backward (last_destination_info->head,
[&] (auto const & block) {
if (block->sideband ().details.is_receive)
{
@ -206,7 +205,7 @@ TEST (ledger_walker, DISABLED_ladder_geometry)
auto amounts_expected_itr = amounts_expected_backwards.crbegin ();
ledger_walker.walk (last_destination_info.head,
ledger_walker.walk (last_destination_info->head,
[&] (auto const & block) {
if (block->sideband ().details.is_receive)
{

View file

@ -17,17 +17,17 @@ TEST (processor_service, bad_send_signature)
auto transaction (store->tx_begin_write ());
store->initialize (transaction, ledger.cache, ledger.constants);
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::account_info info1;
ASSERT_FALSE (store->account.get (transaction, nano::dev::genesis_key.pub, info1));
auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info1);
nano::keypair key2;
nano::block_builder builder;
auto send = builder
.send ()
.previous (info1.head)
.previous (info1->head)
.destination (nano::dev::genesis_key.pub)
.balance (50)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*pool.generate (info1.head))
.work (*pool.generate (info1->head))
.build ();
send->signature.bytes[32] ^= 0x1;
ASSERT_EQ (nano::process_result::bad_signature, ledger.process (transaction, *send).code);
@ -43,21 +43,21 @@ TEST (processor_service, bad_receive_signature)
auto transaction (store->tx_begin_write ());
store->initialize (transaction, ledger.cache, ledger.constants);
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::account_info info1;
ASSERT_FALSE (store->account.get (transaction, nano::dev::genesis_key.pub, info1));
auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info1);
nano::block_builder builder;
auto send = builder
.send ()
.previous (info1.head)
.previous (info1->head)
.destination (nano::dev::genesis_key.pub)
.balance (50)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*pool.generate (info1.head))
.work (*pool.generate (info1->head))
.build ();
nano::block_hash hash1 (send->hash ());
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, *send).code);
nano::account_info info2;
ASSERT_FALSE (store->account.get (transaction, nano::dev::genesis_key.pub, info2));
auto info2 = ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info2);
auto receive = builder
.receive ()
.previous (hash1)

View file

@ -41,11 +41,8 @@ TEST (system, DISABLED_generate_send_existing)
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
nano::keypair stake_preserver;
auto send_block (system.wallet (0)->send_action (nano::dev::genesis->account (), stake_preserver.pub, nano::dev::constants.genesis_amount / 3 * 2, true));
nano::account_info info1;
{
auto transaction (node1.store.tx_begin_read ());
ASSERT_FALSE (node1.store.account.get (transaction, nano::dev::genesis_key.pub, info1));
}
auto info1 = node1.ledger.account_info (node1.store.tx_begin_read (), nano::dev::genesis_key.pub);
ASSERT_TRUE (info1);
std::vector<nano::account> accounts;
accounts.push_back (nano::dev::genesis_key.pub);
system.generate_send_existing (node1, accounts);
@ -65,24 +62,22 @@ TEST (system, DISABLED_generate_send_existing)
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, *open_block).code);
}
ASSERT_GT (node1.balance (stake_preserver.pub), node1.balance (nano::dev::genesis->account ()));
nano::account_info info2;
{
auto transaction (node1.store.tx_begin_read ());
ASSERT_FALSE (node1.store.account.get (transaction, nano::dev::genesis_key.pub, info2));
}
ASSERT_NE (info1.head, info2.head);
auto info2 = node1.ledger.account_info (node1.store.tx_begin_read (), nano::dev::genesis_key.pub);
ASSERT_TRUE (info2);
ASSERT_NE (info1->head, info2->head);
system.deadline_set (15s);
while (info2.block_count < info1.block_count + 2)
while (info2->block_count < info1->block_count + 2)
{
ASSERT_NO_ERROR (system.poll ());
auto transaction (node1.store.tx_begin_read ());
ASSERT_FALSE (node1.store.account.get (transaction, nano::dev::genesis_key.pub, info2));
info2 = node1.ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info2);
}
ASSERT_EQ (info1.block_count + 2, info2.block_count);
ASSERT_EQ (info2.balance, nano::dev::constants.genesis_amount / 3);
ASSERT_EQ (info1->block_count + 2, info2->block_count);
ASSERT_EQ (info2->balance, nano::dev::constants.genesis_amount / 3);
{
auto transaction (node1.store.tx_begin_read ());
ASSERT_NE (node1.ledger.amount (transaction, info2.head), 0);
ASSERT_NE (node1.ledger.amount (transaction, info2->head), 0);
}
system.stop ();
runner.join ();

View file

@ -180,16 +180,13 @@ TEST (wallet, spend_all_one)
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
nano::keypair key2;
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::dev::genesis_key.pub, key2.pub, std::numeric_limits<nano::uint128_t>::max ()));
nano::account_info info2;
{
auto transaction (node1.store.tx_begin_read ());
node1.store.account.get (transaction, nano::dev::genesis_key.pub, info2);
ASSERT_NE (latest1, info2.head);
auto block (node1.store.block.get (transaction, info2.head));
ASSERT_NE (nullptr, block);
ASSERT_EQ (latest1, block->previous ());
}
ASSERT_TRUE (info2.balance.is_zero ());
auto transaction (node1.store.tx_begin_read ());
auto info2 = node1.ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_NE (latest1, info2->head);
auto block (node1.store.block.get (transaction, info2->head));
ASSERT_NE (nullptr, block);
ASSERT_EQ (latest1, block->previous ());
ASSERT_TRUE (info2->balance.is_zero ());
ASSERT_EQ (0, node1.balance (nano::dev::genesis_key.pub));
}
@ -217,16 +214,14 @@ TEST (wallet, spend)
// Sending from empty accounts should always be an error. Accounts need to be opened with an open block, not a send block.
ASSERT_EQ (nullptr, system.wallet (0)->send_action (0, key2.pub, 0));
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::dev::genesis_key.pub, key2.pub, std::numeric_limits<nano::uint128_t>::max ()));
nano::account_info info2;
{
auto transaction (node1.store.tx_begin_read ());
node1.store.account.get (transaction, nano::dev::genesis_key.pub, info2);
ASSERT_NE (latest1, info2.head);
auto block (node1.store.block.get (transaction, info2.head));
ASSERT_NE (nullptr, block);
ASSERT_EQ (latest1, block->previous ());
}
ASSERT_TRUE (info2.balance.is_zero ());
auto transaction (node1.store.tx_begin_read ());
auto info2 = node1.ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info2);
ASSERT_NE (latest1, info2->head);
auto block (node1.store.block.get (transaction, info2->head));
ASSERT_NE (nullptr, block);
ASSERT_EQ (latest1, block->previous ());
ASSERT_TRUE (info2->balance.is_zero ());
ASSERT_EQ (0, node1.balance (nano::dev::genesis_key.pub));
}
@ -258,8 +253,8 @@ TEST (wallet, spend_no_previous)
{
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
auto transaction (system.nodes[0]->store.tx_begin_read ());
nano::account_info info1;
ASSERT_FALSE (system.nodes[0]->store.account.get (transaction, nano::dev::genesis_key.pub, info1));
auto info1 = system.nodes[0]->ledger.account_info (transaction, nano::dev::genesis_key.pub);
ASSERT_TRUE (info1);
for (auto i (0); i < 50; ++i)
{
nano::keypair key;

View file

@ -4400,10 +4400,11 @@ void nano::json_handler::wallet_info ()
{
nano::account const & account (i->first);
nano::account_info account_info{};
if (!node.store.account.get (block_transaction, account, account_info))
auto account_info = node.ledger.account_info (block_transaction, account);
if (account_info)
{
block_count += account_info.block_count;
block_count += account_info->block_count;
balance += account_info->balance.number ();
}
nano::confirmation_height_info confirmation_info{};
@ -4412,7 +4413,6 @@ void nano::json_handler::wallet_info ()
cemented_block_count += confirmation_info.height;
}
balance += account_info.balance.number ();
receivable += node.ledger.account_receivable (block_transaction, account);
nano::key_type key_type (wallet->store.key_type (i->second));
@ -4637,11 +4637,11 @@ void nano::json_handler::wallet_history ()
for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i)
{
nano::account const & account (i->first);
nano::account_info info;
if (!node.store.account.get (block_transaction, account, info))
auto info = node.ledger.account_info (block_transaction, account);
if (info)
{
auto timestamp (info.modified);
auto hash (info.head);
auto timestamp (info->modified);
auto hash (info->head);
while (timestamp >= modified_since && !hash.is_zero ())
{
auto block (node.store.block.get (block_transaction, hash));
@ -4711,23 +4711,23 @@ void nano::json_handler::wallet_ledger ()
for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i)
{
nano::account const & account (i->first);
nano::account_info info;
if (!node.store.account.get (block_transaction, account, info))
auto info = node.ledger.account_info (block_transaction, account);
if (info)
{
if (info.modified >= modified_since)
if (info->modified >= modified_since)
{
boost::property_tree::ptree entry;
entry.put ("frontier", info.head.to_string ());
entry.put ("open_block", info.open_block.to_string ());
entry.put ("representative_block", node.ledger.representative (block_transaction, info.head).to_string ());
entry.put ("frontier", info->head.to_string ());
entry.put ("open_block", info->open_block.to_string ());
entry.put ("representative_block", node.ledger.representative (block_transaction, info->head).to_string ());
std::string balance;
nano::uint128_union (info.balance).encode_dec (balance);
nano::uint128_union (info->balance).encode_dec (balance);
entry.put ("balance", balance);
entry.put ("modified_timestamp", std::to_string (info.modified));
entry.put ("block_count", std::to_string (info.block_count));
entry.put ("modified_timestamp", std::to_string (info->modified));
entry.put ("block_count", std::to_string (info->block_count));
if (representative)
{
entry.put ("representative", info.representative.to_account ());
entry.put ("representative", info->representative.to_account ());
}
if (weight)
{
@ -4877,10 +4877,10 @@ void nano::json_handler::wallet_representative_set ()
for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i)
{
nano::account const & account (i->first);
nano::account_info info;
if (!rpc_l->node.store.account.get (block_transaction, account, info))
auto info = rpc_l->node.ledger.account_info (block_transaction, account);
if (info)
{
if (info.representative != representative)
if (info->representative != representative)
{
accounts.push_back (account);
}

View file

@ -7195,9 +7195,9 @@ TEST (rpc, receive)
{
auto response (wait_response (system, rpc_ctx, request));
auto receive_text (response.get<std::string> ("block"));
nano::account_info info;
ASSERT_FALSE (node->store.account.get (node->store.tx_begin_read (), key1.pub, info));
ASSERT_EQ (info.head, nano::block_hash{ receive_text });
auto info = node->ledger.account_info (node->store.tx_begin_read (), key1.pub);
ASSERT_TRUE (info);
ASSERT_EQ (info->head, nano::block_hash{ receive_text });
}
// Trying to receive the same block should fail with unreceivable
{
@ -7236,11 +7236,11 @@ TEST (rpc, receive_unopened)
{
auto response (wait_response (system, rpc_ctx, request));
auto receive_text (response.get<std::string> ("block"));
nano::account_info info;
ASSERT_FALSE (node->store.account.get (node->store.tx_begin_read (), key1.pub, info));
ASSERT_EQ (info.head, info.open_block);
ASSERT_EQ (info.head.to_string (), receive_text);
ASSERT_EQ (info.representative, nano::dev::genesis_key.pub);
auto info = node->ledger.account_info (node->store.tx_begin_read (), key1.pub);
ASSERT_TRUE (info);
ASSERT_EQ (info->head, info->open_block);
ASSERT_EQ (info->head.to_string (), receive_text);
ASSERT_EQ (info->representative, nano::dev::genesis_key.pub);
}
rpc_ctx.io_scope->reset ();
@ -7260,11 +7260,11 @@ TEST (rpc, receive_unopened)
{
auto response (wait_response (system, rpc_ctx, request));
auto receive_text (response.get<std::string> ("block"));
nano::account_info info;
ASSERT_FALSE (node->store.account.get (node->store.tx_begin_read (), key2.pub, info));
ASSERT_EQ (info.head, info.open_block);
ASSERT_EQ (info.head.to_string (), receive_text);
ASSERT_EQ (info.representative, rep);
auto info = node->ledger.account_info (node->store.tx_begin_read (), key2.pub);
ASSERT_TRUE (info);
ASSERT_EQ (info->head, info->open_block);
ASSERT_EQ (info->head.to_string (), receive_text);
ASSERT_EQ (info->representative, rep);
}
}
@ -7345,9 +7345,9 @@ TEST (rpc, receive_pruned)
{
auto response (wait_response (system, rpc_ctx, request));
auto receive_text (response.get<std::string> ("block"));
nano::account_info info;
ASSERT_FALSE (node2->store.account.get (node2->store.tx_begin_read (), key1.pub, info));
ASSERT_EQ (info.head, nano::block_hash{ receive_text });
auto info = node2->ledger.account_info (node2->store.tx_begin_read (), key1.pub);
ASSERT_TRUE (info);
ASSERT_EQ (info->head, nano::block_hash{ receive_text });
}
// Trying to receive the same block should fail with unreceivable
{

View file

@ -583,9 +583,8 @@ void ledger_processor::receive_block (nano::receive_block & block_a)
#ifdef NDEBUG
if (ledger.store.block.exists (transaction, block_a.hashables.source))
{
nano::account_info source_info;
[[maybe_unused]] auto error (ledger.store.account.get (transaction, pending.source, source_info));
debug_assert (!error);
auto info = ledger.account_info (transaction, pending.source);
debug_assert (info);
}
#endif
ledger.store.pending.del (transaction, key);
@ -1290,10 +1289,10 @@ std::shared_ptr<nano::block> nano::ledger::successor (nano::transaction const &
auto get_from_previous = false;
if (root_a.previous ().is_zero ())
{
nano::account_info info;
if (!store.account.get (transaction_a, root_a.root ().as_account (), info))
auto info = account_info (transaction_a, root_a.root ().as_account ());
if (info)
{
successor = info.open_block;
successor = info->open_block;
}
else
{

View file

@ -32,7 +32,7 @@ public:
* Return account containing hash, expects that block hash exists in ledger
*/
nano::account account (nano::transaction const &, nano::block_hash const &) const;
std::optional<nano::account_info> account_info (nano::transaction const & transaction, nano::account const & account) const;
std::optional<nano::account_info> account_info (nano::transaction const & transaction, nano::account const & account) const;
/**
* For non-prunning nodes same as `ledger::account()`
* For prunning nodes ensures that block hash exists, otherwise returns zero account