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(txsim): improved grpc server discovery, added default keypath value #4340

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

zatarx
Copy link

@zatarx zatarx commented Feb 18, 2025

Overview

Fixes #4223

  1. Added default key path lookup.
  2. Added --feegrant flag to the example of txsim.
  3. buildGRPCConn now filters out most of the invalid URLs, but if for example google.com:443 is provided, then it passes thru the function. IMO, healthcheck grpc endpoint must be introduced to solve this item (mb thru a separate issue/adr).
  4. @rootulp Could you elaborate on having an extra command for blobs? You mentioned filling up the blocks, but I didn't quite get that. Should it dynamically produce a PFB number, blob amount per PFB and blob sizes based on some network parameters and then spam the chain?
  5. grpc urls with 433 port(tls support) after introducing buildGrpcConn aren't failing anymore.

@zatarx zatarx requested a review from a team as a code owner February 18, 2025 00:05
@zatarx zatarx requested review from cmwaters and rach-id and removed request for a team February 18, 2025 00:05
@celestia-bot celestia-bot requested a review from rootulp February 18, 2025 00:05
Copy link
Contributor

coderabbitai bot commented Feb 18, 2025

📝 Walkthrough

Walkthrough

The pull request modifies the txsim tool’s error handling by defaulting to a node home keyring when one is not provided, rather than returning an error. The CLI help text is updated to include the new --feegrant flag. A new test function is added to verify the default keypath behavior with updated flags. Separately, the gRPC connection logic is enhanced by introducing a helper function that attempts a TLS handshake using a new TLS configuration and falls back to insecure credentials on failure.

Changes

File(s) Change Summary
test/cmd/txsim/cli.go, test/cmd/txsim/cli_test.go Updated CLI error handling to initialize the keyring with a default node home when not specified; revised help text to include the --feegrant flag; added test TestTxsimDefaultKeypath to validate default keypath setup with updated flags.
test/txsim/run.go Enhanced gRPC connection handling by adding defaultTLSConfig (with InsecureSkipVerify: true) and introducing the buildGrpcConn function that attempts a TLS handshake and falls back to insecure credentials upon failure.
Makefile Modified the test-race target to include TestTxsimDefaultKeypath in the list of tests to skip during race condition testing.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant KeyringManager

    User->>CLI: Execute txsim command
    alt Keyring provided
        CLI->>KeyringManager: Use provided keyring
    else Default keyring
        CLI->>KeyringManager: Initialize keyring with default node home
    end
    CLI->>CLI: Process command with --feegrant flag
    CLI-->User: Return execution result
Loading
sequenceDiagram
    participant Run
    participant buildGrpcConn
    participant gRPCServer

    Run->>buildGrpcConn: Call with endpoint and TLS config
    buildGrpcConn->>gRPCServer: Attempt TLS handshake
    alt Handshake succeeds
        gRPCServer-->>buildGrpcConn: Secure connection established
    else Handshake fails
        buildGrpcConn->>gRPCServer: Fallback to insecure credentials
    end
    buildGrpcConn-->>Run: Return gRPC connection
Loading

Possibly related PRs

  • fix: increases txsim grpc client max receive message size #3541: The changes in the main PR focus on error handling and command execution logic in the txsim tool, while the retrieved PR modifies gRPC connection settings and message size limits in the same run.go file, indicating a direct relationship in terms of code modifications.

Suggested labels

enhancement, testing, WS: Big Blonks 🔭

Suggested reviewers

  • rootulp
  • evan-forbes
  • ninabarbakadze
  • cmwaters
  • rach-id

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 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. (Beta)
  • @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.

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

🧹 Nitpick comments (4)
test/txsim/run.go (2)

30-30: Consider clarifying the intent of setting InsecureSkipVerify: true.

Having InsecureSkipVerify enabled avoids server certificate validation, which is a security concern in production. If this code is strictly for testing or local development, it would be good to add a clarifying comment indicating that this setting is not for production usage.

 var defaultTLSConfig = &tls.Config{
-	InsecureSkipVerify: true
+	InsecureSkipVerify: true, // For testing only; not recommended in production
 }

178-206: Recommend adding a health check or domain verification before falling back to insecure credentials.

The new buildGrpcConn function attempts a TLS handshake, logs a warning on failure, and then falls back to insecure.NewCredentials(). While this is convenient, consider:

  1. Performing a simple health check (e.g., verifying that the endpoint is actually gRPC capable) rather than defaulting to insecure on any TLS handshake issue.
  2. Logging clarity: including the endpoint domain or IP in the warning for easier troubleshooting.
  3. Possibly verifying domain identity if the environment is not strictly local or ephemeral.
test/cmd/txsim/cli_test.go (1)

56-78: Good coverage for the new default keypath usage.

This new test, TestTxsimDefaultKeypath, validates the fallback to default keyring behavior. Consider adding a negative test (e.g., verifying error handling if the default home directory is not writable or absent). That would ensure robust coverage of edge cases around key generation and usage.

test/cmd/txsim/cli.go (1)

88-88: Fallback to default node home is user friendly.

Changing to a default key path (app.DefaultNodeHome) when neither --key-path nor environment variables are provided is helpful for local or dev usage. Confirm that production deployments set an explicit key path to avoid accidental usage of this fallback.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7960d0f and e648cbc.

📒 Files selected for processing (3)
  • test/cmd/txsim/cli.go (2 hunks)
  • test/cmd/txsim/cli_test.go (1 hunks)
  • test/txsim/run.go (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (3)
test/txsim/run.go (2)

5-9: Imports look appropriate.

The added imports (crypto/tls and net) are necessary to establish manual TCP/TLS connections before handing control to gRPC. This approach is logical for checking handshake validity. No immediate issues here.


53-55: Error message is clear and concise.

The initialization of conn via buildGrpcConn is appropriately handled, and the returned error is well-wrapped. Good job ensuring the user sees the gRPC endpoint in the failure message.

test/cmd/txsim/cli.go (1)

65-67: Documentation updates look good.

The help text now correctly references TXSIM_KEYPATH and includes the --feegrant flag in the usage example, improving discoverability for new features.

@rootulp
Copy link
Collaborator

rootulp commented Feb 18, 2025

@rootulp Could you elaborate on having an extra command for blobs? You mentioned filling up the blocks, but I didn't quite get that. Should it dynamically produce a PFB number, blob amount per PFB and blob sizes based on some network parameters and then spam the chain?

Yes. I want a way to more easily fill blocks to their max capacity. Currently Celestia blocks can contain 8 MiB of blob data but each individual blob is limited to ~2 MiB. This means that a user needs to submit 4 x ~2 MiB (or slightly smaller) blobs in order to fill a block. Even when I tried doing that via txsim, I wasn't able to consistently fill blocks so there may be other issues needed to accomplish my goal. You can skip this and/or extract it to a new issue so that it doesn't block the work in this PR.

rootulp
rootulp previously approved these changes Feb 18, 2025
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

Overall LGTM but I haven't tested it manually.

Comment on lines 62 to 63
t.Log("start test")
t.Log(grpcAddr)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should these be deleted? They only seem helpful ad development time.

Suggested change
t.Log("start test")
t.Log(grpcAddr)

@rootulp rootulp changed the title fix(test/txsim): improved grpc server discovery, added default keypath value fix(txsim): improved grpc server discovery, added default keypath value Feb 19, 2025
rootulp
rootulp previously approved these changes Feb 19, 2025
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

Tested the default keypath lookup and --feegrant in the example command. Both work.

@@ -170,3 +173,34 @@ func (o *Options) WithPollTime(pollTime time.Duration) *Options {
o.pollTime = pollTime
return o
}

// GRPC applies the config if the handshake succeeds; otherwise, it falls back to an insecure connection.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// GRPC applies the config if the handshake succeeds; otherwise, it falls back to an insecure connection.
// buildGrpcConn applies the config if the handshake succeeds; otherwise, it falls back to an insecure connection.

@zatarx
Copy link
Author

zatarx commented Feb 19, 2025

I noticed that test account keyring backend is memory, which causes the test to fail (fails on master acct discovery). Addressing it right now

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

🧹 Nitpick comments (1)
test/cmd/txsim/cli_test.go (1)

57-87: Improve test robustness and cleanup.

Consider these improvements to make the test more robust:

  1. Use defer for account cleanup to ensure it runs even if the test fails
  2. Add assertions to verify the account was created successfully
  3. Consider reducing the timeout from 10 seconds if the test typically completes faster

Here's a suggested refactor:

 func TestTxsimDefaultKeypath(t *testing.T) {
     _, _, grpcAddr := setup(t)
-    ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+    ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
     defer cancel()

     cdc := encoding.MakeConfig(app.ModuleEncodingRegisters...).Codec

     kr, err := keyring.New(app.Name, keyring.BackendTest, app.DefaultNodeHome, nil, cdc)
     if err != nil {
         t.Fatal("Keyring failed with", err)
     }
-    kr.NewAccount(testfactory.TestAccName, testfactory.TestAccMnemo, "", "", hd.Secp256k1)
+    err = kr.NewAccount(testfactory.TestAccName, testfactory.TestAccMnemo, "", "", hd.Secp256k1)
     if err != nil {
         t.Fatal("NewAccount failed with", err)
     }
+    defer func() {
+        if err := kr.Delete(testfactory.TestAccName); err != nil {
+            t.Errorf("Failed to delete test account: %v", err)
+        }
+    }()
+
+    // Verify account was created
+    info, err := kr.Key(testfactory.TestAccName)
+    require.NoError(t, err)
+    require.Equal(t, testfactory.TestAccName, info.Name)

     cmd := command()
     cmd.SetArgs([]string{
         "--blob", "1",
         "--grpc-endpoint", grpcAddr,
         "--seed", "1223",
         "--poll-time", "1s",
         "--feegrant",
     })

     err = cmd.ExecuteContext(ctx)
-
-    // NewAccount is not idempotent, Delete handles teardown
-    kr.Delete(testfactory.TestAccName)
     require.NoError(t, err)
 }
🧰 Tools
🪛 golangci-lint (1.62.2)

68-68: Error return value of kr.NewAccount is not checked

(errcheck)


85-85: Error return value of kr.Delete is not checked

(errcheck)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 04ee1eb and 44d6994.

📒 Files selected for processing (2)
  • test/cmd/txsim/cli_test.go (2 hunks)
  • test/txsim/run.go (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/txsim/run.go
🧰 Additional context used
🪛 golangci-lint (1.62.2)
test/cmd/txsim/cli_test.go

68-68: Error return value of kr.NewAccount is not checked

(errcheck)


85-85: Error return value of kr.Delete is not checked

(errcheck)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (1)
test/cmd/txsim/cli_test.go (1)

15-15: LGTM!

The new import is required for using hd.Secp256k1 in the new test function and is correctly placed.

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

♻️ Duplicate comments (1)
test/cmd/txsim/cli_test.go (1)

85-85: ⚠️ Potential issue

Check error return from Delete.

The error return from kr.Delete should be checked to ensure proper cleanup.

Apply this diff to add error handling:

-    kr.Delete(testfactory.TestAccName)
+    if err := kr.Delete(testfactory.TestAccName); err != nil {
+        t.Errorf("Failed to delete test account: %v", err)
+    }
🧰 Tools
🪛 golangci-lint (1.62.2)

85-85: Error return value of kr.Delete is not checked

(errcheck)

🧹 Nitpick comments (1)
test/cmd/txsim/cli_test.go (1)

57-87: Add a test function comment.

Please add a comment explaining the purpose of this test function, particularly what aspects of the default keypath behavior and new flags it verifies.

Apply this diff to add documentation:

+// TestTxsimDefaultKeypath verifies that the txsim command works correctly with
+// the default keypath and new flags (--poll-time and --feegrant).
 func TestTxsimDefaultKeypath(t *testing.T) {
🧰 Tools
🪛 golangci-lint (1.62.2)

85-85: Error return value of kr.Delete is not checked

(errcheck)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 44d6994 and dc532e4.

📒 Files selected for processing (1)
  • test/cmd/txsim/cli_test.go (2 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
test/cmd/txsim/cli_test.go

85-85: Error return value of kr.Delete is not checked

(errcheck)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (1)
test/cmd/txsim/cli_test.go (1)

15-15: LGTM!

The new import is correctly placed and necessary for using the Secp256k1 key type in the new test.

rootulp
rootulp previously approved these changes Feb 19, 2025
@zatarx
Copy link
Author

zatarx commented Feb 19, 2025

Looking at the ci right now

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

🧹 Nitpick comments (1)
Makefile (1)

168-169: Updated Test Skip List for Race Mode

The updated -skip flag now excludes TestTxsimDefaultKeypath (along with several other tests) during race condition testing. This change aligns with the PR objective of addressing the new default keypath functionality while isolating tests that may cause race issues. For future maintainability, consider adding an in-code comment or extracting the skip test list into a Makefile variable to ease updates as more tests are added or modified.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5c49241 and a405847.

📒 Files selected for processing (1)
  • Makefile (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary

@zatarx
Copy link
Author

zatarx commented Feb 22, 2025

@rootulp could you trigger the ci please? If there's anything else that needs to be done within this PR, lmk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

txsim nice to haves
2 participants