Skip to content

Commit f51cccd

Browse files
committed
revert to just tracking txid
1 parent b62fbf9 commit f51cccd

File tree

4 files changed

+22
-26
lines changed

4 files changed

+22
-26
lines changed

src/net_processing.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -851,15 +851,16 @@ void PeerLogicValidation::InitializeNode(CNode *pnode) {
851851

852852
void PeerLogicValidation::ReattemptInitialBroadcast(CScheduler& scheduler) const
853853
{
854-
std::map<uint256, uint256> unbroadcast_txids = m_mempool.GetUnbroadcastTxs();
854+
std::set<uint256> unbroadcast_txids = m_mempool.GetUnbroadcastTxs();
855855

856-
for (const auto& elem : unbroadcast_txids) {
857-
// Sanity check: all unbroadcast txns should exist in the mempool
858-
if (m_mempool.exists(elem.first)) {
856+
for (const auto& txid : unbroadcast_txids) {
857+
CTransactionRef tx = m_mempool.get(txid);
858+
859+
if (tx != nullptr) {
859860
LOCK(cs_main);
860-
RelayTransaction(elem.first, elem.second, *connman);
861+
RelayTransaction(txid, tx->GetWitnessHash(), *connman);
861862
} else {
862-
m_mempool.RemoveUnbroadcastTx(elem.first, true);
863+
m_mempool.RemoveUnbroadcastTx(txid, true);
863864
}
864865
}
865866

src/node/transaction.cpp

+1-1
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, tx->GetWitnessHash());
83+
node.mempool->AddUnbroadcastTx(hashTx);
8484

8585
LOCK(cs_main);
8686
RelayTransaction(hashTx, tx->GetWitnessHash(), *node.connman);

src/txmempool.h

+8-10
Original file line numberDiff line numberDiff line change
@@ -574,10 +574,9 @@ class CTxMemPool
574574
std::vector<indexed_transaction_set::const_iterator> GetSortedDepthAndScore() const EXCLUSIVE_LOCKS_REQUIRED(cs);
575575

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

582581
public:
583582
indirectmap<COutPoint, const CTransaction*> mapNextTx GUARDED_BY(cs);
@@ -737,19 +736,18 @@ class CTxMemPool
737736
size_t DynamicMemoryUsage() const;
738737

739738
/** Adds a transaction to the unbroadcast set */
740-
void AddUnbroadcastTx(const uint256& txid, const uint256& wtxid) {
739+
void AddUnbroadcastTx(const uint256& txid) {
741740
LOCK(cs);
742-
// Sanity Check: the transaction should also be in the mempool
743-
if (exists(txid)) {
744-
m_unbroadcast_txids[txid] = wtxid;
745-
}
746-
}
741+
// Sanity check the transaction is in the mempool & insert into
742+
// unbroadcast set.
743+
if (exists(txid)) m_unbroadcast_txids.insert(txid);
744+
};
747745

748746
/** Removes a transaction from the unbroadcast set */
749747
void RemoveUnbroadcastTx(const uint256& txid, const bool unchecked = false);
750748

751749
/** Returns transactions in unbroadcast set */
752-
std::map<uint256, uint256> GetUnbroadcastTxs() const {
750+
std::set<uint256> GetUnbroadcastTxs() const {
753751
LOCK(cs);
754752
return m_unbroadcast_txids;
755753
}

src/validation.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -5084,21 +5084,18 @@ bool LoadMempool(CTxMemPool& pool)
50845084
}
50855085

50865086
// TODO: remove this try except in v0.22
5087-
std::map<uint256, uint256> unbroadcast_txids;
5087+
std::set<uint256> unbroadcast_txids;
50885088
try {
50895089
file >> unbroadcast_txids;
50905090
unbroadcast = unbroadcast_txids.size();
50915091
} catch (const std::exception&) {
50925092
// mempool.dat files created prior to v0.21 will not have an
50935093
// unbroadcast set. No need to log a failure if parsing fails here.
50945094
}
5095-
for (const auto& elem : unbroadcast_txids) {
5096-
// Don't add unbroadcast transactions that didn't get back into the
5097-
// mempool.
5098-
const CTransactionRef& added_tx = pool.get(elem.first);
5099-
if (added_tx != nullptr) {
5100-
pool.AddUnbroadcastTx(elem.first, added_tx->GetWitnessHash());
5101-
}
5095+
for (const auto& txid : unbroadcast_txids) {
5096+
// Ensure transactions were accepted to mempool then add to
5097+
// unbroadcast set.
5098+
if (pool.get(txid) != nullptr) pool.AddUnbroadcastTx(txid);
51025099
}
51035100
} catch (const std::exception& e) {
51045101
LogPrintf("Failed to deserialize mempool data on disk: %s. Continuing anyway.\n", e.what());
@@ -5115,7 +5112,7 @@ bool DumpMempool(const CTxMemPool& pool)
51155112

51165113
std::map<uint256, CAmount> mapDeltas;
51175114
std::vector<TxMempoolInfo> vinfo;
5118-
std::map<uint256, uint256> unbroadcast_txids;
5115+
std::set<uint256> unbroadcast_txids;
51195116

51205117
static Mutex dump_mutex;
51215118
LOCK(dump_mutex);

0 commit comments

Comments
 (0)