@@ -198,6 +198,22 @@ struct mempoolentry_txid
198
198
}
199
199
};
200
200
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
+
201
217
/* * \class CompareTxMemPoolEntryByDescendantScore
202
218
*
203
219
* Sort an entry by max(score/size of entry's tx, score/size with all descendants).
@@ -318,6 +334,7 @@ class CompareTxMemPoolEntryByAncestorFee
318
334
struct descendant_score {};
319
335
struct entry_time {};
320
336
struct ancestor_score {};
337
+ struct index_by_wtxid {};
321
338
322
339
class CBlockPolicyEstimator ;
323
340
@@ -383,8 +400,9 @@ class SaltedTxidHasher
383
400
*
384
401
* CTxMemPool::mapTx, and CTxMemPoolEntry bookkeeping:
385
402
*
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)
388
406
* - descendant feerate [we use max(feerate of tx, feerate of tx with all descendants)]
389
407
* - time in mempool
390
408
* - ancestor feerate [we use min(feerate of tx, feerate of tx with all unconfirmed ancestors)]
@@ -469,6 +487,12 @@ class CTxMemPool
469
487
boost::multi_index::indexed_by<
470
488
// sorted by txid
471
489
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
+ >,
472
496
// sorted by fee rate
473
497
boost::multi_index::ordered_non_unique<
474
498
boost::multi_index::tag<descendant_score>,
@@ -586,7 +610,7 @@ class CTxMemPool
586
610
587
611
void clear ();
588
612
void _clear () EXCLUSIVE_LOCKS_REQUIRED(cs); // lock free
589
- bool CompareDepthAndScore (const uint256& hasha, const uint256& hashb);
613
+ bool CompareDepthAndScore (const uint256& hasha, const uint256& hashb, bool wtxid= false );
590
614
void queryHashes (std::vector<uint256>& vtxid) const ;
591
615
bool isSpent (const COutPoint& outpoint) const ;
592
616
unsigned int GetTransactionsUpdated () const ;
@@ -689,14 +713,22 @@ class CTxMemPool
689
713
return totalTxSize;
690
714
}
691
715
692
- bool exists (const uint256& hash) const
716
+ bool exists (const uint256& hash, bool wtxid= false ) const
693
717
{
694
718
LOCK (cs);
719
+ if (wtxid) {
720
+ return (mapTx.get <index_by_wtxid>().count (hash) != 0 );
721
+ }
695
722
return (mapTx.count (hash) != 0 );
696
723
}
697
724
698
725
CTransactionRef get (const uint256& hash) const ;
699
- TxMempoolInfo info (const uint256& hash) const ;
726
+ txiter get_iter_from_wtxid (const uint256& wtxid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
727
+ {
728
+ AssertLockHeld (cs);
729
+ return mapTx.project <0 >(mapTx.get <index_by_wtxid>().find (wtxid));
730
+ }
731
+ TxMempoolInfo info (const uint256& hash, bool wtxid=false ) const ;
700
732
std::vector<TxMempoolInfo> infoAll () const ;
701
733
702
734
size_t DynamicMemoryUsage () const ;
0 commit comments