Skip to content

Commit 0a6f473

Browse files
gladcowUdjinM6
authored andcommitted
Remove dummy confirmations in RPC API and GUI for InstantSend transactions (#2040)
* remove instandsenddepth option * remove CInstantSend::GetConfirmations * Explicit IXlocks processing in the code using GetDepthInMainChain * remove dummy confirmations for IX locks * remove unused constant * Track IS status in TransactionStatus * Highlight IS in tx list * Customize confirmation icons for IS txes * Fix issues: - bring back removed comment; - simplify 2 complex condition to ose `IsTrusted()` function only; - rename `IsLockedIX` function to 'IsLockedByInstantSend`; * Revert condition with IsTrusted() * code style fix * remove dummy confirmations from instantsend.md * fix instantsend.md
1 parent a83ab55 commit 0a6f473

File tree

13 files changed

+111
-148
lines changed

13 files changed

+111
-148
lines changed

doc/instantsend.md

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -25,56 +25,4 @@ When a wallet InstantSend transaction is successfully locked a shell command pro
2525

2626
#### RPC
2727

28-
Details pertaining to an observed "Transaction Lock" can also be retrieved through RPC, it’s important however to understand the underlying mechanism.
29-
30-
By default, the Dash Core daemon will launch using the following constant:
31-
32-
```
33-
static const int DEFAULT_INSTANTSEND_DEPTH = 5;
34-
```
35-
36-
This value can be overridden by passing the following argument to the Dash Core daemon:
37-
38-
```
39-
-instantsenddepth=<n>
40-
```
41-
42-
The key thing to understand is that this value indicates the number of "confirmations" a successful Transaction Lock represents. When Wallet RPC commands which support `minconf` and `addlockconf` parameters (such as `listreceivedbyaddress`) are performed and `addlockconf` is `true`, then `instantsenddepth` attribute is taken into account when returning information about the transaction. In this case the value in `confirmations` field you see through RPC is showing the number of `"Blockchain Confirmations" + "InstantSend Depth"` (assuming the funds were sent via InstantSend).
43-
44-
There is also a field named `instantlock` (that is present in commands such as `listsinceblock`). The value in this field indicates whether a given transaction is locked via InstantSend.
45-
46-
**Examples**
47-
48-
1. `listreceivedbyaddress 0 true`
49-
* InstantSend transaction just occurred:
50-
* confirmations: 5
51-
* InstantSend transaction received one confirmation from blockchain:
52-
* confirmations: 6
53-
* non-InstantSend transaction just occurred:
54-
* confirmations: 0
55-
* non-InstantSend transaction received one confirmation from blockchain:
56-
* confirmations: 1
57-
58-
2. `listreceivedbyaddress 0`
59-
* InstantSend transaction just occurred:
60-
* confirmations: 0
61-
* InstantSend transaction received one confirmation from blockchain:
62-
* confirmations: 1
63-
* non-InstantSend transaction just occurred:
64-
* confirmations: 0
65-
* non-InstantSend transaction received one confirmation from blockchain:
66-
* confirmations: 1
67-
68-
3. `listsinceblock`
69-
* InstantSend transaction just occurred:
70-
* confirmations: 0
71-
* instantlock: true
72-
* InstantSend transaction received one confirmation from blockchain:
73-
* confirmations: 1
74-
* instantlock: true
75-
* non-InstantSend transaction just occurred:
76-
* confirmations: 0
77-
* instantlock: false
78-
* non-InstantSend transaction received one confirmation from blockchain:
79-
* confirmations: 1
80-
* instantlock: false
28+
Details pertaining to an observed "Transaction Lock" can also be retrieved through RPC. There is a boolean field named `instantlock` which indicates whether a given transaction is locked via InstantSend. This field is present in the output of some wallet RPC commands e.g. `listsinceblock`, `gettransaction` etc. as well as in the output of some mempool RPC commands e.g. `getmempoolentry` and a couple of others like `getrawmempool` (for `verbose=true` only).

src/governance-object.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ bool CGovernanceObject::IsCollateralValid(std::string& strError, bool& fMissingC
605605
// GET CONFIRMATIONS FOR TRANSACTION
606606

607607
AssertLockHeld(cs_main);
608-
int nConfirmationsIn = instantsend.GetConfirmations(nCollateralHash);
608+
int nConfirmationsIn = 0;
609609
if (nBlockHash != uint256()) {
610610
BlockMap::iterator mi = mapBlockIndex.find(nBlockHash);
611611
if (mi != mapBlockIndex.end() && (*mi).second) {
@@ -616,7 +616,8 @@ bool CGovernanceObject::IsCollateralValid(std::string& strError, bool& fMissingC
616616
}
617617
}
618618

619-
if(nConfirmationsIn < GOVERNANCE_FEE_CONFIRMATIONS) {
619+
if((nConfirmationsIn < GOVERNANCE_FEE_CONFIRMATIONS) &&
620+
(!instantsend.IsLockedInstantSendTransaction(nCollateralHash))){
620621
strError = strprintf("Collateral requires at least %d confirmations to be relayed throughout the network (it has only %d)", GOVERNANCE_FEE_CONFIRMATIONS, nConfirmationsIn);
621622
if (nConfirmationsIn >= GOVERNANCE_MIN_RELAY_FEE_CONFIRMATIONS) {
622623
fMissingConfirmations = true;

src/init.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,6 @@ std::string HelpMessage(HelpMessageMode mode)
576576

577577
strUsage += HelpMessageGroup(_("InstantSend options:"));
578578
strUsage += HelpMessageOpt("-enableinstantsend=<n>", strprintf(_("Enable InstantSend, show confirmations for locked transactions (0-1, default: %u)"), 1));
579-
strUsage += HelpMessageOpt("-instantsenddepth=<n>", strprintf(_("Show N confirmations for a successfully locked transaction (%u-%u, default: %u)"), MIN_INSTANTSEND_DEPTH, MAX_INSTANTSEND_DEPTH, DEFAULT_INSTANTSEND_DEPTH));
580579
strUsage += HelpMessageOpt("-instantsendnotify=<cmd>", _("Execute command when a wallet InstantSend transaction is successfully locked (%s in cmd is replaced by TxID)"));
581580

582581

@@ -1873,11 +1872,8 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
18731872
#endif // ENABLE_WALLET
18741873

18751874
fEnableInstantSend = GetBoolArg("-enableinstantsend", 1);
1876-
nInstantSendDepth = GetArg("-instantsenddepth", DEFAULT_INSTANTSEND_DEPTH);
1877-
nInstantSendDepth = std::min(std::max(nInstantSendDepth, MIN_INSTANTSEND_DEPTH), MAX_INSTANTSEND_DEPTH);
18781875

18791876
LogPrintf("fLiteMode %d\n", fLiteMode);
1880-
LogPrintf("nInstantSendDepth %d\n", nInstantSendDepth);
18811877
#ifdef ENABLE_WALLET
18821878
LogPrintf("PrivateSend liquidityprovider: %d\n", privateSendClient.nLiquidityProvider);
18831879
LogPrintf("PrivateSend rounds: %d\n", privateSendClient.nPrivateSendRounds);

src/instantx.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ extern CWallet* pwalletMain;
3333
extern CTxMemPool mempool;
3434

3535
bool fEnableInstantSend = true;
36-
int nInstantSendDepth = DEFAULT_INSTANTSEND_DEPTH;
3736
int nCompleteTXLocks;
3837

3938
CInstantSend instantsend;
@@ -838,11 +837,6 @@ int CInstantSend::GetTransactionLockSignatures(const uint256& txHash)
838837
return -1;
839838
}
840839

841-
int CInstantSend::GetConfirmations(const uint256 &nTXHash)
842-
{
843-
return IsLockedInstantSendTransaction(nTXHash) ? nInstantSendDepth : 0;
844-
}
845-
846840
bool CInstantSend::IsTxLockCandidateTimedOut(const uint256& txHash)
847841
{
848842
if(!fEnableInstantSend) return false;

src/instantx.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ extern CInstantSend instantsend;
2626
(1000/2900.0)**5 = 0.004875397277841433
2727
*/
2828

29-
// The INSTANTSEND_DEPTH is the "pseudo block depth" level assigned to locked
30-
// txs to indicate the degree of confidence in their eventual confirmation and
31-
// inability to be double-spent (adjustable via command line argument)
32-
static const int MIN_INSTANTSEND_DEPTH = 0;
33-
static const int MAX_INSTANTSEND_DEPTH = 60;
34-
/// Default number of "pseudo-confirmations" for an InstantSend tx
35-
static const int DEFAULT_INSTANTSEND_DEPTH = 5;
36-
3729
static const int MIN_INSTANTSEND_PROTO_VERSION = 70208;
3830

3931
/// For how long we are going to accept votes/locks
@@ -145,8 +137,6 @@ class CInstantSend
145137
bool IsLockedInstantSendTransaction(const uint256& txHash);
146138
/// Get the actual number of accepted lock signatures
147139
int GetTransactionLockSignatures(const uint256& txHash);
148-
/// Get instantsend confirmations (only)
149-
int GetConfirmations(const uint256 &nTXHash);
150140

151141
/// Remove expired entries from maps
152142
void CheckAndRemove();

src/qt/guiconstants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ static const bool DEFAULT_SPLASHSCREEN = true;
3434
#define COLOR_TX_STATUS_DANGER QColor(200, 100, 100)
3535
/* Transaction list -- TX status decoration - default color */
3636
#define COLOR_BLACK QColor(0, 0, 0)
37+
/* Transaction list -- TX status decoration - LockedByInstantSend color */
38+
#define COLOR_TX_STATUS_LOCKED QColor(0, 128, 255)
3739

3840
/* Tooltips longer than this (in characters) are converted into rich text,
3941
so that they can be word-wrapped.

src/qt/transactionrecord.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
291291
}
292292
else
293293
{
294+
status.lockedByInstantSend = wtx.IsLockedByInstantSend();
294295
if (status.depth < 0)
295296
{
296297
status.status = TransactionStatus::Conflicted;

src/qt/transactionrecord.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class TransactionStatus
4242

4343
/// Transaction counts towards available balance
4444
bool countsForBalance;
45+
/// Transaction was locked via InstantSend
46+
bool lockedByInstantSend;
4547
/// Sorting key based on status
4648
std::string sortKey;
4749

src/qt/transactiontablemodel.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,24 @@ QString TransactionTableModel::formatTxAmount(const TransactionRecord *wtx, bool
484484
return QString(str);
485485
}
486486

487+
QIcon IconWithShiftedColor(const QString& filename, bool shift)
488+
{
489+
if (!shift)
490+
return QIcon(filename);
491+
492+
QImage img(filename);
493+
img = img.convertToFormat(QImage::Format_ARGB32);
494+
for (int x = img.width(); x--; )
495+
{
496+
for (int y = img.height(); y--; )
497+
{
498+
const QRgb rgb = img.pixel(x, y);
499+
img.setPixel(x, y, qRgba(qRed(rgb), qGreen(rgb), qBlue(rgb)+128, qAlpha(rgb)));
500+
}
501+
}
502+
return QIcon(QPixmap::fromImage(img));
503+
}
504+
487505
QVariant TransactionTableModel::txStatusDecoration(const TransactionRecord *wtx) const
488506
{
489507
QString theme = GUIUtil::getThemeName();
@@ -495,17 +513,19 @@ QVariant TransactionTableModel::txStatusDecoration(const TransactionRecord *wtx)
495513
case TransactionStatus::Offline:
496514
return COLOR_TX_STATUS_OFFLINE;
497515
case TransactionStatus::Unconfirmed:
516+
// TODO: use special icon for InstantSend 0-conf
498517
return QIcon(":/icons/" + theme + "/transaction_0");
499518
case TransactionStatus::Abandoned:
500519
return QIcon(":/icons/" + theme + "/transaction_abandoned");
501520
case TransactionStatus::Confirming:
502521
switch(wtx->status.depth)
503522
{
504-
case 1: return QIcon(":/icons/" + theme + "/transaction_1");
505-
case 2: return QIcon(":/icons/" + theme + "/transaction_2");
506-
case 3: return QIcon(":/icons/" + theme + "/transaction_3");
507-
case 4: return QIcon(":/icons/" + theme + "/transaction_4");
508-
default: return QIcon(":/icons/" + theme + "/transaction_5");
523+
// TODO: use special icons for InstantSend instead of color shifting
524+
case 1: return IconWithShiftedColor(":/icons/" + theme + "/transaction_1", wtx->status.lockedByInstantSend);
525+
case 2: return IconWithShiftedColor(":/icons/" + theme + "/transaction_2", wtx->status.lockedByInstantSend);
526+
case 3: return IconWithShiftedColor(":/icons/" + theme + "/transaction_3", wtx->status.lockedByInstantSend);
527+
case 4: return IconWithShiftedColor(":/icons/" + theme + "/transaction_4", wtx->status.lockedByInstantSend);
528+
default: return IconWithShiftedColor(":/icons/" + theme + "/transaction_5", wtx->status.lockedByInstantSend);
509529
};
510530
case TransactionStatus::Confirmed:
511531
return QIcon(":/icons/" + theme + "/transaction_confirmed");
@@ -608,6 +628,10 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
608628
{
609629
return COLOR_TX_STATUS_DANGER;
610630
}
631+
if(rec->status.lockedByInstantSend)
632+
{
633+
return COLOR_TX_STATUS_LOCKED;
634+
}
611635
// Non-confirmed (but not immature) as transactions are grey
612636
if(!rec->status.countsForBalance && rec->status.status != TransactionStatus::Immature)
613637
{

src/qt/walletmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ bool WalletModel::transactionCanBeAbandoned(uint256 hash) const
754754
{
755755
LOCK2(cs_main, wallet->cs_wallet);
756756
const CWalletTx *wtx = wallet->GetWalletTx(hash);
757-
if (!wtx || wtx->isAbandoned() || wtx->GetDepthInMainChain() > 0 || wtx->InMempool())
757+
if (!wtx || wtx->isAbandoned() || wtx->GetDepthInMainChain() > 0 || wtx->IsLockedByInstantSend() || wtx->InMempool())
758758
return false;
759759
return true;
760760
}

0 commit comments

Comments
 (0)