Skip to content

Commit 1956113

Browse files
fdovingHyperPeek
authored andcommitted
Backport: Remove useless mapRequest tracking
Manual backport of bitcoin/bitcoin@beef7ec Fixes issue #1114 CVE-2018-17145
1 parent 41a4d8b commit 1956113

10 files changed

Lines changed: 1 addition & 111 deletions

src/net_processing.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,9 +1171,6 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
11711171
}
11721172
}
11731173

1174-
// Track requests for our stuff.
1175-
GetMainSignals().Inventory(inv.hash);
1176-
11771174
if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK || inv.type == MSG_CMPCT_BLOCK || inv.type == MSG_WITNESS_BLOCK)
11781175
break;
11791176
}
@@ -1931,9 +1928,6 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
19311928
pfrom->AskFor(inv);
19321929
}
19331930
}
1934-
1935-
// Track requests for our stuff
1936-
GetMainSignals().Inventory(inv.hash);
19371931
}
19381932
}
19391933

src/qt/guiconstants.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ static const bool DEFAULT_SPLASHSCREEN = true;
2929
#define COLOR_BAREADDRESS QColor(140, 140, 140)
3030
/* Transaction list -- TX status decoration - open until date */
3131
#define COLOR_TX_STATUS_OPENUNTILDATE QColor(64, 64, 255)
32-
/* Transaction list -- TX status decoration - offline */
33-
#define COLOR_TX_STATUS_OFFLINE QColor(192, 192, 192)
3432
/* Transaction list -- TX status decoration - danger, tx needs attention */
3533
#define COLOR_TX_STATUS_DANGER QColor(200, 100, 100)
3634
/* Transaction list -- TX status decoration - default color */

src/qt/transactiondesc.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ QString TransactionDesc::FormatTxStatus(const CWalletTx& wtx)
3737
int nDepth = wtx.GetDepthInMainChain();
3838
if (nDepth < 0)
3939
return tr("conflicted with a transaction with %1 confirmations").arg(-nDepth);
40-
else if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0)
41-
return tr("%1/offline").arg(nDepth);
4240
else if (nDepth == 0)
4341
return tr("0/unconfirmed, %1").arg((wtx.InMempool() ? tr("in memory pool") : tr("not in memory pool"))) + (wtx.isAbandoned() ? ", "+tr("abandoned") : "");
4442
else if (nDepth < 6)
@@ -66,14 +64,6 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
6664
CAmount nNet = nCredit - nDebit;
6765

6866
strHTML += "<b>" + tr("Status") + ":</b> " + FormatTxStatus(wtx);
69-
int nRequests = wtx.GetRequestCount();
70-
if (nRequests != -1)
71-
{
72-
if (nRequests == 0)
73-
strHTML += tr(", has not been successfully broadcast yet");
74-
else if (nRequests > 0)
75-
strHTML += tr(", broadcast through %n node(s)", "", nRequests);
76-
}
7767
strHTML += "<br>";
7868

7969
strHTML += "<b>" + tr("Date") + ":</b> " + (nTime ? GUIUtil::dateTimeStr(nTime) : "") + "<br>";
@@ -312,14 +302,6 @@ QString TransactionDesc::toAssetHTML(CWallet *wallet, CWalletTx &wtx, Transactio
312302

313303
// Status
314304
strHTML += "<b>" + tr("Status") + ":</b> " + FormatTxStatus(wtx);
315-
int nRequests = wtx.GetRequestCount();
316-
if (nRequests != -1)
317-
{
318-
if (nRequests == 0)
319-
strHTML += tr(", has not been successfully broadcast yet");
320-
else if (nRequests > 0)
321-
strHTML += tr(", broadcast through %n node(s)", "", nRequests);
322-
}
323305
strHTML += "<br>";
324306

325307
strHTML += "<b>" + tr("Date") + ":</b> " + (nTime ? GUIUtil::dateTimeStr(nTime) : "") + "<br>";

src/qt/transactionrecord.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,6 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
491491
if (wtx.IsInMainChain())
492492
{
493493
status.matures_in = wtx.GetBlocksToMaturity();
494-
495-
// Check if the block was requested by anyone
496-
if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0)
497-
status.status = TransactionStatus::MaturesWarning;
498494
}
499495
else
500496
{
@@ -512,10 +508,6 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx)
512508
{
513509
status.status = TransactionStatus::Conflicted;
514510
}
515-
else if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0)
516-
{
517-
status.status = TransactionStatus::Offline;
518-
}
519511
else if (status.depth == 0)
520512
{
521513
status.status = TransactionStatus::Unconfirmed;

src/qt/transactionrecord.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,20 @@ class TransactionStatus
1919
public:
2020
TransactionStatus():
2121
countsForBalance(false), sortKey(""),
22-
matures_in(0), status(Offline), depth(0), open_for(0), cur_num_blocks(-1)
22+
matures_in(0), status(Unconfirmed), depth(0), open_for(0), cur_num_blocks(-1)
2323
{ }
2424

2525
enum Status {
2626
Confirmed, /**< Have 6 or more confirmations (normal tx) or fully mature (mined tx) **/
2727
/// Normal (sent/received) transactions
2828
OpenUntilDate, /**< Transaction not yet final, waiting for date */
2929
OpenUntilBlock, /**< Transaction not yet final, waiting for block */
30-
Offline, /**< Not sent to any other nodes **/
3130
Unconfirmed, /**< Not yet mined into a block **/
3231
Confirming, /**< Confirmed, but waiting for the recommended number of confirmations **/
3332
Conflicted, /**< Conflicts with other transaction or mempool **/
3433
Abandoned, /**< Abandoned from the wallet **/
3534
/// Generated (mined) transactions
3635
Immature, /**< Mined but waiting for maturity */
37-
MaturesWarning, /**< Transaction will likely not mature because no nodes have confirmed */
3836
NotAccepted /**< Mined but not accepted */
3937
};
4038

src/qt/transactiontablemodel.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,6 @@ QString TransactionTableModel::formatTxStatus(const TransactionRecord *wtx) cons
315315
case TransactionStatus::OpenUntilDate:
316316
status = tr("Open until %1").arg(GUIUtil::dateTimeStr(wtx->status.open_for));
317317
break;
318-
case TransactionStatus::Offline:
319-
status = tr("Offline");
320-
break;
321318
case TransactionStatus::Unconfirmed:
322319
status = tr("Unconfirmed");
323320
break;
@@ -336,9 +333,6 @@ QString TransactionTableModel::formatTxStatus(const TransactionRecord *wtx) cons
336333
case TransactionStatus::Immature:
337334
status = tr("Immature (%1 confirmations, will be available after %2)").arg(wtx->status.depth).arg(wtx->status.depth + wtx->status.matures_in);
338335
break;
339-
case TransactionStatus::MaturesWarning:
340-
status = tr("This block was not received by any other nodes and will probably not be accepted!");
341-
break;
342336
case TransactionStatus::NotAccepted:
343337
status = tr("Generated but not accepted");
344338
break;
@@ -517,8 +511,6 @@ QVariant TransactionTableModel::txStatusDecoration(const TransactionRecord *wtx)
517511
case TransactionStatus::OpenUntilBlock:
518512
case TransactionStatus::OpenUntilDate:
519513
return COLOR_TX_STATUS_OPENUNTILDATE;
520-
case TransactionStatus::Offline:
521-
return COLOR_TX_STATUS_OFFLINE;
522514
case TransactionStatus::Unconfirmed:
523515
return QIcon(":/icons/transaction_0");
524516
case TransactionStatus::Abandoned:
@@ -541,7 +533,6 @@ QVariant TransactionTableModel::txStatusDecoration(const TransactionRecord *wtx)
541533
int part = (wtx->status.depth * 4 / total) + 1;
542534
return QIcon(QString(":/icons/transaction_%1").arg(part));
543535
}
544-
case TransactionStatus::MaturesWarning:
545536
case TransactionStatus::NotAccepted:
546537
return QIcon(":/icons/transaction_0");
547538
default:

src/validationinterface.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ struct MainSignalsInstance {
2727
boost::signals2::signal<void (const std::shared_ptr<const CBlock> &, const CBlockIndex *pindex, const std::vector<CTransactionRef>&)> BlockConnected;
2828
boost::signals2::signal<void (const std::shared_ptr<const CBlock> &)> BlockDisconnected;
2929
boost::signals2::signal<void (const CBlockLocator &)> SetBestChain;
30-
boost::signals2::signal<void (const uint256 &)> Inventory;
3130
boost::signals2::signal<void (int64_t nBestBlockTime, CConnman* connman)> Broadcast;
3231
boost::signals2::signal<void (const CBlock&, const CValidationState&)> BlockChecked;
3332
boost::signals2::signal<void (const CBlockIndex *, const std::shared_ptr<const CBlock>&)> NewPoWValidBlock;
@@ -70,7 +69,6 @@ void RegisterValidationInterface(CValidationInterface* pwalletIn) {
7069
g_signals.m_internals->BlockConnected.connect(boost::bind(&CValidationInterface::BlockConnected, pwalletIn, _1, _2, _3));
7170
g_signals.m_internals->BlockDisconnected.connect(boost::bind(&CValidationInterface::BlockDisconnected, pwalletIn, _1));
7271
g_signals.m_internals->SetBestChain.connect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
73-
g_signals.m_internals->Inventory.connect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
7472
g_signals.m_internals->Broadcast.connect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1, _2));
7573
g_signals.m_internals->BlockChecked.connect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
7674
g_signals.m_internals->NewPoWValidBlock.connect(boost::bind(&CValidationInterface::NewPoWValidBlock, pwalletIn, _1, _2));
@@ -82,7 +80,6 @@ void RegisterValidationInterface(CValidationInterface* pwalletIn) {
8280
void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
8381
g_signals.m_internals->BlockChecked.disconnect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
8482
g_signals.m_internals->Broadcast.disconnect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1, _2));
85-
g_signals.m_internals->Inventory.disconnect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
8683
g_signals.m_internals->SetBestChain.disconnect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
8784
g_signals.m_internals->TransactionAddedToMempool.disconnect(boost::bind(&CValidationInterface::TransactionAddedToMempool, pwalletIn, _1));
8885
g_signals.m_internals->BlockConnected.disconnect(boost::bind(&CValidationInterface::BlockConnected, pwalletIn, _1, _2, _3));
@@ -97,7 +94,6 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
9794
void UnregisterAllValidationInterfaces() {
9895
g_signals.m_internals->BlockChecked.disconnect_all_slots();
9996
g_signals.m_internals->Broadcast.disconnect_all_slots();
100-
g_signals.m_internals->Inventory.disconnect_all_slots();
10197
g_signals.m_internals->SetBestChain.disconnect_all_slots();
10298
g_signals.m_internals->TransactionAddedToMempool.disconnect_all_slots();
10399
g_signals.m_internals->BlockConnected.disconnect_all_slots();
@@ -129,10 +125,6 @@ void CMainSignals::SetBestChain(const CBlockLocator &locator) {
129125
m_internals->SetBestChain(locator);
130126
}
131127

132-
void CMainSignals::Inventory(const uint256 &hash) {
133-
m_internals->Inventory(hash);
134-
}
135-
136128
void CMainSignals::Broadcast(int64_t nBestBlockTime, CConnman* connman) {
137129
m_internals->Broadcast(nBestBlockTime, connman);
138130
}

src/validationinterface.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ class CValidationInterface {
5353
virtual void BlockDisconnected(const std::shared_ptr<const CBlock> &block) {}
5454
/** Notifies listeners of the new active block chain on-disk. */
5555
virtual void SetBestChain(const CBlockLocator &locator) {}
56-
/** Notifies listeners about an inventory item being seen on the network. */
57-
virtual void Inventory(const uint256 &hash) {}
5856
/** Tells listeners to broadcast their data. */
5957
virtual void ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman) {}
6058
/**
@@ -102,7 +100,6 @@ class CMainSignals {
102100
void BlockConnected(const std::shared_ptr<const CBlock> &, const CBlockIndex *pindex, const std::vector<CTransactionRef> &);
103101
void BlockDisconnected(const std::shared_ptr<const CBlock> &);
104102
void SetBestChain(const CBlockLocator &);
105-
void Inventory(const uint256 &);
106103
void Broadcast(int64_t nBestBlockTime, CConnman* connman);
107104
void BlockChecked(const CBlock&, const CValidationState&);
108105
void NewPoWValidBlock(const CBlockIndex *, const std::shared_ptr<const CBlock>&);

src/wallet/wallet.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,45 +1624,6 @@ int64_t CWalletTx::GetTxTime() const
16241624
return n ? n : nTimeReceived;
16251625
}
16261626

1627-
int CWalletTx::GetRequestCount() const
1628-
{
1629-
// Returns -1 if it wasn't being tracked
1630-
int nRequests = -1;
1631-
{
1632-
LOCK(pwallet->cs_wallet);
1633-
if (IsCoinBase())
1634-
{
1635-
// Generated block
1636-
if (!hashUnset())
1637-
{
1638-
std::map<uint256, int>::const_iterator mi = pwallet->mapRequestCount.find(hashBlock);
1639-
if (mi != pwallet->mapRequestCount.end())
1640-
nRequests = (*mi).second;
1641-
}
1642-
}
1643-
else
1644-
{
1645-
// Did anyone request this transaction?
1646-
std::map<uint256, int>::const_iterator mi = pwallet->mapRequestCount.find(GetHash());
1647-
if (mi != pwallet->mapRequestCount.end())
1648-
{
1649-
nRequests = (*mi).second;
1650-
1651-
// How about the block it's in?
1652-
if (nRequests == 0 && !hashUnset())
1653-
{
1654-
std::map<uint256, int>::const_iterator _mi = pwallet->mapRequestCount.find(hashBlock);
1655-
if (_mi != pwallet->mapRequestCount.end())
1656-
nRequests = (*_mi).second;
1657-
else
1658-
nRequests = 1; // If it's in someone else's block it must have got out
1659-
}
1660-
}
1661-
}
1662-
}
1663-
return nRequests;
1664-
}
1665-
16661627
void CWalletTx::GetAmounts(std::list<COutputEntry>& listReceived,
16671628
std::list<COutputEntry>& listSent, CAmount& nFee, std::string& strSentAccount, const isminefilter& filter) const {
16681629

@@ -3876,9 +3837,6 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CCon
38763837
}
38773838
}
38783839

3879-
// Track how many getdata requests our transaction gets
3880-
mapRequestCount[wtxNew.GetHash()] = 0;
3881-
38823840
if (fBroadcastTransactions)
38833841
{
38843842
// Broadcast

src/wallet/wallet.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,6 @@ class CWalletTx : public CMerkleTx
491491
bool IsTrusted() const;
492492

493493
int64_t GetTxTime() const;
494-
int GetRequestCount() const;
495494

496495
// RelayWalletTransaction may only be called if fBroadcastTransactions!
497496
bool RelayWalletTransaction(CConnman* connman);
@@ -828,7 +827,6 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
828827

829828
int64_t nOrderPosNext;
830829
uint64_t nAccountingEntryNumber;
831-
std::map<uint256, int> mapRequestCount;
832830

833831
std::map<CTxDestination, CAddressBookData> mapAddressBook;
834832

@@ -1099,16 +1097,6 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
10991097

11001098
const std::string& GetAccountName(const CScript& scriptPubKey) const;
11011099

1102-
void Inventory(const uint256 &hash) override
1103-
{
1104-
{
1105-
LOCK(cs_wallet);
1106-
std::map<uint256, int>::iterator mi = mapRequestCount.find(hash);
1107-
if (mi != mapRequestCount.end())
1108-
(*mi).second++;
1109-
}
1110-
}
1111-
11121100
void GetScriptForMining(std::shared_ptr<CReserveScript> &script); // override;
11131101

11141102
unsigned int GetKeyPoolSize()

0 commit comments

Comments
 (0)