main: return error if user requests addr or tx index while pruned

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

It's not possible to generate the addr or tx indexes from scratch if the
block storage had been pruned previously as it's missing the block data.
When the user asks to create these indexes, tell them it's not possible
and the only way it's possible is if they delete and start anew.
This commit is contained in:
Calvin Kim 2023-08-22 16:09:04 +09:00
parent f161a31a93
commit 8f8040e596

14
btcd.go
View File

@ -175,6 +175,20 @@ func btcdMain(serverChan chan<- *server) error {
btcdLog.Errorf("%v", err)
return err
}
if beenPruned && cfg.TxIndex {
err = fmt.Errorf("--txindex 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", cfg.DataDir)
btcdLog.Errorf("%v", err)
return err
}
if beenPruned && cfg.AddrIndex {
err = fmt.Errorf("--addrindex 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", cfg.DataDir)
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