Skip to content

Commit

Permalink
Show blockbook status in case of backend error
Browse files Browse the repository at this point in the history
  • Loading branch information
martinboehm committed Jun 5, 2019
1 parent d7d596b commit d26995a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
23 changes: 12 additions & 11 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions api/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions static/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ <h3>Blockbook</h3>
<h3>Backend</h3>
<table class="table data-table">
<tbody>
{{- if $be.BackendError -}}
<tr>
<td style="width: 30%;">Backend Error</td>
<td class="data text-danger">{{$be.BackendError}}</td>
</tr>
{{- end -}}
<tr>
<td style="width: 30%;">Chain</td>
<td class="data">{{$be.Chain}}</td>
Expand Down

0 comments on commit d26995a

Please sign in to comment.