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

feat: add support for arabica-11 in download-genesis command #2978

Merged
merged 3 commits into from
Jan 3, 2024

Conversation

subhajit20
Copy link
Contributor

@subhajit20 subhajit20 commented Jan 3, 2024

Closes #2976

Testing

Updated the help and error messages to include arabica-11

$ ./build/celestia-appd download-genesis --help
Download genesis file from https://github.com/celestiaorg/networks.
The first argument should be a known chain-id. Ex. celestia, mocha-4, arabica-10, arabica-11

$ ./build/celestia-appd download-genesis arabaica-12
Error: unknown chain-id: arabaica-12. Must be: celestia, mocha-4, arabica-10, arabica-11

Downloading arabica-11 genesis works

$ ./build/celestia-appd download-genesis arabica-11
Downloading genesis file for arabica-11 to /Users/rootulp/.celestia-app/config/genesis.json
Downloaded genesis file for arabica-11 to /Users/rootulp/.celestia-app/config/genesis.json
SHA-256 hash verified for arabica-11

Copy link
Contributor

coderabbitai bot commented Jan 3, 2024

Walkthrough

Walkthrough

The modification involves updating the download-genesis command to support a new testnet identified as "arabica-11". This entails adding "arabica-11" to a list of hard-coded chain IDs within the application, allowing users to download the genesis file for this specific testnet.

Changes

File Path Change Summary
cmd/celestia-appd/cmd/download_genesis.go Added "arabica-11" to the chainIDToSha256 map with an empty string value.

Assessment against linked issues

Objective Addressed Explanation
Add support for arabica-11 in download-genesis command The change introduces support for "arabica-11" in the download-genesis command as requested in the linked issue.

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 with CodeRabbit Bot (@coderabbitai)

Note: Auto-reply has been disabled for this repository by the repository owner. The CodeRabbit bot will not respond to your comments unless it is explicitly tagged.

  • You can tag CodeRabbit on specific lines of code or entire files in the PR by tagging @coderabbitai in a comment. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • You can tag @coderabbitai in a PR comment and ask questions about the PR and the codebase. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid.
    • @coderabbitai read the files in the src/scheduler package and generate README in the markdown format.

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.

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.

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

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

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@celestia-bot celestia-bot requested a review from a team January 3, 2024 07:49
@@ -19,6 +19,7 @@ var chainIDToSha256 = map[string]string{
"celestia": "9727aac9bbfb021ce7fc695a92f901986421283a891b89e0af97bc9fad187793",
"mocha-4": "0846b99099271b240b638a94e17a6301423b5e4047f6558df543d6e91db7e575",
"arabica-10": "fad0a187669f7a2c11bb07f9dc27140d66d2448b7193e186312713856f28e3e1",
"arabica-11": ""
Copy link
Contributor

Choose a reason for hiding this comment

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

The addition of "arabica-11" with an empty string as its value to the chainIDToSha256 map is a placeholder for future updates. Ensure that the actual SHA256 hash is added before the "arabica-11" network goes live to avoid potential issues with genesis file verification.

@@ -19,6 +19,7 @@
"celestia": "9727aac9bbfb021ce7fc695a92f901986421283a891b89e0af97bc9fad187793",
"mocha-4": "0846b99099271b240b638a94e17a6301423b5e4047f6558df543d6e91db7e575",
"arabica-10": "fad0a187669f7a2c11bb07f9dc27140d66d2448b7193e186312713856f28e3e1",
"arabica-11": ""
}

func downloadGenesisCommand() *cobra.Command {
Copy link
Contributor

Choose a reason for hiding this comment

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

The error message in the RunE function of downloadGenesisCommand does not include "arabica-11" as a known chain-id. This should be updated to reflect the new addition to the chainIDToSha256 map.

- return fmt.Errorf("unknown chain-id: %s. Must be: celestia, mocha-4, or arabica-10", chainID)
+ return fmt.Errorf("unknown chain-id: %s. Must be: celestia, mocha-4, arabica-10, or arabica-11", chainID)

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.

Suggested change
func downloadGenesisCommand() *cobra.Command {
func downloadGenesisCommand() *cobra.Command {

Consider caching the result of getKeys(chainIDToSha256) outside of the isKnownChainID function to avoid recomputing the known chain IDs on every invocation, which could be a performance improvement if the command is run multiple times in a session.


The script output shows the downloadFile function, but it does not include any checks for the HTTP response status code. The function directly proceeds to create a file and copy the response body into it after making the HTTP GET request. There is no check to ensure that the response status code is 200 OK before writing the content to the file.

Based on the provided output, the review comment is correct. The downloadFile function should be updated to handle non-200 HTTP responses appropriately to prevent writing non-genesis file content if the URL is incorrect or the file is not found.

  • The downloadFile function lacks error handling for non-200 HTTP status codes.
  • The function writes the HTTP response body to a file without checking the status code, which could lead to incorrect file content being saved.
Analysis chain

Ensure that the downloadFile function has proper error handling for HTTP status codes other than 200 OK. This is important to prevent writing non-genesis file content if the URL is incorrect or the file is not found.


To verify the review comment, I need to see more of the downloadFile function, particularly the parts that handle the HTTP response status codes. I will generate a script to display more lines following the http.Get call.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that downloadFile handles non-200 HTTP responses appropriately.
rg --type go 'http.Get' --context 10 cmd/celestia-appd/cmd/download_genesis.go

Length of output: 438



Script:

#!/bin/bash
# Display more of the downloadFile function to inspect HTTP status code handling.
rg --type go 'func downloadFile' -A 30 cmd/celestia-appd/cmd/download_genesis.go

Length of output: 692


The computeSha256 function reads the entire file into memory, which could be optimized to handle large genesis files more efficiently by processing the file in chunks.

Copy link
Collaborator

Choose a reason for hiding this comment

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

[blocking] We should update the error messages to also include arabica-11

@subhajit20
Copy link
Contributor Author

subhajit20 commented Jan 3, 2024

Hey I have not found the arabica-11 from the network repo so I added the key to the map as of now and after you guys deployed the network I would add the sha256 hash to it.

@rootulp rootulp changed the title Added support for arabica-11 in download-genesis command feat: add support for arabica-11 in download-genesis command Jan 3, 2024
@rootulp rootulp marked this pull request as draft January 3, 2024 15:51
@rootulp
Copy link
Collaborator

rootulp commented Jan 3, 2024

Thanks for the contribution @subhajit20 . The genesis file now exists at https://github.com/celestiaorg/networks/blob/master/arabica-11/genesis.json

cmd/celestia-appd/cmd/download_genesis.go Outdated Show resolved Hide resolved
@@ -19,6 +19,7 @@
"celestia": "9727aac9bbfb021ce7fc695a92f901986421283a891b89e0af97bc9fad187793",
"mocha-4": "0846b99099271b240b638a94e17a6301423b5e4047f6558df543d6e91db7e575",
"arabica-10": "fad0a187669f7a2c11bb07f9dc27140d66d2448b7193e186312713856f28e3e1",
"arabica-11": ""
}

func downloadGenesisCommand() *cobra.Command {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[blocking] We should update the error messages to also include arabica-11

@rootulp rootulp marked this pull request as ready for review January 3, 2024 16:07
@@ -82,6 +84,10 @@ func isKnownChainID(chainID string) bool {
return contains(knownChainIDs, chainID)
}

func chainIDs() string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice addition 👍

@rootulp rootulp merged commit 5f224ae into celestiaorg:main Jan 3, 2024
29 of 30 checks passed
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.

Add support for arabica-11 in download-genesis command
3 participants