count_acceptable_nodes() would be more accurate using node_has_preferred_descriptor()
On a github review for #25691 (moved), Teor notes about count_acceptable_nodes():
I think this code is correct, but it's not obvious:
- new_route_len() is the only caller
- new_route_len() will fail if count_acceptable_nodes() is less than the route length.
- later functions will fail if there is no guard
- later functions will fail if there are not enough subsequent nodes for the rest of the route
So this check can spuriously succeed when we have no guards, or when we have many bridges, and no subsequent nodes. But it can never fail when there are actually enough nodes for the path. So this is just an optimisation to stop us trying to build lots of circuits when we have no descriptors.
We could return the number that pass for_direct_connect = 1 and for_direct_connect = 0, but that seems unnecessarily complicated.
I think that we should probably adjust this function to do the careful count, but it's safe to defer.