Skip to content

fix testnet issues #279

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

antstalepresh
Copy link

@antstalepresh antstalepresh commented Mar 11, 2025

What is the issue

Running testnet using the snapshot of bitsong mainnet fails with this issue.

Cometbft internally creates a new app state using the last commit from the snapshot when the testnet node runs first time using an existing snapshot.

Here is the relevant code for the operation.
https://github.com/cometbft/cometbft/blob/v0.38.16/consensus/state.go#L197

Reconstructing the last commit requires the last validator set to be matched to the last validator signatures but we have a problem here.

Currently, the last validator set is reset to the testnet node validator properly but last validator signatures still remain as the old ones from the snapshot.

What is the solution

Cosmos SDK already supports testnetify function to reset the last commit for testnet node validator but it is designed for only the chains that use legacy commit type of CometBFT.

Bitsong is using extended commit type, which is an enhanced version of legacy commit type introduced by recent versions of CometBFT and we need to make testnetify function compatible with extended commit type.

What are the changes

  • Add custom in-place-testnet command to bitsong
  • Move the command handler with relevant server functions from server package of SDK v0.50.11 to bitsong
  • Customize testnetify function to make it compatible with bitsong

Key changes for fixing the issue:
https://github.com/bitsongofficial/go-bitsong/pull/279/files#diff-97289af2ab66016f168df6fccac70626d125f170e5cf0841fcdc8fa624999608R701-R727

Summary by CodeRabbit

  • New Features

    • Enhanced blockchain node management now offers a streamlined command for testnet creation with improved startup/shutdown controls, built-in telemetry monitoring, and performance profiling. These improvements deliver a more intuitive and reliable experience when operating your blockchain network.
  • Refactor

    • Reorganized underlying integrations to better support testnet functionalities and cryptographic processing, ensuring smoother and more efficient operations.

Copy link

coderabbitai bot commented Mar 11, 2025

📝 Walkthrough

Walkthrough

This pull request updates cryptographic library imports and testnet command invocations while introducing new server management functionalities. The changes modify the Ed25519 import in the main application file and update the testnet command integration in the command module. Additionally, two new files in the server package provide a comprehensive framework for blockchain node operations including testnet creation, configuration handling, telemetry, gRPC and API server startup, database management, and graceful shutdown processes.

Changes

File(s) Change Summary
app/app.go Updated Ed25519 import from "cosmossdk.io/api/cosmos/crypto/ed25519" to "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519".
cmd/.../root.go Modified testnet command creation: replaced server.AddTestnetCreatorCommand with testnetserver.AddTestnetCreatorCommand and added corresponding import.
server/start.go, server/util.go Added new server management and utility files. Introduces initialization functions for testnet creation, CLI flags, telemetry, gRPC/API servers, database, and trace writer handling.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant CLI as CLI Command
    participant TC as Testnet Creator
    participant APP as Application Server
    participant GRPC as gRPC Server
    participant API as API Server
    participant TEL as Telemetry

    U->>CLI: Run start/testnet command
    CLI->>TC: Invoke InPlaceTestnetCreator (and AddTestnetCreatorCommand)
    TC->>APP: Initialize blockchain node & testnet
    APP->>TEL: Initialize telemetry metrics
    APP->>GRPC: Start gRPC service
    APP->>API: Start API service
    Note over APP: Manage asynchronous tasks & graceful shutdown
Loading

Suggested reviewers

  • angelorc

Poem

I'm a rabbit on a coding spree,
Hopping through changes as swift as can be.
New nodes and testnets bloom like spring,
Carrot code delights in everything.
With joyful hops, I cheer each commit,
Celebrating updates that perfectly fit!
🥕🐇

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • 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 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 generate docstrings to generate docstrings for this 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.

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.

Actionable comments posted: 0

🧹 Nitpick comments (6)
server/util.go (2)

13-17: Check data directory creation or error handling.

When calling dbm.NewDB("application", backendType, dataDir), ensure that the data directory always exists or that the function gracefully handles directory creation errors. Otherwise, there is a potential risk of failing silently if the directory is missing.


18-27: Consider adding error logging for empty traceWriterFile scenario.

If traceWriterFile is empty, the logic simply returns without creating a writer. It might be worth logging or explicitly acknowledging that no trace file is being generated to avoid confusion during debugging.

server/start.go (4)

111-207: Provide additional user guidance on the irreversible nature of testnet modification.

The InPlaceTestnetCreator command correctly warns about the permanent changes to on-disk state. Consider adding verbose logs or a recovery note for potential backups, ensuring operators are fully aware of potential data implications.


209-261: Validate flags for boundary conditions.

The addStartNodeFlags function sets a variety of node configuration flags. Ensure that invalid or risky values (e.g., negative intervals, extremely large memory constraints) are checked or documented. For example, consider bounding the maximum memory or file sizes to prevent excessive resource usage.


331-359: Close application resources after errors.

The startApp function defers a cleanupFn that closes the app and trace writer. This is a good pattern. Ensure any additional opened resources here (e.g., external APIs or file handles) are also accounted for in the cleanup for a robust shutdown.


817-870: Consider explicit logging around gRPC-only mode.

When gRPCOnly is true, the code sets svrCfg.GRPC.Enable = true; it might be helpful to log or mention that API server remains configurable, but CometBFT is disabled. This avoids user confusion regarding full node vs. gRPC-only usage.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d2bff90 and d259750.

📒 Files selected for processing (4)
  • app/app.go (1 hunks)
  • cmd/bitsongd/cmd/root.go (2 hunks)
  • server/start.go (1 hunks)
  • server/util.go (1 hunks)
🔇 Additional comments (9)
app/app.go (1)

50-50: Ensure Ed25519 usage is consistent throughout the codebase.

Changing the import path for the Ed25519 package is typically fine, but confirm that any references to the old package have been updated and that the new import aligns with the rest of the application’s cryptographic utilities.

server/util.go (2)

1-12: No major issues; package and imports look good.

The newly introduced package structure and imports appear consistent. No obvious concurrency or security concerns are evident at this stage.


29-34: Testnet creator command structure looks solid.

Attaching the testnet creation command to the root command is a clean approach. Verify that interactive help text is sufficient for users who may be unfamiliar with the in-place testnet creation process.

cmd/bitsongd/cmd/root.go (2)

37-37: Use of an alias import for improved clarity.

Renaming the import to testnetserver helps differentiate it from the standard server package. This should improve readability and reduce confusion.


270-270: Confirmed reorganization of testnet command logic.

Switching from server.AddTestnetCreatorCommand to testnetserver.AddTestnetCreatorCommand is consistent with the new file structure and import. Good job maintaining clarity for future collaboration.

server/start.go (4)

275-298: Graceful fallback path in standalone mode.

When skipping CometBFT (withCmt == false), the logic defaults to startStandAlone. This separation is clean. Just confirm that all resources needed (e.g., gRPC, API) are still functional or gracefully degrade if CometBFT is not started.


300-329: CPU profiling logic is well-contained.

Wrapping the main callback in wrapCPUProfile neatly isolates CPU profiling concerns. No issues with concurrency or resource leaks are apparent since the function defers StopCPUProfile() on completion.


545-793: Potential risk in rewriting chain data and forging commits.

The testnetify logic forcibly rewrites the chain ID, block store, and validator set, which is expected for a testnet migration. However, be aware that leftover references (e.g., uncleaned references to prior blocks or extended commits) could cause corruption if not thoroughly tested. Confirm that all relevant indexes are updated consistently.


872-911: Restart safety for in-process CometBFT node.

When stopping and restarting the node from within the same process, confirm that ephemeral states (e.g., ephemeral peer sessions, handshake data) are properly cleared. The cleanupFn calls tmNode.Stop(), which is standard, but watch for any reuse pitfalls if the user restarts in the same session.

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.

1 participant