Skip to content

Advance pindexLastCommonBlock for blocks in chainActive#6233

Merged
laanwj merged 1 commit intobitcoin:masterfrom
sdaftuar:fix-lastcommonblock-pruning
Jun 25, 2015
Merged

Advance pindexLastCommonBlock for blocks in chainActive#6233
laanwj merged 1 commit intobitcoin:masterfrom
sdaftuar:fix-lastcommonblock-pruning

Conversation

@sdaftuar
Copy link
Member

@sdaftuar sdaftuar commented Jun 4, 2015

This prevents an edge case where a block downloaded and pruned
in-between successive calls to FindNextBlocksToDownload could
cause the block to be unnecessarily re-requested.

The issue is that pindexLastCommonBlock is only updated on calls
to FindNextBlocksToDownload, by starting at its prior value and then
advancing forward until we encounter a block for which we don't
HAVE_DATA (which we then try to request).

During initial block download, it's possible for the tip to advance by
many blocks during a single call to ActivateBestChain (since blocks
arrive out of order, when a block comes in that completes a long
sequence, then we'll see many tip updates in a row). If a long enough
sequence of tip updates occurs, then it's possible that the block
that just arrived could be pruned at the end of processing, before
FindNextBlocksToDownload can be called for any other peers. This
in turn would cause us to re-request the block from one of those peers,
since we'd no longer HAVE_DATA for it.

Since blocks in chainActive never need to be re-downloaded, this
pull should prevent pruning nodes from ever re-requesting blocks in this
situation, while still allowing for pruning nodes to redownload blocks
that may have been previously pruned but are needed for a reorg (this
is exercised in pruning.py, which this pull passes).

This prevents an edge case where a block downloaded and pruned
in-between successive calls to FindNextBlocksToDownload could
cause the block to be unnecessarily re-requested.
@sipa
Copy link
Member

sipa commented Jun 14, 2015

Untested ACK

@jtimon
Copy link
Contributor

jtimon commented Jun 21, 2015

ut ACK

@sipa
Copy link
Member

sipa commented Jun 21, 2015

Been running on bitcoin.sipa.be for a week, no problems.

@sdaftuar
Copy link
Member Author

Thoughts on merging this into 0.11? This is unfortunately difficult to test, but I did try to recreate the conditions that produced the infinite download bug I previously triggered, and verified that with this code no blocks were downloaded more than once.

Not a conclusive test of the code however.

(To be clear, I don't believe there is a potential infinite download bug in master anymore, that risk was eliminated already, but I think it's possible for a block to be downloaded twice.)

@laanwj
Copy link
Member

laanwj commented Jun 25, 2015

utACK

@laanwj laanwj merged commit 3e91433 into bitcoin:master Jun 25, 2015
laanwj added a commit that referenced this pull request Jun 25, 2015
3e91433 Advance pindexLastCommonBlock for blocks in chainActive (Suhas Daftuar)
laanwj pushed a commit that referenced this pull request Jun 25, 2015
This prevents an edge case where a block downloaded and pruned
in-between successive calls to FindNextBlocksToDownload could
cause the block to be unnecessarily re-requested.

Github-Pull: #6233
Rebased-From: 3e91433
@laanwj
Copy link
Member

laanwj commented Jun 25, 2015

Cherry-picked to 0.11 as a587606

@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants