Browse Source

Include peer round states in the dump_consensus_state RPC call.

pull/61/head
Jae Kwon 10 years ago
parent
commit
9a8652e001
6 changed files with 27 additions and 8 deletions
  1. +2
    -0
      binary/README.md
  2. +4
    -4
      consensus/reactor.go
  3. +1
    -0
      node/node.go
  4. +11
    -2
      rpc/core/consensus.go
  5. +7
    -1
      rpc/core/pipe.go
  6. +2
    -1
      rpc/core/types/responses.go

+ 2
- 0
binary/README.md View File

@ -3,6 +3,8 @@
This documentation is out of date.
* 0x00 is reserved as a nil byte for RegisterInterface
* moved TypeByte() into RegisterInterface/ConcreteType
* Pointers that don't have a declared TypeByte() are
encoded with a leading 0x00 (nil) or 0x01.
# `tendermint/binary`


+ 4
- 4
consensus/reactor.go View File

@ -24,7 +24,7 @@ const (
DataChannel = byte(0x21)
VoteChannel = byte(0x22)
peerStateKey = "ConsensusReactor.peerState"
PeerStateKey = "ConsensusReactor.peerState"
peerGossipSleepDuration = 100 * time.Millisecond // Time to sleep if there's nothing to send.
)
@ -106,7 +106,7 @@ func (conR *ConsensusReactor) AddPeer(peer *p2p.Peer) {
// Create peerState for peer
peerState := NewPeerState(peer)
peer.Data.Set(peerStateKey, peerState)
peer.Data.Set(PeerStateKey, peerState)
// Begin gossip routines for this peer.
go conR.gossipDataRoutine(peer, peerState)
@ -121,7 +121,7 @@ func (conR *ConsensusReactor) RemovePeer(peer *p2p.Peer, reason interface{}) {
if !conR.IsRunning() {
return
}
//peer.Data.Get(peerStateKey).(*PeerState).Disconnect()
//peer.Data.Get(PeerStateKey).(*PeerState).Disconnect()
}
// Implements Reactor
@ -132,7 +132,7 @@ func (conR *ConsensusReactor) Receive(chId byte, peer *p2p.Peer, msgBytes []byte
// Get round state
rs := conR.conS.GetRoundState()
ps := peer.Data.Get(peerStateKey).(*PeerState)
ps := peer.Data.Get(PeerStateKey).(*PeerState)
_, msg_, err := DecodeMessage(msgBytes)
if err != nil {
log.Warn("Error decoding message", "channel", chId, "peer", peer, "msg", msg_, "error", err, "bytes", msgBytes)


+ 1
- 0
node/node.go View File

@ -178,6 +178,7 @@ func (n *Node) dialSeed(addr *p2p.NetAddress) {
func (n *Node) StartRPC() {
core.SetBlockStore(n.blockStore)
core.SetConsensusState(n.consensusState)
core.SetConsensusReactor(n.consensusReactor)
core.SetMempoolReactor(n.mempoolReactor)
core.SetSwitch(n.sw)


+ 11
- 2
rpc/core/consensus.go View File

@ -2,6 +2,7 @@ package core
import (
"github.com/tendermint/tendermint/binary"
cm "github.com/tendermint/tendermint/consensus"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
sm "github.com/tendermint/tendermint/state"
)
@ -26,6 +27,14 @@ func ListValidators() (*ctypes.ResponseListValidators, error) {
}
func DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error) {
jsonBytes := binary.JSONBytes(consensusState.GetRoundState())
return &ctypes.ResponseDumpConsensusState{string(jsonBytes)}, nil
roundState := consensusState.GetRoundState()
peerRoundStates := []string{}
for _, peer := range p2pSwitch.Peers().List() {
// TODO: clean this up?
peerState := peer.Data.Get(cm.PeerStateKey).(*cm.PeerState)
peerRoundState := peerState.GetRoundState()
peerRoundStateStr := peer.Key + ":" + string(binary.JSONBytes(peerRoundState))
peerRoundStates = append(peerRoundStates, peerRoundStateStr)
}
return &ctypes.ResponseDumpConsensusState{roundState.String(), peerRoundStates}, nil
}

+ 7
- 1
rpc/core/pipe.go View File

@ -10,6 +10,7 @@ import (
var blockStore *bc.BlockStore
var consensusState *consensus.ConsensusState
var consensusReactor *consensus.ConsensusReactor
var mempoolReactor *mempl.MempoolReactor
var p2pSwitch *p2p.Switch
@ -21,6 +22,10 @@ func SetConsensusState(cs *consensus.ConsensusState) {
consensusState = cs
}
func SetConsensusReactor(cr *consensus.ConsensusReactor) {
consensusReactor = cr
}
func SetMempoolReactor(mr *mempl.MempoolReactor) {
mempoolReactor = mr
}
@ -29,6 +34,7 @@ func SetSwitch(sw *p2p.Switch) {
p2pSwitch = sw
}
// JAE Why is this here?
func SetPrivValidator(priv *state.PrivValidator) {
consensusState.SetPrivValidator(priv)
consensusReactor.SetPrivValidator(priv)
}

+ 2
- 1
rpc/core/types/responses.go View File

@ -93,5 +93,6 @@ type ResponseListValidators struct {
}
type ResponseDumpConsensusState struct {
ConsensusState string
RoundState string
PeerRoundStates []string
}

Loading…
Cancel
Save