Prevent possible issues with ledger contaning pending rcords only for burn account (#2502)

This commit is contained in:
Sergey Kroshnin 2020-01-22 19:31:26 +03:00 committed by GitHub
commit 0822f38033
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 5 deletions

View file

@ -833,7 +833,7 @@ void nano::json_handler::accounts_pending ()
if (!ec)
{
boost::property_tree::ptree peers_l;
for (auto i (node.store.pending_begin (transaction, nano::pending_key (account, 0))); nano::pending_key (i->first).account == account && peers_l.size () < count; ++i)
for (auto i (node.store.pending_begin (transaction, nano::pending_key (account, 0))), n (node.store.pending_end ()); i != n && nano::pending_key (i->first).account == account && peers_l.size () < count; ++i)
{
nano::pending_key const & key (i->first);
if (block_confirmed (node, transaction, key.hash, include_active, include_only_confirmed))
@ -2912,7 +2912,7 @@ void nano::json_handler::pending ()
{
boost::property_tree::ptree peers_l;
auto transaction (node.store.tx_begin_read ());
for (auto i (node.store.pending_begin (transaction, nano::pending_key (account, 0))); nano::pending_key (i->first).account == account && peers_l.size () < count; ++i)
for (auto i (node.store.pending_begin (transaction, nano::pending_key (account, 0))), n (node.store.pending_end ()); i != n && nano::pending_key (i->first).account == account && peers_l.size () < count; ++i)
{
nano::pending_key const & key (i->first);
if (block_confirmed (node, transaction, key.hash, include_active, include_only_confirmed))
@ -4548,7 +4548,7 @@ void nano::json_handler::wallet_pending ()
{
nano::account const & account (i->first);
boost::property_tree::ptree peers_l;
for (auto ii (node.store.pending_begin (block_transaction, nano::pending_key (account, 0))); nano::pending_key (ii->first).account == account && peers_l.size () < count; ++ii)
for (auto ii (node.store.pending_begin (block_transaction, nano::pending_key (account, 0))), nn (node.store.pending_end ()); ii != nn && nano::pending_key (ii->first).account == account && peers_l.size () < count; ++ii)
{
nano::pending_key key (ii->first);
if (block_confirmed (node, block_transaction, key.hash, include_active, include_only_confirmed))

View file

@ -1253,7 +1253,7 @@ bool nano::wallet::search_pending ()
// Don't search pending for watch-only accounts
if (!nano::wallet_value (i->second).key.is_zero ())
{
for (auto j (wallets.node.store.pending_begin (block_transaction, nano::pending_key (account, 0))); nano::pending_key (j->first).account == account; ++j)
for (auto j (wallets.node.store.pending_begin (block_transaction, nano::pending_key (account, 0))), k (wallets.node.store.pending_end ()); j != k && nano::pending_key (j->first).account == account; ++j)
{
nano::pending_key key (j->first);
auto hash (key.hash);
@ -1318,7 +1318,7 @@ uint32_t nano::wallet::deterministic_check (nano::transaction const & transactio
else
{
// Check if there are pending blocks for account
for (auto ii (wallets.node.store.pending_begin (block_transaction, nano::pending_key (pair.pub, 0))); nano::pending_key (ii->first).account == pair.pub; ++ii)
for (auto ii (wallets.node.store.pending_begin (block_transaction, nano::pending_key (pair.pub, 0))), nn (wallets.node.store.pending_end ()); ii != nn && nano::pending_key (ii->first).account == pair.pub; ++ii)
{
index = i;
n = i + 64 + (i / 64);

View file

@ -2672,6 +2672,45 @@ TEST (rpc, pending)
check_block_response_count (0);
}
TEST (rpc, pending_burn)
{
nano::system system;
auto node = add_ipc_enabled_node (system);
nano::account burn (0);
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
auto block1 (system.wallet (0)->send_action (nano::test_genesis_key.pub, burn, 100));
scoped_io_thread_name_change scoped_thread_name_io;
system.deadline_set (5s);
while (node->active.active (*block1))
{
ASSERT_NO_ERROR (system.poll ());
}
nano::node_rpc_config node_rpc_config;
nano::ipc::ipc_server ipc_server (*node, node_rpc_config);
nano::rpc_config rpc_config (nano::get_available_port (), true);
rpc_config.rpc_process.ipc_port = node->config.ipc_config.transport_tcp.port;
nano::ipc_rpc_processor ipc_rpc_processor (system.io_ctx, rpc_config);
nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor);
rpc.start ();
boost::property_tree::ptree request;
request.put ("action", "pending");
request.put ("account", burn.to_account ());
request.put ("count", "100");
{
test_response response (request, rpc.config.port, system.io_ctx);
system.deadline_set (5s);
while (response.status == 0)
{
ASSERT_NO_ERROR (system.poll ());
}
ASSERT_EQ (200, response.status);
auto & blocks_node (response.json.get_child ("blocks"));
ASSERT_EQ (1, blocks_node.size ());
nano::block_hash hash (blocks_node.begin ()->second.get<std::string> (""));
ASSERT_EQ (block1->hash (), hash);
}
}
TEST (rpc, search_pending)
{
nano::system system;