Return ethereum consensus layer node version via API
This commit is contained in:
parent
76b6f93059
commit
835d0e07ba
@ -2075,19 +2075,20 @@ func (w *Worker) GetSystemInfo(internal bool) (*SystemInfo, error) {
|
|||||||
About: Text.BlockbookAbout,
|
About: Text.BlockbookAbout,
|
||||||
}
|
}
|
||||||
backendInfo := &common.BackendInfo{
|
backendInfo := &common.BackendInfo{
|
||||||
BackendError: backendError,
|
BackendError: backendError,
|
||||||
BestBlockHash: ci.Bestblockhash,
|
BestBlockHash: ci.Bestblockhash,
|
||||||
Blocks: ci.Blocks,
|
Blocks: ci.Blocks,
|
||||||
Chain: ci.Chain,
|
Chain: ci.Chain,
|
||||||
Difficulty: ci.Difficulty,
|
Difficulty: ci.Difficulty,
|
||||||
Headers: ci.Headers,
|
Headers: ci.Headers,
|
||||||
ProtocolVersion: ci.ProtocolVersion,
|
ProtocolVersion: ci.ProtocolVersion,
|
||||||
SizeOnDisk: ci.SizeOnDisk,
|
SizeOnDisk: ci.SizeOnDisk,
|
||||||
Subversion: ci.Subversion,
|
Subversion: ci.Subversion,
|
||||||
Timeoffset: ci.Timeoffset,
|
Timeoffset: ci.Timeoffset,
|
||||||
Version: ci.Version,
|
Version: ci.Version,
|
||||||
Warnings: ci.Warnings,
|
Warnings: ci.Warnings,
|
||||||
Consensus: ci.Consensus,
|
ConsensusVersion: ci.ConsensusVersion,
|
||||||
|
Consensus: ci.Consensus,
|
||||||
}
|
}
|
||||||
w.is.SetBackendInfo(backendInfo)
|
w.is.SetBackendInfo(backendInfo)
|
||||||
glog.Info("GetSystemInfo, ", time.Since(start))
|
glog.Info("GetSystemInfo, ", time.Since(start))
|
||||||
|
|||||||
@ -4,7 +4,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -46,6 +48,7 @@ type Configuration struct {
|
|||||||
QueryBackendOnMempoolResync bool `json:"queryBackendOnMempoolResync"`
|
QueryBackendOnMempoolResync bool `json:"queryBackendOnMempoolResync"`
|
||||||
ProcessInternalTransactions bool `json:"processInternalTransactions"`
|
ProcessInternalTransactions bool `json:"processInternalTransactions"`
|
||||||
ProcessZeroInternalTransactions bool `json:"processZeroInternalTransactions"`
|
ProcessZeroInternalTransactions bool `json:"processZeroInternalTransactions"`
|
||||||
|
ConsensusNodeVersionURL string `json:"consensusNodeVersion"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// EthereumRPC is an interface to JSON-RPC eth service.
|
// EthereumRPC is an interface to JSON-RPC eth service.
|
||||||
@ -335,6 +338,37 @@ func (b *EthereumRPC) GetSubversion() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *EthereumRPC) getConsensusVersion() string {
|
||||||
|
if b.ChainConfig.ConsensusNodeVersionURL == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
httpClient := &http.Client{
|
||||||
|
Timeout: 2 * time.Second,
|
||||||
|
}
|
||||||
|
resp, err := httpClient.Get(b.ChainConfig.ConsensusNodeVersionURL)
|
||||||
|
if err != nil || resp.StatusCode != http.StatusOK {
|
||||||
|
glog.Error("getConsensusVersion ", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
glog.Error("getConsensusVersion ", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
type consensusVersion struct {
|
||||||
|
Data struct {
|
||||||
|
Version string `json:"version"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
var v consensusVersion
|
||||||
|
err = json.Unmarshal(body, &v)
|
||||||
|
if err != nil {
|
||||||
|
glog.Error("getConsensusVersion ", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return v.Data.Version
|
||||||
|
}
|
||||||
|
|
||||||
// GetChainInfo returns information about the connected backend
|
// GetChainInfo returns information about the connected backend
|
||||||
func (b *EthereumRPC) GetChainInfo() (*bchain.ChainInfo, error) {
|
func (b *EthereumRPC) GetChainInfo() (*bchain.ChainInfo, error) {
|
||||||
h, err := b.getBestHeader()
|
h, err := b.getBestHeader()
|
||||||
@ -351,11 +385,13 @@ func (b *EthereumRPC) GetChainInfo() (*bchain.ChainInfo, error) {
|
|||||||
if err := b.rpc.CallContext(ctx, &ver, "web3_clientVersion"); err != nil {
|
if err := b.rpc.CallContext(ctx, &ver, "web3_clientVersion"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
consensusVersion := b.getConsensusVersion()
|
||||||
rv := &bchain.ChainInfo{
|
rv := &bchain.ChainInfo{
|
||||||
Blocks: int(h.Number.Int64()),
|
Blocks: int(h.Number.Int64()),
|
||||||
Bestblockhash: h.Hash().Hex(),
|
Bestblockhash: h.Hash().Hex(),
|
||||||
Difficulty: h.Difficulty.String(),
|
Difficulty: h.Difficulty.String(),
|
||||||
Version: ver,
|
Version: ver,
|
||||||
|
ConsensusVersion: consensusVersion,
|
||||||
}
|
}
|
||||||
idi := int(id.Uint64())
|
idi := int(id.Uint64())
|
||||||
if idi == 1 {
|
if idi == 1 {
|
||||||
|
|||||||
@ -192,18 +192,19 @@ type MempoolEntry struct {
|
|||||||
|
|
||||||
// ChainInfo is used to get information about blockchain
|
// ChainInfo is used to get information about blockchain
|
||||||
type ChainInfo struct {
|
type ChainInfo struct {
|
||||||
Chain string `json:"chain"`
|
Chain string `json:"chain"`
|
||||||
Blocks int `json:"blocks"`
|
Blocks int `json:"blocks"`
|
||||||
Headers int `json:"headers"`
|
Headers int `json:"headers"`
|
||||||
Bestblockhash string `json:"bestblockhash"`
|
Bestblockhash string `json:"bestblockhash"`
|
||||||
Difficulty string `json:"difficulty"`
|
Difficulty string `json:"difficulty"`
|
||||||
SizeOnDisk int64 `json:"size_on_disk"`
|
SizeOnDisk int64 `json:"size_on_disk"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Subversion string `json:"subversion"`
|
Subversion string `json:"subversion"`
|
||||||
ProtocolVersion string `json:"protocolversion"`
|
ProtocolVersion string `json:"protocolversion"`
|
||||||
Timeoffset float64 `json:"timeoffset"`
|
Timeoffset float64 `json:"timeoffset"`
|
||||||
Warnings string `json:"warnings"`
|
Warnings string `json:"warnings"`
|
||||||
Consensus interface{} `json:"consensus,omitempty"`
|
ConsensusVersion string `json:"consensus_version,omitempty"`
|
||||||
|
Consensus interface{} `json:"consensus,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RPCError defines rpc error returned by backend
|
// RPCError defines rpc error returned by backend
|
||||||
|
|||||||
@ -31,19 +31,20 @@ type InternalStateColumn struct {
|
|||||||
|
|
||||||
// BackendInfo is used to get information about blockchain
|
// BackendInfo is used to get information about blockchain
|
||||||
type BackendInfo struct {
|
type BackendInfo struct {
|
||||||
BackendError string `json:"error,omitempty"`
|
BackendError string `json:"error,omitempty"`
|
||||||
Chain string `json:"chain,omitempty"`
|
Chain string `json:"chain,omitempty"`
|
||||||
Blocks int `json:"blocks,omitempty"`
|
Blocks int `json:"blocks,omitempty"`
|
||||||
Headers int `json:"headers,omitempty"`
|
Headers int `json:"headers,omitempty"`
|
||||||
BestBlockHash string `json:"bestBlockHash,omitempty"`
|
BestBlockHash string `json:"bestBlockHash,omitempty"`
|
||||||
Difficulty string `json:"difficulty,omitempty"`
|
Difficulty string `json:"difficulty,omitempty"`
|
||||||
SizeOnDisk int64 `json:"sizeOnDisk,omitempty"`
|
SizeOnDisk int64 `json:"sizeOnDisk,omitempty"`
|
||||||
Version string `json:"version,omitempty"`
|
Version string `json:"version,omitempty"`
|
||||||
Subversion string `json:"subversion,omitempty"`
|
Subversion string `json:"subversion,omitempty"`
|
||||||
ProtocolVersion string `json:"protocolVersion,omitempty"`
|
ProtocolVersion string `json:"protocolVersion,omitempty"`
|
||||||
Timeoffset float64 `json:"timeOffset,omitempty"`
|
Timeoffset float64 `json:"timeOffset,omitempty"`
|
||||||
Warnings string `json:"warnings,omitempty"`
|
Warnings string `json:"warnings,omitempty"`
|
||||||
Consensus interface{} `json:"consensus,omitempty"`
|
ConsensusVersion string `json:"consensus_version,omitempty"`
|
||||||
|
Consensus interface{} `json:"consensus,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// InternalState contains the data of the internal state
|
// InternalState contains the data of the internal state
|
||||||
|
|||||||
@ -51,10 +51,11 @@
|
|||||||
"mempool_sub_workers": 2,
|
"mempool_sub_workers": 2,
|
||||||
"block_addresses_to_keep": 300,
|
"block_addresses_to_keep": 300,
|
||||||
"additional_params": {
|
"additional_params": {
|
||||||
|
"consensusNodeVersion": "http://localhost:7536/eth/v1/node/version",
|
||||||
"mempoolTxTimeoutHours": 48,
|
"mempoolTxTimeoutHours": 48,
|
||||||
"queryBackendOnMempoolResync": false,
|
"queryBackendOnMempoolResync": false,
|
||||||
"fiat_rates": "coingecko",
|
"fiat_rates": "coingecko",
|
||||||
"fiat_rates_params": "{\"url\": \"https://api.coingecko.com/api/v3\", \"coin\": \"ethereum\", \"periodSeconds\": 60}"
|
"fiat_rates_params": "{\"url\": \"https://api.coingecko.com/api/v3\", \"coin\": \"ethereum\",\"platformIdentifier\": \"ethereum\",\"platformVsCurrency\": \"eth\",\"periodSeconds\": 900}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -51,6 +51,7 @@
|
|||||||
"mempool_sub_workers": 2,
|
"mempool_sub_workers": 2,
|
||||||
"block_addresses_to_keep": 600,
|
"block_addresses_to_keep": 600,
|
||||||
"additional_params": {
|
"additional_params": {
|
||||||
|
"consensusNodeVersion": "http://localhost:7516/eth/v1/node/version",
|
||||||
"address_aliases": true,
|
"address_aliases": true,
|
||||||
"mempoolTxTimeoutHours": 48,
|
"mempoolTxTimeoutHours": 48,
|
||||||
"processInternalTransactions": true,
|
"processInternalTransactions": true,
|
||||||
|
|||||||
@ -51,6 +51,7 @@
|
|||||||
"mempool_sub_workers": 2,
|
"mempool_sub_workers": 2,
|
||||||
"block_addresses_to_keep": 3000,
|
"block_addresses_to_keep": 3000,
|
||||||
"additional_params": {
|
"additional_params": {
|
||||||
|
"consensusNodeVersion": "http://localhost:17526/eth/v1/node/version",
|
||||||
"mempoolTxTimeoutHours": 12,
|
"mempoolTxTimeoutHours": 12,
|
||||||
"queryBackendOnMempoolResync": false
|
"queryBackendOnMempoolResync": false
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,6 +51,7 @@
|
|||||||
"mempool_sub_workers": 2,
|
"mempool_sub_workers": 2,
|
||||||
"block_addresses_to_keep": 3000,
|
"block_addresses_to_keep": 3000,
|
||||||
"additional_params": {
|
"additional_params": {
|
||||||
|
"consensusNodeVersion": "http://localhost:17506/eth/v1/node/version",
|
||||||
"address_aliases": true,
|
"address_aliases": true,
|
||||||
"mempoolTxTimeoutHours": 12,
|
"mempoolTxTimeoutHours": 12,
|
||||||
"processInternalTransactions": true,
|
"processInternalTransactions": true,
|
||||||
|
|||||||
@ -51,6 +51,7 @@
|
|||||||
"mempool_sub_workers": 2,
|
"mempool_sub_workers": 2,
|
||||||
"block_addresses_to_keep": 3000,
|
"block_addresses_to_keep": 3000,
|
||||||
"additional_params": {
|
"additional_params": {
|
||||||
|
"consensusNodeVersion": "http://localhost:17536/eth/v1/node/version",
|
||||||
"mempoolTxTimeoutHours": 12,
|
"mempoolTxTimeoutHours": 12,
|
||||||
"queryBackendOnMempoolResync": false
|
"queryBackendOnMempoolResync": false
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,6 +51,7 @@
|
|||||||
"mempool_sub_workers": 2,
|
"mempool_sub_workers": 2,
|
||||||
"block_addresses_to_keep": 3000,
|
"block_addresses_to_keep": 3000,
|
||||||
"additional_params": {
|
"additional_params": {
|
||||||
|
"consensusNodeVersion": "http://localhost:17516/eth/v1/node/version",
|
||||||
"address_aliases": true,
|
"address_aliases": true,
|
||||||
"mempoolTxTimeoutHours": 12,
|
"mempoolTxTimeoutHours": 12,
|
||||||
"processInternalTransactions": true,
|
"processInternalTransactions": true,
|
||||||
|
|||||||
27
db/sync.go
27
db/sync.go
@ -58,19 +58,20 @@ func (w *SyncWorker) updateBackendInfo() {
|
|||||||
ci = &bchain.ChainInfo{}
|
ci = &bchain.ChainInfo{}
|
||||||
}
|
}
|
||||||
w.is.SetBackendInfo(&common.BackendInfo{
|
w.is.SetBackendInfo(&common.BackendInfo{
|
||||||
BackendError: backendError,
|
BackendError: backendError,
|
||||||
BestBlockHash: ci.Bestblockhash,
|
BestBlockHash: ci.Bestblockhash,
|
||||||
Blocks: ci.Blocks,
|
Blocks: ci.Blocks,
|
||||||
Chain: ci.Chain,
|
Chain: ci.Chain,
|
||||||
Difficulty: ci.Difficulty,
|
Difficulty: ci.Difficulty,
|
||||||
Headers: ci.Headers,
|
Headers: ci.Headers,
|
||||||
ProtocolVersion: ci.ProtocolVersion,
|
ProtocolVersion: ci.ProtocolVersion,
|
||||||
SizeOnDisk: ci.SizeOnDisk,
|
SizeOnDisk: ci.SizeOnDisk,
|
||||||
Subversion: ci.Subversion,
|
Subversion: ci.Subversion,
|
||||||
Timeoffset: ci.Timeoffset,
|
Timeoffset: ci.Timeoffset,
|
||||||
Version: ci.Version,
|
Version: ci.Version,
|
||||||
Warnings: ci.Warnings,
|
Warnings: ci.Warnings,
|
||||||
Consensus: ci.Consensus,
|
ConsensusVersion: ci.ConsensusVersion,
|
||||||
|
Consensus: ci.Consensus,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -569,9 +569,10 @@ func (s *WebsocketServer) getInfo() (interface{}, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
type backendInfo struct {
|
type backendInfo struct {
|
||||||
Version string `json:"version,omitempty"`
|
Version string `json:"version,omitempty"`
|
||||||
Subversion string `json:"subversion,omitempty"`
|
Subversion string `json:"subversion,omitempty"`
|
||||||
Consensus interface{} `json:"consensus,omitempty"`
|
ConsensusVersion string `json:"consensus_version,omitempty"`
|
||||||
|
Consensus interface{} `json:"consensus,omitempty"`
|
||||||
}
|
}
|
||||||
type info struct {
|
type info struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@ -594,9 +595,10 @@ func (s *WebsocketServer) getInfo() (interface{}, error) {
|
|||||||
Block0Hash: s.block0hash,
|
Block0Hash: s.block0hash,
|
||||||
Testnet: s.chain.IsTestnet(),
|
Testnet: s.chain.IsTestnet(),
|
||||||
Backend: backendInfo{
|
Backend: backendInfo{
|
||||||
Version: bi.Version,
|
Version: bi.Version,
|
||||||
Subversion: bi.Subversion,
|
Subversion: bi.Subversion,
|
||||||
Consensus: bi.Consensus,
|
ConsensusVersion: bi.ConsensusVersion,
|
||||||
|
Consensus: bi.Consensus,
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,14 +72,24 @@
|
|||||||
<td>Version</td>
|
<td>Version</td>
|
||||||
<td class="data">{{$be.Version}}</td>
|
<td class="data">{{$be.Version}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{{- if $be.Subversion -}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>Subversion</td>
|
<td>Subversion</td>
|
||||||
<td class="data">{{$be.Subversion}}</td>
|
<td class="data">{{$be.Subversion}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{{- end -}}
|
||||||
|
{{- if $be.ProtocolVersion -}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>Protocol Version</td>
|
<td>Protocol Version</td>
|
||||||
<td class="data">{{$be.ProtocolVersion}}</td>
|
<td class="data">{{$be.ProtocolVersion}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{{- end -}}
|
||||||
|
{{- if $be.ConsensusVersion -}}
|
||||||
|
<tr>
|
||||||
|
<td>Consensus Version</td>
|
||||||
|
<td class="data">{{$be.ConsensusVersion}}</td>
|
||||||
|
</tr>
|
||||||
|
{{- end -}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>Last Block</td>
|
<td>Last Block</td>
|
||||||
<td class="data">{{$be.Blocks}}</td>
|
<td class="data">{{$be.Blocks}}</td>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user