Rollback to given height

pull/1/head
Martin Boehm 2018-01-29 17:27:42 +01:00
parent 2dd0b9fc21
commit 858f196484
1 changed files with 19 additions and 2 deletions

View File

@ -42,8 +42,9 @@ var (
dbPath = flag.String("path", "./data", "path to address index directory")
blockHeight = flag.Int("blockheight", -1, "height of the starting block")
blockUntil = flag.Int("blockuntil", -1, "height of the final block")
blockHeight = flag.Int("blockheight", -1, "height of the starting block")
blockUntil = flag.Int("blockuntil", -1, "height of the final block")
rollbackHeight = flag.Int("rollback", -1, "rollback to the given height and quit")
queryAddress = flag.String("address", "", "query contents of this address")
@ -93,6 +94,22 @@ func main() {
}
defer db.Close()
if *rollbackHeight >= 0 {
bestHeight, _, err := db.GetBestBlock()
if err != nil {
log.Fatalf("rollbackHeight: %v", err)
}
if uint32(*rollbackHeight) > bestHeight {
log.Printf("nothing to rollback, rollbackHeight %d, bestHeight: %d", *rollbackHeight, bestHeight)
} else {
err = db.DisconnectBlocks(uint32(*rollbackHeight), bestHeight)
if err != nil {
log.Fatalf("rollbackHeight: %v", err)
}
}
return
}
if *resync {
if err := resyncIndex(rpc, db); err != nil {
log.Fatalf("resyncIndex %v", err)