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: state sync on main #3811

Merged
merged 1 commit into from
Aug 22, 2024
Merged

Conversation

rootulp
Copy link
Collaborator

@rootulp rootulp commented Aug 22, 2024

Forward port of #3808

@rootulp rootulp self-assigned this Aug 22, 2024
@rootulp rootulp marked this pull request as ready for review August 22, 2024 14:29
@rootulp rootulp requested a review from a team as a code owner August 22, 2024 14:29
Copy link
Contributor

coderabbitai bot commented Aug 22, 2024

Walkthrough

Walkthrough

The changes introduce enhancements to the App struct in the app package, adding a new method for handling snapshot offers based on application versions and improving logging during the mount process. Additionally, new shell scripts automate the setup of consensus nodes for the Arabica and Mocha blockchains, including configuration management and state synchronization.

Changes

Files Change Summary
app/app.go, app/app_test.go Added OfferSnapshot method to handle snapshot offers based on app version; improved logging in mountKeysAndInit. Introduced tests for OfferSnapshot.
scripts/arabica.sh, scripts/mocha.sh New scripts automate the setup of consensus nodes for the Arabica and Mocha blockchains, including configuration and state synchronization.

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fd36203 and cc9a3c7.

Files selected for processing (4)
  • app/app.go (2 hunks)
  • app/app_test.go (2 hunks)
  • scripts/arabica.sh (1 hunks)
  • scripts/mocha.sh (1 hunks)
Additional context used
Shellcheck
scripts/arabica.sh

[warning] 25-25: In POSIX sh, read -p is undefined.

(SC3045)

scripts/mocha.sh

[warning] 25-25: In POSIX sh, read -p is undefined.

(SC3045)

Additional comments not posted (8)
scripts/arabica.sh (2)

38-38: Check for command success.

Redirecting output to /dev/null hides errors. Consider checking the success of the command.

Ensure that the command succeeds by checking its exit status.

Verification successful

Command Success Check Implemented Correctly

The script correctly checks the success of the celestia-appd init command by verifying its exit status. The implementation aligns with the review comment's suggestion to ensure command success. The command failed with exit status 127, indicating it was not found, which is appropriately handled by the script.

  • The command success check is already implemented in the script.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check success of celestia-appd init command
celestia-appd init ${NODE_NAME} --chain-id ${CHAIN_ID} > /dev/null 2>&1
if [ $? -ne 0 ]; then
  echo "Initialization failed."
  exit 1
fi

Length of output: 115


41-41: Verify sed command success.

Ensure that the sed command successfully updates the configuration file.

Check the exit status of the sed command to ensure it succeeded.

scripts/mocha.sh (2)

38-38: Check for command success.

Redirecting output to /dev/null hides errors. Consider checking the success of the command.

Ensure that the command succeeds by checking its exit status.

Verification successful

Check for command success by verifying exit status.

The review comment is correct. The celestia-appd init command should have its exit status checked to ensure it executes successfully. The provided script correctly implements this check.

  • The command failed with an exit status of 127, indicating it might not be installed or accessible. Ensure the command is available in your environment.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check success of celestia-appd init command
celestia-appd init ${NODE_NAME} --chain-id ${CHAIN_ID} > /dev/null 2>&1
if [ $? -ne 0 ]; then
  echo "Initialization failed."
  exit 1
fi

Length of output: 115


41-41: Verify sed command success.

Ensure that the sed command successfully updates the configuration file.

Check the exit status of the sed command to ensure it succeeded.

Verification successful

Verification of sed Command Success Already Implemented

The script correctly checks the exit status of the sed command to ensure it succeeded. The error message indicates a missing file, which is a separate issue from the verification of the command's success. The review comment's suggestion is already implemented in the script.

  • The sed command's success is verified by checking its exit status.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check success of sed command
sed -i.bak -e "s/^seeds *=.*/seeds = \"$SEEDS\"/" $CELESTIA_APP_HOME/config/config.toml
if [ $? -ne 0 ]; then
  echo "Failed to update seeds in config.toml."
  exit 1
fi

Length of output: 240

app/app_test.go (2)

55-81: Test function TestOfferSnapshot is well-structured.

The test function effectively validates the OfferSnapshot method using mock objects and assertions. Ensure that the test covers all edge cases.


83-92: Helper function getSnapshotOption is correctly implemented.

The function sets up the snapshot environment and handles errors appropriately. Ensure that the snapshot options align with the application's requirements.

app/app.go (2)

573-573: LGTM: Improved logging in mountKeysAndInit.

The addition of a logging statement enhances traceability by logging the app version being mounted. This is a beneficial change for debugging and monitoring.


789-813: LGTM: New OfferSnapshot method added.

The method correctly determines the app version based on the snapshot height and mounts the appropriate keys before delegating to the baseapp's OfferSnapshot. This enhances the app's adaptability to different versions.

However, ensure that the upgradeHeightV2 is correctly set and used throughout the codebase.

Run the following script to verify the usage of upgradeHeightV2:

Verification successful

Verified: upgradeHeightV2 is used consistently and correctly.

The upgradeHeightV2 variable is employed as expected to coordinate height-based logic, ensuring the correct application version is used.

  • Code Locations:
    • Declaration and initialization in app/app.go.
    • Usage in conditional checks related to request headers and snapshot heights.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `upgradeHeightV2` in the codebase.

# Test: Search for `upgradeHeightV2` usage. Expect: Consistent and correct usage.
rg --type go 'upgradeHeightV2'

Length of output: 545


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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

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: 6

@@ -0,0 +1,59 @@
#!/bin/sh
Copy link
Contributor

Choose a reason for hiding this comment

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

Use #!/bin/bash for better compatibility.

The shebang #!/bin/sh may not support all features used in the script. Consider using #!/bin/bash for better compatibility.

-#!/bin/sh
+#!/bin/bash
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#!/bin/sh
#!/bin/bash


# Ask the user for confirmation before deleting the existing celestia-app home
# directory.
read -p "Are you sure you want to delete: $CELESTIA_APP_HOME? [y/n] " response
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace read -p with a POSIX-compliant alternative.

The read -p option is not defined in POSIX sh. Use printf and read instead for better compatibility.

-read -p "Are you sure you want to delete: $CELESTIA_APP_HOME? [y/n] " response
+printf "Are you sure you want to delete: %s? [y/n] " "$CELESTIA_APP_HOME"
+read response
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
read -p "Are you sure you want to delete: $CELESTIA_APP_HOME? [y/n] " response
printf "Are you sure you want to delete: %s? [y/n] " "$CELESTIA_APP_HOME"
read response
Tools
Shellcheck

[warning] 25-25: In POSIX sh, read -p is undefined.

(SC3045)

fi

echo "Deleting $CELESTIA_APP_HOME..."
rm -r "$CELESTIA_APP_HOME"
Copy link
Contributor

Choose a reason for hiding this comment

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

Add -f flag to rm for safety.

Using rm -r without -f can be dangerous if the directory doesn't exist or if there are permission issues. Add -f to force removal.

-rm -r "$CELESTIA_APP_HOME"
+rm -rf "$CELESTIA_APP_HOME"
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
rm -r "$CELESTIA_APP_HOME"
rm -rf "$CELESTIA_APP_HOME"


# Ask the user for confirmation before deleting the existing celestia-app home
# directory.
read -p "Are you sure you want to delete: $CELESTIA_APP_HOME? [y/n] " response
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace read -p with a POSIX-compliant alternative.

The read -p option is not defined in POSIX sh. Use printf and read instead for better compatibility.

-read -p "Are you sure you want to delete: $CELESTIA_APP_HOME? [y/n] " response
+printf "Are you sure you want to delete: %s? [y/n] " "$CELESTIA_APP_HOME"
+read response
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
read -p "Are you sure you want to delete: $CELESTIA_APP_HOME? [y/n] " response
printf "Are you sure you want to delete: %s? [y/n] " "$CELESTIA_APP_HOME"
read response
Tools
Shellcheck

[warning] 25-25: In POSIX sh, read -p is undefined.

(SC3045)

fi

echo "Deleting $CELESTIA_APP_HOME..."
rm -r "$CELESTIA_APP_HOME"
Copy link
Contributor

Choose a reason for hiding this comment

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

Add -f flag to rm for safety.

Using rm -r without -f can be dangerous if the directory doesn't exist or if there are permission issues. Add -f to force removal.

-rm -r "$CELESTIA_APP_HOME"
+rm -rf "$CELESTIA_APP_HOME"
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
rm -r "$CELESTIA_APP_HOME"
rm -rf "$CELESTIA_APP_HOME"

@@ -0,0 +1,59 @@
#!/bin/sh
Copy link
Contributor

Choose a reason for hiding this comment

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

Use #!/bin/bash for better compatibility.

The shebang #!/bin/sh may not support all features used in the script. Consider using #!/bin/bash for better compatibility.

-#!/bin/sh
+#!/bin/bash
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#!/bin/sh
#!/bin/bash

@rootulp rootulp merged commit ad250dd into celestiaorg:main Aug 22, 2024
33 checks passed
@rootulp rootulp deleted the rp/fix-state-sync-on-main branch August 22, 2024 16:55
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