From 7d98c6aea6614476eb1c708fbe5ddbe80e775260 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Fri, 5 Jan 2024 16:38:42 -0600 Subject: [PATCH] Disable DenomOwners tracking --- x/bank/keeper/grpc_query.go | 37 +---------------------- x/bank/keeper/grpc_query_test.go | 22 ++++---------- x/bank/keeper/send.go | 50 +------------------------------- 3 files changed, 7 insertions(+), 102 deletions(-) diff --git a/x/bank/keeper/grpc_query.go b/x/bank/keeper/grpc_query.go index 7cfc9beb8eca..93f92fce87c8 100644 --- a/x/bank/keeper/grpc_query.go +++ b/x/bank/keeper/grpc_query.go @@ -250,42 +250,7 @@ func (k BaseKeeper) DenomOwners( if req == nil { return nil, status.Errorf(codes.InvalidArgument, "empty request") } - - if err := sdk.ValidateDenom(req.Denom); err != nil { - return nil, status.Error(codes.InvalidArgument, err.Error()) - } - - ctx := sdk.UnwrapSDKContext(goCtx) - denomPrefixStore := k.getDenomAddressPrefixStore(ctx, req.Denom) - - var denomOwners []*types.DenomOwner - pageRes, err := query.FilteredPaginate( - denomPrefixStore, - req.Pagination, - func(key []byte, _ []byte, accumulate bool) (bool, error) { - if accumulate { - address, _, err := types.AddressAndDenomFromBalancesStore(key) - if err != nil { - return false, err - } - - denomOwners = append( - denomOwners, - &types.DenomOwner{ - Address: address.String(), - Balance: k.GetBalance(ctx, address, req.Denom), - }, - ) - } - - return true, nil - }, - ) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - - return &types.QueryDenomOwnersResponse{DenomOwners: denomOwners, Pagination: pageRes}, nil + return nil, status.Error(codes.Unimplemented, "not implemented on Osmosis. Use an indexer.") } func (k BaseKeeper) SendEnabled(goCtx context.Context, req *types.QuerySendEnabledRequest) (*types.QuerySendEnabledResponse, error) { diff --git a/x/bank/keeper/grpc_query_test.go b/x/bank/keeper/grpc_query_test.go index 610bc356e5be..abd2fcbaaeb0 100644 --- a/x/bank/keeper/grpc_query_test.go +++ b/x/bank/keeper/grpc_query_test.go @@ -495,7 +495,7 @@ func (suite *KeeperTestSuite) TestGRPCDenomOwners() { req: &types.QueryDenomOwnersRequest{ Denom: "foo", }, - expPass: true, + expPass: false, numAddrs: 0, hasNext: false, total: 0, @@ -508,7 +508,7 @@ func (suite *KeeperTestSuite) TestGRPCDenomOwners() { CountTotal: true, }, }, - expPass: true, + expPass: false, numAddrs: 6, hasNext: true, total: 10, @@ -522,7 +522,7 @@ func (suite *KeeperTestSuite) TestGRPCDenomOwners() { CountTotal: true, }, }, - expPass: true, + expPass: false, numAddrs: 4, hasNext: false, total: 10, @@ -532,20 +532,8 @@ func (suite *KeeperTestSuite) TestGRPCDenomOwners() { for name, tc := range testCases { suite.Run(name, func() { resp, err := suite.queryClient.DenomOwners(gocontext.Background(), tc.req) - if tc.expPass { - suite.NoError(err) - suite.NotNil(resp) - suite.Len(resp.DenomOwners, tc.numAddrs) - suite.Equal(tc.total, resp.Pagination.Total) - - if tc.hasNext { - suite.NotNil(resp.Pagination.NextKey) - } else { - suite.Nil(resp.Pagination.NextKey) - } - } else { - suite.Require().Error(err) - } + suite.Require().Error(err) + suite.Require().Nil(resp) }) } diff --git a/x/bank/keeper/send.go b/x/bank/keeper/send.go index fce3008aa8eb..666d335df1b4 100644 --- a/x/bank/keeper/send.go +++ b/x/bank/keeper/send.go @@ -368,7 +368,6 @@ func (k BaseSendKeeper) addCoinsImproved(ctx sdk.Context, addr sdk.AccAddress, a balance := k.GetBalance(ctx, addr, coin.Denom) newBalance := balance.Add(coin) - // err := k.setBalance(ctx, addr, balance, newBalance) err := k.setBalance(ctx, addr, newBalance) if err != nil { return err @@ -444,47 +443,6 @@ func (k BaseSendKeeper) initBalances(ctx sdk.Context, addr sdk.AccAddress, balan // 2 blocks after osmosis first epoch var osmosisFirstEpochHeight = int64(12834361) -// Better add coins implementation for code that is not gas metered. Reduces I/O overhead. -// Used in osmosis epoch. -// Also removes event that should not exist. -// SDK should always use this for teh denom reverse map, but we can't edit right now as that would be a state break. -// Furthermore, this reverse map code should just get deleted. -func (k BaseSendKeeper) setBalanceImproved(ctx sdk.Context, addr sdk.AccAddress, oldBalance sdk.Coin, newBalance sdk.Coin) error { - if !newBalance.IsValid() { - return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, oldBalance.String()) - } - - accountStore := k.getAccountStore(ctx, addr) - denomPrefixStore := k.getDenomAddressPrefixStore(ctx, oldBalance.Denom) - // x/bank invariants prohibit persistence of zero balances - if newBalance.IsZero() { - accountStore.Delete([]byte(newBalance.Denom)) - denomPrefixStore.Delete(address.MustLengthPrefix(addr)) - } else { - amount, err := newBalance.Amount.Marshal() - if err != nil { - return err - } - - accountStore.Set([]byte(newBalance.Denom), amount) - - mustSetDenom := oldBalance.IsZero() - if ctx.BlockHeight() <= osmosisFirstEpochHeight || newBalance.Denom != "uosmo" { - mustSetDenom = true - } - if mustSetDenom { - // Store a reverse index from denomination to account address with a - // sentinel value. - denomAddrKey := address.MustLengthPrefix(addr) - if !denomPrefixStore.Has(denomAddrKey) { - denomPrefixStore.Set(denomAddrKey, []byte{0}) - } - } - } - - return nil -} - // setBalance sets the coin balance for an account by address. func (k BaseSendKeeper) setBalance(ctx sdk.Context, addr sdk.AccAddress, balance sdk.Coin) error { if !balance.IsValid() { @@ -505,13 +463,7 @@ func (k BaseSendKeeper) setBalance(ctx sdk.Context, addr sdk.AccAddress, balance } accountStore.Set([]byte(balance.Denom), amount) - - // Store a reverse index from denomination to account address with a - // sentinel value. - denomAddrKey := address.MustLengthPrefix(addr) - if !denomPrefixStore.Has(denomAddrKey) { - denomPrefixStore.Set(denomAddrKey, []byte{0}) - } + // We deleted denomPrefixStore setting. } return nil