Skip to content

Commit

Permalink
revert to just tracking txid
Browse files Browse the repository at this point in the history
  • Loading branch information
amitiuttarwar committed Jul 28, 2020
1 parent b62fbf9 commit f51cccd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
13 changes: 7 additions & 6 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,15 +851,16 @@ void PeerLogicValidation::InitializeNode(CNode *pnode) {

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

for (const auto& elem : unbroadcast_txids) {
// Sanity check: all unbroadcast txns should exist in the mempool
if (m_mempool.exists(elem.first)) {
for (const auto& txid : unbroadcast_txids) {
CTransactionRef tx = m_mempool.get(txid);

if (tx != nullptr) {
LOCK(cs_main);
RelayTransaction(elem.first, elem.second, *connman);
RelayTransaction(txid, tx->GetWitnessHash(), *connman);
} else {
m_mempool.RemoveUnbroadcastTx(elem.first, true);
m_mempool.RemoveUnbroadcastTx(txid, true);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/node/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, tx->GetWitnessHash());
node.mempool->AddUnbroadcastTx(hashTx);

LOCK(cs_main);
RelayTransaction(hashTx, tx->GetWitnessHash(), *node.connman);
Expand Down
18 changes: 8 additions & 10 deletions src/txmempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -574,10 +574,9 @@ class CTxMemPool
std::vector<indexed_transaction_set::const_iterator> GetSortedDepthAndScore() const EXCLUSIVE_LOCKS_REQUIRED(cs);

/**
* track locally submitted transactions to periodically retry initial broadcast
* map of txid -> wtxid
* Track locally submitted transactions to periodically retry initial broadcast.
*/
std::map<uint256, uint256> m_unbroadcast_txids GUARDED_BY(cs);
std::set<uint256> m_unbroadcast_txids GUARDED_BY(cs);

public:
indirectmap<COutPoint, const CTransaction*> mapNextTx GUARDED_BY(cs);
Expand Down Expand Up @@ -737,19 +736,18 @@ class CTxMemPool
size_t DynamicMemoryUsage() const;

/** Adds a transaction to the unbroadcast set */
void AddUnbroadcastTx(const uint256& txid, const uint256& wtxid) {
void AddUnbroadcastTx(const uint256& txid) {
LOCK(cs);
// Sanity Check: the transaction should also be in the mempool
if (exists(txid)) {
m_unbroadcast_txids[txid] = wtxid;
}
}
// Sanity check the transaction is in the mempool & insert into
// unbroadcast set.
if (exists(txid)) m_unbroadcast_txids.insert(txid);
};

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

/** Returns transactions in unbroadcast set */
std::map<uint256, uint256> GetUnbroadcastTxs() const {
std::set<uint256> GetUnbroadcastTxs() const {
LOCK(cs);
return m_unbroadcast_txids;
}
Expand Down
15 changes: 6 additions & 9 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5084,21 +5084,18 @@ bool LoadMempool(CTxMemPool& pool)
}

// TODO: remove this try except in v0.22
std::map<uint256, uint256> unbroadcast_txids;
std::set<uint256> unbroadcast_txids;
try {
file >> unbroadcast_txids;
unbroadcast = unbroadcast_txids.size();
} 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());
}
for (const auto& txid : unbroadcast_txids) {
// Ensure transactions were accepted to mempool then add to
// unbroadcast set.
if (pool.get(txid) != nullptr) pool.AddUnbroadcastTx(txid);
}
} catch (const std::exception& e) {
LogPrintf("Failed to deserialize mempool data on disk: %s. Continuing anyway.\n", e.what());
Expand All @@ -5115,7 +5112,7 @@ bool DumpMempool(const CTxMemPool& pool)

std::map<uint256, CAmount> mapDeltas;
std::vector<TxMempoolInfo> vinfo;
std::map<uint256, uint256> unbroadcast_txids;
std::set<uint256> unbroadcast_txids;

static Mutex dump_mutex;
LOCK(dump_mutex);
Expand Down

0 comments on commit f51cccd

Please sign in to comment.