This commit is contained in:
Sjors Provoost 2024-04-29 04:28:43 +02:00 committed by GitHub
commit 0cd5db7e16
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 70 additions and 28 deletions

View File

@ -418,6 +418,8 @@ struct WalletTxStatus
bool is_abandoned;
bool is_coinbase;
bool is_in_main_chain;
// The block containing this transaction is assumed valid
bool is_assumed;
};
//! Wallet transaction output.

View File

@ -175,42 +175,31 @@ void TransactionRecord::updateStatus(const interfaces::WalletTxStatus& wtx, cons
// For generated transactions, determine maturity
if (type == TransactionRecord::Generated) {
if (wtx.blocks_to_maturity > 0)
{
if (wtx.blocks_to_maturity > 0) {
status.status = TransactionStatus::Immature;
if (wtx.is_in_main_chain)
{
if (wtx.is_in_main_chain) {
status.matures_in = wtx.blocks_to_maturity;
}
else
{
} else {
status.status = TransactionStatus::NotAccepted;
}
}
else
{
} else {
status.status = TransactionStatus::Confirmed;
}
}
else
{
if (status.depth < 0)
{
} else {
if (status.depth < 0) {
status.status = TransactionStatus::Conflicted;
}
else if (status.depth == 0)
{
else if (status.depth == 0) {
status.status = TransactionStatus::Unconfirmed;
if (wtx.is_abandoned)
if (wtx.is_abandoned) {
status.status = TransactionStatus::Abandoned;
}
else if (status.depth < RecommendedNumConfirmations)
{
}
} else if (wtx.is_assumed) {
status.status = TransactionStatus::AssumedConfirmed;
} else if (status.depth < RecommendedNumConfirmations) {
status.status = TransactionStatus::Confirming;
}
else
{
} else {
status.status = TransactionStatus::Confirmed;
}
}

View File

@ -25,6 +25,7 @@ struct TransactionStatus {
Confirmed, /**< Have 6 or more confirmations (normal tx) or fully mature (mined tx) **/
/// Normal (sent/received) transactions
Unconfirmed, /**< Not yet mined into a block **/
AssumedConfirmed, /**< Confirmed, but background validation hasn't finished */
Confirming, /**< Confirmed, but waiting for the recommended number of confirmations **/
Conflicted, /**< Conflicts with other transaction or mempool **/
Abandoned, /**< Abandoned from the wallet **/

View File

@ -320,6 +320,9 @@ QString TransactionTableModel::formatTxStatus(const TransactionRecord *wtx) cons
case TransactionStatus::Abandoned:
status = tr("Abandoned");
break;
case TransactionStatus::AssumedConfirmed:
status = tr("%1 confirmations, pending verification of historical blocks").arg(wtx->status.depth);
break;
case TransactionStatus::Confirming:
status = tr("Confirming (%1 of %2 recommended confirmations)").arg(wtx->status.depth).arg(TransactionRecord::RecommendedNumConfirmations);
break;
@ -465,6 +468,8 @@ QVariant TransactionTableModel::txStatusDecoration(const TransactionRecord *wtx)
return QIcon(":/icons/transaction_0");
case TransactionStatus::Abandoned:
return QIcon(":/icons/transaction_abandoned");
case TransactionStatus::AssumedConfirmed:
return QIcon(":/icons/transaction_1");
case TransactionStatus::Confirming:
switch(wtx->status.depth)
{
@ -639,7 +644,14 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
return details;
}
case ConfirmedRole:
return rec->status.status == TransactionStatus::Status::Confirming || rec->status.status == TransactionStatus::Status::Confirmed;
switch (rec->status.status) {
case TransactionStatus::Status::AssumedConfirmed:
case TransactionStatus::Status::Confirming:
case TransactionStatus::Status::Confirmed:
return true;
default:
return false;
}
case FormattedAmountRole:
// Used for copy/export, so don't include separators
return formatTxAmount(rec, false, BitcoinUnits::SeparatorStyle::NEVER);

View File

@ -102,6 +102,7 @@ WalletTxStatus MakeWalletTxStatus(const CWallet& wallet, const CWalletTx& wtx)
result.is_abandoned = wtx.isAbandoned();
result.is_coinbase = wtx.IsCoinBase();
result.is_in_main_chain = wtx.isConfirmed();
result.is_assumed = wallet.IsTxAssumed(wtx);
return result;
}

View File

@ -1491,12 +1491,23 @@ void CWallet::transactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRe
void CWallet::blockConnected(ChainstateRole role, const interfaces::BlockInfo& block)
{
if (role == ChainstateRole::BACKGROUND) {
return;
}
assert(block.data);
LOCK(cs_wallet);
switch (role) {
case ChainstateRole::BACKGROUND:
m_background_validation_height = block.height;
return;
case ChainstateRole::ASSUMEDVALID:
if (m_background_validation_height == -1) {
m_background_validation_height = 0;
}
break;
case ChainstateRole::NORMAL:
m_background_validation_height = -1;
break;
} // no default case, so the compiler can warn about missing cases
m_last_block_processed_height = block.height;
m_last_block_processed = block.hash;
@ -3437,6 +3448,18 @@ bool CWallet::IsTxImmatureCoinBase(const CWalletTx& wtx) const
return GetTxBlocksToMaturity(wtx) > 0;
}
bool CWallet::IsTxAssumed(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
{
AssertLockHeld(cs_wallet);
if (GetBackgroundValidationHeight() == -1) return false;
if (auto* conf = wtx.state<TxStateConfirmed>()) {
int height{conf->confirmed_block_height};
return height > GetBackgroundValidationHeight();
}
return false;
}
bool CWallet::IsCrypted() const
{
return HasEncryptionKeys();

View File

@ -409,6 +409,13 @@ private:
*/
int m_last_block_processed_height GUARDED_BY(cs_wallet) = -1;
/**
* The following is used to track whether a confirmed transaction is in
* a block that background validation hasn't checked yet, or above the
* assume utxo snapshot height when background validation hasn't completed.
*/
int m_background_validation_height GUARDED_BY(cs_wallet) = -1;
std::map<OutputType, ScriptPubKeyMan*> m_external_spk_managers;
std::map<OutputType, ScriptPubKeyMan*> m_internal_spk_managers;
@ -519,6 +526,7 @@ public:
* referenced in transaction, and might cause assert failures.
*/
int GetTxDepthInMainChain(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool IsTxAssumed(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
/**
* @return number of blocks to maturity for this transaction:
@ -989,6 +997,12 @@ public:
m_last_block_processed_height = block_height;
m_last_block_processed = block_hash;
};
/** Height of background validation. Returns -1 if there is no background validation. */
int GetBackgroundValidationHeight() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
{
AssertLockHeld(cs_wallet);
return m_background_validation_height;
};
//! Connect the signals from ScriptPubKeyMans to the signals in CWallet
void ConnectScriptPubKeyManNotifiers();