Merging block work validity checks in to an early-return pattern.

This commit is contained in:
clemahieu 2022-07-11 20:18:42 +01:00
commit f12f5d54fb
No known key found for this signature in database
GPG key ID: 43708520C8DFB938
2 changed files with 22 additions and 20 deletions

View file

@ -208,8 +208,17 @@ void nano::bulk_pull_client::received_block (boost::system::error_code const & e
{ {
nano::bufferstream stream (connection->receive_buffer->data (), size_a); nano::bufferstream stream (connection->receive_buffer->data (), size_a);
auto block (nano::deserialize_block (stream, type_a)); auto block (nano::deserialize_block (stream, type_a));
if (block != nullptr && !connection->node->network_params.work.validate_entry (*block)) if (block != nullptr)
{ {
if (connection->node->network_params.work.validate_entry (*block))
{
if (connection->node->config.logging.bulk_pull_logging ())
{
connection->node->logger.try_log (boost::str (boost::format ("Insufficient work for bulk pull block: %1%") % block->hash ().to_string ()));
}
connection->node->stats.inc_detail_only (nano::stat::type::error, nano::stat::detail::insufficient_work);
return;
}
auto hash (block->hash ()); auto hash (block->hash ());
if (connection->node->config.logging.bulk_pull_logging ()) if (connection->node->config.logging.bulk_pull_logging ())
{ {
@ -256,7 +265,7 @@ void nano::bulk_pull_client::received_block (boost::system::error_code const & e
connection->connections.pool_connection (connection); connection->connections.pool_connection (connection);
} }
} }
else if (block == nullptr) else
{ {
if (connection->node->config.logging.bulk_pull_logging ()) if (connection->node->config.logging.bulk_pull_logging ())
{ {
@ -264,14 +273,6 @@ void nano::bulk_pull_client::received_block (boost::system::error_code const & e
} }
connection->node->stats.inc (nano::stat::type::bootstrap, nano::stat::detail::bulk_pull_deserialize_receive_block, nano::stat::dir::in); connection->node->stats.inc (nano::stat::type::bootstrap, nano::stat::detail::bulk_pull_deserialize_receive_block, nano::stat::dir::in);
} }
else // Work invalid
{
if (connection->node->config.logging.bulk_pull_logging ())
{
connection->node->logger.try_log (boost::str (boost::format ("Insufficient work for bulk pull block: %1%") % block->hash ().to_string ()));
}
connection->node->stats.inc_detail_only (nano::stat::type::error, nano::stat::detail::insufficient_work);
}
} }
else else
{ {

View file

@ -233,25 +233,26 @@ void nano::bulk_push_server::received_block (boost::system::error_code const & e
{ {
nano::bufferstream stream (receive_buffer->data (), size_a); nano::bufferstream stream (receive_buffer->data (), size_a);
auto block (nano::deserialize_block (stream, type_a)); auto block (nano::deserialize_block (stream, type_a));
if (block != nullptr && !connection->node->network_params.work.validate_entry (*block)) if (block != nullptr)
{ {
if (connection->node->network_params.work.validate_entry (*block))
{
if (connection->node->config.logging.bulk_pull_logging ())
{
connection->node->logger.try_log (boost::str (boost::format ("Insufficient work for bulk push block: %1%") % block->hash ().to_string ()));
}
connection->node->stats.inc_detail_only (nano::stat::type::error, nano::stat::detail::insufficient_work);
return;
}
connection->node->process_active (std::move (block)); connection->node->process_active (std::move (block));
throttled_receive (); throttled_receive ();
} }
else if (block == nullptr) else
{ {
if (connection->node->config.logging.bulk_pull_logging ()) if (connection->node->config.logging.bulk_pull_logging ())
{ {
connection->node->logger.try_log ("Error deserializing block received from pull request"); connection->node->logger.try_log ("Error deserializing block received from pull request");
} }
} }
else // Work invalid
{
if (connection->node->config.logging.bulk_pull_logging ())
{
connection->node->logger.try_log (boost::str (boost::format ("Insufficient work for bulk push block: %1%") % block->hash ().to_string ()));
}
connection->node->stats.inc_detail_only (nano::stat::type::error, nano::stat::detail::insufficient_work);
}
} }
} }