Repository: bitcoin/bitcoin
File: src/cluster_linearize.h (C/C++)

Code before:
                    if (dep2_idx != dep_idx && (expected_top[par2_idx] || expected_top[chl2_idx])) {
                        expected_top.Set(par2_idx);
                        expected_top.Set(chl2_idx);
                    }
                }
                if (old == expected_top) break;
            }
            assert(!expected_top[chl_idx]);
            assert(dep_data.top_setinfo.transactions == expected_top);
            // Verify the top_info's feerate.
            assert(dep_data.top_setinfo.feerate ==
                   depgraph.FeeRate(dep_data.top_setinfo.transactions));
        }

        //
        // Verify m_suboptimal_chunks.
        //
        for (size_t i = 0; i < m_suboptimal_chunks.size(); ++i) {
            auto tx_idx = m_suboptimal_chunks[i];
            assert(m_transaction_idxs[tx_idx]);
        }

        //
        // Verify m_nonminimal_chunks.
        //
        SetType nonminimal_reps;
        for (size_t i = 0; i < m_nonminimal_chunks.size(); ++i) {
            auto [chunk_rep, pivot, flags] = m_nonminimal_chunks[i];
            assert(m_tx_data[chunk_rep].chunk_rep == chunk_rep);
            assert(m_tx_data[pivot].chunk_rep == chunk_rep);
            assert(!nonminimal_reps[chunk_rep]);
            nonminimal_reps.Set(chunk_rep);
        }
    }
};

/** Find or improve a linearization for a cluster.
 *
 * @param[in] depgraph            Dependency graph of the cluster to be linearized.
 * @param[in] max_iterations      Upper bound on the amount of work that will be done.
 * @param[in] rng_seed            A random number seed to control search order. This prevents peers
 *                                from predicting exactly which clusters would be hard for us to
 *                                linearize.
 * @param[in] old_linearization   An existing linearization for the cluster, or empty.
 * @param[in] is_topological      (Only relevant if old_linearization is not empty) Whether
 *                                old_linearization is topologically valid.
 * @return                        A tuple of:
 *                                - The resulting linearization. It is guaranteed to be at least as
 *                                  good (in the feerate diagram sense) as old_linearization.
 *                                - A boolean indicating whether the result is guaranteed to be
 *                                  optimal.

Review comment (suggestion):
nit
```suggestion
        assert(m_nonminimal_chunks.size() <= depgraph.TxCount());
        SetType nonminimal_reps;
```

Code after:
                    if (dep2_idx != dep_idx && (expected_top[par2_idx] || expected_top[chl2_idx])) {
                        expected_top.Set(par2_idx);
                        expected_top.Set(chl2_idx);
                    }
                }
                if (old == expected_top) break;
            }
            assert(!expected_top[chl_idx]);
            assert(dep_data.top_setinfo.transactions == expected_top);
            // Verify the top_info's feerate.
            assert(dep_data.top_setinfo.feerate ==
                   depgraph.FeeRate(dep_data.top_setinfo.transactions));
        }

        //
        // Verify m_suboptimal_chunks.
        //
        for (size_t i = 0; i < m_suboptimal_chunks.size(); ++i) {
            auto tx_idx = m_suboptimal_chunks[i];
            assert(m_transaction_idxs[tx_idx]);
        }

        //
        // Verify m_nonminimal_chunks.
        //
        SetType nonminimal_reps;
        for (size_t i = 0; i < m_nonminimal_chunks.size(); ++i) {
            auto [chunk_rep, pivot, flags] = m_nonminimal_chunks[i];
            assert(m_tx_data[chunk_rep].chunk_rep == chunk_rep);
            assert(m_tx_data[pivot].chunk_rep == chunk_rep);
            assert(!nonminimal_reps[chunk_rep]);
            nonminimal_reps.Set(chunk_rep);
        }
        assert(nonminimal_reps.IsSubsetOf(m_transaction_idxs));
    }
};

/** Find or improve a linearization for a cluster.
 *
 * @param[in] depgraph            Dependency graph of the cluster to be linearized.
 * @param[in] max_iterations      Upper bound on the amount of work that will be done.
 * @param[in] rng_seed            A random number seed to control search order. This prevents peers
 *                                from predicting exactly which clusters would be hard for us to
 *                                linearize.
 * @param[in] old_linearization   An existing linearization for the cluster, or empty.
 * @param[in] is_topological      (Only relevant if old_linearization is not empty) Whether
 *                                old_linearization is topologically valid.
 * @return                        A tuple of:
 *                                - The resulting linearization. It is guaranteed to be at least as
 *                                  good (in the feerate diagram sense) as old_linearization.
 *                                - A boolean indicating whether the result is guaranteed to be