Skip to content

Commit

Permalink
fix(rpc): fix nil pointer error in /tx and /tx_search (backport t…
Browse files Browse the repository at this point in the history
…endermint#3355) (tendermint#3357)

when block is absent
Closes tendermint#3352



---

#### PR checklist

- [ ] ~~Tests written/updated~~
- [x] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] ~~Updated relevant documentation (`docs/` or `spec/`) and code
comments~~
- [x] Title follows the [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec
<hr>This is an automatic backport of pull request tendermint#3355 done by
[Mergify](https://mergify.com).

---------

Co-authored-by: Anton Kaliaev <[email protected]>
  • Loading branch information
mergify[bot] and melekes authored Jun 28, 2024
1 parent 6959205 commit 4027622
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/bug-fixes/3352-nil-pointer-tx-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `[rpc]` Fix nil pointer error in `/tx` and `/tx_search` when block is
absent ([\#3352](https://github.com/cometbft/cometbft/issues/3352))
8 changes: 6 additions & 2 deletions rpc/core/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ func (env *Environment) Tx(_ *rpctypes.Context, hash []byte, prove bool) (*ctype
var proof types.TxProof
if prove {
block := env.BlockStore.LoadBlock(r.Height)
proof = block.Data.Txs.Proof(int(r.Index))
if block != nil {
proof = block.Data.Txs.Proof(int(r.Index))
}
}

return &ctypes.ResultTx{
Expand Down Expand Up @@ -114,7 +116,9 @@ func (env *Environment) TxSearch(
var proof types.TxProof
if prove {
block := env.BlockStore.LoadBlock(r.Height)
proof = block.Data.Txs.Proof(int(r.Index))
if block != nil {
proof = block.Data.Txs.Proof(int(r.Index))
}
}

apiResults = append(apiResults, &ctypes.ResultTx{
Expand Down

0 comments on commit 4027622

Please sign in to comment.