Skip to content

-prune doesn't work during import #23852

Closed

Description

@maflcko

It appears that -prune is ignored during import (-reindex, or -loadblock).

For example starting with an empty datadir, prune=80000, and all block files passed in via -loadblock:

...
2021-12-23T12:49:44Z [loadblk] [node/blockstorage.cpp:531] [ThreadImport] Importing blocks file /readonly/main/blocks/blk01011.dat...
2021-12-23T12:49:44Z [loadblk] [node/blockstorage.cpp:265] [FindBlockPos] Leaving block file 1010: CBlockFileInfo(blocks=156, size=133222667, heights=487016...487360, time=2017-09-26...2017-09-28)
2021-12-23T12:49:45Z [loadblk] [flatfile.cpp:69] [Allocate] Pre-allocating up to position 0x1000000 in blk01011.dat
2021-12-23T12:49:45Z [loadblk] [logging/timer.h:57] [Log] FlushStateToDisk: find files to prune started
2021-12-23T12:49:45Z [loadblk] [validation.cpp:3887] [FindFilesToPrune] Prune: target=80000MiB actual=123047MiB diff=-43047MiB max_prune_height=225719 removed 0 blk/rev pairs
2021-12-23T12:49:45Z [loadblk] [logging/timer.h:57] [Log] FlushStateToDisk: find files to prune completed (0.05ms)
...

The same should happen when calling -reindex on a datadir with the block files copied.

So prune only works with IBD from the network?

Activity

  1. maflcko commented on Dec 24, 2021

    @maflcko
    MemberAuthor

    As a workaround it is possible to start a node with the datadir on one hard drive and another one with the datadir on the other hard drive using -connect=localhost to import the blocks

  2. mruddy commented on Apr 20, 2022

    @mruddy
    Contributor

    @MarcoFalke I was just looking at this because I've been looking at issues related to re-indexing. Please re-open this issue if you agree with my thoughts below.

    1. I think that -prune=N plus -loadblock=path could be made to work. That seems to make sense. An example use case is like what you were doing in your issue report above, 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 change the input set of block files.

    2. I think that -prune=N plus -reindex makes potentially less sense together and should not be made to work.

      1. Enabling this combo could be dangerous by being destructive of the input blk files. If a problem occurs during re-indexing, then this combo may increase the chance of having to re-download lots of block data. If we leave them as a non-effective combo, then many re-indexing failures can be overcome by simply staring over with the original blk files still intact.
      2. A case where this combo may not make sense has to do with out of order blocks in blk files. The -reindex process can process blocks out of order. We wouldn't want to prune a blk file that contains a block that was encountered out of order because when an out of order block is processed during re-indexing, its location is saved for a later re-read from the blk file after its parent is processed. If we pruned the blk file containing it, then we'd lose it and all of its ancestor blocks. We'd have to re-download them because the re-index process would consider all of its ancestors as being encountered out of order and not connectable. Therefore, we would not prune those blk files and thus the -prune=N would be a potentially meaningless suggestion (depending on how out of order a block was in a set of input block files) rather than a limit set by the node operator that will be generally adhered too. A worst case would have the last/best block inserted after genesis in the first blk file (dumb, but possible). No pruning would be possible until after everything is re-indexed.
  3. added a commit that references this issue on May 21, 2022
    c86f129
  4. added a commit that references this issue on Feb 22, 2023
    c4981e7
  5. locked and limited conversation to collaborators on Apr 20, 2023
  6. added a commit that references this issue on May 3, 2023
    aebcd18
  7. added a commit that references this issue on May 27, 2023
    83c6c50
  8. added a commit that references this issue on Jun 27, 2023
    50e3f6c
  9. added a commit that references this issue on Oct 22, 2025
    0ebbf76
  10. added 3 commits that reference this issue on Jan 31, 2026
    7e59f71
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions