Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: barrysty1e on March 25, 2020, 01:25:00 PM



Title: getblocks vs getheaders
Post by: barrysty1e on March 25, 2020, 01:25:00 PM
Hi everyone,

I'm currently mid way through converting Bitcoin 0.19 based client so that it can properly synchronize from a pre-0.10 clients chain.
Those who are in the know should automatically know exactly which currency i'm talking about.

So far i'm having good luck but seem to run into an unusual and undocumented problem.
Every 500 blocks received via INV request, seem to come with an extra block at the end that reflects the current chains tip.
Everywhere i've read suggests that *only* 500 blocks are sent, but I always seem to get this extra block tacked onto the end.

Quote
2020-03-24T15:44:05Z ComputeNextStakeModifier: prev modifier=0x000000105dbc2bd6 time=1545703144
2020-03-24T15:44:05Z ComputeNextStakeModifier: no new interval keep current modifier: pindexPrev nHeight=499 nTime=1545703144
2020-03-24T15:44:05Z UpdateTip: new best=0000000105a7e280f68b5d030282998640d6da2fa0eb107e9dd65a3e7ccad9d8 height=500 version=0x00000003 log2_work=8.9686668 tx=521 date='2018-12-25T02:01:18Z' progress=1.000000 cache=0.1MiB(676txo)
2020-03-24T15:44:06Z ERROR: ProcessNewBlock: AcceptBlock FAILED ( (code 0))
2020-03-24T15:44:08Z ComputeNextStakeModifier: prev modifier=0x000000105dbc2bd6 time=1545703144

It doesnt actually affect sync at all, but it bugs the s**t out of me.

Yes neckbeards, this isnt technically 'bitcoin only' discussion; but I think its a heartwarming change from 'howTO cloening of the cOIN'.. and technical discussion, which this forum has sorely lacked over the past few years.

james


Title: Re: getblocks vs getheaders
Post by: achow101 on March 25, 2020, 04:23:10 PM
It's there to prompt nodes to request the next 500 blocks. It's to ensure that they know there are more blocks to download. Relevant lines in Bitcoin Core: https://github.com/bitcoin/bitcoin/blob/v0.9.5/src/main.cpp#L3698 and https://github.com/bitcoin/bitcoin/blob/v0.9.5/src/main.cpp#L3344


Title: Re: getblocks vs getheaders
Post by: barrysty1e on March 25, 2020, 04:49:58 PM
It's there to prompt nodes to request the next 500 blocks. It's to ensure that they know there are more blocks to download. Relevant lines in Bitcoin Core: https://github.com/bitcoin/bitcoin/blob/v0.9.5/src/main.cpp#L3698 and https://github.com/bitcoin/bitcoin/blob/v0.9.5/src/main.cpp#L3344

thankyou.
where in the code does it 'set' this as the known tip? ive tried using hashStop/hashContinue but this doesnt seem to work..


Title: Re: getblocks vs getheaders
Post by: achow101 on March 26, 2020, 06:12:03 AM
thankyou.
where in the code does it 'set' this as the known tip? ive tried using hashStop/hashContinue but this doesnt seem to work..
It doesn't. The node makes no assumptions about the validity of that block. All it knows is that it is missing the chain leading up to that block and needs to fetch that chain in order to verify that block. For efficiency, the block's hash is cached in mapOrphanBlocks so that it doesn't have to download the same block over and over. Instead it knows that if it sees a block hash in that map, it knows it checked some things (e.g. PoW) but still needs the chain leading up to it to verify it. So it requests more blocks in that chain.