Automatically check for UTXO inconsitencies
parent
1b713308a3
commit
9feccfdb2e
28
blockbook.go
28
blockbook.go
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue