mirror of
https://github.com/tendermint/tendermint.git
synced 2026-04-28 03:16:58 +00:00
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.
This commit is contained in:
committed by
Anton Kaliaev
parent
0a014e37b7
commit
274447e2b0
@@ -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)
|
||||
- [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)
|
||||
|
||||
@@ -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")
|
||||
} else if ok {
|
||||
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
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user