What's the difference between synced_blocks and synced_headers?

Lucas: 2 weeks ago

My P2P is a bit rusty, but as far as I understand; if we're running a full node, other nodes will connect to us to share blocks. So I can see why it would be useful to be able to see how far behind other nodes's blockchains are with the getpeerinfo command.

However, what's the practical difference between synced_headers and synced_blocks?

For example, what does it mean if a peer has synced_headers equal to the height of our own blockchain, but a synced_blocks of -1?

Liam: 2 weeks ago

Bitcoin clients can have headers without having blocks. (However, Bitcoin Core never has a block without a header.)

A synced_blocks of -1 means that the best block for the other node is unknown.

synced_blocks is set here:

stats.nCommonHeight = state->pindexLastCommonBlock ? state->pindexLastCommonBlock->nHeight : -1;

A synced_headers of -1 means that the best header for the other node is unknown.

synced_headers is set here:

stats.nSyncHeight = state->pindexBestKnownBlock ? state->pindexBestKnownBlock->nHeight : -1;