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

Add uncemented frontier output CLI command #2777

Merged
merged 13 commits into from
Sep 11, 2020
Merged
17 changes: 17 additions & 0 deletions nano/nano_node/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ int main (int argc, char * const * argv)
("debug_cemented_block_count", "Displays the number of cemented (confirmed) blocks")
("debug_stacktrace", "Display an example stacktrace")
("debug_account_versions", "Display the total counts of each version for all accounts (including unpocketed)")
("debug_unconfirmed_frontiers", "Displays the account, height (sorted), cemented frontier and frontier for the account")
("validate_blocks,debug_validate_blocks", "Check all blocks for correct hash, signature, work value")
("platform", boost::program_options::value<std::string> (), "Defines the <platform> for OpenCL commands")
("device", boost::program_options::value<std::string> (), "Defines <device> for OpenCL command")
Expand Down Expand Up @@ -1934,6 +1935,22 @@ int main (int argc, char * const * argv)
output_account_version_number (i, unopened_account_version_totals[i]);
}
}
else if (vm.count ("debug_unconfirmed_frontiers"))
{
auto inactive_node = nano::default_inactive_node (data_path, vm);
auto node = inactive_node->node;

auto unconfirmed_frontiers = node->ledger.unconfirmed_frontiers ();
std::cout << "Account: Height delta | Frontier | Confirmed frontier\n";
for (auto & unconfirmed_frontier : unconfirmed_frontiers)
{
auto const & unconfirmed_info = unconfirmed_frontier.second;

std::cout << (boost::format ("%1%: %2% %3% %4%\n") % unconfirmed_info.account.to_account () % unconfirmed_frontier.first % unconfirmed_info.frontier.to_string () % unconfirmed_info.cemented_frontier.to_string ()).str ();
}

std::cout << "\nNumber of unconfirmed frontiers: " << unconfirmed_frontiers.size () << std::endl;
}
else if (vm.count ("version"))
{
std::cout << "Version " << NANO_VERSION_STRING << "\n"
Expand Down
42 changes: 42 additions & 0 deletions nano/secure/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,48 @@ bool nano::ledger::block_not_confirmed_or_not_exists (nano::block const & block_
return result;
}

std::multimap<uint64_t, nano::uncemented_info, std::greater<>> nano::ledger::unconfirmed_frontiers () const
{
std::multimap<uint64_t, nano::uncemented_info, std::greater<>> unconfirmed_frontiers_l;
auto transaction (store.tx_begin_read ());
auto conf_height_i = store.confirmation_height_begin (transaction);

for (auto i (store.latest_begin (transaction)), n (store.latest_end ()); i != n; ++i)
{
// If the confirmation height of an account doesn't exist the iterator will point 1 past it.
auto conf_height_info = conf_height_i->second;
auto const & account (i->first);
auto conf_height_exists = (conf_height_i->first == account);
if (!conf_height_exists)
{
conf_height_info.height = 0;
conf_height_info.frontier = 0;
}

auto const & account_info (i->second);
if (account_info.block_count != conf_height_info.height)
{
// Always output as no confirmation height has been set on the account yet
auto height_delta = account_info.block_count - conf_height_info.height;
auto const & frontier = account_info.head;
auto const & cemented_frontier = conf_height_info.frontier;
unconfirmed_frontiers_l.emplace (std::piecewise_construct, std::forward_as_tuple (height_delta), std::forward_as_tuple (cemented_frontier, frontier, i->first));
}

if (conf_height_exists)
{
// Increment the iterator so that it stays in sync with accounts in the account table.
++conf_height_i;
}
}
return unconfirmed_frontiers_l;
}

nano::uncemented_info::uncemented_info (nano::block_hash const & cemented_frontier, nano::block_hash const & frontier, nano::account const & account) :
cemented_frontier (cemented_frontier), frontier (frontier), account (account)
{
}

std::unique_ptr<nano::container_info_component> nano::collect_container_info (ledger & ledger, const std::string & name)
{
auto count = ledger.bootstrap_weights_size.load ();
Expand Down
11 changes: 11 additions & 0 deletions nano/secure/ledger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ class stat;
class write_transaction;

using tally_t = std::map<nano::uint128_t, std::shared_ptr<nano::block>, std::greater<nano::uint128_t>>;

class uncemented_info
{
public:
uncemented_info (nano::block_hash const & cemented_frontier, nano::block_hash const & frontier, nano::account const & account);
nano::block_hash cemented_frontier;
nano::block_hash frontier;
nano::account account;
};

class ledger final
{
public:
Expand Down Expand Up @@ -49,6 +59,7 @@ class ledger final
std::array<nano::block_hash, 2> dependent_blocks (nano::transaction const &, nano::block const &);
nano::account const & epoch_signer (nano::link const &) const;
nano::link const & epoch_link (nano::epoch) const;
std::multimap<uint64_t, uncemented_info, std::greater<>> unconfirmed_frontiers () const;
static nano::uint128_t const unit;
nano::network_params network_params;
nano::block_store & store;
Expand Down