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

Fix potential div-by-zero issue in receive_frontier #1629

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion nano/node/bootstrap.cpp
Expand Up @@ -294,7 +294,7 @@ void nano::frontier_req_client::received_frontier (boost::system::error_code con
++count;
std::chrono::duration<double> time_span = std::chrono::duration_cast<std::chrono::duration<double>> (std::chrono::steady_clock::now () - start_time);
double elapsed_sec = time_span.count ();
double blocks_per_sec = (double)count / elapsed_sec;
double blocks_per_sec = elapsed_sec > 0.0 ? (static_cast<double> (count) / elapsed_sec) : 0.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since a divide by zero case would go toward infinity instead of toward zero, should we pick a minimum value for elapsed seconds? Perhaps a typical timeslice preemption interval, 20ms or 50ms if I recall?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed an updated and, gave bootstrap_client::block_rate the same treatment. Is that in line with your idea? If so, maybe we should factor out a utility function for this.

if (elapsed_sec > bootstrap_connection_warmup_time_sec && blocks_per_sec < bootstrap_minimum_frontier_blocks_per_sec)
{
BOOST_LOG (connection->node->log) << boost::str (boost::format ("Aborting frontier req because it was too slow"));
Expand Down