Browse Source

rpc: historical validators

pull/618/head
Ethan Buchman 7 years ago
parent
commit
e2e8746044
9 changed files with 31 additions and 15 deletions
  1. +4
    -2
      rpc/client/httpclient.go
  2. +1
    -1
      rpc/client/interface.go
  3. +2
    -2
      rpc/client/localclient.go
  4. +2
    -2
      rpc/client/mock/client.go
  5. +1
    -1
      rpc/client/rpc_test.go
  6. +3
    -1
      rpc/core/blocks.go
  7. +13
    -4
      rpc/core/consensus.go
  8. +4
    -1
      rpc/core/pipe.go
  9. +1
    -1
      rpc/core/routes.go

+ 4
- 2
rpc/client/httpclient.go View File

@ -174,9 +174,11 @@ func (c *HTTP) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {
return result, nil
}
func (c *HTTP) Validators() (*ctypes.ResultValidators, error) {
func (c *HTTP) Validators(height *int) (*ctypes.ResultValidators, error) {
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 {
return nil, errors.Wrap(err, "Validators")
}


+ 1
- 1
rpc/client/interface.go View File

@ -44,7 +44,7 @@ type ABCIClient interface {
type SignClient interface {
Block(height int) (*ctypes.ResultBlock, 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)
}


+ 2
- 2
rpc/client/localclient.go View File

@ -101,8 +101,8 @@ func (c Local) Commit(height int) (*ctypes.ResultCommit, error) {
return core.Commit(height)
}
func (c Local) Validators() (*ctypes.ResultValidators, error) {
return core.Validators()
func (c Local) Validators(height *int) (*ctypes.ResultValidators, error) {
return core.Validators(height)
}
func (c Local) Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) {


+ 2
- 2
rpc/client/mock/client.go View File

@ -124,6 +124,6 @@ func (c Client) Commit(height int) (*ctypes.ResultCommit, error) {
return core.Commit(height)
}
func (c Client) Validators() (*ctypes.ResultValidators, error) {
return core.Validators()
func (c Client) Validators(height *int) (*ctypes.ResultValidators, error) {
return core.Validators(height)
}

+ 1
- 1
rpc/client/rpc_test.go View File

@ -87,7 +87,7 @@ func TestGenesisAndValidators(t *testing.T) {
gval := gen.Genesis.Validators[0]
// get the current validators
vals, err := c.Validators()
vals, err := c.Validators(nil)
require.Nil(t, err, "%d: %+v", i, err)
require.Equal(t, 1, len(vals.Validators))
val := vals.Validators[0]


+ 3
- 1
rpc/core/blocks.go View File

@ -85,6 +85,7 @@ func BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, err
}
// Get block at a given height.
// If no height is provided, it will fetch the latest block.
//
// ```shell
// curl 'localhost:46657/block?height=10'
@ -196,7 +197,8 @@ func Block(height int) (*ctypes.ResultBlock, error) {
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
// curl 'localhost:46657/commit?height=11'


+ 13
- 4
rpc/core/consensus.go View File

@ -7,7 +7,8 @@ import (
"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
// curl 'localhost:46657/validators'
@ -41,9 +42,17 @@ import (
// "jsonrpc": "2.0"
// }
// ```
func Validators() (*ctypes.ResultValidators, error) {
blockHeight, validators := consensusState.GetValidators()
return &ctypes.ResultValidators{blockHeight, validators}, nil
func Validators(height *int) (*ctypes.ResultValidators, error) {
if height == 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.


+ 4
- 1
rpc/core/pipe.go View File

@ -2,18 +2,21 @@ package core
import (
crypto "github.com/tendermint/go-crypto"
"github.com/tendermint/tmlibs/log"
"github.com/tendermint/tendermint/consensus"
p2p "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/proxy"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/state/txindex"
"github.com/tendermint/tendermint/types"
"github.com/tendermint/tmlibs/log"
)
//----------------------------------------------
// These interfaces are used by RPC and must be thread safe
type Consensus interface {
GetState() *sm.State
GetValidators() (int, []*types.Validator)
GetRoundState() *consensus.RoundState
}


+ 1
- 1
rpc/core/routes.go View File

@ -18,7 +18,7 @@ var Routes = map[string]*rpc.RPCFunc{
"block": rpc.NewRPCFunc(Block, "height"),
"commit": rpc.NewRPCFunc(Commit, "height"),
"tx": rpc.NewRPCFunc(Tx, "hash,prove"),
"validators": rpc.NewRPCFunc(Validators, ""),
"validators": rpc.NewRPCFunc(Validators, "height"),
"dump_consensus_state": rpc.NewRPCFunc(DumpConsensusState, ""),
"unconfirmed_txs": rpc.NewRPCFunc(UnconfirmedTxs, ""),
"num_unconfirmed_txs": rpc.NewRPCFunc(NumUnconfirmedTxs, ""),


Loading…
Cancel
Save