From d9b8593ad12f19c48006d72aa71b1abd223184ea Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Mon, 2 Sep 2024 20:59:23 +0100 Subject: [PATCH 1/5] Fix issue where unchecked_map::entries was being accessed for container information without acquiring the entries_mutex. --- nano/node/unchecked_map.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/nano/node/unchecked_map.cpp b/nano/node/unchecked_map.cpp index 88e3cdb9..9430f97e 100644 --- a/nano/node/unchecked_map.cpp +++ b/nano/node/unchecked_map.cpp @@ -168,10 +168,14 @@ void nano::unchecked_map::query_impl (nano::block_hash const & hash) std::unique_ptr nano::unchecked_map::collect_container_info (const std::string & name) { - nano::lock_guard lock{ mutex }; - auto composite = std::make_unique (name); - composite->add_component (std::make_unique (container_info{ "entries", entries.size (), sizeof (decltype (entries)::value_type) })); - composite->add_component (std::make_unique (container_info{ "queries", buffer.size (), sizeof (decltype (buffer)::value_type) })); + { + std::lock_guard guard{ entries_mutex }; + composite->add_component (std::make_unique (container_info{ "entries", entries.size (), sizeof (decltype (entries)::value_type) })); + } + { + nano::lock_guard lock{ mutex }; + composite->add_component (std::make_unique (container_info{ "queries", buffer.size (), sizeof (decltype (buffer)::value_type) })); + } return composite; } From be53f611a7421bbe0bbfee50f865d2b9bac0e06c Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Tue, 3 Sep 2024 01:27:39 +0100 Subject: [PATCH 2/5] Add sanity check --- nano/node/active_elections.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/nano/node/active_elections.cpp b/nano/node/active_elections.cpp index 8cb16c1e..bef80ca3 100644 --- a/nano/node/active_elections.cpp +++ b/nano/node/active_elections.cpp @@ -506,6 +506,7 @@ bool nano::active_elections::erase (nano::qualified_root const & root_a) auto root_it (roots.get ().find (root_a)); if (root_it != roots.get ().end ()) { + release_assert (root_it->election->qualified_root == root_a); cleanup_election (lock, root_it->election); return true; } From ebea02d94ae2a99bdac86df2f052a4053abb87d1 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Tue, 3 Sep 2024 01:43:28 +0100 Subject: [PATCH 3/5] Remove this_thread::sleep_for and instead use condition_variable::wait. Fixes checking whether the component is stopped. --- nano/node/confirming_set.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nano/node/confirming_set.cpp b/nano/node/confirming_set.cpp index 9a8f436e..49f6daff 100644 --- a/nano/node/confirming_set.cpp +++ b/nano/node/confirming_set.cpp @@ -132,11 +132,15 @@ void nano::confirming_set::run_batch (std::unique_lock & lock) notification.cemented.swap (cemented); notification.already_cemented.swap (already); - // Wait for the worker thread if too many notifications are queued + std::unique_lock lock{ mutex }; while (notification_workers.num_queued_tasks () >= config.max_queued_notifications) { stats.inc (nano::stat::type::confirming_set, nano::stat::detail::cooldown); - std::this_thread::sleep_for (100ms); + condition.wait_for (lock, 100ms, [this] { return stopped; }); + if (stopped) + { + return; + } } notification_workers.push_task ([this, notification = std::move (notification)] () { From d4ff55bff7582c57cfa62fa4c522dd47d81ff015 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Tue, 3 Sep 2024 18:23:07 +0100 Subject: [PATCH 4/5] Fix negative-wraparound issue when converting size_t to ptrdiff_t which is used by std::views::take. This issue was flagged by VisualStudio debug asserts --- nano/node/repcrawler.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nano/node/repcrawler.cpp b/nano/node/repcrawler.cpp index f6cca66b..debb30cd 100644 --- a/nano/node/repcrawler.cpp +++ b/nano/node/repcrawler.cpp @@ -452,8 +452,9 @@ std::vector nano::rep_crawler::representatives (std::size_ } std::vector result; - for (auto const & [weight, rep] : ordered | std::views::take (count)) + for (auto i = ordered.begin (), n = ordered.end (); i != n && result.size () < count; ++i) { + auto const & [weight, rep] = *i; result.push_back ({ rep.account, rep.channel }); } return result; From aae52f6ac2e616a2cbb723607867d4b2a67af5f6 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 4 Sep 2024 03:23:47 +0100 Subject: [PATCH 5/5] Silence some TSAN errors --- tsan_suppressions | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tsan_suppressions b/tsan_suppressions index e08006ce..3936f8fa 100644 --- a/tsan_suppressions +++ b/tsan_suppressions @@ -2,3 +2,5 @@ race:mdb.c race:rocksdb race:Rijndael::Base::FillEncTable race:Rijndael::Base::FillDecTable +race:CryptoPP::Rijndael +race:boost::asio::detail::conditionally_enabled_mutex::scoped_lock::scoped_lock