Remove active blocks from *_pending RPC calls

This commit is contained in:
Lee Bousfield 2018-08-05 10:52:26 -06:00 committed by clemahieu
commit 06501b1925
2 changed files with 66 additions and 39 deletions

View file

@ -2335,6 +2335,13 @@ TEST (rpc, accounts_pending)
rai::keypair key1;
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
auto block1 (system.wallet (0)->send_action (rai::test_genesis_key.pub, key1.pub, 100));
auto iterations (0);
while (system.nodes[0]->active.active (*block1))
{
system.poll ();
++iterations;
ASSERT_LT (iterations, 200);
}
rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true));
rpc.start ();
boost::property_tree::ptree request;
@ -2541,6 +2548,13 @@ TEST (rpc, wallet_pending)
system0.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
system0.wallet (0)->insert_adhoc (key1.prv);
auto block1 (system0.wallet (0)->send_action (rai::test_genesis_key.pub, key1.pub, 100));
auto iterations (0);
while (system0.nodes[0]->active.active (*block1))
{
system0.poll ();
++iterations;
ASSERT_LT (iterations, 200);
}
rai::rpc rpc (system0.service, *system0.nodes[0], rai::rpc_config (true));
rpc.start ();
boost::property_tree::ptree request;
@ -2553,6 +2567,7 @@ TEST (rpc, wallet_pending)
system0.poll ();
}
ASSERT_EQ (200, response.status);
ASSERT_EQ (1, response.json.get_child ("blocks").size ());
for (auto & pending : response.json.get_child ("blocks"))
{
std::string account_text (pending.first);
@ -2568,6 +2583,7 @@ TEST (rpc, wallet_pending)
}
ASSERT_EQ (200, response0.status);
std::unordered_map<rai::block_hash, rai::uint128_union> blocks;
ASSERT_EQ (1, response0.json.get_child ("blocks").size ());
for (auto & pending : response0.json.get_child ("blocks"))
{
std::string account_text (pending.first);
@ -2606,6 +2622,7 @@ TEST (rpc, wallet_pending)
ASSERT_EQ (200, response2.status);
std::unordered_map<rai::block_hash, rai::uint128_union> amounts;
std::unordered_map<rai::block_hash, rai::account> sources;
ASSERT_EQ (1, response0.json.get_child ("blocks").size ());
for (auto & pending : response2.json.get_child ("blocks"))
{
std::string account_text (pending.first);

View file

@ -769,27 +769,32 @@ void rai::rpc_handler::accounts_pending ()
for (auto i (node.store.pending_begin (transaction, rai::pending_key (account, 0))), n (node.store.pending_begin (transaction, rai::pending_key (end, 0))); i != n && peers_l.size () < count; ++i)
{
rai::pending_key key (i->first);
if (threshold.is_zero () && !source)
std::shared_ptr<rai::block> block (node.store.block_get (transaction, key.hash));
assert (block);
if (block && !node.active.active (*block))
{
boost::property_tree::ptree entry;
entry.put ("", key.hash.to_string ());
peers_l.push_back (std::make_pair ("", entry));
}
else
{
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 (threshold.is_zero () && !source)
{
if (source)
boost::property_tree::ptree entry;
entry.put ("", key.hash.to_string ());
peers_l.push_back (std::make_pair ("", entry));
}
else
{
rai::pending_info info (i->second, i->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0);
if (info.amount.number () >= threshold.number ())
{
boost::property_tree::ptree pending_tree;
pending_tree.put ("amount", info.amount.number ().convert_to<std::string> ());
pending_tree.put ("source", info.source.to_account ());
peers_l.add_child (key.hash.to_string (), pending_tree);
}
else
{
peers_l.put (key.hash.to_string (), info.amount.number ().convert_to<std::string> ());
if (source)
{
boost::property_tree::ptree pending_tree;
pending_tree.put ("amount", info.amount.number ().convert_to<std::string> ());
pending_tree.put ("source", info.source.to_account ());
peers_l.add_child (key.hash.to_string (), pending_tree);
}
else
{
peers_l.put (key.hash.to_string (), info.amount.number ().convert_to<std::string> ());
}
}
}
}
@ -3123,34 +3128,39 @@ void rai::rpc_handler::wallet_pending ()
for (auto ii (node.store.pending_begin (transaction, rai::pending_key (account, 0))), nn (node.store.pending_begin (transaction, rai::pending_key (end, 0))); ii != nn && peers_l.size () < count; ++ii)
{
rai::pending_key key (ii->first);
if (threshold.is_zero () && !source)
std::shared_ptr<rai::block> block (node.store.block_get (transaction, key.hash));
assert (block);
if (block && !node.active.active (*block))
{
boost::property_tree::ptree entry;
entry.put ("", key.hash.to_string ());
peers_l.push_back (std::make_pair ("", entry));
}
else
{
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 (threshold.is_zero () && !source)
{
if (source || min_version)
boost::property_tree::ptree entry;
entry.put ("", key.hash.to_string ());
peers_l.push_back (std::make_pair ("", entry));
}
else
{
rai::pending_info info (ii->second, ii->from_secondary_store ? rai::epoch::epoch_1 : rai::epoch::epoch_0);
if (info.amount.number () >= threshold.number ())
{
boost::property_tree::ptree pending_tree;
pending_tree.put ("amount", info.amount.number ().convert_to<std::string> ());
if (source)
if (source || min_version)
{
pending_tree.put ("source", info.source.to_account ());
boost::property_tree::ptree pending_tree;
pending_tree.put ("amount", info.amount.number ().convert_to<std::string> ());
if (source)
{
pending_tree.put ("source", info.source.to_account ());
}
if (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);
}
if (min_version)
else
{
pending_tree.put ("min_version", info.epoch == rai::epoch::epoch_1 ? "1" : "0");
peers_l.put (key.hash.to_string (), info.amount.number ().convert_to<std::string> ());
}
peers_l.add_child (key.hash.to_string (), pending_tree);
}
else
{
peers_l.put (key.hash.to_string (), info.amount.number ().convert_to<std::string> ());
}
}
}