@@ -198,6 +198,22 @@ struct mempoolentry_txid
198198 }
199199};
200200
201+ // extracts a transaction witness-hash from CTxMemPoolEntry or CTransactionRef
202+ struct mempoolentry_wtxid
203+ {
204+ typedef uint256 result_type;
205+ result_type operator () (const CTxMemPoolEntry &entry) const
206+ {
207+ return entry.GetTx ().GetWitnessHash ();
208+ }
209+
210+ result_type operator () (const CTransactionRef& tx) const
211+ {
212+ return tx->GetWitnessHash ();
213+ }
214+ };
215+
216+
201217/* * \class CompareTxMemPoolEntryByDescendantScore
202218 *
203219 * Sort an entry by max(score/size of entry's tx, score/size with all descendants).
@@ -318,6 +334,7 @@ class CompareTxMemPoolEntryByAncestorFee
318334struct descendant_score {};
319335struct entry_time {};
320336struct ancestor_score {};
337+ struct index_by_wtxid {};
321338
322339class CBlockPolicyEstimator ;
323340
@@ -383,8 +400,9 @@ class SaltedTxidHasher
383400 *
384401 * CTxMemPool::mapTx, and CTxMemPoolEntry bookkeeping:
385402 *
386- * mapTx is a boost::multi_index that sorts the mempool on 4 criteria:
387- * - transaction hash
403+ * mapTx is a boost::multi_index that sorts the mempool on 5 criteria:
404+ * - transaction hash (txid)
405+ * - witness-transaction hash (wtxid)
388406 * - descendant feerate [we use max(feerate of tx, feerate of tx with all descendants)]
389407 * - time in mempool
390408 * - ancestor feerate [we use min(feerate of tx, feerate of tx with all unconfirmed ancestors)]
@@ -469,6 +487,12 @@ class CTxMemPool
469487 boost::multi_index::indexed_by<
470488 // sorted by txid
471489 boost::multi_index::hashed_unique<mempoolentry_txid, SaltedTxidHasher>,
490+ // sorted by wtxid
491+ boost::multi_index::hashed_unique<
492+ boost::multi_index::tag<index_by_wtxid>,
493+ mempoolentry_wtxid,
494+ SaltedTxidHasher
495+ >,
472496 // sorted by fee rate
473497 boost::multi_index::ordered_non_unique<
474498 boost::multi_index::tag<descendant_score>,
@@ -583,7 +607,7 @@ class CTxMemPool
583607
584608 void clear ();
585609 void _clear () EXCLUSIVE_LOCKS_REQUIRED(cs); // lock free
586- bool CompareDepthAndScore (const uint256& hasha, const uint256& hashb);
610+ bool CompareDepthAndScore (const uint256& hasha, const uint256& hashb, bool wtxid= false );
587611 void queryHashes (std::vector<uint256>& vtxid) const ;
588612 bool isSpent (const COutPoint& outpoint) const ;
589613 unsigned int GetTransactionsUpdated () const ;
@@ -686,14 +710,22 @@ class CTxMemPool
686710 return totalTxSize;
687711 }
688712
689- bool exists (const uint256& hash) const
713+ bool exists (const uint256& hash, bool wtxid= false ) const
690714 {
691715 LOCK (cs);
716+ if (wtxid) {
717+ return (mapTx.get <index_by_wtxid>().count (hash) != 0 );
718+ }
692719 return (mapTx.count (hash) != 0 );
693720 }
694721
695722 CTransactionRef get (const uint256& hash) const ;
696- TxMempoolInfo info (const uint256& hash) const ;
723+ txiter get_iter_from_wtxid (const uint256& wtxid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
724+ {
725+ AssertLockHeld (cs);
726+ return mapTx.project <0 >(mapTx.get <index_by_wtxid>().find (wtxid));
727+ }
728+ TxMempoolInfo info (const uint256& hash, bool wtxid=false ) const ;
697729 std::vector<TxMempoolInfo> infoAll () const ;
698730
699731 size_t DynamicMemoryUsage () const ;
0 commit comments