Browse Source

rpc: PR#4320 follow up (#4323)

* rpc: update urls to rpc website

* rpc: check blockMeta is not nil in Commit

Refs #4319
pull/4334/head
Anton Kaliaev 5 years ago
committed by GitHub
parent
commit
2d510d2f27
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 35 additions and 33 deletions
  1. +2
    -2
      rpc/core/abci.go
  2. +14
    -12
      rpc/core/blocks.go
  3. +3
    -3
      rpc/core/consensus.go
  4. +3
    -3
      rpc/core/events.go
  5. +1
    -1
      rpc/core/evidence.go
  6. +1
    -1
      rpc/core/health.go
  7. +5
    -5
      rpc/core/mempool.go
  8. +2
    -2
      rpc/core/net.go
  9. +2
    -1
      rpc/core/status.go
  10. +2
    -3
      rpc/core/tx.go

+ 2
- 2
rpc/core/abci.go View File

@ -9,7 +9,7 @@ import (
) )
// ABCIQuery queries the application for some information. // ABCIQuery queries the application for some information.
// More: https://tendermint.com/rpc/#/ABCI/abci_query
// More: https://docs.tendermint.com/master/rpc/#/ABCI/abci_query
func ABCIQuery( func ABCIQuery(
ctx *rpctypes.Context, ctx *rpctypes.Context,
path string, path string,
@ -31,7 +31,7 @@ func ABCIQuery(
} }
// ABCIInfo gets some info about the application. // ABCIInfo gets some info about the application.
// More: https://tendermint.com/rpc/#/ABCI/abci_info
// More: https://docs.tendermint.com/master/rpc/#/ABCI/abci_info
func ABCIInfo(ctx *rpctypes.Context) (*ctypes.ResultABCIInfo, error) { func ABCIInfo(ctx *rpctypes.Context) (*ctypes.ResultABCIInfo, error) {
resInfo, err := proxyAppQuery.InfoSync(proxy.RequestInfo) resInfo, err := proxyAppQuery.InfoSync(proxy.RequestInfo)
if err != nil { if err != nil {


+ 14
- 12
rpc/core/blocks.go View File

@ -12,9 +12,8 @@ import (
// BlockchainInfo gets block headers for minHeight <= height <= maxHeight. // BlockchainInfo gets block headers for minHeight <= height <= maxHeight.
// Block headers are returned in descending order (highest first). // Block headers are returned in descending order (highest first).
// More: https://tendermint.com/rpc/#/Info/blockchain
// More: https://docs.tendermint.com/master/rpc/#/Info/blockchain
func BlockchainInfo(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) { func BlockchainInfo(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) {
// maximum 20 block metas // maximum 20 block metas
const limit int64 = 20 const limit int64 = 20
var err error var err error
@ -68,7 +67,7 @@ func filterMinMax(height, min, max, limit int64) (int64, int64, error) {
// Block gets block at a given height. // Block gets block at a given height.
// If no height is provided, it will fetch the latest block. // If no height is provided, it will fetch the latest block.
// More: https://tendermint.com/rpc/#/Info/block
// More: https://docs.tendermint.com/master/rpc/#/Info/block
func Block(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlock, error) { func Block(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlock, error) {
storeHeight := blockStore.Height() storeHeight := blockStore.Height()
height, err := getHeight(storeHeight, heightPtr) height, err := getHeight(storeHeight, heightPtr)
@ -85,21 +84,20 @@ func Block(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlock, error)
} }
// BlockByHash gets block by hash. // BlockByHash gets block by hash.
// More: https://tendermint.com/rpc/#/Info/block_by_hash
// More: https://docs.tendermint.com/master/rpc/#/Info/block_by_hash
func BlockByHash(ctx *rpctypes.Context, hash []byte) (*ctypes.ResultBlock, error) { func BlockByHash(ctx *rpctypes.Context, hash []byte) (*ctypes.ResultBlock, error) {
block := blockStore.LoadBlockByHash(hash) block := blockStore.LoadBlockByHash(hash)
height := block.Height
blockMeta := blockStore.LoadBlockMeta(height)
if blockMeta == nil {
return &ctypes.ResultBlock{BlockID: types.BlockID{}, Block: block}, nil
if block == nil {
return &ctypes.ResultBlock{BlockID: types.BlockID{}, Block: nil}, nil
} }
// If block is not nil, then blockMeta can't be nil.
blockMeta := blockStore.LoadBlockMeta(block.Height)
return &ctypes.ResultBlock{BlockID: blockMeta.BlockID, Block: block}, nil return &ctypes.ResultBlock{BlockID: blockMeta.BlockID, Block: block}, nil
} }
// Commit gets block commit at a given height. // Commit gets block commit at a given height.
// If no height is provided, it will fetch the commit for the latest block. // If no height is provided, it will fetch the commit for the latest block.
// More: https://tendermint.com/rpc/#/Info/commit
// More: https://docs.tendermint.com/master/rpc/#/Info/commit
func Commit(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultCommit, error) { func Commit(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultCommit, error) {
storeHeight := blockStore.Height() storeHeight := blockStore.Height()
height, err := getHeight(storeHeight, heightPtr) height, err := getHeight(storeHeight, heightPtr)
@ -107,7 +105,11 @@ func Commit(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultCommit, erro
return nil, err return nil, err
} }
header := blockStore.LoadBlockMeta(height).Header
blockMeta := blockStore.LoadBlockMeta(height)
if blockMeta == nil {
return nil, nil
}
header := blockMeta.Header
// If the next block has not been committed yet, // If the next block has not been committed yet,
// use a non-canonical commit // use a non-canonical commit
@ -127,7 +129,7 @@ func Commit(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultCommit, erro
// Results are for the height of the block containing the txs. // Results are for the height of the block containing the txs.
// Thus response.results.deliver_tx[5] is the results of executing // Thus response.results.deliver_tx[5] is the results of executing
// getBlock(h).Txs[5] // getBlock(h).Txs[5]
// More: https://tendermint.com/rpc/#/Info/block_results
// More: https://docs.tendermint.com/master/rpc/#/Info/block_results
func BlockResults(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlockResults, error) { func BlockResults(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlockResults, error) {
storeHeight := blockStore.Height() storeHeight := blockStore.Height()
height, err := getHeight(storeHeight, heightPtr) height, err := getHeight(storeHeight, heightPtr)


+ 3
- 3
rpc/core/consensus.go View File

@ -13,7 +13,7 @@ import (
// If no height is provided, it will fetch the current validator set. // If no height is provided, it will fetch the current validator set.
// Note the validators are sorted by their address - this is the canonical // 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. // order for the validators in the set as used in computing their Merkle root.
// More: https://tendermint.com/rpc/#/Info/validators
// More: https://docs.tendermint.com/master/rpc/#/Info/validators
func Validators(ctx *rpctypes.Context, heightPtr *int64, page, perPage int) (*ctypes.ResultValidators, error) { func Validators(ctx *rpctypes.Context, heightPtr *int64, page, perPage int) (*ctypes.ResultValidators, error) {
// The latest validator that we know is the // The latest validator that we know is the
// NextValidator of the last block. // NextValidator of the last block.
@ -46,7 +46,7 @@ func Validators(ctx *rpctypes.Context, heightPtr *int64, page, perPage int) (*ct
// DumpConsensusState dumps consensus state. // DumpConsensusState dumps consensus state.
// UNSTABLE // UNSTABLE
// More: https://tendermint.com/rpc/#/Info/dump_consensus_state
// More: https://docs.tendermint.com/master/rpc/#/Info/dump_consensus_state
func DumpConsensusState(ctx *rpctypes.Context) (*ctypes.ResultDumpConsensusState, error) { func DumpConsensusState(ctx *rpctypes.Context) (*ctypes.ResultDumpConsensusState, error) {
// Get Peer consensus states. // Get Peer consensus states.
peers := p2pPeers.Peers().List() peers := p2pPeers.Peers().List()
@ -88,7 +88,7 @@ func ConsensusState(ctx *rpctypes.Context) (*ctypes.ResultConsensusState, error)
// ConsensusParams gets the consensus parameters at the given block height. // ConsensusParams gets the consensus parameters at the given block height.
// If no height is provided, it will fetch the current consensus params. // If no height is provided, it will fetch the current consensus params.
// More: https://tendermint.com/rpc/#/Info/consensus_params
// More: https://docs.tendermint.com/master/rpc/#/Info/consensus_params
func ConsensusParams(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultConsensusParams, error) { func ConsensusParams(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultConsensusParams, error) {
height := consensusState.GetState().LastBlockHeight + 1 height := consensusState.GetState().LastBlockHeight + 1
height, err := getHeight(height, heightPtr) height, err := getHeight(height, heightPtr)


+ 3
- 3
rpc/core/events.go View File

@ -13,7 +13,7 @@ import (
) )
// Subscribe for events via WebSocket. // Subscribe for events via WebSocket.
// More: https://tendermint.com/rpc/#/Websocket/subscribe
// More: https://docs.tendermint.com/master/rpc/#/Websocket/subscribe
func Subscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultSubscribe, error) { func Subscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultSubscribe, error) {
addr := ctx.RemoteAddr() addr := ctx.RemoteAddr()
@ -72,7 +72,7 @@ func Subscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultSubscribe, er
} }
// Unsubscribe from events via WebSocket. // Unsubscribe from events via WebSocket.
// More: https://tendermint.com/rpc/#/Websocket/unsubscribe
// More: https://docs.tendermint.com/master/rpc/#/Websocket/unsubscribe
func Unsubscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultUnsubscribe, error) { func Unsubscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultUnsubscribe, error) {
addr := ctx.RemoteAddr() addr := ctx.RemoteAddr()
logger.Info("Unsubscribe from query", "remote", addr, "query", query) logger.Info("Unsubscribe from query", "remote", addr, "query", query)
@ -88,7 +88,7 @@ func Unsubscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultUnsubscribe
} }
// UnsubscribeAll from all events via WebSocket. // UnsubscribeAll from all events via WebSocket.
// More: https://tendermint.com/rpc/#/Websocket/unsubscribe_all
// More: https://docs.tendermint.com/master/rpc/#/Websocket/unsubscribe_all
func UnsubscribeAll(ctx *rpctypes.Context) (*ctypes.ResultUnsubscribe, error) { func UnsubscribeAll(ctx *rpctypes.Context) (*ctypes.ResultUnsubscribe, error) {
addr := ctx.RemoteAddr() addr := ctx.RemoteAddr()
logger.Info("Unsubscribe from all", "remote", addr) logger.Info("Unsubscribe from all", "remote", addr)


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

@ -7,7 +7,7 @@ import (
) )
// BroadcastEvidence broadcasts evidence of the misbehavior. // BroadcastEvidence broadcasts evidence of the misbehavior.
// More: https://tendermint.com/rpc/#/Info/broadcast_evidence
// More: https://docs.tendermint.com/master/rpc/#/Info/broadcast_evidence
func BroadcastEvidence(ctx *rpctypes.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) { func BroadcastEvidence(ctx *rpctypes.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) {
err := evidencePool.AddEvidence(ev) err := evidencePool.AddEvidence(ev)
if err != nil { if err != nil {


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

@ -7,7 +7,7 @@ import (
// Health gets node health. Returns empty result (200 OK) on success, no // Health gets node health. Returns empty result (200 OK) on success, no
// response - in case of an error. // response - in case of an error.
// More: https://tendermint.com/rpc/#/Info/health
// More: https://docs.tendermint.com/master/rpc/#/Info/health
func Health(ctx *rpctypes.Context) (*ctypes.ResultHealth, error) { func Health(ctx *rpctypes.Context) (*ctypes.ResultHealth, error) {
return &ctypes.ResultHealth{}, nil return &ctypes.ResultHealth{}, nil
} }

+ 5
- 5
rpc/core/mempool.go View File

@ -19,7 +19,7 @@ import (
// BroadcastTxAsync returns right away, with no response. Does not wait for // BroadcastTxAsync returns right away, with no response. Does not wait for
// CheckTx nor DeliverTx results. // CheckTx nor DeliverTx results.
// More: https://tendermint.com/rpc/#/Tx/broadcast_tx_async
// More: https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_async
func BroadcastTxAsync(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) { func BroadcastTxAsync(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
err := mempool.CheckTx(tx, nil, mempl.TxInfo{}) err := mempool.CheckTx(tx, nil, mempl.TxInfo{})
@ -31,7 +31,7 @@ func BroadcastTxAsync(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadca
// BroadcastTxSync returns with the response from CheckTx. Does not wait for // BroadcastTxSync returns with the response from CheckTx. Does not wait for
// DeliverTx result. // DeliverTx result.
// More: https://tendermint.com/rpc/#/Tx/broadcast_tx_sync
// More: https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_sync
func BroadcastTxSync(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) { func BroadcastTxSync(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
resCh := make(chan *abci.Response, 1) resCh := make(chan *abci.Response, 1)
err := mempool.CheckTx(tx, func(res *abci.Response) { err := mempool.CheckTx(tx, func(res *abci.Response) {
@ -51,7 +51,7 @@ func BroadcastTxSync(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcas
} }
// BroadcastTxCommit returns with the responses from CheckTx and DeliverTx. // BroadcastTxCommit returns with the responses from CheckTx and DeliverTx.
// More: https://tendermint.com/rpc/#/Tx/broadcast_tx_commit
// More: https://docs.tendermint.com/master/rpc/#/Tx/broadcast_tx_commit
func BroadcastTxCommit(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) { func BroadcastTxCommit(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
subscriber := ctx.RemoteAddr() subscriber := ctx.RemoteAddr()
@ -129,7 +129,7 @@ func BroadcastTxCommit(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadc
// UnconfirmedTxs gets unconfirmed transactions (maximum ?limit entries) // UnconfirmedTxs gets unconfirmed transactions (maximum ?limit entries)
// including their number. // including their number.
// More: https://tendermint.com/rpc/#/Info/unconfirmed_txs
// More: https://docs.tendermint.com/master/rpc/#/Info/unconfirmed_txs
func UnconfirmedTxs(ctx *rpctypes.Context, limit int) (*ctypes.ResultUnconfirmedTxs, error) { func UnconfirmedTxs(ctx *rpctypes.Context, limit int) (*ctypes.ResultUnconfirmedTxs, error) {
// reuse per_page validator // reuse per_page validator
limit = validatePerPage(limit) limit = validatePerPage(limit)
@ -143,7 +143,7 @@ func UnconfirmedTxs(ctx *rpctypes.Context, limit int) (*ctypes.ResultUnconfirmed
} }
// NumUnconfirmedTxs gets number of unconfirmed transactions. // NumUnconfirmedTxs gets number of unconfirmed transactions.
// More: https://tendermint.com/rpc/#/Info/num_unconfirmed_txs
// More: https://docs.tendermint.com/master/rpc/#/Info/num_unconfirmed_txs
func NumUnconfirmedTxs(ctx *rpctypes.Context) (*ctypes.ResultUnconfirmedTxs, error) { func NumUnconfirmedTxs(ctx *rpctypes.Context) (*ctypes.ResultUnconfirmedTxs, error) {
return &ctypes.ResultUnconfirmedTxs{ return &ctypes.ResultUnconfirmedTxs{
Count: mempool.Size(), Count: mempool.Size(),


+ 2
- 2
rpc/core/net.go View File

@ -11,7 +11,7 @@ import (
) )
// NetInfo returns network info. // NetInfo returns network info.
// More: https://tendermint.com/rpc/#/Info/net_info
// More: https://docs.tendermint.com/master/rpc/#/Info/net_info
func NetInfo(ctx *rpctypes.Context) (*ctypes.ResultNetInfo, error) { func NetInfo(ctx *rpctypes.Context) (*ctypes.ResultNetInfo, error) {
peersList := p2pPeers.Peers().List() peersList := p2pPeers.Peers().List()
peers := make([]ctypes.Peer, 0, len(peersList)) peers := make([]ctypes.Peer, 0, len(peersList))
@ -69,7 +69,7 @@ func UnsafeDialPeers(ctx *rpctypes.Context, peers []string, persistent bool) (*c
} }
// Genesis returns genesis file. // Genesis returns genesis file.
// More: https://tendermint.com/rpc/#/Info/genesis
// More: https://docs.tendermint.com/master/rpc/#/Info/genesis
func Genesis(ctx *rpctypes.Context) (*ctypes.ResultGenesis, error) { func Genesis(ctx *rpctypes.Context) (*ctypes.ResultGenesis, error) {
return &ctypes.ResultGenesis{Genesis: genDoc}, nil return &ctypes.ResultGenesis{Genesis: genDoc}, nil
} }

+ 2
- 1
rpc/core/status.go View File

@ -14,7 +14,7 @@ import (
// Status returns Tendermint status including node info, pubkey, latest block // Status returns Tendermint status including node info, pubkey, latest block
// hash, app hash, block height and time. // hash, app hash, block height and time.
// More: https://tendermint.com/rpc/#/Info/status
// More: https://docs.tendermint.com/master/rpc/#/Info/status
func Status(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) { func Status(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) {
var latestHeight int64 var latestHeight int64
if consensusReactor.FastSync() { if consensusReactor.FastSync() {
@ -22,6 +22,7 @@ func Status(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) {
} else { } else {
latestHeight = consensusState.GetLastHeight() latestHeight = consensusState.GetLastHeight()
} }
var ( var (
latestBlockMeta *types.BlockMeta latestBlockMeta *types.BlockMeta
latestBlockHash tmbytes.HexBytes latestBlockHash tmbytes.HexBytes


+ 2
- 3
rpc/core/tx.go View File

@ -15,9 +15,8 @@ import (
// Tx allows you to query the transaction results. `nil` could mean the // Tx allows you to query the transaction results. `nil` could mean the
// transaction is in the mempool, invalidated, or was not sent in the first // transaction is in the mempool, invalidated, or was not sent in the first
// place. // place.
// More: https://tendermint.com/rpc/#/Info/tx
// More: https://docs.tendermint.com/master/rpc/#/Info/tx
func Tx(ctx *rpctypes.Context, hash []byte, prove bool) (*ctypes.ResultTx, error) { func Tx(ctx *rpctypes.Context, hash []byte, prove bool) (*ctypes.ResultTx, error) {
// if index is disabled, return error // if index is disabled, return error
if _, ok := txIndexer.(*null.TxIndex); ok { if _, ok := txIndexer.(*null.TxIndex); ok {
return nil, fmt.Errorf("transaction indexing is disabled") return nil, fmt.Errorf("transaction indexing is disabled")
@ -53,7 +52,7 @@ func Tx(ctx *rpctypes.Context, hash []byte, prove bool) (*ctypes.ResultTx, error
// TxSearch allows you to query for multiple transactions results. It returns a // TxSearch allows you to query for multiple transactions results. It returns a
// list of transactions (maximum ?per_page entries) and the total count. // list of transactions (maximum ?per_page entries) and the total count.
// More: https://tendermint.com/rpc/#/Info/tx_search
// More: https://docs.tendermint.com/master/rpc/#/Info/tx_search
func TxSearch(ctx *rpctypes.Context, query string, prove bool, page, perPage int) (*ctypes.ResultTxSearch, error) { func TxSearch(ctx *rpctypes.Context, query string, prove bool, page, perPage int) (*ctypes.ResultTxSearch, error) {
// if index is disabled, return error // if index is disabled, return error
if _, ok := txIndexer.(*null.TxIndex); ok { if _, ok := txIndexer.(*null.TxIndex); ok {


Loading…
Cancel
Save