The method wait_for_getdata() was recently changed to be more precise by waiting for a specified list of hashes, instead of only matching any getdata message (see PR18690). This PR replaces the remaining occurences of manual inspection of last_messages with this call.
This is a backport of Core PR18756