Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rpc): fix nil pointer error in /tx and /tx_search (backport #3355) #3357

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(rpc): fix nil pointer error in /tx and /tx_search (#3355)
when block is absent
Closes #3352

<!--

Please add a reference to the issue that this PR addresses and indicate
which
files are most critical to review. If it fully addresses a particular
issue,
please include "Closes #XXX" (where "XXX" is the issue number).

If this PR is non-trivial/large/complex, please ensure that you have
either
created an issue that the team's had a chance to respond to, or had some
discussion with the team prior to submitting substantial pull requests.
The team
can be reached via GitHub Discussions or the Cosmos Network Discord
server in
the #cometbft channel. GitHub Discussions is preferred over Discord as
it
allows us to keep track of conversations topically.
https://github.com/cometbft/cometbft/discussions

If the work in this PR is not aligned with the team's current
priorities, please
be advised that it may take some time before it is merged - especially
if it has
not yet been discussed with the team.

See the project board for the team's current priorities:
https://github.com/orgs/cometbft/projects/1

-->

---

#### 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

(cherry picked from commit 3d9bbb6)

# Conflicts:
#	.changelog/v0.38.3/bug-fixes/3352-nil-pointer-tx-search.md
#	rpc/core/tx.go
  • Loading branch information
melekes authored and mergify[bot] committed Jun 28, 2024
commit 175f4d179f6576ab5f308119213f435f6f1c4e9b
2 changes: 2 additions & 0 deletions .changelog/v0.38.3/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))
14 changes: 14 additions & 0 deletions rpc/core/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,15 @@

var proof types.TxProof
if prove {
<<<<<<< HEAD

Check failure on line 37 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / govulncheck

expected statement, found '<<'

Check failure on line 37 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / Build (amd64, linux)

syntax error: unexpected <<, expected }

Check failure on line 37 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / Build (arm, linux)

syntax error: unexpected <<, expected }

Check failure on line 37 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected <<, expected }

Check failure on line 37 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (04)

syntax error: unexpected <<, expected }

Check failure on line 37 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (04)

syntax error: unexpected <<, expected }

Check failure on line 37 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected <<, expected }

Check failure on line 37 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected <<, expected }

Check failure on line 37 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected <<, expected }

Check failure on line 37 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected <<, expected }

Check failure on line 37 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected <<, expected }
block := env.BlockStore.LoadBlock(r.Height)
proof = block.Data.Txs.Proof(int(r.Index))
=======

Check failure on line 40 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / Build (amd64, linux)

syntax error: unexpected ==, expected }

Check failure on line 40 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / Build (arm, linux)

syntax error: unexpected ==, expected }

Check failure on line 40 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected ==, expected }

Check failure on line 40 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (04)

syntax error: unexpected ==, expected }

Check failure on line 40 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (04)

syntax error: unexpected ==, expected }

Check failure on line 40 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected ==, expected }

Check failure on line 40 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected ==, expected }

Check failure on line 40 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected ==, expected }

Check failure on line 40 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected ==, expected }
block, _ := env.BlockStore.LoadBlock(r.Height)
if block != nil {
proof = block.Data.Txs.Proof(int(r.Index))
}
>>>>>>> 3d9bbb6f3 (fix(rpc): fix nil pointer error in `/tx` and `/tx_search` (#3355))

Check failure on line 45 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / govulncheck

expected statement, found '>>'

Check failure on line 45 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / govulncheck

illegal character U+0023 '#'

Check failure on line 45 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / Build (amd64, linux)

invalid character U+0023 '#'

Check failure on line 45 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / Build (arm, linux)

invalid character U+0023 '#'

Check failure on line 45 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (01)

invalid character U+0023 '#'

Check failure on line 45 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (04)

invalid character U+0023 '#'

Check failure on line 45 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (04)

invalid character U+0023 '#'

Check failure on line 45 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (03)

invalid character U+0023 '#'

Check failure on line 45 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (03)

invalid character U+0023 '#'

Check failure on line 45 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / golangci-lint

invalid character U+0023 '#'

Check failure on line 45 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (00)

invalid character U+0023 '#'
}

return &ctypes.ResultTx{
Expand All @@ -53,14 +60,14 @@
// More: https://docs.cometbft.com/v0.38.x/rpc/#/Info/tx_search
func (env *Environment) TxSearch(
ctx *rpctypes.Context,
query string,

Check failure on line 63 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / govulncheck

missing ',' in argument list

Check failure on line 63 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / govulncheck

expected operand, found ','
prove bool,
pagePtr, perPagePtr *int,
orderBy string,
) (*ctypes.ResultTxSearch, error) {
// if index is disabled, return error
if _, ok := env.TxIndexer.(*null.TxIndex); ok {

Check failure on line 69 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / govulncheck

missing ',' in argument list

Check failure on line 69 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / govulncheck

missing ',' in argument list

Check failure on line 69 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / govulncheck

missing ',' in argument list
return nil, errors.New("transaction indexing is disabled")

Check failure on line 70 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / govulncheck

expected operand, found 'return'

Check failure on line 70 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / govulncheck

missing ',' in composite literal
} else if len(query) > maxQueryLength {
return nil, errors.New("maximum query length exceeded")
}
Expand Down Expand Up @@ -113,8 +120,15 @@

var proof types.TxProof
if prove {
<<<<<<< HEAD

Check failure on line 123 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / Build (amd64, linux)

syntax error: unexpected <<, expected }

Check failure on line 123 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / Build (arm, linux)

syntax error: unexpected <<, expected }

Check failure on line 123 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected <<, expected }

Check failure on line 123 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (04)

syntax error: unexpected <<, expected }

Check failure on line 123 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected <<, expected }

Check failure on line 123 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected <<, expected }

Check failure on line 123 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected <<, expected }
block := env.BlockStore.LoadBlock(r.Height)
proof = block.Data.Txs.Proof(int(r.Index))
=======

Check failure on line 126 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / Build (amd64, linux)

syntax error: unexpected ==, expected }

Check failure on line 126 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / Build (arm, linux)

syntax error: unexpected ==, expected }

Check failure on line 126 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected ==, expected }

Check failure on line 126 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (04)

syntax error: unexpected ==, expected }

Check failure on line 126 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected ==, expected }

Check failure on line 126 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected ==, expected }

Check failure on line 126 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected ==, expected }
block, _ := env.BlockStore.LoadBlock(r.Height)
if block != nil {
proof = block.Data.Txs.Proof(int(r.Index))
}
>>>>>>> 3d9bbb6f3 (fix(rpc): fix nil pointer error in `/tx` and `/tx_search` (#3355))

Check failure on line 131 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / Build (amd64, linux)

syntax error: unexpected >>, expected }

Check failure on line 131 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / Build (amd64, linux)

invalid character U+0023 '#'

Check failure on line 131 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / Build (arm, linux)

syntax error: unexpected >>, expected }

Check failure on line 131 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / Build (arm, linux)

invalid character U+0023 '#'

Check failure on line 131 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected >>, expected }

Check failure on line 131 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (01)

invalid character U+0023 '#'

Check failure on line 131 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (04)

syntax error: unexpected >>, expected }

Check failure on line 131 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (04)

invalid character U+0023 '#'

Check failure on line 131 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected >>, expected }

Check failure on line 131 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (03)

invalid character U+0023 '#'

Check failure on line 131 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected >>, expected }

Check failure on line 131 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / golangci-lint

invalid character U+0023 '#') (typecheck)

Check failure on line 131 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected >>, expected }

Check failure on line 131 in rpc/core/tx.go

View workflow job for this annotation

GitHub Actions / tests (00)

invalid character U+0023 '#'
}

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