From cf2b2c24a0ee56d058e76d9ec85c9d73bf60c643 Mon Sep 17 00:00:00 2001 From: Matt Witkowski Date: Thu, 13 Jul 2023 10:23:53 -0400 Subject: [PATCH] =?UTF-8?q?Removed=20ibc-go=20dependency,=20and=20updated?= =?UTF-8?q?=20code=20to=20route=20messages=20to=20the=20=E2=80=A6=20(#1618?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Removed ibc-go dependency, and updated code to route messages to the ibc transfer module. * Updated the routeMsgIbcTransfer to return the result so the events can be emitted. * Added WithBypass to match previous implementation. * Passed in the message server instead of the router. This is similar to how some modules did message passing in Osmosis. * Updated CHANGELOG. * Added validate basic check. --- CHANGELOG.md | 1 + app/app.go | 2 +- go.mod | 3 --- go.sum | 4 ++-- x/marker/keeper/keeper.go | 10 +++++----- x/marker/keeper/marker.go | 19 ++++++------------- x/marker/keeper/msg_server.go | 14 +------------- x/marker/keeper/proposal_handler_test.go | 2 +- x/marker/simulation/proposals_test.go | 2 +- x/marker/types/expected_keepers.go | 6 ++++++ 10 files changed, 24 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a44e3860d..70f4019e7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements * Update ibcnet ports so they don't conflict with host machine. [#1622](https://github.com/provenance-io/provenance/issues/1622) +* Replace custom ibc-go v6.1.1 fork with official module. [#1616](https://github.com/provenance-io/provenance/issues/1616) ### Bug Fixes diff --git a/app/app.go b/app/app.go index 6b6c1040d4..456889b7db 100644 --- a/app/app.go +++ b/app/app.go @@ -480,7 +480,7 @@ func New( ) app.MarkerKeeper = markerkeeper.NewKeeper( - appCodec, keys[markertypes.StoreKey], app.GetSubspace(markertypes.ModuleName), app.AccountKeeper, app.BankKeeper, app.AuthzKeeper, app.FeeGrantKeeper, app.TransferKeeper, app.AttributeKeeper, app.NameKeeper, + appCodec, keys[markertypes.StoreKey], app.GetSubspace(markertypes.ModuleName), app.AccountKeeper, app.BankKeeper, app.AuthzKeeper, app.FeeGrantKeeper, app.AttributeKeeper, app.NameKeeper, app.TransferKeeper, ) pioMessageRouter := MessageRouterFunc(func(msg sdk.Msg) baseapp.MsgServiceHandler { diff --git a/go.mod b/go.mod index 21062f345f..b870e4da41 100644 --- a/go.mod +++ b/go.mod @@ -190,6 +190,3 @@ replace github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0 // TODO: This is also required for https://github.com/provenance-io/provenance/issues/1414 replace github.com/CosmWasm/wasmd => github.com/provenance-io/wasmd v0.30.0-pio-5 - -// TODO: Required for IBC Transfer Module. Remove this when they patch it to include our changes. https://github.com/provenance-io/provenance/issues/1100 -replace github.com/cosmos/ibc-go/v6 => github.com/provenance-io/ibc-go/v6 v6.1.1-pio-1 diff --git a/go.sum b/go.sum index 25fcc13d5b..d89fefc67f 100644 --- a/go.sum +++ b/go.sum @@ -377,6 +377,8 @@ github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4 github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw= github.com/cosmos/iavl v0.19.6 h1:XY78yEeNPrEYyNCKlqr9chrwoeSDJ0bV2VjocTk//OU= github.com/cosmos/iavl v0.19.6/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= +github.com/cosmos/ibc-go/v6 v6.1.1 h1:oqqMNyjj6SLQF8rvgCaDGwfdITEIsbhs8F77/8xvRIo= +github.com/cosmos/ibc-go/v6 v6.1.1/go.mod h1:NL17FpFAaWjRFVb1T7LUKuOoMSsATPpu+Icc4zL5/Ik= github.com/cosmos/interchain-accounts v0.4.2 h1:BxdzY22uouwe9wGK7h/HbzPNIH89JJ/4+V6n02l3cG4= github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo= github.com/cosmos/keyring v1.2.0/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA= @@ -1005,8 +1007,6 @@ github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/provenance-io/cosmos-sdk v0.46.13-pio-1 h1:kkF1cRulmJS6uAbILsoZSb2qaUnPgBg8yR6cr9rk9YY= github.com/provenance-io/cosmos-sdk v0.46.13-pio-1/go.mod h1:H7JTxq/UEPvM/LSs5bNYvMwmZlVl2NBT5UlqNe8tjEU= -github.com/provenance-io/ibc-go/v6 v6.1.1-pio-1 h1:jeNhAAkH7wxi0jnVo/vLtlaURU9ghCITiGF0Jzqjf7o= -github.com/provenance-io/ibc-go/v6 v6.1.1-pio-1/go.mod h1:NL17FpFAaWjRFVb1T7LUKuOoMSsATPpu+Icc4zL5/Ik= github.com/provenance-io/wasmd v0.30.0-pio-5 h1:SNEZDiCC4LJdcLpINhhz5Jf0zddIQ76QIwScy4uxebM= github.com/provenance-io/wasmd v0.30.0-pio-5/go.mod h1:z03r/MHY9N+sO95lxNPiOlg4XMqE/rdeyBjYX54CT8o= github.com/rakyll/statik v0.1.7 h1:OF3QCZUuyPxuGEP7B4ypUa7sB/iHtqOTDYZXGM8KOdQ= diff --git a/x/marker/keeper/keeper.go b/x/marker/keeper/keeper.go index 40ab016ae8..c1fd6f8a22 100644 --- a/x/marker/keeper/keeper.go +++ b/x/marker/keeper/keeper.go @@ -11,7 +11,6 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - ibckeeper "github.com/cosmos/ibc-go/v6/modules/apps/transfer/keeper" ibctypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" "github.com/provenance-io/provenance/x/marker/types" @@ -58,8 +57,6 @@ type Keeper struct { // To pass through grant creation for callers with admin access on a marker. feegrantKeeper types.FeeGrantKeeper - ibcKeeper ibckeeper.Keeper - // To access attributes for addresses attrKeeper types.AttrKeeper // To access names and normalize required attributes @@ -77,6 +74,9 @@ type Keeper struct { markerModuleAddr sdk.AccAddress ibcTransferModuleAddr sdk.AccAddress + + // Used to transfer the ibc marker + ibcTransferServer types.IbcTransferMsgServer } // NewKeeper returns a marker keeper. It handles: @@ -92,9 +92,9 @@ func NewKeeper( bankKeeper types.BankKeeper, authzKeeper types.AuthzKeeper, feegrantKeeper types.FeeGrantKeeper, - ibcKeeper ibckeeper.Keeper, attrKeeper types.AttrKeeper, nameKeeper types.NameKeeper, + ibcTransferServer types.IbcTransferMsgServer, ) Keeper { if !paramSpace.HasKeyTable() { paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) @@ -106,7 +106,6 @@ func NewKeeper( authzKeeper: authzKeeper, bankKeeper: bankKeeper, feegrantKeeper: feegrantKeeper, - ibcKeeper: ibcKeeper, attrKeeper: attrKeeper, nameKeeper: nameKeeper, storeKey: key, @@ -114,6 +113,7 @@ func NewKeeper( authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), markerModuleAddr: authtypes.NewModuleAddress(types.CoinPoolName), ibcTransferModuleAddr: authtypes.NewModuleAddress(ibctypes.ModuleName), + ibcTransferServer: ibcTransferServer, } bankKeeper.AppendSendRestriction(rv.SendRestrictionFn) return rv diff --git a/x/marker/keeper/marker.go b/x/marker/keeper/marker.go index 529da1890d..731694063b 100644 --- a/x/marker/keeper/marker.go +++ b/x/marker/keeper/marker.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - ibckeeper "github.com/cosmos/ibc-go/v6/modules/apps/transfer/keeper" ibctypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" @@ -672,7 +671,6 @@ func (k Keeper) IbcTransferCoin( timeoutHeight clienttypes.Height, timeoutTimestamp uint64, memo string, - checkRestrictionsHandler ibckeeper.CheckRestrictionsHandler, ) error { m, err := k.GetMarkerByDenom(ctx, token.Denom) if err != nil { @@ -705,18 +703,13 @@ func (k Keeper) IbcTransferCoin( k.SetMarker(ctx, m) } - _, err = k.ibcKeeper.SendTransfer( - types.WithBypass(ctx), - sourcePort, - sourceChannel, - token, - sender, - receiver, - timeoutHeight, - timeoutTimestamp, - memo, - checkRestrictionsHandler, + msg := ibctypes.NewMsgTransfer( + sourcePort, sourceChannel, token, sender.String(), receiver, timeoutHeight, timeoutTimestamp, memo, ) + if validationErr := msg.ValidateBasic(); validationErr != nil { + return validationErr + } + _, err = k.ibcTransferServer.Transfer(types.WithBypass(ctx), msg) if err != nil { return err } diff --git a/x/marker/keeper/msg_server.go b/x/marker/keeper/msg_server.go index 2a0848ab02..b249b2e256 100644 --- a/x/marker/keeper/msg_server.go +++ b/x/marker/keeper/msg_server.go @@ -13,8 +13,6 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - ibckeeper "github.com/cosmos/ibc-go/v6/modules/apps/transfer/keeper" - ibctypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" "github.com/provenance-io/provenance/x/marker/types" ) @@ -485,17 +483,7 @@ func (k msgServer) IbcTransfer(goCtx context.Context, msg *types.MsgIbcTransferR return nil, err } - err = k.IbcTransferCoin(ctx, msg.Transfer.SourcePort, msg.Transfer.SourceChannel, msg.Transfer.Token, from, admin, msg.Transfer.Receiver, msg.Transfer.TimeoutHeight, msg.Transfer.TimeoutTimestamp, msg.Transfer.Memo, func(ctx sdk.Context, ibcKeeper ibckeeper.Keeper, sender sdk.AccAddress, token sdk.Coin) (canTransfer bool, err error) { - if !ibcKeeper.GetSendEnabled(ctx) { - return false, ibctypes.ErrSendDisabled - } - - if ibcKeeper.BankKeeper.BlockedAddr(sender) { - return false, sdkerrors.ErrUnauthorized.Wrapf("%s is not allowed to send funds", sender) - } - - return true, nil - }) + err = k.IbcTransferCoin(ctx, msg.Transfer.SourcePort, msg.Transfer.SourceChannel, msg.Transfer.Token, from, admin, msg.Transfer.Receiver, msg.Transfer.TimeoutHeight, msg.Transfer.TimeoutTimestamp, msg.Transfer.Memo) if err != nil { return nil, err } diff --git a/x/marker/keeper/proposal_handler_test.go b/x/marker/keeper/proposal_handler_test.go index f6231c7ea7..8967c4233c 100644 --- a/x/marker/keeper/proposal_handler_test.go +++ b/x/marker/keeper/proposal_handler_test.go @@ -34,7 +34,7 @@ type IntegrationTestSuite struct { func (s *IntegrationTestSuite) SetupSuite() { s.app = provenance.Setup(s.T()) s.ctx = s.app.BaseApp.NewContext(false, tmproto.Header{}) - s.k = markerkeeper.NewKeeper(s.app.AppCodec(), s.app.GetKey(markertypes.ModuleName), s.app.GetSubspace(markertypes.ModuleName), s.app.AccountKeeper, s.app.BankKeeper, s.app.AuthzKeeper, s.app.FeeGrantKeeper, s.app.TransferKeeper, s.app.AttributeKeeper, s.app.NameKeeper) + s.k = markerkeeper.NewKeeper(s.app.AppCodec(), s.app.GetKey(markertypes.ModuleName), s.app.GetSubspace(markertypes.ModuleName), s.app.AccountKeeper, s.app.BankKeeper, s.app.AuthzKeeper, s.app.FeeGrantKeeper, s.app.AttributeKeeper, s.app.NameKeeper, s.app.TransferKeeper) s.accountAddr = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) } diff --git a/x/marker/simulation/proposals_test.go b/x/marker/simulation/proposals_test.go index 4ec1b22721..1358f28d76 100644 --- a/x/marker/simulation/proposals_test.go +++ b/x/marker/simulation/proposals_test.go @@ -39,9 +39,9 @@ func TestProposalContents(t *testing.T) { app.BankKeeper, app.AuthzKeeper, app.FeeGrantKeeper, - app.TransferKeeper, app.AttributeKeeper, app.NameKeeper, + app.TransferKeeper, ), ) require.Len(t, weightedProposalContent, 6) diff --git a/x/marker/types/expected_keepers.go b/x/marker/types/expected_keepers.go index 1d8c5a517c..3326933cd1 100644 --- a/x/marker/types/expected_keepers.go +++ b/x/marker/types/expected_keepers.go @@ -10,6 +10,7 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/feegrant" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" attrtypes "github.com/provenance-io/provenance/x/attribute/types" ) @@ -91,3 +92,8 @@ type GovKeeper interface { GetVotingParams(ctx sdk.Context) govtypes.VotingParams GetProposalID(ctx sdk.Context) (uint64, error) } + +// IbcTransferMsgServer defines the message server functionality needed by the marker module. +type IbcTransferMsgServer interface { + Transfer(goCtx context.Context, msg *transfertypes.MsgTransfer) (*transfertypes.MsgTransferResponse, error) +}