main: cfindex related sanity checks when enabled with pruning

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.
This commit is contained in:
Calvin Kim 2023-08-22 16:12:05 +09:00
parent 8f8040e596
commit 65c729960a

27
btcd.go
View File

@ -189,6 +189,33 @@ 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. The node has also been previously pruned and " +
"the database would be left in an inconsistent state if the compact " +
"filters don't get indexed now. 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