From 01b343f885c9c38d532098a736a81e16a95e62dd Mon Sep 17 00:00:00 2001 From: Cian Hatton Date: Mon, 24 Apr 2023 16:34:50 +0100 Subject: [PATCH 1/9] wip: experiement with string value for proto --- e2e/tests/transfer/base_test.go | 25 +-- e2e/testsuite/grpc_query.go | 9 +- modules/apps/transfer/keeper/grpc_query.go | 5 +- modules/apps/transfer/types/query.pb.go | 142 +++++++++--------- .../ibc/applications/transfer/v1/query.proto | 8 +- 5 files changed, 97 insertions(+), 92 deletions(-) diff --git a/e2e/tests/transfer/base_test.go b/e2e/tests/transfer/base_test.go index 577f4a89bd1..89280d90c92 100644 --- a/e2e/tests/transfer/base_test.go +++ b/e2e/tests/transfer/base_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "cosmossdk.io/math" // "cosmossdk.io/math" paramsproposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal" "github.com/strangelove-ventures/interchaintest/v7/ibc" @@ -90,11 +91,11 @@ func (s *TransferTestSuite) TestMsgTransfer_Succeeds_Nonincentivized() { expected := testvalues.StartingTokenAmount - testvalues.IBCTransferAmount s.Require().Equal(expected, actualBalance) - // actualTotalEscrow, err := s.QueryTotalEscrowForDenom(ctx, chainA, chainADenom) - // s.Require().NoError(err) + actualTotalEscrow, err := s.QueryTotalEscrowForDenom(ctx, chainA, chainADenom) + s.Require().NoError(err) - // expectedTotalEscrow := math.NewInt(testvalues.IBCTransferAmount) - // s.Require().Equal(expectedTotalEscrow, actualTotalEscrow) + expectedTotalEscrow := math.NewInt(testvalues.IBCTransferAmount) + s.Require().Equal(expectedTotalEscrow, actualTotalEscrow) }) t.Run("start relayer", func(t *testing.T) { @@ -125,9 +126,9 @@ func (s *TransferTestSuite) TestMsgTransfer_Succeeds_Nonincentivized() { s.Require().Equal(int64(0), actualBalance) - // actualTotalEscrow, err := s.QueryTotalEscrowForDenom(ctx, chainB, chainBIBCToken.IBCDenom()) - // s.Require().NoError(err) - // s.Require().Equal(math.ZeroInt(), actualTotalEscrow) // total escrow is zero because sending chain is not source for tokens + actualTotalEscrow, err := s.QueryTotalEscrowForDenom(ctx, chainB, chainBIBCToken.IBCDenom()) + s.Require().NoError(err) + s.Require().Equal(math.ZeroInt(), actualTotalEscrow) // total escrow is zero because sending chain is not source for tokens }) s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA, chainB), "failed to wait for blocks") @@ -142,11 +143,11 @@ func (s *TransferTestSuite) TestMsgTransfer_Succeeds_Nonincentivized() { s.Require().Equal(expected, actualBalance) }) - // t.Run("tokens are un-escrowed", func(t *testing.T) { - // actualTotalEscrow, err := s.QueryTotalEscrowForDenom(ctx, chainA, chainADenom) - // s.Require().NoError(err) - // s.Require().Equal(math.ZeroInt(), actualTotalEscrow) // total escrow is zero because tokens have come back - // }) + t.Run("tokens are un-escrowed", func(t *testing.T) { + actualTotalEscrow, err := s.QueryTotalEscrowForDenom(ctx, chainA, chainADenom) + s.Require().NoError(err) + s.Require().Equal(math.ZeroInt(), actualTotalEscrow) // total escrow is zero because tokens have come back + }) } // TestMsgTransfer_Fails_InvalidAddress attempts to send an IBC transfer to an invalid address and ensures diff --git a/e2e/testsuite/grpc_query.go b/e2e/testsuite/grpc_query.go index 4a83d863897..ac01de950b4 100644 --- a/e2e/testsuite/grpc_query.go +++ b/e2e/testsuite/grpc_query.go @@ -168,11 +168,16 @@ func (s *E2ETestSuite) QueryTotalEscrowForDenom(ctx context.Context, chain ibc.C res, err := queryClient.TotalEscrowForDenom(ctx, &transfertypes.QueryTotalEscrowForDenomRequest{ Denom: denom, }) - if err != nil { + + amount := sdk.IntProto{} + Codec().MustUnmarshal([]byte(res.Amount), &amount) + + + if err != nil || amount.Int.IsNil() { return math.ZeroInt(), err } - return res.Amount, nil + return math.NewInt(amount.Int.Int64()), nil } // QueryInterchainAccount queries the interchain account for the given owner and connectionID. diff --git a/modules/apps/transfer/keeper/grpc_query.go b/modules/apps/transfer/keeper/grpc_query.go index 256df6ee1f6..7c5906dfc9f 100644 --- a/modules/apps/transfer/keeper/grpc_query.go +++ b/modules/apps/transfer/keeper/grpc_query.go @@ -134,9 +134,10 @@ func (k Keeper) TotalEscrowForDenom(c context.Context, req *types.QueryTotalEscr return nil, status.Error(codes.InvalidArgument, err.Error()) } - denomAmount := k.GetTotalEscrowForDenom(ctx, req.Denom) + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.TotalEscrowForDenomKey(req.Denom)) return &types.QueryTotalEscrowForDenomResponse{ - Amount: denomAmount, + Amount: string(bz), }, nil } diff --git a/modules/apps/transfer/types/query.pb.go b/modules/apps/transfer/types/query.pb.go index ed4becfe8e1..8891323936a 100644 --- a/modules/apps/transfer/types/query.pb.go +++ b/modules/apps/transfer/types/query.pb.go @@ -5,7 +5,6 @@ package types import ( context "context" - cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" _ "github.com/cosmos/cosmos-proto" query "github.com/cosmos/cosmos-sdk/types/query" @@ -554,7 +553,7 @@ func (m *QueryTotalEscrowForDenomRequest) GetDenom() string { // QueryTotalEscrowForDenomResponse is the response type for TotalEscrowForDenom RPC method. type QueryTotalEscrowForDenomResponse struct { - Amount cosmossdk_io_math.Int `protobuf:"bytes,1,opt,name=amount,proto3,customtype=cosmossdk.io/math.Int" json:"amount"` + Amount string `protobuf:"bytes,1,opt,name=amount,proto3" json:"amount,omitempty"` } func (m *QueryTotalEscrowForDenomResponse) Reset() { *m = QueryTotalEscrowForDenomResponse{} } @@ -590,6 +589,13 @@ func (m *QueryTotalEscrowForDenomResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QueryTotalEscrowForDenomResponse proto.InternalMessageInfo +func (m *QueryTotalEscrowForDenomResponse) GetAmount() string { + if m != nil { + return m.Amount + } + return "" +} + func init() { proto.RegisterType((*QueryDenomTraceRequest)(nil), "ibc.applications.transfer.v1.QueryDenomTraceRequest") proto.RegisterType((*QueryDenomTraceResponse)(nil), "ibc.applications.transfer.v1.QueryDenomTraceResponse") @@ -610,60 +616,59 @@ func init() { } var fileDescriptor_a638e2800a01538c = []byte{ - // 847 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0x4f, 0x6f, 0xe3, 0x44, - 0x14, 0x8f, 0x0b, 0x1b, 0xc8, 0x0b, 0xbb, 0x87, 0xd9, 0x2e, 0xdb, 0xb5, 0x4a, 0x52, 0x59, 0x05, - 0xaa, 0xec, 0xc6, 0x43, 0x76, 0xd3, 0x86, 0x43, 0x8b, 0x44, 0x0b, 0x85, 0x20, 0x0e, 0x6d, 0xda, - 0x13, 0x1c, 0xa2, 0x89, 0x3d, 0x38, 0x16, 0x89, 0xc7, 0xf5, 0x4c, 0x82, 0xaa, 0xa8, 0x17, 0x3e, - 0x01, 0x52, 0xbf, 0x04, 0x42, 0x42, 0x5c, 0xf8, 0x00, 0x1c, 0x7b, 0xac, 0x8a, 0x84, 0x2a, 0x0e, - 0x05, 0xb5, 0x7c, 0x10, 0xe4, 0x99, 0x49, 0x62, 0xd3, 0x34, 0x4d, 0x38, 0xc5, 0x33, 0xf3, 0x7e, - 0xef, 0xfd, 0x7e, 0xef, 0x9f, 0x02, 0x6b, 0x7e, 0xcb, 0xc1, 0x24, 0x0c, 0x3b, 0xbe, 0x43, 0x84, - 0xcf, 0x02, 0x8e, 0x45, 0x44, 0x02, 0xfe, 0x0d, 0x8d, 0x70, 0xbf, 0x82, 0x8f, 0x7a, 0x34, 0x3a, - 0xb6, 0xc3, 0x88, 0x09, 0x86, 0x96, 0xfd, 0x96, 0x63, 0x27, 0x2d, 0xed, 0xa1, 0xa5, 0xdd, 0xaf, - 0x98, 0x8b, 0x1e, 0xf3, 0x98, 0x34, 0xc4, 0xf1, 0x97, 0xc2, 0x98, 0xcf, 0x1c, 0xc6, 0xbb, 0x8c, - 0x37, 0xd5, 0x83, 0x3a, 0xe8, 0xa7, 0x92, 0x3a, 0xe1, 0x16, 0xe1, 0x54, 0xc5, 0xc1, 0xfd, 0x4a, -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- 0x13, 0x1c, 0xef, 0x1c, 0x8e, 0x07, 0x7a, 0x13, 0x9d, 0xe0, 0xf4, 0xf2, 0x40, 0x17, 0x06, 0x3c, - 0x9e, 0x30, 0xea, 0x68, 0x6b, 0x06, 0x96, 0x77, 0xef, 0x16, 0xf3, 0xa3, 0xff, 0x0b, 0xd7, 0x52, - 0x37, 0xa5, 0xd4, 0x0d, 0x54, 0x9d, 0x52, 0x26, 0x8e, 0x07, 0xf2, 0x37, 0x2e, 0x10, 0x16, 0xb1, - 0xb3, 0xa6, 0x12, 0xb7, 0xbd, 0x7f, 0x76, 0x5d, 0x30, 0xce, 0xaf, 0x0b, 0xc6, 0xdf, 0xd7, 0x05, - 0xe3, 0x87, 0x9b, 0x42, 0xe6, 0xfc, 0xa6, 0x90, 0xb9, 0xbc, 0x29, 0x64, 0xbe, 0xaa, 0x79, 0xbe, - 0x68, 0xf7, 0x5a, 0xb6, 0xc3, 0xba, 0xfa, 0x2f, 0x4c, 0x1c, 0xa0, 0xec, 0x31, 0xdc, 0xaf, 0xe1, - 0x2e, 0x73, 0x7b, 0x1d, 0xca, 0xff, 0x13, 0x4e, 0x1c, 0x87, 0x94, 0xb7, 0xb2, 0xf2, 0x2f, 0xc7, - 0xab, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x14, 0x3b, 0x12, 0x7f, 0x64, 0x09, 0x00, 0x00, + // 828 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0xd1, 0x4e, 0x33, 0x45, + 0x14, 0xee, 0xa2, 0x54, 0x7b, 0x2a, 0x5c, 0x0c, 0x28, 0xb0, 0xc1, 0x96, 0x6c, 0x50, 0x49, 0xa5, + 0x3b, 0x16, 0x0a, 0xf5, 0x02, 0x4c, 0x44, 0x45, 0x6b, 0x8c, 0x81, 0xc2, 0x95, 0x5e, 0x34, 0xd3, + 0xdd, 0x71, 0xbb, 0x49,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xb2, 0xb6, 0xa6, 0x6d, 0x64, 0x6a, + 0xe2, 0xdb, 0xb0, 0x61, 0xe9, 0x91, 0x37, 0xf7, 0x99, 0xc7, 0x29, 0xaa, 0x42, 0xd6, 0x8e, 0x6e, + 0xeb, 0x61, 0x74, 0x2d, 0x50, 0xd9, 0xad, 0x0d, 0x73, 0x5c, 0x91, 0xcc, 0x58, 0x18, 0xb0, 0x07, + 0xdf, 0x06, 0x79, 0x94, 0x85, 0xf7, 0x49, 0x1d, 0x02, 0x0c, 0xab, 0xa1, 0x92, 0x7c, 0x68, 0xaa, + 0x42, 0x46, 0xa5, 0x33, 0x65, 0x8b, 0x54, 0xe9, 0xcc, 0x23, 0xe2, 0xf4, 0x05, 0xd5, 0x62, 0x48, + 0xe3, 0x6f, 0x0d, 0x96, 0x1f, 0xe7, 0x50, 0x52, 0x7e, 0x84, 0x77, 0x62, 0x52, 0xf8, 0xb2, 0xb6, + 0xf6, 0xc6, 0x34, 0x5a, 0x0e, 0xe6, 0xaf, 0xee, 0xf2, 0xa9, 0xdf, 0xff, 0xcb, 0xa7, 0x55, 0xdc, + 0xec, 0x50, 0x1b, 0x47, 0x5f, 0x27, 0x14, 0xcc, 0x08, 0x05, 0x1f, 0x3d, 0xab, 0x40, 0x32, 0x4b, + 0x48, 0x58, 0x04, 0x24, 0x14, 0x1c, 0x91, 0x80, 0xb4, 0xfb, 0x05, 0x32, 0x4e, 0x60, 0x21, 0x71, + 0xab, 0x24, 0xed, 0x41, 0xda, 0x17, 0x37, 0xaa, 0x66, 0xeb, 0xe3, 0xc5, 0x28, 0xb4, 0xc2, 0x18, + 0x45, 0x78, 0x77, 0x58, 0xac, 0x6f, 0x08, 0x6f, 0xf6, 0xdb, 0xb1, 0x08, 0xb3, 0xc3, 0x76, 0x67, + 0x6a, 0xf2, 0x90, 0x7c, 0x53, 0xd2, 0x5d, 0xd1, 0x18, 0xf5, 0xa6, 0x4e, 0x60, 0x45, 0x78, 0x7f, + 0xc5, 0xad, 0x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 0x86, 0xcd, 0x4e, + 0xc3, 0xb4, 0x58, 0x5b, 0xfd, 0x53, 0x89, 0x12, 0x14, 0x1d, 0x86, 0xbb, 0x15, 0xdc, 0x66, 0x76, + 0xa7, 0x45, 0xf9, 0x2b, 0xe9, 0xc2, 0x73, 0x9f, 0xf2, 0x46, 0x5a, 0xfc, 0xb3, 0xd8, 0x7e, 0x19, + 0x00, 0x00, 0xff, 0xff, 0x64, 0x23, 0x47, 0xa2, 0x4b, 0x09, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1322,16 +1327,13 @@ func (m *QueryTotalEscrowForDenomResponse) MarshalToSizedBuffer(dAtA []byte) (in _ = i var l int _ = l - { - size := m.Amount.Size() - i -= size - if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintQuery(dAtA, i, uint64(size)) + if len(m.Amount) > 0 { + i -= len(m.Amount) + copy(dAtA[i:], m.Amount) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Amount))) + i-- + dAtA[i] = 0xa } - i-- - dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -1501,8 +1503,10 @@ func (m *QueryTotalEscrowForDenomResponse) Size() (n int) { } var l int _ = l - l = m.Amount.Size() - n += 1 + l + sovQuery(uint64(l)) + l = len(m.Amount) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -2523,9 +2527,7 @@ func (m *QueryTotalEscrowForDenomResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.Amount = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex diff --git a/proto/ibc/applications/transfer/v1/query.proto b/proto/ibc/applications/transfer/v1/query.proto index 83b8317def7..5186aafe0f6 100644 --- a/proto/ibc/applications/transfer/v1/query.proto +++ b/proto/ibc/applications/transfer/v1/query.proto @@ -117,9 +117,5 @@ message QueryTotalEscrowForDenomRequest { // QueryTotalEscrowForDenomResponse is the response type for TotalEscrowForDenom RPC method. message QueryTotalEscrowForDenomResponse { - string amount = 1 [ - (cosmos_proto.scalar) = "cosmos.Int", - (gogoproto.customtype) = "cosmossdk.io/math.Int", - (gogoproto.nullable) = false - ]; -} \ No newline at end of file + string amount = 1 [(cosmos_proto.scalar) = "cosmos.Int", (gogoproto.nullable) = true]; +} From b1bf9b73e4d8d566a1fd884463cb037527f3bd27 Mon Sep 17 00:00:00 2001 From: Cian Hatton Date: Tue, 25 Apr 2023 11:07:50 +0100 Subject: [PATCH 2/9] apply PR suggestions and fix unit tests --- e2e/tests/transfer/base_test.go | 1 - e2e/testsuite/grpc_query.go | 13 +++++++------ modules/apps/transfer/keeper/grpc_query.go | 5 ++--- modules/apps/transfer/keeper/grpc_query_test.go | 9 +++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/e2e/tests/transfer/base_test.go b/e2e/tests/transfer/base_test.go index 89280d90c92..161ec1a4a49 100644 --- a/e2e/tests/transfer/base_test.go +++ b/e2e/tests/transfer/base_test.go @@ -7,7 +7,6 @@ import ( "time" "cosmossdk.io/math" - // "cosmossdk.io/math" paramsproposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal" "github.com/strangelove-ventures/interchaintest/v7/ibc" test "github.com/strangelove-ventures/interchaintest/v7/testutil" diff --git a/e2e/testsuite/grpc_query.go b/e2e/testsuite/grpc_query.go index ac01de950b4..c7f6746808b 100644 --- a/e2e/testsuite/grpc_query.go +++ b/e2e/testsuite/grpc_query.go @@ -169,15 +169,16 @@ func (s *E2ETestSuite) QueryTotalEscrowForDenom(ctx context.Context, chain ibc.C Denom: denom, }) - amount := sdk.IntProto{} - Codec().MustUnmarshal([]byte(res.Amount), &amount) - - - if err != nil || amount.Int.IsNil() { + if err != nil { return math.ZeroInt(), err } - return math.NewInt(amount.Int.Int64()), nil + amount, ok := math.NewIntFromString(res.Amount) + if !ok { + return math.ZeroInt(), fmt.Errorf(`unable to convert string "%s" to int`, res.Amount) + } + + return math.NewInt(amount.Int64()), nil } // QueryInterchainAccount queries the interchain account for the given owner and connectionID. diff --git a/modules/apps/transfer/keeper/grpc_query.go b/modules/apps/transfer/keeper/grpc_query.go index 7c5906dfc9f..f9f4e9b126c 100644 --- a/modules/apps/transfer/keeper/grpc_query.go +++ b/modules/apps/transfer/keeper/grpc_query.go @@ -134,10 +134,9 @@ func (k Keeper) TotalEscrowForDenom(c context.Context, req *types.QueryTotalEscr return nil, status.Error(codes.InvalidArgument, err.Error()) } - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.TotalEscrowForDenomKey(req.Denom)) + denomAmount := k.GetTotalEscrowForDenom(ctx, req.Denom) return &types.QueryTotalEscrowForDenomResponse{ - Amount: string(bz), + Amount: denomAmount.String(), }, nil } diff --git a/modules/apps/transfer/keeper/grpc_query_test.go b/modules/apps/transfer/keeper/grpc_query_test.go index 32fa80b7f3c..89de34d66c3 100644 --- a/modules/apps/transfer/keeper/grpc_query_test.go +++ b/modules/apps/transfer/keeper/grpc_query_test.go @@ -266,7 +266,7 @@ func (suite *KeeperTestSuite) TestEscrowAddress() { func (suite *KeeperTestSuite) TestTotalEscrowForDenom() { var ( req *types.QueryTotalEscrowForDenomRequest - expEscrowAmount math.Int + expEscrowAmount string ) testCases := []struct { @@ -281,8 +281,9 @@ func (suite *KeeperTestSuite) TestTotalEscrowForDenom() { Denom: sdk.DefaultBondDenom, } - expEscrowAmount = math.NewInt(100) - suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), sdk.DefaultBondDenom, expEscrowAmount) + expEscrowAmountInt := math.NewInt(100) + expEscrowAmount = expEscrowAmountInt.String() + suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), sdk.DefaultBondDenom, expEscrowAmountInt) }, true, }, @@ -343,7 +344,7 @@ func (suite *KeeperTestSuite) TestTotalEscrowForDenom() { suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset - expEscrowAmount = math.ZeroInt() + expEscrowAmount = math.ZeroInt().String() tc.malleate() ctx := sdk.WrapSDKContext(suite.chainA.GetContext()) From 2e026cd6ab6099684f30b4f1cbb088e704189fa0 Mon Sep 17 00:00:00 2001 From: Cian Hatton Date: Tue, 25 Apr 2023 11:19:16 +0100 Subject: [PATCH 3/9] added extension method to gRPC response --- e2e/testsuite/grpc_query.go | 7 +------ modules/apps/transfer/types/grpc.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 modules/apps/transfer/types/grpc.go diff --git a/e2e/testsuite/grpc_query.go b/e2e/testsuite/grpc_query.go index c7f6746808b..5f14a6764bf 100644 --- a/e2e/testsuite/grpc_query.go +++ b/e2e/testsuite/grpc_query.go @@ -173,12 +173,7 @@ func (s *E2ETestSuite) QueryTotalEscrowForDenom(ctx context.Context, chain ibc.C return math.ZeroInt(), err } - amount, ok := math.NewIntFromString(res.Amount) - if !ok { - return math.ZeroInt(), fmt.Errorf(`unable to convert string "%s" to int`, res.Amount) - } - - return math.NewInt(amount.Int64()), nil + return res.GetSDKAmount() } // QueryInterchainAccount queries the interchain account for the given owner and connectionID. diff --git a/modules/apps/transfer/types/grpc.go b/modules/apps/transfer/types/grpc.go new file mode 100644 index 00000000000..4d19a09e85d --- /dev/null +++ b/modules/apps/transfer/types/grpc.go @@ -0,0 +1,16 @@ +package types + +import ( + "fmt" + + "cosmossdk.io/math" +) + +// GetSDKAmount returns the amount as a cosmos-sdk math.Int. +func (m *QueryTotalEscrowForDenomResponse) GetSDKAmount() (math.Int, error) { + amount, ok := math.NewIntFromString(m.Amount) + if !ok { + return math.ZeroInt(), fmt.Errorf(`unable to convert string "%s" to int`, m.Amount) + } + return math.NewInt(amount.Int64()), nil +} From 9cda05069367474e369d9b8690003d7ec7234752 Mon Sep 17 00:00:00 2001 From: Cian Hatton Date: Wed, 26 Apr 2023 17:14:46 +0100 Subject: [PATCH 4/9] refactor: change response return type to sdk Coin --- e2e/tests/transfer/base_test.go | 7 +- e2e/testsuite/grpc_query.go | 7 +- modules/apps/transfer/keeper/genesis.go | 2 +- modules/apps/transfer/keeper/genesis_test.go | 2 +- modules/apps/transfer/keeper/grpc_query.go | 4 +- .../apps/transfer/keeper/grpc_query_test.go | 13 +- modules/apps/transfer/keeper/keeper.go | 18 +-- modules/apps/transfer/keeper/keeper_test.go | 10 +- modules/apps/transfer/keeper/migrations.go | 2 +- .../apps/transfer/keeper/migrations_test.go | 2 +- modules/apps/transfer/keeper/relay.go | 12 +- modules/apps/transfer/keeper/relay_test.go | 40 ++--- modules/apps/transfer/types/grpc.go | 16 -- modules/apps/transfer/types/query.pb.go | 148 +++++++++--------- .../ibc/applications/transfer/v1/query.proto | 6 +- 15 files changed, 137 insertions(+), 152 deletions(-) delete mode 100644 modules/apps/transfer/types/grpc.go diff --git a/e2e/tests/transfer/base_test.go b/e2e/tests/transfer/base_test.go index 161ec1a4a49..a8ae1a52c07 100644 --- a/e2e/tests/transfer/base_test.go +++ b/e2e/tests/transfer/base_test.go @@ -7,6 +7,7 @@ import ( "time" "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" paramsproposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal" "github.com/strangelove-ventures/interchaintest/v7/ibc" test "github.com/strangelove-ventures/interchaintest/v7/testutil" @@ -93,7 +94,7 @@ func (s *TransferTestSuite) TestMsgTransfer_Succeeds_Nonincentivized() { actualTotalEscrow, err := s.QueryTotalEscrowForDenom(ctx, chainA, chainADenom) s.Require().NoError(err) - expectedTotalEscrow := math.NewInt(testvalues.IBCTransferAmount) + expectedTotalEscrow := sdk.NewCoin(chainADenom, math.NewInt(testvalues.IBCTransferAmount)) s.Require().Equal(expectedTotalEscrow, actualTotalEscrow) }) @@ -127,7 +128,7 @@ func (s *TransferTestSuite) TestMsgTransfer_Succeeds_Nonincentivized() { actualTotalEscrow, err := s.QueryTotalEscrowForDenom(ctx, chainB, chainBIBCToken.IBCDenom()) s.Require().NoError(err) - s.Require().Equal(math.ZeroInt(), actualTotalEscrow) // total escrow is zero because sending chain is not source for tokens + s.Require().Equal(sdk.NewCoin(chainBIBCToken.IBCDenom(), sdk.NewInt(0)), actualTotalEscrow) // total escrow is zero because sending chain is not source for tokens }) s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA, chainB), "failed to wait for blocks") @@ -145,7 +146,7 @@ func (s *TransferTestSuite) TestMsgTransfer_Succeeds_Nonincentivized() { t.Run("tokens are un-escrowed", func(t *testing.T) { actualTotalEscrow, err := s.QueryTotalEscrowForDenom(ctx, chainA, chainADenom) s.Require().NoError(err) - s.Require().Equal(math.ZeroInt(), actualTotalEscrow) // total escrow is zero because tokens have come back + s.Require().Equal(sdk.NewCoin(chainADenom, sdk.NewInt(0)), actualTotalEscrow) // total escrow is zero because tokens have come back }) } diff --git a/e2e/testsuite/grpc_query.go b/e2e/testsuite/grpc_query.go index 5f14a6764bf..0de464205bc 100644 --- a/e2e/testsuite/grpc_query.go +++ b/e2e/testsuite/grpc_query.go @@ -5,7 +5,6 @@ import ( "fmt" "sort" - "cosmossdk.io/math" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" sdk "github.com/cosmos/cosmos-sdk/types" @@ -163,17 +162,17 @@ func (s *E2ETestSuite) QueryPacketCommitment(ctx context.Context, chain ibc.Chai } // QueryTotalEscrowForDenom queries the total amount of tokens in escrow for a denom -func (s *E2ETestSuite) QueryTotalEscrowForDenom(ctx context.Context, chain ibc.Chain, denom string) (math.Int, error) { +func (s *E2ETestSuite) QueryTotalEscrowForDenom(ctx context.Context, chain ibc.Chain, denom string) (sdk.Coin, error) { queryClient := s.GetChainGRCPClients(chain).TransferQueryClient res, err := queryClient.TotalEscrowForDenom(ctx, &transfertypes.QueryTotalEscrowForDenomRequest{ Denom: denom, }) if err != nil { - return math.ZeroInt(), err + return sdk.NewCoin(denom, sdk.NewInt(0)), err } - return res.GetSDKAmount() + return res.Amount, nil } // QueryInterchainAccount queries the interchain account for the given owner and connectionID. diff --git a/modules/apps/transfer/keeper/genesis.go b/modules/apps/transfer/keeper/genesis.go index b31f53229e2..02b29d32ca1 100644 --- a/modules/apps/transfer/keeper/genesis.go +++ b/modules/apps/transfer/keeper/genesis.go @@ -32,7 +32,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) { // Every denom will have only one total escrow amount, since any // duplicate entry will fail validation in Validate of GenesisState for _, denomEscrow := range state.TotalEscrowed { - k.SetTotalEscrowForDenom(ctx, denomEscrow.Denom, denomEscrow.Amount) + k.SetTotalEscrowForDenom(ctx, denomEscrow) } } diff --git a/modules/apps/transfer/keeper/genesis_test.go b/modules/apps/transfer/keeper/genesis_test.go index e878ffbe229..0ea92efcf52 100644 --- a/modules/apps/transfer/keeper/genesis_test.go +++ b/modules/apps/transfer/keeper/genesis_test.go @@ -41,7 +41,7 @@ func (suite *KeeperTestSuite) TestGenesis() { amount, ok := math.NewIntFromString(pathAndEscrowMount.escrow) suite.Require().True(ok) escrows = append(sdk.NewCoins(sdk.NewCoin(denom, amount)), escrows...) - suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), denom, amount) + suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), sdk.NewCoin(denom, amount)) } genesis := suite.chainA.GetSimApp().TransferKeeper.ExportGenesis(suite.chainA.GetContext()) diff --git a/modules/apps/transfer/keeper/grpc_query.go b/modules/apps/transfer/keeper/grpc_query.go index f9f4e9b126c..87648d2f9dc 100644 --- a/modules/apps/transfer/keeper/grpc_query.go +++ b/modules/apps/transfer/keeper/grpc_query.go @@ -134,9 +134,9 @@ func (k Keeper) TotalEscrowForDenom(c context.Context, req *types.QueryTotalEscr return nil, status.Error(codes.InvalidArgument, err.Error()) } - denomAmount := k.GetTotalEscrowForDenom(ctx, req.Denom) + amount := k.GetTotalEscrowForDenom(ctx, req.Denom) return &types.QueryTotalEscrowForDenomResponse{ - Amount: denomAmount.String(), + Amount: amount, }, nil } diff --git a/modules/apps/transfer/keeper/grpc_query_test.go b/modules/apps/transfer/keeper/grpc_query_test.go index 89de34d66c3..38a97401120 100644 --- a/modules/apps/transfer/keeper/grpc_query_test.go +++ b/modules/apps/transfer/keeper/grpc_query_test.go @@ -266,7 +266,7 @@ func (suite *KeeperTestSuite) TestEscrowAddress() { func (suite *KeeperTestSuite) TestTotalEscrowForDenom() { var ( req *types.QueryTotalEscrowForDenomRequest - expEscrowAmount string + expEscrowAmount math.Int ) testCases := []struct { @@ -281,9 +281,8 @@ func (suite *KeeperTestSuite) TestTotalEscrowForDenom() { Denom: sdk.DefaultBondDenom, } - expEscrowAmountInt := math.NewInt(100) - expEscrowAmount = expEscrowAmountInt.String() - suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), sdk.DefaultBondDenom, expEscrowAmountInt) + expEscrowAmount = math.NewInt(100) + suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), sdk.NewCoin(sdk.DefaultBondDenom, expEscrowAmount)) }, true, }, @@ -298,7 +297,7 @@ func (suite *KeeperTestSuite) TestTotalEscrowForDenom() { suite.chainA.GetSimApp().TransferKeeper.SetDenomTrace(suite.chainA.GetContext(), denomTrace) expEscrowAmount, ok := math.NewIntFromString("100000000000000000000") suite.Require().True(ok) - suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), sdk.DefaultBondDenom, expEscrowAmount) + suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), sdk.NewCoin(sdk.DefaultBondDenom, expEscrowAmount)) req = &types.QueryTotalEscrowForDenomRequest{ Denom: denomTrace.IBCDenom(), @@ -344,7 +343,7 @@ func (suite *KeeperTestSuite) TestTotalEscrowForDenom() { suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset - expEscrowAmount = math.ZeroInt().String() + expEscrowAmount = sdk.ZeroInt() tc.malleate() ctx := sdk.WrapSDKContext(suite.chainA.GetContext()) @@ -352,7 +351,7 @@ func (suite *KeeperTestSuite) TestTotalEscrowForDenom() { if tc.expPass { suite.Require().NoError(err) - suite.Require().Equal(expEscrowAmount, res.Amount) + suite.Require().Equal(expEscrowAmount, res.Amount.Amount) } else { suite.Require().Error(err) } diff --git a/modules/apps/transfer/keeper/keeper.go b/modules/apps/transfer/keeper/keeper.go index 9b54521d352..fe7adac2032 100644 --- a/modules/apps/transfer/keeper/keeper.go +++ b/modules/apps/transfer/keeper/keeper.go @@ -4,7 +4,6 @@ import ( "fmt" "strings" - "cosmossdk.io/math" tmbytes "github.com/cometbft/cometbft/libs/bytes" "github.com/cometbft/cometbft/libs/log" "github.com/cosmos/cosmos-sdk/codec" @@ -12,6 +11,7 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" @@ -146,28 +146,28 @@ func (k Keeper) IterateDenomTraces(ctx sdk.Context, cb func(denomTrace types.Den // GetTotalEscrowForDenom gets the total amount of source chain tokens that // are in escrow, keyed by the denomination. -func (k Keeper) GetTotalEscrowForDenom(ctx sdk.Context, denom string) math.Int { +func (k Keeper) GetTotalEscrowForDenom(ctx sdk.Context, denom string) sdk.Coin { store := ctx.KVStore(k.storeKey) bz := store.Get(types.TotalEscrowForDenomKey(denom)) if bz == nil { - return math.ZeroInt() + return sdk.NewCoin(denom, sdk.ZeroInt()) } amount := sdk.IntProto{} k.cdc.MustUnmarshal(bz, &amount) - return amount.Int + return sdk.NewCoin(denom, amount.Int) } // SetTotalEscrowForDenom stores the total amount of source chain tokens that are in escrow. -func (k Keeper) SetTotalEscrowForDenom(ctx sdk.Context, denom string, amount math.Int) { - if amount.IsNegative() { - panic(fmt.Sprintf("amount cannot be negative: %s", amount)) +func (k Keeper) SetTotalEscrowForDenom(ctx sdk.Context, coin sdk.Coin) { + if coin.Amount.IsNegative() { + panic(fmt.Sprintf("amount cannot be negative: %s", coin.Amount)) } store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshal(&sdk.IntProto{Int: amount}) - store.Set(types.TotalEscrowForDenomKey(denom), bz) + bz := k.cdc.MustMarshal(&sdk.IntProto{Int: coin.Amount}) + store.Set(types.TotalEscrowForDenomKey(coin.Denom), bz) } // GetAllTotalEscrowed returns the escrow information for all the denominations. diff --git a/modules/apps/transfer/keeper/keeper_test.go b/modules/apps/transfer/keeper/keeper_test.go index 9c3a7a2e4fd..c22489391cc 100644 --- a/modules/apps/transfer/keeper/keeper_test.go +++ b/modules/apps/transfer/keeper/keeper_test.go @@ -91,15 +91,15 @@ func (suite *KeeperTestSuite) TestSetGetTotalEscrowForDenom() { tc.malleate() if tc.expPass { - suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(ctx, denom, expAmount) + suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(ctx, sdk.NewCoin(denom, expAmount)) total := suite.chainA.GetSimApp().TransferKeeper.GetTotalEscrowForDenom(ctx, denom) - suite.Require().Equal(expAmount, total) + suite.Require().Equal(expAmount, total.Amount) } else { - suite.Require().PanicsWithValue("amount cannot be negative: -1", func() { - suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(ctx, denom, expAmount) + suite.Require().PanicsWithError("negative coin amount: -1", func() { + suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(ctx, sdk.NewCoin(denom, expAmount)) }) total := suite.chainA.GetSimApp().TransferKeeper.GetTotalEscrowForDenom(ctx, denom) - suite.Require().Equal(math.ZeroInt(), total) + suite.Require().Equal(math.ZeroInt(), total.Amount) } }) } diff --git a/modules/apps/transfer/keeper/migrations.go b/modules/apps/transfer/keeper/migrations.go index d9dfdcfb398..759f2e1d2b7 100644 --- a/modules/apps/transfer/keeper/migrations.go +++ b/modules/apps/transfer/keeper/migrations.go @@ -67,7 +67,7 @@ func (m Migrator) MigrateTotalEscrowForDenom(ctx sdk.Context) error { } for _, totalEscrow := range totalEscrowed { - m.keeper.SetTotalEscrowForDenom(ctx, totalEscrow.Denom, totalEscrow.Amount) + m.keeper.SetTotalEscrowForDenom(ctx, totalEscrow) } return nil diff --git a/modules/apps/transfer/keeper/migrations_test.go b/modules/apps/transfer/keeper/migrations_test.go index 23564dece4e..5faca42989d 100644 --- a/modules/apps/transfer/keeper/migrations_test.go +++ b/modules/apps/transfer/keeper/migrations_test.go @@ -197,7 +197,7 @@ func (suite *KeeperTestSuite) TestMigrateTotalEscrowForDenom() { // check that the migration set the expected amount for both native and IBC tokens amount := suite.chainA.GetSimApp().TransferKeeper.GetTotalEscrowForDenom(suite.chainA.GetContext(), denom) - suite.Require().Equal(tc.expectedEscrowAmt, amount) + suite.Require().Equal(tc.expectedEscrowAmt, amount.Amount) }) } } diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index 6a7c6b140df..67b73e2f7d2 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -113,8 +113,8 @@ func (k Keeper) sendTransfer( // track the total amount in escrow keyed by denomination to allow for efficient iteration currentTotalEscrow := k.GetTotalEscrowForDenom(ctx, token.GetDenom()) - newTotalEscrow := currentTotalEscrow.Add(token.Amount) - k.SetTotalEscrowForDenom(ctx, token.GetDenom(), newTotalEscrow) + newTotalEscrow := currentTotalEscrow.Add(token) + k.SetTotalEscrowForDenom(ctx, sdk.NewCoin(token.GetDenom(), newTotalEscrow.Amount)) } else { labels = append(labels, telemetry.NewLabel(coretypes.LabelSource, "false")) @@ -236,8 +236,8 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t // track the total amount in escrow keyed by denomination to allow for efficient iteration currentTotalEscrow := k.GetTotalEscrowForDenom(ctx, token.GetDenom()) - newTotalEscrow := currentTotalEscrow.Sub(token.Amount) - k.SetTotalEscrowForDenom(ctx, token.GetDenom(), newTotalEscrow) + newTotalEscrow := currentTotalEscrow.Sub(token) + k.SetTotalEscrowForDenom(ctx, sdk.NewCoin(token.GetDenom(), newTotalEscrow.Amount)) defer func() { if transferAmount.IsInt64() { @@ -377,8 +377,8 @@ func (k Keeper) refundPacketToken(ctx sdk.Context, packet channeltypes.Packet, d // track the total amount in escrow keyed by denomination to allow for efficient iteration currentTotalEscrow := k.GetTotalEscrowForDenom(ctx, token.GetDenom()) - newTotalEscrow := currentTotalEscrow.Sub(token.Amount) - k.SetTotalEscrowForDenom(ctx, token.GetDenom(), newTotalEscrow) + newTotalEscrow := currentTotalEscrow.Sub(token) + k.SetTotalEscrowForDenom(ctx, sdk.NewCoin(token.GetDenom(), newTotalEscrow.Amount)) return nil } diff --git a/modules/apps/transfer/keeper/relay_test.go b/modules/apps/transfer/keeper/relay_test.go index ddda92004ca..c59c7326979 100644 --- a/modules/apps/transfer/keeper/relay_test.go +++ b/modules/apps/transfer/keeper/relay_test.go @@ -145,7 +145,7 @@ func (suite *KeeperTestSuite) TestSendTransfer() { // check total amount in escrow of sent token denom on sending chain amount := suite.chainA.GetSimApp().TransferKeeper.GetTotalEscrowForDenom(suite.chainA.GetContext(), coin.GetDenom()) - suite.Require().Equal(expEscrowAmount, amount) + suite.Require().Equal(expEscrowAmount, amount.Amount) if tc.expPass { suite.Require().NoError(err) @@ -233,7 +233,7 @@ func (suite *KeeperTestSuite) TestSendTransferSetsTotalEscrowAmountForSourceIBCT // check total amount in escrow of sent token on sending chain totalEscrow := suite.chainB.GetSimApp().TransferKeeper.GetTotalEscrowForDenom(suite.chainB.GetContext(), coin.GetDenom()) - suite.Require().Equal(math.NewInt(100), totalEscrow) + suite.Require().Equal(math.NewInt(100), totalEscrow.Amount) } // test receiving coin on chainB with coin that orignate on chainA and @@ -385,14 +385,14 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { // check total amount in escrow of received token denom on receiving chain var denom string - var totalEscrow math.Int + var totalEscrow sdk.Coin if tc.recvIsSource { denom = sdk.DefaultBondDenom } else { denom = trace.IBCDenom() } totalEscrow = suite.chainB.GetSimApp().TransferKeeper.GetTotalEscrowForDenom(suite.chainB.GetContext(), denom) - suite.Require().Equal(expEscrowAmount, totalEscrow) + suite.Require().Equal(expEscrowAmount, totalEscrow.Amount) if tc.expPass { suite.Require().NoError(err) @@ -483,9 +483,9 @@ func (suite *KeeperTestSuite) TestOnRecvPacketSetsTotalEscrowAmountForSourceIBCT ), ) - suite.chainB.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainB.GetContext(), coin.GetDenom(), coin.Amount) + suite.chainB.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainB.GetContext(), coin) totalEscrowChainB := suite.chainB.GetSimApp().TransferKeeper.GetTotalEscrowForDenom(suite.chainB.GetContext(), coin.GetDenom()) - suite.Require().Equal(math.NewInt(100), totalEscrowChainB) + suite.Require().Equal(math.NewInt(100), totalEscrowChainB.Amount) // execute onRecvPacket, when chaninB receives the source token the escrow amount should decrease err := suite.chainB.GetSimApp().TransferKeeper.OnRecvPacket(suite.chainB.GetContext(), packet, data) @@ -493,7 +493,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacketSetsTotalEscrowAmountForSourceIBCT // check total amount in escrow of sent token on reveiving chain totalEscrowChainB = suite.chainB.GetSimApp().TransferKeeper.GetTotalEscrowForDenom(suite.chainB.GetContext(), coin.GetDenom()) - suite.Require().Equal(math.ZeroInt(), totalEscrowChainB) + suite.Require().Equal(math.ZeroInt(), totalEscrowChainB.Amount) } // TestOnAcknowledgementPacket tests that successful acknowledgement is a no-op @@ -535,7 +535,7 @@ func (suite *KeeperTestSuite) TestOnAcknowledgementPacket() { suite.Require().NoError(banktestutil.FundAccount(suite.chainA.GetSimApp().BankKeeper, suite.chainA.GetContext(), escrow, sdk.NewCoins(coin))) // set escrow amount that would have been stored after successful execution of MsgTransfer - suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), sdk.DefaultBondDenom, amount) + suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), sdk.NewCoin(sdk.DefaultBondDenom, amount)) }, false, true, }, { @@ -545,7 +545,7 @@ func (suite *KeeperTestSuite) TestOnAcknowledgementPacket() { trace = types.ParseDenomTrace(sdk.DefaultBondDenom) // set escrow amount that would have been stored after successful execution of MsgTransfer - suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), sdk.DefaultBondDenom, amount) + suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), sdk.NewCoin(sdk.DefaultBondDenom, amount)) expEscrowAmount = math.NewInt(100) }, false, false, }, @@ -582,7 +582,7 @@ func (suite *KeeperTestSuite) TestOnAcknowledgementPacket() { // check total amount in escrow of sent token denom on sending chain totalEscrow := suite.chainA.GetSimApp().TransferKeeper.GetTotalEscrowForDenom(suite.chainA.GetContext(), trace.IBCDenom()) - suite.Require().Equal(expEscrowAmount, totalEscrow) + suite.Require().Equal(expEscrowAmount, totalEscrow.Amount) if tc.expPass { suite.Require().NoError(err) @@ -675,16 +675,16 @@ func (suite *KeeperTestSuite) TestOnAcknowledgementPacketSetsTotalEscrowAmountFo suite.chainA.GetTimeoutHeight(), 0, ) - suite.chainB.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainB.GetContext(), coin.GetDenom(), coin.Amount) + suite.chainB.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainB.GetContext(), coin) totalEscrowChainB := suite.chainB.GetSimApp().TransferKeeper.GetTotalEscrowForDenom(suite.chainB.GetContext(), coin.GetDenom()) - suite.Require().Equal(math.NewInt(100), totalEscrowChainB) + suite.Require().Equal(math.NewInt(100), totalEscrowChainB.Amount) err := suite.chainB.GetSimApp().TransferKeeper.OnAcknowledgementPacket(suite.chainB.GetContext(), packet, data, ack) suite.Require().NoError(err) // check total amount in escrow of sent token on sending chain totalEscrowChainB = suite.chainB.GetSimApp().TransferKeeper.GetTotalEscrowForDenom(suite.chainB.GetContext(), coin.GetDenom()) - suite.Require().Equal(math.ZeroInt(), totalEscrowChainB) + suite.Require().Equal(math.ZeroInt(), totalEscrowChainB.Amount) } // TestOnTimeoutPacket test private refundPacket function since it is a simple @@ -716,7 +716,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacket() { // funds the escrow account to have balance suite.Require().NoError(banktestutil.FundAccount(suite.chainA.GetSimApp().BankKeeper, suite.chainA.GetContext(), escrow, sdk.NewCoins(coin))) // set escrow amount that would have been stored after successful execution of MsgTransfer - suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), coin.GetDenom(), coin.Amount) + suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), coin) }, true, }, { @@ -738,7 +738,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacket() { expEscrowAmount = amount // set escrow amount that would have been stored after successful execution of MsgTransfer - suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), trace.IBCDenom(), amount) + suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), sdk.NewCoin(trace.IBCDenom(), amount)) }, false, }, { @@ -748,7 +748,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacket() { expEscrowAmount = amount // set escrow amount that would have been stored after successful execution of MsgTransfer - suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), trace.IBCDenom(), amount) + suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), sdk.NewCoin(trace.IBCDenom(), amount)) }, false, }, { @@ -786,7 +786,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacket() { // check total amount in escrow of sent token denom on sending chain totalEscrow := suite.chainA.GetSimApp().TransferKeeper.GetTotalEscrowForDenom(suite.chainA.GetContext(), trace.IBCDenom()) - suite.Require().Equal(expEscrowAmount, totalEscrow) + suite.Require().Equal(expEscrowAmount, totalEscrow.Amount) if tc.expPass { suite.Require().NoError(err) @@ -869,14 +869,14 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacketSetsTotalEscrowAmountForSourceI suite.chainA.GetTimeoutHeight(), 0, ) - suite.chainB.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainB.GetContext(), coin.GetDenom(), coin.Amount) + suite.chainB.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainB.GetContext(), coin) totalEscrowChainB := suite.chainB.GetSimApp().TransferKeeper.GetTotalEscrowForDenom(suite.chainB.GetContext(), coin.GetDenom()) - suite.Require().Equal(math.NewInt(100), totalEscrowChainB) + suite.Require().Equal(math.NewInt(100), totalEscrowChainB.Amount) err := suite.chainB.GetSimApp().TransferKeeper.OnTimeoutPacket(suite.chainB.GetContext(), packet, data) suite.Require().NoError(err) // check total amount in escrow of sent token on sending chain totalEscrowChainB = suite.chainB.GetSimApp().TransferKeeper.GetTotalEscrowForDenom(suite.chainB.GetContext(), coin.GetDenom()) - suite.Require().Equal(math.ZeroInt(), totalEscrowChainB) + suite.Require().Equal(math.ZeroInt(), totalEscrowChainB.Amount) } diff --git a/modules/apps/transfer/types/grpc.go b/modules/apps/transfer/types/grpc.go deleted file mode 100644 index 4d19a09e85d..00000000000 --- a/modules/apps/transfer/types/grpc.go +++ /dev/null @@ -1,16 +0,0 @@ -package types - -import ( - "fmt" - - "cosmossdk.io/math" -) - -// GetSDKAmount returns the amount as a cosmos-sdk math.Int. -func (m *QueryTotalEscrowForDenomResponse) GetSDKAmount() (math.Int, error) { - amount, ok := math.NewIntFromString(m.Amount) - if !ok { - return math.ZeroInt(), fmt.Errorf(`unable to convert string "%s" to int`, m.Amount) - } - return math.NewInt(amount.Int64()), nil -} diff --git a/modules/apps/transfer/types/query.pb.go b/modules/apps/transfer/types/query.pb.go index 8891323936a..b7a3904461e 100644 --- a/modules/apps/transfer/types/query.pb.go +++ b/modules/apps/transfer/types/query.pb.go @@ -6,7 +6,7 @@ package types import ( context "context" fmt "fmt" - _ "github.com/cosmos/cosmos-proto" + types "github.com/cosmos/cosmos-sdk/types" query "github.com/cosmos/cosmos-sdk/types/query" _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" @@ -553,7 +553,7 @@ func (m *QueryTotalEscrowForDenomRequest) GetDenom() string { // QueryTotalEscrowForDenomResponse is the response type for TotalEscrowForDenom RPC method. type QueryTotalEscrowForDenomResponse struct { - Amount string `protobuf:"bytes,1,opt,name=amount,proto3" json:"amount,omitempty"` + Amount types.Coin `protobuf:"bytes,1,opt,name=amount,proto3" json:"amount"` } func (m *QueryTotalEscrowForDenomResponse) Reset() { *m = QueryTotalEscrowForDenomResponse{} } @@ -589,11 +589,11 @@ func (m *QueryTotalEscrowForDenomResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QueryTotalEscrowForDenomResponse proto.InternalMessageInfo -func (m *QueryTotalEscrowForDenomResponse) GetAmount() string { +func (m *QueryTotalEscrowForDenomResponse) GetAmount() types.Coin { if m != nil { return m.Amount } - return "" + return types.Coin{} } func init() { @@ -616,59 +616,59 @@ func init() { } var fileDescriptor_a638e2800a01538c = []byte{ - // 828 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0xd1, 0x4e, 0x33, 0x45, - 0x14, 0xee, 0xa2, 0x54, 0x7b, 0x2a, 0x5c, 0x0c, 0x28, 0xb0, 0xc1, 0x96, 0x6c, 0x50, 0x49, 0xa5, - 0x3b, 0x16, 0x0a, 0xf5, 0x02, 0x4c, 0x44, 0x45, 0x6b, 0x8c, 0x81, 0xc2, 0x95, 0x5e, 0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42, 0xf0, 0x66, 0x93, 0xf0, 0xe6, 0xb2, 0xb6, 0xa6, 0x6d, 0x64, 0x6a, - 0xe2, 0xdb, 0xb0, 0x61, 0xe9, 0x91, 0x37, 0xf7, 0x99, 0xc7, 0x29, 0xaa, 0x42, 0xd6, 0x8e, 0x6e, - 0xeb, 0x61, 0x74, 0x2d, 0x50, 0xd9, 0xad, 0x0d, 0x73, 0x5c, 0x91, 0xcc, 0x58, 0x18, 0xb0, 0x07, - 0xdf, 0x06, 0x79, 0x94, 0x85, 0xf7, 0x49, 0x1d, 0x02, 0x0c, 0xab, 0xa1, 0x92, 0x7c, 0x68, 0xaa, - 0x42, 0x46, 0xa5, 0x33, 0x65, 0x8b, 0x54, 0xe9, 0xcc, 0x23, 0xe2, 0xf4, 0x05, 0xd5, 0x62, 0x48, - 0xe3, 0x6f, 0x0d, 0x96, 0x1f, 0xe7, 0x50, 0x52, 0x7e, 0x84, 0x77, 0x62, 0x52, 0xf8, 0xb2, 0xb6, - 0xf6, 0xc6, 0x34, 0x5a, 0x0e, 0xe6, 0xaf, 0xee, 0xf2, 0xa9, 0xdf, 0xff, 0xcb, 0xa7, 0x55, 0xdc, - 0xec, 0x50, 0x1b, 0x47, 0x5f, 0x27, 0x14, 0xcc, 0x08, 0x05, 0x1f, 0x3d, 0xab, 0x40, 0x32, 0x4b, - 0x48, 0x58, 0x04, 0x24, 0x14, 0x1c, 0x91, 0x80, 0xb4, 0xfb, 0x05, 0x32, 0x4e, 0x60, 0x21, 0x71, - 0xab, 0x24, 0xed, 0x41, 0xda, 0x17, 0x37, 0xaa, 0x66, 0xeb, 0xe3, 0xc5, 0x28, 0xb4, 0xc2, 0x18, - 0x45, 0x78, 0x77, 0x58, 0xac, 0x6f, 0x08, 0x6f, 0xf6, 0xdb, 0xb1, 0x08, 0xb3, 0xc3, 0x76, 0x67, - 0x6a, 0xf2, 0x90, 0x7c, 0x53, 0xd2, 0x5d, 0xd1, 0x18, 0xf5, 0xa6, 0x4e, 0x60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0x87, 0x5c, 0xea, 0x87, 0x8a, 0xe3, 0x86, 0xcd, 0x4e, - 0xc3, 0xb4, 0x58, 0x5b, 0xfd, 0x53, 0x89, 0x12, 0x14, 0x1d, 0x86, 0xbb, 0x15, 0xdc, 0x66, 0x76, - 0xa7, 0x45, 0xf9, 0x2b, 0xe9, 0xc2, 0x73, 0x9f, 0xf2, 0x46, 0x5a, 0xfc, 0xb3, 0xd8, 0x7e, 0x19, - 0x00, 0x00, 0xff, 0xff, 0x64, 0x23, 0x47, 0xa2, 0x4b, 0x09, 0x00, 0x00, + // 830 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0x4f, 0x4f, 0xe3, 0x46, + 0x14, 0x8f, 0x29, 0xa4, 0xcd, 0x4b, 0xe1, 0x30, 0xd0, 0x02, 0x16, 0x35, 0xc8, 0xa2, 0x2d, 0x4a, + 0xc1, 0xd3, 0x40, 0x20, 0x3d, 0x40, 0xa5, 0x42, 0x4b, 0x4b, 0xd5, 0x03, 0x04, 0x4e, 0xe5, 0x10, + 0x4d, 0xec, 0xa9, 0x63, 0x29, 0xf1, 0x18, 0x8f, 0x93, 0x0a, 0x45, 0x5c, 0xfa, 0x09, 0x2a, 0xf1, + 0x25, 0x56, 0x2b, 0xad, 0xf6, 0x2b, 0xec, 0x91, 0x23, 0xda, 0x95, 0x56, 0x9c, 0x76, 0x57, 0xb0, + 0x1f, 0x64, 0xe5, 0xf1, 0x38, 0xb1, 0x97, 0x10, 0x92, 0x3d, 0xc5, 0x33, 0xef, 0xdf, 0xef, 0xf7, + 0x7e, 0xf3, 0x9e, 0x02, 0x2b, 0x4e, 0xcd, 0xc4, 0xc4, 0xf3, 0x1a, 0x8e, 0x49, 0x02, 0x87, 0xb9, + 0x1c, 0x07, 0x3e, 0x71, 0xf9, 0x3f, 0xd4, 0xc7, 0xed, 0x22, 0x3e, 0x6b, 0x51, 0xff, 0x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0xcc, 0x17, 0xac, 0x12, 0x0d, + 0x10, 0xe2, 0xc6, 0x0d, 0x10, 0x07, 0xfd, 0x14, 0x96, 0x1e, 0x0e, 0x94, 0x18, 0xca, 0x90, 0x25, + 0x4d, 0xd6, 0x72, 0x03, 0xa9, 0xc8, 0x7c, 0xea, 0x0d, 0xc4, 0xea, 0xef, 0x31, 0xc7, 0xdd, 0x1d, + 0x0f, 0xdf, 0x53, 0x45, 0xba, 0xaf, 0xdf, 0x7c, 0x01, 0x13, 0x22, 0x3b, 0x7a, 0xae, 0x00, 0xf4, + 0x9e, 0x1d, 0x2a, 0x0d, 0xd6, 0xb4, 0xff, 0x98, 0xab, 0x9b, 0x23, 0x46, 0x45, 0xf0, 0xf5, 0xd2, + 0x7f, 0xaf, 0xde, 0x5f, 0x8e, 0x19, 0x68, 0x15, 0xcb, 0x5d, 0x94, 0xde, 0x41, 0xc9, 0xf9, 0xc1, + 0x9d, 0x50, 0xe7, 0x9d, 0x42, 0xe1, 0x02, 0x3d, 0x51, 0x20, 0x9f, 0x98, 0x38, 0x34, 0x5a, 0xf1, + 0xf8, 0x55, 0xa8, 0x5b, 0xa3, 0x86, 0x49, 0xd0, 0x05, 0x01, 0x7a, 0x19, 0xe9, 0x8f, 0x83, 0x46, + 0x97, 0x0a, 0x64, 0xa3, 0x31, 0x40, 0x3f, 0x0e, 0x51, 0x2e, 0x35, 0x85, 0x6a, 0x71, 0x84, 0x08, + 0x89, 0x6d, 0x59, 0x60, 0xd3, 0xd0, 0x42, 0x7f, 0x6c, 0xd1, 0x24, 0xa2, 0x67, 0x0a, 0xe4, 0xba, + 0x63, 0x85, 0x36, 0x86, 0xed, 0x43, 0x62, 0x66, 0xd5, 0xd2, 0x68, 0x41, 0x12, 0xde, 0xa6, 0x80, + 0x87, 0xd1, 0xda, 0xa0, 0xd6, 0x85, 0x3a, 0x87, 0x7a, 0x8b, 0x16, 0x0a, 0xc1, 0x5f, 0x2b, 0x30, + 0x99, 0x9a, 0x41, 0x54, 0x1e, 0xa2, 0x7c, 0xbf, 0x55, 0xa0, 0xfe, 0x34, 0x7a, 0xa0, 0xc4, 0x5e, + 0x11, 0xd8, 0xff, 0x42, 0x7f, 0xf6, 0xc7, 0x2e, 0xb7, 0x06, 0xc7, 0x9d, 0xde, 0x46, 0xb9, 0xc0, + 0xe1, 0x9e, 0xe1, 0xb8, 0x23, 0xb7, 0xcf, 0x05, 0x4e, 0x2f, 0x0c, 0xf4, 0x52, 0x81, 0xe9, 0x3e, + 0xe3, 0x8d, 0x76, 0x86, 0x40, 0xf9, 0xf0, 0x3e, 0x51, 0x7f, 0xfe, 0xd4, 0x70, 0x49, 0x75, 0x5b, + 0x50, 0xdd, 0x42, 0xa5, 0x01, 0x32, 0x71, 0xdc, 0x11, 0xbf, 0xa1, 0x40, 0x38, 0x08, 0x93, 0x55, + 0x23, 0x72, 0xbb, 0x47, 0x57, 0xb7, 0x9a, 0x72, 0x7d, 0xab, 0x29, 0xef, 0x6e, 0x35, 0xe5, 0xff, + 0x3b, 0x2d, 0x73, 0x7d, 0xa7, 0x65, 0x6e, 0xee, 0xb4, 0xcc, 0xdf, 0x65, 0xdb, 0x09, 0xea, 0xad, + 0x9a, 0x61, 0xb2, 0x26, 0x96, 0x7f, 0x54, 0x9c, 0x9a, 0xb9, 0x66, 0x33, 0xdc, 0x2e, 0xe3, 0x26, + 0xb3, 0x5a, 0x0d, 0xca, 0x3f, 0x2a, 0x17, 0x9c, 0x7b, 0x94, 0xd7, 0xb2, 0xe2, 0x6f, 0xc6, 0xc6, + 0x87, 0x00, 0x00, 0x00, 0xff, 0xff, 0xd9, 0x35, 0xa9, 0x75, 0x5d, 0x09, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1327,13 +1327,16 @@ func (m *QueryTotalEscrowForDenomResponse) MarshalToSizedBuffer(dAtA []byte) (in _ = i var l int _ = l - if len(m.Amount) > 0 { - i -= len(m.Amount) - copy(dAtA[i:], m.Amount) - i = encodeVarintQuery(dAtA, i, uint64(len(m.Amount))) - i-- - dAtA[i] = 0xa + { + size, err := m.Amount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -1503,10 +1506,8 @@ func (m *QueryTotalEscrowForDenomResponse) Size() (n int) { } var l int _ = l - l = len(m.Amount) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } + l = m.Amount.Size() + n += 1 + l + sovQuery(uint64(l)) return n } @@ -2501,7 +2502,7 @@ func (m *QueryTotalEscrowForDenomResponse) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowQuery @@ -2511,23 +2512,24 @@ func (m *QueryTotalEscrowForDenomResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthQuery } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthQuery } if postIndex > l { return io.ErrUnexpectedEOF } - m.Amount = string(dAtA[iNdEx:postIndex]) + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex default: iNdEx = preIndex diff --git a/proto/ibc/applications/transfer/v1/query.proto b/proto/ibc/applications/transfer/v1/query.proto index 5186aafe0f6..786ccbae84d 100644 --- a/proto/ibc/applications/transfer/v1/query.proto +++ b/proto/ibc/applications/transfer/v1/query.proto @@ -3,7 +3,8 @@ syntax = "proto3"; package ibc.applications.transfer.v1; import "gogoproto/gogo.proto"; -import "cosmos_proto/cosmos.proto"; +// import "cosmos_proto/cosmos.proto"; +import "cosmos/base/v1beta1/coin.proto"; import "cosmos/base/query/v1beta1/pagination.proto"; import "ibc/applications/transfer/v1/transfer.proto"; import "google/api/annotations.proto"; @@ -114,8 +115,7 @@ message QueryEscrowAddressResponse { message QueryTotalEscrowForDenomRequest { string denom = 1; } - // QueryTotalEscrowForDenomResponse is the response type for TotalEscrowForDenom RPC method. message QueryTotalEscrowForDenomResponse { - string amount = 1 [(cosmos_proto.scalar) = "cosmos.Int", (gogoproto.nullable) = true]; + cosmos.base.v1beta1.Coin amount = 1 [(gogoproto.nullable) = false]; } From fa096ca2b3b0874f12456c0d1163bd601059074c Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 2 May 2023 10:37:57 +0200 Subject: [PATCH 5/9] rm commented out proto import --- proto/ibc/applications/transfer/v1/query.proto | 1 - 1 file changed, 1 deletion(-) diff --git a/proto/ibc/applications/transfer/v1/query.proto b/proto/ibc/applications/transfer/v1/query.proto index 786ccbae84d..9a41aa847b3 100644 --- a/proto/ibc/applications/transfer/v1/query.proto +++ b/proto/ibc/applications/transfer/v1/query.proto @@ -3,7 +3,6 @@ syntax = "proto3"; package ibc.applications.transfer.v1; import "gogoproto/gogo.proto"; -// import "cosmos_proto/cosmos.proto"; import "cosmos/base/v1beta1/coin.proto"; import "cosmos/base/query/v1beta1/pagination.proto"; import "ibc/applications/transfer/v1/transfer.proto"; From ed5f1e523ec16aa8c4096f0e6c035447d513e7c6 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 2 May 2023 10:40:10 +0200 Subject: [PATCH 6/9] remove empty sdk.Coin literal in e2e/grpc_query --- e2e/testsuite/grpc_query.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/testsuite/grpc_query.go b/e2e/testsuite/grpc_query.go index 0de464205bc..31cf5910176 100644 --- a/e2e/testsuite/grpc_query.go +++ b/e2e/testsuite/grpc_query.go @@ -169,7 +169,7 @@ func (s *E2ETestSuite) QueryTotalEscrowForDenom(ctx context.Context, chain ibc.C }) if err != nil { - return sdk.NewCoin(denom, sdk.NewInt(0)), err + return sdk.Coin{}, err } return res.Amount, nil From 102e2debb2a5f51a0537d7c8ab8c46116d8fc641 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Tue, 2 May 2023 10:42:13 +0200 Subject: [PATCH 7/9] reference same type in relay.go in favour of creating new sdk.Coin --- modules/apps/transfer/keeper/relay.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/apps/transfer/keeper/relay.go b/modules/apps/transfer/keeper/relay.go index 67b73e2f7d2..7bf08139e4e 100644 --- a/modules/apps/transfer/keeper/relay.go +++ b/modules/apps/transfer/keeper/relay.go @@ -114,7 +114,7 @@ func (k Keeper) sendTransfer( // track the total amount in escrow keyed by denomination to allow for efficient iteration currentTotalEscrow := k.GetTotalEscrowForDenom(ctx, token.GetDenom()) newTotalEscrow := currentTotalEscrow.Add(token) - k.SetTotalEscrowForDenom(ctx, sdk.NewCoin(token.GetDenom(), newTotalEscrow.Amount)) + k.SetTotalEscrowForDenom(ctx, newTotalEscrow) } else { labels = append(labels, telemetry.NewLabel(coretypes.LabelSource, "false")) @@ -237,7 +237,7 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t // track the total amount in escrow keyed by denomination to allow for efficient iteration currentTotalEscrow := k.GetTotalEscrowForDenom(ctx, token.GetDenom()) newTotalEscrow := currentTotalEscrow.Sub(token) - k.SetTotalEscrowForDenom(ctx, sdk.NewCoin(token.GetDenom(), newTotalEscrow.Amount)) + k.SetTotalEscrowForDenom(ctx, newTotalEscrow) defer func() { if transferAmount.IsInt64() { @@ -378,7 +378,7 @@ func (k Keeper) refundPacketToken(ctx sdk.Context, packet channeltypes.Packet, d // track the total amount in escrow keyed by denomination to allow for efficient iteration currentTotalEscrow := k.GetTotalEscrowForDenom(ctx, token.GetDenom()) newTotalEscrow := currentTotalEscrow.Sub(token) - k.SetTotalEscrowForDenom(ctx, sdk.NewCoin(token.GetDenom(), newTotalEscrow.Amount)) + k.SetTotalEscrowForDenom(ctx, newTotalEscrow) return nil } From b5f831e6a99a3f10cbddb5d7e39965093284679b Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 3 May 2023 14:04:11 +0200 Subject: [PATCH 8/9] adding code comment regarding zero value coin return --- modules/apps/transfer/keeper/keeper.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/apps/transfer/keeper/keeper.go b/modules/apps/transfer/keeper/keeper.go index fe7adac2032..031927c568b 100644 --- a/modules/apps/transfer/keeper/keeper.go +++ b/modules/apps/transfer/keeper/keeper.go @@ -146,6 +146,9 @@ func (k Keeper) IterateDenomTraces(ctx sdk.Context, cb func(denomTrace types.Den // GetTotalEscrowForDenom gets the total amount of source chain tokens that // are in escrow, keyed by the denomination. +// +// NOTE: if there is no value stored in state for the provided denom then a new Coin is returned for the denom with an intial value of zero. +// This accommodates callers to simply call `Add()` on the returned Coin as an empty Coin literal (e.g. sdk.Coin{}) will trigger a panic due to the absence of a denom. func (k Keeper) GetTotalEscrowForDenom(ctx sdk.Context, denom string) sdk.Coin { store := ctx.KVStore(k.storeKey) bz := store.Get(types.TotalEscrowForDenomKey(denom)) From fb063c2b167af3981748a8c15ad30ab249604b88 Mon Sep 17 00:00:00 2001 From: Damian Nolan Date: Wed, 3 May 2023 16:42:04 +0200 Subject: [PATCH 9/9] fix typo, linter --- modules/apps/transfer/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/transfer/keeper/keeper.go b/modules/apps/transfer/keeper/keeper.go index 031927c568b..63e2847a680 100644 --- a/modules/apps/transfer/keeper/keeper.go +++ b/modules/apps/transfer/keeper/keeper.go @@ -147,7 +147,7 @@ func (k Keeper) IterateDenomTraces(ctx sdk.Context, cb func(denomTrace types.Den // GetTotalEscrowForDenom gets the total amount of source chain tokens that // are in escrow, keyed by the denomination. // -// NOTE: if there is no value stored in state for the provided denom then a new Coin is returned for the denom with an intial value of zero. +// NOTE: if there is no value stored in state for the provided denom then a new Coin is returned for the denom with an initial value of zero. // This accommodates callers to simply call `Add()` on the returned Coin as an empty Coin literal (e.g. sdk.Coin{}) will trigger a panic due to the absence of a denom. func (k Keeper) GetTotalEscrowForDenom(ctx sdk.Context, denom string) sdk.Coin { store := ctx.KVStore(k.storeKey)