From 8f8040e596aa267c5cbad8a815e872f569cf413b Mon Sep 17 00:00:00 2001 From: Calvin Kim Date: Tue, 22 Aug 2023 16:09:04 +0900 Subject: [PATCH] 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. --- btcd.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/btcd.go b/btcd.go index 3d0dafda..0ac2f1bf 100644 --- a/btcd.go +++ b/btcd.go @@ -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