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

docs: Update transaction building using v2 #23257

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

Conversation

ziscky
Copy link
Contributor

@ziscky ziscky commented Jan 8, 2025

Description

Closes: #11652


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • Documentation
    • Added a comprehensive guide for developers on building and broadcasting transactions using Cosmos SDK's clientv2
    • Included step-by-step instructions with code snippets for transaction creation and broadcasting
    • Provided detailed examples of transaction process stages, including setup, configuration, and execution

@ziscky ziscky requested a review from a team as a code owner January 8, 2025 13:12
Copy link
Contributor

coderabbitai bot commented Jan 8, 2025

📝 Walkthrough

Walkthrough

The pull request introduces a new section in the Cosmos SDK documentation focusing on building and broadcasting transactions using clientv2. The added content provides a comprehensive, step-by-step guide for developers, demonstrating how to create and send transactions through detailed code examples. The documentation update includes practical instructions for setting up imports, establishing gRPC connections, initializing keyrings, configuring transaction parameters, and broadcasting transactions.

Changes

File Change Summary
docs/learn/advanced/01-transactions.md Added new section "Complete Example Building and Broadcasting a Transaction using clientv2" with detailed transaction process walkthrough

Assessment against linked issues

Objective Addressed Explanation
Update documentation
Provide transaction building examples
Demonstrate clientv2 usage

Possibly related PRs

Suggested labels

C:server/v2, backport/v0.52.x

Suggested reviewers

  • julienrbrt
  • akhilkumarpilli
  • sontrinh16

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>, 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. (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: 1

🧹 Nitpick comments (3)
docs/learn/advanced/01-transactions.md (3)

243-399: Fix markdown formatting issues

The ordered list numbering should be consistent (all items should start with 1.), and the file should end with a single newline character.

-2. Create a gRPC connection
+1. Create a gRPC connection

-3. Setup codec and interface registry
+1. Setup codec and interface registry

-4. Initialize keyring
+1. Initialize keyring

-5. Setup transaction parameters
+1. Setup transaction parameters

-6. Build the transaction
+1. Build the transaction

-7. Broadcast the transaction
+1. Broadcast the transaction

-8. Helpers
+1. Helpers
+
🧰 Tools
🪛 Markdownlint (0.37.0)

243-243: Expected: 1; Actual: 2; Style: 1/1/1
Ordered list item prefix

(MD029, ol-prefix)


252-252: Expected: 1; Actual: 3; Style: 1/1/1
Ordered list item prefix

(MD029, ol-prefix)


266-266: Expected: 1; Actual: 4; Style: 1/1/1
Ordered list item prefix

(MD029, ol-prefix)


282-282: Expected: 1; Actual: 5; Style: 1/1/1
Ordered list item prefix

(MD029, ol-prefix)


331-331: Expected: 1; Actual: 6; Style: 1/1/1
Ordered list item prefix

(MD029, ol-prefix)


360-360: Expected: 1; Actual: 7; Style: 1/1/1
Ordered list item prefix

(MD029, ol-prefix)


377-377: Expected: 1; Actual: 8; Style: 1/1/1
Ordered list item prefix

(MD029, ol-prefix)


399-399: null
Files should end with a single newline character

(MD047, single-trailing-newline)


364-373: Improve error handling and configuration in broadcasting

  1. The CometBFT endpoint should be configurable.
  2. Error messages should provide more context about the failure.
+const (
+    defaultCometEndpoint = "http://127.0.0.1:26675"
+)

-c, err := comet.NewCometBFTBroadcaster("http://127.0.0.1:26675", comet.BroadcastSync, protoCodec)
+endpoint := os.Getenv("COMET_ENDPOINT")
+if endpoint == "" {
+    endpoint = defaultCometEndpoint
+}
+c, err := comet.NewCometBFTBroadcaster(endpoint, comet.BroadcastSync, protoCodec)
 if err != nil {
-    log.Fatal("error creating comet broadcaster", err)
+    log.Fatal("failed to create CometBFT broadcaster: ", err)
 }

 res, err := c.Broadcast(context.Background(), tx.Bytes())
 if err != nil {
-    log.Fatal("error broadcasting tx", err)
+    log.Fatal("failed to broadcast transaction: ", err)
 }

212-399: Add context and improve documentation

The example is comprehensive but could benefit from:

  1. A brief introduction explaining when to use clientv2.
  2. Comments explaining the purpose of each configuration option.
  3. Error handling best practices and recovery strategies.
  4. Examples of different transaction types beyond bank transfers.
🧰 Tools
🪛 Markdownlint (0.37.0)

243-243: Expected: 1; Actual: 2; Style: 1/1/1
Ordered list item prefix

(MD029, ol-prefix)


252-252: Expected: 1; Actual: 3; Style: 1/1/1
Ordered list item prefix

(MD029, ol-prefix)


266-266: Expected: 1; Actual: 4; Style: 1/1/1
Ordered list item prefix

(MD029, ol-prefix)


282-282: Expected: 1; Actual: 5; Style: 1/1/1
Ordered list item prefix

(MD029, ol-prefix)


331-331: Expected: 1; Actual: 6; Style: 1/1/1
Ordered list item prefix

(MD029, ol-prefix)


360-360: Expected: 1; Actual: 7; Style: 1/1/1
Ordered list item prefix

(MD029, ol-prefix)


377-377: Expected: 1; Actual: 8; Style: 1/1/1
Ordered list item prefix

(MD029, ol-prefix)


399-399: null
Files should end with a single newline character

(MD047, single-trailing-newline)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c5b3033 and e42927d.

📒 Files selected for processing (1)
  • docs/learn/advanced/01-transactions.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
docs/learn/advanced/01-transactions.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

🪛 Markdownlint (0.37.0)
docs/learn/advanced/01-transactions.md

243-243: Expected: 1; Actual: 2; Style: 1/1/1
Ordered list item prefix

(MD029, ol-prefix)


252-252: Expected: 1; Actual: 3; Style: 1/1/1
Ordered list item prefix

(MD029, ol-prefix)


266-266: Expected: 1; Actual: 4; Style: 1/1/1
Ordered list item prefix

(MD029, ol-prefix)


282-282: Expected: 1; Actual: 5; Style: 1/1/1
Ordered list item prefix

(MD029, ol-prefix)


331-331: Expected: 1; Actual: 6; Style: 1/1/1
Ordered list item prefix

(MD029, ol-prefix)


360-360: Expected: 1; Actual: 7; Style: 1/1/1
Ordered list item prefix

(MD029, ol-prefix)


377-377: Expected: 1; Actual: 8; Style: 1/1/1
Ordered list item prefix

(MD029, ol-prefix)


399-399: null
Files should end with a single newline character

(MD047, single-trailing-newline)

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: repo-analysis
  • GitHub Check: test-x-nft
  • GitHub Check: build (arm64)
  • GitHub Check: build (amd64)
  • GitHub Check: markdown-link-check
  • GitHub Check: dependency-review
  • GitHub Check: Summary

Comment on lines +246 to +250
clientConn, err := grpc.NewClient("127.0.0.1:9090", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatal(err)
}
```
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve security and configuration handling

  1. Using insecure credentials is not recommended for production environments.
  2. The gRPC endpoint should be configurable rather than hardcoded.
+// Define configuration variables
+const (
+    defaultGRPCEndpoint = "127.0.0.1:9090"
+)

-clientConn, err := grpc.NewClient("127.0.0.1:9090", grpc.WithTransportCredentials(insecure.NewCredentials()))
+// TODO: In production, use secure credentials
+endpoint := os.Getenv("GRPC_ENDPOINT")
+if endpoint == "" {
+    endpoint = defaultGRPCEndpoint
+}
+clientConn, err := grpc.NewClient(endpoint, grpc.WithTransportCredentials(insecure.NewCredentials()))
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
clientConn, err := grpc.NewClient("127.0.0.1:9090", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatal(err)
}
```
// Define configuration variables
const (
defaultGRPCEndpoint = "127.0.0.1:9090"
)
// TODO: In production, use secure credentials
endpoint := os.Getenv("GRPC_ENDPOINT")
if endpoint == "" {
endpoint = defaultGRPCEndpoint
}
clientConn, err := grpc.NewClient(endpoint, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatal(err)
}

@@ -207,3 +207,193 @@ An example can be seen [here](https://docs.cosmos.network/main/user/run-node/txs
#### CometBFT RPC

The three methods presented above are actually higher abstractions over the CometBFT RPC `/broadcast_tx_{async,sync,commit}` endpoints, documented [here](https://docs.cometbft.com/v1.0/explanation/core/rpc). This means that you can use the CometBFT RPC endpoints directly to broadcast the transaction, if you wish so.


#### Complete Example Building and Broadcasting a Transaction using clientv2
Copy link
Member

Choose a reason for hiding this comment

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

IMHO, this should be moved under https://docs.cosmos.network/v0.52/tutorials and not here.
This page is about the general concepts of transactions

Copy link
Member

Choose a reason for hiding this comment

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

Not sure what other think, but adding it here: https://github.com/cosmos/cosmos-sdk-docs/tree/main/docs/tutorials and maybe linking it in this page, makes more sense to me.

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.

4 participants