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: check mainnet genesis hash #667

Merged
merged 2 commits into from
Sep 2, 2024
Merged

fix: check mainnet genesis hash #667

merged 2 commits into from
Sep 2, 2024

Conversation

zakir-code
Copy link
Contributor

@zakir-code zakir-code commented Sep 2, 2024

Summary by CodeRabbit

  • New Features

    • Updated methods for computing and validating genesis hashes for both mainnet and testnet configurations.
    • Enhanced clarity and performance in handling genesis document processing.
  • Bug Fixes

    • Improved error handling in the genesis block validation process.
  • Chores

    • Removed deprecated hash calculation utility to streamline functionality.

Copy link

coderabbitai bot commented Sep 2, 2024

Walkthrough

The changes primarily involve updates to the methods for computing the SHA256 hash of the genesis block across multiple files. The getGenesisDocAndSha256 function now computes the hash directly from the genesis file data without using an intermediate buffer. The StartCmd and checkMainnetAndBlock functions have been modified to utilize the new hash calculation method, with the latter accepting the hash as a parameter. Additionally, the genesis hashes for mainnet and testnet configurations have been updated.

Changes

Files Change Summary
cmd/doctor.go Updated getGenesisDocAndSha256 to compute SHA256 hash directly from genesisFileData using tmhash.Sum, removing the buffer step.
server/start.go Modified StartCmd and checkMainnetAndBlock to use hex.EncodeToString(tmhash.Sum(genesisBytes)) for hash calculation; adjusted checkMainnetAndBlock to accept genesisHash as a parameter.
types/version.go Updated MainnetGenesisHash and TestnetGenesisHash values; removed the Sha256Hex function.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Doctor
    participant Server
    participant Version

    User->>Doctor: Request genesis doc and hash
    Doctor->>Doctor: Compute hash using tmhash.Sum
    Doctor->>User: Return genesisDoc and genesisHash

    User->>Server: Start command with genesisDoc and genesisHash
    Server->>Server: Validate mainnet and block using provided genesisHash
    Server->>User: Command execution result
Loading

🐰 "In the meadow where bunnies play,
The hashes dance in a bright array.
With a hop and a skip, we cheer with glee,
For changes made, oh so sprightly!
New paths are drawn, and hashes align,
A joyful leap in code, how divine!" 🐇✨


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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 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.

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.
Early access features: disabled

We are currently testing the following features in early access:

  • Anthropic claude-3-5-sonnet for code reviews: Anthropic claims that the new Claude model has stronger code understanding and code generation capabilities than their previous models. Note: Our default code review model was also updated late last week. Please compare the quality of the reviews between the two models by toggling the early access feature.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues on the discussion post.

Copy link

@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.

Caution

Inline review comments failed to post

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 925d7bb and 378a4c0.

Files selected for processing (3)
  • cmd/doctor.go (3 hunks)
  • server/start.go (5 hunks)
  • types/version.go (3 hunks)
Additional comments not posted (8)
types/version.go (2)

13-13: LGTM!

The MainnetGenesisHash has been correctly updated to reflect the new mainnet genesis block hash.


26-26: LGTM!

The TestnetGenesisHash has been correctly updated to reflect the new testnet genesis block hash.

server/start.go (4)

53-53: LGTM!

Passing the computed genesis hash to checkMainnetAndBlock enhances clarity and reusability.


83-83: LGTM!

Accepting the genesis hash as a parameter enhances clarity and reusability.


100-100: LGTM!

Using the passed genesis hash is more efficient than recalculating it.


45-46: Verify the impact of the hash calculation change.

The genesis hash calculation method has been updated. This may affect how the genesis hash is validated against the expected value.

Run the following script to verify that the new hash calculation method produces the expected hash for mainnet and testnet configurations:

cmd/doctor.go (2)

534-535: LGTM!

The changes to the getGenesisDocAndSha256 function look good:

  • Directly computing the SHA256 hash from genesisFileData using tmhash.Sum simplifies the logic and improves performance by removing the intermediate buffer.
  • Encoding the hash to a hex string using hex.EncodeToString is the correct approach.
  • Returning genesisHash alongside genesisDoc improves the function's usability.

Overall, the changes enhance the code quality and maintainability. Nice work!


15-15: LGTM!

The import statement for the tmhash package is correct and required for using tmhash.Sum in the getGenesisDocAndSha256 function.

Comments failed to post (1)
server/start.go (1)

127-128: Reminder: Remove the TODO comment and the associated error message before the release.

The TODO comment suggests ongoing refinement of the error handling process.

Do you want me to open a GitHub issue to track this task?

@mergify mergify bot merged commit 20e5977 into main Sep 2, 2024
7 of 8 checks passed
@mergify mergify bot deleted the zakir/hash branch September 2, 2024 07:23
mergify bot pushed a commit that referenced this pull request Sep 2, 2024
zakir-code added a commit that referenced this pull request Sep 2, 2024
Co-authored-by: zakir <80246097+zakir-code@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants