Automatically check for UTXO inconsitencies
This commit is contained in:
parent
1b713308a3
commit
9feccfdb2e
28
blockbook.go
28
blockbook.go
@ -179,21 +179,31 @@ func mainWithExitCode() int {
|
|||||||
}
|
}
|
||||||
defer index.Close()
|
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)
|
internalState, err = newInternalState(coin, coinShortcut, coinLabel, index)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Error("internalState: ", err)
|
glog.Error("internalState: ", err)
|
||||||
return exitCodeFatal
|
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)
|
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.DbStateClosed {
|
||||||
if internalState.DbState == common.DbStateInconsistent {
|
if internalState.DbState == common.DbStateInconsistent {
|
||||||
glog.Error("internalState: database is in inconsistent state and cannot be used")
|
glog.Error("internalState: database is in inconsistent state and cannot be used")
|
||||||
|
|||||||
@ -53,6 +53,8 @@ type InternalState struct {
|
|||||||
LastMempoolSync time.Time `json:"lastMempoolSync"`
|
LastMempoolSync time.Time `json:"lastMempoolSync"`
|
||||||
|
|
||||||
DbColumns []InternalStateColumn `json:"dbColumns"`
|
DbColumns []InternalStateColumn `json:"dbColumns"`
|
||||||
|
|
||||||
|
UtxoChecked bool `json:"utxoChecked"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartedSync signals start of synchronization
|
// StartedSync signals start of synchronization
|
||||||
|
|||||||
@ -1707,7 +1707,7 @@ func (d *RocksDB) LoadInternalState(rpcCoin string) (*common.InternalState, erro
|
|||||||
data := val.Data()
|
data := val.Data()
|
||||||
var is *common.InternalState
|
var is *common.InternalState
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
is = &common.InternalState{Coin: rpcCoin}
|
is = &common.InternalState{Coin: rpcCoin, UtxoChecked: true}
|
||||||
} else {
|
} else {
|
||||||
is, err = common.UnpackInternalState(data)
|
is, err = common.UnpackInternalState(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user