Skip to content

Commit e8ad580

Browse files
committed
Merge #14556: qt: fix confirmed transaction labeled "open" (#13299)
fb3ce75 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
2 parents a5daf70 + fb3ce75 commit e8ad580

File tree

7 files changed

+27
-14
lines changed

7 files changed

+27
-14
lines changed

src/chain.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,23 @@
1818
* Maximum amount of time that a block timestamp is allowed to exceed the
1919
* current network-adjusted time before the block will be accepted.
2020
*/
21-
static const int64_t MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60;
21+
static constexpr int64_t MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60;
2222

2323
/**
2424
* Timestamp window used as a grace period by code that compares external
2525
* timestamps (such as timestamps passed to RPCs, or wallet key creation times)
2626
* to block timestamps. This should be set at least as high as
2727
* MAX_FUTURE_BLOCK_TIME.
2828
*/
29-
static const int64_t TIMESTAMP_WINDOW = MAX_FUTURE_BLOCK_TIME;
29+
static constexpr int64_t TIMESTAMP_WINDOW = MAX_FUTURE_BLOCK_TIME;
30+
31+
/**
32+
* Maximum gap between node time and block time used
33+
* for the "Catching up..." mode in GUI.
34+
*
35+
* Ref: https://github.com/bitcoin/bitcoin/pull/1026
36+
*/
37+
static constexpr int64_t MAX_BLOCK_TIME_GAP = 90 * 60;
3038

3139
class CBlockFileInfo
3240
{

src/interfaces/wallet.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ class WalletImpl : public Wallet
318318
}
319319
bool tryGetTxStatus(const uint256& txid,
320320
interfaces::WalletTxStatus& tx_status,
321-
int& num_blocks) override
321+
int& num_blocks,
322+
int64_t& block_time) override
322323
{
323324
auto locked_chain = m_wallet.chain().lock(true /* try_lock */);
324325
if (!locked_chain) {
@@ -333,6 +334,7 @@ class WalletImpl : public Wallet
333334
return false;
334335
}
335336
num_blocks = ::chainActive.Height();
337+
block_time = ::chainActive.Tip()->GetBlockTime();
336338
tx_status = MakeWalletTxStatus(*locked_chain, mi->second);
337339
return true;
338340
}

src/interfaces/wallet.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ class Wallet
178178
//! Try to get updated status for a particular transaction, if possible without blocking.
179179
virtual bool tryGetTxStatus(const uint256& txid,
180180
WalletTxStatus& tx_status,
181-
int& num_blocks) = 0;
181+
int& num_blocks,
182+
int64_t& block_time) = 0;
182183

183184
//! Get transaction details.
184185
virtual WalletTx getWalletTxDetails(const uint256& txid,

src/qt/bitcoingui.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <qt/macdockiconhandler.h>
2929
#endif
3030

31+
#include <chain.h>
3132
#include <chainparams.h>
3233
#include <interfaces/handler.h>
3334
#include <interfaces/node.h>
@@ -901,8 +902,7 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
901902
tooltip = tr("Processed %n block(s) of transaction history.", "", count);
902903

903904
// Set icon state: spinning if catching up, tick otherwise
904-
if(secs < 90*60)
905-
{
905+
if (secs < MAX_BLOCK_TIME_GAP) {
906906
tooltip = tr("Up to date") + QString(".<br>") + tooltip;
907907
labelBlocksIcon->setPixmap(platformStyle->SingleColorIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
908908

src/qt/transactionrecord.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <qt/transactionrecord.h>
66

7+
#include <chain.h>
78
#include <consensus/consensus.h>
89
#include <interfaces/wallet.h>
910
#include <key_io.h>
@@ -12,6 +13,7 @@
1213

1314
#include <stdint.h>
1415

16+
#include <QDateTime>
1517

1618
/* Return positive answer if transaction should be shown in list.
1719
*/
@@ -158,7 +160,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interface
158160
return parts;
159161
}
160162

161-
void TransactionRecord::updateStatus(const interfaces::WalletTxStatus& wtx, int numBlocks)
163+
void TransactionRecord::updateStatus(const interfaces::WalletTxStatus& wtx, int numBlocks, int64_t block_time)
162164
{
163165
// Determine transaction status
164166

@@ -172,10 +174,9 @@ void TransactionRecord::updateStatus(const interfaces::WalletTxStatus& wtx, int
172174
status.depth = wtx.depth_in_main_chain;
173175
status.cur_num_blocks = numBlocks;
174176

175-
if (!wtx.is_final)
176-
{
177-
if (wtx.lock_time < LOCKTIME_THRESHOLD)
178-
{
177+
const bool up_to_date = ((int64_t)QDateTime::currentMSecsSinceEpoch() / 1000 - block_time < MAX_BLOCK_TIME_GAP);
178+
if (up_to_date && !wtx.is_final) {
179+
if (wtx.lock_time < LOCKTIME_THRESHOLD) {
179180
status.status = TransactionStatus::OpenUntilBlock;
180181
status.open_for = wtx.lock_time - numBlocks;
181182
}

src/qt/transactionrecord.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class TransactionRecord
138138

139139
/** Update status from core wallet tx.
140140
*/
141-
void updateStatus(const interfaces::WalletTxStatus& wtx, int numBlocks);
141+
void updateStatus(const interfaces::WalletTxStatus& wtx, int numBlocks, int64_t block_time);
142142

143143
/** Return whether a status update is needed.
144144
*/

src/qt/transactiontablemodel.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,9 @@ class TransactionTablePriv
192192
// simply re-use the cached status.
193193
interfaces::WalletTxStatus wtx;
194194
int numBlocks;
195-
if (wallet.tryGetTxStatus(rec->hash, wtx, numBlocks) && rec->statusUpdateNeeded(numBlocks)) {
196-
rec->updateStatus(wtx, numBlocks);
195+
int64_t block_time;
196+
if (wallet.tryGetTxStatus(rec->hash, wtx, numBlocks, block_time) && rec->statusUpdateNeeded(numBlocks)) {
197+
rec->updateStatus(wtx, numBlocks, block_time);
197198
}
198199
return rec;
199200
}

0 commit comments

Comments
 (0)