Browse Source

state: txindex/kv: return an error if there's one (#4095)

when the user searches for a tx (hash=X)

This PR fixes error handling for performing a txindex search.

TxIndex.Get returns

    (txresult, nil) if the transaction is found.
    (nil, nil) if the transaction is not found.
    (nil, error) if error is occurred.

Therefore, if res is not nil, I think TxIndex.Search should return (txresult, nil).

Previously, however, this was not a problem because errors.Wrap returns nil if its first argument err is nil.
pull/4116/head
seungyeon-hwang 5 years ago
committed by Anton Kaliaev
parent
commit
274447e2b0
2 changed files with 7 additions and 2 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +6
    -2
      state/txindex/kv/kv.go

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -32,3 +32,4 @@ program](https://hackerone.com/tendermint).
- [tools] [\#4023](https://github.com/tendermint/tendermint/issues/4023) Refresh `tm-monitor` health when validator count is updated (@erikgrinaker) - [tools] [\#4023](https://github.com/tendermint/tendermint/issues/4023) Refresh `tm-monitor` health when validator count is updated (@erikgrinaker)
- [state] [\#4104](https://github.com/tendermint/tendermint/pull/4104) txindex/kv: Fsync data to disk immediately after receiving it (@guagualvcha) - [state] [\#4104](https://github.com/tendermint/tendermint/pull/4104) txindex/kv: Fsync data to disk immediately after receiving it (@guagualvcha)
- [state] [\#4095](https://github.com/tendermint/tendermint/pull/4095) txindex/kv: Return an error if there's one when the user searches for a tx (hash=X) (@hsyis)

+ 6
- 2
state/txindex/kv/kv.go View File

@ -179,10 +179,14 @@ func (txi *TxIndex) Search(q *query.Query) ([]*types.TxResult, error) {
return nil, errors.Wrap(err, "error during searching for a hash in the query") return nil, errors.Wrap(err, "error during searching for a hash in the query")
} else if ok { } else if ok {
res, err := txi.Get(hash) res, err := txi.Get(hash)
if res == nil {
switch {
case err != nil:
return []*types.TxResult{}, errors.Wrap(err, "error while retrieving the result")
case res == nil:
return []*types.TxResult{}, nil return []*types.TxResult{}, nil
default:
return []*types.TxResult{res}, nil
} }
return []*types.TxResult{res}, errors.Wrap(err, "error while retrieving the result")
} }
// conditions to skip because they're handled before "everything else" // conditions to skip because they're handled before "everything else"


Loading…
Cancel
Save