Skip to content

Commit

Permalink
Disable DenomOwners tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
ValarDragon committed Jan 5, 2024
1 parent b85d6b8 commit 7d98c6a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 102 deletions.
37 changes: 1 addition & 36 deletions x/bank/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 5 additions & 17 deletions x/bank/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ func (suite *KeeperTestSuite) TestGRPCDenomOwners() {
req: &types.QueryDenomOwnersRequest{
Denom: "foo",
},
expPass: true,
expPass: false,
numAddrs: 0,
hasNext: false,
total: 0,
Expand All @@ -508,7 +508,7 @@ func (suite *KeeperTestSuite) TestGRPCDenomOwners() {
CountTotal: true,
},
},
expPass: true,
expPass: false,
numAddrs: 6,
hasNext: true,
total: 10,
Expand All @@ -522,7 +522,7 @@ func (suite *KeeperTestSuite) TestGRPCDenomOwners() {
CountTotal: true,
},
},
expPass: true,
expPass: false,
numAddrs: 4,
hasNext: false,
total: 10,
Expand All @@ -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)
})
}

Expand Down
50 changes: 1 addition & 49 deletions x/bank/keeper/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Check failure on line 444 in x/bank/keeper/send.go

View workflow job for this annotation

GitHub Actions / Analyze

var `osmosisFirstEpochHeight` is unused (unused)

// 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() {
Expand All @@ -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
Expand Down

0 comments on commit 7d98c6a

Please sign in to comment.