mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 06:42:16 +00:00
rpc: /consensus_state for simplified output
This commit is contained in:
parent
658060150c
commit
a41f0d3891
@ -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()
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ type Consensus interface {
|
||||
GetState() sm.State
|
||||
GetValidators() (int64, []*types.Validator)
|
||||
GetRoundStateJSON() ([]byte, error)
|
||||
GetRoundStateSimpleJSON() ([]byte, error)
|
||||
}
|
||||
|
||||
type P2P interface {
|
||||
|
@ -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, ""),
|
||||
|
||||
|
@ -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…
x
Reference in New Issue
Block a user