mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-13 21:31:23 +00:00
rpc: historical validators
This commit is contained in:
@ -174,9 +174,11 @@ func (c *HTTP) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HTTP) Validators() (*ctypes.ResultValidators, error) {
|
func (c *HTTP) Validators(height *int) (*ctypes.ResultValidators, error) {
|
||||||
result := new(ctypes.ResultValidators)
|
result := new(ctypes.ResultValidators)
|
||||||
_, err := c.rpc.Call("validators", map[string]interface{}{}, result)
|
_, err := c.rpc.Call("validators", map[string]interface{}{
|
||||||
|
"height": height,
|
||||||
|
}, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "Validators")
|
return nil, errors.Wrap(err, "Validators")
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ type ABCIClient interface {
|
|||||||
type SignClient interface {
|
type SignClient interface {
|
||||||
Block(height int) (*ctypes.ResultBlock, error)
|
Block(height int) (*ctypes.ResultBlock, error)
|
||||||
Commit(height int) (*ctypes.ResultCommit, error)
|
Commit(height int) (*ctypes.ResultCommit, error)
|
||||||
Validators() (*ctypes.ResultValidators, error)
|
Validators(height *int) (*ctypes.ResultValidators, error)
|
||||||
Tx(hash []byte, prove bool) (*ctypes.ResultTx, error)
|
Tx(hash []byte, prove bool) (*ctypes.ResultTx, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,8 +101,8 @@ func (c Local) Commit(height int) (*ctypes.ResultCommit, error) {
|
|||||||
return core.Commit(height)
|
return core.Commit(height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Local) Validators() (*ctypes.ResultValidators, error) {
|
func (c Local) Validators(height *int) (*ctypes.ResultValidators, error) {
|
||||||
return core.Validators()
|
return core.Validators(height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Local) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
|
func (c Local) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
|
||||||
|
@ -124,6 +124,6 @@ func (c Client) Commit(height int) (*ctypes.ResultCommit, error) {
|
|||||||
return core.Commit(height)
|
return core.Commit(height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Validators() (*ctypes.ResultValidators, error) {
|
func (c Client) Validators(height *int) (*ctypes.ResultValidators, error) {
|
||||||
return core.Validators()
|
return core.Validators(height)
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ func TestGenesisAndValidators(t *testing.T) {
|
|||||||
gval := gen.Genesis.Validators[0]
|
gval := gen.Genesis.Validators[0]
|
||||||
|
|
||||||
// get the current validators
|
// get the current validators
|
||||||
vals, err := c.Validators()
|
vals, err := c.Validators(nil)
|
||||||
require.Nil(t, err, "%d: %+v", i, err)
|
require.Nil(t, err, "%d: %+v", i, err)
|
||||||
require.Equal(t, 1, len(vals.Validators))
|
require.Equal(t, 1, len(vals.Validators))
|
||||||
val := vals.Validators[0]
|
val := vals.Validators[0]
|
||||||
|
@ -85,6 +85,7 @@ func BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get block at a given height.
|
// Get block at a given height.
|
||||||
|
// If no height is provided, it will fetch the latest block.
|
||||||
//
|
//
|
||||||
// ```shell
|
// ```shell
|
||||||
// curl 'localhost:46657/block?height=10'
|
// curl 'localhost:46657/block?height=10'
|
||||||
@ -196,7 +197,8 @@ func Block(height int) (*ctypes.ResultBlock, error) {
|
|||||||
return &ctypes.ResultBlock{blockMeta, block}, nil
|
return &ctypes.ResultBlock{blockMeta, block}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get block commit at a given height.
|
// Get block commit at a given height. If the height is left out, it
|
||||||
|
// If no height is provided, it will fetch the commit for the latest block.
|
||||||
//
|
//
|
||||||
// ```shell
|
// ```shell
|
||||||
// curl 'localhost:46657/commit?height=11'
|
// curl 'localhost:46657/commit?height=11'
|
||||||
|
@ -7,7 +7,8 @@ import (
|
|||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get current validators set along with a block height.
|
// Get the validator set at a give block height.
|
||||||
|
// If no height is provided, it will fetch the current validator set.
|
||||||
//
|
//
|
||||||
// ```shell
|
// ```shell
|
||||||
// curl 'localhost:46657/validators'
|
// curl 'localhost:46657/validators'
|
||||||
@ -41,9 +42,17 @@ import (
|
|||||||
// "jsonrpc": "2.0"
|
// "jsonrpc": "2.0"
|
||||||
// }
|
// }
|
||||||
// ```
|
// ```
|
||||||
func Validators() (*ctypes.ResultValidators, error) {
|
func Validators(height *int) (*ctypes.ResultValidators, error) {
|
||||||
blockHeight, validators := consensusState.GetValidators()
|
if height == nil {
|
||||||
return &ctypes.ResultValidators{blockHeight, validators}, nil
|
blockHeight, validators := consensusState.GetValidators()
|
||||||
|
return &ctypes.ResultValidators{blockHeight, validators}, nil
|
||||||
|
}
|
||||||
|
state := consensusState.GetState()
|
||||||
|
validators, err := state.LoadValidators(*height)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &ctypes.ResultValidators{*height, validators.Validators}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dump consensus state.
|
// Dump consensus state.
|
||||||
|
@ -2,18 +2,21 @@ package core
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
crypto "github.com/tendermint/go-crypto"
|
crypto "github.com/tendermint/go-crypto"
|
||||||
|
"github.com/tendermint/tmlibs/log"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/consensus"
|
"github.com/tendermint/tendermint/consensus"
|
||||||
p2p "github.com/tendermint/tendermint/p2p"
|
p2p "github.com/tendermint/tendermint/p2p"
|
||||||
"github.com/tendermint/tendermint/proxy"
|
"github.com/tendermint/tendermint/proxy"
|
||||||
|
sm "github.com/tendermint/tendermint/state"
|
||||||
"github.com/tendermint/tendermint/state/txindex"
|
"github.com/tendermint/tendermint/state/txindex"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
"github.com/tendermint/tmlibs/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//----------------------------------------------
|
//----------------------------------------------
|
||||||
// These interfaces are used by RPC and must be thread safe
|
// These interfaces are used by RPC and must be thread safe
|
||||||
|
|
||||||
type Consensus interface {
|
type Consensus interface {
|
||||||
|
GetState() *sm.State
|
||||||
GetValidators() (int, []*types.Validator)
|
GetValidators() (int, []*types.Validator)
|
||||||
GetRoundState() *consensus.RoundState
|
GetRoundState() *consensus.RoundState
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ var Routes = map[string]*rpc.RPCFunc{
|
|||||||
"block": rpc.NewRPCFunc(Block, "height"),
|
"block": rpc.NewRPCFunc(Block, "height"),
|
||||||
"commit": rpc.NewRPCFunc(Commit, "height"),
|
"commit": rpc.NewRPCFunc(Commit, "height"),
|
||||||
"tx": rpc.NewRPCFunc(Tx, "hash,prove"),
|
"tx": rpc.NewRPCFunc(Tx, "hash,prove"),
|
||||||
"validators": rpc.NewRPCFunc(Validators, ""),
|
"validators": rpc.NewRPCFunc(Validators, "height"),
|
||||||
"dump_consensus_state": rpc.NewRPCFunc(DumpConsensusState, ""),
|
"dump_consensus_state": rpc.NewRPCFunc(DumpConsensusState, ""),
|
||||||
"unconfirmed_txs": rpc.NewRPCFunc(UnconfirmedTxs, ""),
|
"unconfirmed_txs": rpc.NewRPCFunc(UnconfirmedTxs, ""),
|
||||||
"num_unconfirmed_txs": rpc.NewRPCFunc(NumUnconfirmedTxs, ""),
|
"num_unconfirmed_txs": rpc.NewRPCFunc(NumUnconfirmedTxs, ""),
|
||||||
|
Reference in New Issue
Block a user