Skip to content

Commit

Permalink
main: error on startup for attempting to switch between utreexo and
Browse files Browse the repository at this point in the history
non-utreexo nodes
  • Loading branch information
kcalvinalvin committed Jan 3, 2024
1 parent 1e93fbe commit 818d6fc
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions utreexod.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"runtime/pprof"
"runtime/trace"

"github.com/utreexo/utreexod/blockchain"
"github.com/utreexo/utreexod/blockchain/indexers"
"github.com/utreexo/utreexod/database"
"github.com/utreexo/utreexod/limits"
Expand Down Expand Up @@ -139,6 +140,45 @@ func btcdMain(serverChan chan<- *server) error {
return nil
}

// Find out if the user is restarting the node.
var chainstateInitialized bool
db.View(func(dbTx database.Tx) error {
chainstateInitialized = blockchain.ChainstateInitialized(dbTx)
return nil
})

// If the node is being re-started, do some checks to prevent the user from switching
// between a utreexo node vs a non-utreexo node.
if chainstateInitialized {
var cacheInitialized bool
db.View(func(dbTx database.Tx) error {
cacheInitialized = blockchain.UtxoCacheInitialized(dbTx)
return nil
})

// If the node has been a non-utreexo node but it was now re-started as a utreexo node.
if cacheInitialized && !cfg.NoUtreexo {
err = fmt.Errorf("Utreexo enabled but this node has been "+
"started as a non-utreexo node previously at datadir of \"%v\". "+
"Please completely remove the datadir to start as a utreexo "+
"node or pass in a different --datadir.",
cfg.DataDir)
btcdLog.Error(err)
return err
}

// If the node has been a utreexo node but it was now re-started as a non-utreexo node.
if !cacheInitialized && cfg.NoUtreexo {
err = fmt.Errorf("Utreexo disabled but this node has been previously "+
"started as a utreexo node at datadir of \"%v\". Please "+
"completely remove the datadir to start as a non-utreexo node "+
"or pass in a different --datadir.",
cfg.DataDir)
btcdLog.Error(err)
return err
}
}

// Drop indexes and exit if requested.
//
// NOTE: The order is important here because dropping the tx index also
Expand Down

0 comments on commit 818d6fc

Please sign in to comment.