Skip to content

Commit

Permalink
Don't label transactions "Open" while catching up
Browse files Browse the repository at this point in the history
Since the default `nSequence` is `0xFFFFFFFE` and locktime is enabled,
the checking `wtx.is_final` is meaningless until the syncing has
completed.
  • Loading branch information
hebasto committed Jan 2, 2019
1 parent bfd7e54 commit fb3ce75
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 14 deletions.
12 changes: 10 additions & 2 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,23 @@
* 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.
*
* Ref: https://github.com/bitcoin/bitcoin/pull/1026
*/
static constexpr int64_t MAX_BLOCK_TIME_GAP = 90 * 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 @@ -318,7 +318,8 @@ class WalletImpl : public Wallet
}
bool tryGetTxStatus(const uint256& txid,
interfaces::WalletTxStatus& tx_status,
int& num_blocks) override
int& num_blocks,
int64_t& block_time) override
{
auto locked_chain = m_wallet.chain().lock(true /* try_lock */);
if (!locked_chain) {
Expand All @@ -333,6 +334,7 @@ class WalletImpl : public Wallet
return false;
}
num_blocks = ::chainActive.Height();
block_time = ::chainActive.Tip()->GetBlockTime();
tx_status = MakeWalletTxStatus(*locked_chain, mi->second);
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,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,
int& num_blocks) = 0;
int& num_blocks,
int64_t& block_time) = 0;

//! Get transaction details.
virtual WalletTx getWalletTxDetails(const uint256& txid,
Expand Down
4 changes: 2 additions & 2 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <qt/macdockiconhandler.h>
#endif

#include <chain.h>
#include <chainparams.h>
#include <interfaces/handler.h>
#include <interfaces/node.h>
Expand Down Expand Up @@ -903,8 +904,7 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
tooltip = tr("Processed %n block(s) of transaction history.", "", count);

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

Expand Down
11 changes: 6 additions & 5 deletions src/qt/transactionrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <qt/transactionrecord.h>

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

#include <stdint.h>

#include <QDateTime>

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

void TransactionRecord::updateStatus(const interfaces::WalletTxStatus& wtx, int numBlocks)
void TransactionRecord::updateStatus(const interfaces::WalletTxStatus& wtx, int numBlocks, int64_t block_time)
{
// Determine transaction status

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

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 @@ -138,7 +138,7 @@ class TransactionRecord

/** Update status from core wallet tx.
*/
void updateStatus(const interfaces::WalletTxStatus& wtx, int numBlocks);
void updateStatus(const interfaces::WalletTxStatus& wtx, int numBlocks, 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 @@ -193,8 +193,9 @@ class TransactionTablePriv
// simply re-use the cached status.
interfaces::WalletTxStatus wtx;
int numBlocks;
if (wallet.tryGetTxStatus(rec->hash, wtx, numBlocks) && rec->statusUpdateNeeded(numBlocks)) {
rec->updateStatus(wtx, numBlocks);
int64_t block_time;
if (wallet.tryGetTxStatus(rec->hash, wtx, numBlocks, block_time) && rec->statusUpdateNeeded(numBlocks)) {
rec->updateStatus(wtx, numBlocks, block_time);
}
return rec;
}
Expand Down

0 comments on commit fb3ce75

Please sign in to comment.