Automatically check for UTXO inconsitencies

pull/380/head
Martin Boehm 2020-02-16 23:07:50 +01:00
parent 1b713308a3
commit 9feccfdb2e
3 changed files with 22 additions and 10 deletions

View File

@ -179,21 +179,31 @@ func mainWithExitCode() int {
}
defer index.Close()
if *fixUtxo {
err = index.FixUtxos(chanOsSignal)
if err != nil {
glog.Error("fixUtxos: ", err)
return exitCodeFatal
}
return exitCodeOK
}
internalState, err = newInternalState(coin, coinShortcut, coinLabel, index)
if err != nil {
glog.Error("internalState: ", err)
return exitCodeFatal
}
// fix possible inconsistencies in the UTXO index
if *fixUtxo || !internalState.UtxoChecked {
err = index.FixUtxos(chanOsSignal)
if err != nil {
glog.Error("fixUtxos: ", err)
return exitCodeFatal
}
internalState.UtxoChecked = true
}
index.SetInternalState(internalState)
if *fixUtxo {
err = index.StoreInternalState(internalState)
if err != nil {
glog.Error("StoreInternalState: ", err)
return exitCodeFatal
}
return exitCodeOK
}
if internalState.DbState != common.DbStateClosed {
if internalState.DbState == common.DbStateInconsistent {
glog.Error("internalState: database is in inconsistent state and cannot be used")

View File

@ -53,6 +53,8 @@ type InternalState struct {
LastMempoolSync time.Time `json:"lastMempoolSync"`
DbColumns []InternalStateColumn `json:"dbColumns"`
UtxoChecked bool `json:"utxoChecked"`
}
// StartedSync signals start of synchronization

View File

@ -1707,7 +1707,7 @@ func (d *RocksDB) LoadInternalState(rpcCoin string) (*common.InternalState, erro
data := val.Data()
var is *common.InternalState
if len(data) == 0 {
is = &common.InternalState{Coin: rpcCoin}
is = &common.InternalState{Coin: rpcCoin, UtxoChecked: true}
} else {
is, err = common.UnpackInternalState(data)
if err != nil {