In When and how does bitcoin node sync itself? it is described that there are a number of ways for nodes to synchronize on the blockchain state.
How does (legacy) INV mechanism works?
Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It only takes a minute to sign up.Sign up to join this community
If I understood correctly it goes like this:
I get the announcement from a peer that he found a new tip in his blockchain. (so called INV message)
I send him the block locator message with last 10 hashes from the tip of my blockchain.
Me and him could be on different branches so he has to detect which hash do we have in common (the hash where fork happened). Or we are on the same branch and he just advanced the branch by one hash. NOTE: If he does not find the common hash he will ask me to send hashes further back my chain (fork happened somewhere earlier).
When he detects the common hash, he will send me the headers from this hash up to the newly found hash. I validate each header, stopping if a header in this process is invalid.
If his chain is now longer than mine (edit: and download the transaction part's of his blocks, verify them then) I switch to new chain.