aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmiti Uttarwar <amiti@uttarwar.org>2020-04-30 18:20:01 -0700
committerSuhas Daftuar <sdaftuar@gmail.com>2020-07-18 19:00:01 -0400
commitc7eb6b4f1fe5bd76388a023529977674534334a7 (patch)
treeaf43adf8cbb691da6e6b330c2b14926985cb0775
parent2b4b90aa8f0440deacefb5997d7bd1f9f5c591b3 (diff)
Add wtxid to mempool unbroadcast tracking
-rw-r--r--src/net_processing.cpp10
-rw-r--r--src/node/transaction.cpp2
-rw-r--r--src/txmempool.h13
-rw-r--r--src/validation.cpp17
4 files changed, 24 insertions, 18 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 7a58de35d7..6663ece8db 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -830,14 +830,14 @@ void PeerLogicValidation::InitializeNode(CNode *pnode) {
void PeerLogicValidation::ReattemptInitialBroadcast(CScheduler& scheduler) const
{
- std::set<uint256> unbroadcast_txids = m_mempool.GetUnbroadcastTxs();
+ std::map<uint256, uint256> unbroadcast_txids = m_mempool.GetUnbroadcastTxs();
- for (const uint256& txid : unbroadcast_txids) {
+ for (const auto& elem : unbroadcast_txids) {
// Sanity check: all unbroadcast txns should exist in the mempool
- if (m_mempool.exists(txid)) {
- RelayTransaction(txid, *connman);
+ if (m_mempool.exists(elem.first)) {
+ RelayTransaction(elem.first, *connman);
} else {
- m_mempool.RemoveUnbroadcastTx(txid, true);
+ m_mempool.RemoveUnbroadcastTx(elem.first, true);
}
}
diff --git a/src/node/transaction.cpp b/src/node/transaction.cpp
index 3841d8687d..a571e3b02a 100644
--- a/src/node/transaction.cpp
+++ b/src/node/transaction.cpp
@@ -80,7 +80,7 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
if (relay) {
// the mempool tracks locally submitted transactions to make a
// best-effort of initial broadcast
- node.mempool->AddUnbroadcastTx(hashTx);
+ node.mempool->AddUnbroadcastTx(hashTx, tx->GetWitnessHash());
RelayTransaction(hashTx, *node.connman);
}
diff --git a/src/txmempool.h b/src/txmempool.h
index 80cde0750c..d4e9845942 100644
--- a/src/txmempool.h
+++ b/src/txmempool.h
@@ -573,8 +573,11 @@ private:
std::vector<indexed_transaction_set::const_iterator> GetSortedDepthAndScore() const EXCLUSIVE_LOCKS_REQUIRED(cs);
- /** track locally submitted transactions to periodically retry initial broadcast */
- std::set<uint256> m_unbroadcast_txids GUARDED_BY(cs);
+ /**
+ * track locally submitted transactions to periodically retry initial broadcast
+ * map of txid -> wtxid
+ */
+ std::map<uint256, uint256> m_unbroadcast_txids GUARDED_BY(cs);
public:
indirectmap<COutPoint, const CTransaction*> mapNextTx GUARDED_BY(cs);
@@ -734,11 +737,11 @@ public:
size_t DynamicMemoryUsage() const;
/** Adds a transaction to the unbroadcast set */
- void AddUnbroadcastTx(const uint256& txid) {
+ void AddUnbroadcastTx(const uint256& txid, const uint256& wtxid) {
LOCK(cs);
// Sanity Check: the transaction should also be in the mempool
if (exists(txid)) {
- m_unbroadcast_txids.insert(txid);
+ m_unbroadcast_txids[txid] = wtxid;
}
}
@@ -746,7 +749,7 @@ public:
void RemoveUnbroadcastTx(const uint256& txid, const bool unchecked = false);
/** Returns transactions in unbroadcast set */
- std::set<uint256> GetUnbroadcastTxs() const {
+ std::map<uint256, uint256> GetUnbroadcastTxs() const {
LOCK(cs);
return m_unbroadcast_txids;
}
diff --git a/src/validation.cpp b/src/validation.cpp
index b90ff440be..d271be6310 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -5083,19 +5083,22 @@ bool LoadMempool(CTxMemPool& pool)
}
// TODO: remove this try except in v0.22
+ std::map<uint256, uint256> unbroadcast_txids;
try {
- std::set<uint256> unbroadcast_txids;
file >> unbroadcast_txids;
unbroadcast = unbroadcast_txids.size();
-
- for (const auto& txid : unbroadcast_txids) {
- pool.AddUnbroadcastTx(txid);
- }
} catch (const std::exception&) {
// mempool.dat files created prior to v0.21 will not have an
// unbroadcast set. No need to log a failure if parsing fails here.
}
-
+ for (const auto& elem : unbroadcast_txids) {
+ // Don't add unbroadcast transactions that didn't get back into the
+ // mempool.
+ const CTransactionRef& added_tx = pool.get(elem.first);
+ if (added_tx != nullptr) {
+ pool.AddUnbroadcastTx(elem.first, added_tx->GetWitnessHash());
+ }
+ }
} catch (const std::exception& e) {
LogPrintf("Failed to deserialize mempool data on disk: %s. Continuing anyway.\n", e.what());
return false;
@@ -5111,7 +5114,7 @@ bool DumpMempool(const CTxMemPool& pool)
std::map<uint256, CAmount> mapDeltas;
std::vector<TxMempoolInfo> vinfo;
- std::set<uint256> unbroadcast_txids;
+ std::map<uint256, uint256> unbroadcast_txids;
static Mutex dump_mutex;
LOCK(dump_mutex);