Browse Source

rpc: /consensus_state for simplified output

pull/1564/head
Ethan Buchman 6 years ago
parent
commit
a41f0d3891
7 changed files with 52 additions and 2 deletions
  1. +8
    -0
      consensus/state.go
  2. +7
    -2
      consensus/types/height_vote_set.go
  3. +23
    -0
      consensus/types/round_state.go
  4. +7
    -0
      rpc/core/consensus.go
  5. +1
    -0
      rpc/core/pipe.go
  6. +1
    -0
      rpc/core/routes.go
  7. +5
    -0
      rpc/core/types/responses.go

+ 8
- 0
consensus/state.go View File

@ -185,6 +185,14 @@ func (cs *ConsensusState) GetRoundStateJSON() ([]byte, error) {
return cdc.MarshalJSON(cs.RoundState)
}
// GetRoundStateSimpleJSON returns a json of RoundStateSimple, marshalled using go-amino.
func (cs *ConsensusState) GetRoundStateSimpleJSON() ([]byte, error) {
cs.mtx.Lock()
defer cs.mtx.Unlock()
return cdc.MarshalJSON(cs.RoundState.RoundStateSimple())
}
// GetValidators returns a copy of the current validators.
func (cs *ConsensusState) GetValidators() (int64, []*types.Validator) {
cs.mtx.Lock()


+ 7
- 2
consensus/types/height_vote_set.go View File

@ -219,6 +219,12 @@ type roundVotes struct {
func (hvs *HeightVoteSet) MarshalJSON() ([]byte, error) {
hvs.mtx.Lock()
defer hvs.mtx.Unlock()
roundsVotes := hvs.toRoundVotes()
return cdc.MarshalJSON(roundsVotes)
}
func (hvs *HeightVoteSet) toRoundVotes() []roundVotes {
totalRounds := hvs.round + 1
roundsVotes := make([]roundVotes, totalRounds)
// rounds 0 ~ hvs.round inclusive
@ -232,8 +238,7 @@ func (hvs *HeightVoteSet) MarshalJSON() ([]byte, error) {
}
}
// TODO: all other peer catchup rounds
return cdc.MarshalJSON(roundsVotes)
return roundsVotes
}
// If a peer claims that it has 2/3 majority for given blockKey, call this.


+ 23
- 0
consensus/types/round_state.go View File

@ -1,10 +1,12 @@
package types
import (
"encoding/json"
"fmt"
"time"
"github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common"
)
//-----------------------------------------------------------------------------
@ -77,6 +79,27 @@ type RoundState struct {
LastValidators *types.ValidatorSet `json:"last_validators"`
}
type RoundStateSimple struct {
HeightRoundStep string `json:"height/round/step"`
StartTime time.Time `json:"start_time"`
ProposalBlockHash cmn.HexBytes `json:"proposal_block_hash"`
LockedBlockHash cmn.HexBytes `json:"locked_block_hash"`
ValidBlockHash cmn.HexBytes `json:"valid_block_hash"`
Votes json.RawMessage `json:"height_vote_set"`
}
func (rs *RoundState) RoundStateSimple() RoundStateSimple {
votesJSON, _ := rs.Votes.MarshalJSON() // TODO err
return RoundStateSimple{
HeightRoundStep: fmt.Sprintf("%d/%d/%d", rs.Height, rs.Round, rs.Step),
StartTime: rs.StartTime,
ProposalBlockHash: rs.ProposalBlock.Hash(),
LockedBlockHash: rs.LockedBlock.Hash(),
ValidBlockHash: rs.ValidBlock.Hash(),
Votes: votesJSON,
}
}
// RoundStateEvent returns the H/R/S of the RoundState as an event.
func (rs *RoundState) RoundStateEvent() types.EventDataRoundState {
// XXX: copy the RoundState


+ 7
- 0
rpc/core/consensus.go View File

@ -211,3 +211,10 @@ func DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) {
}
return &ctypes.ResultDumpConsensusState{roundState, peerStates}, nil
}
// UNSTABLE
func ConsensusState() (*ctypes.ResultConsensusState, error) {
// Get self round state.
bz, err := consensusState.GetRoundStateSimpleJSON()
return &ctypes.ResultConsensusState{bz}, err
}

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

@ -23,6 +23,7 @@ type Consensus interface {
GetState() sm.State
GetValidators() (int64, []*types.Validator)
GetRoundStateJSON() ([]byte, error)
GetRoundStateSimpleJSON() ([]byte, error)
}
type P2P interface {


+ 1
- 0
rpc/core/routes.go View File

@ -25,6 +25,7 @@ var Routes = map[string]*rpc.RPCFunc{
"tx_search": rpc.NewRPCFunc(TxSearch, "query,prove"),
"validators": rpc.NewRPCFunc(Validators, "height"),
"dump_consensus_state": rpc.NewRPCFunc(DumpConsensusState, ""),
"consensus_state": rpc.NewRPCFunc(ConsensusState, ""),
"unconfirmed_txs": rpc.NewRPCFunc(UnconfirmedTxs, ""),
"num_unconfirmed_txs": rpc.NewRPCFunc(NumUnconfirmedTxs, ""),


+ 5
- 0
rpc/core/types/responses.go View File

@ -140,6 +140,11 @@ type PeerStateInfo struct {
PeerState json.RawMessage `json:"peer_state"`
}
// UNSTABLE
type ResultConsensusState struct {
RoundState json.RawMessage `json:"round_state"`
}
// CheckTx result
type ResultBroadcastTx struct {
Code uint32 `json:"code"`


Loading…
Cancel
Save