From 134298ca77b48c4f3c85a57b19cac5dda3c62405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Fri, 18 Apr 2025 00:25:37 +0200 Subject: [PATCH 1/2] Improve monitor logging --- nano/node/monitor.cpp | 56 +++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/nano/node/monitor.cpp b/nano/node/monitor.cpp index 44ce038bb..563414048 100644 --- a/nano/node/monitor.cpp +++ b/nano/node/monitor.cpp @@ -64,46 +64,48 @@ void nano::monitor::run_one () // - election stats over last 5m (confirmed, dropped) auto const now = std::chrono::steady_clock::now (); + auto blocks_cemented = node.ledger.cemented_count (); auto blocks_total = node.ledger.block_count (); - // Wait for node to warm up before logging + // TODO: Maybe emphasize somehow that confirmed doesn't need to be equal to total; backlog is OK + logger.info (nano::log::type::monitor, "Blocks confirmed: {} | total: {} (backlog: {})", + blocks_cemented, + blocks_total, + blocks_total - blocks_cemented); + + // Wait for node to warm up before logging rates if (last_time != std::chrono::steady_clock::time_point{}) { - // TODO: Maybe emphasize somehow that confirmed doesn't need to be equal to total; backlog is OK - logger.info (nano::log::type::monitor, "Blocks confirmed: {} | total: {}", - blocks_cemented, - blocks_total); - // Calculate the rates auto elapsed_seconds = std::chrono::duration_cast (now - last_time).count (); auto blocks_confirmed_rate = static_cast (blocks_cemented - last_blocks_cemented) / elapsed_seconds; auto blocks_checked_rate = static_cast (blocks_total - last_blocks_total) / elapsed_seconds; - logger.info (nano::log::type::monitor, "Blocks rate (average over last {}s): confirmed {:.2f}/s | total {:.2f}/s", + logger.info (nano::log::type::monitor, "Blocks rate (avg over {}s): confirmed {:.2f}/s | total {:.2f}/s", elapsed_seconds, blocks_confirmed_rate, blocks_checked_rate); - - logger.info (nano::log::type::monitor, "Peers: {} (realtime: {} | bootstrap: {} | inbound connections: {} | outbound connections: {})", - node.network.size (), - node.tcp_listener.realtime_count (), - node.tcp_listener.bootstrap_count (), - node.tcp_listener.connection_count (nano::transport::tcp_listener::connection_type::inbound), - node.tcp_listener.connection_count (nano::transport::tcp_listener::connection_type::outbound)); - - logger.info (nano::log::type::monitor, "Quorum: {} (stake peered: {} | stake online: {})", - nano::uint128_union{ node.online_reps.delta () }.format_balance (nano_ratio, 1, true), - nano::uint128_union{ node.rep_crawler.total_weight () }.format_balance (nano_ratio, 1, true), - nano::uint128_union{ node.online_reps.online () }.format_balance (nano_ratio, 1, true)); - - logger.info (nano::log::type::monitor, "Elections active: {} (priority: {} | hinted: {} | optimistic: {})", - node.active.size (), - node.active.size (nano::election_behavior::priority), - node.active.size (nano::election_behavior::hinted), - node.active.size (nano::election_behavior::optimistic)); } + logger.info (nano::log::type::monitor, "Peers: {} (realtime: {} | bootstrap: {}) (inbound: {} | outbound: {})", + node.network.size (), + node.tcp_listener.realtime_count (), + node.tcp_listener.bootstrap_count (), + node.tcp_listener.connection_count (nano::transport::tcp_listener::connection_type::inbound), + node.tcp_listener.connection_count (nano::transport::tcp_listener::connection_type::outbound)); + + logger.info (nano::log::type::monitor, "Quorum: {} (stake peered: {} | stake online: {})", + nano::uint128_union{ node.online_reps.delta () }.format_balance (nano_ratio, 1, true), + nano::uint128_union{ node.rep_crawler.total_weight () }.format_balance (nano_ratio, 1, true), + nano::uint128_union{ node.online_reps.online () }.format_balance (nano_ratio, 1, true)); + + logger.info (nano::log::type::monitor, "Elections active: {} (priority: {} | hinted: {} | optimistic: {})", + node.active.size (), + node.active.size (nano::election_behavior::priority), + node.active.size (nano::election_behavior::hinted), + node.active.size (nano::election_behavior::optimistic)); + last_time = now; last_blocks_cemented = blocks_cemented; last_blocks_total = blocks_total; @@ -124,9 +126,7 @@ nano::error nano::monitor_config::serialize (nano::tomlconfig & toml) const nano::error nano::monitor_config::deserialize (nano::tomlconfig & toml) { toml.get ("enable", enable); - auto interval_l = interval.count (); - toml.get ("interval", interval_l); - interval = std::chrono::seconds{ interval_l }; + toml.get_duration ("interval", interval); return toml.get_error (); } \ No newline at end of file From 92ca481915828f3d3bcd38652f51fa711df8db96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Fri, 18 Apr 2025 00:40:59 +0200 Subject: [PATCH 2/2] Improve assertion logging --- nano/core_test/assert.cpp | 4 ++-- nano/lib/assert.cpp | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/nano/core_test/assert.cpp b/nano/core_test/assert.cpp index 32a40a300..0a49a595c 100644 --- a/nano/core_test/assert.cpp +++ b/nano/core_test/assert.cpp @@ -5,11 +5,11 @@ TEST (assert_DeathTest, debug_assert) { debug_assert (true); - ASSERT_DEATH (debug_assert (false), ".*Assertion \\(false\\) failed.*"); + ASSERT_DEATH (debug_assert (false, "test"), ".*Assertion `false` failed: test.*"); } TEST (assert_DeathTest, release_assert) { release_assert (true); - ASSERT_DEATH (release_assert (false), ".*Assertion \\(false\\) failed.*"); + ASSERT_DEATH (release_assert (false, "test"), ".*Assertion `false` failed: test.*"); } \ No newline at end of file diff --git a/nano/lib/assert.cpp b/nano/lib/assert.cpp index 0a607b3dc..e93221fb4 100644 --- a/nano/lib/assert.cpp +++ b/nano/lib/assert.cpp @@ -14,11 +14,12 @@ void assert_internal (char const * check_expr, char const * func, char const * file, unsigned int line, bool is_release_assert, std::string_view error_msg) { std::stringstream ss; - ss << "Assertion (" << check_expr << ") failed"; + ss << "Assertion `" << check_expr << "` failed"; if (!error_msg.empty ()) { - ss << ": " << error_msg << "\n"; + ss << ": " << error_msg; } + ss << "\n"; ss << file << ":" << line << " [" << func << "]" << "'\n";