daemon: sort alt chains by height

This commit is contained in:
moneromooo-monero 2019-05-02 22:23:00 +00:00
parent c0bc6d96cd
commit 0605406714
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
5 changed files with 9 additions and 7 deletions

View file

@ -1861,7 +1861,9 @@ bool t_rpc_command_executor::alt_chain_info(const std::string &tip)
if (tip.empty())
{
tools::msg_writer() << boost::lexical_cast<std::string>(res.chains.size()) << " alternate chains found:";
for (const auto &chain: res.chains)
auto chains = res.chains;
std::sort(chains.begin(), chains.end(), [](const cryptonote::COMMAND_RPC_GET_ALTERNATE_CHAINS::chain_info &info0, cryptonote::COMMAND_RPC_GET_ALTERNATE_CHAINS::chain_info &info1){ return info0.height < info1.height; });
for (const auto &chain: chains)
{
uint64_t start_height = (chain.height - chain.length + 1);
tools::msg_writer() << chain.length << " blocks long, from height " << start_height << " (" << (ires.height - start_height - 1)