-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Changes from 22 commits
8200ab3
69a489d
122e733
4cf132d
b17c74e
5aeec6b
81637da
016a885
b6ea844
d60edd9
ae845ba
e3bc77f
b1485f8
063f02b
7fc4ddb
12ad1f9
d10a259
daaf91b
736d39a
d4997af
27d2eb3
c04d07f
2366d2c
7f469d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -278,6 +278,12 @@ There are three parameters that define if the deposit of a proposal should be bu | |||||
|
||||||
> Note: These parameters are modifiable via governance. | ||||||
|
||||||
#### Execution | ||||||
|
||||||
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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
ToolsLanguageTool
|
||||||
|
||||||
## State | ||||||
|
||||||
### Constitution | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ import ( | |
|
||
"github.com/cosmos/cosmos-sdk/telemetry" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
// EndBlocker is called every block. | ||
|
@@ -35,6 +36,11 @@ func (k Keeper) EndBlocker(ctx context.Context) error { | |
return err | ||
} | ||
|
||
params, err := k.Params.Get(ctx) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, prop := range inactiveProps { | ||
proposal, err := k.Proposals.Get(ctx, prop.Key.K2()) | ||
if err != nil { | ||
|
@@ -61,10 +67,6 @@ func (k Keeper) EndBlocker(ctx context.Context) error { | |
return err | ||
} | ||
|
||
params, err := k.Params.Get(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
if !params.BurnProposalDepositPrevote { | ||
err = k.RefundAndDeleteDeposits(ctx, proposal.Id) // refund deposit if proposal got removed without getting 100% of the proposal | ||
} else { | ||
|
@@ -77,7 +79,7 @@ func (k Keeper) EndBlocker(ctx context.Context) error { | |
|
||
// called when proposal become inactive | ||
// call hook when proposal become inactive | ||
if err := k.BranchService.Execute(ctx, func(ctx context.Context) error { | ||
if err = k.BranchService.Execute(ctx, func(ctx context.Context) error { | ||
return k.Hooks().AfterProposalFailedMinDeposit(ctx, proposal.Id) | ||
}); err != nil { | ||
// purposely ignoring the error here not to halt the chain if the hook fails | ||
|
@@ -193,16 +195,10 @@ 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 { | ||
_, 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 | ||
} | ||
} | ||
|
@@ -212,7 +208,21 @@ func (k Keeper) EndBlocker(ctx context.Context) error { | |
logMsg = "passed" | ||
|
||
return nil | ||
}); err != nil { | ||
}) | ||
if err != nil { | ||
// update proposal if error is out of gas | ||
if errors.Is(err, sdkerrors.ErrOutOfGas) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. problem is branch service implementation of stf doesn't return this error There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, we can just remove this https://github.com/cosmos/cosmos-sdk/pull/20348/files/12ad1f9e4f4600950f089e358215d5fc68bcae6d#diff-4bb7b38066b637ade8ae58c5d5bf4050e08f2af0f89aa791baee39cb008187b9R206-R212 (but store the proposal idx), and handle for all error here instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this solved? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think so yet There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pushed what i think you mean, not sure where to store the proposal idx There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to remove L214-L219 and make the error log more generic (as it can be out of gas or proposal execution error (at handling)). As it is only used in the log, let's skip it? |
||
proposal.Status = v1.StatusFailed | ||
proposal.FailedReason = err.Error() | ||
tagValue = types.AttributeValueProposalFailed | ||
logMsg = "passed proposal failed due to out of gas" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a break missing or this is overwritten in L224. Is there a way for people to find out the required gas amount? If the original error msg contains this information it feels like the better choice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That whole if condition above should be removed (L214-L219) |
||
} | ||
// `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) | ||
|
||
break // We do not anything with the error. Returning an error halts the chain, and proposal struct is already updated. | ||
} | ||
case !burnDeposits && (proposal.ProposalType == v1.ProposalType_PROPOSAL_TYPE_EXPEDITED || | ||
|
@@ -222,10 +232,6 @@ func (k Keeper) EndBlocker(ctx context.Context) error { | |
// once the regular voting period expires again, the tally is repeated | ||
// according to the regular proposal rules. | ||
proposal.ProposalType = v1.ProposalType_PROPOSAL_TYPE_STANDARD | ||
params, err := k.Params.Get(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
endTime := proposal.VotingStartTime.Add(*params.VotingPeriod) | ||
proposal.VotingEndTime = &endTime | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ import ( | |
|
||
var votingPeriodProposalKeyPrefix = collections.NewPrefix(4) // VotingPeriodProposalKeyPrefix stores which proposals are on voting period. | ||
|
||
// MigrateStore performs in-place store migrations from v5 (v0.50) to v6 (v0.51). The | ||
// MigrateStore performs in-place store migrations from v5 (v0.50) to v6 (v0.52). The | ||
// migration includes: | ||
// | ||
// Addition of new field in params to store types of proposals that can be submitted. | ||
|
@@ -56,6 +56,7 @@ func MigrateStore(ctx context.Context, storeService corestoretypes.KVStoreServic | |
govParams.OptimisticAuthorizedAddresses = defaultParams.OptimisticAuthorizedAddresses | ||
govParams.OptimisticRejectedThreshold = defaultParams.OptimisticRejectedThreshold | ||
govParams.ProposalCancelMaxPeriod = defaultParams.ProposalCancelMaxPeriod | ||
govParams.ProposalExecutionGas = defaultParams.ProposalExecutionGas | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
return paramsCollection.Set(ctx, govParams) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comma for better readability.
Committable suggestion
Tools
LanguageTool
Correct the pluralization for grammatical accuracy.
Committable suggestion
Tools
LanguageTool
Refine the changelog entry for better clarity and correctness.
Committable suggestion
Tools
LanguageTool