From 550b2777fd2217f2ea0fbdd68e3d81f42b220715 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Thu, 22 Nov 2018 10:48:25 +0100 Subject: [PATCH 1/8] Merge #14715: Drop defunct prevector compat handling 69ca48717ceb31e37e90276278362c809cf98cc6 Implement prevector::fill once (Ben Woosley) 7bad78c2c83d73b7e0518f3e1b835f0157b80ec6 Drop defunct IS_TRIVIALLY_CONSTRUCTIBLE handling from prevector.h (Ben Woosley) Pull request description: This is clean-up post #14651: * Use one implementation of `prevector::fill`, as it's possible now that the implementations are identical. * Only apply the `IS_TRIVIALLY_CONSTRUCTIBLE` handling to the bench file where it is used, and drop the now-unnecessary associated compat includes. Tree-SHA512: 5930b3a17fccd39af10add40202ad97a297aebecc049af72ca920d0d55b3e4c3c30ce864c8a683355895f0196396d4ea56ba9f9637bdc7d16964cdf66c195485 --- src/bench/prevector.cpp | 8 ++++++++ src/compat.h | 10 ---------- src/prevector.h | 12 +++--------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/bench/prevector.cpp b/src/bench/prevector.cpp index 7cf58c51dda2..4aeab6c57203 100644 --- a/src/bench/prevector.cpp +++ b/src/bench/prevector.cpp @@ -10,6 +10,14 @@ #include +// GCC 4.8 is missing some C++11 type_traits, +// https://www.gnu.org/software/gcc/gcc-5/changes.html +#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 5 +#define IS_TRIVIALLY_CONSTRUCTIBLE std::has_trivial_default_constructor +#else +#define IS_TRIVIALLY_CONSTRUCTIBLE std::is_trivially_default_constructible +#endif + struct nontrivial_t { int x; nontrivial_t() :x(-1) {} diff --git a/src/compat.h b/src/compat.h index d6bd5bfabba1..813e0babb133 100644 --- a/src/compat.h +++ b/src/compat.h @@ -10,16 +10,6 @@ #include #endif -#include - -// GCC 4.8 is missing some C++11 type_traits, -// https://www.gnu.org/software/gcc/gcc-5/changes.html -#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 5 -#define IS_TRIVIALLY_CONSTRUCTIBLE std::has_trivial_default_constructor -#else -#define IS_TRIVIALLY_CONSTRUCTIBLE std::is_trivially_default_constructible -#endif - #ifdef WIN32 #ifdef _WIN32_WINNT #undef _WIN32_WINNT diff --git a/src/prevector.h b/src/prevector.h index 8c45738d94c3..5b9cd0dfb3ea 100644 --- a/src/prevector.h +++ b/src/prevector.h @@ -15,8 +15,6 @@ #include #include -#include - /** Implements a drop-in replacement for std::vector which stores up to N * elements directly (without heap allocation). The types Size and Diff are * used to store element counts, and can be any unsigned + signed type. @@ -203,11 +201,7 @@ class prevector { T* item_ptr(difference_type pos) { return is_direct() ? direct_ptr(pos) : indirect_ptr(pos); } const T* item_ptr(difference_type pos) const { return is_direct() ? direct_ptr(pos) : indirect_ptr(pos); } - void fill(T* dst, ptrdiff_t count) { - std::fill_n(dst, count, T{}); - } - - void fill(T* dst, ptrdiff_t count, const T& value) { + void fill(T* dst, ptrdiff_t count, const T& value = T{}) { std::fill_n(dst, count, value); } @@ -226,7 +220,7 @@ class prevector { } void fill(T* dst, const T* src, ptrdiff_t count) { - if (IS_TRIVIALLY_CONSTRUCTIBLE::value) { + if (std::is_trivially_constructible::value) { ::memmove(dst, src, count * sizeof(T)); } else { for (ptrdiff_t i = 0; i < count; i++) { @@ -560,7 +554,7 @@ class prevector { static void assign_to(const_iterator b, const_iterator e, V& v) { // We know that internally the iterators are pointing to continues memory, so we can directly use the pointers here // This avoids internal use of std::copy and operator++ on the iterators and instead allows efficient memcpy/memmove - if (IS_TRIVIALLY_CONSTRUCTIBLE::value) { + if (std::is_trivially_constructible::value) { auto s = e - b; if (v.size() != s) { v.resize(s); From e447c4e0cd10ce50be89ce7e5b0688e198d01f20 Mon Sep 17 00:00:00 2001 From: fanquake Date: Mon, 30 Nov 2020 15:45:37 +0800 Subject: [PATCH 2/8] Partial Merge #20491: refactor: Drop noop gcc version checks 830ddf413934226d0b6ca99165916790cc52ca18 Drop noop gcc version checks (Hennadii Stepanov) Pull request description: Since #20413 the minimum required GCC version is 7. ACKs for top commit: fanquake: ACK 830ddf413934226d0b6ca99165916790cc52ca18 Tree-SHA512: 36264661d6ced1683a0c907efba7c700502acaf8e9fd50d9066bc9c7b877b25165b0684c2d7fe74bd58e500a77d7702bdbdd53691c274f29e4abccd241c10964 --- src/bench/prevector.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/bench/prevector.cpp b/src/bench/prevector.cpp index 4aeab6c57203..5075312fe9ae 100644 --- a/src/bench/prevector.cpp +++ b/src/bench/prevector.cpp @@ -10,14 +10,6 @@ #include -// GCC 4.8 is missing some C++11 type_traits, -// https://www.gnu.org/software/gcc/gcc-5/changes.html -#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 5 -#define IS_TRIVIALLY_CONSTRUCTIBLE std::has_trivial_default_constructor -#else -#define IS_TRIVIALLY_CONSTRUCTIBLE std::is_trivially_default_constructible -#endif - struct nontrivial_t { int x; nontrivial_t() :x(-1) {} @@ -25,11 +17,11 @@ struct nontrivial_t { }; typedef prevector<28, unsigned char> prevec; -static_assert(!IS_TRIVIALLY_CONSTRUCTIBLE::value, +static_assert(!std::is_trivially_default_constructible::value, "expected nontrivial_t to not be trivially constructible"); typedef unsigned char trivial_t; -static_assert(IS_TRIVIALLY_CONSTRUCTIBLE::value, +static_assert(std::is_trivially_default_constructible::value, "expected trivial_t to be trivially constructible"); template From 33a38b84defae8844231471ce506eab7a1cd74d1 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 16 Jan 2019 12:37:53 +0100 Subject: [PATCH 3/8] Merge #15136: qt: "Peers" tab overhaul 3537c8345c788a527bb4e1d00683ca7f8ee5fb1a Do not deselect peer when switching away from tab (Hennadii Stepanov) b0037c51909dc55e279baa81f063c169c9735105 Improve Peers tab layout (Hennadii Stepanov) Pull request description: This is an alternative to #14798. The "Peers" tab of the "Debug" window improved to address comments https://github.com/bitcoin/bitcoin/pull/6209#issuecomment-108072605 (by @jonasschnelli) and https://github.com/bitcoin/bitcoin/pull/14798#issuecomment-441618268 (by @promag). This allows to keep the peer selection while navigating to other places and effectively reverts e0597268116cf90d961abeba9d14aaad0ab682d2. Screenshots with this PR: ![screenshot from 2019-01-09 22-01-36](https://user-images.githubusercontent.com/32963518/50927352-2e6fb700-1460-11e9-9173-582348210492.png) ![screenshot from 2019-01-09 22-02-11](https://user-images.githubusercontent.com/32963518/50927354-329bd480-1460-11e9-9926-d0eb0f026a35.png) ![screenshot from 2019-01-09 22-02-37](https://user-images.githubusercontent.com/32963518/50927358-3596c500-1460-11e9-864d-c8704451f3d9.png) Tree-SHA512: 3d086007f6d72930bc2fc3c395175adda0f1a7722de3842bc246ee4f3bfc5ebda4b9a626fb68a7ee8663a88d0842deb37c0c460ad84cc58e22f138acf8bc71ea --- src/qt/forms/debugwindow.ui | 1219 ++++++++++++++++++----------------- src/qt/rpcconsole.cpp | 5 +- 2 files changed, 623 insertions(+), 601 deletions(-) diff --git a/src/qt/forms/debugwindow.ui b/src/qt/forms/debugwindow.ui index e8f275b3f588..03d6466f77ac 100644 --- a/src/qt/forms/debugwindow.ui +++ b/src/qt/forms/debugwindow.ui @@ -763,606 +763,629 @@ - - - - - 0 - - - - - Qt::ScrollBarAsNeeded - - - false - - - true - - - false - - - - - - - - 0 - 0 - - - - - 300 - 32 - - - - - 16777215 - 32 - - - - IBeamCursor - - - Banned peers - - - Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft - - - true - - - Qt::NoTextInteraction - - - - - - - - 0 - 0 - - - - Qt::ScrollBarAsNeeded - - - false - - - true - - - false - - - - - - - - - - 0 - 0 - - - - - 300 - 32 - - - - IBeamCursor - - - Select a peer to view detailed information. - - - Qt::AlignCenter - - - true - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + Qt::Horizontal - - - - - - - 300 - 0 - + + false - - - - - Node Type - - - - - - - IBeamCursor - - - N/A - - - Qt::PlainText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - PoSe Score - - - - - - - IBeamCursor - - - N/A - - - Qt::PlainText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Whitelisted - - - - - - - IBeamCursor - - - N/A - - - Qt::PlainText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Direction - - - - - - - IBeamCursor - - - N/A - - - Qt::PlainText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Version - - - - - - - IBeamCursor - - - N/A - - - Qt::PlainText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - User Agent - - - - - - - IBeamCursor - - - N/A - - - Qt::PlainText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Services - - - - - - - IBeamCursor - - - N/A - - - Qt::PlainText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Starting Block - - - - - - - IBeamCursor - - - N/A - - - Qt::PlainText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Synced Headers - - - - - - - IBeamCursor - - - N/A - - - Qt::PlainText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Synced Blocks - - - - - - - IBeamCursor - - - N/A - - - Qt::PlainText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Ban Score - - - - - - - IBeamCursor - - - N/A - - - Qt::PlainText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Connection Time - - - - - - - IBeamCursor - - - N/A - - - Qt::PlainText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Last Send - - - - - - - IBeamCursor - - - N/A - - - Qt::PlainText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Last Receive - - - - - - - IBeamCursor - - - N/A - - - Qt::PlainText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Sent - - - - - - - IBeamCursor - - - N/A - - - Qt::PlainText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Received - - - - - - - IBeamCursor - - - N/A - - - Qt::PlainText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Ping Time - - - - - - - IBeamCursor - - - N/A - - - Qt::PlainText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - The duration of a currently outstanding ping. - - - Ping Wait - - - - - - - IBeamCursor - - - N/A - - - Qt::PlainText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Min Ping - - - - - - - IBeamCursor - - - N/A - - - Qt::PlainText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Time Offset - - - - - - - IBeamCursor - - - N/A - - - Qt::PlainText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - + + + + 1 + 0 + + + + + 400 + 0 + + + + + + + false + + + true + + + false + + + + + + + + 0 + 0 + + + + + 0 + 32 + + + + + 16777215 + 32 + + + + IBeamCursor + + + Banned peers + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + true + + + Qt::NoTextInteraction + + + + + + + false + + + true + + + false + + + + + + + + + 0 + 0 + + + + + 300 + 0 + + + + + + + + 0 + 0 + + + + + 0 + 32 + + + + IBeamCursor + + + Select a peer to view detailed information. + + + Qt::AlignCenter + + + true + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + true + + + + + 0 + 0 + 300 + 426 + + + + + 300 + 0 + + + + + + + Node Type + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + PoSe Score + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + Whitelisted + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + Direction + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + Version + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + User Agent + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + Services + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + Starting Block + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + Synced Headers + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + Synced Blocks + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + Ban Score + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + Connection Time + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + Last Send + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + Last Receive + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + Sent + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + Received + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + Ping Time + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + The duration of a currently outstanding ping. + + + Ping Wait + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + Min Ping + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + Time Offset + + + + + + + IBeamCursor + + + N/A + + + Qt::PlainText + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + + diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 0520eaaf7ec5..9b65509eaf46 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -1133,10 +1133,9 @@ void RPCConsole::startExecutor() void RPCConsole::on_stackedWidgetRPC_currentChanged(int index) { - if (ui->stackedWidgetRPC->widget(index) == ui->pageConsole) + if (ui->stackedWidgetRPC->widget(index) == ui->pageConsole) { ui->lineEdit->setFocus(); - else if (ui->stackedWidgetRPC->widget(index) != ui->pagePeers) - clearSelectedNode(); + } } void RPCConsole::on_openDebugLogfileButton_clicked() From 8caf2f002f9727b040126f05ed612459f20a6ec8 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 15 Jan 2019 15:13:18 +0100 Subject: [PATCH 4/8] Merge #14594: qt: Fix minimized window bug on Linux a88640e123ca0c00d81719f9a009699c26e85b90 Fix minimized window bug on Linux (Hennadii Stepanov) Pull request description: Fix #14591 On some Linux systems the minimized to the taskbar (iconified) main window cannot be restored properly using actions from the systray icon menu when `QSystemTrayIcon::contextMenu()` is a child of the main window. Tree-SHA512: 05c9f724fc2278d45dac6fe72b09859f12b5d71f54659bb779403c8cd81b55e610fb7b5aa912ac273d3cd19bf953b0405bbc6451feb00d1827c95dd9f0876aa4 --- src/qt/bitcoingui.cpp | 11 +++++++---- src/qt/bitcoingui.h | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 70e7bbb139e7..9a528507a4db 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -37,6 +37,7 @@ #include #include +#include #include #include @@ -46,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -55,6 +57,7 @@ #include #include #include +#include #include #include #include @@ -76,7 +79,8 @@ const std::string BitcoinGUI::DEFAULT_UIPLATFORM = BitcoinGUI::BitcoinGUI(interfaces::Node& node, const NetworkStyle* networkStyle, QWidget* parent) : QMainWindow(parent), m_node(node), - m_network_style(networkStyle) + m_network_style(networkStyle), + trayIconMenu{new QMenu()} { GUIUtil::loadTheme(true); @@ -692,9 +696,8 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel) // while the client has not yet fully loaded if (trayIcon) { // do so only if trayIcon is already set - trayIconMenu = new QMenu(this); - trayIcon->setContextMenu(trayIconMenu); - createIconMenu(trayIconMenu); + trayIcon->setContextMenu(trayIconMenu.get()); + createIconMenu(trayIconMenu.get()); #ifndef Q_OS_MAC // Show main window on tray icon click diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 28b5d7590543..e946f58b445a 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -47,6 +46,7 @@ QT_BEGIN_NAMESPACE class QAction; class QButtonGroup; class QComboBox; +class QMenu; class QProgressBar; class QProgressDialog; class QToolButton; @@ -165,7 +165,7 @@ class BitcoinGUI : public QMainWindow QComboBox* m_wallet_selector = nullptr; QSystemTrayIcon* trayIcon = nullptr; - QMenu* trayIconMenu = nullptr; + const std::unique_ptr trayIconMenu; QMenu* dockIconMenu = nullptr; Notificator* notificator = nullptr; RPCConsole* rpcConsole = nullptr; From 5fb15a98aaa7ba26dc900d39cacf49b9ce86f8f2 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 15 Jan 2019 17:25:14 +0100 Subject: [PATCH 5/8] Merge #14556: qt: fix confirmed transaction labeled "open" (#13299) fb3ce75807c50055a97f573fc72bf44d997ea218 Don't label transactions "Open" while catching up (Hennadii Stepanov) Pull request description: Fix #13299. Since the default `nSequence` is `0xFFFFFFFE` and locktime is enabled, the checking `wtx.is_final` is meaningless until the syncing has completed (ref: #1026). This PR makes the wallet mark a transaction "Unconfirmed" instead of misleading "Open for NNN more blocks" when syncing after a period of being offline. Before this PR (with the issue): ![screenshot from 2018-12-12 15-56-23](https://user-images.githubusercontent.com/32963518/49874288-cdd06880-fe26-11e8-8441-f3ceb479611b.png) With this PR (the issue has been resolved): ![screenshot from 2018-12-12 15-54-41](https://user-images.githubusercontent.com/32963518/49874336-e9d40a00-fe26-11e8-8c05-9aeee2eb1bba.png) Tree-SHA512: 358ec83b43c266a4d32a37a79dda80e80d40a2b77ad38261c84a095e613399f674aa7184805b3f6310e51ddb83ae2636b8849fcc7c4333e1b3ecbb0f70ad86d3 --- src/chain.h | 10 ++++++++-- src/interfaces/wallet.cpp | 4 +++- src/interfaces/wallet.h | 3 ++- src/qt/bitcoingui.cpp | 11 ++++------- src/qt/transactionrecord.cpp | 11 ++++++----- src/qt/transactionrecord.h | 2 +- src/qt/transactiontablemodel.cpp | 5 +++-- 7 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/chain.h b/src/chain.h index f9558f26743b..7e3c6ce68db5 100644 --- a/src/chain.h +++ b/src/chain.h @@ -19,7 +19,7 @@ * Maximum amount of time that a block timestamp is allowed to exceed the * current network-adjusted time before the block will be accepted. */ -static const int64_t MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60; +static constexpr int64_t MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60; /** * Timestamp window used as a grace period by code that compares external @@ -27,7 +27,13 @@ static const int64_t MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60; * to block timestamps. This should be set at least as high as * MAX_FUTURE_BLOCK_TIME. */ -static const int64_t TIMESTAMP_WINDOW = MAX_FUTURE_BLOCK_TIME; +static constexpr int64_t TIMESTAMP_WINDOW = MAX_FUTURE_BLOCK_TIME; + +/** + * Maximum gap between node time and block time used + * for the "Catching up..." mode in GUI. + */ +static constexpr int64_t MAX_BLOCK_TIME_GAP = 25 * 60; class CBlockFileInfo { diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp index 5077cbf710a6..2e345ec88cb1 100644 --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -343,7 +343,8 @@ class WalletImpl : public Wallet return result; } bool tryGetTxStatus(const uint256& txid, - interfaces::WalletTxStatus& tx_status) override + interfaces::WalletTxStatus& tx_status, + int64_t& block_time) override { TRY_LOCK(::cs_main, locked_chain); if (!locked_chain) { @@ -358,6 +359,7 @@ class WalletImpl : public Wallet return false; } tx_status = MakeWalletTxStatus(mi->second); + block_time = ::chainActive.Tip()->GetBlockTime(); return true; } WalletTx getWalletTxDetails(const uint256& txid, diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h index 94a75df56377..7c88fd4ce4a2 100644 --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -183,7 +183,8 @@ class Wallet //! Try to get updated status for a particular transaction, if possible without blocking. virtual bool tryGetTxStatus(const uint256& txid, - WalletTxStatus& tx_status) = 0; + WalletTxStatus& tx_status, + int64_t& block_time) = 0; //! Get transaction details. virtual WalletTx getWalletTxDetails(const uint256& txid, diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 9a528507a4db..bb982547a303 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -29,6 +29,7 @@ #include #endif +#include #include #include #include @@ -1321,16 +1322,12 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, const QStri // Set icon state: spinning if catching up, tick otherwise #ifdef ENABLE_WALLET - if (walletFrame) - { - if(secs < 25*60) // 90*60 in bitcoin - { + if (walletFrame) { + if(secs < MAX_BLOCK_TIME_GAP) { modalOverlay->showHide(true, true); // TODO instead of hiding it forever, we should add meaningful information about MN sync to the overlay modalOverlay->hideForever(); - } - else - { + } else { modalOverlay->showHide(); } } diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index 6d7384fad5ee..07a469cb5590 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -5,6 +5,7 @@ #include +#include #include #include #include @@ -13,6 +14,7 @@ #include +#include /* Return positive answer if transaction should be shown in list. */ @@ -252,7 +254,7 @@ QList TransactionRecord::decomposeTransaction(interfaces::Wal return parts; } -void TransactionRecord::updateStatus(const interfaces::WalletTxStatus& wtx, int numBlocks, int chainLockHeight) +void TransactionRecord::updateStatus(const interfaces::WalletTxStatus& wtx, int numBlocks, int chainLockHeight, int64_t block_time) { // Determine transaction status @@ -269,10 +271,9 @@ void TransactionRecord::updateStatus(const interfaces::WalletTxStatus& wtx, int status.lockedByChainLocks = wtx.is_chainlocked; status.lockedByInstantSend = wtx.is_islocked; - if (!wtx.is_final) - { - if (wtx.lock_time < LOCKTIME_THRESHOLD) - { + const bool up_to_date = ((int64_t)QDateTime::currentMSecsSinceEpoch() / 1000 - block_time < MAX_BLOCK_TIME_GAP); + if (up_to_date && !wtx.is_final) { + if (wtx.lock_time < LOCKTIME_THRESHOLD) { status.status = TransactionStatus::OpenUntilBlock; status.open_for = wtx.lock_time - numBlocks; } diff --git a/src/qt/transactionrecord.h b/src/qt/transactionrecord.h index f66452e6bd90..a84eb3fff83e 100644 --- a/src/qt/transactionrecord.h +++ b/src/qt/transactionrecord.h @@ -161,7 +161,7 @@ class TransactionRecord /** Update status from core wallet tx. */ - void updateStatus(const interfaces::WalletTxStatus& wtx, int numBlocks, int chainLockHeight); + void updateStatus(const interfaces::WalletTxStatus& wtx, int numBlocks, int chainLockHeight, int64_t block_time); /** Return whether a status update is needed. */ diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index c3d07c761a38..2b09ce2f6ca4 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -199,8 +199,9 @@ class TransactionTablePriv // try to update the status of this transaction from the wallet. // Otherwise, simply re-use the cached status. interfaces::WalletTxStatus wtx; - if (rec->statusUpdateNeeded(numBlocks, parent->getChainLockHeight()) && wallet.tryGetTxStatus(rec->hash, wtx)) { - rec->updateStatus(wtx, numBlocks, parent->getChainLockHeight()); + int64_t block_time; + if (rec->statusUpdateNeeded(numBlocks, parent->getChainLockHeight()) && wallet.tryGetTxStatus(rec->hash, wtx, block_time)) { + rec->updateStatus(wtx, numBlocks, parent->getChainLockHeight(), block_time); } return rec; } From 52318c950f7d4c0bc4c89794f47c44639a6032a7 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Fri, 8 Mar 2019 15:26:15 +0100 Subject: [PATCH 6/8] Merge #15532: Remove sharp edge (uninit member) when using the compiler-generated ctor for BlockFilter 82c3b3f8e07f0572327275841333256fa3e679e3 Remove sharp edge (uninitialized m_filter_type) when using the compiler-generated constructor for BlockFilter (practicalswift) Pull request description: Remove sharp edge (uninitialised member `m_filter_type`) when using the compiler-generated constructor for `BlockFilter`. Before (but after added test): ``` $ src/test/test_bitcoin -t blockfilter_tests/blockfilter_basic_test Running 1 test case... test/blockfilter_tests.cpp(118): error: in "blockfilter_tests/blockfilter_basic_test": check default_ctor_block_filter_1.GetFilterType() == default_ctor_block_filter_2.GetFilterType() has failed [ != ] *** 1 failure is detected in the test module "Bitcoin Test Suite" ``` After: ``` $ src/test/test_bitcoin -t blockfilter_tests/blockfilter_basic_test Running 1 test case... *** No errors detected ``` Tree-SHA512: 21d41f036b0bf12adcf1a788d84747353f2023cb85fd8ea6c97222967032e8bf54e7910cadb45dfcecd78e5b5dca86685f78cad0596b6d1a08f910ebf20d90aa --- src/blockfilter.cpp | 2 ++ src/blockfilter.h | 5 +++-- src/test/blockfilter_tests.cpp | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/blockfilter.cpp b/src/blockfilter.cpp index 92079493ffe9..5a260a04cdda 100644 --- a/src/blockfilter.cpp +++ b/src/blockfilter.cpp @@ -309,6 +309,8 @@ bool BlockFilter::BuildParams(GCSFilter::Params& params) const params.m_P = BASIC_FILTER_P; params.m_M = BASIC_FILTER_M; return true; + case BlockFilterType::INVALID: + return false; } return false; diff --git a/src/blockfilter.h b/src/blockfilter.h index 0510c7e001c7..28c833502935 100644 --- a/src/blockfilter.h +++ b/src/blockfilter.h @@ -85,9 +85,10 @@ class GCSFilter constexpr uint8_t BASIC_FILTER_P = 19; constexpr uint32_t BASIC_FILTER_M = 784931; -enum BlockFilterType : uint8_t +enum class BlockFilterType : uint8_t { BASIC_FILTER = 0, + INVALID = 255, }; /** Get the human-readable name for a filter type. Returns empty string for unknown types. */ @@ -109,7 +110,7 @@ const std::string& ListBlockFilterTypes(); class BlockFilter { private: - BlockFilterType m_filter_type; + BlockFilterType m_filter_type = BlockFilterType::INVALID; uint256 m_block_hash; GCSFilter m_filter; diff --git a/src/test/blockfilter_tests.cpp b/src/test/blockfilter_tests.cpp index e63ee858ca0d..edcb46ae3f6e 100644 --- a/src/test/blockfilter_tests.cpp +++ b/src/test/blockfilter_tests.cpp @@ -117,6 +117,12 @@ BOOST_AUTO_TEST_CASE(blockfilter_basic_test) BOOST_CHECK_EQUAL(block_filter.GetFilterType(), block_filter2.GetFilterType()); BOOST_CHECK_EQUAL(block_filter.GetBlockHash(), block_filter2.GetBlockHash()); BOOST_CHECK(block_filter.GetEncodedFilter() == block_filter2.GetEncodedFilter()); + + BlockFilter default_ctor_block_filter_1; + BlockFilter default_ctor_block_filter_2; + BOOST_CHECK_EQUAL(default_ctor_block_filter_1.GetFilterType(), default_ctor_block_filter_2.GetFilterType()); + BOOST_CHECK_EQUAL(default_ctor_block_filter_1.GetBlockHash(), default_ctor_block_filter_2.GetBlockHash()); + BOOST_CHECK(default_ctor_block_filter_1.GetEncodedFilter() == default_ctor_block_filter_2.GetEncodedFilter()); } BOOST_AUTO_TEST_CASE(blockfilters_json_test) From f43b8216b150aee66bcd591a05272c75fe4b7367 Mon Sep 17 00:00:00 2001 From: MeshCollider Date: Wed, 10 Apr 2019 00:21:35 +1200 Subject: [PATCH 7/8] Merge #15747: wallet: Remove plethora of Get*Balance fa57411fc wallet: Get all balances in one call (MarcoFalke) Pull request description: The wallet provides a getter for each "type" of balance. However, a single iteration over `mapWallet` is sufficient to calculate all types of balances. ACKs for commit fa5741: Empact: utACK https://github.com/bitcoin/bitcoin/pull/15747/commits/fa57411fcba00556ba25d45bca53cc04623da051 promag: utACK fa57411. MeshCollider: utACK https://github.com/bitcoin/bitcoin/pull/15747/commits/fa57411fcba00556ba25d45bca53cc04623da051 Tree-SHA512: 38b7f346ec95d2604a4d32f4caef2841b8fe59511d2d23890ba3dc497bb2f45eb6be87d12eb004005cad16e9fea83ae6e3000f2197c7a677a07debdb457064a2 --- src/interfaces/wallet.cpp | 15 +++---- src/wallet/rpcwallet.cpp | 19 +++++---- src/wallet/test/wallet_tests.cpp | 4 +- src/wallet/wallet.cpp | 72 +++++++------------------------- src/wallet/wallet.h | 14 ++++--- 5 files changed, 46 insertions(+), 78 deletions(-) diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp index 2e345ec88cb1..d51bf0ce4688 100644 --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -383,16 +383,17 @@ class WalletImpl : public Wallet bool isFullyMixed(const COutPoint& outpoint) override { return m_wallet->IsFullyMixed(outpoint); } WalletBalances getBalances() override { + const auto bal = m_wallet->GetBalance(); WalletBalances result; - result.balance = m_wallet->GetBalance(); - result.unconfirmed_balance = m_wallet->GetUnconfirmedBalance(); - result.immature_balance = m_wallet->GetImmatureBalance(); + result.balance = bal.m_mine_trusted; + result.unconfirmed_balance = bal.m_mine_untrusted_pending; + result.immature_balance = bal.m_mine_immature; result.anonymized_balance = m_wallet->GetAnonymizedBalance(); result.have_watch_only = m_wallet->HaveWatchOnly(); if (result.have_watch_only) { - result.watch_only_balance = m_wallet->GetBalance(ISMINE_WATCH_ONLY); - result.unconfirmed_watch_only_balance = m_wallet->GetUnconfirmedWatchOnlyBalance(); - result.immature_watch_only_balance = m_wallet->GetImmatureWatchOnlyBalance(); + result.watch_only_balance = bal.m_watchonly_trusted; + result.unconfirmed_watch_only_balance = bal.m_watchonly_untrusted_pending; + result.immature_watch_only_balance = bal.m_watchonly_immature; } return result; } @@ -410,7 +411,7 @@ class WalletImpl : public Wallet } CAmount getBalance() override { - return m_wallet->GetBalance(); + return m_wallet->GetBalance().m_mine_trusted; } CAmount getAnonymizableBalance(bool fSkipDenominated, bool fSkipUnconfirmed) override { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c8af0cc936c6..dd454230e2b6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -288,7 +288,7 @@ static UniValue setlabel(const JSONRPCRequest& request) static CTransactionRef SendMoney(CWallet * const pwallet, const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount, const CCoinControl& coin_control, mapValue_t mapValue) { - CAmount curBalance = pwallet->GetBalance(); + CAmount curBalance = pwallet->GetBalance().m_mine_trusted; // Check amount if (nValue <= 0) @@ -827,12 +827,14 @@ static UniValue getbalance(const JSONRPCRequest& request) fAddLocked = addlocked.get_bool(); } - isminefilter filter = ISMINE_SPENDABLE; + bool include_watchonly = false; if (!request.params[3].isNull() && request.params[3].get_bool()) { - filter = filter | ISMINE_WATCH_ONLY; + include_watchonly = true; } - return ValueFromAmount(pwallet->GetBalance(filter, min_depth, fAddLocked)); + const auto bal = pwallet->GetBalance(min_depth, fAddLocked); + + return ValueFromAmount(bal.m_mine_trusted + (include_watchonly ? bal.m_watchonly_trusted : 0)); } static UniValue getunconfirmedbalance(const JSONRPCRequest &request) @@ -856,7 +858,7 @@ static UniValue getunconfirmedbalance(const JSONRPCRequest &request) LOCK2(cs_main, pwallet->cs_wallet); - return ValueFromAmount(pwallet->GetUnconfirmedBalance()); + return ValueFromAmount(pwallet->GetBalance().m_mine_untrusted_pending); } @@ -2642,12 +2644,13 @@ static UniValue getwalletinfo(const JSONRPCRequest& request) bool fHDEnabled = pwallet->GetHDChain(hdChainCurrent); UniValue obj(UniValue::VOBJ); + const auto bal = pwallet->GetBalance(); obj.pushKV("walletname", pwallet->GetName()); obj.pushKV("walletversion", pwallet->GetVersion()); - obj.pushKV("balance", ValueFromAmount(pwallet->GetBalance())); + obj.pushKV("balance", ValueFromAmount(bal.m_mine_trusted)); obj.pushKV("coinjoin_balance", ValueFromAmount(pwallet->GetAnonymizedBalance())); - obj.pushKV("unconfirmed_balance", ValueFromAmount(pwallet->GetUnconfirmedBalance())); - obj.pushKV("immature_balance", ValueFromAmount(pwallet->GetImmatureBalance())); + obj.pushKV("unconfirmed_balance", ValueFromAmount(bal.m_mine_untrusted_pending)); + obj.pushKV("immature_balance", ValueFromAmount(bal.m_mine_immature)); obj.pushKV("txcount", (int)pwallet->mapWallet.size()); obj.pushKV("timefirstkey", pwallet->GetTimeFirstKey()); obj.pushKV("keypoololdest", pwallet->GetOldestKeyPoolTime()); diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp index 14517fb098ab..7b8ab2cfa6ae 100644 --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -57,7 +57,7 @@ BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup) BOOST_CHECK_EQUAL(wallet.ScanForWalletTransactions(oldTip, nullptr, reserver, failed_block, stop_block), CWallet::ScanResult::SUCCESS); BOOST_CHECK_EQUAL(failed_block, null_block); BOOST_CHECK_EQUAL(stop_block, newTip); - BOOST_CHECK_EQUAL(wallet.GetImmatureBalance(), 1000 * COIN); + BOOST_CHECK_EQUAL(wallet.GetBalance().m_mine_immature, 1000 * COIN); } // Prune the older block file. @@ -75,7 +75,7 @@ BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup) BOOST_CHECK_EQUAL(wallet.ScanForWalletTransactions(oldTip, nullptr, reserver, failed_block, stop_block), CWallet::ScanResult::FAILURE); BOOST_CHECK_EQUAL(failed_block, oldTip); BOOST_CHECK_EQUAL(stop_block, newTip); - BOOST_CHECK_EQUAL(wallet.GetImmatureBalance(), 500 * COIN); + BOOST_CHECK_EQUAL(wallet.GetBalance().m_mine_immature, 500 * COIN); } // Verify importmulti RPC returns failure for a key whose creation time is diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 85f5a13c7e02..c94e6ec775ad 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2649,19 +2649,29 @@ std::unordered_set CWallet::GetSpendableTXs() return ret; } -CAmount CWallet::GetBalance(const isminefilter& filter, const int min_depth, const bool fAddLocked) const +CWallet::Balance CWallet::GetBalance(const int min_depth, const bool fAddLocked) const { - CAmount nTotal = 0; + Balance ret; { LOCK2(cs_main, cs_wallet); for (auto pcoin : GetSpendableTXs()) { - if (pcoin->IsTrusted() && ((pcoin->GetDepthInMainChain() >= min_depth) || (fAddLocked && pcoin->IsLockedByInstantSend()))) { - nTotal += pcoin->GetAvailableCredit(true, filter); + const bool is_trusted{pcoin->IsTrusted()}; + const int tx_depth{pcoin->GetDepthInMainChain()}; + const CAmount tx_credit_mine{pcoin->GetAvailableCredit(/* fUseCache */ true, ISMINE_SPENDABLE)}; + const CAmount tx_credit_watchonly{pcoin->GetAvailableCredit(/* fUseCache */ true, ISMINE_WATCH_ONLY)}; + if (is_trusted && ((tx_depth >= min_depth) || (fAddLocked && pcoin->IsLockedByInstantSend()))) { + ret.m_mine_trusted += tx_credit_mine; + ret.m_watchonly_trusted += tx_credit_watchonly; + } + if (!is_trusted && tx_depth == 0 && pcoin->InMempool()) { + ret.m_mine_untrusted_pending += tx_credit_mine; + ret.m_watchonly_untrusted_pending += tx_credit_watchonly; } + ret.m_mine_immature += pcoin->GetImmatureCredit(); + ret.m_watchonly_immature += pcoin->GetImmatureWatchOnlyCredit(); } } - - return nTotal; + return ret; } CAmount CWallet::GetAnonymizableBalance(bool fSkipDenominated, bool fSkipUnconfirmed) const @@ -2762,56 +2772,6 @@ CAmount CWallet::GetDenominatedBalance(bool unconfirmed) const return nTotal; } -CAmount CWallet::GetUnconfirmedBalance() const -{ - CAmount nTotal = 0; - { - LOCK2(cs_main, cs_wallet); - for (auto pcoin : GetSpendableTXs()) { - if (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0 && !pcoin->IsLockedByInstantSend() && pcoin->InMempool()) - nTotal += pcoin->GetAvailableCredit(); - } - } - return nTotal; -} - -CAmount CWallet::GetImmatureBalance() const -{ - CAmount nTotal = 0; - { - LOCK2(cs_main, cs_wallet); - for (auto pcoin : GetSpendableTXs()) { - nTotal += pcoin->GetImmatureCredit(); - } - } - return nTotal; -} - -CAmount CWallet::GetUnconfirmedWatchOnlyBalance() const -{ - CAmount nTotal = 0; - { - LOCK2(cs_main, cs_wallet); - for (auto pcoin : GetSpendableTXs()) { - if (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0 && !pcoin->IsLockedByInstantSend() && pcoin->InMempool()) - nTotal += pcoin->GetAvailableCredit(true, ISMINE_WATCH_ONLY); - } - } - return nTotal; -} - -CAmount CWallet::GetImmatureWatchOnlyBalance() const -{ - CAmount nTotal = 0; - { - LOCK2(cs_main, cs_wallet); - for (auto pcoin : GetSpendableTXs()) { - nTotal += pcoin->GetImmatureWatchOnlyCredit(); - } - } - return nTotal; -} - // Calculate total balance in a different way from GetBalance. The biggest // difference is that GetBalance sums up all unspent TxOuts paying to the // wallet, while this sums up both spent and unspent TxOuts paying to the diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 04b15c6f1d61..2c8eb15eefd1 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -987,12 +987,16 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface void ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman) override EXCLUSIVE_LOCKS_REQUIRED(cs_main); // ResendWalletTransactionsBefore may only be called if fBroadcastTransactions! std::vector ResendWalletTransactionsBefore(int64_t nTime, CConnman* connman) EXCLUSIVE_LOCKS_REQUIRED(cs_main); - CAmount GetBalance(const isminefilter& filter=ISMINE_SPENDABLE, const int min_depth=0, bool fAddLocked = false) const; - CAmount GetUnconfirmedBalance() const; - CAmount GetImmatureBalance() const; - CAmount GetUnconfirmedWatchOnlyBalance() const; - CAmount GetImmatureWatchOnlyBalance() const; + struct Balance { + CAmount m_mine_trusted{0}; //!< Trusted, at depth=GetBalance.min_depth or more + CAmount m_mine_untrusted_pending{0}; //!< Untrusted, but in mempool (pending) + CAmount m_mine_immature{0}; //!< Immature coinbases in the main chain + CAmount m_watchonly_trusted{0}; + CAmount m_watchonly_untrusted_pending{0}; + CAmount m_watchonly_immature{0}; + }; CAmount GetLegacyBalance(const isminefilter& filter, int minDepth, const bool fAddLocked) const; + Balance GetBalance(int min_depth = 0, const bool fAddLocked = false) const; CAmount GetAnonymizableBalance(bool fSkipDenominated = false, bool fSkipUnconfirmed = true) const; CAmount GetAnonymizedBalance(const CCoinControl* coinControl = nullptr) const; From fa8300f6ccdf20a3841ba3f228b9d47f345ae76f Mon Sep 17 00:00:00 2001 From: Christian Fifi Culp Date: Tue, 5 Oct 2021 21:43:24 -0500 Subject: [PATCH 8/8] Extend #15747: Remove some Dash Get*Balance --- src/coinjoin/client.cpp | 8 +++++--- src/interfaces/wallet.cpp | 13 +++++++++---- src/wallet/rpcwallet.cpp | 2 +- src/wallet/wallet.cpp | 37 ++++++------------------------------- src/wallet/wallet.h | 7 ++++--- 5 files changed, 25 insertions(+), 42 deletions(-) diff --git a/src/coinjoin/client.cpp b/src/coinjoin/client.cpp index 25c776f5d932..98ac7305ca17 100644 --- a/src/coinjoin/client.cpp +++ b/src/coinjoin/client.cpp @@ -812,8 +812,10 @@ bool CCoinJoinClientSession::DoAutomaticDenominating(CConnman& connman, bool fDr return false; } + const auto bal = mixingWallet.GetBalance(); + // check if there is anything left to do - CAmount nBalanceAnonymized = mixingWallet.GetAnonymizedBalance(); + CAmount nBalanceAnonymized = bal.m_anonymized; nBalanceNeedsAnonymized = CCoinJoinClientOptions::GetAmount() * COIN - nBalanceAnonymized; if (nBalanceNeedsAnonymized < 0) { @@ -843,8 +845,8 @@ bool CCoinJoinClientSession::DoAutomaticDenominating(CConnman& connman, bool fDr // excluding denoms CAmount nBalanceAnonimizableNonDenom = mixingWallet.GetAnonymizableBalance(true); // denoms - CAmount nBalanceDenominatedConf = mixingWallet.GetDenominatedBalance(); - CAmount nBalanceDenominatedUnconf = mixingWallet.GetDenominatedBalance(true); + CAmount nBalanceDenominatedConf = bal.m_denominated_trusted; + CAmount nBalanceDenominatedUnconf = bal.m_denominated_untrusted_pending; CAmount nBalanceDenominated = nBalanceDenominatedConf + nBalanceDenominatedUnconf; CAmount nBalanceToDenominate = CCoinJoinClientOptions::GetAmount() * COIN - nBalanceDenominated; diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp index d51bf0ce4688..ab67ec904f76 100644 --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -388,7 +388,7 @@ class WalletImpl : public Wallet result.balance = bal.m_mine_trusted; result.unconfirmed_balance = bal.m_mine_untrusted_pending; result.immature_balance = bal.m_mine_immature; - result.anonymized_balance = m_wallet->GetAnonymizedBalance(); + result.anonymized_balance = bal.m_anonymized; result.have_watch_only = m_wallet->HaveWatchOnly(); if (result.have_watch_only) { result.watch_only_balance = bal.m_watchonly_trusted; @@ -419,11 +419,16 @@ class WalletImpl : public Wallet } CAmount getAnonymizedBalance() override { - return m_wallet->GetAnonymizedBalance(); + return m_wallet->GetBalance().m_anonymized; } CAmount getDenominatedBalance(bool unconfirmed) override { - return m_wallet->GetDenominatedBalance(unconfirmed); + const auto bal = m_wallet->GetBalance(); + if (unconfirmed) { + return bal.m_denominated_untrusted_pending; + } else { + return bal.m_denominated_trusted; + } } CAmount getNormalizedAnonymizedBalance() override { @@ -436,7 +441,7 @@ class WalletImpl : public Wallet CAmount getAvailableBalance(const CCoinControl& coin_control) override { if (coin_control.IsUsingCoinJoin()) { - return m_wallet->GetAnonymizedBalance(&coin_control); + return m_wallet->GetBalance(0, false, &coin_control).m_anonymized; } else { return m_wallet->GetAvailableBalance(&coin_control); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index dd454230e2b6..7889d9fa042f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2648,7 +2648,7 @@ static UniValue getwalletinfo(const JSONRPCRequest& request) obj.pushKV("walletname", pwallet->GetName()); obj.pushKV("walletversion", pwallet->GetVersion()); obj.pushKV("balance", ValueFromAmount(bal.m_mine_trusted)); - obj.pushKV("coinjoin_balance", ValueFromAmount(pwallet->GetAnonymizedBalance())); + obj.pushKV("coinjoin_balance", ValueFromAmount(bal.m_anonymized)); obj.pushKV("unconfirmed_balance", ValueFromAmount(bal.m_mine_untrusted_pending)); obj.pushKV("immature_balance", ValueFromAmount(bal.m_mine_immature)); obj.pushKV("txcount", (int)pwallet->mapWallet.size()); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c94e6ec775ad..b1a80350a4fa 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2649,7 +2649,7 @@ std::unordered_set CWallet::GetSpendableTXs() return ret; } -CWallet::Balance CWallet::GetBalance(const int min_depth, const bool fAddLocked) const +CWallet::Balance CWallet::GetBalance(const int min_depth, const bool fAddLocked, const CCoinControl* coinControl) const { Balance ret; { @@ -2669,6 +2669,11 @@ CWallet::Balance CWallet::GetBalance(const int min_depth, const bool fAddLocked) } ret.m_mine_immature += pcoin->GetImmatureCredit(); ret.m_watchonly_immature += pcoin->GetImmatureWatchOnlyCredit(); + if (CCoinJoinClientOptions::IsEnabled()) { + ret.m_anonymized += pcoin->GetAnonymizedCredit(coinControl); + ret.m_denominated_trusted += pcoin->GetDenominatedCredit(false); + ret.m_denominated_untrusted_pending += pcoin->GetDenominatedCredit(true); + } } } return ret; @@ -2696,21 +2701,6 @@ CAmount CWallet::GetAnonymizableBalance(bool fSkipDenominated, bool fSkipUnconfi return nTotal; } -CAmount CWallet::GetAnonymizedBalance(const CCoinControl* coinControl) const -{ - if (!CCoinJoinClientOptions::IsEnabled()) return 0; - - CAmount nTotal = 0; - - LOCK2(cs_main, cs_wallet); - - for (auto pcoin : GetSpendableTXs()) { - nTotal += pcoin->GetAnonymizedCredit(coinControl); - } - - return nTotal; -} - // Note: calculated including unconfirmed, // that's ok as long as we use it for informational purposes only float CWallet::GetAverageAnonymizedRounds() const @@ -2757,21 +2747,6 @@ CAmount CWallet::GetNormalizedAnonymizedBalance() const return nTotal; } -CAmount CWallet::GetDenominatedBalance(bool unconfirmed) const -{ - if (!CCoinJoinClientOptions::IsEnabled()) return 0; - - CAmount nTotal = 0; - - LOCK2(cs_main, cs_wallet); - - for (auto pcoin : GetSpendableTXs()) { - nTotal += pcoin->GetDenominatedCredit(unconfirmed); - } - - return nTotal; -} - // Calculate total balance in a different way from GetBalance. The biggest // difference is that GetBalance sums up all unspent TxOuts paying to the // wallet, while this sums up both spent and unspent TxOuts paying to the diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 2c8eb15eefd1..a6ffb25d7b99 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -994,15 +994,16 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface CAmount m_watchonly_trusted{0}; CAmount m_watchonly_untrusted_pending{0}; CAmount m_watchonly_immature{0}; + CAmount m_anonymized{0}; + CAmount m_denominated_trusted{0}; + CAmount m_denominated_untrusted_pending{0}; }; CAmount GetLegacyBalance(const isminefilter& filter, int minDepth, const bool fAddLocked) const; - Balance GetBalance(int min_depth = 0, const bool fAddLocked = false) const; + Balance GetBalance(int min_depth = 0, const bool fAddLocked = false, const CCoinControl* coinControl = nullptr) const; CAmount GetAnonymizableBalance(bool fSkipDenominated = false, bool fSkipUnconfirmed = true) const; - CAmount GetAnonymizedBalance(const CCoinControl* coinControl = nullptr) const; float GetAverageAnonymizedRounds() const; CAmount GetNormalizedAnonymizedBalance() const; - CAmount GetDenominatedBalance(bool unconfirmed=false) const; bool GetBudgetSystemCollateralTX(CTransactionRef& tx, uint256 hash, CAmount amount, const COutPoint& outpoint=COutPoint()/*defaults null*/); CAmount GetAvailableBalance(const CCoinControl* coinControl = nullptr) const;