re: #15288 (review)
I didn’t check if this needs a broader mempool (or main) lock (maybe for this whole function, since the mempool can remove/expire entries at will), but you are not changing this in your refactoring. So probably orthogonal to your changes. Still, I wanted to leave the comment
This is called from coin selection, so I’m guessing it’s just a tradeoff between having to keep the mempool locked continuously and selected outputs being possibly out of date.
I think ideally the wallet wouldn’t have any ability to lock the mempool mutex for an extended period of time, so if there is a bug here, it would be better to resolve it by adding a batch TransactionAncestry lookup method, so the wallet could look up many transactions in a single call, but not be able to keep mempool.cs
locked indefinitely over many calls.