mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
[rpc] DumpConsensusState: output state as json rather than string
Before: ``` { "jsonrpc": "2.0", "id": "", "result": { "round_state": "RoundState{\n H:10 R:0 S:RoundStepNewHeight\n StartTime: 2017-10-09 13:07:24.841134374 +0400 +04\n CommitTime: 2017-10-09 13:07:23.841134374 +0400 +04\n Validators: ValidatorSet{\n Proposer: Validator{EF243CC0E9B88D0161D24D733BDE9003518CEA27 {PubKeyEd25519{2E0B9301334FCDAB193D514022F81BA09BBEC028685C96602BE9DD0BD4F9E202}} VP:10 A:0}\n Validators:\n Validator{EF243CC0E9B88D0161D24D733BDE9003518CEA27 {PubKeyEd25519{2E0B9301334FCDAB193D514022F81BA09BBEC028685C96602BE9DD0BD4F9E202}} VP:10 A:0}\n }\n Proposal: \u003cnil\u003e\n ProposalBlock: nil-PartSet nil-Block\n LockedRound: 0\n LockedBlock: nil-PartSet nil-Block\n Votes: HeightVoteSet{H:10 R:0~0\n VoteSet{H:10 R:0 T:1 +2/3:\u003cnil\u003e BA{1:_} map[]}\n VoteSet{H:10 R:0 T:2 +2/3:\u003cnil\u003e BA{1:_} map[]}\n }\n LastCommit: VoteSet{H:9 R:0 T:2 +2/3:947F67A7B85439AF2CD5DFED376C51AC7BD67AEE:1:365E9983E466 BA{1:X} map[]}\n LastValidators: ValidatorSet{\n Proposer: Validator{EF243CC0E9B88D0161D24D733BDE9003518CEA27 {PubKeyEd25519{2E0B9301334FCDAB193D514022F81BA09BBEC028685C96602BE9DD0BD4F9E202}} VP:10 A:0}\n Validators:\n Validator{EF243CC0E9B88D0161D24D733BDE9003518CEA27 {PubKeyEd25519{2E0B9301334FCDAB193D514022F81BA09BBEC028685C96602BE9DD0BD4F9E202}} VP:10 A:0}\n }\n}", "peer_round_states": [] } } ``` After: ``` { "jsonrpc": "2.0", "id": "", "result": { "round_state": { "Height": 1691, "Round": 0, "Step": 1, "StartTime": "2017-10-09T14:08:09.129491764+04:00", "CommitTime": "2017-10-09T14:08:08.129491764+04:00", "Validators": { "validators": [ { "address": "EF243CC0E9B88D0161D24D733BDE9003518CEA27", "pub_key": { "type": "ed25519", "data": "2E0B9301334FCDAB193D514022F81BA09BBEC028685C96602BE9DD0BD4F9E202" }, "voting_power": 10, "accum": 0 } ], "proposer": { "address": "EF243CC0E9B88D0161D24D733BDE9003518CEA27", "pub_key": { "type": "ed25519", "data": "2E0B9301334FCDAB193D514022F81BA09BBEC028685C96602BE9DD0BD4F9E202" }, "voting_power": 10, "accum": 0 } }, "Proposal": null, "ProposalBlock": null, "ProposalBlockParts": null, "LockedRound": 0, "LockedBlock": null, "LockedBlockParts": null, "Votes": {}, "CommitRound": -1, "LastCommit": {}, "LastValidators": { "validators": [ { "address": "EF243CC0E9B88D0161D24D733BDE9003518CEA27", "pub_key": { "type": "ed25519", "data": "2E0B9301334FCDAB193D514022F81BA09BBEC028685C96602BE9DD0BD4F9E202" }, "voting_power": 10, "accum": 0 } ], "proposer": { "address": "EF243CC0E9B88D0161D24D733BDE9003518CEA27", "pub_key": { "type": "ed25519", "data": "2E0B9301334FCDAB193D514022F81BA09BBEC028685C96602BE9DD0BD4F9E202" }, "voting_power": 10, "accum": 0 } } }, "peer_round_states": { "75EC8F15D244A421202F9725CD4DE509EE50303670310CF7530EF25E2B7C524B": { "Height": 1691, "Round": 0, "Step": 1, "StartTime": "2017-10-09T14:08:08.563251997+04:00", "Proposal": false, "ProposalBlockPartsHeader": { "total": 0, "hash": "" }, "ProposalBlockParts": null, "ProposalPOLRound": -1, "ProposalPOL": null, "Prevotes": null, "Precommits": null, "LastCommitRound": 0, "LastCommit": null, "CatchupCommitRound": -1, "CatchupCommit": null } } } } ```
This commit is contained in:
parent
a3adac3787
commit
d6a87d3c43
@ -1,10 +1,13 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
wire "github.com/tendermint/go-wire"
|
||||
"encoding/json"
|
||||
|
||||
cm "github.com/tendermint/tendermint/consensus"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Get the validator set at the given block height.
|
||||
@ -82,14 +85,22 @@ func Validators(heightPtr *int) (*ctypes.ResultValidators, error) {
|
||||
// }
|
||||
// ```
|
||||
func DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) {
|
||||
roundState := consensusState.GetRoundState()
|
||||
peerRoundStates := []string{}
|
||||
for _, peer := range p2pSwitch.Peers().List() {
|
||||
roundStateBytes, err := json.Marshal(consensusState.GetRoundState())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to marshal round state")
|
||||
}
|
||||
|
||||
peerRoundStates := make(map[string]json.RawMessage)
|
||||
for i, peer := range p2pSwitch.Peers().List() {
|
||||
// TODO: clean this up?
|
||||
peerState := peer.Get(types.PeerStateKey).(*cm.PeerState)
|
||||
peerRoundState := peerState.GetRoundState()
|
||||
peerRoundStateStr := peer.Key() + ":" + string(wire.JSONBytes(peerRoundState))
|
||||
peerRoundStates = append(peerRoundStates, peerRoundStateStr)
|
||||
peerRoundStateBytes, err := json.Marshal(peerRoundState)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to marshal peer#%d round state", i)
|
||||
}
|
||||
peerRoundStates[peer.Key()] = json.RawMessage(peerRoundStateBytes)
|
||||
}
|
||||
return &ctypes.ResultDumpConsensusState{roundState.String(), peerRoundStates}, nil
|
||||
|
||||
return &ctypes.ResultDumpConsensusState{json.RawMessage(roundStateBytes), peerRoundStates}, nil
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
package core_types
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
abci "github.com/tendermint/abci/types"
|
||||
"github.com/tendermint/go-crypto"
|
||||
crypto "github.com/tendermint/go-crypto"
|
||||
"github.com/tendermint/go-wire/data"
|
||||
"github.com/tendermint/tendermint/p2p"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
@ -75,8 +76,8 @@ type ResultValidators struct {
|
||||
}
|
||||
|
||||
type ResultDumpConsensusState struct {
|
||||
RoundState string `json:"round_state"`
|
||||
PeerRoundStates []string `json:"peer_round_states"`
|
||||
RoundState json.RawMessage `json:"round_state"`
|
||||
PeerRoundStates map[string]json.RawMessage `json:"peer_round_states"`
|
||||
}
|
||||
|
||||
type ResultBroadcastTx struct {
|
||||
|
Loading…
x
Reference in New Issue
Block a user