diff --git a/src/chain.h b/src/chain.h index f9558f2674..7e3c6ce68d 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 5077cbf710..2e345ec88c 100644 --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -343,7 +343,8 @@ public: 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 @@ public: 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 94a75df563..7c88fd4ce4 100644 --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -183,7 +183,8 @@ public: //! 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 9a528507a4..bb982547a3 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 6d7384fad5..07a469cb55 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 f66452e6bd..a84eb3fff8 100644 --- a/src/qt/transactionrecord.h +++ b/src/qt/transactionrecord.h @@ -161,7 +161,7 @@ public: /** 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 c3d07c761a..2b09ce2f6c 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -199,8 +199,9 @@ public: // 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; }