From fe35fd6da5a11c0c490b757227cfe6df5d848dce Mon Sep 17 00:00:00 2001 From: "Dani (Sergey) K" Date: Fri, 25 Oct 2024 17:12:16 +0100 Subject: [PATCH] Update pruned blocks detection in QT GUI history --- nano/qt/qt.cpp | 73 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index 201299bc97..1120103e52 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -585,44 +585,69 @@ class short_text_visitor : public nano::block_visitor { auto balance (block_a.hashables.balance.number ()); auto previous_balance = ledger.any.block_balance (transaction, block_a.hashables.previous); - if (!block_a.hashables.previous.is_zero () && !previous_balance) + // Error to receive previous block balance means that previous block was pruned from the ledger + if ((!previous_balance && block_a.sideband ().details.is_send) || balance < previous_balance.value ().number ()) { - type = "Unknown (pruned)"; + type = "Send"; + account = block_a.hashables.link.as_account (); + if (!previous_balance) + { + type = "Send (pruned)"; + amount = 0; + } + else + { + amount = previous_balance.value ().number () - balance; + } + } + else if (block_a.hashables.link.is_zero ()) + { + debug_assert (!block_a.sideband ().details.is_send && !block_a.sideband ().details.is_receive && !block_a.sideband ().details.is_epoch); + type = "Change"; + account = block_a.hashables.representative; amount = 0; - account = block_a.hashables.account; + if (!previous_balance) + { + type = "Change (pruned)"; + } + else + { + debug_assert (balance == previous_balance); + } } - else if (balance < previous_balance.value ().number ()) + else if (ledger.is_epoch_link (block_a.hashables.link) && block_a.sideband ().details.is_epoch) { - type = "Send"; - amount = previous_balance.value ().number () - balance; - account = block_a.hashables.link.as_account (); + debug_assert (!previous_balance || balance == previous_balance); + type = "Epoch"; + amount = 0; + if (!previous_balance) + { + type = "Epoch (pruned)"; + } + account = ledger.epoch_signer (block_a.hashables.link); } else { - if (block_a.hashables.link.is_zero ()) + debug_assert (block_a.sideband ().details.is_receive); + type = "Receive"; + auto account_l = ledger.any.block_account (transaction, block_a.hashables.link.as_block_hash ()); + if (!account_l) + { + type = "Receive (pruned sender)"; + } + else { - type = "Change"; - account = block_a.hashables.representative; + account = account_l.value (); } - else if (balance == previous_balance && ledger.is_epoch_link (block_a.hashables.link)) + if (!previous_balance) { - type = "Epoch"; - account = ledger.epoch_signer (block_a.hashables.link); + type = "Receive (pruned)"; + amount = 0; } else { - type = "Receive"; - auto account_l = ledger.any.block_account (transaction, block_a.hashables.link.as_block_hash ()); - if (!account_l) - { - type = "Receive (pruned)"; - } - else - { - account = account_l.value (); - } + amount = balance - previous_balance.value ().number (); } - amount = balance - previous_balance.value ().number (); } } nano::secure::transaction const & transaction;