From ee33436500a747e41ec20dc34e54ffd3fa46334c Mon Sep 17 00:00:00 2001 From: Christian Despres Date: Thu, 4 Dec 2025 15:51:55 -0500 Subject: [PATCH 1/2] Disable total currency in frontier visualization The total_currency computation that is run in display_attached_mask here will foldi over a mask to compute the total balance of the default token. This causes every account in the ledger represented by that mask to be read; since most of those will be in the ledger database on disk, this is essentially equivalent to a full database read. This full read can take a few seconds to complete (for current devnet and depending on hardware). This problem is compounded by the fact that display_attached_mask will be run for every mask in the frontier when computing its visualization. For a daemon synced to a network, that's at least 290 iterations of this function, and likely more. This endeds up causing the daemon to "hang" during shutdown if stopped with ctrl-c on the command line; what it's really doing is slowly going through the ledger over and over again to compute this total currency value in order to save the transition frontier visualization to disk. The change here eliminates this particular shutdown bug by temporarily disabling this part of the visualization. --- src/lib/merkle_mask/maskable_merkle_tree.ml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/lib/merkle_mask/maskable_merkle_tree.ml b/src/lib/merkle_mask/maskable_merkle_tree.ml index b7bd32cc3eaf..c2b4332b5228 100644 --- a/src/lib/merkle_mask/maskable_merkle_tree.ml +++ b/src/lib/merkle_mask/maskable_merkle_tree.ml @@ -53,13 +53,20 @@ module Make (Inputs : Inputs_intf) = struct let display_attached_mask mask = let root_hash = Mask.Attached.merkle_root mask in let num_accounts = Mask.Attached.num_accounts mask in - let total_currency = - Mask.Attached.foldi mask ~init:0 ~f:(fun _ total_currency account -> - (* only default token matters for total currency *) - if Token_id.equal (Account.token account) Token_id.default then - total_currency + (Balance.to_int @@ Account.balance account) - else total_currency ) - in + (* This total_currency computation is temporarily disabled - it causes the + frontier mask visualization that happens at shutdown to be + exceptionally slow. See #17501 and #18196, though if we decide we + really need this then we could also consider optionally caching the + total_currency in ledger masks, and then recomputing the currency + change each mask would cause in the ledger. *) + (* let total_currency = + Mask.Attached.foldi mask ~init:0 ~f:(fun _ total_currency account -> + (* only default token matters for total currency *) + if Token_id.equal (Account.token account) Token_id.default then + total_currency + (Balance.to_int @@ Account.balance account) + else total_currency ) + in *) + let total_currency = 0 in let uuid = format_uuid mask in { hash = Visualization.display_prefix_of_string From 023d218904d43166a6a03948b962208dbbd3eba1 Mon Sep 17 00:00:00 2001 From: Christian Despres Date: Thu, 4 Dec 2025 16:15:23 -0500 Subject: [PATCH 2/2] Add changelog for 18197 --- changes/18197.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changes/18197.md diff --git a/changes/18197.md b/changes/18197.md new file mode 100644 index 000000000000..06b789b39cb0 --- /dev/null +++ b/changes/18197.md @@ -0,0 +1,5 @@ +Fix a bug that causes the daemon to freeze when shut down with a signal like +SIGINT or SIGTERM, and not with `mina client stop`. The frontier visualization +debug diagram that is written at shutdown will now display a total_currency of 0 +for every mask. This functionality will be restored when the efficiency of the +underlying operation is improved.