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: query signal after successful try upgrade #4045

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rootulp
Copy link
Collaborator

@rootulp rootulp commented Nov 21, 2024

Closes #4007

Testing

Using the updated single-node.sh script (see other PR), I can query the version tally even after a successful try upgrade.

$ ./scripts/upgrade-to-v3.sh

$ celestia-appd query signal tally 3
threshold_power: "4167"
total_voting_power: "5000"
voting_power: "5000"

@rootulp rootulp self-assigned this Nov 21, 2024
@rootulp rootulp requested a review from a team as a code owner November 21, 2024 21:50
@rootulp rootulp requested review from staheri14 and evan-forbes and removed request for a team November 21, 2024 21:50
@celestia-bot celestia-bot requested a review from a team November 21, 2024 21:50
Copy link
Contributor

coderabbitai bot commented Nov 21, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request enhance the integration and unit tests for the upgrade signaling mechanism in the signal package. Key modifications include additional assertions in the integration test to verify the functionality of the version tally post-upgrade and improved error handling for pending upgrades. The keeper.go file is updated to filter out upgrade-related signals during the tallying process, ensuring only relevant signals are considered. A new test function is added to validate the behavior of the upgrade logic, addressing a previously identified bug.

Changes

File Change Summary
x/signal/integration_test.go Added assertions in TestUpgradeIntegration to verify version tally post-upgrade and enhanced error handling for pending upgrades.
x/signal/keeper.go Added import for bytes, implemented checks in VersionTally and TallyVotingPower to skip upgrade-related signals.
x/signal/keeper_test.go Introduced TestTallyAfterTryUpgrade to verify behavior after a successful upgrade attempt and ensure no panic occurs.

Assessment against linked issues

Objective Addressed Explanation
Ensure querying empty signal tally does not cause panic (4007)

Possibly related PRs

Suggested labels

warn:api breaking, enhancement

Suggested reviewers

  • evan-forbes
  • cmwaters
  • staheri14

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 49daf5e and e66495b.

📒 Files selected for processing (1)
  • x/signal/keeper_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • x/signal/keeper_test.go

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
x/signal/keeper.go (1)

126-128: Consider extracting duplicate upgrade key check

The upgrade key check is duplicated in both VersionTally and TallyVotingPower. Consider extracting this into a helper method to improve maintainability and ensure consistent behavior.

Example implementation:

+// isUpgradeKey returns true if the given key is the upgrade key
+func (k Keeper) isUpgradeKey(key []byte) bool {
+    return bytes.Equal(key, types.UpgradeKey)
+}

 func (k Keeper) VersionTally(...) {
     ...
     for ; iterator.Valid(); iterator.Next() {
-        if bytes.Equal(iterator.Key(), types.UpgradeKey) {
+        if k.isUpgradeKey(iterator.Key()) {
             continue
         }
     ...
 }

 func (k Keeper) TallyVotingPower(...) {
     ...
     for ; iterator.Valid(); iterator.Next() {
-        if bytes.Equal(iterator.Key(), types.UpgradeKey) {
+        if k.isUpgradeKey(iterator.Key()) {
             continue
         }
     ...
 }

Also applies to: 165-167

x/signal/keeper_test.go (1)

433-468: Test successfully addresses the panic issue mentioned in #4007.

The test case effectively verifies that querying version tally after a successful upgrade doesn't panic. However, there are a few suggestions to make the test more robust:

  1. The test could verify VotingPower is 0 after the upgrade
  2. Consider adding assertions for version 3 tally as well, since that's the version being signaled
 res, err := upgradeKeeper.VersionTally(goCtx, &types.QueryVersionTallyRequest{
   Version: 2,
 })
 require.NoError(t, err)
+require.EqualValues(t, 0, res.VotingPower)
 require.EqualValues(t, 100, res.ThresholdPower)
 require.EqualValues(t, 120, res.TotalVotingPower)
+
+// Also verify version 3 tally
+res, err = upgradeKeeper.VersionTally(goCtx, &types.QueryVersionTallyRequest{
+  Version: 3,
+})
+require.NoError(t, err)
+require.EqualValues(t, 100, res.VotingPower)
+require.EqualValues(t, 100, res.ThresholdPower)
+require.EqualValues(t, 120, res.TotalVotingPower)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 66699e7 and 49daf5e.

📒 Files selected for processing (3)
  • x/signal/integration_test.go (1 hunks)
  • x/signal/keeper.go (3 hunks)
  • x/signal/keeper_test.go (1 hunks)
🔇 Additional comments (5)
x/signal/integration_test.go (1)

63-71: LGTM! Good test coverage for the empty tally query issue.

This test addition directly addresses issue #4007 by verifying that querying the version tally remains functional after a successful upgrade. The assertions ensure consistent behavior and prevent potential panics.

Let's verify there are no other places where version tally queries might need similar protection:

✅ Verification successful

Based on the search results, I can now generate the final response:

✓ The version tally query implementation is properly protected against empty data

The codebase search reveals that the VersionTally implementation in x/signal/keeper.go properly handles empty data cases by:

  • Initializing voting power with sdk.NewInt(0)
  • Using proper error handling throughout the query flow
  • Returning consistent response structure even when no votes are present

The test additions in the integration test complement the existing test coverage in keeper_test.go, which already includes test cases for:

  • Empty tally queries
  • Queries after reset
  • Queries with varying voting power states
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other version tally query calls that might need similar protection
ast-grep --pattern 'VersionTally($$$)'

Length of output: 40


Script:

#!/bin/bash
# Let's try a more comprehensive search for version tally related code
rg -i "versiontally" -A 3 -B 3

Length of output: 31038


Script:

#!/bin/bash
# Search for the query handler implementation
ast-grep --pattern 'func $_ VersionTally($$$) {
  $$$
}'

Length of output: 58


Script:

#!/bin/bash
# Look for the protobuf service definition
rg "VersionTally" --type proto

Length of output: 60

x/signal/keeper.go (3)

4-4: LGTM: Import addition is appropriate

The addition of the "bytes" package import is necessary for the new byte comparison operations.


165-167: LGTM: Consistent handling of upgrade key

The change maintains consistency with the VersionTally fix by properly skipping the upgrade key during power tallying.


126-128: Fix confirmed: Properly handles upgrade key during version tally

This change correctly addresses issue #4007 by skipping the upgrade key during iteration, preventing the index panic when querying an empty signal tally.

Let's verify that this is the only place where we might encounter similar issues with the upgrade key:

✅ Verification successful

Upgrade key handling is correctly implemented

The search results confirm that the upgrade key check is only needed in the signal module's version tally operations, where it's already properly implemented. Other store iterations in the codebase either:

  1. Use specific prefixes that exclude the upgrade key
  2. Have different purposes where upgrade key handling is not relevant
  3. Intentionally iterate over all keys (like in ResetTally)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other store iterations that might need similar upgrade key handling
ast-grep --pattern 'store.Iterator($$$)' 

Length of output: 42


Script:

#!/bin/bash
# Search for store iterations using ripgrep for a broader search
rg -i "iterator|store.iter" --type go -A 3 -B 3

Length of output: 5226

x/signal/keeper_test.go (1)

458-460: Well-documented test case with clear reference to the issue.

The comment effectively explains the bug being addressed and includes a link to the issue.

evan-forbes
evan-forbes previously approved these changes Nov 21, 2024
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

yo nice find

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.

querying empty signal tally causes index panic
2 participants