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(x/gov): limit execution in gov #20348

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Conversation

tac0turtle
Copy link
Member

@tac0turtle tac0turtle commented May 10, 2024

Description

limit execution of gov proposals to infinite messages.


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

  • New Features

    • Introduced a maximum gas limit for executing governance proposals, adjustable via parameters.
  • Bug Fixes

    • Improved error handling and context usage during proposal execution, including handling out-of-gas errors.
  • Chores

    • Updated project dependencies, adding cosmossdk.io/x/bank and updating versions for cosmossdk.io/log and github.com/hashicorp/golang-lru/v2.
  • Refactor

    • Enhanced migration logic to include ProposalExecutionGas in governance parameters.
  • Documentation

    • Updated CHANGELOG to reflect the new governance proposal gas limit feature.

Copy link
Contributor

coderabbitai bot commented May 10, 2024

Walkthrough

Walkthrough

This update introduces a new requirement for the cosmossdk.io/x/bank module, updates dependencies, and enhances the governance module (x/gov). Key changes include setting a maximum gas limit for governance proposal execution, updating error handling in the EndBlocker function, and adding a new proposal_execution_gas field to the governance parameters. These changes improve the robustness and configurability of the governance process.

Changes

File Path Change Summary
x/accounts/go.mod Added cosmossdk.io/x/bank dependency and updated versions for log and golang-lru.
x/gov/CHANGELOG.md Documented the addition of a maximum gas limit for governance proposal execution.
x/gov/keeper/abci.go Improved error handling and context usage in EndBlocker function, including out-of-gas scenarios.
x/gov/migrations/v6/store.go Updated MigrateStore to include ProposalExecutionGas in govParams.
x/gov/proto/cosmos/gov/v1/gov.proto Added proposal_execution_gas field to Params message.
x/gov/simulation/genesis.go Added 10_000_000 integer value in RandomizedGenState function initialization.
x/gov/types/v1/params.go Added DefaultProposalExecutionGas constant and modified NewParams function to include proposalExecutionGas.

Sequence Diagrams

sequenceDiagram
    participant User
    participant GovernanceModule
    participant Proposal
    participant Context

    User->>GovernanceModule: Submit Proposal
    GovernanceModule->>Proposal: Validate Proposal
    Proposal->>GovernanceModule: Proposal Validated
    GovernanceModule->>Context: Execute Proposal
    Context-->>GovernanceModule: Out-of-Gas Error
    GovernanceModule->>User: Proposal Execution Failed
sequenceDiagram
    participant Developer
    participant MigrationScript
    participant GovernanceModule

    Developer->>MigrationScript: Run Migration to v6
    MigrationScript->>GovernanceModule: Add ProposalExecutionGas to govParams
    GovernanceModule->>MigrationScript: Migration Successful
    MigrationScript->>Developer: Migration Completed

Warning

Review ran into problems

Problems (1)
  • Git: Failed to clone repository. Please contact CodeRabbit support.

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

x/gov/keeper/abci.go Fixed Show fixed Hide fixed
x/gov/keeper/abci.go Outdated Show resolved Hide resolved
x/gov/README.md Outdated

Execution is the process of executing the messages contained in a proposal. The execution phase will commence after the proposal has been accepted by the network. The messages contained in the proposal will be executed in the order they were submitted.

Execution has a upper limit on how many messages can be executed in a single block. This limit is defined by the `MaxMessagesPerProposal` parameter. We use the MaxBlockGas from the consensus engine, value stored in the consensus module, to calculate the limit of messages that can be executed in a block.
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need a MaxMessagesPerProposal if we already have that block gas limit?

x/gov/keeper/abci.go Outdated Show resolved Hide resolved
x/gov/keeper/abci.go Fixed Show fixed Hide fixed
x/gov/keeper/abci.go Fixed Show fixed Hide fixed
x/gov/keeper/abci.go Fixed Show fixed Hide fixed
Comment on lines 201 to 220
_, err = k.BranchService.ExecuteWithGasLimit(ctx, params.ProposalExecutionGas, func(ctx context.Context) error {
// execute all messages
for idx, msg = range messages {
if _, err := safeExecuteHandler(ctx, msg, k.MsgRouterService); err != nil {
// `idx` and `err` are populated with the msg index and error.
proposal.Status = v1.StatusFailed
proposal.FailedReason = err.Error()
tagValue = types.AttributeValueProposalFailed
logMsg = fmt.Sprintf("passed, but msg %d (%s) failed on execution: %s", idx, sdk.MsgTypeURL(msg), err)

return err
}
}

proposal.Status = v1.StatusPassed
tagValue = types.AttributeValueProposalPassed
logMsg = "passed"

return nil
}); err != nil {
})

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
@tac0turtle tac0turtle marked this pull request as ready for review June 3, 2024 08:34
@tac0turtle tac0turtle requested a review from a team as a code owner June 3, 2024 08:34
Copy link
Contributor

github-actions bot commented Jun 3, 2024

@tac0turtle your pull request is missing a changelog!

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

Outside diff range and nitpick comments (7)
x/gov/README.md (7)

Line range hint 26-26: Add a period after "a.k.a" for correct abbreviation usage.

- This module is in use on the Cosmos Hub (a.k.a [gaia](https://github.com/cosmos/gaia)).
+ This module is in use on the Cosmos Hub (a.k.a. [gaia](https://github.com/cosmos/gaia)).
Tools
LanguageTool

[misspelling] ~285-~285: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...der they were submitted. Execution has a upper limit on how much gas can be cons...


Line range hint 94-94: Replace "ie." with "i.e." to correct the abbreviation usage.

- Messages without authority are message meant to be executed by users. Using the `MsgSudoExec` message in a proposal, let governance can execute any message, effectively acting as super user.
+ Messages without authority are message meant to be executed by users. Using the `MsgSudoExec` message in a proposal, let governance can execute any message, effectively acting as super user (i.e., no authority present).
Tools
LanguageTool

[misspelling] ~285-~285: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...der they were submitted. Execution has a upper limit on how much gas can be cons...


Line range hint 95-95: Change "super user" to "superuser" for correct terminology.

- Messages without authority are message meant to be executed by users. Using the `MsgSudoExec` message in a proposal, let governance can execute any message, effectively acting as super user.
+ Messages without authority are message meant to be executed by users. Using the `MsgSudoExec` message in a proposal, let governance can execute any message, effectively acting as superuser.
Tools
LanguageTool

[misspelling] ~285-~285: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...der they were submitted. Execution has a upper limit on how much gas can be cons...


Line range hint 103-103: Change "accompanied with" to "accompanied by" for correct preposition usage.

- When a proposal is submitted, it has to be accompanied with a deposit that must be strictly positive...
+ When a proposal is submitted, it has to be accompanied by a deposit that must be strictly positive...
Tools
LanguageTool

[misspelling] ~285-~285: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...der they were submitted. Execution has a upper limit on how much gas can be cons...


Line range hint 110-110: Add "the" before "state" for correct article usage.

- ...the proposal will be removed from state and the deposit will be burned...
+ ...the proposal will be removed from the state and the deposit will be burned...
Tools
LanguageTool

[misspelling] ~285-~285: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...der they were submitted. Execution has a upper limit on how much gas can be cons...


Line range hint 136-136: Replace "that" with "who" when referring to people for correct pronoun usage.

- *Participants* are users that have the right to vote on proposals.
+ *Participants* are users who have the right to vote on proposals.
Tools
LanguageTool

[misspelling] ~285-~285: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...der they were submitted. Execution has a upper limit on how much gas can be cons...


Line range hint 172-172: Add a comma after "No" for better readability.

- Often times the entity owning that address might not be a single individual. For example, a company might have different stakeholders who want to vote differently, and so it makes sense to allow them to split their voting power. Currently, it is not possible for them to do "passthrough voting" and giving their users voting rights over their tokens. However, with this system, exchanges can poll their users for voting preferences, and then vote on-chain proportionally to the results of the poll.
+ Often times the entity owning that address might not be a single individual. For example, a company might have different stakeholders who want to vote differently, and so it makes sense to allow them to split their voting power. Currently, it is not possible for them to do "passthrough voting" and giving their users voting rights over their tokens. However, with this system, exchanges can poll their users for voting preferences, and then vote on-chain proportionally to the results of the poll. Often times the entity owning that address might not be a single individual. For example, a company might have different stakeholders who want to vote differently, and so it makes sense to allow them to split their voting power. Currently, it is not possible for them to do "passthrough voting" and giving their users voting rights over their tokens. However, with this system, exchanges can poll their users for voting preferences, and then vote on-chain proportionally to the results of the poll.
Tools
LanguageTool

[misspelling] ~285-~285: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...der they were submitted. Execution has a upper limit on how much gas can be cons...

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 61da5d1 and 7fc4ddb.

Files ignored due to path filters (2)
  • x/gov/go.mod is excluded by !**/*.mod
  • x/gov/types/v1/gov.pb.go is excluded by !**/*.pb.go
Files selected for processing (7)
  • api/cosmos/gov/v1/gov.pulsar.go (16 hunks)
  • x/gov/README.md (1 hunks)
  • x/gov/keeper/abci.go (3 hunks)
  • x/gov/migrations/v6/store.go (2 hunks)
  • x/gov/proto/cosmos/gov/v1/gov.proto (2 hunks)
  • x/gov/simulation/genesis.go (1 hunks)
  • x/gov/types/v1/params.go (4 hunks)
Files not summarized due to errors (1)
  • api/cosmos/gov/v1/gov.pulsar.go: Error: Message exceeds token limit
Additional context used
Path-based instructions (6)
x/gov/migrations/v6/store.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/gov/simulation/genesis.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

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

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

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

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/gov/README.md (1)

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

api/cosmos/gov/v1/gov.pulsar.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

LanguageTool
x/gov/README.md

[uncategorized] ~26-~26: The abbreviation/initialism is missing a period after the last letter.
Context: ...his module is in use on the Cosmos Hub (a.k.a gaia)...


[grammar] ~87-~87: Possible subject-verb agreement error detected.
Context: ...self. Modules such as x/upgrade, that want to allow certain messages to be execute...


[style] ~94-~94: As a shorter alternative for ‘able to’, consider using “can”.
Context: ...eck. :::warning Ultimately, governance is able to execute any proposal, even if they were...


[uncategorized] ~94-~94: The abbreviation “i.e.” (= that is) requires two periods.
Context: ...n't meant to be executed by governance (ie. no authority present). Messages without...


[grammar] ~95-~95: This is normally spelled as one word.
Context: ...cute any message, effectively acting as super user. ::: ### Deposit To prevent spam, pro...


[grammar] ~103-~103: The usual collocation for “accompany” is “by”, not “with”.
Context: ...n a proposal is submitted, it has to be accompanied with a deposit that must be strictly positiv...


[uncategorized] ~110-~110: Possible missing article found.
Context: ...oyed: the proposal will be removed from state and the deposit will be burned (see x/g...


[style] ~136-~136: Consider using “who” when you are referring to people instead of objects.
Context: ... Participants Participants are users that have the right to vote on proposals. On...


[uncategorized] ~172-~172: Possible missing comma found.
Context: ... of its voting power to vote No. Often times the entity owning that address might no...


[typographical] ~198-~198: It seems that a comma is missing.
Context: ...oposal for the result to be valid. ### Yes Quorum Yes quorum is a more restrictiv...


[typographical] ~199-~199: It seems that a comma is missing.
Context: ...he result to be valid. ### Yes Quorum Yes quorum is a more restrictive quorum tha...


[style] ~201-~201: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...minimum percentage of voting power that needs to have voted Yes for the proposal to pa...


[style] ~277-~277: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ... quorum. * BurnProposalDepositPrevote burns the proposal deposit if it does not ent...


[misspelling] ~285-~285: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...der they were submitted. Execution has a upper limit on how much gas can be cons...


[uncategorized] ~304-~304: When specifying a month and year, the comma is unnecessary.
Context: ...validators do? * Terra crash of May, 2022, saw validators choose to run a new bin...


[formatting] ~304-~304: If the ‘because’ clause is essential to the meaning, do not use a comma before the clause.
Context: ...that had not been approved by governance, because the governance token had been inflated ...


[style] ~310-~310: Consider shortening this phrase to strengthen your wording.
Context: ...by governance. Communities whishing to make amendments to their original constitution should use ...


[style] ~320-~320: Consider using “arise” to strengthen your wording.
Context: ...nesis, so that when difficult questions come up, the constutituon can provide guidance ...


[typographical] ~339-~339: The word “however” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence.
Context: ...ta` field allows custom use for networks, however, it is expected that the field contains ...


[grammar] ~357-~357: The verb form ‘are’ does not appear to fit in this context.
Context: ...keeper as a config. The default maximum length are: for the title 255 characters, for the ...


[misspelling] ~357-~357: Make sure that ‘the one of’ is correct and that ‘one’ is a pronoun. Possibly, the ‘the’ is unnecessary or ‘of’ is better expressed with a preposition such as ‘about’ or ‘in’.
Context: ... for summary 10200 characters (40 times the one of the title). #### Writing a module that...


[style] ~362-~362: As an alternative to the over-used intensifier ‘very’, consider replacing this phrase.
Context: ...as changing various parameters. This is very simple to do. First, write out your message ty...


[uncategorized] ~378-~378: Use a comma before “and” if it connects two independent clauses (unless they are closely connected and short).
Context: ...d, a new parameter set has to be created and the previous one rendered inactive. ##...


[grammar] ~445-~445: Did you mean “querying”? Or maybe you should add a pronoun? In active voice, ‘allow’ + ‘to’ takes an object, usually a pronoun.
Context: ...|'Params'toParams`. This map allows to query all x/gov params. For pseudocode p...


[uncategorized] ~450-~450: Loose punctuation mark.
Context: ...rite in stores: * load(StoreKey, Key): Retrieve item stored at key Key in st...


[uncategorized] ~457-~457: Loose punctuation mark.
Context: ... Store: * ProposalProcessingQueue: A queue queue[proposalID] containing ...


[grammar] ~472-~472: Did you mean “submitting”? Or maybe you should add a pronoun? In active voice, ‘allow’ + ‘to’ takes an object, usually a pronoun.
Context: ... any messages, a legacy proposal allows to submit a set of pre-defined proposals. These p...


[uncategorized] ~509-~509: The preposition ‘to’ seems more likely in this position.
Context: ...itis reached: * PushproposalIDinProposalProcessingQueue* TransferI...


[grammar] ~521-~521: Consider using either the past participle “conformed” or the present participle “conforming” here.
Context: ...voting period * The deposited coins are conform to the accepted denom from the `MinDepo...


[style] ~539-~539: As a shorter alternative for ‘able to’, consider using “can”.
Context: ...starts. From there, bonded Atom holders are able to send MsgVote transactions to cast the...


[style] ~551-~551: ‘take into account’ might be wordy. Consider a shorter alternative.
Context: ...::note Gas cost for this message has to take into account the future tallying of the vote in EndB...


[typographical] ~638-~638: Two consecutive dots
Context: ... | string (address) | "cosmos1.." or empty for burn | | propos...


[uncategorized] ~643-~643: Possible missing comma found.
Context: ...nce module contains parameters that are objects unlike other modules. If only a subset ...


[grammar] ~644-~644: Make sure the noun ‘subset’ is in agreement with the verb ‘are’. Beware that some collective nouns (like ‘police’ or ‘team’) can be treated as both singular and plural.
Context: ...modules. If only a subset of parameters are desired to be changed, only they need t...


[uncategorized] ~647-~647: This expression is usually spelled with a hyphen.
Context: ...entire parameter object structure. ### Message Based Parameters In addition to the paramete...


[uncategorized] ~2465-~2465: Did you mean: “By default,”?
Context: ...t the on-chain actions they are taking. By default all metadata fields have a 255 characte...


[style] ~2465-~2465: As an alternative to the over-used intensifier ‘quite’, consider replacing this phrase.
Context: ... of proposals made by all groups may be quite large. Second, that client applications such ...


[grammar] ~2489-~2489: When ‘255-character’ is used as a modifier, it is usually spelled with a hyphen.
Context: ...Vote Location: on-chain as json within 255 character limit (mirrors [group vote](../group/RE...

Markdownlint
x/gov/README.md

36-36: Expected: 2; Actual: 4
Unordered list indentation


37-37: Expected: 2; Actual: 4
Unordered list indentation


38-38: Expected: 2; Actual: 4
Unordered list indentation


40-40: Expected: 2; Actual: 4
Unordered list indentation


41-41: Expected: 2; Actual: 4
Unordered list indentation


42-42: Expected: 2; Actual: 4
Unordered list indentation


43-43: Expected: 2; Actual: 4
Unordered list indentation


44-44: Expected: 2; Actual: 4
Unordered list indentation


45-45: Expected: 2; Actual: 4
Unordered list indentation


46-46: Expected: 2; Actual: 4
Unordered list indentation


48-48: Expected: 2; Actual: 4
Unordered list indentation


49-49: Expected: 2; Actual: 4
Unordered list indentation


50-50: Expected: 2; Actual: 4
Unordered list indentation


52-52: Expected: 2; Actual: 4
Unordered list indentation


53-53: Expected: 2; Actual: 4
Unordered list indentation


56-56: Expected: 2; Actual: 4
Unordered list indentation


57-57: Expected: 2; Actual: 4
Unordered list indentation


58-58: Expected: 2; Actual: 4
Unordered list indentation


60-60: Expected: 2; Actual: 4
Unordered list indentation


61-61: Expected: 2; Actual: 4
Unordered list indentation


301-301: Expected: 2; Actual: 4
Unordered list indentation


302-302: Expected: 2; Actual: 4
Unordered list indentation


303-303: Expected: 2; Actual: 4
Unordered list indentation


304-304: Expected: 4; Actual: 8
Unordered list indentation


306-306: Expected: 2; Actual: 4
Unordered list indentation


509-509: Expected: 2; Actual: 4
Unordered list indentation


533-533: Expected: 2; Actual: 4
Unordered list indentation


312-312: null
Emphasis used instead of a heading


27-27: null
Link fragments should be valid


62-62: null
Link fragments should be valid

Additional comments not posted (24)
x/gov/migrations/v6/store.go (1)

59-59: The addition of ProposalExecutionGas to govParams aligns with the PR's objectives to manage gas consumption effectively. Ensure that all related components that utilize govParams are aware of this new field.

x/gov/simulation/genesis.go (1)

197-197: The inclusion of 10_000_000 as a parameter in the RandomizedGenState function aligns with the new ProposalExecutionGas parameter, ensuring consistency in simulation environments.

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

80-80: The updated error handling in the EndBlocker function for out-of-gas errors enhances the robustness of proposal execution. This is a critical update for maintaining system stability.


Line range hint 196-227: The implementation of ExecuteWithGasLimit within the EndBlocker function is a significant enhancement. It ensures that proposal execution respects the newly introduced gas limits, aligning with the PR's objectives.

x/gov/types/v1/params.go (2)

51-51: The addition of proposalExecutionGas to the NewParams function ensures that all new parameter instances will include the new gas limit setting, which is crucial for the governance module's operation.


103-103: Setting DefaultProposalExecutionGas in the DefaultParams function ensures that the default settings are aligned with the new governance requirements regarding gas consumption.

x/gov/proto/cosmos/gov/v1/gov.proto (1)

347-347: The addition of the proposal_execution_gas field to the Params message is well-integrated and aligns with the PR's objectives to manage gas consumption in governance proposals.

x/gov/README.md (1)

281-286: The addition of the ProposalExecutionGas parameter is well-explained and aligns with the PR's objectives to limit gas consumption during proposal execution.

Tools
LanguageTool

[misspelling] ~285-~285: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...der they were submitted. Execution has a upper limit on how much gas can be cons...

api/cosmos/gov/v1/gov.pulsar.go (16)

6648-6648: Field descriptor for proposal_execution_gas correctly added.


6675-6675: Initialization of proposal_execution_gas field descriptor is correct.


6869-6874: Handling of ProposalExecutionGas in conditional block is implemented correctly.


6932-6933: Case for proposal_execution_gas correctly added to switch statement.


6992-6993: Case for resetting proposal_execution_gas correctly added to switch statement.


7082-7084: Case for retrieving proposal_execution_gas value correctly added to switch statement.


7153-7154: Case for setting proposal_execution_gas correctly added to switch statement.


7238-7239: Case for handling immutability of proposal_execution_gas correctly added to switch statement.


7301-7302: Case for default value of proposal_execution_gas correctly added to switch statement.


7459-7461: Handling for size calculation of proposal_execution_gas implemented correctly.


7491-7497: Handling for encoding proposal_execution_gas implemented correctly.


8408-8426: Error handling for incorrect wire type of proposal_execution_gas during unmarshalling is implemented correctly.


10137-10138: ProposalExecutionGas field correctly added to the Params message.


10308-10313: Getter method for ProposalExecutionGas correctly implemented.


10572-10572: Binary encoding for ProposalExecutionGas appears to be handled correctly.


10674-10749: Binary encoding for ProposalExecutionGas appears to be handled correctly.


Execution is the process of executing the messages contained in a proposal. The execution phase will commence after the proposal has been accepted by the network. The messages contained in the proposal will be executed in the order they were submitted.

Execution has a upper limit on how much gas can be consumed in a single block. This limit is defined by the `ProposalExecutionGas` parameter.
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 article usage for better grammatical accuracy.

- Execution has a upper limit on how much gas can be consumed in a single block.
+ Execution has an upper limit on how much gas can be consumed in a single block.
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
Execution has a upper limit on how much gas can be consumed in a single block. This limit is defined by the `ProposalExecutionGas` parameter.
Execution has an upper limit on how much gas can be consumed in a single block. This limit is defined by the `ProposalExecutionGas` parameter.
Tools
LanguageTool

[misspelling] ~285-~285: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...der they were submitted. Execution has a upper limit on how much gas can be cons...

@julienrbrt julienrbrt changed the title fix: limit execution in gov fix(x/gov): limit execution in gov Jun 3, 2024
@@ -193,7 +193,11 @@ func (k Keeper) EndBlocker(ctx context.Context) error {
// Messages may mutate state thus we use a cached context. If one of
// the handlers fails, no state mutation is written and the error
// message is logged.
if err := k.BranchService.Execute(ctx, func(ctx context.Context) error {
params, err := k.Params.Get(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

The params should already be there somewhere. I don't think we to get them again

})
if err != nil {
// update proposal if error is out of gas
if errors.Is(err, sdkerrors.ErrOutOfGas) {
Copy link
Member

Choose a reason for hiding this comment

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

problem is branch service implementation of stf doesn't return this error

Copy link
Member Author

Choose a reason for hiding this comment

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

should it be in all cases we set the proposal to fail? if not then we need to see how to make this work correctly

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Was this solved?

Copy link
Member

Choose a reason for hiding this comment

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

Don't think so yet

@@ -35,6 +36,11 @@
return err
}

params, err := k.Params.Get(ctx)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
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

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7fc4ddb and d4997af.

Files selected for processing (5)
  • x/accounts/go.mod (4 hunks)
  • x/gov/CHANGELOG.md (1 hunks)
  • x/gov/keeper/abci.go (7 hunks)
  • x/gov/proto/cosmos/gov/v1/gov.proto (2 hunks)
  • x/gov/types/v1/params.go (5 hunks)
Files skipped from review as they are similar to previous changes (3)
  • x/gov/keeper/abci.go
  • x/gov/proto/cosmos/gov/v1/gov.proto
  • x/gov/types/v1/params.go
Additional context used
Path-based instructions (1)
x/gov/CHANGELOG.md (1)

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

LanguageTool
x/gov/CHANGELOG.md

[grammar] ~42-~42: You should probably use “replicate”. (AGREEMENT_SENT_START)
Context: ...clude vote options counts. Those counts replicates the now deprecated (but not removed) ye...


[style] ~72-~72: Consider a shorter alternative to avoid wordiness. (IN_ORDER_TO_PREMIUM)
Context: ...` have been moved to the keeper package in order to support the custom tallying function. *...

Additional comments not posted (1)
x/accounts/go.mod (1)

10-10: Dependency updates are correct and match the specified versions.

Also applies to: 96-96

@@ -55,6 +55,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#18762](https://github.com/cosmos/cosmos-sdk/pull/18762) Add multiple choice proposals.
* [#18856](https://github.com/cosmos/cosmos-sdk/pull/18856) Add `ProposalCancelMaxPeriod` parameters.
* [#19167](https://github.com/cosmos/cosmos-sdk/pull/19167) Add `YesQuorum` parameter.
* [#20348](https://github.com/cosmos/cosmos-sdk/pull/20348) Limit gov exectution of proposals to a max gas limit. The limit was added to parameters and can be modified
Copy link
Contributor

Choose a reason for hiding this comment

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

Clarify the changelog entry for better understanding.

- * [#20348](https://github.com/cosmos/cosmos-sdk/pull/20348) Limit gov exectution of proposals to a max gas limit. The limit was added to parameters and can be modified
+ * [#20348](https://github.com/cosmos/cosmos-sdk/pull/20348) Introduce a configurable maximum gas limit for governance proposal execution, enhancing control over resource usage.
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
* [#20348](https://github.com/cosmos/cosmos-sdk/pull/20348) Limit gov exectution of proposals to a max gas limit. The limit was added to parameters and can be modified
* [#20348](https://github.com/cosmos/cosmos-sdk/pull/20348) Introduce a configurable maximum gas limit for governance proposal execution, enhancing control over resource usage.

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.

None yet

4 participants