diff --git a/src/bench/prevector.cpp b/src/bench/prevector.cpp index 7cf58c51dda2..5075312fe9ae 100644 --- a/src/bench/prevector.cpp +++ b/src/bench/prevector.cpp @@ -17,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 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/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/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/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/interfaces/wallet.cpp b/src/interfaces/wallet.cpp index 5077cbf710a6..ab67ec904f76 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, @@ -381,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.anonymized_balance = m_wallet->GetAnonymizedBalance(); + result.balance = bal.m_mine_trusted; + result.unconfirmed_balance = bal.m_mine_untrusted_pending; + result.immature_balance = bal.m_mine_immature; + result.anonymized_balance = bal.m_anonymized; 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; } @@ -408,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 { @@ -416,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 { @@ -433,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/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/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); diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 70e7bbb139e7..bb982547a303 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -29,6 +29,7 @@ #include #endif +#include #include #include #include @@ -37,6 +38,7 @@ #include #include +#include #include #include @@ -46,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -55,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -76,7 +80,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 +697,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 @@ -1318,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/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; 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() 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; } 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) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c8af0cc936c6..7889d9fa042f 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("coinjoin_balance", ValueFromAmount(pwallet->GetAnonymizedBalance())); - obj.pushKV("unconfirmed_balance", ValueFromAmount(pwallet->GetUnconfirmedBalance())); - obj.pushKV("immature_balance", ValueFromAmount(pwallet->GetImmatureBalance())); + obj.pushKV("balance", ValueFromAmount(bal.m_mine_trusted)); + 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()); 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..b1a80350a4fa 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2649,19 +2649,34 @@ 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 CCoinControl* coinControl) 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(); + 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 nTotal; + return ret; } CAmount CWallet::GetAnonymizableBalance(bool fSkipDenominated, bool fSkipUnconfirmed) const @@ -2686,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 @@ -2747,71 +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; -} - -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..a6ffb25d7b99 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -987,18 +987,23 @@ 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 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 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;