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

fix: apply audit #229

Merged
merged 17 commits into from
Jul 23, 2024
Merged

fix: apply audit #229

merged 17 commits into from
Jul 23, 2024

Conversation

beer-1
Copy link
Member

@beer-1 beer-1 commented Jul 17, 2024

No description provided.

@beer-1 beer-1 self-assigned this Jul 17, 2024
@beer-1 beer-1 requested a review from a team as a code owner July 17, 2024 08:12
Copy link

coderabbitai bot commented Jul 17, 2024

Walkthrough

Walkthrough

The changes mainly involve updates to the genesis.proto, tx.proto, and various files within the keeper package across different modules. Key changes include modifications to the genesis state handling for NFTs, adjustments to message naming conventions, improvements to token allocation logic, and bug fixes. Additionally, permission checks have been introduced for relayers in the IBC module, and minor code cleanups have been applied throughout.

Changes

File(s) Change Summary
proto/ibc/applications/nft_transfer/v1/genesis.proto Modified GenesisState to include class_data and token_data arrays. Introduced ClassData and TokenData message types.
proto/initia/distribution/v1/tx.proto Updated MsgDepositValidatorRewardsPool's amino.name option from "cosmos-sdk/distr/MsgDepositValRewards" to "distr/MsgDepositValidatorRewardsPool".
x/bank/keeper/grpc_query.go Simplified error handling in the DenomMetadata function to directly return an error.
x/distribution/keeper/allocation.go Improved allocation logic in AllocateTokens function to handle zero pool size and amount cases better.
x/distribution/types/codec.go Registered MsgDepositValidatorRewardsPool under distr and as an implementation in RegisterInterfaces.
x/gov/... Various updates to the gov module including emergency proposal handling, deposit management, and receiver name changes.
x/ibc/nft-transfer/keeper/genesis.go Added logic for handling ClassData and TokenData in InitGenesis and ExportGenesis functions.
x/ibc/perm/ibc_module.go Introduced permission checks in OnRecvPacket function for relayers.
x/ibc/perm/keeper/keeper.go HasPermission function now returns true if no permissioned relayers are set.
x/mstaking/keeper/slash.go Adjusted slashing logic in SlashRedelegation function.
x/mstaking/types/authz.go Updated StakeAuthorization to handle MsgCancelUnbondingDelegation messages.
x/reward/abci.go Added a conditional check in BeginBlocker to set releaseRate to zero if negative.

Sequence Diagram(s)

NFT Genesis State Handling (New Flow)

sequenceDiagram
    participant Client
    participant Keeper
    participant State
    
    Client->>Keeper: InitGenesis(state)
    Keeper->>State: Set ClassData
    Keeper->>State: Set TokenData
    Client-->>Keeper: ExportGenesis()
    Keeper->>State: Get ClassData
    Keeper->>State: Get TokenData
    State-->>Keeper: Return Data
    Keeper-->>Client: Return Genesis State
Loading

IBC Packet Permission Check

sequenceDiagram
    participant IBCMiddleware
    participant Keeper
    
    IBCMiddleware->>Keeper: OnRecvPacket(packet)
    Keeper->>Keeper: HasPermission(relayer)
    alt Permission Granted
        Keeper-->>IBCMiddleware: Continue Processing
    else Permission Denied
        Keeper-->>IBCMiddleware: Panic with Error
    end
Loading

Poem

In the realm of code so fine,
Genesis states now intertwine.
Permissions check for packets swift,
Allocation logic gets a lift.
With changes flowing, neat and clear,
Our system grows, no bugs to fear.


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

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

Outside diff range, codebase verification and nitpick comments (3)
x/distribution/types/codec.go (1)

24-24: Issue: MsgDepositValidatorRewardsPool does not implement the sdk.Msg interface.

The MsgDepositValidatorRewardsPool struct is missing the required methods to implement the sdk.Msg interface. This is crucial for its correct operation within the SDK.

  • Ensure that MsgDepositValidatorRewardsPool implements the following methods:
    • Route() string
    • Type() string
    • ValidateBasic() error
    • GetSignBytes() []byte
    • GetSigners() []sdk.AccAddress
Analysis chain

Ensure correct interface registration.

The registration of MsgDepositValidatorRewardsPool as an implementation of sdk.Msg is crucial for its correct operation within the SDK. Ensure that this registration is reflected wherever MsgDepositValidatorRewardsPool is used to maintain interface consistency.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that `MsgDepositValidatorRewardsPool` is correctly recognized as an implementation of `sdk.Msg` across the codebase.

# Test: Search for the implementation usage. Expect: Correct recognition and usage as `sdk.Msg`.
rg --type go -A 5 $'MsgDepositValidatorRewardsPool'

Length of output: 77038


Script:

#!/bin/bash
# Description: Verify that `MsgDepositValidatorRewardsPool` implements `sdk.Msg` interface methods.

# Test: Search for the implementation of `sdk.Msg` interface methods in `MsgDepositValidatorRewardsPool`.
rg --type go -A 5 'func (m \*MsgDepositValidatorRewardsPool) Route\(\) string'
rg --type go -A 5 'func (m \*MsgDepositValidatorRewardsPool) Type\(\) string'
rg --type go -A 5 'func (m \*MsgDepositValidatorRewardsPool) ValidateBasic\(\) error'
rg --type go -A 5 'func (m \*MsgDepositValidatorRewardsPool) GetSignBytes\(\) \[\]byte'
rg --type go -A 5 'func (m \*MsgDepositValidatorRewardsPool) GetSigners\(\) \[\]sdk.AccAddress'

Length of output: 436


Script:

#!/bin/bash
# Description: Verify that `MsgDepositValidatorRewardsPool` implements `sdk.Msg` interface methods.

# Test: Search for the definition of `MsgDepositValidatorRewardsPool` struct and list all its methods.
rg --type go -A 10 'type MsgDepositValidatorRewardsPool struct'
rg --type go -A 10 'func (m \*MsgDepositValidatorRewardsPool) '

Length of output: 2493


Script:

#!/bin/bash
# Description: Verify all methods associated with `MsgDepositValidatorRewardsPool` to check if it implements `sdk.Msg` interface.

# Test: Search for all methods of `MsgDepositValidatorRewardsPool`.
rg --type go 'func (m \*MsgDepositValidatorRewardsPool) '

Length of output: 59

x/ibc/perm/ibc_module.go (1)

160-167: Clarify error message for better user understanding.

The error message "all packets of the channel %s should be relayed by the permissioned relayers" could be more descriptive. It should clarify why the packet cannot be relayed and what actions, if any, the user can take to correct this.

- "all packets of the channel `%s` should be relayed by the permissioned relayers",
+ "Permission denied: The packet cannot be relayed on channel `%s` as it is not from a permissioned relayer. Please contact the network administrator.",
x/mstaking/keeper/slash.go (1)

323-361: Review of new slashing logic in SlashRedelegation

The new logic introduced in SlashRedelegation prioritizes slashing unbonding delegations over regular delegations. This is a significant change and seems to align with the intended behavior described in the summary. However, there are a few points to consider:

  1. Correctness: The logic correctly checks if the unbonding delegation can be slashed before moving on to slash the delegation. This ensures that tokens that are in the process of unbonding are considered first, which might be crucial for maintaining the integrity of the slashing process.

  2. Performance: The function iterates over entries in the unbonding delegation and delegation, which could be performance-intensive depending on the number of entries. It would be beneficial to monitor the performance of this section, especially under high load.

  3. Error Handling: The function handles errors from SetUnbondingDelegation but does not log these errors. Adding logging for these errors could help with debugging and operational monitoring.

  4. Potential Improvement: Consider adding more detailed comments explaining why unbonding delegations are prioritized over delegations. This will help future maintainers understand the reasoning behind this design choice.

Overall, the changes appear sound, but adding more detailed logging and comments would enhance maintainability and debuggability.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c95783c and 401e399.

Files ignored due to path filters (2)
  • x/distribution/types/tx.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/ibc/nft-transfer/types/genesis.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
Files selected for processing (17)
  • proto/ibc/applications/nft_transfer/v1/genesis.proto (1 hunks)
  • proto/initia/distribution/v1/tx.proto (1 hunks)
  • x/bank/keeper/grpc_query.go (2 hunks)
  • x/distribution/keeper/allocation.go (1 hunks)
  • x/distribution/types/codec.go (1 hunks)
  • x/gov/abci.go (1 hunks)
  • x/gov/keeper/deposit.go (10 hunks)
  • x/gov/keeper/proposal.go (11 hunks)
  • x/gov/keeper/tally.go (5 hunks)
  • x/gov/keeper/vote.go (4 hunks)
  • x/gov/types/params.go (1 hunks)
  • x/ibc/nft-transfer/keeper/genesis.go (4 hunks)
  • x/ibc/perm/ibc_module.go (1 hunks)
  • x/ibc/perm/keeper/keeper.go (1 hunks)
  • x/mstaking/keeper/slash.go (1 hunks)
  • x/mstaking/types/authz.go (2 hunks)
  • x/reward/abci.go (1 hunks)
Additional comments not posted (16)
x/distribution/types/codec.go (1)

16-16: Verify registration under shortened alias.

The message type MsgDepositValidatorRewardsPool is registered with a shortened alias due to Amino's rejection of long type names. While this resolves the immediate issue, it's crucial to verify that this alias does not conflict with other aliases and that it is consistently used across the codebase where relevant.

Verification successful

Alias 'distr/MsgDepositValidatorRewardsPool' is unique and consistently used.

  • The alias 'distr/MsgDepositValidatorRewardsPool' is registered in x/distribution/types/codec.go.
  • It is also defined as an option in proto/initia/distribution/v1/tx.proto.

There are no conflicts or additional usages found in the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the alias 'distr/MsgDepositValidatorRewardsPool' is unique and consistently used.

# Test: Search for the alias usage. Expect: Only occurrences linked to MsgDepositValidatorRewardsPool.
rg --type go -A 5 $'distr/MsgDepositValidatorRewardsPool'

Length of output: 546


Script:

#!/bin/bash
# Comprehensive search for the alias 'distr/MsgDepositValidatorRewardsPool' to ensure uniqueness and consistent usage across the codebase.

# Test: Search for the alias usage across the entire codebase.
rg 'distr/MsgDepositValidatorRewardsPool'

Length of output: 288

proto/ibc/applications/nft_transfer/v1/genesis.proto (2)

26-28: Ensure correct definition and usage of ClassData and TokenData.

The new message types ClassData and TokenData are introduced to handle class and token data respectively. It's crucial to ensure that these types are used correctly throughout the codebase, particularly in functions that handle genesis data.

Also applies to: 34-36

Verification successful

Verification successful: Correct definition and usage of ClassData and TokenData.

The ClassData and TokenData message types are correctly defined and consistently used throughout the codebase, including in genesis handling functions and various tests.

  • proto/ibc/applications/nft_transfer/v1/genesis.proto
  • x/ibc/nft-transfer/keeper/genesis.go
  • x/ibc/nft-transfer/keeper/relay.go
  • x/ibc/nft-transfer/keeper/keeper.go
  • x/ibc/nft-transfer/types/genesis.pb.go
  • x/ibc/nft-transfer/types/packet.pb.go
  • x/ibc/nft-transfer/types/ibc.go
  • x/ibc-hooks/move-hooks/timeout_test.go
  • x/ibc-hooks/move-hooks/ack_test.go
  • x/ibc-hooks/move-hooks/receive_test.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that `ClassData` and `TokenData` are defined and used correctly.

# Test: Search for the usage of `ClassData` and `TokenData`. Expect: Correct definition and consistent usage.
rg --type proto -A 5 $'ClassData|TokenData'

Length of output: 74


Script:

#!/bin/bash
# Description: Verify that `ClassData` and `TokenData` are defined and used correctly.

# Test: Search for the definition and usage of `ClassData` and `TokenData` in .proto files.
rg 'ClassData|TokenData' --glob '*.proto' -A 5

Length of output: 1723


Script:

#!/bin/bash
# Description: Verify that `ClassData` and `TokenData` are used correctly throughout the codebase.

# Test: Search for the usage of `ClassData` and `TokenData` in the codebase.
rg 'ClassData|TokenData' -A 5

Length of output: 51905


18-19: Review the updated GenesisState structure.

The replacement of the Params field with class_data and token_data arrays in GenesisState is a significant change. Ensure that all references to the old Params field are updated to accommodate this new structure. Additionally, validate that the serialization and deserialization processes handle these repeated fields correctly.

Also applies to: 21-21

x/gov/keeper/vote.go (1)

16-16: Review changes in receiver variable names.

The renaming of the receiver variable from keeper to k in the AddVote and deleteVotes functions is a minor change but requires careful attention to ensure that all references within these functions are updated accordingly. Verify that the new variable name k does not introduce any scope or access issues.

Also applies to: 64-64

x/ibc/nft-transfer/keeper/genesis.go (2)

7-7: Review new imports.

The addition of cosmossdk.io/collections and github.com/initia-labs/initia/x/ibc/nft-transfer/types imports should be verified to ensure that they are necessary and used appropriately throughout the file. Particularly, check that the collections package is used efficiently in the new logic.

Verification successful

New imports are used appropriately.

The imports cosmossdk.io/collections and github.com/initia-labs/initia/x/ibc/nft-transfer/types are effectively utilized within the x/ibc/nft-transfer/keeper/genesis.go file:

  • cosmossdk.io/collections is used for operations involving the collections package.
  • github.com/initia-labs/initia/x/ibc/nft-transfer/types is used for handling types specific to the NFT transfer logic.

These usages confirm that the imports are necessary and used appropriately.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the new imports are used effectively.

# Test: Search for the usage of the new imports. Expect: Effective and necessary usage.
rg --type go -A 5 $'cosmossdk.io/collections|github.com/initia-labs/initia/x/ibc/nft-transfer/types'

Length of output: 33188


Script:

#!/bin/bash
# Description: Verify the usage of the new imports in the specific file `x/ibc/nft-transfer/keeper/genesis.go`.

# Test: Search for the usage of the `cosmossdk.io/collections` and `github.com/initia-labs/initia/x/ibc/nft-transfer/types` imports in the target file.
rg --type go --no-heading --line-number --color never 'collections|nft-transfer/types' x/ibc/nft-transfer/keeper/genesis.go

Length of output: 437


23-33: Ensure correct handling of ClassData and TokenData.

The modifications in InitGenesis and ExportGenesis to incorporate ClassData and TokenData handling are substantial. Verify that these changes do not introduce any logical errors or inefficiencies, particularly in the loops and data retrieval functions. Additionally, ensure that the new structure of the GenesisState return value in ExportGenesis correctly reflects the added data.

Also applies to: 63-91

proto/initia/distribution/v1/tx.proto (1)

50-50: Approved: Update to amino.name in MsgDepositValidatorRewardsPool.

The change in the amino.name option is noted and approved.

However, ensure that all references and usages of this message type are updated accordingly.

Verification successful

Verified: Update to amino.name in MsgDepositValidatorRewardsPool.

The change in the amino.name option has been successfully propagated throughout the codebase. No occurrences of the old message type name were found.

  • x/distribution/types/codec.go
  • proto/initia/distribution/v1/tx.proto
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the updated message type is correctly handled in the codebase.

# Test: Search for the old and new message type names. Expect: Only occurrences of the new name.
rg --type proto -A 5 $'distr/MsgDepositValidatorRewardsPool'
rg --type proto -A 5 $'cosmos-sdk/distr/MsgDepositValRewards'

Length of output: 180


Script:

#!/bin/bash
# Description: Verify that the updated message type is correctly handled in the codebase.

# Test: Search for the old and new message type names. Expect: Only occurrences of the new name.
rg -A 5 'distr/MsgDepositValidatorRewardsPool'
rg -A 5 'cosmos-sdk/distr/MsgDepositValRewards'

Length of output: 1030

x/ibc/perm/keeper/keeper.go (1)

101-102: Verify the default permission logic.

Allowing all relayers by default when no permissioned relayers are set is a significant change.

Ensure this behavior is clearly documented to avoid security misunderstandings.

Would you like me to draft the documentation for this change?

x/gov/types/params.go (1)

111-111: Ensure the validation logic is correctly implemented.

The change to require the expedited minimum deposit to be greater than the minimum deposit is correctly implemented. This aligns with the PR objectives and enhances the validation logic.

x/gov/keeper/proposal.go (1)

22-36: Review of receiver variable changes and method updates in proposal.go.

The changes to use the receiver k instead of keeper are consistently applied across all the methods in this file. This is a straightforward refactor and does not change the logic of the methods.

Also applies to: 56-66, 75-75, 97-102, 115-115, 119-119, 125-125, 142-144, 172-172, 177-177, 183-183, 188-188, 193-193, 203-203, 205-205, 210-210, 216-216, 220-220, 221-221, 227-227, 233-233, 238-238, 244-244, 249-249, 256-256, 260-260, 265-265, 279-279, 284-284, 289-289, 296-296, 300-300, 310-310, 315-315, 320-320

x/gov/keeper/deposit.go (1)

22-27: Review of receiver variable changes and method updates in deposit.go.

The changes to use the receiver k instead of keeper are consistently applied across all the methods in this file. This is a straightforward refactor and does not change the logic of the methods.

Also applies to: 31-32, 40-44, 50-50, 54-56, 65-67, 78-78, 126-126, 133-133, 141-141, 148-148, 156-156, 163-163, 177-178, 182-182, 191-191, 197-197, 208-208, 212-212, 218-218, 243-243, 250-250, 259-259, 263-263, 268-268, 273-273, 277-277, 290-290, 291-291, 293-293, 297-297

x/gov/abci.go (1)

133-136: Ensure the handling of emergency proposals is correctly implemented.

The change to return early for emergency proposals in the EndBlocker function is correctly implemented. This prevents emergency proposals from undergoing the tallying process, which aligns with the PR objectives.

x/gov/keeper/tally.go (2)

22-22: Review of function signature change:

The change from keeper to k as the receiver variable is a minor, stylistic adjustment that improves consistency if it matches other methods in the Keeper struct.


23-23: Review of method calls with updated receiver variable:

All method calls within the Tally function now use the k receiver variable consistently. This change should not affect functionality but does improve readability and consistency across the codebase.

Also applies to: 39-39, 63-63, 74-74, 107-107

x/distribution/keeper/allocation.go (1)

89-98: Review of updates in the AllocateTokens function:

The changes to skip allocation when poolSize or bondedTokens.Amount are zero are crucial for robustness. These checks prevent divisions by zero and other mathematical errors, which are essential for the stability of the token distribution logic.

Also applies to: 103-103

x/bank/keeper/grpc_query.go (1)

189-189: Simplification of error handling in DenomMetadata:

Removing the fetching of metadata if not found and directly returning an error simplifies the function. This change should make the function more predictable and easier to maintain, assuming that clients handle these errors appropriately.

Comment on lines 160 to 167
if ok, err := im.keeper.HasPermission(ctx, packet.DestinationPort, packet.DestinationChannel, relayer); err != nil {
return newEmitErrorAcknowledgement(ctx, err)
} else if !ok {
panic(fmt.Errorf(
"all packets of the channel `%s` should be relayed by the permissioned relayers",
packet.DestinationChannel,
))
}
Copy link

Choose a reason for hiding this comment

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

Potential improvement in error handling consistency.

The function newEmitErrorAcknowledgement is used to handle errors in one branch but not consistently across all error scenarios. Consider using this function consistently for all error conditions to maintain uniform error handling across the module.

- panic(fmt.Errorf(
-	"all packets of the channel `%s` should be relayed by the permissioned relayers",
-	packet.DestinationChannel,
- ))
+ return newEmitErrorAcknowledgement(ctx, fmt.Errorf(
+	"all packets of the channel `%s` should be relayed by the permissioned relayers",
+	packet.DestinationChannel,
+ ))
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
if ok, err := im.keeper.HasPermission(ctx, packet.DestinationPort, packet.DestinationChannel, relayer); err != nil {
return newEmitErrorAcknowledgement(ctx, err)
} else if !ok {
panic(fmt.Errorf(
"all packets of the channel `%s` should be relayed by the permissioned relayers",
packet.DestinationChannel,
))
}
if ok, err := im.keeper.HasPermission(ctx, packet.DestinationPort, packet.DestinationChannel, relayer); err != nil {
return newEmitErrorAcknowledgement(ctx, err)
} else if !ok {
return newEmitErrorAcknowledgement(ctx, fmt.Errorf(
"all packets of the channel `%s` should be relayed by the permissioned relayers",
packet.DestinationChannel,
))
}

Consider replacing panic with a more graceful error handling approach.

Using panic can lead to abrupt termination of the application, which might not be desirable, especially in a distributed system like a blockchain where stability is crucial. Consider returning an error or a specific error acknowledgement instead.

- panic(fmt.Errorf(
-	"all packets of the channel `%s` should be relayed by the permissioned relayers",
-	packet.DestinationChannel,
- ))
+ return newEmitErrorAcknowledgement(ctx, fmt.Errorf(
+	"all packets of the channel `%s` should be relayed by the permissioned relayers",
+	packet.DestinationChannel,
+ ))
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
if ok, err := im.keeper.HasPermission(ctx, packet.DestinationPort, packet.DestinationChannel, relayer); err != nil {
return newEmitErrorAcknowledgement(ctx, err)
} else if !ok {
panic(fmt.Errorf(
"all packets of the channel `%s` should be relayed by the permissioned relayers",
packet.DestinationChannel,
))
}
if ok, err := im.keeper.HasPermission(ctx, packet.DestinationPort, packet.DestinationChannel, relayer); err != nil {
return newEmitErrorAcknowledgement(ctx, err)
} else if !ok {
return newEmitErrorAcknowledgement(ctx, fmt.Errorf(
"all packets of the channel `%s` should be relayed by the permissioned relayers",
packet.DestinationChannel,
))
}

Comment on lines +70 to +72
if releaseRate.IsNegative() {
releaseRate = math.LegacyZeroDec()
}
Copy link

Choose a reason for hiding this comment

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

Approved: Ensuring non-negative releaseRate.

The addition of a check to ensure releaseRate is non-negative is a good safety measure.

Consider adding unit tests to verify this behavior.

Would you like me to help in writing these tests or should I open a GitHub issue to track this task?

Comment on lines +75 to +77
case *MsgCancelUnbondingDelegation:
validatorAddress = msg.ValidatorAddress
amount = msg.Amount
Copy link

Choose a reason for hiding this comment

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

Approved: Handling of MsgCancelUnbondingDelegation in StakeAuthorization.

The update to handle MsgCancelUnbondingDelegation messages is a logical extension of the existing functionality.

Ensure this new handling is covered by unit tests to verify its correctness.

Would you like assistance in creating these tests, or should I open a GitHub issue to track this task?

@@ -19,8 +19,8 @@ import (

// Tally iterates over the votes and updates the tally of a proposal based on the voting power of the
// voters
func (keeper Keeper) Tally(ctx context.Context, params customtypes.Params, proposal customtypes.Proposal) (quorumReached, passed bool, burnDeposits bool, tallyResults v1.TallyResult, err error) {
weights, err := keeper.sk.GetVotingPowerWeights(ctx)
func (k Keeper) Tally(ctx context.Context, params customtypes.Params, proposal customtypes.Proposal) (quorumReached, passed bool, burnDeposits bool, tallyResults v1.TallyResult, err error) {
Copy link

Choose a reason for hiding this comment

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

Consider breaking down the Tally function:

The TODO comment suggests breaking the function into smaller parts for better clarity. This is a valid suggestion given the complexity and length of the function.

Consider refactoring Tally into smaller, more manageable functions that handle specific parts of the tallying process. This will improve maintainability and testability.

Copy link

codecov bot commented Jul 17, 2024

Codecov Report

Attention: Patch coverage is 46.70330% with 97 lines in your changes missing coverage. Please review.

Project coverage is 40.13%. Comparing base (c95783c) to head (166d698).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #229      +/-   ##
==========================================
- Coverage   40.24%   40.13%   -0.11%     
==========================================
  Files         259      259              
  Lines       24643    24712      +69     
==========================================
+ Hits         9918     9919       +1     
- Misses      13191    13249      +58     
- Partials     1534     1544      +10     
Files Coverage Δ
x/gov/keeper/vote.go 59.09% <100.00%> (ø)
x/bank/keeper/grpc_query.go 25.29% <0.00%> (+0.72%) ⬆️
x/gov/types/params.go 63.95% <0.00%> (ø)
x/ibc/perm/keeper/keeper.go 54.38% <0.00%> (-1.76%) ⬇️
x/distribution/types/codec.go 0.00% <0.00%> (ø)
x/gov/abci.go 27.44% <0.00%> (-0.27%) ⬇️
x/ibc/perm/ibc_module.go 24.61% <0.00%> (+0.73%) ⬆️
x/reward/abci.go 53.52% <0.00%> (-3.63%) ⬇️
x/gov/keeper/deposit.go 59.91% <90.47%> (-0.43%) ⬇️
x/mstaking/types/authz.go 0.00% <0.00%> (ø)
... and 5 more

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 401e399 and da9dae8.

Files selected for processing (2)
  • x/gov/keeper/common_test.go (1 hunks)
  • x/gov/types/params.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/gov/types/params.go
Additional comments not posted (1)
x/gov/keeper/common_test.go (1)

435-435: Proper initialization of ExpeditedMinDeposit field.

The change to initialize the ExpeditedMinDeposit field with bondDenom aligns with the existing pattern of using bondDenom for other deposit types. This standardization is beneficial for consistency across different types of governance proposals.

However, ensure to verify the impact of this new field on the governance module's functionality, especially in scenarios where expedited processing is required.

Verification successful

Proper initialization of ExpeditedMinDeposit field.

The change to initialize the ExpeditedMinDeposit field with bondDenom aligns with the existing pattern of using bondDenom for other deposit types. This standardization is beneficial for consistency across different types of governance proposals.

The search results confirm that the ExpeditedMinDeposit field is properly integrated and validated across the codebase, indicating no immediate issues with this change.

  • x/gov/types/params.go: Validation and assignment of ExpeditedMinDeposit.
  • x/gov/types/proposal.go: Utilization of ExpeditedMinDeposit in proposal logic.
  • x/gov/types/gov.pb.go: Protobuf serialization and getter methods for ExpeditedMinDeposit.
  • x/gov/keeper/deposit.go: Handling of ExpeditedMinDeposit in deposit logic.
  • x/gov/genesis_test.go, x/gov/keeper/common_test.go, app/genesis.go: Initialization in test and genesis setup.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the new `ExpeditedMinDeposit` field on governance functionality.

# Test: Search for the use of `ExpeditedMinDeposit` in governance logic. Expect: Proper handling and checks.
rg --type go -A 5 $'ExpeditedMinDeposit'

Length of output: 13093

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between da9dae8 and 4427c13.

Files ignored due to path filters (2)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum, !**/*.sum
Files selected for processing (1)
  • x/ibc/nft-transfer/keeper/genesis.go (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/ibc/nft-transfer/keeper/genesis.go

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4427c13 and 166d698.

Files selected for processing (1)
  • x/ibc/perm/ibc_module.go (3 hunks)
Additional context used
GitHub Check: codecov/patch
x/ibc/perm/ibc_module.go

[warning] 176-176: x/ibc/perm/ibc_module.go#L176
Added line #L176 was not covered by tests

Additional comments not posted (2)
x/ibc/perm/ibc_module.go (2)

158-160: Ensure consistent error handling.

Consider using newEmitErrorAcknowledgement consistently for all error conditions to maintain uniform error handling across the module.

- panic(fmt.Errorf(
-	"all packets of the channel `%s` should be relayed by the permissioned relayers",
-	packet.DestinationChannel,
- ))
+ return newEmitErrorAcknowledgement(ctx, fmt.Errorf(
+	"all packets of the channel `%s` should be relayed by the permissioned relayers",
+	packet.DestinationChannel,
+ ))

176-176: Replace panic with a more graceful error handling approach.

Using panic can lead to abrupt termination of the application, which might not be desirable, especially in a distributed system like a blockchain where stability is crucial. Consider returning an error or a specific error acknowledgement instead.

- panic(fmt.Errorf(
-	"all packets of the channel `%s` should be relayed by the permissioned relayers",
-	packet.DestinationChannel,
- ))
+ return newEmitErrorAcknowledgement(ctx, fmt.Errorf(
+	"all packets of the channel `%s` should be relayed by the permissioned relayers",
+	packet.DestinationChannel,
+ ))
Tools
GitHub Check: codecov/patch

[warning] 176-176: x/ibc/perm/ibc_module.go#L176
Added line #L176 was not covered by tests

Copy link
Contributor

@sh-cha sh-cha 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 58dd526 into main Jul 23, 2024
7 checks passed
@beer-1 beer-1 deleted the fix/audit branch July 23, 2024 06:58
This was referenced Sep 23, 2024
@coderabbitai coderabbitai bot mentioned this pull request Nov 21, 2024
11 tasks
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