lite2/rpc: verify block results and validators (#4703)

Closes: #4695

Verify /block_results and /validators responses from an HTTP client using the light client.

Added count and total to /validators response.

Refs #3113
This commit is contained in:
Anton Kaliaev
2020-04-20 16:38:34 +04:00
committed by GitHub
parent ec1c657d5a
commit 349556c6d9
6 changed files with 107 additions and 24 deletions

View File

@@ -10,9 +10,11 @@ import (
)
// Validators gets the validator set at the given block height.
// If no height is provided, it will fetch the current validator set.
// Note the validators are sorted by their address - this is the canonical
// order for the validators in the set as used in computing their Merkle root.
//
// If no height is provided, it will fetch the current validator set. Note the
// validators are sorted by their address - this is the canonical order for the
// validators in the set as used in computing their Merkle root.
//
// More: https://docs.tendermint.com/master/rpc/#/Info/validators
func Validators(ctx *rpctypes.Context, heightPtr *int64, page, perPage int) (*ctypes.ResultValidators, error) {
// The latest validator that we know is the
@@ -41,7 +43,9 @@ func Validators(ctx *rpctypes.Context, heightPtr *int64, page, perPage int) (*ct
return &ctypes.ResultValidators{
BlockHeight: height,
Validators: v}, nil
Validators: v,
Count: len(v),
Total: totalCount}, nil
}
// DumpConsensusState dumps consensus state.

View File

@@ -122,10 +122,14 @@ type Peer struct {
RemoteIP string `json:"remote_ip"`
}
// Validators for a height
// Validators for a height.
type ResultValidators struct {
BlockHeight int64 `json:"block_height"`
Validators []*types.Validator `json:"validators"`
// Count of actual validators in this result
Count int `json:"count"`
// Total number of validators
Total int `json:"total"`
}
// ConsensusParams for given height