<p>Always.</p>

<p>When starting up, Bitcoin Core sends out a request to its peers to inform it about the best chains they know about (using a <code>getheaders</code> message). </p>

<p>After that point, it is automatic: peers will immediately announce new blocks they knew about after they learn about them. This either happens using:</p>

<ul>
<li>legacy <code>inv</code> mechanism, in which case just block hashes are announced</li>
<li>BIP130 (if negotiated), in which case announcements send full block headers</li>
<li>BIP152 high-bandwidth mode (if negotiated), in which case blocks are immediately transferred in full using compact blocks protocol</li>
</ul>

CC BY-SA 3.0
2017-10-22T20:05:19.783Z
I was thinking more about the following: If the node (for some reason) missed a block from main branch or a side branch, he will be out of sync. And he will reject all blocks mined on top of these branches? He must perform some kind of sync. Is this done only when disconected/reconected or periodically?
croraf
CC BY-SA 3.0
2017-10-22T20:14:14.950Z
Your node always works towards the best valid block it knows about. If it learns about a side branch that grows longer than the best block it knew about before, it will download it, and rewind the current block chain to the forking point, and then connect the new best. If the new branch turns out to be invalid, it will revert back to the older tip. All that also happens all the time - we always want to have the best possible block active.
Pieter Wuille
CC BY-SA 3.0
2017-10-22T20:36:24.307Z
Can we continue in https://chat.stackexchange.com/rooms/67480/bitcoin-chain-progression
croraf
CC BY-SA 4.0
2018-05-11T12:29:07.063Z
What stops me from tampering with a new block (I created), before it is distributed to the rest of the nodes?
olfek
CC BY-SA 4.0
2018-05-11T13:00:32.823Z
@daka That depends on what you mean by tampering. If you modify the block is a legal way before grinding the PoW, it will just be valid. If you make an illegal modification (double spend, theft, inflation, ...), the block will be invalid no matter what. If you modify a block after grinding, you invalidate the PoW, and you'll have to redo it.
Pieter Wuille
CC BY-SA 4.0
2018-05-11T13:16:08.313Z
"the block will be invalid no matter what" why is that? could you please elaborate on this? thanks
olfek
CC BY-SA 4.0
2018-05-11T13:26:51.767Z
Because all full nodes verify all transaction in a block before accepting. The rule is that the longest **valid** chain wins; not just the longest one regardless of its contents.
Pieter Wuille
CC BY-SA 3.0
2017-10-22T19:37:00.933Z
2017-10-23T14:19:23.073Z
2017-10-23T14:19:23.073Z
Pieter Wuille
<p>When does bitcoin node sync itself?</p>

<p>Do different types of sync in bitcoin exist (initial, periodic...)?</p>

<bitcoin-core><synchronization>
When and how does bitcoin node sync itself?
croraf
# When and how does bitcoin node sync itself?

(Asked by: username_0 on 2017-10-22)

When does bitcoin node sync itself?

Do different types of sync in bitcoin exist (initial, periodic...)?

**Tags:** bitcoin-core, synchronization


---

## 1 answers

### Answer by username_1 on 2017-10-22. Score: 6 | Accepted answer

Always.

When starting up, Bitcoin Core sends out a request to its peers to inform it about the best chains they know about (using a `getheaders` message).

After that point, it is automatic: peers will immediately announce new blocks they knew about after they learn about them. This either happens using:

* legacy `inv` mechanism, in which case just block hashes are announced
* BIP130 (if negotiated), in which case announcements send full block headers
* BIP152 high-bandwidth mode (if negotiated), in which case blocks are immediately transferred in full using compact blocks protocol

> **Comments:**
> **username_0**: I was thinking more about the following: If the node (for some reason) missed a block from main branch or a side branch, he will be out of sync. And he will reject all blocks mined on top of these branches? He must perform some kind of sync. Is this done only when disconected/reconected or periodically?  
> **username_1**: Your node always works towards the best valid block it knows about. If it learns about a side branch that grows longer than the best block it knew about before, it will download it, and rewind the current block chain to the forking point, and then connect the new best. If the new branch turns out to be invalid, it will revert back to the older tip. All that also happens all the time - we always want to have the best possible block active.  
> **username_0**: Can we continue in https://chat.stackexchange.com/rooms/67480/bitcoin-chain-progression  
> **username_2**: What stops me from tampering with a new block (I created), before it is distributed to the rest of the nodes?  
> **username_1**: @daka That depends on what you mean by tampering. If you modify the block is a legal way before grinding the PoW, it will just be valid. If you make an illegal modification (double spend, theft, inflation, ...), the block will be invalid no matter what. If you modify a block after grinding, you invalidate the PoW, and you'll have to redo it.  
> **username_2**: "the block will be invalid no matter what" why is that? could you please elaborate on this? thanks  
> **username_1**: Because all full nodes verify all transaction in a block before accepting. The rule is that the longest **valid** chain wins; not just the longest one regardless of its contents.  

---

