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(store/commitment/iavl): honor tree.Remove error firstly #18651

Merged
merged 1 commit into from
Dec 8, 2023

Conversation

odeke-em
Copy link
Collaborator

@odeke-em odeke-em commented Dec 7, 2023

Previously the check was if !res and then it would return the error below but that has a consequence of ignoring/swallowing up the error returned by (*iavl.MutableTree).Remove. Even more is the fact that when !res, an error occurred and it could be anything else, thus checking against the error firstly ensures that we only return a synthesized error when we are certain the key wasn't in the tree.

Fixes #18650

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for tree removal operations, ensuring that accurate error messages are propagated to the user.
    • Snapshot failures are now correctly reported to the user, rather than creating an empty snapshot without notification.

@odeke-em odeke-em requested a review from a team as a code owner December 7, 2023 07:13
Copy link
Contributor

coderabbitai bot commented Dec 7, 2023

Walkthrough

Walkthrough

The changes involve improving error handling in the IavlTree.Remove method. The method now prioritizes checking for errors before considering the result of the removal operation. This ensures that errors are not missed and are properly propagated to the caller, aligning with the objectives to handle specific error scenarios more effectively.

Changes

File Path Change Summary
store/commitment/iavl/tree.go Updated IavlTree.Remove to check and return errors before evaluating the result of the removal operation.
store/CHANGELOG.md Documented the changes in error handling for iavl.MutableTree.Remove and the Snapshotter's error propagation.

Assessment against linked issues

Objective Addressed Explanation
Update IavlTree.Remove to check errors before result (res) (#18650)
Handle errors related to leaf nodes, nil keys, and missing values (#18650) The summary does not provide enough detail to confirm if all specific error scenarios are addressed.
Align error handling with identified scenarios without being overshadowed by result-based checks (#18650)
Notify the relevant contributor for awareness and potential input (#18650) This task is non-coding and thus not verifiable through the code changes.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

@odeke-em odeke-em force-pushed the store-respect-Remove.error-firstly branch 2 times, most recently from 4aedf30 to 4991053 Compare December 7, 2023 21:56
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f6df368 and 4991053.
Files selected for processing (2)
  • store/CHANGELOG.md (1 hunks)
  • store/commitment/iavl/tree.go (1 hunks)
Additional comments: 1
store/commitment/iavl/tree.go (1)
  • 29-39: The changes to the Remove method correctly prioritize error handling before checking the result, which aligns with the PR's objective to ensure that errors are not overlooked. This is a critical improvement for the reliability and correctness of the method.

store/CHANGELOG.md Outdated Show resolved Hide resolved
store/CHANGELOG.md Outdated Show resolved Hide resolved
store/CHANGELOG.md Outdated Show resolved Hide resolved
@odeke-em odeke-em force-pushed the store-respect-Remove.error-firstly branch from 4991053 to 2ee2063 Compare December 8, 2023 02:50
@odeke-em odeke-em force-pushed the store-respect-Remove.error-firstly branch from 2ee2063 to da54529 Compare December 8, 2023 11:43
@odeke-em odeke-em enabled auto-merge December 8, 2023 11:44
@@ -54,7 +54,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* [#16588](https://github.com/cosmos/cosmos-sdk/pull/16588) Propogate the Snapshotter's failure to the caller, (it will create a empty snapshot silently before).
* [#18651](https://github.com/cosmos/cosmos-sdk/pull/18651) Propagate iavl.MutableTree.Remove errors firstly to the caller instead of returning a synthesized error firstly.
Copy link
Member

Choose a reason for hiding this comment

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

Can you move this under unreleased?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done and thank you @julienrbrt!

@odeke-em odeke-em force-pushed the store-respect-Remove.error-firstly branch from da54529 to 48908fc Compare December 8, 2023 12:28
@odeke-em odeke-em requested a review from julienrbrt December 8, 2023 13:40
Previously the check was if !res and then it would return
the error below but that has a consequence of ignoring/swallowing
up the error returned by (*iavl.MutableTree).Remove. Even more is
the fact that when !res, an error occurred and it could be anything
else, thus checking against the error firstly ensures that we only
return a synthesized error when we are certain the key wasn't in the tree.

Fixes #18650
@odeke-em odeke-em force-pushed the store-respect-Remove.error-firstly branch from 48908fc to 9409254 Compare December 8, 2023 13:42
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 112f6cb and 9409254.
Files selected for processing (2)
  • store/CHANGELOG.md (2 hunks)
  • store/commitment/iavl/tree.go (1 hunks)
Additional comments: 3
store/CHANGELOG.md (2)
store/commitment/iavl/tree.go (1)
  • 29-39: The changes to the Remove method correctly prioritize error handling before checking the result of the removal operation. This ensures that errors are not ignored and are properly communicated to the caller, aligning with the PR objectives to fix the error handling bug.

@odeke-em odeke-em added this pull request to the merge queue Dec 8, 2023
Merged via the queue into main with commit 1e216af Dec 8, 2023
58 of 60 checks passed
@odeke-em odeke-em deleted the store-respect-Remove.error-firstly branch December 8, 2023 14:00
marcello33 added a commit to 0xPolygon/cosmos-sdk that referenced this pull request Dec 13, 2023
* feat: secp256k1 public key constant time (cosmos#18026)

Signed-off-by: bizk <[email protected]>

* chore: Fixed changelog duplicated items (cosmos#18628)

* adr: Un-Ordered Transaction Inclusion (cosmos#18553)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <[email protected]>

* docs: lint ADR-070 (cosmos#18634)

* fix(baseapp)!: postHandler should run regardless of result (cosmos#18627)

* docs: fix typos in adr-007-specialization-groups.md (cosmos#18635)

* chore: alphabetize labels (cosmos#18640)

* docs(x/circuit): add note on ante handler (cosmos#18637)

Co-authored-by: Aleksandr Bezobchuk <[email protected]>

* fix: telemetry metric label variable (cosmos#18643)

* chore: typos fix (cosmos#18642)

* refactor(store/v2): updates from integration (cosmos#18633)

* build(deps): Bump actions/setup-go from 4 to 5 (cosmos#18647)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* feat(store/v2): snapshot manager (cosmos#18458)

* chore(client/v2): fix typos in the README.md (cosmos#18657)

* fix(baseapp):  protocompat.go gogoproto.Merge does not work with custom types (cosmos#18654)

Co-authored-by: unknown unknown <unknown@unknown>

* chore: fix several minor typos (cosmos#18660)

* chore(tools/confix/cmd): fix typo in view.go (cosmos#18659)

* refactor(x/staking): check duplicate addresses in StakeAuthorization's params (cosmos#18655)

* feat(accounts): use gogoproto API instead of protov2.  (cosmos#18653)

Co-authored-by: unknown unknown <unknown@unknown>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fix(store/commitment/iavl): honor tree.Remove error firstly (cosmos#18651)

* build(deps): Bump actions/stale from 8 to 9 (cosmos#18656)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(docs): fix typos & wording in docs (cosmos#18667)

* chore: fix several typos.   (cosmos#18666)

* feat(telemetry): enable `statsd` and `dogstatsd` telemetry sinks (cosmos#18646)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <[email protected]>
Co-authored-by: marbar3778 <[email protected]>
Co-authored-by: Marko <[email protected]>

* feat(store/v2): add SetInitialVersion in SC (cosmos#18665)

* feat(client/keys): support display discreetly for `keys add` (cosmos#18663)

Co-authored-by: Julien Robert <[email protected]>

* ci: add misspell action (cosmos#18671)

* chore: typos fix by misspell-fixer (cosmos#18683)

Co-authored-by: github-merge-queue <[email protected]>
Co-authored-by: Julien Robert <[email protected]>

* chore: add v0.50.2 changelog to main (cosmos#18682)

* build(deps): Bump github.com/jhump/protoreflect from 1.15.3 to 1.15.4 in /tests (cosmos#18678)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* refactor(bank): remove .String() calls  (cosmos#18175)

Co-authored-by: Facundo <[email protected]>

* ci: use codespell instead of misspell-fixer (cosmos#18686)

Co-authored-by: Marko <[email protected]>

* feat(gov): add proposal types and spam votes (cosmos#18532)

* feat(accounts): use account number as state prefix for account state (cosmos#18664)

Co-authored-by: unknown unknown <unknown@unknown>

* chore: typos fixes by cosmos-sdk bot (cosmos#18689)

Co-authored-by: github-merge-queue <[email protected]>
Co-authored-by: Julien Robert <[email protected]>
Co-authored-by: marbar3778 <[email protected]>

* feat(client/keys): support display discreetly for keys mnemonic (cosmos#18688)

* refactor: remove panic usage in keeper methods (cosmos#18636)

* ci: rename pr name in misspell job (cosmos#18693)

Co-authored-by: Marko <[email protected]>

* build(deps): Bump github.com/pelletier/go-toml/v2 from 2.1.0 to 2.1.1 in /tools/confix (cosmos#18702)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>

* feat(client/keys): support display discreetly for keys export (cosmos#18684)

* feat(x/gov): better gov genesis validation (cosmos#18707)

---------

Signed-off-by: bizk <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Carlos Santiago Yanzon <[email protected]>
Co-authored-by: yihuang <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <[email protected]>
Co-authored-by: Facundo Medica <[email protected]>
Co-authored-by: Akaonetwo <[email protected]>
Co-authored-by: Marko <[email protected]>
Co-authored-by: Julien Robert <[email protected]>
Co-authored-by: dreamweaverxyz <[email protected]>
Co-authored-by: Pioua <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: cool-developer <[email protected]>
Co-authored-by: leonarddt05 <[email protected]>
Co-authored-by: testinginprod <[email protected]>
Co-authored-by: unknown unknown <unknown@unknown>
Co-authored-by: Sukey <[email protected]>
Co-authored-by: axie <[email protected]>
Co-authored-by: Luke Ma <[email protected]>
Co-authored-by: Emmanuel T Odeke <[email protected]>
Co-authored-by: 0xn4de <[email protected]>
Co-authored-by: hattizai <[email protected]>
Co-authored-by: Devon Bear <[email protected]>
Co-authored-by: Marko <[email protected]>
Co-authored-by: Halimao <[email protected]>
Co-authored-by: Cosmos SDK <[email protected]>
Co-authored-by: github-merge-queue <[email protected]>
Co-authored-by: Facundo <[email protected]>
Co-authored-by: Likhita Polavarapu <[email protected]>
@marcello33 marcello33 mentioned this pull request Jan 22, 2024
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants