From e7cd8f12e5ebe0564ec650e28c8643ebb95b5bcb Mon Sep 17 00:00:00 2001 From: Pino' Surace Date: Fri, 12 Aug 2022 13:35:11 +0200 Subject: [PATCH 1/2] Revisit logic for ibc v3 gov updates --- x/twasm/contract/incoming_msgs.go | 28 +++++++++++--------------- x/twasm/contract/incoming_msgs_test.go | 4 +--- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/x/twasm/contract/incoming_msgs.go b/x/twasm/contract/incoming_msgs.go index 5b859181..b2f2d9df 100644 --- a/x/twasm/contract/incoming_msgs.go +++ b/x/twasm/contract/incoming_msgs.go @@ -65,11 +65,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 @@ -129,15 +127,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. @@ -191,10 +185,12 @@ func (p *GovProposal) UnmarshalJSON(b []byte) error { 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, + result.RegisterUpgrade = &ibcclienttypes.UpgradeProposal{ + Plan: upgradetypes.Plan{ + Name: proxy.Name, + Height: proxy.Height, + Info: proxy.Info, + }, } return nil }, @@ -264,7 +260,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 diff --git a/x/twasm/contract/incoming_msgs_test.go b/x/twasm/contract/incoming_msgs_test.go index d52641d6..1c8c0f5e 100644 --- a/x/twasm/contract/incoming_msgs_test.go +++ b/x/twasm/contract/incoming_msgs_test.go @@ -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" @@ -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", }}, From 20913f3654b93e1bc38d205fdeed4bd1ac32b635 Mon Sep 17 00:00:00 2001 From: Pino' Surace Date: Wed, 28 Sep 2022 14:11:43 +0200 Subject: [PATCH 2/2] Add draft implementation --- x/poe/contract/tgrade_validator_voting.go | 12 ++++++++---- .../tgrade_validator_voting_integration_test.go | 16 +++++++++++++--- x/twasm/contract/incoming_msgs.go | 15 ++++++++++++--- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/x/poe/contract/tgrade_validator_voting.go b/x/poe/contract/tgrade_validator_voting.go index 1bb2244b..f3f3463d 100644 --- a/x/poe/contract/tgrade_validator_voting.go +++ b/x/poe/contract/tgrade_validator_voting.go @@ -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 { @@ -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 diff --git a/x/poe/contract/tgrade_validator_voting_integration_test.go b/x/poe/contract/tgrade_validator_voting_integration_test.go index 08926bd6..f18a20f5 100644 --- a/x/poe/contract/tgrade_validator_voting_integration_test.go +++ b/x/poe/contract/tgrade_validator_voting_integration_test.go @@ -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" @@ -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) @@ -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) { diff --git a/x/twasm/contract/incoming_msgs.go b/x/twasm/contract/incoming_msgs.go index b2f2d9df..bdd9509f 100644 --- a/x/twasm/contract/incoming_msgs.go +++ b/x/twasm/contract/incoming_msgs.go @@ -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" @@ -178,19 +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()) } + + 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 },