rpc: Add /consensus_params endpoint (#2415)
* Add /consensus_params endpoint * Incorporated change https://github.com/tendermint/tendermint/pull/2415#discussion_r219078049 * Fixed an error in pervious commit
This commit is contained in:
parent
bd951171db
commit
84b518b8d3
|
@ -261,3 +261,49 @@ func ConsensusState() (*ctypes.ResultConsensusState, error) {
|
|||
bz, err := consensusState.GetRoundStateSimpleJSON()
|
||||
return &ctypes.ResultConsensusState{bz}, err
|
||||
}
|
||||
|
||||
// Get the consensus parameters at the given block height.
|
||||
// If no height is provided, it will fetch the current consensus params.
|
||||
//
|
||||
// ```shell
|
||||
// curl 'localhost:26657/consensus_params'
|
||||
// ```
|
||||
//
|
||||
// ```go
|
||||
// client := client.NewHTTP("tcp://0.0.0.0:26657", "/websocket")
|
||||
// state, err := client.ConsensusParams()
|
||||
// ```
|
||||
//
|
||||
// The above command returns JSON structured like this:
|
||||
//
|
||||
// ```json
|
||||
// {
|
||||
// "jsonrpc": "2.0",
|
||||
// "id": "",
|
||||
// "result": {
|
||||
// "block_height": "1",
|
||||
// "consensus_params": {
|
||||
// "block_size_params": {
|
||||
// "max_txs_bytes": "22020096",
|
||||
// "max_gas": "-1"
|
||||
// },
|
||||
// "evidence_params": {
|
||||
// "max_age": "100000"
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// ```
|
||||
func ConsensusParams(heightPtr *int64) (*ctypes.ResultConsensusParams, error) {
|
||||
height := consensusState.GetState().LastBlockHeight + 1
|
||||
height, err := getHeight(height, heightPtr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
consensusparams, err := sm.LoadConsensusParams(stateDB, height)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ctypes.ResultConsensusParams{BlockHeight: height, ConsensusParams: consensusparams}, nil
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ var Routes = map[string]*rpc.RPCFunc{
|
|||
"validators": rpc.NewRPCFunc(Validators, "height"),
|
||||
"dump_consensus_state": rpc.NewRPCFunc(DumpConsensusState, ""),
|
||||
"consensus_state": rpc.NewRPCFunc(ConsensusState, ""),
|
||||
"consensus_params": rpc.NewRPCFunc(ConsensusParams, "height"),
|
||||
"unconfirmed_txs": rpc.NewRPCFunc(UnconfirmedTxs, "limit"),
|
||||
"num_unconfirmed_txs": rpc.NewRPCFunc(NumUnconfirmedTxs, ""),
|
||||
|
||||
|
|
|
@ -118,6 +118,12 @@ type ResultValidators struct {
|
|||
Validators []*types.Validator `json:"validators"`
|
||||
}
|
||||
|
||||
// ConsensusParams for given height
|
||||
type ResultConsensusParams struct {
|
||||
BlockHeight int64 `json:"block_height"`
|
||||
ConsensusParams types.ConsensusParams `json:"consensus_params"`
|
||||
}
|
||||
|
||||
// Info about the consensus state.
|
||||
// UNSTABLE
|
||||
type ResultDumpConsensusState struct {
|
||||
|
|
Loading…
Reference in New Issue