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

Don't panic during any store operations. #5294

Merged
merged 4 commits into from
Dec 4, 2023

Conversation

DimitrisJim
Copy link
Contributor

@DimitrisJim DimitrisJim commented Dec 1, 2023

Description

should be mostly ready, wanna go through it again before opening

closes: #5282

Commit Message / Changelog Entry

chore: don't panic during store operations that use wrong prefix.

see the guidelines for commit messages. (view raw markdown for examples)


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md).
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.


// closedIterator returns an iterator that is always closed, used when Iterator() or ReverseIterator() is called
// with an invalid prefix or start/end key.
func (ws migrateClientWrappedStore) closedIterator() storetypes.Iterator {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

could also return invalid one directly (start == end) if people think that would be better?

Copy link
Member

Choose a reason for hiding this comment

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

there's no danger in returning a closed iterator, right? it will just be false on iter.Valid() and iter.Next(), and return nilon calls toKey()andValue()`

Copy link
Contributor Author

@DimitrisJim DimitrisJim Dec 4, 2023

Choose a reason for hiding this comment

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

key/value/next should panic as calls, according to Iterator interface. Concretely, if they don't call Valid before trying to iterate, we can't help em is my view 🤷

func (ws migrateClientWrappedStore) Set(key, value []byte) {
prefix, key := splitPrefix(key)
if !bytes.Equal(prefix, subjectPrefix) {
panic(fmt.Errorf("writes only allowed on subject store; key must be prefixed with \"%s\"", subjectPrefix))
return // no-op
Copy link
Contributor Author

Choose a reason for hiding this comment

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

tho I must say one thing I don't like about this approach is that now errors are just as silent as can be

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes... Would there be some check we could do in 08-wasm's CheckSubstituteAndUpdateState after calling the contract to validate that the subject client state has been updated with the substitute's? Maybe checking the status of the subject client? If the call to the contract succeeded, then we would expect the subject client to be active again, so if the call to the contract succeeds, but the subject client is not active, then we could maybe maybe hint that the problem might be here?

Similarly, maybe there's also a check on the consensus state that we could do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do think the check for the status could be done in 02-client layer? For 07-tendermint this is done implicitly considering we check the subject status before calling CheckSubstituteAndUpdateState.

As for consensus state checks, is this an assumption we shouldn't be making? I.e solomachine precedent.

Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

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

Thanks, @DimitrisJim. I think this all looks good. Left just a couple of comments.

modules/light-clients/08-wasm/types/store.go Outdated Show resolved Hide resolved
func (ws migrateClientWrappedStore) Set(key, value []byte) {
prefix, key := splitPrefix(key)
if !bytes.Equal(prefix, subjectPrefix) {
panic(fmt.Errorf("writes only allowed on subject store; key must be prefixed with \"%s\"", subjectPrefix))
return // no-op
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes... Would there be some check we could do in 08-wasm's CheckSubstituteAndUpdateState after calling the contract to validate that the subject client state has been updated with the substitute's? Maybe checking the status of the subject client? If the call to the contract succeeded, then we would expect the subject client to be active again, so if the call to the contract succeeds, but the subject client is not active, then we could maybe maybe hint that the problem might be here?

Similarly, maybe there's also a check on the consensus state that we could do.

@DimitrisJim DimitrisJim force-pushed the jim/5282-remove-panics-in-wrapped-store branch from e1e6e67 to 783e4e2 Compare December 4, 2023 10:19
@DimitrisJim DimitrisJim force-pushed the jim/5282-remove-panics-in-wrapped-store branch from d99f4a0 to c981859 Compare December 4, 2023 11:28
Copy link
Member

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

Awesome, thank you @DimitrisJim!

LGTM pending the arg switch :)

🚀

modules/light-clients/08-wasm/types/export_test.go Outdated Show resolved Hide resolved
modules/light-clients/08-wasm/types/store_test.go Outdated Show resolved Hide resolved

// closedIterator returns an iterator that is always closed, used when Iterator() or ReverseIterator() is called
// with an invalid prefix or start/end key.
func (ws migrateClientWrappedStore) closedIterator() storetypes.Iterator {
Copy link
Member

Choose a reason for hiding this comment

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

there's no danger in returning a closed iterator, right? it will just be false on iter.Valid() and iter.Next(), and return nilon calls toKey()andValue()`

@DimitrisJim DimitrisJim enabled auto-merge (squash) December 4, 2023 15:13
Copy link
Member

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

ACK, thanks @DimitrisJim

@DimitrisJim DimitrisJim merged commit b7d6a30 into main Dec 4, 2023
70 of 72 checks passed
@DimitrisJim DimitrisJim deleted the jim/5282-remove-panics-in-wrapped-store branch December 4, 2023 15:18
mergify bot pushed a commit that referenced this pull request Dec 4, 2023
* Don't panic during any store operations.

* Panic when creating wrapped store if substores are nil.

* Address Damian's feedback.

(cherry picked from commit b7d6a30)

# Conflicts:
#	modules/light-clients/08-wasm/types/export_test.go
#	modules/light-clients/08-wasm/types/store_test.go
mergify bot pushed a commit that referenced this pull request Dec 4, 2023
* Don't panic during any store operations.

* Panic when creating wrapped store if substores are nil.

* Address Damian's feedback.

(cherry picked from commit b7d6a30)
DimitrisJim added a commit that referenced this pull request Dec 4, 2023
* Don't panic during any store operations.

* Panic when creating wrapped store if substores are nil.

* Address Damian's feedback.

(cherry picked from commit b7d6a30)

Co-authored-by: DimitrisJim <d.f.hilliard@gmail.com>
DimitrisJim added a commit that referenced this pull request Dec 4, 2023
* Don't panic during any store operations. (#5294)

* Don't panic during any store operations.

* Panic when creating wrapped store if substores are nil.

* Address Damian's feedback.

(cherry picked from commit b7d6a30)

# Conflicts:
#	modules/light-clients/08-wasm/types/export_test.go
#	modules/light-clients/08-wasm/types/store_test.go

* fix conflicts.

---------

Co-authored-by: DimitrisJim <d.f.hilliard@gmail.com>
damiannolan pushed a commit that referenced this pull request Dec 5, 2023
* Don't panic during any store operations.

* Panic when creating wrapped store if substores are nil.

* Address Damian's feedback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove panics in wrapped store
3 participants