-
Notifications
You must be signed in to change notification settings - Fork 657
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: check that MsgChannelUpgradeInit
is signed by authority
#4773
Changes from 13 commits
069d61b
dc20e7e
86a840f
6a393f8
2e88090
acb926c
814c8f5
91f299b
2388c60
459f5bf
686d6ce
c82d053
c694852
dd97efa
0ae26b2
cd16010
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,15 @@ package ibctesting | |
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov" | ||
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" | ||
|
||
abci "github.com/cometbft/cometbft/abci/types" | ||
|
||
|
@@ -587,18 +591,68 @@ func (endpoint *Endpoint) QueryChannelUpgradeProof() ([]byte, []byte, clienttype | |
|
||
// ChanUpgradeInit sends a MsgChannelUpgradeInit on the associated endpoint. | ||
// A default upgrade proposal is used with overrides from the ProposedUpgrade | ||
// in the channel config. | ||
// in the channel config, and submitted via governance proposal | ||
func (endpoint *Endpoint) ChanUpgradeInit() error { | ||
upgrade := endpoint.GetProposedUpgrade() | ||
|
||
// create upgrade init message via gov proposal and submit the proposal | ||
msg := channeltypes.NewMsgChannelUpgradeInit( | ||
endpoint.ChannelConfig.PortID, | ||
endpoint.ChannelID, | ||
upgrade.Fields, | ||
endpoint.Chain.GetSimApp().IBCKeeper.GetAuthority(), | ||
) | ||
|
||
proposal, err := govtypesv1.NewMsgSubmitProposal( | ||
[]sdk.Msg{msg}, | ||
sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, govtypesv1.DefaultMinDepositTokens)), | ||
endpoint.Chain.SenderAccount.GetAddress().String(), | ||
endpoint.ChannelID, | ||
"upgrade-init", | ||
fmt.Sprintf("gov proposal for initialising channel upgrade: %s", endpoint.ChannelID), | ||
false, | ||
) | ||
require.NoError(endpoint.Chain.TB, err) | ||
|
||
return endpoint.Chain.sendMsgs(msg) | ||
var proposalID int | ||
res, err := endpoint.Chain.SendMsgs(proposal) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
events := res.Events | ||
for _, event := range events { | ||
for _, attribute := range event.Attributes { | ||
if attribute.Key == "proposal_id" { | ||
proposalID, err = strconv.Atoi(attribute.Value) | ||
charleenfei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
require.NoError(endpoint.Chain.TB, err) | ||
} | ||
} | ||
} | ||
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 can use the proposal id in the msg response https://github.com/cosmos/cosmos-sdk/blob/main/x/gov/types/v1/tx.pb.go#L151 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. With this approach we would need to convert the any into a 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. ah that's annoying. Opened #4803, happy to fix later
charleenfei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// vote on proposal | ||
charleenfei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ctx := endpoint.Chain.GetContext() | ||
require.NoError(endpoint.Chain.TB, endpoint.Chain.GetSimApp().GovKeeper.AddVote(ctx, uint64(proposalID), endpoint.Chain.SenderAccount.GetAddress(), govtypesv1.NewNonSplitVoteOption(govtypesv1.OptionYes), "")) | ||
require.NoError(endpoint.Chain.TB, endpoint.Chain.GetSimApp().GovKeeper.AddVote(ctx, uint64(proposalID), endpoint.Chain.SenderAccount.GetAddress(), govtypesv1.NewNonSplitVoteOption(govtypesv1.OptionYes), "")) | ||
charleenfei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// fast forward the chain context to end the voting period | ||
params, err := endpoint.Chain.GetSimApp().GovKeeper.Params.Get(ctx) | ||
require.NoError(endpoint.Chain.TB, err) | ||
|
||
newHeader := endpoint.Chain.GetContext().BlockHeader() | ||
newHeader.Time = endpoint.Chain.GetContext().BlockHeader().Time.Add(*params.MaxDepositPeriod).Add(*params.VotingPeriod) | ||
ctx = ctx.WithBlockHeader(newHeader) | ||
require.NoError(endpoint.Chain.TB, govtypes.EndBlocker(ctx, &endpoint.Chain.GetSimApp().GovKeeper)) | ||
colin-axner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// check if proposal passed or failed on msg execution | ||
p, err := endpoint.Chain.GetSimApp().GovKeeper.Proposals.Get(ctx, 1) | ||
charleenfei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
require.NoError(endpoint.Chain.TB, err) | ||
if p.Status != govtypesv1.StatusPassed { | ||
return fmt.Errorf("proposal failed: %s", p.FailedReason) | ||
} | ||
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. Do we need to return the error? Maybe we can just do an assertion here? require.Equalf(endpoint.Chain.TB, govtypesv1.StatusPassed, p.Status, "proposal failed: %s", p.FailedReason) 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. I wanted to return the error here so that I could do an assertion in the test itself, since this is a util function. |
||
|
||
endpoint.Chain.Coordinator.CommitBlock(endpoint.Chain) | ||
charleenfei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return nil | ||
} | ||
|
||
// ChanUpgradeTry sends a MsgChannelUpgradeTry on the associated endpoint. | ||
|
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.
Maybe we should have a consistent error message for this check?
ibc-go/modules/core/keeper/msg_server.go
Line 106 in c694852
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.
actually, it looks like theres an invalid signer error in
govtypes
. maybe we can update all of these to use that error return, looks like that's what the 08-wasm client returns inStoreCode
. i can open a code hygiene issue.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.
sounds good, maybe we open an issue and address once all the feature branches are merged to main?