Add checkBlockHash procedure

blockhashcheck
Martin Boehm 2020-11-25 15:33:45 +01:00
parent c6327399ae
commit 5a4cde6941
1 changed files with 42 additions and 0 deletions

View File

@ -343,6 +343,8 @@ func mainWithExitCode() int {
}
}
go checkBlockHash()
if internalServer != nil || publicServer != nil || chain != nil {
// start fiat rates downloader only if not shutting down immediately
initFiatRatesDownloader(index, *blockchain)
@ -743,3 +745,43 @@ func initFiatRatesDownloader(db *db.RocksDB, configfile string) {
go fiatRates.Run()
}
}
func checkBlockHash() {
glog.Infof("checkBlockHash starting")
diff := 0
best, _, err := index.GetBestBlock()
if err != nil {
glog.Errorf("checkBlockHash GetBestBlock: %v", err)
return
}
for height := uint32(1); height <= best; height++ {
bi, err := index.GetBlockInfo(height)
if err != nil {
glog.Errorf("checkBlockHash db GetBlockInfo %d : %v", height, err)
return
}
var retryCount int
var hash string
for {
hash, err = chain.GetBlockHash(height)
if err != nil {
retryCount++
if retryCount > 5 {
glog.Errorf("checkBlockHash chain GetBlockHash %d : %v", height, err)
return
}
time.Sleep(time.Millisecond * 1000)
} else {
break
}
}
if bi.Hash != hash {
glog.Infof("checkBlockHash diff height %d, db %s, chain %s", height, bi.Hash, hash)
diff++
}
if height%10000 == 0 {
glog.Infof("checkBlockHash processing block %d", height)
}
}
glog.Infof("checkBlockHash finished, found %d differences", diff)
}