PR description:
There's a race between sending a getdata for a bunch of blocks with the node receiving those blocks from a peer, which could cause test failure. Fix this.
Motivated by observing this race caused an appveyor test failure on another PR
Backport of Core PR16459