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

add oracle flag & flag checker to msgupdateoracle of opchild #105

Merged
merged 4 commits into from
Aug 28, 2024

Conversation

sh-cha
Copy link
Contributor

@sh-cha sh-cha commented Aug 27, 2024

  • add oracle flag into bridge config
  • add oracle flag checker to MsgUpdateOracle

Summary by CodeRabbit

  • New Features

    • Introduced new message types for updating Oracle configurations, enhancing the system's interaction capabilities.
    • Added a new field to the BridgeConfig for enabling/disabling Oracle functionality.
    • Implemented a robust validation mechanism for the new Oracle configuration updates.
  • Bug Fixes

    • Improved error handling for scenarios when Oracle functionality is disabled, ensuring proper feedback during updates.
  • Tests

    • Enhanced test coverage with new cases for Oracle updates, validating both successful and error scenarios.
  • Documentation

    • Updated comments and documentation to clarify the purpose of new functionalities and fields related to Oracle configurations.

@sh-cha sh-cha self-assigned this Aug 27, 2024
@sh-cha sh-cha requested a review from a team as a code owner August 27, 2024 07:02
Copy link

coderabbitai bot commented Aug 27, 2024

Warning

Rate limit exceeded

@beer-1 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 30 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between b25e356 and f4ecc01.

Walkthrough

The changes introduce new message types and configurations for oracle management within the codebase. Key modifications include the addition of MsgUpdateOracleConfig and MsgUpdateOracleConfigResponse, enhancements to the BridgeConfig structure with an OracleEnabled field, and updates to relevant methods and error handling. Additionally, tests have been expanded to ensure robust validation of the oracle functionality, integrating these updates into the existing protocol effectively.

Changes

Files Change Summary
api/opinit/ophost/v1/tx.pulsar.go, proto/opinit/ophost/v1/tx.proto, x/opchild/keeper/msg_server.go, x/ophost/keeper/msg_server.go, x/ophost/types/tx.go Introduced MsgUpdateOracleConfig and MsgUpdateOracleConfigResponse message types; updated existing messages and methods to support oracle configurations.
api/opinit/ophost/v1/types.pulsar.go, proto/opinit/ophost/v1/types.proto Added OracleEnabled boolean field to BridgeConfig, modifying related methods to handle this new field.
x/opchild/types/errors.go Introduced ErrOracleDisabled error and updated ErrRedundantTx code.
x/opchild/keeper/msg_server_test.go, x/ophost/keeper/msg_server_test.go Expanded test coverage for oracle functionality, validating both successful updates and error scenarios.
x/ophost/types/event.go Added constant AttributeKeyOracleEnabled to track oracle state in events.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MsgServer
    participant Keeper
    participant BridgeConfig

    User->>MsgServer: UpdateOracleConfig(request)
    MsgServer->>Keeper: GetBridgeInfo()
    Keeper-->>MsgServer: BridgeInfo
    MsgServer->>BridgeConfig: Check OracleEnabled
    alt OracleEnabled is true
        MsgServer->>Keeper: ApplyOracleUpdate()
        Keeper-->>MsgServer: Update Success
    else OracleEnabled is false
        MsgServer-->>User: ErrOracleDisabled
    end
Loading

🐰 In the realm of code where changes abound,
New oracles bloom, with features profound.
With tests to ensure all functions align,
Our bridges now dance, in harmony, they shine!
Let's hop with joy, for the updates are here,
A future of oracles, bright and clear! 🌟


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

codecov bot commented Aug 27, 2024

Codecov Report

Attention: Patch coverage is 43.47826% with 26 lines in your changes missing coverage. Please review.

Project coverage is 47.61%. Comparing base (7a2cc2e) to head (295e67b).

Files Patch % Lines
x/ophost/types/tx.go 0.00% 14 Missing ⚠️
x/ophost/keeper/msg_server.go 62.50% 6 Missing and 3 partials ⚠️
x/opchild/keeper/msg_server.go 62.50% 2 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #105      +/-   ##
==========================================
- Coverage   47.66%   47.61%   -0.06%     
==========================================
  Files          57       57              
  Lines        4204     4249      +45     
==========================================
+ Hits         2004     2023      +19     
- Misses       1782     1804      +22     
- Partials      418      422       +4     
Files Coverage Δ
x/opchild/keeper/msg_server.go 56.25% <62.50%> (+0.01%) ⬆️
x/ophost/keeper/msg_server.go 57.60% <62.50%> (+0.28%) ⬆️
x/ophost/types/tx.go 0.00% <0.00%> (ø)

Copy link

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7a2cc2e and b25e356.

Files ignored due to path filters (2)
  • x/ophost/types/tx.pb.go is excluded by !**/*.pb.go
  • x/ophost/types/types.pb.go is excluded by !**/*.pb.go
Files selected for processing (11)
  • api/opinit/ophost/v1/tx.pulsar.go (25 hunks)
  • api/opinit/ophost/v1/types.pulsar.go (16 hunks)
  • proto/opinit/ophost/v1/tx.proto (2 hunks)
  • proto/opinit/ophost/v1/types.proto (1 hunks)
  • x/opchild/keeper/msg_server.go (1 hunks)
  • x/opchild/keeper/msg_server_test.go (2 hunks)
  • x/opchild/types/errors.go (1 hunks)
  • x/ophost/keeper/msg_server.go (2 hunks)
  • x/ophost/keeper/msg_server_test.go (2 hunks)
  • x/ophost/types/event.go (1 hunks)
  • x/ophost/types/tx.go (1 hunks)
Additional context used
GitHub Check: codecov/patch
x/ophost/types/tx.go

[warning] 390-395: x/ophost/types/tx.go#L390-L395
Added lines #L390 - L395 were not covered by tests


[warning] 399-402: x/ophost/types/tx.go#L399-L402
Added lines #L399 - L402 were not covered by tests


[warning] 404-407: x/ophost/types/tx.go#L404-L407
Added lines #L404 - L407 were not covered by tests

x/opchild/keeper/msg_server.go

[warning] 595-596: x/opchild/keeper/msg_server.go#L595-L596
Added lines #L595 - L596 were not covered by tests

x/ophost/keeper/msg_server.go

[warning] 503-504: x/ophost/keeper/msg_server.go#L503-L504
Added lines #L503 - L504 were not covered by tests


[warning] 509-510: x/ophost/keeper/msg_server.go#L509-L510
Added lines #L509 - L510 were not covered by tests


[warning] 520-521: x/ophost/keeper/msg_server.go#L520-L521
Added lines #L520 - L521 were not covered by tests

Additional comments not posted (45)
x/ophost/types/event.go (1)

34-34: LGTM!

The constant AttributeKeyOracleEnabled is correctly defined and follows the naming conventions used in the file.

The code changes are approved.

x/opchild/types/errors.go (2)

35-35: LGTM!

The error variable ErrOracleDisabled is correctly defined and registered with the error module. The error message is clear and descriptive.

The code changes are approved.


38-38: LGTM!

The error variable ErrRedundantTx is correctly updated to reflect the new registration code. The error message remains clear and descriptive.

The code changes are approved.

proto/opinit/ophost/v1/types.proto (2)

55-56: LGTM!

The field oracle_enabled is correctly defined and follows the naming conventions used in the file. The addition enhances the configuration capabilities of the BridgeConfig message.

The code changes are approved.


59-59: LGTM!

The field metadata is correctly updated to reflect the new position. The change ensures that the new oracle_enabled field is correctly positioned in the updated schema.

The code changes are approved.

x/ophost/types/tx.go (1)

385-396: LGTM!

The function is correctly initializing the MsgUpdateOracleConfig struct.

The code changes are approved.

Tools
GitHub Check: codecov/patch

[warning] 390-395: x/ophost/types/tx.go#L390-L395
Added lines #L390 - L395 were not covered by tests

proto/opinit/ophost/v1/tx.proto (3)

251-251: LGTM!

The updated comment enhances the clarity of the documentation.

The code changes are approved.


266-276: LGTM!

The message type is correctly defined and enhances the functionality of the protocol.

The code changes are approved.


278-279: LGTM!

The message type is correctly defined.

The code changes are approved.

x/opchild/keeper/msg_server_test.go (1)

628-647: LGTM!

The test case correctly validates the behavior of UpdateOracle when the Oracle is disabled.

The code changes are approved.

x/ophost/keeper/msg_server_test.go (1)

444-488: LGTM!

The test case correctly validates the functionality of updating the Oracle configuration under various conditions.

The code changes are approved.

api/opinit/ophost/v1/types.pulsar.go (9)

569-569: LGTM!

The addition of the field descriptor fd_BridgeConfig_oracle_enabled is appropriate.

The code changes are approved.


582-582: LGTM!

The initialization of the field descriptor fd_BridgeConfig_oracle_enabled is appropriate.

The code changes are approved.


687-692: LGTM!

The update to include the OracleEnabled field in the Range method is appropriate.

The code changes are approved.


726-727: LGTM!

The update to include the OracleEnabled field in the Has method is appropriate.

The code changes are approved.


758-759: LGTM!

The update to reset the OracleEnabled field to false in the Clear method is appropriate.

The code changes are approved.


799-801: LGTM!

The update to retrieve the value of the OracleEnabled field in the Get method is appropriate.

The code changes are approved.


839-840: LGTM!

The update to allow setting the value of the OracleEnabled field in the Set method is appropriate.

The code changes are approved.


888-889: LGTM!

The update to include a panic condition for the OracleEnabled field in the Mutable method is appropriate.

The code changes are approved.


Line range hint 1019-1070: LGTM!

The update to account for the OracleEnabled field during serialization and deserialization processes in the ProtoMethods function is appropriate.

The code changes are approved.

api/opinit/ophost/v1/tx.pulsar.go (25)

9164-9169: LGTM!

The initialization of new message and field descriptors for MsgUpdateOracleConfig is correctly implemented.

The code changes are approved.

Also applies to: 9171-9177


9179-9185: LGTM!

The fastReflection_MsgUpdateOracleConfig type and its associated methods are correctly implemented.

The code changes are approved.

Also applies to: 9187-9197, 9199-9212


9213-9218: LGTM!

The additional methods for fastReflection_MsgUpdateOracleConfig provide comprehensive reflection capabilities and are correctly implemented.

The code changes are approved.

Also applies to: 9220-9236, 9238-9262, 9264-9289, 9291-9311, 9313-9335, 9338-9362, 9364-9387, 9390-9407, 9409-9417, 9420-9436, 9438-9448, 9450-9684


9686-9688: LGTM!

The MsgUpdateOracleConfigResponse type and its associated methods are correctly implemented, providing necessary reflection capabilities.

The code changes are approved.

Also applies to: 9690-9693, 9695-9701, 9703-9713, 9715-9728, 9730-9734, 9736-9752, 9754-9760, 9762-9781, 9783-9797, 9799-9812, 9815-9832, 9835-9852, 9855-9866, 9868-9877, 9879-9884, 9886-9895, 9897-9907, 9909-10040


Line range hint 10066-10070: LGTM!

The updates to the MsgUpdateMetadata type and its associated methods are correctly implemented.

The code changes are approved.


Line range hint 10598-10602: LGTM!

The updates to the MsgUpdateMetadataResponse type and its associated methods are correctly implemented.

The code changes are approved.


Line range hint 11050-11054: LGTM!

The updates to the MsgUpdateParams type and its associated methods are correctly implemented.

The code changes are approved.


Line range hint 11545-11549: LGTM!

The updates to the MsgUpdateParamsResponse type and its associated methods are correctly implemented.

The code changes are approved.


Line range hint 12681-12685: LGTM!

The new fields Authority, BridgeId, and OracleEnabled are correctly added to the MsgUpdateOracleConfig type.

The code changes are approved.


12774-12853: LGTM!

The MsgUpdateOracleConfig type and its associated methods are correctly implemented, providing necessary reflection capabilities.

The code changes are approved.


Line range hint 12874-12878: LGTM!

The updates to the MsgUpdateMetadata type and its associated methods are correctly implemented.

The code changes are approved.


Line range hint 12927-12931: LGTM!

The updates to the MsgUpdateMetadataResponse type and its associated methods are correctly implemented.

The code changes are approved.


Line range hint 12974-12978: LGTM!

The updates to the MsgUpdateParams type and its associated methods are correctly implemented.

The code changes are approved.


Line range hint 13015-13019: LGTM!

The updates to the MsgUpdateParamsResponse type and its associated methods are correctly implemented.

The code changes are approved.


13272-13300: LGTM!

The new fields Authority, BridgeId, and OracleEnabled are correctly added to the MsgUpdateOracleConfig type.

The code changes are approved.


13301-13327: LGTM!

The updates to the MsgUpdateOracleConfigResponse type and its associated methods are correctly implemented.

The code changes are approved.


Line range hint 13426-13433: LGTM!

The updates to the MsgUpdateMetadata type and its associated methods are correctly implemented.

The code changes are approved.


13446-13455: LGTM!

The updates to the MsgUpdateOracleConfig type and its associated methods are correctly implemented.

The code changes are approved.


Line range hint 13472-13484: LGTM!

The updates to the MsgUpdateMetadata type and its associated methods are correctly implemented.

The code changes are approved.


13483-13484: LGTM!

The updates to the MsgUpdateParams type and its associated methods are correctly implemented.

The code changes are approved.


Line range hint 13716-13721: LGTM!

The updates to the MsgUpdateOracleConfig type and its associated methods are correctly implemented.

The code changes are approved.


Line range hint 13728-13733: LGTM!

The updates to the MsgUpdateOracleConfigResponse type and its associated methods are correctly implemented.

The code changes are approved.


Line range hint 13740-13745: LGTM!

The updates to the MsgUpdateMetadata type and its associated methods are correctly implemented.

The code changes are approved.


13752-13761: LGTM!

The updates to the MsgUpdateMetadataResponse type and its associated methods are correctly implemented.

The code changes are approved.


13764-13773: LGTM!

The updates to the MsgUpdateParams type and its associated methods are correctly implemented.

The code changes are approved.

Comment on lines +398 to +407
// Validate performs basic MsgUpdateOracleConfig message validation.
func (msg MsgUpdateOracleConfig) Validate(accAddressCodec address.Codec) error {
if _, err := accAddressCodec.StringToBytes(msg.Authority); err != nil {
return err
}

if msg.BridgeId == 0 {
return ErrInvalidBridgeId
}
return nil
Copy link

Choose a reason for hiding this comment

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

LGTM! But add tests for validation.

The validation logic is correct. However, the added lines are not covered by tests.

The code changes are approved.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 399-402: x/ophost/types/tx.go#L399-L402
Added lines #L399 - L402 were not covered by tests


[warning] 404-407: x/ophost/types/tx.go#L404-L407
Added lines #L404 - L407 were not covered by tests

Comment on lines +592 to +599
// config check
info, err := ms.Keeper.BridgeInfo.Get(ctx)
if err != nil {
return nil, err
}
if !info.BridgeConfig.OracleEnabled {
return nil, types.ErrOracleDisabled
}
Copy link

Choose a reason for hiding this comment

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

LGTM! But add tests for the configuration check.

The added configuration check enhances the robustness of the function. However, the added lines are not covered by tests.

The code changes are approved.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Tools
GitHub Check: codecov/patch

[warning] 595-596: x/opchild/keeper/msg_server.go#L595-L596
Added lines #L595 - L596 were not covered by tests

Comment on lines +501 to +504
func (ms MsgServer) UpdateOracleConfig(ctx context.Context, req *types.MsgUpdateOracleConfig) (*types.MsgUpdateOracleConfigResponse, error) {
if err := req.Validate(ms.authKeeper.AddressCodec()); err != nil {
return nil, err
}
Copy link

Choose a reason for hiding this comment

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

Ensure validation errors are covered by tests.

The validation check for the request is not covered by tests.

Add a test case to cover validation errors for the request.

Tools
GitHub Check: codecov/patch

[warning] 503-504: x/ophost/keeper/msg_server.go#L503-L504
Added lines #L503 - L504 were not covered by tests

Comment on lines +506 to +510
bridgeId := req.BridgeId
config, err := ms.GetBridgeConfig(ctx, bridgeId)
if err != nil {
return nil, err
}
Copy link

Choose a reason for hiding this comment

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

Ensure error handling for bridge configuration retrieval is covered by tests.

The error handling for retrieving the bridge configuration is not covered by tests.

Add a test case to cover errors when retrieving the bridge configuration.

Tools
GitHub Check: codecov/patch

[warning] 509-510: x/ophost/keeper/msg_server.go#L509-L510
Added lines #L509 - L510 were not covered by tests

Comment on lines +512 to +515
// gov or current proposer can update metadata.
if ms.authority != req.Authority && config.Proposer != req.Authority {
return nil, govtypes.ErrInvalidSigner.Wrapf("invalid authority; expected %s or %s, got %s", ms.authority, config.Proposer, req.Authority)
}
Copy link

Choose a reason for hiding this comment

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

Ensure permission checks are covered by tests.

The permission check for updating the Oracle configuration is correctly implemented but not covered by tests.

Add a test case to cover permission checks for updating the Oracle configuration.

Comment on lines +517 to +521
config.OracleEnabled = req.OracleEnabled

if err := ms.SetBridgeConfig(ctx, bridgeId, config); err != nil {
return nil, err
}
Copy link

Choose a reason for hiding this comment

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

Ensure setting the bridge configuration is covered by tests.

The process of setting the bridge configuration is not covered by tests.

Add a test case to cover setting the bridge configuration.

Tools
GitHub Check: codecov/patch

[warning] 520-521: x/ophost/keeper/msg_server.go#L520-L521
Added lines #L520 - L521 were not covered by tests

Comment on lines +523 to +527
sdk.UnwrapSDKContext(ctx).EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeUpdateBatchInfo,
sdk.NewAttribute(types.AttributeKeyBridgeId, strconv.FormatUint(bridgeId, 10)),
sdk.NewAttribute(types.AttributeKeyOracleEnabled, strconv.FormatBool(config.OracleEnabled)),
))
Copy link

Choose a reason for hiding this comment

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

Ensure event emission is covered by tests.

The event emission for updating the Oracle configuration is correctly implemented but not covered by tests.

Add a test case to cover event emission for updating the Oracle configuration.

Copy link
Contributor

@beer-1 beer-1 left a comment

Choose a reason for hiding this comment

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

LGTM

@beer-1 beer-1 merged commit a428c7d into main Aug 28, 2024
3 of 4 checks passed
@beer-1 beer-1 deleted the feat/oracle-flag branch August 28, 2024 07:14
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.

2 participants