add git commit hash to nodeInfo

This commit is contained in:
Ethan Buchman 2015-07-10 15:50:58 +00:00
parent 751b892cba
commit 3f7f3dd37f
10 changed files with 38 additions and 20 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ rpc/test/.tendermint
.debora
.tendermint
remote_dump
.revision

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -49,14 +49,12 @@ type Receipt struct {
}
type ResponseStatus struct {
Moniker string `json:"moniker"`
ChainID string `json:"chain_id"`
Version string `json:"version"`
GenesisHash []byte `json:"genesis_hash"`
PubKey account.PubKey `json:"pub_key"`
LatestBlockHash []byte `json:"latest_block_hash"`
LatestBlockHeight int `json:"latest_block_height"`
LatestBlockTime int64 `json:"latest_block_time"` // nano
NodeInfo *types.NodeInfo `json:"node_info"`
GenesisHash []byte `json:"genesis_hash"`
PubKey account.PubKey `json:"pub_key"`
LatestBlockHash []byte `json:"latest_block_hash"`
LatestBlockHeight int `json:"latest_block_height"`
LatestBlockTime int64 `json:"latest_block_time"` // nano
}
type ResponseNetInfo struct {

View File

@ -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))
}
}

View File

@ -6,9 +6,10 @@ import (
)
type NodeInfo struct {
Moniker string `json:"moniker"`
ChainID string `json:"chain_id"`
Version string `json:"version"`
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"`