Skip to content

Commit c7eb6b4

Browse files
amitiuttarwarsdaftuar
authored andcommitted
Add wtxid to mempool unbroadcast tracking
1 parent 2b4b90a commit c7eb6b4

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

src/net_processing.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -830,14 +830,14 @@ void PeerLogicValidation::InitializeNode(CNode *pnode) {
830830

831831
void PeerLogicValidation::ReattemptInitialBroadcast(CScheduler& scheduler) const
832832
{
833-
std::set<uint256> unbroadcast_txids = m_mempool.GetUnbroadcastTxs();
833+
std::map<uint256, uint256> unbroadcast_txids = m_mempool.GetUnbroadcastTxs();
834834

835-
for (const uint256& txid : unbroadcast_txids) {
835+
for (const auto& elem : unbroadcast_txids) {
836836
// Sanity check: all unbroadcast txns should exist in the mempool
837-
if (m_mempool.exists(txid)) {
838-
RelayTransaction(txid, *connman);
837+
if (m_mempool.exists(elem.first)) {
838+
RelayTransaction(elem.first, *connman);
839839
} else {
840-
m_mempool.RemoveUnbroadcastTx(txid, true);
840+
m_mempool.RemoveUnbroadcastTx(elem.first, true);
841841
}
842842
}
843843

src/node/transaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
8080
if (relay) {
8181
// the mempool tracks locally submitted transactions to make a
8282
// best-effort of initial broadcast
83-
node.mempool->AddUnbroadcastTx(hashTx);
83+
node.mempool->AddUnbroadcastTx(hashTx, tx->GetWitnessHash());
8484

8585
RelayTransaction(hashTx, *node.connman);
8686
}

src/txmempool.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,11 @@ class CTxMemPool
573573

574574
std::vector<indexed_transaction_set::const_iterator> GetSortedDepthAndScore() const EXCLUSIVE_LOCKS_REQUIRED(cs);
575575

576-
/** track locally submitted transactions to periodically retry initial broadcast */
577-
std::set<uint256> m_unbroadcast_txids GUARDED_BY(cs);
576+
/**
577+
* track locally submitted transactions to periodically retry initial broadcast
578+
* map of txid -> wtxid
579+
*/
580+
std::map<uint256, uint256> m_unbroadcast_txids GUARDED_BY(cs);
578581

579582
public:
580583
indirectmap<COutPoint, const CTransaction*> mapNextTx GUARDED_BY(cs);
@@ -734,19 +737,19 @@ class CTxMemPool
734737
size_t DynamicMemoryUsage() const;
735738

736739
/** Adds a transaction to the unbroadcast set */
737-
void AddUnbroadcastTx(const uint256& txid) {
740+
void AddUnbroadcastTx(const uint256& txid, const uint256& wtxid) {
738741
LOCK(cs);
739742
// Sanity Check: the transaction should also be in the mempool
740743
if (exists(txid)) {
741-
m_unbroadcast_txids.insert(txid);
744+
m_unbroadcast_txids[txid] = wtxid;
742745
}
743746
}
744747

745748
/** Removes a transaction from the unbroadcast set */
746749
void RemoveUnbroadcastTx(const uint256& txid, const bool unchecked = false);
747750

748751
/** Returns transactions in unbroadcast set */
749-
std::set<uint256> GetUnbroadcastTxs() const {
752+
std::map<uint256, uint256> GetUnbroadcastTxs() const {
750753
LOCK(cs);
751754
return m_unbroadcast_txids;
752755
}

src/validation.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5083,19 +5083,22 @@ bool LoadMempool(CTxMemPool& pool)
50835083
}
50845084

50855085
// TODO: remove this try except in v0.22
5086+
std::map<uint256, uint256> unbroadcast_txids;
50865087
try {
5087-
std::set<uint256> unbroadcast_txids;
50885088
file >> unbroadcast_txids;
50895089
unbroadcast = unbroadcast_txids.size();
5090-
5091-
for (const auto& txid : unbroadcast_txids) {
5092-
pool.AddUnbroadcastTx(txid);
5093-
}
50945090
} catch (const std::exception&) {
50955091
// mempool.dat files created prior to v0.21 will not have an
50965092
// unbroadcast set. No need to log a failure if parsing fails here.
50975093
}
5098-
5094+
for (const auto& elem : unbroadcast_txids) {
5095+
// Don't add unbroadcast transactions that didn't get back into the
5096+
// mempool.
5097+
const CTransactionRef& added_tx = pool.get(elem.first);
5098+
if (added_tx != nullptr) {
5099+
pool.AddUnbroadcastTx(elem.first, added_tx->GetWitnessHash());
5100+
}
5101+
}
50995102
} catch (const std::exception& e) {
51005103
LogPrintf("Failed to deserialize mempool data on disk: %s. Continuing anyway.\n", e.what());
51015104
return false;
@@ -5111,7 +5114,7 @@ bool DumpMempool(const CTxMemPool& pool)
51115114

51125115
std::map<uint256, CAmount> mapDeltas;
51135116
std::vector<TxMempoolInfo> vinfo;
5114-
std::set<uint256> unbroadcast_txids;
5117+
std::map<uint256, uint256> unbroadcast_txids;
51155118

51165119
static Mutex dump_mutex;
51175120
LOCK(dump_mutex);

0 commit comments

Comments
 (0)