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

Revisit logic for ibc v3 gov updates #440

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions x/poe/contract/tgrade_validator_voting.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package contract

import "github.com/confio/tgrade/x/twasm/contract"
import (
"github.com/confio/tgrade/x/twasm/contract"
lightclienttypes "github.com/cosmos/ibc-go/v3/modules/light-clients/09-localhost/types"
)

// ValidatorVotingInitMsg setup contract on instantiation
type ValidatorVotingInitMsg struct {
Expand Down Expand Up @@ -38,9 +41,10 @@ type ValidatorProposal struct {
}

type ChainUpgrade struct {
Name string `json:"name"`
Height uint64 `json:"height"`
Info string `json:"info"`
Name string `json:"name"`
Height uint64 `json:"height"`
Info string `json:"info"`
UpgradedClientState *lightclienttypes.ClientState `json:"UpgradedClientState"`
}

type ConsensusBlockParamsUpdate = contract.BlockParams
Expand Down
16 changes: 13 additions & 3 deletions x/poe/contract/tgrade_validator_voting_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import (
"testing"
"time"

ibcclienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"

wasmapp "github.com/CosmWasm/wasmd/app"

"github.com/confio/tgrade/x/poe/contract"

sdk "github.com/cosmos/cosmos-sdk/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
lightclienttypes "github.com/cosmos/ibc-go/v3/modules/light-clients/09-localhost/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -56,6 +59,12 @@ func TestValidatorsGovProposal(t *testing.T) {
codeID, err := contractKeeper.Create(ctx, anyAddress, validatorVotingContract, nil)
require.NoError(t, err)
require.False(t, example.TWasmKeeper.IsPinnedCode(ctx, codeID), "pinned")

clientState := lightclienttypes.NewClientState("test-chain", ibcclienttypes.Height{
RevisionNumber: 7654321,
RevisionHeight: 7654321,
})

specs := map[string]struct {
src contract.ValidatorProposal
assertExp func(t *testing.T, ctx sdk.Context)
Expand All @@ -79,9 +88,10 @@ func TestValidatorsGovProposal(t *testing.T) {
"chain upgrade": {
src: contract.ValidatorProposal{
RegisterUpgrade: &contract.ChainUpgrade{
Name: "v2",
Info: "v2-info",
Height: 7654321,
Name: "v2",
Info: "v2-info",
Height: 7654321,
UpgradedClientState: clientState,
},
},
assertExp: func(t *testing.T, ctx sdk.Context) {
Expand Down
43 changes: 24 additions & 19 deletions x/twasm/contract/incoming_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/json"
"sort"

lightclienttypes "github.com/cosmos/ibc-go/v3/modules/light-clients/09-localhost/types"

wasmvmtypes "github.com/CosmWasm/wasmvm/types"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -65,11 +67,9 @@ func (p ExecuteGovProposal) GetProposalContent(sender sdk.AccAddress) govtypes.C
p.Proposal.Text.Description = p.Description
return p.Proposal.Text
case p.Proposal.RegisterUpgrade != nil:
return &upgradetypes.SoftwareUpgradeProposal{
Title: p.Title,
Description: p.Description,
Plan: *p.Proposal.RegisterUpgrade,
}
p.Proposal.RegisterUpgrade.Title = p.Title
p.Proposal.RegisterUpgrade.Description = p.Description
return p.Proposal.RegisterUpgrade
case p.Proposal.CancelUpgrade != nil:
p.Proposal.CancelUpgrade.Title = p.Title
p.Proposal.CancelUpgrade.Description = p.Description
Expand Down Expand Up @@ -129,15 +129,11 @@ func (p ExecuteGovProposal) GetProposalContent(sender sdk.AccAddress) govtypes.C

// unpackInterfaces unpacks the Any type into the interface type in `Any.cachedValue`
func (p *ExecuteGovProposal) unpackInterfaces(unpacker codectypes.AnyUnpacker) error {
var err error
switch { //nolint:gocritic
case p.Proposal.RegisterUpgrade != nil:
// revisit with https://github.com/confio/tgrade/issues/364
if p.Proposal.RegisterUpgrade.UpgradedClientState != nil { //nolint:staticcheck
return sdkerrors.ErrInvalidRequest.Wrap("upgrade logic for IBC has been moved to the IBC module")
}
return p.Proposal.RegisterUpgrade.UnpackInterfaces(unpacker)
}
return err
return nil
}

// ProtoAny data type to map from json to cosmos-sdk Any type.
Expand Down Expand Up @@ -184,17 +180,26 @@ func (p *GovProposal) UnmarshalJSON(b []byte) error {
},
"register_upgrade": func(b []byte) error {
proxy := struct {
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
Height int64 `protobuf:"varint,3,opt,name=height,proto3" json:"height,omitempty"`
Info string `protobuf:"bytes,4,opt,name=info,proto3" json:"info,omitempty"`
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
Height int64 `protobuf:"varint,3,opt,name=height,proto3" json:"height,omitempty"`
Info string `protobuf:"bytes,4,opt,name=info,proto3" json:"info,omitempty"`
UpgradedClientState *lightclienttypes.ClientState `protobuf:"bytes,4,opt,name=upgraded_client_state,json=upgradedClientState,proto3" json:"upgraded_client_state,omitempty"`
}{}
if err := json.Unmarshal(b, &proxy); err != nil {
return sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
}
result.RegisterUpgrade = &upgradetypes.Plan{
Name: proxy.Name,
Height: proxy.Height,
Info: proxy.Info,

csAny, err := codectypes.NewAnyWithValue(proxy.UpgradedClientState)
if err != nil {
return sdkerrors.Wrap(sdkerrors.ErrPackAny, err.Error())
}
result.RegisterUpgrade = &ibcclienttypes.UpgradeProposal{
Plan: upgradetypes.Plan{
Name: proxy.Name,
Height: proxy.Height,
Info: proxy.Info,
},
UpgradedClientState: csAny,
}
return nil
},
Expand Down Expand Up @@ -264,7 +269,7 @@ type proposalContent struct {

// Register an "live upgrade" on the x/upgrade module
// See https://github.com/cosmos/cosmos-sdk/blob/v0.42.3/proto/cosmos/upgrade/v1beta1/upgrade.proto#L12-L53
RegisterUpgrade *upgradetypes.Plan `json:"register_upgrade"`
RegisterUpgrade *ibcclienttypes.UpgradeProposal `json:"register_upgrade"`

// There can only be one pending upgrade at a given time. This cancels the pending upgrade, if any.
// See https://github.com/cosmos/cosmos-sdk/blob/v0.42.3/proto/cosmos/upgrade/v1beta1/upgrade.proto#L57-L62
Expand Down
4 changes: 1 addition & 3 deletions x/twasm/contract/incoming_msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package contract
import (
"encoding/json"
"testing"
"time"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -47,9 +46,8 @@ func TestGetProposalContent(t *testing.T) {
"height": 1,
"info": "any information"
}}}}`,
expGovProposal: &upgradetypes.SoftwareUpgradeProposal{Title: "myTitle", Description: "myDescription", Plan: upgradetypes.Plan{
expGovProposal: &ibcclienttypes.UpgradeProposal{Title: "myTitle", Description: "myDescription", Plan: upgradetypes.Plan{
Name: "myUpgradeName",
Time: time.Time{},
Height: 1,
Info: "any information",
}},
Expand Down