mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-25 09:24:30 +00:00
Merge remote-tracking branch 'origin/develop' into jae/literefactor4
This commit is contained in:
@@ -23,7 +23,7 @@ var (
|
||||
)
|
||||
|
||||
func (a ABCIApp) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
|
||||
return &ctypes.ResultABCIInfo{a.App.Info(abci.RequestInfo{version.Version})}, nil
|
||||
return &ctypes.ResultABCIInfo{a.App.Info(abci.RequestInfo{Version: version.Version})}, nil
|
||||
}
|
||||
|
||||
func (a ABCIApp) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) {
|
||||
@@ -31,7 +31,7 @@ func (a ABCIApp) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQu
|
||||
}
|
||||
|
||||
func (a ABCIApp) ABCIQueryWithOptions(path string, data cmn.HexBytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
|
||||
q := a.App.Query(abci.RequestQuery{data, path, opts.Height, opts.Trusted})
|
||||
q := a.App.Query(abci.RequestQuery{Data: data, Path: path, Height: opts.Height, Prove: opts.Trusted})
|
||||
return &ctypes.ResultABCIQuery{q}, nil
|
||||
}
|
||||
|
||||
|
||||
+3
-6
@@ -1,18 +1,15 @@
|
||||
# Tendermint RPC
|
||||
|
||||
## Generate markdown for [Slate](https://github.com/tendermint/slate)
|
||||
|
||||
We are using [Slate](https://github.com/tendermint/slate) to power our RPC
|
||||
We are using [Slate](https://github.com/lord/slate) to power our RPC
|
||||
documentation. For generating markdown use:
|
||||
|
||||
```shell
|
||||
go get github.com/davecheney/godoc2md
|
||||
|
||||
godoc2md -template rpc/core/doc_template.txt github.com/tendermint/tendermint/rpc/core | grep -v -e "pipe.go" -e "routes.go" -e "dev.go" | sed 's$/src/target$https://github.com/tendermint/tendermint/tree/master/rpc/core$'
|
||||
# from root of this repo
|
||||
make rpc-docs
|
||||
```
|
||||
|
||||
For more information see the [CI script for building the Slate docs](/scripts/slate.sh)
|
||||
|
||||
## Pagination
|
||||
|
||||
Requests that return multiple items will be paginated to 30 items by default.
|
||||
|
||||
+8
-2
@@ -1,10 +1,12 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
"github.com/tendermint/tendermint/version"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
)
|
||||
|
||||
// Query the application for some information.
|
||||
@@ -48,6 +50,10 @@ import (
|
||||
// | height | int64 | 0 | false | Height (0 means latest) |
|
||||
// | trusted | bool | false | false | Does not include a proof of the data inclusion |
|
||||
func ABCIQuery(path string, data cmn.HexBytes, height int64, trusted bool) (*ctypes.ResultABCIQuery, error) {
|
||||
if height < 0 {
|
||||
return nil, fmt.Errorf("height must be non-negative")
|
||||
}
|
||||
|
||||
resQuery, err := proxyAppQuery.QuerySync(abci.RequestQuery{
|
||||
Path: path,
|
||||
Data: data,
|
||||
@@ -87,7 +93,7 @@ func ABCIQuery(path string, data cmn.HexBytes, height int64, trusted bool) (*cty
|
||||
// }
|
||||
// ```
|
||||
func ABCIInfo() (*ctypes.ResultABCIInfo, error) {
|
||||
resInfo, err := proxyAppQuery.InfoSync(abci.RequestInfo{version.Version})
|
||||
resInfo, err := proxyAppQuery.InfoSync(abci.RequestInfo{Version: version.Version})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+36
-15
@@ -64,25 +64,15 @@ import (
|
||||
//
|
||||
// <aside class="notice">Returns at most 20 items.</aside>
|
||||
func BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) {
|
||||
if minHeight == 0 {
|
||||
minHeight = 1
|
||||
}
|
||||
|
||||
if maxHeight == 0 {
|
||||
maxHeight = blockStore.Height()
|
||||
} else {
|
||||
maxHeight = cmn.MinInt64(blockStore.Height(), maxHeight)
|
||||
}
|
||||
|
||||
// maximum 20 block metas
|
||||
const limit int64 = 20
|
||||
minHeight = cmn.MaxInt64(minHeight, maxHeight-limit)
|
||||
|
||||
logger.Debug("BlockchainInfoHandler", "maxHeight", maxHeight, "minHeight", minHeight)
|
||||
|
||||
if minHeight > maxHeight {
|
||||
return nil, fmt.Errorf("min height %d can't be greater than max height %d", minHeight, maxHeight)
|
||||
var err error
|
||||
minHeight, maxHeight, err = filterMinMax(blockStore.Height(), minHeight, maxHeight, limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
logger.Debug("BlockchainInfoHandler", "maxHeight", maxHeight, "minHeight", minHeight)
|
||||
|
||||
blockMetas := []*types.BlockMeta{}
|
||||
for height := maxHeight; height >= minHeight; height-- {
|
||||
@@ -93,6 +83,37 @@ func BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, e
|
||||
return &ctypes.ResultBlockchainInfo{blockStore.Height(), blockMetas}, nil
|
||||
}
|
||||
|
||||
// error if either min or max are negative or min < max
|
||||
// if 0, use 1 for min, latest block height for max
|
||||
// enforce limit.
|
||||
// error if min > max
|
||||
func filterMinMax(height, min, max, limit int64) (int64, int64, error) {
|
||||
// filter negatives
|
||||
if min < 0 || max < 0 {
|
||||
return min, max, fmt.Errorf("heights must be non-negative")
|
||||
}
|
||||
|
||||
// adjust for default values
|
||||
if min == 0 {
|
||||
min = 1
|
||||
}
|
||||
if max == 0 {
|
||||
max = height
|
||||
}
|
||||
|
||||
// limit max to the height
|
||||
max = cmn.MinInt64(height, max)
|
||||
|
||||
// limit min to within `limit` of max
|
||||
// so the total number of blocks returned will be `limit`
|
||||
min = cmn.MaxInt64(min, max-limit+1)
|
||||
|
||||
if min > max {
|
||||
return min, max, fmt.Errorf("min height %d can't be greater than max height %d", min, max)
|
||||
}
|
||||
return min, max, nil
|
||||
}
|
||||
|
||||
// Get block at a given height.
|
||||
// If no height is provided, it will fetch the latest block.
|
||||
//
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestBlockchainInfo(t *testing.T) {
|
||||
|
||||
cases := []struct {
|
||||
min, max int64
|
||||
height int64
|
||||
limit int64
|
||||
resultLength int64
|
||||
wantErr bool
|
||||
}{
|
||||
|
||||
// min > max
|
||||
{0, 0, 0, 10, 0, true}, // min set to 1
|
||||
{0, 1, 0, 10, 0, true}, // max set to height (0)
|
||||
{0, 0, 1, 10, 1, false}, // max set to height (1)
|
||||
{2, 0, 1, 10, 0, true}, // max set to height (1)
|
||||
{2, 1, 5, 10, 0, true},
|
||||
|
||||
// negative
|
||||
{1, 10, 14, 10, 10, false}, // control
|
||||
{-1, 10, 14, 10, 0, true},
|
||||
{1, -10, 14, 10, 0, true},
|
||||
{-9223372036854775808, -9223372036854775788, 100, 20, 0, true},
|
||||
|
||||
// check limit and height
|
||||
{1, 1, 1, 10, 1, false},
|
||||
{1, 1, 5, 10, 1, false},
|
||||
{2, 2, 5, 10, 1, false},
|
||||
{1, 2, 5, 10, 2, false},
|
||||
{1, 5, 1, 10, 1, false},
|
||||
{1, 5, 10, 10, 5, false},
|
||||
{1, 15, 10, 10, 10, false},
|
||||
{1, 15, 15, 10, 10, false},
|
||||
{1, 15, 15, 20, 15, false},
|
||||
{1, 20, 15, 20, 15, false},
|
||||
{1, 20, 20, 20, 20, false},
|
||||
}
|
||||
|
||||
for i, c := range cases {
|
||||
caseString := fmt.Sprintf("test %d failed", i)
|
||||
min, max, err := filterMinMax(c.height, c.min, c.max, c.limit)
|
||||
if c.wantErr {
|
||||
require.Error(t, err, caseString)
|
||||
} else {
|
||||
require.NoError(t, err, caseString)
|
||||
require.Equal(t, 1+max-min, c.resultLength, caseString)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
title: RPC Reference
|
||||
|
||||
language_tabs: # must be one of https://git.io/vQNgJ
|
||||
- shell
|
||||
- go
|
||||
|
||||
toc_footers:
|
||||
- <a href='https://tendermint.com/'>Tendermint</a>
|
||||
- <a href='https://github.com/lord/slate'>Documentation Powered by Slate</a>
|
||||
|
||||
search: true
|
||||
---
|
||||
+1
-40
@@ -109,21 +109,11 @@ func Status() (*ctypes.ResultStatus, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
const consensusTimeout = time.Second
|
||||
|
||||
func validatorAtHeight(h int64) *types.Validator {
|
||||
lastBlockHeight, vals := getValidatorsWithTimeout(
|
||||
consensusState,
|
||||
consensusTimeout,
|
||||
)
|
||||
|
||||
if lastBlockHeight == -1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
privValAddress := pubKey.Address()
|
||||
|
||||
// If we're still at height h, search in the current validator set.
|
||||
lastBlockHeight, vals := consensusState.GetValidators()
|
||||
if lastBlockHeight == h {
|
||||
for _, val := range vals {
|
||||
if bytes.Equal(val.Address, privValAddress) {
|
||||
@@ -144,32 +134,3 @@ func validatorAtHeight(h int64) *types.Validator {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type validatorRetriever interface {
|
||||
GetValidators() (int64, []*types.Validator)
|
||||
}
|
||||
|
||||
// NOTE: Consensus might halt, but we still need to process RPC requests (at
|
||||
// least for endpoints whole output does not depend on consensus state).
|
||||
func getValidatorsWithTimeout(
|
||||
vr validatorRetriever,
|
||||
t time.Duration,
|
||||
) (int64, []*types.Validator) {
|
||||
resultCh := make(chan struct {
|
||||
lastBlockHeight int64
|
||||
vals []*types.Validator
|
||||
})
|
||||
go func() {
|
||||
h, v := vr.GetValidators()
|
||||
resultCh <- struct {
|
||||
lastBlockHeight int64
|
||||
vals []*types.Validator
|
||||
}{h, v}
|
||||
}()
|
||||
select {
|
||||
case res := <-resultCh:
|
||||
return res.lastBlockHeight, res.vals
|
||||
case <-time.After(t):
|
||||
return -1, []*types.Validator{}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
func TestGetValidatorsWithTimeout(t *testing.T) {
|
||||
height, vs := getValidatorsWithTimeout(
|
||||
testValidatorReceiver{},
|
||||
time.Millisecond,
|
||||
)
|
||||
|
||||
if height != -1 {
|
||||
t.Errorf("expected negative height")
|
||||
}
|
||||
|
||||
if len(vs) != 0 {
|
||||
t.Errorf("expected no validators")
|
||||
}
|
||||
}
|
||||
|
||||
type testValidatorReceiver struct{}
|
||||
|
||||
func (tr testValidatorReceiver) GetValidators() (int64, []*types.Validator) {
|
||||
vs := []*types.Validator{}
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
v, _ := types.RandValidator(true, 10)
|
||||
|
||||
vs = append(vs, v)
|
||||
}
|
||||
|
||||
time.Sleep(time.Millisecond)
|
||||
|
||||
return 10, vs
|
||||
}
|
||||
@@ -2,12 +2,10 @@ package core_types
|
||||
|
||||
import (
|
||||
"github.com/tendermint/go-amino"
|
||||
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
func RegisterAmino(cdc *amino.Codec) {
|
||||
types.RegisterEventDatas(cdc)
|
||||
types.RegisterEvidences(cdc)
|
||||
cryptoAmino.RegisterAmino(cdc)
|
||||
types.RegisterBlockAmino(cdc)
|
||||
}
|
||||
|
||||
+1
-1
@@ -123,7 +123,7 @@ func NewTendermint(app abci.Application) *nm.Node {
|
||||
node, err := nm.NewNode(config, pv, papp,
|
||||
nm.DefaultGenesisDocProviderFunc(config),
|
||||
nm.DefaultDBProvider,
|
||||
nm.DefaultMetricsProvider,
|
||||
nm.DefaultMetricsProvider(config.Instrumentation),
|
||||
logger)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
Reference in New Issue
Block a user