Skip to content

Commit

Permalink
rpcserver: Calc verify progress based on best hdr.
Browse files Browse the repository at this point in the history
This modifies the RPC server getblockchaininfo to base the verification
progress calculation on the best header now that all headers are
determined prior to downloading and verifying blocks.
  • Loading branch information
davecgh committed Jan 19, 2021
1 parent 1d98814 commit 2e55226
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions internal/rpcserver/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2035,10 +2035,10 @@ func handleGetBlockchainInfo(_ context.Context, s *Server, cmd interface{}) (int
}

// Estimate the verification progress of the node.
syncHeight := s.cfg.SyncMgr.SyncHeight()
var verifyProgress float64
if syncHeight > 0 {
verifyProgress = math.Min(float64(best.Height)/float64(syncHeight), 1.0)
if bestHeaderHeight > 0 {
progress := float64(best.Height) / float64(bestHeaderHeight)
verifyProgress = math.Min(progress, 1.0)
}

// Fetch the maximum allowed block size for all blocks other than the
Expand Down Expand Up @@ -2101,7 +2101,7 @@ func handleGetBlockchainInfo(_ context.Context, s *Server, cmd interface{}) (int
Chain: params.Name,
Blocks: best.Height,
Headers: bestHeaderHeight,
SyncHeight: syncHeight,
SyncHeight: s.cfg.SyncMgr.SyncHeight(),
ChainWork: fmt.Sprintf("%064x", chainWork),
InitialBlockDownload: !chain.IsCurrent(),
VerificationProgress: verifyProgress,
Expand Down
2 changes: 1 addition & 1 deletion internal/rpcserver/rpcserverhandlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3519,7 +3519,7 @@ func TestHandleGetBlockchainInfo(t *testing.T) {
SyncHeight: int64(463074),
ChainWork: "000000000000000000000000000000000000000000115d2833849090b0026506",
InitialBlockDownload: true,
VerificationProgress: float64(0.9999978405179302),
VerificationProgress: float64(1),
BestBlockHash: "00000000000000001e6ec1501c858506de1de4703d1be8bab4061126e8f61480",
Difficulty: uint32(404696953),
DifficultyRatio: float64(35256672611.3862),
Expand Down

0 comments on commit 2e55226

Please sign in to comment.