[qa] Fix race condition in p2p-compactblocks test
Also fix a bug in the sync_with_ping() helper function