mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-17 15:11:21 +00:00
add git commit hash to nodeInfo
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ rpc/test/.tendermint
|
|||||||
.debora
|
.debora
|
||||||
.tendermint
|
.tendermint
|
||||||
remote_dump
|
remote_dump
|
||||||
|
.revision
|
||||||
|
7
Makefile
7
Makefile
@ -8,6 +8,7 @@ install:
|
|||||||
go install github.com/tendermint/tendermint/cmd/debora
|
go install github.com/tendermint/tendermint/cmd/debora
|
||||||
go install github.com/tendermint/tendermint/cmd/stdinwriter
|
go install github.com/tendermint/tendermint/cmd/stdinwriter
|
||||||
go install github.com/tendermint/tendermint/cmd/logjack
|
go install github.com/tendermint/tendermint/cmd/logjack
|
||||||
|
echo -n `git rev-parse --verify HEAD` > .revision
|
||||||
|
|
||||||
build:
|
build:
|
||||||
go build -o build/tendermint github.com/tendermint/tendermint/cmd/tendermint
|
go build -o build/tendermint github.com/tendermint/tendermint/cmd/tendermint
|
||||||
@ -42,11 +43,11 @@ gen_client:
|
|||||||
go install github.com/ebuchman/go-rpc-gen
|
go install github.com/ebuchman/go-rpc-gen
|
||||||
go generate rpc/core_client/*.go
|
go generate rpc/core_client/*.go
|
||||||
|
|
||||||
|
revision:
|
||||||
|
echo -n `git rev-parse --verify HEAD` > .revision
|
||||||
|
|
||||||
tendermint_root/priv_validator.json: tendermint_root/priv_validator.json.orig
|
tendermint_root/priv_validator.json: tendermint_root/priv_validator.json.orig
|
||||||
cp $< $@
|
cp $< $@
|
||||||
|
|
||||||
economy: tendermint_root/priv_validator.json
|
|
||||||
docker run -v $(CURDIR)/tendermint_root:/tendermint_root -p 46656:46656 tendermint
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f tendermint tendermint_root/priv_validator.json
|
rm -f tendermint tendermint_root/priv_validator.json
|
||||||
|
@ -5,10 +5,16 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"path"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
GoPath = os.Getenv("GOPATH")
|
||||||
|
TendermintRepo = path.Join(GoPath, "src", "github.com", "tendermint", "tendermint")
|
||||||
|
)
|
||||||
|
|
||||||
func TrapSignal(cb func()) {
|
func TrapSignal(cb func()) {
|
||||||
c := make(chan os.Signal, 1)
|
c := make(chan os.Signal, 1)
|
||||||
signal.Notify(c, os.Interrupt)
|
signal.Notify(c, os.Interrupt)
|
||||||
|
@ -50,7 +50,7 @@ func (n *Node) Address() string {
|
|||||||
// Set the basic status and chain_id info for a node from RPC responses
|
// Set the basic status and chain_id info for a node from RPC responses
|
||||||
func (n *Node) SetInfo(status *rpctypes.ResponseStatus, netinfo *rpctypes.ResponseNetInfo) {
|
func (n *Node) SetInfo(status *rpctypes.ResponseStatus, netinfo *rpctypes.ResponseNetInfo) {
|
||||||
n.LastSeen = time.Now()
|
n.LastSeen = time.Now()
|
||||||
n.ChainID = status.ChainID
|
n.ChainID = status.NodeInfo.ChainID
|
||||||
n.BlockHeight = status.LatestBlockHeight
|
n.BlockHeight = status.LatestBlockHeight
|
||||||
n.NetInfo = netinfo
|
n.NetInfo = netinfo
|
||||||
// n.Validator
|
// n.Validator
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -242,9 +243,16 @@ func makeNodeInfo(sw *p2p.Switch) *types.NodeInfo {
|
|||||||
Moniker: config.GetString("moniker"),
|
Moniker: config.GetString("moniker"),
|
||||||
Version: config.GetString("version"),
|
Version: config.GetString("version"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// include git hash in the nodeInfo if available
|
||||||
|
if rev, err := ReadFile(path.Join(TendermintRepo, ".revision")); err == nil {
|
||||||
|
nodeInfo.Revision = string(rev)
|
||||||
|
}
|
||||||
|
|
||||||
if !sw.IsListening() {
|
if !sw.IsListening() {
|
||||||
return nodeInfo
|
return nodeInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
p2pListener := sw.Listeners()[0]
|
p2pListener := sw.Listeners()[0]
|
||||||
p2pHost := p2pListener.ExternalAddress().IP.String()
|
p2pHost := p2pListener.ExternalAddress().IP.String()
|
||||||
p2pPort := p2pListener.ExternalAddress().Port
|
p2pPort := p2pListener.ExternalAddress().Port
|
||||||
|
@ -119,6 +119,11 @@ func (sw *Switch) SetNodeInfo(nodeInfo *types.NodeInfo) {
|
|||||||
sw.nodeInfo = nodeInfo
|
sw.nodeInfo = nodeInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Not goroutine safe.
|
||||||
|
func (sw *Switch) NodeInfo() *types.NodeInfo {
|
||||||
|
return sw.nodeInfo
|
||||||
|
}
|
||||||
|
|
||||||
func (sw *Switch) Start() {
|
func (sw *Switch) Start() {
|
||||||
if atomic.CompareAndSwapUint32(&sw.running, 0, 1) {
|
if atomic.CompareAndSwapUint32(&sw.running, 0, 1) {
|
||||||
// Start reactors
|
// Start reactors
|
||||||
|
@ -31,9 +31,7 @@ func Status() (*ctypes.ResponseStatus, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &ctypes.ResponseStatus{
|
return &ctypes.ResponseStatus{
|
||||||
Moniker: config.GetString("moniker"),
|
NodeInfo: p2pSwitch.NodeInfo(),
|
||||||
ChainID: config.GetString("chain_id"),
|
|
||||||
Version: config.GetString("version"),
|
|
||||||
GenesisHash: genesisHash,
|
GenesisHash: genesisHash,
|
||||||
PubKey: privValidator.PubKey,
|
PubKey: privValidator.PubKey,
|
||||||
LatestBlockHash: latestBlockHash,
|
LatestBlockHash: latestBlockHash,
|
||||||
|
@ -49,14 +49,12 @@ type Receipt struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ResponseStatus struct {
|
type ResponseStatus struct {
|
||||||
Moniker string `json:"moniker"`
|
NodeInfo *types.NodeInfo `json:"node_info"`
|
||||||
ChainID string `json:"chain_id"`
|
GenesisHash []byte `json:"genesis_hash"`
|
||||||
Version string `json:"version"`
|
PubKey account.PubKey `json:"pub_key"`
|
||||||
GenesisHash []byte `json:"genesis_hash"`
|
LatestBlockHash []byte `json:"latest_block_hash"`
|
||||||
PubKey account.PubKey `json:"pub_key"`
|
LatestBlockHeight int `json:"latest_block_height"`
|
||||||
LatestBlockHash []byte `json:"latest_block_hash"`
|
LatestBlockTime int64 `json:"latest_block_time"` // nano
|
||||||
LatestBlockHeight int `json:"latest_block_height"`
|
|
||||||
LatestBlockTime int64 `json:"latest_block_time"` // nano
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResponseNetInfo struct {
|
type ResponseNetInfo struct {
|
||||||
|
@ -16,9 +16,9 @@ func testStatus(t *testing.T, typ string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if resp.ChainID != chainID {
|
if resp.NodeInfo.ChainID != chainID {
|
||||||
t.Fatal(fmt.Errorf("ChainID mismatch: got %s expected %s",
|
t.Fatal(fmt.Errorf("ChainID mismatch: got %s expected %s",
|
||||||
resp.ChainID, chainID))
|
resp.NodeInfo.ChainID, chainID))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,9 +6,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type NodeInfo struct {
|
type NodeInfo struct {
|
||||||
Moniker string `json:"moniker"`
|
Moniker string `json:"moniker"`
|
||||||
ChainID string `json:"chain_id"`
|
ChainID string `json:"chain_id"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
|
Revision string `json:"revision"`
|
||||||
|
|
||||||
Host string `json:"host"`
|
Host string `json:"host"`
|
||||||
P2PPort uint16 `json:"p2p_port"`
|
P2PPort uint16 `json:"p2p_port"`
|
||||||
|
Reference in New Issue
Block a user