diff --git a/rpc/core/consensus.go b/rpc/core/consensus.go index 193fbd285..a4a2c667c 100644 --- a/rpc/core/consensus.go +++ b/rpc/core/consensus.go @@ -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 +} diff --git a/rpc/core/routes.go b/rpc/core/routes.go index f26fadb62..639a2d08a 100644 --- a/rpc/core/routes.go +++ b/rpc/core/routes.go @@ -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, ""), diff --git a/rpc/core/types/responses.go b/rpc/core/types/responses.go index 77672910f..a6dcf2b93 100644 --- a/rpc/core/types/responses.go +++ b/rpc/core/types/responses.go @@ -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 {