-
Notifications
You must be signed in to change notification settings - Fork 351
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"io" | ||
"net/http" | ||
"os" | ||
"strings" | ||
|
||
"github.com/cosmos/cosmos-sdk/server" | ||
"github.com/spf13/cobra" | ||
|
@@ -19,20 +20,21 @@ var chainIDToSha256 = map[string]string{ | |
"celestia": "9727aac9bbfb021ce7fc695a92f901986421283a891b89e0af97bc9fad187793", | ||
"mocha-4": "0846b99099271b240b638a94e17a6301423b5e4047f6558df543d6e91db7e575", | ||
"arabica-10": "fad0a187669f7a2c11bb07f9dc27140d66d2448b7193e186312713856f28e3e1", | ||
"arabica-11": "77605cee57ce545b1be22402110d4baacac837bdc7fc3f5c74020abf9a08810f", | ||
} | ||
|
||
func downloadGenesisCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "download-genesis [chain-id]", | ||
Short: "Download genesis file from https://github.com/celestiaorg/networks", | ||
Long: "Download genesis file from https://github.com/celestiaorg/networks.\n" + | ||
"The first argument should be a known chain-id. Ex. celestia, mocha-4, or arabica-10.\n" + | ||
fmt.Sprintf("The first argument should be a known chain-id. Ex. %s\n", chainIDs()) + | ||
"If no argument is provided, defaults to celestia.\n", | ||
Args: cobra.MaximumNArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
chainID := getChainIDOrDefault(args) | ||
if !isKnownChainID(chainID) { | ||
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: %s", chainID, chainIDs()) | ||
} | ||
outputFile := server.GetServerContextFromCmd(cmd).Config.GenesisFile() | ||
fmt.Printf("Downloading genesis file for %s to %s\n", chainID, outputFile) | ||
|
@@ -82,6 +84,10 @@ func isKnownChainID(chainID string) bool { | |
return contains(knownChainIDs, chainID) | ||
} | ||
|
||
func chainIDs() string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice addition 👍 |
||
return strings.Join(getKeys(chainIDToSha256), ", ") | ||
} | ||
|
||
// contains checks if a string is present in a slice. | ||
func contains(slice []string, s string) bool { | ||
for _, v := range slice { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 ofdownloadGenesisCommand
does not include "arabica-11" as a known chain-id. This should be updated to reflect the new addition to thechainIDToSha256
map.Committable suggestion
Consider caching the result of
getKeys(chainIDToSha256)
outside of theisKnownChainID
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.downloadFile
function lacks error handling for non-200 HTTP status codes.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 thehttp.Get
call.Scripts Executed
The following scripts were executed for the analysis:
Script:
Length of output: 438
Script:
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.There was a problem hiding this comment.
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