main: force user to enable pruning if database is already pruned

This change is part of the effort to add pruning support to btcd.

Allowing the user to not pass in the --prune flag after pruning results
in inaccurate reporting of the prune status for getblockchaininfo and
for signaling NODE_NETWORK_LIMITED to peers.  Anything that relies on
cfg.Prune to be accurate is at risk of being incorrect.

To solve the current problems and to prevent potential future problems,
just force the user to keep the prune flag on like bitcoind.  In terms
of UX, there isn't that much of a loss since if the user wants to keep
more blocks than they previously did, they can just increase the size
passed to --prune.
This commit is contained in:
Calvin Kim 2023-08-23 00:21:19 +09:00
parent aaedc11887
commit 56f3463d9d

19
btcd.go
View File

@ -157,6 +157,25 @@ func btcdMain(serverChan chan<- *server) error {
return nil
}
// Check if the database had previously been pruned. If it had been, it's
// not possible to newly generate the tx index and addr index.
var beenPruned bool
db.View(func(dbTx database.Tx) error {
beenPruned, err = dbTx.BeenPruned()
return err
})
if err != nil {
btcdLog.Errorf("%v", err)
return err
}
if beenPruned && cfg.Prune == 0 {
err = fmt.Errorf("--prune cannot be disabled as the node has been "+
"previously pruned. You must delete the files in the datadir: \"%s\" "+
"and sync from the beginning to disable pruning", cfg.DataDir)
btcdLog.Errorf("%v", err)
return err
}
// The config file is already created if it did not exist and the log
// file has already been opened by now so we only need to allow
// creating rpc cert and key files if they don't exist.