diff --git a/src/txmempool.h b/src/txmempool.h --- a/src/txmempool.h +++ b/src/txmempool.h @@ -808,7 +808,8 @@ /** Adds a transaction to the unbroadcast set */ void AddUnbroadcastTx(const TxId &txid) { LOCK(cs); - // Sanity Check: the transaction should also be in the mempool + // Sanity check the transaction is in the mempool & insert into + // unbroadcast set. if (exists(txid)) { m_unbroadcast_txids.insert(txid); } diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -5798,18 +5798,21 @@ // TODO: remove this try...catch after May 15th 2021, // when no one is running v0.22.11 or lower anymore. // This will be done by backporting PR20854. + std::set unbroadcast_txids; try { - std::set 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.22.12 will not have an // unbroadcast set. No need to log a failure if parsing fails here. } - + 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",