Skip to content

Commit

Permalink
Optimization: only explore if higher feerates left
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Jun 16, 2023
1 parent 1ed69c8 commit 6b8d942
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/cluster_linearize.h
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,8 @@ CandidateSetAnalysis<S> FindBestCandidateSetEfficient(const Cluster<S>& cluster,
S pot = inc;
/** The set of ancestors of everything in pot, combined. */
S pot_ancestors;
/** Whether any undecided transactions with higher feerate than inc_feerate are left. */
bool explore_further{false};
// Loop over all undecided transactions (not yet included or excluded), from high to low feerate.
auto undecided{(all / (inc | exc)).Elements()};
while (undecided) {
Expand All @@ -651,6 +653,9 @@ CandidateSetAnalysis<S> FindBestCandidateSetEfficient(const Cluster<S>& cluster,
inc = pot;
inc_feerate = pot_feerate;
inc_may_be_best = true;
explore_further = false;
} else {
explore_further = true;
}
}

Expand All @@ -673,9 +678,9 @@ CandidateSetAnalysis<S> FindBestCandidateSetEfficient(const Cluster<S>& cluster,
}
}

// Only if there are undecided transactions left besides inc and exc actually add it to the
// queue.
if (!((inc | exc) >> all)) {
// Only if any transactions with feerate higher than inc_feerate exist add this entry to the
// queue. If not, it's not worth exploring further.
if (explore_further) {
queue.emplace_back(inc, exc, inc_feerate, pot_feerate);
ret.max_queue_size = std::max(ret.max_queue_size, queue.size());
}
Expand Down Expand Up @@ -703,6 +708,8 @@ CandidateSetAnalysis<S> FindBestCandidateSetEfficient(const Cluster<S>& cluster,
}

// Decide which transaction to split on (highest undecided individual feerate one left).
// There must be at least one such transaction, because otherwise explore_further would
// have been false inside add_fn, and the entry would never have been added to the queue.
auto undecided{(all / (inc | exc)).Elements()};
assert(undecided);
auto pos = undecided.Next();
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/clustermempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ FUZZ_TARGET(clustermempool_efficient_limits)
auto initial_buffer = buffer;

Cluster<BitSet> cluster = DeserializeCluster<BitSet>(buffer);
if (cluster.size() > 20) return;
if (cluster.size() > 26) return;

BitSet all = BitSet::Full(cluster.size());
bool connected = IsConnectedSubset(cluster, all);
Expand Down

0 comments on commit 6b8d942

Please sign in to comment.