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: Prevent newExporter crash if tree.ndb is nil #622

Merged
merged 8 commits into from
Nov 25, 2022

Conversation

chillyvee
Copy link
Contributor

@chillyvee chillyvee commented Nov 20, 2022

Found a case where dig chain did not have all stores configured with a nodedb (for whatever reason)

It is better to return an error so that cosmos-sdk can determine whether to skip the misconfigured store or panic.

Would also like to backport to fix v0.19.4 (but need assistance to target the right branch)

export.go Outdated
}
// CV Prevent crash on incrVersionReaders if tree.ndb == nil
if tree.ndb == nil {
fmt.Printf("iavl/export newExporter failed to create because tree.ndb is nil\n")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function should return error. Doing fmt.Printf doesn't make sense here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, lets break the api.

Copy link
Contributor Author

@chillyvee chillyvee Nov 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could just return (nil, err) with fmt.Errorf to start with. Then any more complicated error handling can be followed up in other commits/improvment?

Or is there some error standard you're trying to maintain?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea that makes sense, we would then handle this in the application

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning error now, updated api/test

@chillyvee
Copy link
Contributor Author

Last commit returns explicit error as recommended.
Tests also updated

Copy link
Collaborator

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, added one suggestion

CHANGELOG.md Show resolved Hide resolved
export.go Outdated
}
// CV Prevent crash on incrVersionReaders if tree.ndb == nil
if tree.ndb == nil {
return nil, ErrorTreeNodeDbNil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can have one error type: ErrNotIniitalizedTree. And then use wrapping to add more details, eg:

ErrNotIniitalizedTree.Wrap("ndb is nil")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapped

@chillyvee
Copy link
Contributor Author

change log updated, errors wrapped

@chillyvee
Copy link
Contributor Author

note change in errors package

export.go Outdated
func newExporter(tree *ImmutableTree) *Exporter {
func newExporter(tree *ImmutableTree) (*Exporter, error) {
if tree == nil {
return nil, errors.Wrap(ErrNotInitalizedTree, "tree is nil")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use fmt.Errorf to avoid introducing GitHub.com/pkg/errors as a dependency

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake. I thought the team was looking to call Wrap() specifically. Will change it again.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no worries, pkg/errors is deprecated with go 1.18 and beyond because of fmt.errorf and/or errors pkg.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Learn something new every day

@chillyvee
Copy link
Contributor Author

Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for submitting this!!! we can look at back porting this to avoid the issues being seen.

@tac0turtle tac0turtle changed the title Prevent newExporter crash if tree.ndb is nil fix: Prevent newExporter crash if tree.ndb is nil Nov 24, 2022
@tac0turtle
Copy link
Member

linting and tests are failing, could you fix and we will handle backport

@chillyvee
Copy link
Contributor Author

linting and tests are failing, could you fix and we will handle backport

Will give it a shot and let you know if help is required :)

@chillyvee
Copy link
Contributor Author

Issue was hiding in the benchmarks, fixed and running through tests.

@chillyvee
Copy link
Contributor Author

chillyvee commented Nov 24, 2022

looks like there's some fumpting to do (sorry not yet completely familiar with all the tests in this repo)

@chillyvee
Copy link
Contributor Author

went fumpting

@chillyvee
Copy link
Contributor Author

Also as a note, noticed:

dfde9a5 iavl: remove grpc server (#499) [GitHub]
0       129     cmd/iavlserver/README.md
0       207     cmd/iavlserver/main.go

But in Makefile it still tries to build iavlserver

ifeq ($(COLORS_ON),)
        go install ./cmd/iaviewer
        go install ./cmd/iavlserver <-- FAILS
else
        go install $(CMDFLAGS) ./cmd/iaviewer
        go install $(CMDFLAGS) ./cmd/iavlserver <-- FAILS
endif

Want it removed?

@chillyvee
Copy link
Contributor Author

Removed failing build of cmd/iavlserver. Let me know if you want it back.

@tac0turtle tac0turtle merged commit 2777659 into cosmos:master Nov 25, 2022
@tac0turtle
Copy link
Member

thanks for the pr @chillyvee

@tac0turtle
Copy link
Member

@Mergifyio backport release/v0.19.x

@tac0turtle
Copy link
Member

@Mergifyio backport release/v0.19.x

@mergify
Copy link
Contributor

mergify bot commented Nov 25, 2022

backport release/v0.19.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Nov 25, 2022
Co-authored-by: Marko <marbar3778@yahoo.com>
(cherry picked from commit 2777659)

# Conflicts:
#	export.go
tac0turtle added a commit that referenced this pull request Dec 8, 2022
Co-authored-by: Chill Validation <92176880+chillyvee@users.noreply.github.com>
Co-authored-by: Marko Baricevic <marbar3778@yahoo.com>
tac0turtle added a commit that referenced this pull request Dec 8, 2022
yihuang added a commit to yihuang/iavl that referenced this pull request Jan 11, 2023
yihuang added a commit to yihuang/iavl that referenced this pull request Jan 26, 2023
ankurdotb pushed a commit to cheqd/iavl that referenced this pull request Feb 28, 2023
… (cosmos#631)

Co-authored-by: Chill Validation <92176880+chillyvee@users.noreply.github.com>
Co-authored-by: Marko Baricevic <marbar3778@yahoo.com>
assafmo added a commit to scrtlabs/SecretNetwork that referenced this pull request May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants