This is demonstrating an alternative approach to #33663. The author didn’t seem to like by suggestion so I am putting it here to be considered by reviewers. I personally prefer this approach due to it’s simplicity.
GetAddressesUnsafe filters banned and discouraged addresses if those exist. If addresses are filtered the returned list of addresses can be shorter than originally requested because the list isn’t backfilled with more valid addresses. These results end up in GETADDR responses as well as the getnodeaddresses RPC.
Fix this by requesting all available addresses and filter them, then only trim them to the requested max_addresses afterwards. Also adds a functional test which checks the new behavior via getnodeaddresses RPC.