Skip to content

Commit

Permalink
statesync: get the hash exactly at the snapshot height
Browse files Browse the repository at this point in the history
  • Loading branch information
altergui committed Apr 16, 2024
1 parent ccf1d71 commit 01e4eb2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions vochain/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ func newTendermint(app *BaseApplication,
log.Warnf("cannot fetch status from remote RPC server: %v", err)
return 0, ""
}
// try to get the hash exactly at the snapshot height, to avoid a long verification chain
height := status.SyncInfo.LatestBlockHeight - (status.SyncInfo.LatestBlockHeight % int64(localConfig.SnapshotInterval))
b, err := cli.Block(context.TODO(), &height)
if err == nil {
log.Infow("fetched statesync params from remote RPC",
"height", height, "hash", b.BlockID.Hash.String())
return height, b.BlockID.Hash.String()
}
// else at least fallback to the latest height and hash
log.Infow("fetched statesync params from remote RPC",
"height", status.SyncInfo.LatestBlockHeight, "hash", status.SyncInfo.LatestBlockHash.String())
return status.SyncInfo.LatestBlockHeight, status.SyncInfo.LatestBlockHash.String()
Expand Down

0 comments on commit 01e4eb2

Please sign in to comment.