From 752e7231e85f0777a3baa273dd1c86b15773455e Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Sun, 17 Jan 2021 15:46:17 -0600 Subject: [PATCH] rpcserver: Calc verify progress based on best hdr. 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. --- internal/rpcserver/rpcserver.go | 8 ++++---- internal/rpcserver/rpcserverhandlers_test.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/rpcserver/rpcserver.go b/internal/rpcserver/rpcserver.go index 1e08c3ff5c..292e8dfc56 100644 --- a/internal/rpcserver/rpcserver.go +++ b/internal/rpcserver/rpcserver.go @@ -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 @@ -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, diff --git a/internal/rpcserver/rpcserverhandlers_test.go b/internal/rpcserver/rpcserverhandlers_test.go index 0ca81a350c..53267ad57c 100644 --- a/internal/rpcserver/rpcserverhandlers_test.go +++ b/internal/rpcserver/rpcserverhandlers_test.go @@ -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),