New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
p2p: For assumeutxo, download snapshot chain before background chain #29519
base: master
Are you sure you want to change the base?
p2p: For assumeutxo, download snapshot chain before background chain #29519
Conversation
After loading a snapshot, pindexLastCommonBlock is usually already set to some block for existing peers. That means we'd continue syncing the background chain from those peers instead of prioritising the snapshot chain, which defeats the purpose of doing assumeutxo in the first place. Only existing peers are affected by this bug.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. |
Note that given that 27 will not ship with mainnet assumeutxo, this isn't a blocker, and a fix can still be backported to 27.x if deemed necessary. |
Concept ACK ac547ea looks reasonable, but it would be nice to somehow add a test for it. What happens once we've reached the tip and need more peers for background sync? And once background sync is done, is it updated to the tip again? Would it make sense to introduce |
I tested this syncing on signet, but I'll think about a functional test; I imagine that it would be hard to prevent race conditions in a functional test because we'd:
It might be possible though if that peer was a
We have this logic in |
I can see how it would be difficult to test, indeed. I encountered this scenario while testing #29370 on signet. All my peers were only downloading the background state. I only got headers for the tip chain, but it didn't progress. The workaround there was to turn the network off and on, which is consistent with your observation that only existing peers are affected. utACK ac547ea |
The code and reasoning look good to me and I have been trying to write a test but I am currently unable to reproduce the behavior described before the change, i.e. to make the test fail on master. Here is the test so far: fjahr@478fb28 This now does fail on master but only because it also checks for the debug log @mzumsande do you have an idea why this doesn't reproduce the behavior you have seen on master? |
I tested your branch, and I see the same - this is really interesting, and it works differently than I thought when I opened the PR! I think the following happens in bitcoin/src/net_processing.cpp Line 1430 in 2102c97
But due to the lines bitcoin/src/net_processing.cpp Lines 1497 to 1502 in 2102c97
we never ask for the blocks below the snapshot block here: Even though we don't have their data, they are now in the active chain, so they are skipped instead. In the test, we immediately ask for the blocks after the snapshot instead, which is exactly the desired behavior. So why did I observe a different behavior on signet? If this wasn't the case, we'd request nothing in So I think what would actually happen on mainnet and signet is that each time we can process a block request with an existing peer, we'd move Still, I think that this behavior is not great, and the fix is an improvement - not only because we start downloading the snapshot chain immediately, we also do much less iterating in |
After loading a snapshot,
pindexLastCommonBlock
is usually already set to some block for existing peers. That means we'd continue syncing the background chain from those peers instead of prioritising the snapshot chain, which defeats the purpose of doing assumeutxo in the first place. Only existing peers are affected by this bug.