@@ -632,16 +632,25 @@ class CTxMemPool
632
632
*/
633
633
void RemoveStaged (setEntries& stage, bool updateDescendants, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs);
634
634
635
- /* * When adding transactions from a disconnected block back to the mempool,
636
- * new mempool entries may have children in the mempool (which is generally
637
- * not the case when otherwise adding transactions).
638
- * UpdateTransactionsFromBlock() will find child transactions and update the
639
- * descendant state for each transaction in vHashesToUpdate (excluding any
640
- * child transactions present in vHashesToUpdate, which are already accounted
641
- * for). Note: vHashesToUpdate should be the set of transactions from the
642
- * disconnected block that have been accepted back into the mempool.
635
+ /* * UpdateTransactionsFromBlock is called when adding transactions from a
636
+ * disconnected block back to the mempool, new mempool entries may have
637
+ * children in the mempool (which is generally not the case when otherwise
638
+ * adding transactions).
639
+ * @post updated descendant state for descendants of each transaction in
640
+ * vHashesToUpdate (excluding any child transactions present in
641
+ * vHashesToUpdate, which are already accounted for). Updated state
642
+ * includes add fee/size information for such descendants to the
643
+ * parent and updated ancestor state to include the parent.
644
+ *
645
+ * @param[in] vHashesToUpdate The set of txids from the
646
+ * disconnected block that have been accepted back into the mempool.
647
+ * @param[in] ancestor_size_limit The maximum allowed size in virtual
648
+ * bytes of an entry and its ancestors
649
+ * @param[in] ancestor_count_limit The maximum allowed number of
650
+ * transactions including the entry and its ancestors.
643
651
*/
644
- void UpdateTransactionsFromBlock (const std::vector<uint256>& vHashesToUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main) LOCKS_EXCLUDED(m_epoch);
652
+ void UpdateTransactionsFromBlock (const std::vector<uint256>& vHashesToUpdate,
653
+ uint64_t ancestor_size_limit, uint64_t ancestor_count_limit) EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main) LOCKS_EXCLUDED(m_epoch);
645
654
646
655
/* * Try to calculate all in-mempool ancestors of entry.
647
656
* (these are all calculated including the tx itself)
@@ -790,19 +799,38 @@ class CTxMemPool
790
799
/* * UpdateForDescendants is used by UpdateTransactionsFromBlock to update
791
800
* the descendants for a single transaction that has been added to the
792
801
* mempool but may have child transactions in the mempool, eg during a
793
- * chain reorg. setExclude is the set of descendant transactions in the
794
- * mempool that must not be accounted for (because any descendants in
795
- * setExclude were added to the mempool after the transaction being
796
- * updated and hence their state is already reflected in the parent
797
- * state).
802
+ * chain reorg.
803
+ *
804
+ * @pre CTxMemPool::m_children is correct for the given tx and all
805
+ * descendants.
806
+ * @pre cachedDescendants is an accurate cache where each entry has all
807
+ * descendants of the corresponding key, including those that should
808
+ * be removed for violation of ancestor limits.
809
+ * @post if updateIt has any non-excluded descendants, cachedDescendants has
810
+ * a new cache line for updateIt.
811
+ * @post descendants_to_remove has a new entry for any descendant which exceeded
812
+ * ancestor limits relative to updateIt.
798
813
*
799
- * cachedDescendants will be updated with the descendants of the transaction
800
- * being updated, so that future invocations don't need to walk the
801
- * same transaction again, if encountered in another transaction chain.
814
+ * @param[in] updateIt the entry to update for its descendants
815
+ * @param[in,out] cachedDescendants a cache where each line corresponds to all
816
+ * descendants. It will be updated with the descendants of the transaction
817
+ * being updated, so that future invocations don't need to walk the same
818
+ * transaction again, if encountered in another transaction chain.
819
+ * @param[in] setExclude the set of descendant transactions in the mempool
820
+ * that must not be accounted for (because any descendants in setExclude
821
+ * were added to the mempool after the transaction being updated and hence
822
+ * their state is already reflected in the parent state).
823
+ * @param[out] descendants_to_remove Populated with the txids of entries that
824
+ * exceed ancestor limits. It's the responsibility of the caller to
825
+ * removeRecursive them.
826
+ * @param[in] ancestor_size_limit the max number of ancestral bytes allowed
827
+ * for any descendant
828
+ * @param[in] ancestor_count_limit the max number of ancestor transactions
829
+ * allowed for any descendant
802
830
*/
803
- void UpdateForDescendants (txiter updateIt,
804
- cacheMap &cachedDescendants ,
805
- const std::set<uint256> &setExclude ) EXCLUSIVE_LOCKS_REQUIRED(cs);
831
+ void UpdateForDescendants (txiter updateIt, cacheMap& cachedDescendants,
832
+ const std::set<uint256>& setExclude, std::set<uint256>& descendants_to_remove ,
833
+ uint64_t ancestor_size_limit, uint64_t ancestor_count_limit ) EXCLUSIVE_LOCKS_REQUIRED(cs);
806
834
/* * Update ancestors of hash to add/remove it as a descendant transaction. */
807
835
void UpdateAncestorsOf (bool add, txiter hash, setEntries &setAncestors) EXCLUSIVE_LOCKS_REQUIRED(cs);
808
836
/* * Set ancestor state for an entry */
0 commit comments