From d26995a1e45267e395dee319bb043fd4e303bc47 Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Wed, 5 Jun 2019 13:29:06 +0200 Subject: [PATCH] Show blockbook status in case of backend error --- api/types.go | 23 ++++++++++++----------- api/worker.go | 16 +++++++++++----- static/templates/index.html | 6 ++++++ 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/api/types.go b/api/types.go index c839093e..111e6c55 100644 --- a/api/types.go +++ b/api/types.go @@ -341,17 +341,18 @@ type BlockbookInfo struct { // BackendInfo is used to get information about blockchain type BackendInfo struct { - Chain string `json:"chain"` - Blocks int `json:"blocks"` - Headers int `json:"headers"` - Bestblockhash string `json:"bestBlockHash"` - Difficulty string `json:"difficulty"` - SizeOnDisk int64 `json:"sizeOnDisk"` - Version string `json:"version"` - Subversion string `json:"subversion"` - ProtocolVersion string `json:"protocolVersion"` - Timeoffset float64 `json:"timeOffset"` - Warnings string `json:"warnings"` + BackendError string `json:"error,omitempty"` + Chain string `json:"chain,omitempty"` + Blocks int `json:"blocks,omitempty"` + Headers int `json:"headers,omitempty"` + BestBlockHash string `json:"bestBlockHash,omitempty"` + Difficulty string `json:"difficulty,omitempty"` + SizeOnDisk int64 `json:"sizeOnDisk,omitempty"` + Version string `json:"version,omitempty"` + Subversion string `json:"subversion,omitempty"` + ProtocolVersion string `json:"protocolVersion,omitempty"` + Timeoffset float64 `json:"timeOffset,omitempty"` + Warnings string `json:"warnings,omitempty"` } // SystemInfo contains information about the running blockbook and backend instance diff --git a/api/worker.go b/api/worker.go index e305ae45..b2a47795 100644 --- a/api/worker.go +++ b/api/worker.go @@ -1091,13 +1091,18 @@ func (w *Worker) ComputeFeeStats(blockFrom, blockTo int, stopCompute chan os.Sig // GetSystemInfo returns information about system func (w *Worker) GetSystemInfo(internal bool) (*SystemInfo, error) { start := time.Now() - ci, err := w.chain.GetChainInfo() - if err != nil { - return nil, errors.Annotatef(err, "GetChainInfo") - } vi := common.GetVersionInfo() inSync, bestHeight, lastBlockTime := w.is.GetSyncState() inSyncMempool, lastMempoolTime, mempoolSize := w.is.GetMempoolSyncState() + ci, err := w.chain.GetChainInfo() + var backendError string + if err != nil { + backendError = errors.Annotatef(err, "GetChainInfo").Error() + ci = &bchain.ChainInfo{} + // set not in sync in case of backend error + inSync = false + inSyncMempool = false + } var columnStats []common.InternalStateColumn var internalDBSize int64 if internal { @@ -1125,7 +1130,8 @@ func (w *Worker) GetSystemInfo(internal bool) (*SystemInfo, error) { About: Text.BlockbookAbout, } backendInfo := &BackendInfo{ - Bestblockhash: ci.Bestblockhash, + BackendError: backendError, + BestBlockHash: ci.Bestblockhash, Blocks: ci.Blocks, Chain: ci.Chain, Difficulty: ci.Difficulty, diff --git a/static/templates/index.html b/static/templates/index.html index 5e275fc3..ff36faa8 100644 --- a/static/templates/index.html +++ b/static/templates/index.html @@ -58,6 +58,12 @@

Backend

+ {{- if $be.BackendError -}} + + + + + {{- end -}}
Backend Error{{$be.BackendError}}
Chain {{$be.Chain}}