Skip to content

Commit

Permalink
main: cfindex related sanity checks when enabled with pruning
Browse files Browse the repository at this point in the history
This change is part of the effort to add pruning support to btcd.

cfIndex is a useful index even if the node has been pruned so it's
allowed to be enabled together with pruning.  However, if the user had
disabled cfindex and enabled pruning, it's not possible to generate
them.  In this case, we tell the user that it's impossible unless the
user deletes and start anew.

Additionally, if the user had enabled cfindex and also enabled pruning
from the start, don't let the user turn the cfindex off without dropping
it explicitly.  This is to make sure that the user isn't left at an
inconsistent state where the cfindex isn't able to catch up to the tip
because the blocks have already been pruned.
  • Loading branch information
kcalvinalvin committed Aug 22, 2023
1 parent eff1d55 commit a5d082e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions btcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,31 @@ func btcdMain(serverChan chan<- *server) error {
btcdLog.Errorf("%v", err)
return err
}
// If we've previously been pruned and the cfindex isn't present, it means that the
// user wants to enable the cfindex after the node has already synced up and been
// pruned.
if beenPruned && !indexers.CfIndexInitialized(db) && !cfg.NoCFilters {
err = fmt.Errorf("compact filters cannot be enabled as the node has been "+
"previously pruned. You must delete the files in the datadir: \"%s\" "+
"and sync from the beginning to enable the desired index. You may "+
"use the --nocfilters flag to start the node up without the compact "+
"filters", cfg.DataDir)
btcdLog.Errorf("%v", err)
return err
}
// If the user wants to disable the cfindex and is pruned or has enabled pruning, force
// the user to either drop the cfindex manually or restart the node without the --nocfilters
// flag.
if (beenPruned || cfg.Prune != 0) && indexers.CfIndexInitialized(db) && cfg.NoCFilters {
err = fmt.Errorf("--nocfilters flag was given but the compact filters have " +
"previously been enabled on this node and the index data currently " +
"exists in the database. To disable compact filters, please drop the " +
"index completely with the --dropcfindex flag and restart the node. " +
"To keep the compact filters, restart the node without the --nocfilters " +
"flag")
btcdLog.Errorf("%v", err)
return err
}

// Enforce removal of txindex and addrindex if user requested pruning.
// This is to require explicit action from the user before removing
Expand Down

0 comments on commit a5d082e

Please sign in to comment.