mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-21 17:42:37 +02:00
[mempool] Revert unbroadcast set to tracking just txid
When I originally implemented the unbroadcast set in 18038, it just tracked txids. After 18038 was merged, I offered a patch to 18044 to make the unbroadcast changes compatible with wtxid relay. In this patch, I updated `unbroadcast_txids` to a map of txid -> wtxid. Post merge review comments shed light on the fact that this update was unnecessary, and distracting. So, this commit updates the unbroadcast ids back to a set.
This commit is contained in:
parent
23d3ae7acc
commit
cb79b9dbf4
@ -889,15 +889,16 @@ void PeerLogicValidation::InitializeNode(CNode *pnode) {
|
|||||||
|
|
||||||
void PeerLogicValidation::ReattemptInitialBroadcast(CScheduler& scheduler) const
|
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) {
|
for (const auto& txid : unbroadcast_txids) {
|
||||||
// Sanity check: all unbroadcast txns should exist in the mempool
|
CTransactionRef tx = m_mempool.get(txid);
|
||||||
if (m_mempool.exists(elem.first)) {
|
|
||||||
|
if (tx != nullptr) {
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
RelayTransaction(elem.first, elem.second, m_connman);
|
RelayTransaction(txid, tx->GetWitnessHash(), m_connman);
|
||||||
} else {
|
} else {
|
||||||
m_mempool.RemoveUnbroadcastTx(elem.first, true);
|
m_mempool.RemoveUnbroadcastTx(txid, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
|
|||||||
if (relay) {
|
if (relay) {
|
||||||
// the mempool tracks locally submitted transactions to make a
|
// the mempool tracks locally submitted transactions to make a
|
||||||
// best-effort of initial broadcast
|
// best-effort of initial broadcast
|
||||||
node.mempool->AddUnbroadcastTx(hashTx, tx->GetWitnessHash());
|
node.mempool->AddUnbroadcastTx(hashTx);
|
||||||
|
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
RelayTransaction(hashTx, tx->GetWitnessHash(), *node.connman);
|
RelayTransaction(hashTx, tx->GetWitnessHash(), *node.connman);
|
||||||
|
@ -574,10 +574,9 @@ private:
|
|||||||
std::vector<indexed_transaction_set::const_iterator> GetSortedDepthAndScore() const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
std::vector<indexed_transaction_set::const_iterator> GetSortedDepthAndScore() const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* track locally submitted transactions to periodically retry initial broadcast
|
* Track locally submitted transactions to periodically retry initial broadcast.
|
||||||
* map of txid -> wtxid
|
|
||||||
*/
|
*/
|
||||||
std::map<uint256, uint256> m_unbroadcast_txids GUARDED_BY(cs);
|
std::set<uint256> m_unbroadcast_txids GUARDED_BY(cs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
indirectmap<COutPoint, const CTransaction*> mapNextTx GUARDED_BY(cs);
|
indirectmap<COutPoint, const CTransaction*> mapNextTx GUARDED_BY(cs);
|
||||||
@ -739,19 +738,20 @@ public:
|
|||||||
size_t DynamicMemoryUsage() const;
|
size_t DynamicMemoryUsage() const;
|
||||||
|
|
||||||
/** Adds a transaction to the unbroadcast set */
|
/** Adds a transaction to the unbroadcast set */
|
||||||
void AddUnbroadcastTx(const uint256& txid, const uint256& wtxid) {
|
void AddUnbroadcastTx(const uint256& txid)
|
||||||
|
{
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
// Sanity Check: the transaction should also be in the mempool
|
// Sanity check the transaction is in the mempool & insert into
|
||||||
if (exists(txid)) {
|
// unbroadcast set.
|
||||||
m_unbroadcast_txids[txid] = wtxid;
|
if (exists(txid)) m_unbroadcast_txids.insert(txid);
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
|
||||||
/** Removes a transaction from the unbroadcast set */
|
/** Removes a transaction from the unbroadcast set */
|
||||||
void RemoveUnbroadcastTx(const uint256& txid, const bool unchecked = false);
|
void RemoveUnbroadcastTx(const uint256& txid, const bool unchecked = false);
|
||||||
|
|
||||||
/** Returns transactions in unbroadcast set */
|
/** Returns transactions in unbroadcast set */
|
||||||
std::map<uint256, uint256> GetUnbroadcastTxs() const {
|
std::set<uint256> GetUnbroadcastTxs() const
|
||||||
|
{
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
return m_unbroadcast_txids;
|
return m_unbroadcast_txids;
|
||||||
}
|
}
|
||||||
|
@ -5116,7 +5116,7 @@ bool LoadMempool(CTxMemPool& pool)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove this try except in v0.22
|
// TODO: remove this try except in v0.22
|
||||||
std::map<uint256, uint256> unbroadcast_txids;
|
std::set<uint256> unbroadcast_txids;
|
||||||
try {
|
try {
|
||||||
file >> unbroadcast_txids;
|
file >> unbroadcast_txids;
|
||||||
unbroadcast = unbroadcast_txids.size();
|
unbroadcast = unbroadcast_txids.size();
|
||||||
@ -5124,13 +5124,10 @@ bool LoadMempool(CTxMemPool& pool)
|
|||||||
// mempool.dat files created prior to v0.21 will not have an
|
// mempool.dat files created prior to v0.21 will not have an
|
||||||
// unbroadcast set. No need to log a failure if parsing fails here.
|
// unbroadcast set. No need to log a failure if parsing fails here.
|
||||||
}
|
}
|
||||||
for (const auto& elem : unbroadcast_txids) {
|
for (const auto& txid : unbroadcast_txids) {
|
||||||
// Don't add unbroadcast transactions that didn't get back into the
|
// Ensure transactions were accepted to mempool then add to
|
||||||
// mempool.
|
// unbroadcast set.
|
||||||
const CTransactionRef& added_tx = pool.get(elem.first);
|
if (pool.get(txid) != nullptr) pool.AddUnbroadcastTx(txid);
|
||||||
if (added_tx != nullptr) {
|
|
||||||
pool.AddUnbroadcastTx(elem.first, added_tx->GetWitnessHash());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
LogPrintf("Failed to deserialize mempool data on disk: %s. Continuing anyway.\n", e.what());
|
LogPrintf("Failed to deserialize mempool data on disk: %s. Continuing anyway.\n", e.what());
|
||||||
@ -5147,7 +5144,7 @@ bool DumpMempool(const CTxMemPool& pool)
|
|||||||
|
|
||||||
std::map<uint256, CAmount> mapDeltas;
|
std::map<uint256, CAmount> mapDeltas;
|
||||||
std::vector<TxMempoolInfo> vinfo;
|
std::vector<TxMempoolInfo> vinfo;
|
||||||
std::map<uint256, uint256> unbroadcast_txids;
|
std::set<uint256> unbroadcast_txids;
|
||||||
|
|
||||||
static Mutex dump_mutex;
|
static Mutex dump_mutex;
|
||||||
LOCK(dump_mutex);
|
LOCK(dump_mutex);
|
||||||
|
Loading…
Reference in New Issue
Block a user