Repository navigation
prune, import: allow pruning to work during loadblock import - #24957
Conversation
luke-jr
left a comment
There was a problem hiding this comment.
Code safety utACK. Did not verify if it fixes a bug or impacts performance.
allows pruning to work during the loadblock import process. Github-Pull: bitcoin#24957 Rebased-From: da8e95c01401edd5e33c04ad412a6df2997f58c9
|
Concept ACK. I think this should be reopened, as it's a small diff and a good change. I can review more thoroughly next week. |
|
Yeah, concept ACK |
|
I closed this to garbage collect because I thought it was dead. But, since there's interest I've reopened it. Thanks! |
|
Reopening since I have time to usher this to completion now. |
347664e to
2f62704
Compare
|
I'm not sure how to test this? where but I get these logs for every block (both on master and this PR): |
|
@aureleoules thanks for looking into this. your block files have blocks out of order. it's nothing that you did wrong. it's just that with the There is a tool to make some block files for testing where the blocks are in order and loadable with If I remember correctly, another snag you'll come across is that you need to have at least 100,000 blocks for mainnet due to I'll make a todo item for myself to see how I can make testing this easier via a follow-up comment, and maybe a set of test input block files or something. |
2f62704 to
488682e
Compare
useful for testing bitcoin/bitcoin#24957
|
@aureleoules I put a set of linearized block files that are useful for testing this at: A way to use the files and be able to watch what is going on in the debugger is with: The debug log will log related messages and can be found easily with grep like the following examples: Depending on what you're looking to understand, various breakpoints can be set within gdb, for example: |
aureleoules
left a comment
There was a problem hiding this comment.
ACK 488682e785194f807f21b4dc6826df7714d78a25
Thanks @mruddy for the linearized block files!
I was able to verify with the given block files that pruning occurs during the import process in this PR and not at the end (master).
If I understand correctly, this would allow cloning a full node into a pruned node without needing the double amount of disk space during the import process and without needing a workaround (-connect=localhost).
|
In the future, please don't rebase for no reason |
|
Should we be doing this check later on when processing out of order successor blocks? |
|
P.S. Needs rebase. Silent conflict with #16981 diff --git a/src/validation.cpp b/src/validation.cpp
index 40d15b60d63..285aeb16d4e 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -4366,6 +4366,7 @@ void Chainstate::LoadExternalBlockFile(
// next block, but it's still possible to rewind to the start of the current block (without a disk read).
nRewind = nBlockPos + nSize;
blkdat.SkipTo(nRewind);
+ std::shared_ptr<CBlock> recent_block_maybe_not_this_block;
{
LOCK(cs_main);
// detect out of order blocks, and store them for later
@@ -4383,7 +4384,7 @@ void Chainstate::LoadExternalBlockFile(
if (!pindex || (pindex->nStatus & BLOCK_HAVE_DATA) == 0) {
// This block can be processed immediately; rewind to its start, read and deserialize it.
blkdat.SetPos(nBlockPos);
- std::shared_ptr<CBlock> pblock{std::make_shared<CBlock>()};
+ auto& pblock = recent_block_maybe_not_this_block = std::make_shared<CBlock>();
blkdat >> *pblock;
nRewind = blkdat.GetPos();
@@ -4416,7 +4417,7 @@ void Chainstate::LoadExternalBlockFile(
// called by concurrent network message processing. but, that is not
// reliable for the purpose of pruning while importing.
BlockValidationState state;
- if (!ActivateBestChain(state, pblock)) {
+ if (!ActivateBestChain(state, recent_block_maybe_not_this_block)) {
LogPrint(BCLog::REINDEX, "failed to activate chain (%s)\n", state.ToString());
break;
}
|
488682e to
f5c1649
Compare
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. 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. |
|
@luke-jr Thanks! I just rebased and had to make a small change due to the #16981 updates. Those updates moved the block data read from disk into the code block that is guarded by
No, because |
f5c1649 to
734355b
Compare
luke-jr
left a comment
There was a problem hiding this comment.
utACK 734355b470764c523ef08b25320a5fabb73358a6
|
Thanks to those that have reviewed/tested this already, I think it's ready to go. @jamesob Is there a chance that you might be able to review or test this PR? Thanks! |
aureleoules
left a comment
There was a problem hiding this comment.
re-tACK 734355b470764c523ef08b25320a5fabb73358a6
|
ACK 734355b470764c523ef08b25320a5fabb73358a6 |
|
Looks like there's a silent merge conflict: |
allows pruning to work during the loadblock import process.
734355b to
c4981e7
Compare
|
@achow101 Thanks! I rebased and then resolved the silent merge conflict by changing |
|
re-ACK c4981e7 |
allows pruning to work during the loadblock import process. Github-Pull: bitcoin#24957 Rebased-From: 488682e785194f807f21b4dc6826df7714d78a25
…cess Summary: allows pruning to work during the loadblock import process. This is a backport of [[bitcoin/bitcoin#24957 | core#24957]] Depends on D15003 Test Plan: Backup the eCash data dir, create a bootstrap.dat file by following the instructions in contrib/linearize, then delete the content of the data dir, comment out config options that are incompatible with pruning (txindex=1) then `src/bitcoind -prune=550 -loadblock=/data/bootstrap.dat` Check while the node is importing the blocks from bootstrap.dat that the new data dir does not grow significantly larger than 550 MB (I saw it oscillates between that target and 800 MB, while the bootstrap.dat file was 21 GB of blocks 0--313000) `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D15004
Fixes #23852
This allows pruning to work during the
-loadblockimport process.An example use case is where you have a clean set of block files and you want to create a pruned node from them, but you don't want to alter the input set of block files.
#23852 noted that pruning was not working reliably during the loadblock import process. The reason why the loadblock process was not pruning regularly as it progressed is that the pruning process (
BlockManager::FindFilesToPrune) checks the tip height of the active chainstate, andCChainState::ActivateBestChainwas not called (which updates that tip height) inThreadImportuntil after all the import files were processed.An example bash command line that makes it easy to import a bunch of block files:
One interesting side note is that
CChainState::ActivateBestChaincan be called while the import process is running (in theloadblkthread) by concurrent network message processing activity in themsghandthread. For example, one way to reproduce this easily is with thegetblockfrompeerRPC (requesting a block with height greater than 100000) run from a node connected to an importing node. There are other ways too, but this is an easy way. I only mention this to explain how themax_prune_height=225719log message in the original issue came to occur.