@@ -668,7 +668,10 @@ class SearchCandidateFinder
668
668
SetType und;
669
669
/* * (Only when inc is not empty) The best feerate of any superset of inc that is also a
670
670
* subset of (inc | und), without requiring it to be topologically valid. It forms a
671
- * conservative upper bound on how good a set this work item can give rise to. */
671
+ * conservative upper bound on how good a set this work item can give rise to.
672
+ * Transactions whose feerate is below best's are ignored when determining this value,
673
+ * which means it may technically be an underestimate, but if so, this work item
674
+ * cannot result in something that beats best anyway. */
672
675
FeeFrac pot_feerate;
673
676
674
677
/* * Construct a new work item. */
@@ -711,8 +714,16 @@ class SearchCandidateFinder
711
714
/* * Local copy of the iteration limit. */
712
715
uint64_t iterations_left = max_iterations;
713
716
717
+ /* * The set of transactions in m_todo which have feerate > best's. */
718
+ SetType imp = m_todo;
719
+ while (imp.Any ()) {
720
+ ClusterIndex check = imp.Last ();
721
+ if (m_sorted_depgraph.FeeRate (check) >> best.feerate ) break ;
722
+ imp.Reset (check);
723
+ }
724
+
714
725
/* * Internal function to add an item to the queue of elements to explore if there are any
715
- * transactions left to split on, and to update best.
726
+ * transactions left to split on, and to update best/imp .
716
727
*
717
728
* - inc: the "inc" value for the new work item (must be topological).
718
729
* - und: the "und" value for the new work item ((inc | und) must be topological).
@@ -722,8 +733,11 @@ class SearchCandidateFinder
722
733
* pot_feerate. It starts off equal to inc. */
723
734
auto pot = inc;
724
735
if (!inc.feerate .IsEmpty ()) {
725
- // Add entries to pot.
726
- for (auto pos : und) {
736
+ // Add entries to pot. We iterate over all undecided transactions whose feerate is
737
+ // higher than best. While undecided transactions of lower feerate may improve pot,
738
+ // the resulting pot feerate cannot possibly exceed best's (and this item will be
739
+ // skipped in split_fn anyway).
740
+ for (auto pos : imp & und) {
727
741
// Determine if adding transaction pos to pot (ignoring topology) would improve
728
742
// it. If not, we're done updating pot. This relies on the fact that
729
743
// m_sorted_depgraph, and thus the transactions iterated over, are in decreasing
@@ -735,6 +749,12 @@ class SearchCandidateFinder
735
749
// If inc's feerate is better than best's, remember it as our new best.
736
750
if (inc.feerate > best.feerate ) {
737
751
best = inc;
752
+ // See if we can remove any entries from imp now.
753
+ while (imp.Any ()) {
754
+ ClusterIndex check = imp.Last ();
755
+ if (m_sorted_depgraph.FeeRate (check) >> best.feerate ) break ;
756
+ imp.Reset (check);
757
+ }
738
758
}
739
759
740
760
// If no potential transactions exist beyond the already included ones, no
@@ -774,6 +794,9 @@ class SearchCandidateFinder
774
794
775
795
const ClusterIndex first = elem.und .First ();
776
796
if (!elem.inc .feerate .IsEmpty ()) {
797
+ // If no undecided transactions remain with feerate higher than best, this entry
798
+ // cannot be improved beyond best.
799
+ if (!elem.und .Overlaps (imp)) return ;
777
800
// We can ignore any queue item whose potential feerate isn't better than the best
778
801
// seen so far.
779
802
if (elem.pot_feerate <= best.feerate ) return ;
0 commit comments