A single sync_with_ping can't be used to drop a block announcement, as the block might be sent after the ping has been responded to.
Fix that by waiting for the block.
Note: The useless [0] after generatetoaddress was a leftover that should have been removed in D10804.
This is a backport of core#20466