Browse Source

add git commit hash to nodeInfo

pull/110/head
Ethan Buchman 10 years ago
parent
commit
3f7f3dd37f
10 changed files with 38 additions and 20 deletions
  1. +1
    -0
      .gitignore
  2. +4
    -3
      Makefile
  3. +6
    -0
      common/os.go
  4. +1
    -1
      crawler/crawl.go
  5. +8
    -0
      node/node.go
  6. +5
    -0
      p2p/switch.go
  7. +1
    -3
      rpc/core/net.go
  8. +6
    -8
      rpc/core/types/responses.go
  9. +2
    -2
      rpc/test/tests.go
  10. +4
    -3
      types/node.go

+ 1
- 0
.gitignore View File

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

+ 4
- 3
Makefile View File

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

+ 6
- 0
common/os.go View File

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


+ 1
- 1
crawler/crawl.go 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 // 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


+ 8
- 0
node/node.go View File

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


+ 5
- 0
p2p/switch.go View File

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


+ 1
- 3
rpc/core/net.go View File

@ -31,9 +31,7 @@ func Status() (*ctypes.ResponseStatus, error) {
} }
return &ctypes.ResponseStatus{ return &ctypes.ResponseStatus{
Moniker: config.GetString("moniker"),
ChainID: config.GetString("chain_id"),
Version: config.GetString("version"),
NodeInfo: p2pSwitch.NodeInfo(),
GenesisHash: genesisHash, GenesisHash: genesisHash,
PubKey: privValidator.PubKey, PubKey: privValidator.PubKey,
LatestBlockHash: latestBlockHash, LatestBlockHash: latestBlockHash,


+ 6
- 8
rpc/core/types/responses.go View File

@ -49,14 +49,12 @@ type Receipt struct {
} }
type ResponseStatus 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 { type ResponseNetInfo struct {


+ 2
- 2
rpc/test/tests.go View File

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


+ 4
- 3
types/node.go View File

@ -6,9 +6,10 @@ import (
) )
type NodeInfo struct { 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"` Host string `json:"host"`
P2PPort uint16 `json:"p2p_port"` P2PPort uint16 `json:"p2p_port"`


Loading…
Cancel
Save