Revert "UI to alert of respend attempt affecting wallet."

This reverts commit ada5a067c7.

Conflicts:
	src/qt/guiconstants.h
	src/wallet.h
This commit is contained in:
Wladimir J. van der Laan 2014-07-17 14:09:46 +02:00
parent 39d3f2cb40
commit 3015e0bca6
9 changed files with 21 additions and 87 deletions

View File

@ -23,10 +23,6 @@ static const int STATUSBAR_ICONSIZE = 16;
#define COLOR_NEGATIVE QColor(255, 0, 0) #define COLOR_NEGATIVE QColor(255, 0, 0)
/* Transaction list -- bare address (without label) */ /* Transaction list -- bare address (without label) */
#define COLOR_BAREADDRESS QColor(140, 140, 140) #define COLOR_BAREADDRESS QColor(140, 140, 140)
/* Transaction list -- has conflicting transactions */
#define COLOR_HASCONFLICTING QColor(255, 255, 255)
/* Transaction list -- has conflicting transactions - background */
#define COLOR_HASCONFLICTING_BG QColor(192, 0, 0)
/* Tooltips longer than this (in characters) are converted into rich text, /* Tooltips longer than this (in characters) are converted into rich text,
so that they can be word-wrapped. so that they can be word-wrapped.

View File

@ -24,7 +24,7 @@ TransactionFilterProxy::TransactionFilterProxy(QObject *parent) :
typeFilter(ALL_TYPES), typeFilter(ALL_TYPES),
minAmount(0), minAmount(0),
limitRows(-1), limitRows(-1),
showInactive(false) showInactive(true)
{ {
} }
@ -39,7 +39,7 @@ bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &
qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong()); qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong());
int status = index.data(TransactionTableModel::StatusRole).toInt(); int status = index.data(TransactionTableModel::StatusRole).toInt();
if(!showInactive && status == TransactionStatus::Conflicted && type == TransactionRecord::Other) if(!showInactive && status == TransactionStatus::Conflicted)
return false; return false;
if(!(TYPE(type) & typeFilter)) if(!(TYPE(type) & typeFilter))
return false; return false;

View File

@ -184,8 +184,6 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
status.depth = wtx.GetDepthInMainChain(); status.depth = wtx.GetDepthInMainChain();
status.cur_num_blocks = chainActive.Height(); status.cur_num_blocks = chainActive.Height();
status.hasConflicting = false;
if (!IsFinalTx(wtx, chainActive.Height() + 1)) if (!IsFinalTx(wtx, chainActive.Height() + 1))
{ {
if (wtx.nLockTime < LOCKTIME_THRESHOLD) if (wtx.nLockTime < LOCKTIME_THRESHOLD)
@ -229,7 +227,6 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
if (status.depth < 0) if (status.depth < 0)
{ {
status.status = TransactionStatus::Conflicted; status.status = TransactionStatus::Conflicted;
status.hasConflicting = !(wtx.GetConflicts(false).empty());
} }
else if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0) else if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0)
{ {
@ -238,7 +235,6 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
else if (status.depth == 0) else if (status.depth == 0)
{ {
status.status = TransactionStatus::Unconfirmed; status.status = TransactionStatus::Unconfirmed;
status.hasConflicting = !(wtx.GetConflicts(false).empty());
} }
else if (status.depth < RecommendedNumConfirmations) else if (status.depth < RecommendedNumConfirmations)
{ {
@ -249,13 +245,13 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
status.status = TransactionStatus::Confirmed; status.status = TransactionStatus::Confirmed;
} }
} }
} }
bool TransactionRecord::statusUpdateNeeded(int64_t nConflictsReceived) bool TransactionRecord::statusUpdateNeeded()
{ {
AssertLockHeld(cs_main); AssertLockHeld(cs_main);
return (status.cur_num_blocks != chainActive.Height() || return status.cur_num_blocks != chainActive.Height();
status.cur_num_conflicts != nConflictsReceived);
} }
QString TransactionRecord::getTxID() const QString TransactionRecord::getTxID() const

View File

@ -20,8 +20,7 @@ class TransactionStatus
public: public:
TransactionStatus(): TransactionStatus():
countsForBalance(false), sortKey(""), countsForBalance(false), sortKey(""),
matures_in(0), status(Offline), hasConflicting(false), depth(0), open_for(0), cur_num_blocks(-1), matures_in(0), status(Offline), depth(0), open_for(0), cur_num_blocks(-1)
cur_num_conflicts(-1)
{ } { }
enum Status { enum Status {
@ -52,10 +51,6 @@ public:
/** @name Reported status /** @name Reported status
@{*/ @{*/
Status status; Status status;
// Has conflicting transactions spending same prevout
bool hasConflicting;
qint64 depth; qint64 depth;
qint64 open_for; /**< Timestamp if status==OpenUntilDate, otherwise number qint64 open_for; /**< Timestamp if status==OpenUntilDate, otherwise number
of additional blocks that need to be mined before of additional blocks that need to be mined before
@ -64,10 +59,6 @@ public:
/** Current number of blocks (to know whether cached status is still valid) */ /** Current number of blocks (to know whether cached status is still valid) */
int cur_num_blocks; int cur_num_blocks;
/** Number of conflicts received into wallet as of last status update */
int64_t cur_num_conflicts;
}; };
/** UI model for a transaction. A core transaction can be represented by multiple UI transactions if it has /** UI model for a transaction. A core transaction can be represented by multiple UI transactions if it has
@ -145,7 +136,7 @@ public:
/** Return whether a status update is needed. /** Return whether a status update is needed.
*/ */
bool statusUpdateNeeded(int64_t nConflictsReceived); bool statusUpdateNeeded();
}; };
#endif // TRANSACTIONRECORD_H #endif // TRANSACTIONRECORD_H

View File

@ -167,7 +167,8 @@ public:
parent->endRemoveRows(); parent->endRemoveRows();
break; break;
case CT_UPDATED: case CT_UPDATED:
emit parent->dataChanged(parent->index(lowerIndex, parent->Status), parent->index(upperIndex-1, parent->Amount)); // Miscellaneous updates -- nothing to do, status update will take care of this, and is only computed for
// visible transactions.
break; break;
} }
} }
@ -188,21 +189,20 @@ public:
// stuck if the core is holding the locks for a longer time - for // stuck if the core is holding the locks for a longer time - for
// example, during a wallet rescan. // example, during a wallet rescan.
// //
// If a status update is needed (blocks or conflicts came in since last check), // If a status update is needed (blocks came in since last check),
// update the status of this transaction from the wallet. Otherwise, // update the status of this transaction from the wallet. Otherwise,
// simply re-use the cached status. // simply re-use the cached status.
TRY_LOCK(cs_main, lockMain); TRY_LOCK(cs_main, lockMain);
if(lockMain) if(lockMain)
{ {
TRY_LOCK(wallet->cs_wallet, lockWallet); TRY_LOCK(wallet->cs_wallet, lockWallet);
if(lockWallet && rec->statusUpdateNeeded(wallet->nConflictsReceived)) if(lockWallet && rec->statusUpdateNeeded())
{ {
std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(rec->hash); std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(rec->hash);
if(mi != wallet->mapWallet.end()) if(mi != wallet->mapWallet.end())
{ {
rec->updateStatus(mi->second); rec->updateStatus(mi->second);
rec->status.cur_num_conflicts = wallet->nConflictsReceived;
} }
} }
} }
@ -368,8 +368,6 @@ QString TransactionTableModel::formatTxType(const TransactionRecord *wtx) const
return tr("Payment to yourself"); return tr("Payment to yourself");
case TransactionRecord::Generated: case TransactionRecord::Generated:
return tr("Mined"); return tr("Mined");
case TransactionRecord::Other:
return tr("Other");
default: default:
return QString(); return QString();
} }
@ -545,13 +543,7 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
return formatTooltip(rec); return formatTooltip(rec);
case Qt::TextAlignmentRole: case Qt::TextAlignmentRole:
return column_alignments[index.column()]; return column_alignments[index.column()];
case Qt::BackgroundColorRole:
if (rec->status.hasConflicting)
return COLOR_HASCONFLICTING_BG;
break;
case Qt::ForegroundRole: case Qt::ForegroundRole:
if (rec->status.hasConflicting)
return COLOR_HASCONFLICTING;
// Non-confirmed (but not immature) as transactions are grey // Non-confirmed (but not immature) as transactions are grey
if(!rec->status.countsForBalance && rec->status.status != TransactionStatus::Immature) if(!rec->status.countsForBalance && rec->status.status != TransactionStatus::Immature)
{ {

View File

@ -164,14 +164,6 @@ void WalletModel::checkBalanceChanged()
void WalletModel::updateTransaction(const QString &hash, int status) void WalletModel::updateTransaction(const QString &hash, int status)
{ {
if (status == CT_GOT_CONFLICT)
{
emit message(tr("Conflict Received"),
tr("WARNING: Transaction may never be confirmed. Its input was seen being spent by another transaction on the network. Wait for confirmation!"),
CClientUIInterface::MSG_WARNING);
return;
}
if(transactionTableModel) if(transactionTableModel)
transactionTableModel->updateTransaction(hash, status); transactionTableModel->updateTransaction(hash, status);

View File

@ -21,8 +21,7 @@ enum ChangeType
{ {
CT_NEW, CT_NEW,
CT_UPDATED, CT_UPDATED,
CT_DELETED, CT_DELETED
CT_GOT_CONFLICT
}; };
/** Signals for UI communication. */ /** Signals for UI communication. */

View File

@ -274,7 +274,7 @@ bool CWallet::SetMaxVersion(int nVersion)
return true; return true;
} }
set<uint256> CWallet::GetConflicts(const uint256& txid, bool includeEquivalent) const set<uint256> CWallet::GetConflicts(const uint256& txid) const
{ {
set<uint256> result; set<uint256> result;
AssertLockHeld(cs_wallet); AssertLockHeld(cs_wallet);
@ -292,8 +292,7 @@ set<uint256> CWallet::GetConflicts(const uint256& txid, bool includeEquivalent)
continue; // No conflict if zero or one spends continue; // No conflict if zero or one spends
range = mapTxSpends.equal_range(txin.prevout); range = mapTxSpends.equal_range(txin.prevout);
for (TxSpends::const_iterator it = range.first; it != range.second; ++it) for (TxSpends::const_iterator it = range.first; it != range.second; ++it)
if (includeEquivalent || !wtx.IsEquivalentTo(mapWallet.at(it->second))) result.insert(it->second);
result.insert(it->second);
} }
return result; return result;
} }
@ -322,7 +321,6 @@ void CWallet::SyncMetaData(pair<TxSpends::iterator, TxSpends::iterator> range)
const uint256& hash = it->second; const uint256& hash = it->second;
CWalletTx* copyTo = &mapWallet[hash]; CWalletTx* copyTo = &mapWallet[hash];
if (copyFrom == copyTo) continue; if (copyFrom == copyTo) continue;
if (!copyFrom->IsEquivalentTo(*copyTo)) continue;
copyTo->mapValue = copyFrom->mapValue; copyTo->mapValue = copyFrom->mapValue;
copyTo->vOrderForm = copyFrom->vOrderForm; copyTo->vOrderForm = copyFrom->vOrderForm;
// fTimeReceivedIsTxTime not copied on purpose // fTimeReceivedIsTxTime not copied on purpose
@ -610,20 +608,6 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet)
// Notify UI of new or updated transaction // Notify UI of new or updated transaction
NotifyTransactionChanged(this, hash, fInsertedNew ? CT_NEW : CT_UPDATED); NotifyTransactionChanged(this, hash, fInsertedNew ? CT_NEW : CT_UPDATED);
// Notifications for existing transactions that now have conflicts with this one
if (fInsertedNew)
{
BOOST_FOREACH(const uint256& conflictHash, wtxIn.GetConflicts(false))
{
CWalletTx& txConflict = mapWallet[conflictHash];
NotifyTransactionChanged(this, conflictHash, CT_UPDATED); //Updates UI table
if (IsFromMe(txConflict) || IsMine(txConflict))
{
NotifyTransactionChanged(this, conflictHash, CT_GOT_CONFLICT); //Throws dialog
}
}
}
// notify an external script when a wallet transaction comes in or is updated // notify an external script when a wallet transaction comes in or is updated
std::string strCmd = GetArg("-walletnotify", ""); std::string strCmd = GetArg("-walletnotify", "");
@ -646,12 +630,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl
AssertLockHeld(cs_wallet); AssertLockHeld(cs_wallet);
bool fExisted = mapWallet.count(tx.GetHash()); bool fExisted = mapWallet.count(tx.GetHash());
if (fExisted && !fUpdate) return false; if (fExisted && !fUpdate) return false;
if (fExisted || IsMine(tx) || IsFromMe(tx))
bool fIsConflicting = IsConflicting(tx);
if (fIsConflicting)
nConflictsReceived++;
if (fExisted || IsMine(tx) || IsFromMe(tx) || fIsConflicting)
{ {
CWalletTx wtx(this,tx); CWalletTx wtx(this,tx);
// Get merkle branch if transaction was found in a block // Get merkle branch if transaction was found in a block
@ -940,7 +919,7 @@ void CWallet::ReacceptWalletTransactions()
int nDepth = wtx.GetDepthInMainChain(); int nDepth = wtx.GetDepthInMainChain();
if (!wtx.IsCoinBase() && nDepth < 0 && (IsMine(wtx) || IsFromMe(wtx))) if (!wtx.IsCoinBase() && nDepth < 0)
{ {
// Try to add to memory pool // Try to add to memory pool
LOCK(mempool.cs); LOCK(mempool.cs);
@ -960,13 +939,13 @@ void CWalletTx::RelayWalletTransaction()
} }
} }
set<uint256> CWalletTx::GetConflicts(bool includeEquivalent) const set<uint256> CWalletTx::GetConflicts() const
{ {
set<uint256> result; set<uint256> result;
if (pwallet != NULL) if (pwallet != NULL)
{ {
uint256 myHash = GetHash(); uint256 myHash = GetHash();
result = pwallet->GetConflicts(myHash, includeEquivalent); result = pwallet->GetConflicts(myHash);
result.erase(myHash); result.erase(myHash);
} }
return result; return result;

View File

@ -144,9 +144,6 @@ public:
MasterKeyMap mapMasterKeys; MasterKeyMap mapMasterKeys;
unsigned int nMasterKeyMaxID; unsigned int nMasterKeyMaxID;
// Increment to cause UI refresh, similar to new block
int64_t nConflictsReceived;
CWallet() CWallet()
{ {
SetNull(); SetNull();
@ -169,7 +166,6 @@ public:
nNextResend = 0; nNextResend = 0;
nLastResend = 0; nLastResend = 0;
nTimeFirstKey = 0; nTimeFirstKey = 0;
nConflictsReceived = 0;
} }
std::map<uint256, CWalletTx> mapWallet; std::map<uint256, CWalletTx> mapWallet;
@ -322,13 +318,6 @@ public:
{ {
return (GetDebit(tx, ISMINE_ALL) > 0); return (GetDebit(tx, ISMINE_ALL) > 0);
} }
bool IsConflicting(const CTransaction& tx) const
{
BOOST_FOREACH(const CTxIn& txin, tx.vin)
if (mapTxSpends.count(txin.prevout))
return true;
return false;
}
int64_t GetDebit(const CTransaction& tx, const isminefilter& filter) const int64_t GetDebit(const CTransaction& tx, const isminefilter& filter) const
{ {
int64_t nDebit = 0; int64_t nDebit = 0;
@ -401,7 +390,7 @@ public:
int GetVersion() { LOCK(cs_wallet); return nWalletVersion; } int GetVersion() { LOCK(cs_wallet); return nWalletVersion; }
// Get wallet transactions that conflict with given transaction (spend same outputs) // Get wallet transactions that conflict with given transaction (spend same outputs)
std::set<uint256> GetConflicts(const uint256& txid, bool includeEquivalent) const; std::set<uint256> GetConflicts(const uint256& txid) const;
/** Address book entry changed. /** Address book entry changed.
* @note called with lock cs_wallet held. * @note called with lock cs_wallet held.
@ -812,7 +801,7 @@ public:
void RelayWalletTransaction(); void RelayWalletTransaction();
std::set<uint256> GetConflicts(bool includeEquivalent=true) const; std::set<uint256> GetConflicts() const;
}; };