Include peer round states in the dump_consensus_state RPC call.

This commit is contained in:
Jae Kwon
2015-04-25 11:49:26 -07:00
parent 5557923245
commit 9a8652e001
6 changed files with 27 additions and 8 deletions

View File

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

View File

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

View File

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

View File

@ -2,6 +2,7 @@ package core
import ( import (
"github.com/tendermint/tendermint/binary" "github.com/tendermint/tendermint/binary"
cm "github.com/tendermint/tendermint/consensus"
ctypes "github.com/tendermint/tendermint/rpc/core/types" ctypes "github.com/tendermint/tendermint/rpc/core/types"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
) )
@ -26,6 +27,14 @@ func ListValidators() (*ctypes.ResponseListValidators, error) {
} }
func DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error) { func DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error) {
jsonBytes := binary.JSONBytes(consensusState.GetRoundState()) roundState := consensusState.GetRoundState()
return &ctypes.ResponseDumpConsensusState{string(jsonBytes)}, nil 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
} }

View File

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

View File

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