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: add docs on server v2 vote extensions #23010

Merged
merged 1 commit into from
Dec 19, 2024
Merged

Conversation

facundomedica
Copy link
Member

@facundomedica facundomedica commented Dec 19, 2024

Description

Closes: #XXXX


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 documentation to include new sections on vote extensions in version 2 of the ABCI framework.
    • Added examples for extending, verifying votes, and processing proposals.
    • Clarified usage of the PreBlocker function and its integration with vote extensions.

@facundomedica facundomedica requested a review from a team as a code owner December 19, 2024 14:56
Copy link
Contributor

coderabbitai bot commented Dec 19, 2024

📝 Walkthrough

Walkthrough

The pull request updates the documentation for ABCI vote extensions in version 2, focusing on explaining how to implement and use new server options for extending and verifying votes. The documentation provides detailed guidance on handlers for extending votes, verifying vote extensions, preparing and processing proposals, and using the PreBlocker function. The changes illustrate the new approach to handling vote extensions within the CometBFT framework, demonstrating practical implementation examples for developers.

Changes

File Change Summary
docs/build/abci/03-vote-extensions.md Added comprehensive documentation for vote extensions v2, including detailed sections on ExtendVoteHandler, VerifyVoteExtensionHandler, PrepareProposalHandler, and ProcessProposalHandler
types/abci.go Method signatures for vote extension handlers remain unchanged, but usage context updated for v2 implementation

Sequence Diagram

sequenceDiagram
    participant App as Application
    participant CometBFT as CometBFT Server
    
    App->>CometBFT: Set ExtendVoteHandler
    App->>CometBFT: Set VerifyVoteExtensionHandler
    App->>CometBFT: Set PrepareProposalHandler
    App->>CometBFT: Set ProcessProposalHandler
    
    CometBFT-->>App: Request Vote Extension
    App-->>CometBFT: Provide Vote Extension
    
    CometBFT-->>App: Verify Vote Extension
    App-->>CometBFT: Validation Result
Loading

Possibly related PRs

Suggested labels

Type: ADR

Suggested reviewers

  • kocubinski
  • testinginprod
  • octavio12345300
  • hieuvubk
  • julienrbrt

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.

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 (6)
docs/build/abci/03-vote-extensions.md (6)

124-125: Add context about v2 changes

Consider adding a brief introduction explaining the key differences or improvements in v2 compared to v1, helping readers understand what to expect in this section.


134-140: Enhance the example implementation

The current example could be improved to demonstrate best practices:

  1. Add proper error handling
  2. Validate inputs
  3. Show a more realistic implementation instead of hardcoded values

Consider this enhanced example:

 func CustomExtendVoteHandler() handlers.ExtendVoteHandler {
-	return func(ctx context.Context, rm store.ReaderMap, evr *v1.ExtendVoteRequest) (*v1.ExtendVoteResponse, error) {
-		return &v1.ExtendVoteResponse{
-			VoteExtension: []byte("BTC=1234567.89;height=" + fmt.Sprint(evr.Height)),
-		}, nil
+	return func(ctx context.Context, rm store.ReaderMap, evr *v1.ExtendVoteRequest) (*v1.ExtendVoteResponse, error) {
+		if evr == nil {
+			return nil, fmt.Errorf("extend vote request cannot be nil")
+		}
+		
+		// Fetch real price data from your oracle
+		price, err := fetchCurrentPrice(ctx)
+		if err != nil {
+			return nil, fmt.Errorf("failed to fetch price: %w", err)
+		}
+		
+		voteExt := fmt.Sprintf("BTC=%f;height=%d", price, evr.Height)
+		return &v1.ExtendVoteResponse{
+			VoteExtension: []byte(voteExt),
+		}, nil
+	}
 }

198-198: Fix grammar: Add missing comma

Add a comma after "them" in the sentence.

-The ProcessProposal handler can be used to recover the vote extensions from the first transaction and perform any necessary verification on them. In the example below
+The ProcessProposal handler can be used to recover the vote extensions from the first transaction and perform any necessary verification on them, in the example below
🧰 Tools
🪛 LanguageTool

[uncategorized] ~198-~198: Possible missing comma found.
Context: ...ry verification on them. In the example below we also use the `cometbft.ValidateVoteE...

(AI_HYDRA_LEO_MISSING_COMMA)


260-260: Implement the TODO comment

The TODO comment should be implemented to show how to properly handle vote extensions.

Would you like me to provide an example implementation for handling the vote extensions in the ProcessProposal handler?


270-271: Fix grammatical error: Remove repeated word

Remove the duplicate "is" in the sentence.

-In v2, the `PreBlocker` function works in the same way as it does in v1. However, it is is now passed in as an option to `appbuilder.Build`.
+In v2, the `PreBlocker` function works in the same way as it does in v1. However, it is now passed in as an option to `appbuilder.Build`.
🧰 Tools
🪛 LanguageTool

[duplication] ~270-~270: Possible typo: you repeated a word
Context: ... same way as it does in v1. However, it is is now passed in as an option to `appbuild...

(ENGLISH_WORD_REPEAT_RULE)


282-282: Add newline at end of file

Add a newline character at the end of the file to follow Markdown best practices.

🧰 Tools
🪛 Markdownlint (0.37.0)

282-282: 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 448b33d and d74c6ca.

📒 Files selected for processing (1)
  • docs/build/abci/03-vote-extensions.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
docs/build/abci/03-vote-extensions.md (1)

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

🪛 LanguageTool
docs/build/abci/03-vote-extensions.md

[uncategorized] ~198-~198: Possible missing comma found.
Context: ...ry verification on them. In the example below we also use the `cometbft.ValidateVoteE...

(AI_HYDRA_LEO_MISSING_COMMA)


[duplication] ~270-~270: Possible typo: you repeated a word
Context: ... same way as it does in v1. However, it is is now passed in as an option to `appbuild...

(ENGLISH_WORD_REPEAT_RULE)

🪛 Markdownlint (0.37.0)
docs/build/abci/03-vote-extensions.md

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

(MD047, single-trailing-newline)

Comment on lines +150 to +154
func CustomVerifyVoteExtensionHandler]() handlers.VerifyVoteExtensionHandler {
return func(context.Context, store.ReaderMap, *abci.VerifyVoteExtensionRequest) (*abci.VerifyVoteExtensionResponse, error) {
return &abci.VerifyVoteExtensionResponse{}, nil
}
}
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

Add proper verification logic

The current implementation returns an empty response without any verification. This could be misleading as production code should properly validate vote extensions.

Consider this implementation:

-func CustomVerifyVoteExtensionHandler]() handlers.VerifyVoteExtensionHandler {
-    return  func(context.Context, store.ReaderMap, *abci.VerifyVoteExtensionRequest) (*abci.VerifyVoteExtensionResponse, error) {
-        return &abci.VerifyVoteExtensionResponse{}, nil
-    }
+func CustomVerifyVoteExtensionHandler() handlers.VerifyVoteExtensionHandler {
+    return func(ctx context.Context, rm store.ReaderMap, req *abci.VerifyVoteExtensionRequest) (*abci.VerifyVoteExtensionResponse, error) {
+        if req == nil || len(req.VoteExtension) == 0 {
+            return nil, fmt.Errorf("invalid vote extension")
+        }
+        
+        // Verify the format and data
+        if err := validateVoteExtensionFormat(req.VoteExtension); err != nil {
+            return nil, fmt.Errorf("invalid vote extension format: %w", err)
+        }
+        
+        return &abci.VerifyVoteExtensionResponse{}, nil
+    }
 }

Committable suggestion skipped: line range outside the PR's diff.

@julienrbrt julienrbrt changed the title chore: Add docs on server v2 vote extensions docs: add docs on server v2 vote extensions Dec 19, 2024
Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

nice job!!

@tac0turtle tac0turtle added this pull request to the merge queue Dec 19, 2024
Merged via the queue into main with commit 65ceca6 Dec 19, 2024
79 of 80 checks passed
@tac0turtle tac0turtle deleted the facu/add-voteextsv2-docs branch December 19, 2024 19:42
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.

3 participants