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

feat(x/accounts): On-chain multisig #19988

Merged
merged 27 commits into from May 6, 2024
Merged

feat(x/accounts): On-chain multisig #19988

merged 27 commits into from May 6, 2024

Conversation

facundomedica
Copy link
Member

@facundomedica facundomedica commented Apr 9, 2024

Description

This multisig design requires members to be existing accounts ... WIP

Closes: #18859


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

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

Summary by CodeRabbit

  • New Features

    • Implemented a multisig account management system with account initialization, proposal handling, configuration updates, and member voting.
    • Introduced protocol messages for managing multisig accounts.
  • Documentation

    • Defined messages for multisig account operations in the multisig.proto file.
  • Tests

    • Added comprehensive test coverage for multisig account functionalities.

Copy link
Contributor

coderabbitai bot commented Apr 25, 2024

Walkthrough

Walkthrough

The recent updates focus on expanding multisig account capabilities within a Cosmos SDK application. These changes introduce new features for creating, managing, and testing multisig accounts. They also enhance the ability to update configurations and handle proposals. Additionally, improvements in context handling across modules establish a unified method for setting the sender context, enhancing consistency in system interactions.

Changes

File(s) Change Summary
x/accounts/defaults/multisig/account.go, x/accounts/defaults/multisig/account_test.go Introduced functionality for managing multisig accounts, including initialization, voting, proposal handling, and testing.
x/accounts/defaults/multisig/utils_test.go Provided test utilities, mocks, and dependencies for multisig accounts within the Cosmos SDK application.
x/accounts/defaults/multisig/update_config.go Added methods for updating multisig account configuration and ensuring setup consistency.
x/accounts/proto/cosmos/accounts/defaults/multisig/v1/multisig.proto Defined messages for managing multisig accounts, covering actions like initialization, voting, and configuration updates.
x/accounts/testing/counter/counter.go Updated declarations with new fields for better service integration.
x/accounts/CHANGELOG.md Added a feature entry for implementing x/accounts/multisig.

Assessment against linked issues

Objective Addressed Explanation
Feature: onchain multisig
Create a default multisig account using x/accounts
Migrate existing multisig to the new multisig
Allow multisig to be upgraded to add or remove participants

Recent Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between b57d3a1 and 5ba3d59.
Files selected for processing (3)
  • x/accounts/defaults/multisig/account.go (1 hunks)
  • x/accounts/defaults/multisig/account_test.go (1 hunks)
  • x/accounts/defaults/multisig/utils_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • x/accounts/defaults/multisig/account.go
  • x/accounts/defaults/multisig/account_test.go
  • x/accounts/defaults/multisig/utils_test.go

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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

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

@facundomedica facundomedica marked this pull request as ready for review April 26, 2024 16:37
@facundomedica facundomedica requested a review from a team as a code owner April 26, 2024 16:37

This comment has been minimized.

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

Out of diff range and nitpick comments (3)
x/accounts/defaults/multisig/update_config.go (1)

11-59: The logic for updating the multisig configuration and handling member updates is well-implemented. Consider adding more detailed comments to explain the validation logic and the conditions under which members are added or removed.

x/accounts/internal/implementation/context.go (1)

73-77: The implementation of SetSender correctly updates the sender in the context. Consider adding a comment to explain the importance of this operation, especially in a multisig context where the correct sender identity is crucial.

x/accounts/defaults/multisig/account.go (1)

44-341: The implementation of multisig account management in this file is comprehensive and robust. The methods for initializing accounts, managing proposals, and handling votes are well-structured. Consider adding more detailed comments to explain the logic in complex methods, especially those involving proposal execution and voting validation.

Comment on lines +26 to +169
&v1.MsgInit{
Config: nil,
Members: []*v1.Member{
{
Address: "addr1",
Weight: 500,
},
},
},
"config must be specified",
},
{
"member weight zero",
&v1.MsgInit{
Config: &v1.Config{
Threshold: 666,
Quorum: 400,
VotingPeriod: 60,
},
Members: []*v1.Member{
{
Address: "addr1",
Weight: 0,
},
},
},
"member weight must be greater than zero",
},
{
"threshold is zero",
&v1.MsgInit{
Config: &v1.Config{
Threshold: 0,
Quorum: 400,
VotingPeriod: 60,
},
Members: []*v1.Member{
{
Address: "addr1",
Weight: 500,
},
},
},
"threshold, quorum and voting period must be greater than zero",
},
{
"threshold greater than total weight",
&v1.MsgInit{
Config: &v1.Config{
Threshold: 2000,
Quorum: 400,
VotingPeriod: 60,
},
Members: []*v1.Member{
{
Address: "addr1",
Weight: 500,
},
{
Address: "addr2",
Weight: 1000,
},
},
},
"threshold must be less than or equal to the total weight",
},
{
"quorum greater than total weight",
&v1.MsgInit{
Config: &v1.Config{
Threshold: 666,
Quorum: 2000,
VotingPeriod: 60,
},
Members: []*v1.Member{
{
Address: "addr1",
Weight: 500,
},
{
Address: "addr2",
Weight: 1000,
},
},
},
"quorum must be less than or equal to the total weight",
},
}

for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
_, err := acc.Init(ctx, tc.msg)
if tc.expErr != "" {
require.EqualError(t, err, tc.expErr)
return
}
require.NoError(t, err)
})
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The TestInit function is well-structured and covers a wide range of scenarios. Consider adding a test case for a null MsgInit to ensure robust error handling.

@sontrinh16
Copy link
Member

hmmmm do we need to keep the proposal and votes after proposal being executed

@facundomedica
Copy link
Member Author

hmmmm do we need to keep the proposal and votes after proposal being executed

Sounds good, I can remove votes given that we are producing events for them. And I guess we can say the same about the proposal? So we'll rely on an indexer to keep these


// set members
totalWeight := uint64(0)
for i := range msg.Members {
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose we'd need to check that a member does not appear twice

Copy link
Contributor

@testinginprod testinginprod left a comment

Choose a reason for hiding this comment

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

LGTM, only thing I'm not a fan of is the SetSender API leaking for tests only.

I think we should generally study around a better x/accounts test-suite.

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.

the main thing is lazy tallying instead of tallying all at the end. we go this in gov and it runs into issues when member count gets too big

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

Out of diff range and nitpick comments (1)
x/accounts/defaults/multisig/README.md (1)

1-1: Correct the spelling mistake in the document title.

Comment on lines +9 to +13
* [MsgInit](#msginit)
* [MsgUpdateConfig](#msgupdateconfig)
* [MsgCreateProposal](#msgcreateproposal)
* [MsgVote](#msgvote)
* [MsgExecuteProposal](#msgexecuteproposal)
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation of list items is inconsistent with Markdown standards.

-    * [MsgInit](#msginit)
-    * [MsgUpdateConfig](#msgupdateconfig)
-    * [MsgCreateProposal](#msgcreateproposal)
-    * [MsgVote](#msgvote)
-    * [MsgExecuteProposal](#msgexecuteproposal)
+  * [MsgInit](#msginit)
+  * [MsgUpdateConfig](#msgupdateconfig)
+  * [MsgCreateProposal](#msgcreateproposal)
+  * [MsgVote](#msgvote)
+  * [MsgExecuteProposal](#msgexecuteproposal)

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.

Suggested change
* [MsgInit](#msginit)
* [MsgUpdateConfig](#msgupdateconfig)
* [MsgCreateProposal](#msgcreateproposal)
* [MsgVote](#msgvote)
* [MsgExecuteProposal](#msgexecuteproposal)
* [MsgInit](#msginit)
* [MsgUpdateConfig](#msgupdateconfig)
* [MsgCreateProposal](#msgcreateproposal)
* [MsgVote](#msgvote)
* [MsgExecuteProposal](#msgexecuteproposal)

Comment on lines +23 to +33
Members collections.Map[[]byte, uint64]
Sequence collections.Sequence
Config collections.Item[v1.Config]

addrCodec address.Codec
headerService header.Service
eventService event.Service

Proposals collections.Map[uint64, v1.Proposal]
Votes collections.Map[collections.Pair[uint64, []byte], int32] // key: proposalID + voter address
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace hard tabs with spaces to maintain consistency in indentation.

-	Members  collections.Map[[]byte, uint64]
-	Sequence collections.Sequence
-	Config   collections.Item[v1.Config]
-	addrCodec     address.Codec
-	headerService header.Service
-	eventService  event.Service
-	Proposals collections.Map[uint64, v1.Proposal]
-	Votes     collections.Map[collections.Pair[uint64, []byte], int32] // key: proposalID + voter address
+  Members  collections.Map[[]byte, uint64]
+  Sequence collections.Sequence
+  Config   collections.Item[v1.Config]
+  addrCodec     address.Codec
+  headerService header.Service
+  eventService  event.Service
+  Proposals collections.Map[uint64, v1.Proposal]
+  Votes     collections.Map[collections.Pair[uint64, []byte], int32] // key: proposalID + voter address

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.

Suggested change
Members collections.Map[[]byte, uint64]
Sequence collections.Sequence
Config collections.Item[v1.Config]
addrCodec address.Codec
headerService header.Service
eventService event.Service
Proposals collections.Map[uint64, v1.Proposal]
Votes collections.Map[collections.Pair[uint64, []byte], int32] // key: proposalID + voter address
}
Members collections.Map[[]byte, uint64]
Sequence collections.Sequence
Config collections.Item[v1.Config]
addrCodec address.Codec
headerService header.Service
eventService event.Service
Proposals collections.Map[uint64, v1.Proposal]
Votes collections.Map[collections.Pair[uint64, []byte], int32] // key: proposalID + voter address


### Config

The config contains the basic rules defining how the multisig will work. All of these fields can be modified afterwards by calling [MsgUpdateConfig](#msgupdateconfig).
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using "afterward" instead of "afterwards" to align with American English conventions.

- All of these fields can be modified afterwards by calling [MsgUpdateConfig](#msgupdateconfig).
+ All of these fields can be modified afterward by calling [MsgUpdateConfig](#msgupdateconfig).

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.

Suggested change
The config contains the basic rules defining how the multisig will work. All of these fields can be modified afterwards by calling [MsgUpdateConfig](#msgupdateconfig).
The config contains the basic rules defining how the multisig will work. All of these fields can be modified afterward by calling [MsgUpdateConfig](#msgupdateconfig).


### Proposal

The proposal contains the title, summary, messages and the status of the proposal. The messages are stored as `google.protobuf.Any` to allow for any type of message to be stored.
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a space after the period for better readability.

- The proposal contains the title, summary, messages and the status of the proposal. The messages are stored as `google.protobuf.Any` to allow for any type of message to be stored.
+ The proposal contains the title, summary, messages and the status of the proposal. The messages are stored as `google.protobuf.Any` to allow for any type of message to be stored.

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.

Suggested change
The proposal contains the title, summary, messages and the status of the proposal. The messages are stored as `google.protobuf.Any` to allow for any type of message to be stored.
The proposal contains the title, summary, messages and the status of the proposal. The messages are stored as `google.protobuf.Any` to allow for any type of message to be stored.

message MsgExecuteProposal {
uint64 proposal_id = 1;
}
```
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure the file ends with a single newline character.

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.

missing go docs on the functions otherwise utACK

return &v1.MsgVoteResponse{}, a.Votes.Set(ctx, collections.Join(msg.ProposalId, sender), int32(msg.Vote))
}

func (a Account) CreateProposal(ctx context.Context, msg *v1.MsgCreateProposal) (*v1.MsgCreateProposalResponse, error) {
Copy link
Member

Choose a reason for hiding this comment

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

can we add go docs to all these functions

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

Out of diff range and nitpick comments (1)
x/accounts/CHANGELOG.md (1)

30-30: Ensure the file ends with a single newline character.

Please add a newline at the end of the file to adhere to POSIX standards and ensure compatibility with various tools and systems.

### Features

* [#19988](https://github.com/cosmos/cosmos-sdk/pull/19988) Implemented `x/accounts/multisig`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct the markdown link syntax.

- * [#19988](https://github.com/cosmos/cosmos-sdk/pull/19988) Implemented `x/accounts/multisig`.
+ * [[#19988](https://github.com/cosmos/cosmos-sdk/pull/19988)] Implemented `x/accounts/multisig`.

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.

Suggested change
* [#19988](https://github.com/cosmos/cosmos-sdk/pull/19988) Implemented `x/accounts/multisig`.
* [[#19988](https://github.com/cosmos/cosmos-sdk/pull/19988)] Implemented `x/accounts/multisig`.

@facundomedica facundomedica added this pull request to the merge queue May 6, 2024
Merged via the queue into main with commit f8b18f1 May 6, 2024
65 checks passed
@facundomedica facundomedica deleted the facu/accmultisig branch May 6, 2024 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: onchain multisig
5 participants