Skip to content

Commit edd0f2f

Browse files
MSalopekmpoke
andauthored
feat!: add expedited propsals support (#3149)
* feat!: add expedited propsal antehandler * wip: add e2e testing * deps: add lsm ics version * test: sims, genesis, e2e expedite; export tool; upgrade handler * rm extra files * tests: nits * add some log lines to check test state * rm some log lines * set gov params in upgrade * make lint pass * wip: use cosmwasm fork with expedited props handling * chore: change wasmd version * chore: connect wasmd-lsm and ics-lsm * add changelog entries * chore: add changelogs from other PR * chore: update ignore file * chore: add cosmwasm changelogs * chore: bump ics to v4.3.0-lsm * chore: fix nits --------- Co-authored-by: mpoke <marius.poke@posteo.de>
1 parent 3def471 commit edd0f2f

27 files changed

+604
-32
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- Bump [interchain-security](https://github.com/cosmos/interchain-security) to
2+
[v4.3.0-lsm](https://github.com/cosmos/interchain-security/releases/tag/v4.3.0-lsm).
3+
([\#3149](https://github.com/cosmos/gaia/pull/3149))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Add the wasmd module.
2+
([\#3051](https://github.com/cosmos/gaia/pull/3051))

.changelog/unreleased/dependencies/3109-bump-ibc.md

-3
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- Bump [ibc-go](https://github.com/cosmos/ibc-go) to
2+
[v7.6.0](https://github.com/cosmos/ibc-go/releases/tag/v7.6.0)
3+
([\#3149](https://github.com/cosmos/gaia/pull/3149))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- Bump [cosmos-sdk](https://github.com/cosmos/cosmos-sdk) to
2+
[v0.47.16-ics-lsm](https://github.com/cosmos/cosmos-sdk/tree/v0.47.16-ics-lsm).
3+
This is a special cosmos-sdk branch with support for both ICS and LSM.
4+
([\#3149](https://github.com/cosmos/gaia/pull/3149))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Add the wasmd module.
2+
([\#3051](https://github.com/cosmos/gaia/pull/3051))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Add the wasmd module.
2+
([\#3051](https://github.com/cosmos/gaia/pull/3051))

.changelog/unreleased/state-breaking/3109-bump-ibc.md

-3
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- Bump [ibc-go](https://github.com/cosmos/ibc-go) to
2+
[v7.6.0](https://github.com/cosmos/ibc-go/releases/tag/v7.6.0)
3+
([\#3149](https://github.com/cosmos/gaia/pull/3149))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- Bump [interchain-security](https://github.com/cosmos/interchain-security) to
2+
[v4.3.0-lsm](https://github.com/cosmos/interchain-security/releases/tag/v4.3.0-lsm).
3+
([\#3149](https://github.com/cosmos/gaia/pull/3149))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- Bump [cosmos-sdk](https://github.com/cosmos/cosmos-sdk) to
2+
[v0.47.16-ics-lsm](https://github.com/cosmos/cosmos-sdk/tree/v0.47.16-ics-lsm).
3+
This is a special cosmos-sdk branch with support for both ICS and LSM.
4+
([\#3149](https://github.com/cosmos/gaia/pull/3149))

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ docs/tutorial
2020
dist
2121
tools-stamp
2222
docs/node_modules
23+
docs/versioned_docs
24+
docs/versioned_sidebars
2325

2426
# Data - ideally these don't exist
2527
baseapp/data/*

ante/ante.go

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
7373
ante.NewValidateMemoDecorator(opts.AccountKeeper),
7474
ante.NewConsumeGasForTxSizeDecorator(opts.AccountKeeper),
7575
NewGovVoteDecorator(opts.Codec, opts.StakingKeeper),
76+
NewGovExpeditedProposalsDecorator(opts.Codec),
7677
ante.NewSetPubKeyDecorator(opts.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
7778
ante.NewValidateSigCountDecorator(opts.AccountKeeper),
7879
ante.NewSigGasConsumeDecorator(opts.AccountKeeper, sigGasConsumer),

ante/gov_expedited_ante.go

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package ante
2+
3+
import (
4+
errorsmod "cosmossdk.io/errors"
5+
6+
"github.com/cosmos/cosmos-sdk/codec"
7+
sdk "github.com/cosmos/cosmos-sdk/types"
8+
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
9+
10+
gaiaerrors "github.com/cosmos/gaia/v18/types/errors"
11+
)
12+
13+
var expeditedPropDecoratorEnabled = true
14+
15+
// SetExpeditedProposalsEnabled toggles the expedited proposals decorator on/off.
16+
// Should only be used in testing - this is to allow simtests to pass.
17+
func SetExpeditedProposalsEnabled(val bool) {
18+
expeditedPropDecoratorEnabled = val
19+
}
20+
21+
var expeditedPropsWhitelist = map[string]struct{}{
22+
"/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade": {},
23+
"/cosmos.upgrade.v1beta1.MsgCancelUpgrade": {},
24+
// legacy proposals can still be submitted using govv1.MsgSubmitProposal
25+
"/cosmos.upgrade.v1beta1.SoftwareUpgradeProposal": {},
26+
"/cosmos.upgrade.v1beta1.CancelSoftwareUpgradeProposal": {},
27+
}
28+
29+
// Check if the proposal is whitelisted for expedited voting.
30+
type GovExpeditedProposalsDecorator struct {
31+
cdc codec.BinaryCodec
32+
}
33+
34+
func NewGovExpeditedProposalsDecorator(cdc codec.BinaryCodec) GovExpeditedProposalsDecorator {
35+
return GovExpeditedProposalsDecorator{
36+
cdc: cdc,
37+
}
38+
}
39+
40+
// AnteHandle checks if the proposal is whitelisted for expedited voting.
41+
// Only proposals submitted using "gaiad tx gov submit-proposal" can be expedited.
42+
// Legacy proposals submitted using "gaiad tx gov submit-legacy-proposal" cannot be marked as expedited.
43+
func (g GovExpeditedProposalsDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
44+
if expeditedPropDecoratorEnabled {
45+
for _, msg := range tx.GetMsgs() {
46+
prop, ok := msg.(*govv1.MsgSubmitProposal)
47+
if !ok {
48+
continue
49+
}
50+
if prop.Expedited {
51+
if err := g.validateExpeditedGovProp(prop); err != nil {
52+
return ctx, err
53+
}
54+
}
55+
}
56+
}
57+
return next(ctx, tx, simulate)
58+
}
59+
60+
func (g GovExpeditedProposalsDecorator) isWhitelisted(msgType string) bool {
61+
_, ok := expeditedPropsWhitelist[msgType]
62+
return ok
63+
}
64+
65+
func (g GovExpeditedProposalsDecorator) validateExpeditedGovProp(prop *govv1.MsgSubmitProposal) error {
66+
msgs := prop.GetMessages()
67+
if len(msgs) == 0 {
68+
return gaiaerrors.ErrInvalidExpeditedProposal
69+
}
70+
for _, message := range msgs {
71+
// in case of legacy content submitted using govv1.MsgSubmitProposal
72+
if sdkMsg, isLegacy := message.GetCachedValue().(*govv1.MsgExecLegacyContent); isLegacy {
73+
if !g.isWhitelisted(sdkMsg.Content.TypeUrl) {
74+
return errorsmod.Wrapf(gaiaerrors.ErrInvalidExpeditedProposal, "invalid Msg type: %s", sdkMsg.Content.TypeUrl)
75+
}
76+
continue
77+
}
78+
if !g.isWhitelisted(message.TypeUrl) {
79+
return errorsmod.Wrapf(gaiaerrors.ErrInvalidExpeditedProposal, "invalid Msg type: %s", message.TypeUrl)
80+
}
81+
}
82+
return nil
83+
}

0 commit comments

Comments
 (0)