From 0719168183b6935e721f78bdde8e624239f42b38 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 16 May 2023 13:23:34 +0200 Subject: [PATCH] chore: optimise transfer authz to consume less gas for unbounded spend limits (#3586) (cherry picked from commit f6e8f038826d7c3c7310ea9b50a2706759bf48e1) # Conflicts: # modules/apps/transfer/types/transfer_authorization.go --- modules/apps/transfer/types/transfer_authorization.go | 8 +++++++- .../apps/transfer/types/transfer_authorization_test.go | 8 +++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/apps/transfer/types/transfer_authorization.go b/modules/apps/transfer/types/transfer_authorization.go index 5e3ab9495f4..344c13ea26d 100644 --- a/modules/apps/transfer/types/transfer_authorization.go +++ b/modules/apps/transfer/types/transfer_authorization.go @@ -10,8 +10,14 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/authz" +<<<<<<< HEAD channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types" host "github.com/cosmos/ibc-go/v6/modules/core/24-host" +======= + ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors" + channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + host "github.com/cosmos/ibc-go/v7/modules/core/24-host" +>>>>>>> f6e8f038 (chore: optimise transfer authz to consume less gas for unbounded spend limits (#3586)) ) var _ authz.Authorization = &TransferAuthorization{} @@ -49,7 +55,7 @@ func (a TransferAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.Accep // If the spend limit is set to the MaxUint256 sentinel value, do not subtract the amount from the spend limit. if allocation.SpendLimit.AmountOf(msgTransfer.Token.Denom).Equal(UnboundedSpendLimit()) { - return authz.AcceptResponse{Accept: true, Delete: false, Updated: &a}, nil + return authz.AcceptResponse{Accept: true, Delete: false, Updated: nil}, nil } limitLeft, isNegative := allocation.SpendLimit.SafeSub(msgTransfer.Token) diff --git a/modules/apps/transfer/types/transfer_authorization_test.go b/modules/apps/transfer/types/transfer_authorization_test.go index 330260e9e25..66d8e05b46e 100644 --- a/modules/apps/transfer/types/transfer_authorization_test.go +++ b/modules/apps/transfer/types/transfer_authorization_test.go @@ -94,11 +94,9 @@ func (suite *TypesTestSuite) TestTransferAuthorizationAccept() { func(res authz.AcceptResponse, err error) { suite.Require().NoError(err) - updatedTransferAuthz, ok := res.Updated.(*types.TransferAuthorization) - suite.Require().True(ok) - - remainder := updatedTransferAuthz.Allocations[0].SpendLimit.AmountOf(sdk.DefaultBondDenom) - suite.Require().True(types.UnboundedSpendLimit().Equal(remainder)) + suite.Require().True(res.Accept) + suite.Require().False(res.Delete) + suite.Require().Nil(res.Updated) }, }, {