-
Notifications
You must be signed in to change notification settings - Fork 251
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: re-add support for gov v1beta1 messages #725
Conversation
err = proposal.UnpackInterfaces(m.cdc) | ||
if err != nil { | ||
return fmt.Errorf("error while unpacking proposal interfaces: %s", err) | ||
} |
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.
Using codec to unpack Any type messages to the underlying structure, then we can get proposal message by proposal.Messages without error.
// handleMsgSubmitProposal allows to properly handle a MsgSubmitProposal | ||
func (m *Module) handleMsgSubmitProposal(tx *juno.Tx, index int, msg *govtypesv1.MsgSubmitProposal) error { | ||
// handleSubmitProposalEvent allows to properly handle a handleSubmitProposalEvent | ||
func (m *Module) handleSubmitProposalEvent(tx *juno.Tx, proposer string, events sdk.StringEvents) error { |
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.
V1beta1 and V1 messages are sharing the same event, so we can parse event rather than push message directly so that we don't support many version messages later.
// 1. "{\"option\":1,\"weight\":\"1.000000000000000000\"}" | ||
// 2. "option:VOTE_OPTION_NO weight:\"1.000000000000000000\"" |
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.
VoteOption inside event is represented in these two type format, v1 and v1beta1 currently.
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.
I am still trying to understand cosmos SDK.
We are not able to use provided methods like:
func (m *Vote) GetOptions() []*WeightedVoteOption {
if m != nil {
return m.Options
}
return nil
}
|
||
case *govtypesv1.MsgVote: | ||
return m.handleMsgVote(tx, cosmosMsg) | ||
return m.handleVoteEvent(tx, cosmosMsg.Voter, tx.Logs[index].Events) |
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.
Voter event is supported by 0.47.5, we currently better to put Voter from message to make it backward compatible.
https://github.com/cosmos/cosmos-sdk/blob/main/CHANGELOG.md#v0475---2023-09-01
@@ -32,37 +30,35 @@ func (m *Module) HandleMsg(index int, msg sdk.Msg, tx *juno.Tx) error { | |||
|
|||
switch cosmosMsg := msg.(type) { | |||
case *govtypesv1.MsgSubmitProposal: | |||
return m.handleMsgSubmitProposal(tx, index, cosmosMsg) | |||
return m.handleSubmitProposalEvent(tx, cosmosMsg.Proposer, tx.Logs[index].Events) |
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.
We still need put proposer from message since Cosmos-SDK does not support proposer
attribute inside submit_proposal
event, it maybe better we post a request to Cosmos-SDK team or just remove this field in the feature. From my side, I would remove it as I would see depositors more than proposer, in addition, proposer must be one of depositors.
} | ||
|
||
// handleMsgVoteWeighted allows to properly handle a MsgVoteWeighted | ||
func (m *Module) handleMsgVoteWeighted(tx *juno.Tx, msg *govtypesv1.MsgVoteWeighted) error { |
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.
It shares the same vote event as MsgVote, so it can be removed safely.
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.
Some questions :)
cmd/parse/gov/proposal.go
Outdated
} | ||
|
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.
What about
switch msg.(type) {
case *govtypesv1.MsgSubmitProposal, *govtypesv1beta1.MsgSubmitProposal:
err = govModule.HandleMsg(index, msg, tx)
if err != nil {
return fmt.Errorf("error while handling MsgSubmitProposal: %s", err)
}
}
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.
Great, it is cleaner, thanks! 3936cc6
// 1. "{\"option\":1,\"weight\":\"1.000000000000000000\"}" | ||
// 2. "option:VOTE_OPTION_NO weight:\"1.000000000000000000\"" |
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.
I am still trying to understand cosmos SDK.
We are not able to use provided methods like:
func (m *Vote) GetOptions() []*WeightedVoteOption {
if m != nil {
return m.Options
}
return nil
}
Unluckily, the thing I tried is to parse the string from event, and it shows two cases in Cosmos-SDK now. There is no function supporting to parse string into option and also WeightOptionsFromString couldn't parse these option string properly since it is used for cmd string. Therefore we can only parse them by ourselves. If we handle message instance directly, then we need to have both functions, v1 and v1beta1 for each gov messages. |
Very interesting. |
Description
Closes: #XXXX
Currently, gov module is updated to gov v1, however, gov v1beta1 is still alive to chains, Cosmos-SDK doesn't completely remove v1beta1 support. As a result, we should re-add gov v1beta1 support to make sure our proposals data are also updated when gov v1beta1 messages are performed.
Say, some of users on Cheqd is using gov.v1beta1.MsgVote to vote on the proposal.
https://bigdipper.live/cheqd/transactions/19E4F068FBFBC46DA9BEF3E0F7CA908317D5582CAB2A17683138A5248ED34E3C
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...
!
to the type prefix if API or client breaking changeCHANGELOG.md
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...
!
in the type prefix if API or client breaking change