Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[CT-1237] enable messages and add ante decorator to the chain #2375

Merged
merged 2 commits into from
Sep 30, 2024
Merged

Conversation

jayy04
Copy link
Contributor

@jayy04 jayy04 commented Sep 26, 2024

Changelist

[Describe or list the changes made in this PR]

Test Plan

[Describe how this PR was tested (if applicable)]

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced new message types for managing authenticators and account states in the accountplus module.
    • Enhanced gRPC functionality with new query and message server registrations.
    • Improved signature verification handling with a new circuit breaker decorator.
  • Bug Fixes

    • Updated handling of decorators in the CircuitBreakerDecorator for better execution flow.
  • Tests

    • Expanded test coverage for new message types related to authenticator management and account states.
  • Chores

    • Cleaned up comments and improved code structure for better maintainability.

@jayy04 jayy04 requested a review from a team as a code owner September 26, 2024 18:19
Copy link

linear bot commented Sep 26, 2024

Copy link
Contributor

coderabbitai bot commented Sep 26, 2024

Walkthrough

The changes introduced in this pull request focus on enhancing the functionality of the accountplus module within the protocol. Key modifications include the update of the sigVerification field in the lockingAnteHandler, the addition of new message types related to authenticator management, and enhancements to the CircuitBreakerDecorator. Furthermore, the registration of gRPC services has been improved, and new interface implementations for transaction extensions have been established.

Changes

Files Change Summary
protocol/app/ante.go Updated sigVerification field in lockingAnteHandler to use CircuitBreakerDecorator.
protocol/app/msgs/all_msgs.go Added new message types for managing authenticators and account states.
protocol/app/msgs/internal_msgs.go Introduced new internal message samples for MsgSetActiveState and its response.
protocol/app/msgs/normal_msgs.go Added message types for authenticator management to the messaging system.
protocol/app/msgs/internal_msgs_test.go Expanded tests to include new message types related to account state management.
protocol/app/msgs/normal_msgs_test.go Added test cases for new message paths associated with authenticator management.
protocol/x/accountplus/ante/circuit_breaker.go Changed field types in CircuitBreakerDecorator and updated method calls in AnteHandle.
protocol/x/accountplus/module.go Enhanced gRPC functionality by registering query and message handlers.
protocol/x/accountplus/types/codec.go Registered TxExtension for message service and interface implementations.
protocol/lib/ante/internal_msg.go Updated IsInternalMsg to recognize MsgSetActiveState as a valid internal message.

Possibly related PRs

Suggested labels

feature:timestamp_nonce

Suggested reviewers

  • teddyding
  • vincentwschau

Poem

🐇 In the meadow, changes bloom,
With circuits breaking, there's more room.
Authenticator's dance, a new delight,
Messages added, shining bright.
Hops of progress, we cheer and play,
For a brighter, safer day! 🌼


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between fb6050e and 8c66d69.

📒 Files selected for processing (1)
  • protocol/lib/ante/internal_msg.go (2 hunks)
🔇 Additional comments (2)
protocol/lib/ante/internal_msg.go (2)

18-18: LGTM: Import statement added correctly.

The new import for accountplus is correctly formatted and follows the existing import style. This import is necessary for the new message type added to the IsInternalMsg function.


75-77: LGTM: New internal message type added correctly.

The *accountplus.MsgSetActiveState has been correctly added to the list of internal messages. This change aligns with the PR objective of enabling messaging functionality.

Please verify the implications of treating MsgSetActiveState as an internal message:

✅ Verification successful

Verified: Internal message type handling confirmed.

The *accountplus.MsgSetActiveState has been correctly integrated as an internal message throughout the codebase. All related functions and tests properly handle this message type, ensuring its intended functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any special handling of internal messages in the codebase

# Test: Search for any special handling of internal messages
rg --type go -e "IsInternalMsg" -A 10

Length of output: 4656


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.

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

🧹 Outside diff range and nitpick comments (2)
protocol/x/accountplus/module.go (2)

64-69: LGTM! Consider adding error logging before panic.

The implementation correctly registers the gRPC gateway routes for the module, which aligns with the PR objective of enabling messaging functionality.

Consider adding error logging before the panic to provide more context for debugging:

 func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
 	err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
 	if err != nil {
+		log.Printf("Failed to register query handler client: %v", err)
 		panic(err)
 	}
 }

129-130: LGTM! Consider adding a descriptive comment.

The implementation correctly registers both QueryServer and MsgServer, which aligns with the PR objective of enabling messaging functionality.

Consider adding a brief comment to explain the purpose of this method:

 func (am AppModule) RegisterServices(cfg module.Configurator) {
+	// Register the query and message servers for the accountplus module
 	types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
 	types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 59b6b7a and fb6050e.

📒 Files selected for processing (10)
  • protocol/app/ante.go (2 hunks)
  • protocol/app/msgs/all_msgs.go (1 hunks)
  • protocol/app/msgs/internal_msgs.go (2 hunks)
  • protocol/app/msgs/internal_msgs_test.go (1 hunks)
  • protocol/app/msgs/normal_msgs.go (2 hunks)
  • protocol/app/msgs/normal_msgs_test.go (1 hunks)
  • protocol/x/accountplus/ante/circuit_breaker.go (2 hunks)
  • protocol/x/accountplus/ante/circuit_breaker_test.go (1 hunks)
  • protocol/x/accountplus/module.go (2 hunks)
  • protocol/x/accountplus/types/codec.go (2 hunks)
🔇 Additional comments (14)
protocol/x/accountplus/module.go (1)

Line range hint 1-163: Overall, the changes look good and align with the PR objectives.

The modifications to RegisterGRPCGatewayRoutes and RegisterServices successfully enable messaging functionality for the accountplus module. The implementation follows Cosmos SDK conventions and integrates well with the existing code structure.

protocol/x/accountplus/ante/circuit_breaker_test.go (1)

153-154: Simplification of CircuitBreakerDecorator instantiation

The change simplifies the instantiation of CircuitBreakerDecorator by directly passing mockTestAuthenticator and mockTestClassic instead of wrapping them with sdk.ChainAnteDecorators. This modification appears to maintain the core functionality while reducing code complexity.

However, to ensure the test accurately represents the production code:

  1. Verify that this change aligns with how CircuitBreakerDecorator is instantiated in the actual implementation.
  2. Confirm that CircuitBreakerDecorator can handle individual decorators as well as decorator chains.

To validate the consistency with the actual implementation, please run the following script:

This script will help us understand how CircuitBreakerDecorator is used and defined in the actual codebase, ensuring our test accurately reflects the production code.

✅ Verification successful

Verification Successful: CircuitBreakerDecorator instantiation aligns with production usage.

The simplified instantiation in the test correctly mirrors how CircuitBreakerDecorator is utilized in the codebase by accepting individual AnteDecorators. No inconsistencies or issues were found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the usage of NewCircuitBreakerDecorator in the codebase

# Search for NewCircuitBreakerDecorator usage
echo "Searching for NewCircuitBreakerDecorator usage:"
rg --type go "NewCircuitBreakerDecorator\(" -A 3 -B 1

# Search for CircuitBreakerDecorator struct definition
echo "\nSearching for CircuitBreakerDecorator struct definition:"
rg --type go "type CircuitBreakerDecorator struct" -A 10

Length of output: 2397

protocol/app/msgs/internal_msgs_test.go (1)

66-69: LGTM! New message types for accountplus module added.

The addition of MsgSetActiveState and MsgSetActiveStateResponse for the accountplus module is consistent with the existing structure and naming conventions. This change appears to be part of implementing new functionality for account state management.

To ensure consistency with the accountplus module implementation, please run the following script:

This will help confirm that the new message types are properly implemented in the accountplus module.

✅ Verification successful

Verification Successful! The new message types for the accountplus module are properly defined and implemented.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of MsgSetActiveState and MsgSetActiveStateResponse in the accountplus module

# Test: Search for MsgSetActiveState and MsgSetActiveStateResponse in the accountplus module
rg --type go -e 'MsgSetActiveState' -e 'MsgSetActiveStateResponse' $(fd -t d -d 1 accountplus)

# Expected output: Definitions or usages of these message types in the accountplus module files

Length of output: 7148

protocol/app/msgs/normal_msgs_test.go (1)

121-126: LGTM: New message paths for accountplus module added correctly.

The new message paths for the accountplus module have been added correctly and in the proper alphabetical order. This addition suggests new functionality related to account authentication, which aligns with the PR objectives of enabling messaging functionality.

To ensure consistency, please verify that these new message types are properly implemented in the corresponding files. You can use the following script to check for their implementations:

✅ Verification successful

Verified: New accountplus message types are fully implemented and tested.

The implementations for MsgAddAuthenticator, MsgRemoveAuthenticator, and TxExtension are present and appropriately registered in the protocol/x/accountplus module. Corresponding tests have been added to ensure their functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of new accountplus message types

# Test: Search for the implementation of new message types
rg --type go -e "MsgAddAuthenticator" -e "MsgRemoveAuthenticator" -e "TxExtension" ./protocol/x/accountplus

Length of output: 18357

protocol/app/msgs/internal_msgs.go (3)

19-19: New import for accountplus module added

The new import for the accountplus module has been correctly added. This import is necessary for the new message types that are being introduced in the InternalMsgSamplesDydxCustom map.


19-19: Summary of changes and potential impact

The changes introduce new message types (MsgSetActiveState and MsgSetActiveStateResponse) for the accountplus module. This addition aligns with the PR objective of enabling messaging functionality, specifically related to setting an active state for accounts.

These changes have the following potential impacts:

  1. They enable new functionality for account state management.
  2. They maintain consistency with the existing code structure and patterns.
  3. They may require corresponding changes in other parts of the codebase to fully implement and utilize this new functionality.

To ensure full implementation:

Let's check for any related changes in the accountplus module:

#!/bin/bash
# Description: Check for related changes in the accountplus module

echo "Searching for files with recent changes in the accountplus module:"
git diff --name-only HEAD~1 HEAD | grep 'protocol/x/accountplus'

echo "Searching for new functions or methods related to SetActiveState:"
rg --type go 'func.*SetActiveState' protocol/x/accountplus

This will help identify any related changes and ensure that the new message types are properly integrated into the accountplus module.

Also applies to: 116-119


116-119: New message types added for accountplus module

Two new entries have been added to the InternalMsgSamplesDydxCustom map:

  1. "/dydxprotocol.accountplus.MsgSetActiveState" with a value of &accountplus.MsgSetActiveState{}
  2. "/dydxprotocol.accountplus.MsgSetActiveStateResponse" with a nil value

These additions are consistent with the pattern used for other custom messages in this map. The nil value for the response type is also consistent with other response types in this map.

However, to ensure completeness:

Let's verify if these new message types are properly defined in the accountplus module:

This will help confirm that these new message types are properly defined in the accountplus module.

protocol/app/msgs/normal_msgs.go (1)

225-232: LGTM. Please clarify the purpose of TxExtension.

The additions of MsgAddAuthenticator, MsgRemoveAuthenticator, and their respective response types align well with the PR objectives of enabling messaging functionality. These new message types enhance account management capabilities, particularly in authentication.

However, could you please elaborate on the purpose and usage of the TxExtension type? Understanding its role would help in assessing how it relates to the ante decorator mentioned in the PR objectives.

protocol/app/msgs/all_msgs.go (1)

158-167: New message types added for the accountplus module

The changes introduce seven new message types for the accountplus module, expanding the functionality of the application. These new types include operations for adding and removing authenticators, setting active state, and a transaction extension. The implementation follows the existing naming conventions and is correctly integrated into the AllTypeMessages map.

This addition enhances the capabilities of the accountplus module, potentially allowing for more flexible account management and authentication processes.

protocol/x/accountplus/types/codec.go (2)

6-7: Approved: Necessary imports added

The imports of "github.com/cosmos/cosmos-sdk/types/msgservice" and "github.com/cosmos/cosmos-sdk/types/tx" are required for the implementation of message services and transaction extension options.


24-24: Approved: Message service descriptor registered

The call to msgservice.RegisterMsgServiceDesc registers the _Msg_serviceDesc. This is necessary for enabling message services within the module.

protocol/x/accountplus/ante/circuit_breaker.go (2)

47-47: Invocation of AnteHandle on decorator is appropriate

The call to AnteHandle on authenticatorAnteHandlerFlow correctly aligns with the updated use of sdk.AnteDecorator. This ensures that the decorator pattern is properly utilized.


51-51: Invocation of AnteHandle on decorator is appropriate

The call to AnteHandle on originalAnteHandlerFlow is appropriate following the change to sdk.AnteDecorator, maintaining consistency in the ante handler flow.

protocol/app/ante.go (1)

125-136: Proper Integration of Ante Decorators

The sigVerification field has been updated to include a composition of the CircuitBreakerDecorator, AuthenticatorDecorator, and SigVerificationDecorator. This enhances the transaction verification process by adding circuit-breaking capabilities and improved authentication handling.

Comment on lines +18 to +24
registry.RegisterImplementations((*tx.TxExtensionOptionI)(nil), &TxExtension{})

registry.RegisterImplementations(
(*AuthenticatorTxOptions)(nil),
&TxExtension{},
)
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

TxExtension does not implement the required methods for tx.TxExtensionOptionI and AuthenticatorTxOptions.

  • Missing method: Marshal() ([]byte, error)
  • Missing method: GetSelectedAuthenticators() []uint64
🔗 Analysis chain

Verify that TxExtension implements the required interfaces

The RegisterInterfaces function now registers TxExtension as an implementation of tx.TxExtensionOptionI and AuthenticatorTxOptions. Ensure that TxExtension correctly implements all methods required by these interfaces.

Run the following script to confirm the implementation:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that TxExtension implements tx.TxExtensionOptionI and AuthenticatorTxOptions

# Check for methods implementing tx.TxExtensionOptionI
ast-grep --lang go --pattern $'func (TxExtension) Marshal() ([]byte, error) { $$$ }'

# Check for methods implementing AuthenticatorTxOptions
ast-grep --lang go --pattern $'func (TxExtension) GetSelectedAuthenticators() []uint64 { $$$ }'

Length of output: 182


Script:

#!/bin/bash
# Description: List all methods implemented by TxExtension

# Retrieve all method declarations for TxExtension
ast-grep --lang go --pattern $'func (TxExtension) $_() $_ { $$$ }'

Length of output: 67


Script:

#!/bin/bash
# Description: Verify that TxExtension implements tx.TxExtensionOptionI and AuthenticatorTxOptions using pointer receivers

# Check for methods implementing tx.TxExtensionOptionI with pointer receiver
ast-grep --lang go --pattern $'func (*TxExtension) Marshal() ([]byte, error) { $$$ }'

# Check for methods implementing AuthenticatorTxOptions with pointer receiver
ast-grep --lang go --pattern $'func (*TxExtension) GetSelectedAuthenticators() []uint64 { $$$ }'

# List all methods implemented by TxExtension with pointer receivers
ast-grep --lang go --pattern $'func (*TxExtension) $_() $_ { $$$ }'

Length of output: 482

Comment on lines +14 to +15
authenticatorAnteHandlerFlow sdk.AnteDecorator
originalAnteHandlerFlow sdk.AnteDecorator
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

Consider renaming variables to reflect their updated types

The fields authenticatorAnteHandlerFlow and originalAnteHandlerFlow have been changed from type sdk.AnteHandler to sdk.AnteDecorator. To improve clarity and maintain consistency with their new types, consider renaming them to authenticatorAnteDecoratorFlow and originalAnteDecoratorFlow.

Comment on lines +21 to +22
auth sdk.AnteDecorator,
classic sdk.AnteDecorator,
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

Update parameter names to enhance readability

In the NewCircuitBreakerDecorator function, the parameters auth and classic are now of type sdk.AnteDecorator. To make the code more readable and to reflect their types, consider renaming them to authDecorator and classicDecorator.

@@ -163,7 +172,7 @@ type lockingAnteHandler struct {
validateSigCount ante.ValidateSigCountDecorator
incrementSequence ante.IncrementSequenceDecorator
replayProtection customante.ReplayProtectionDecorator
sigVerification customante.SigVerificationDecorator
sigVerification accountplusante.CircuitBreakerDecorator
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

Consider Typing sigVerification as sdk.AnteDecorator for Flexibility

Currently, sigVerification is declared as accountplusante.CircuitBreakerDecorator. To promote interface-based design and improve maintainability, consider changing the type to sdk.AnteDecorator, the interface implemented by all ante decorators. This allows for easier substitution and testing of different decorators.

Apply this diff to update the type:

-     sigVerification          accountplusante.CircuitBreakerDecorator
+     sigVerification          sdk.AnteDecorator
📝 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
sigVerification accountplusante.CircuitBreakerDecorator
sigVerification sdk.AnteDecorator

@jayy04 jayy04 merged commit 19fd34d into main Sep 30, 2024
22 checks passed
@jayy04 jayy04 deleted the jy/ct-1237 branch September 30, 2024 15:46
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants