Skip to content

Commit

Permalink
Merge bitcoin#14556: qt: fix confirmed transaction labeled "open" (bi…
Browse files Browse the repository at this point in the history
…tcoin#13299)

fb3ce75 Don't label transactions "Open" while catching up (Hennadii Stepanov)

Pull request description:

  Fix bitcoin#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
  • Loading branch information
laanwj authored and christiancfifi committed Oct 14, 2021
1 parent 8caf2f0 commit 5fb15a9
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 19 deletions.
10 changes: 8 additions & 2 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@
* 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
* timestamps (such as timestamps passed to RPCs, or wallet key creation times)
* 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
{
Expand Down
4 changes: 3 additions & 1 deletion src/interfaces/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 4 additions & 7 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <qt/macdockiconhandler.h>
#endif

#include <chain.h>
#include <chainparams.h>
#include <interfaces/handler.h>
#include <interfaces/node.h>
Expand Down Expand Up @@ -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();
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/qt/transactionrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <qt/transactionrecord.h>

#include <chain.h>
#include <consensus/consensus.h>
#include <interfaces/wallet.h>
#include <interfaces/node.h>
Expand All @@ -13,6 +14,7 @@

#include <stdint.h>

#include <QDateTime>

/* Return positive answer if transaction should be shown in list.
*/
Expand Down Expand Up @@ -252,7 +254,7 @@ QList<TransactionRecord> 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

Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/qt/transactionrecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
5 changes: 3 additions & 2 deletions src/qt/transactiontablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 5fb15a9

Please sign in to comment.