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(core): create docs for environment and core API #22156

Merged
merged 6 commits into from
Oct 7, 2024
Merged

Conversation

kocubinski
Copy link
Member

@kocubinski kocubinski commented Oct 7, 2024

Description

Ref: #21429

Removes most references to Amino in the encoding docs, and clarifies some points about Amino JSON.

Adds docs for core as used in Environment.


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
    • Updated encoding documentation to clarify the transition from go-amino to gogoprotobuf, emphasizing Protobuf as the primary encoding method.
    • Introduced a new document detailing the "Core" package of the Cosmos SDK, outlining its components and services, including Environment, BranchService, and Event Service.

@kocubinski kocubinski requested a review from a team as a code owner October 7, 2024 15:57
Copy link
Contributor

coderabbitai bot commented Oct 7, 2024

📝 Walkthrough

Walkthrough

The pull request includes substantial revisions to the documentation for the Cosmos SDK, specifically focusing on encoding mechanisms and the introduction of a new "Core" package. The updates clarify the transition from go-amino to gogoprotobuf for encoding, emphasizing Protobuf as the primary method for binary encoding. Additionally, a new document outlines the core components and services of the SDK, detailing their functionalities and promoting modularity. The changes aim to provide clearer guidance for developers on encoding practices and the architecture of the Cosmos SDK.

Changes

File Path Change Summary
docs/learn/advanced/05-encoding.md Significant revisions to clarify encoding mechanisms, emphasizing Protobuf over Amino, and restructuring sections on encoding protocols and store encoding.
docs/learn/advanced/17-core.md Introduction of the "Core" package, detailing its interfaces and components, including Environment, BranchService, Event Service, Gas Service, Header Service, TransactionService, and KVStore Service.

Possibly related PRs

Suggested reviewers

  • tac0turtle
  • akhilkumarpilli

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

be backed by a merkle-tree store, but developers can provide their own implementations if
needed. In the case of the `KVStoreService` implementation provided in `Environment`, module
developers should understand that calling `OpenKVStore` will return a store already scoped to
the module's prefix. The wiring for this scoping is specified in `runtime`.
Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't find any docs for runtime to link out to, do we want some?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we need an explanation of what is runtime in concepts too 👍🏾
I think the order should be, baseapp, transaction, core, runtime and then the rest, but we can do the ordering later.

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

lgtm! one nit

that needs to make changes to the store, but may need to be rolled back if an error occurs.
Below is a contrived example based on the `x/epoch` module's BeginBlocker logic.

```go reference
Copy link
Member

Choose a reason for hiding this comment

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

should be just go, reference is when having a link

be backed by a merkle-tree store, but developers can provide their own implementations if
needed. In the case of the `KVStoreService` implementation provided in `Environment`, module
developers should understand that calling `OpenKVStore` will return a store already scoped to
the module's prefix. The wiring for this scoping is specified in `runtime`.
Copy link
Member

Choose a reason for hiding this comment

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

Yes, we need an explanation of what is runtime in concepts too 👍🏾
I think the order should be, baseapp, transaction, core, runtime and then the rest, but we can do the ordering later.

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Oct 7, 2024
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

🧹 Outside diff range and nitpick comments (12)
docs/learn/advanced/17-core.md (7)

1-24: Minor grammatical improvements needed

The content provides a clear introduction to the Core package and the Environment struct. However, there are a few minor grammatical issues that can be addressed:

  1. Line 21: Consider adding a comma after "Historically" for improved clarity.
  2. Line 22: Replace "an" with "a" before "sdk.Context" as it doesn't start with a vowel sound.
  3. Line 23: The phrase "in many cases" is used frequently. Consider rephrasing to "in numerous scenarios" or "in various situations" for variety.

These small changes will enhance the readability and professionalism of the document.

🧰 Tools
🪛 LanguageTool

[typographical] ~21-~21: Consider adding a comma after ‘Historically’ for more clarity.
Context: ...ppmodule/v2/environment.go#L16-L29 ``` Historically the SDK has used an [sdk.Context](02-co...

(RB_LY_COMMA)


[misspelling] ~22-~22: Use “a” instead of ‘an’ if the following word doesn’t start with a vowel sound, e.g. ‘a sentence’, ‘a university’.
Context: ...-L29 ``` Historically the SDK has used an sdk.Context to pass ar...

(EN_A_VS_AN)


[style] ~23-~23: The phrase ‘in many cases’ is used quite frequently. Consider using a less frequent alternative to set your writing apart from others.
Context: ...is intended to replace an sdk.Context in many cases. sdk.Context will be deprecated in th...

(IN_MANY_STYLE_CASES)


26-53: Branch Service section looks good with a minor suggestion

The Branch Service section provides a clear explanation of its purpose and usage, along with a relevant code example. The content is informative and well-structured.

Consider rephrasing the sentence on line 30 to strengthen the wording:
"This is useful for executing code that requires store modifications but may need to be rolled back if an error occurs."

Overall, this section effectively communicates the functionality of the BranchService.

🧰 Tools
🪛 LanguageTool

[style] ~30-~30: Consider shortening or rephrasing this to strengthen your wording.
Context: ...useful for executing code that needs to make changes to the store, but may need to be rolled ba...

(MAKE_CHANGES)


54-66: Event Service section is informative with a minor correction needed

The Event Service section provides a clear explanation of its functionality and its relationship to the EventManager. The content is well-structured and informative.

Please add a comma after "SDK" on line 58 to improve readability:
"For information on how to emit events and their meaning in the SDK, see the Events document."

Additionally, on line 61, add a comma after "Roughly speaking" as it's an introductory phrase.

The code reference provided is appropriate and adds value to the explanation.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~58-~58: Possible missing comma found.
Context: ...to emit events and their meaning in the SDK see the Events document...

(AI_HYDRA_LEO_MISSING_COMMA)


[typographical] ~61-~61: This introductory phrase requires a comma.
Context: ... deprecated and removed in the future. Roughly speaking legacy EmitTypeEvent maps to Emit a...

(RB_SPEAKING_COMMA)


68-76: Gas Service section is well-explained with a minor correction needed

The Gas Service section provides a concise and clear explanation of its functionality and usage. The content effectively communicates the purpose of the Gas Service.

Please add a comma before "but" on line 71 to separate the two independent clauses:
"Gas consumption is largely handled at the framework level for transaction processing and state access, but modules can choose to use the gas service directly if needed."

The code reference provided is appropriate and enhances the explanation.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~71-~71: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ... transaction processing and state access but modules can choose to use the gas servi...

(COMMA_COMPOUND_SENTENCE_2)


78-104: Header Service sections are well-explained with minor improvements needed

The Header Service and Custom Header Service sections provide clear and informative explanations of their functionalities and implementation. The content effectively communicates the purpose and customization options for the Header Service.

Please make the following minor improvements:

  1. On line 89, hyphenate "service-oriented" as it's used as a modifier: "Core's service-oriented architecture (SOA) allows for chain developers to define a custom implementation of the HeaderService interface."

  2. On line 92, add a comma after the parenthetical: "Note, this example is taken from runtime/v2 but could easily be adapted to runtime/v1 (the default runtime 0.52)."

The code references provided are appropriate and enhance the explanations for both the Header Service and Custom Header Service.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~89-~89: When ‘service-oriented’ is used as a modifier, it is usually spelled with a hyphen.
Context: ... ``` ### Custom Header Service Core's service oriented architecture (SOA) allows for chain developers to de...

(SERVICE_LEVEL_HYPHEN)


[uncategorized] ~92-~92: Possible missing comma found.
Context: ...(when using depinject is shown below). Note this example is taken from runtime/v2...

(AI_HYDRA_LEO_MISSING_COMMA)


106-118: Query and Message Router Service section is informative with a minor correction needed

The Query and Message Router Service section provides a clear explanation of these services and their importance in module decoupling. The content effectively communicates the purpose and benefits of these services.

Please make the following minor correction:

On line 108, add the article "an" before "implementation": "Both the query and message router services are an implementation of the same interface, router.Service."

The code reference provided is appropriate and adds value to the explanation.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~108-~108: Possible missing article found.
Context: ...e query and message router services are implementation of the same interface, router.Service...

(AI_HYDRA_LEO_MISSING_AN)


[style] ~117-~117: Consider a shorter alternative to avoid wordiness.
Context: ...ch require a dynamic dispatch mechanism in order to function. ## TransactionService ```go...

(IN_ORDER_TO_PREMIUM)


131-141: KVStore Service section is informative with a minor suggestion

The KVStore Service section provides a clear explanation of its functionality and usage. The content effectively communicates the purpose of the KVStore Service and its implementation details.

Consider rephrasing the last sentence on line 117 to avoid wordiness:
"The wiring for this scoping is specified in runtime."

The code reference provided is appropriate and adds value to the explanation.

Overall, this section is well-written and informative.

docs/learn/advanced/05-encoding.md (5)

19-27: Approve changes with a minor suggestion for clarity

The revisions to the introduction and encoding protocols section provide a clear and concise explanation of the current encoding practices in the Cosmos SDK. The transition from go-amino to gogoprotobuf is well-emphasized, and the limitations of Amino are clearly stated.

Consider rephrasing line 27 for improved clarity:

- JSON) in order to support the Amino JSON sign mode, and for JSON RPC endpoints.
+ JSON) to support the Amino JSON sign mode and JSON RPC endpoints.

This minor change removes the redundant "in order to" phrase, making the sentence more concise.

🧰 Tools
🪛 LanguageTool

[style] ~27-~27: Consider a shorter alternative to avoid wordiness.
Context: ...only used to generate JSON (Amino JSON) in order to support the Amino JSON sign mode, and f...

(IN_ORDER_TO_PREMIUM)


35-47: Approve changes with a suggestion for additional context

The updates to the storage encoding and ProtoCodec sections provide clear guidance for module developers. The emphasis on Protobuf encoding and the explanation of ProtoCodec are well-articulated.

Consider adding a brief explanation or link to more information about the collections package mentioned in lines 37-38. This would provide readers with context on why this package is recommended and how it relates to encoding and decoding state.


Line range hint 49-70: Approve changes with a suggestion for additional information

The new section on Gogoproto and the guidelines for protobuf message definitions are excellent additions to the documentation. They provide clear and specific guidance for developers working with Protobuf in the Cosmos SDK context.

Consider adding a brief note or link to documentation explaining how to generate code using these annotations. This would provide a complete picture for developers who are new to working with Protobuf in the Cosmos SDK.

🧰 Tools
🪛 LanguageTool

[style] ~27-~27: Consider a shorter alternative to avoid wordiness.
Context: ...only used to generate JSON (Amino JSON) in order to support the Amino JSON sign mode, and f...

(IN_ORDER_TO_PREMIUM)


Line range hint 95-232: Approve changes with a suggestion for additional clarity

The section on Interface Encoding and Usage of Any is comprehensive and well-explained. It provides clear examples of how to use Any for interface encoding, including packing and unpacking. The explanation of the UnpackInterfaces method and the real-life examples from the Cosmos SDK are particularly valuable for developers.

Consider adding a brief note or visual diagram illustrating the relationship between Any, InterfaceRegistry, and UnpackInterfaces. This could help developers better understand how these components work together in the context of interface encoding.

🧰 Tools
🪛 LanguageTool

[style] ~27-~27: Consider a shorter alternative to avoid wordiness.
Context: ...only used to generate JSON (Amino JSON) in order to support the Amino JSON sign mode, and f...

(IN_ORDER_TO_PREMIUM)


Line range hint 275-293: Approve changes to FAQ section with a suggestion for additional information

The FAQ section provides concise and useful guidance for creating modules using protobuf encoding. The coverage of module types, naming conventions, and links to style guides is helpful for developers.

Consider adding a brief example or link to a sample module that demonstrates best practices in protobuf encoding. This could provide a practical reference for developers implementing these guidelines.

🧰 Tools
🪛 LanguageTool

[style] ~27-~27: Consider a shorter alternative to avoid wordiness.
Context: ...only used to generate JSON (Amino JSON) in order to support the Amino JSON sign mode, and f...

(IN_ORDER_TO_PREMIUM)

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 46b01ba and 89291c9.

📒 Files selected for processing (2)
  • docs/learn/advanced/05-encoding.md (1 hunks)
  • docs/learn/advanced/17-core.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
docs/learn/advanced/05-encoding.md (1)

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

docs/learn/advanced/17-core.md (1)

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

🪛 LanguageTool
docs/learn/advanced/05-encoding.md

[style] ~27-~27: Consider a shorter alternative to avoid wordiness.
Context: ...only used to generate JSON (Amino JSON) in order to support the Amino JSON sign mode, and f...

(IN_ORDER_TO_PREMIUM)

docs/learn/advanced/17-core.md

[typographical] ~21-~21: Consider adding a comma after ‘Historically’ for more clarity.
Context: ...ppmodule/v2/environment.go#L16-L29 ``` Historically the SDK has used an [sdk.Context](02-co...

(RB_LY_COMMA)


[misspelling] ~22-~22: Use “a” instead of ‘an’ if the following word doesn’t start with a vowel sound, e.g. ‘a sentence’, ‘a university’.
Context: ...-L29 ``` Historically the SDK has used an sdk.Context to pass ar...

(EN_A_VS_AN)


[style] ~23-~23: The phrase ‘in many cases’ is used quite frequently. Consider using a less frequent alternative to set your writing apart from others.
Context: ...is intended to replace an sdk.Context in many cases. sdk.Context will be deprecated in th...

(IN_MANY_STYLE_CASES)


[style] ~30-~30: Consider shortening or rephrasing this to strengthen your wording.
Context: ...useful for executing code that needs to make changes to the store, but may need to be rolled ba...

(MAKE_CHANGES)


[uncategorized] ~58-~58: Possible missing comma found.
Context: ...to emit events and their meaning in the SDK see the Events document...

(AI_HYDRA_LEO_MISSING_COMMA)


[typographical] ~61-~61: This introductory phrase requires a comma.
Context: ... deprecated and removed in the future. Roughly speaking legacy EmitTypeEvent maps to Emit a...

(RB_SPEAKING_COMMA)


[uncategorized] ~71-~71: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ... transaction processing and state access but modules can choose to use the gas servi...

(COMMA_COMPOUND_SENTENCE_2)


[uncategorized] ~89-~89: When ‘service-oriented’ is used as a modifier, it is usually spelled with a hyphen.
Context: ... ``` ### Custom Header Service Core's service oriented architecture (SOA) allows for chain developers to de...

(SERVICE_LEVEL_HYPHEN)


[uncategorized] ~92-~92: Possible missing comma found.
Context: ...(when using depinject is shown below). Note this example is taken from runtime/v2...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~108-~108: Possible missing article found.
Context: ...e query and message router services are implementation of the same interface, router.Service...

(AI_HYDRA_LEO_MISSING_AN)


[style] ~117-~117: Consider a shorter alternative to avoid wordiness.
Context: ...ch require a dynamic dispatch mechanism in order to function. ## TransactionService ```go...

(IN_ORDER_TO_PREMIUM)

🔇 Additional comments (3)
docs/learn/advanced/17-core.md (1)

120-130: TransactionService section is well-explained and concise

The TransactionService section provides a clear and concise explanation of its functionality and usage. The content effectively communicates the purpose of the TransactionService and its various execution modes.

The code reference provided is appropriate and enhances the explanation.

Overall, this section is well-written and informative.

docs/learn/advanced/05-encoding.md (2)

Line range hint 72-93: Approve changes to Transaction Encoding section

The section on Transaction Encoding provides a clear and concise explanation of how Protobuf is used for encoding and decoding transactions in the Cosmos SDK. The references to TxEncoder and TxDecoder objects, along with links to implementation examples and ADR-020, offer valuable resources for developers seeking to understand or implement transaction encoding.

🧰 Tools
🪛 LanguageTool

[style] ~27-~27: Consider a shorter alternative to avoid wordiness.
Context: ...only used to generate JSON (Amino JSON) in order to support the Amino JSON sign mode, and f...

(IN_ORDER_TO_PREMIUM)


Line range hint 234-273: Approve changes to Any's TypeURL section

The section on Any's TypeURL provides a clear explanation of how TypeURLs are structured in the Cosmos SDK, highlighting important differences from other implementations. The guidelines for using helper functions from "github.com/cosmos/cosmos-proto/anyutil" are practical and help maintain compatibility. The provided example effectively illustrates the difference in TypeURL format.

🧰 Tools
🪛 LanguageTool

[style] ~27-~27: Consider a shorter alternative to avoid wordiness.
Context: ...only used to generate JSON (Amino JSON) in order to support the Amino JSON sign mode, and f...

(IN_ORDER_TO_PREMIUM)

@tac0turtle tac0turtle added this pull request to the merge queue Oct 7, 2024
Merged via the queue into main with commit 9076487 Oct 7, 2024
76 checks passed
@tac0turtle tac0turtle deleted the kocu/core-docs branch October 7, 2024 19:58
mergify bot pushed a commit that referenced this pull request Oct 7, 2024
julienrbrt added a commit that referenced this pull request Oct 7, 2024
#22159)

Co-authored-by: Matt Kocubinski <mkocubinski@gmail.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
@coderabbitai coderabbitai bot mentioned this pull request Oct 25, 2024
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants