add git commit hash to nodeInfo
This commit is contained in:
parent
751b892cba
commit
3f7f3dd37f
|
@ -8,3 +8,4 @@ rpc/test/.tendermint
|
|||
.debora
|
||||
.tendermint
|
||||
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/stdinwriter
|
||||
go install github.com/tendermint/tendermint/cmd/logjack
|
||||
echo -n `git rev-parse --verify HEAD` > .revision
|
||||
|
||||
build:
|
||||
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 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
|
||||
cp $< $@
|
||||
|
||||
economy: tendermint_root/priv_validator.json
|
||||
docker run -v $(CURDIR)/tendermint_root:/tendermint_root -p 46656:46656 tendermint
|
||||
|
||||
clean:
|
||||
rm -f tendermint tendermint_root/priv_validator.json
|
||||
|
|
|
@ -5,10 +5,16 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
GoPath = os.Getenv("GOPATH")
|
||||
TendermintRepo = path.Join(GoPath, "src", "github.com", "tendermint", "tendermint")
|
||||
)
|
||||
|
||||
func TrapSignal(cb func()) {
|
||||
c := make(chan os.Signal, 1)
|
||||
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
|
||||
func (n *Node) SetInfo(status *rpctypes.ResponseStatus, netinfo *rpctypes.ResponseNetInfo) {
|
||||
n.LastSeen = time.Now()
|
||||
n.ChainID = status.ChainID
|
||||
n.ChainID = status.NodeInfo.ChainID
|
||||
n.BlockHeight = status.LatestBlockHeight
|
||||
n.NetInfo = netinfo
|
||||
// n.Validator
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -242,9 +243,16 @@ func makeNodeInfo(sw *p2p.Switch) *types.NodeInfo {
|
|||
Moniker: config.GetString("moniker"),
|
||||
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() {
|
||||
return nodeInfo
|
||||
}
|
||||
|
||||
p2pListener := sw.Listeners()[0]
|
||||
p2pHost := p2pListener.ExternalAddress().IP.String()
|
||||
p2pPort := p2pListener.ExternalAddress().Port
|
||||
|
|
|
@ -119,6 +119,11 @@ func (sw *Switch) SetNodeInfo(nodeInfo *types.NodeInfo) {
|
|||
sw.nodeInfo = nodeInfo
|
||||
}
|
||||
|
||||
// Not goroutine safe.
|
||||
func (sw *Switch) NodeInfo() *types.NodeInfo {
|
||||
return sw.nodeInfo
|
||||
}
|
||||
|
||||
func (sw *Switch) Start() {
|
||||
if atomic.CompareAndSwapUint32(&sw.running, 0, 1) {
|
||||
// Start reactors
|
||||
|
|
|
@ -31,9 +31,7 @@ func Status() (*ctypes.ResponseStatus, error) {
|
|||
}
|
||||
|
||||
return &ctypes.ResponseStatus{
|
||||
Moniker: config.GetString("moniker"),
|
||||
ChainID: config.GetString("chain_id"),
|
||||
Version: config.GetString("version"),
|
||||
NodeInfo: p2pSwitch.NodeInfo(),
|
||||
GenesisHash: genesisHash,
|
||||
PubKey: privValidator.PubKey,
|
||||
LatestBlockHash: latestBlockHash,
|
||||
|
|
|
@ -49,9 +49,7 @@ type Receipt struct {
|
|||
}
|
||||
|
||||
type ResponseStatus struct {
|
||||
Moniker string `json:"moniker"`
|
||||
ChainID string `json:"chain_id"`
|
||||
Version string `json:"version"`
|
||||
NodeInfo *types.NodeInfo `json:"node_info"`
|
||||
GenesisHash []byte `json:"genesis_hash"`
|
||||
PubKey account.PubKey `json:"pub_key"`
|
||||
LatestBlockHash []byte `json:"latest_block_hash"`
|
||||
|
|
|
@ -16,9 +16,9 @@ func testStatus(t *testing.T, typ string) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if resp.ChainID != chainID {
|
||||
if resp.NodeInfo.ChainID != chainID {
|
||||
t.Fatal(fmt.Errorf("ChainID mismatch: got %s expected %s",
|
||||
resp.ChainID, chainID))
|
||||
resp.NodeInfo.ChainID, chainID))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ type NodeInfo struct {
|
|||
Moniker string `json:"moniker"`
|
||||
ChainID string `json:"chain_id"`
|
||||
Version string `json:"version"`
|
||||
Revision string `json:"revision"`
|
||||
|
||||
Host string `json:"host"`
|
||||
P2PPort uint16 `json:"p2p_port"`
|
||||
|
|
Loading…
Reference in New Issue