-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for spendable balances gRPC query #11417
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we get a test for this please 😄
I was thinking why not have spendable coins, vested coins, staked coins and unbonding coins under one response, https://github.com/cosmos/cosmos-sdk/blob/master/x/bank/types/query.pb.go#L78. Something like:
we could also add bonded and unbending balance here too. seems some what simpler than introducing a new endpoint for this. |
That would require more work and proto types. Also, that info is already available via other endpoints. That's also not backwards compatible. |
the spendable would be this pr, not in a new sturct? |
It depends, are you proposing to introduce a new type or modify the existing balances gRPC query? |
modify existing |
I suppose I would also be in favor of that, but:
This is why I propose we just keep it simple and have a spendable query :) |
@AmauryM or @robert-zaremba thoughts or any opposition to this new handler? If not, I'll merge. |
lgtm
but it's better to wait for the response. |
I think the failing tests are from this PR #10988 |
@marbar3778 are you gonna fix that? How did that PR land in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useful query. One nit to see if we can optimize the store flow.
it looks to be non deterministic. I was having issues replicating it locally, seems GitHub actions had it pass once and it worked |
spendable := k.SpendableCoins(sdkCtx, addr) | ||
|
||
for _, c := range balances { | ||
result = append(result, sdk.NewCoin(c.Denom, spendable.AmountOf(c.Denom))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function can be called by other transaction. So, let's charge extra gas here. Eg 20gas per iteration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Charge gas? This is a query, not a transaction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know. But it can be called from a transaction, in other words, a RPC Msg method, when running can do a query call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't follow?
These methods are for queries only. In fact, in a subsequent PR, I'll be removing these from the Keeper
entirely, in favor of a dedicated Querier
(Example). All modules should follow this approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look at this example: https://github.com/regen-network/regen-ledger/blob/master/x/ecocredit/server/msg_server.go#L718 - The rpc Buy
will call bank.SpendableCoins
.
Technically we can create a QueryClient
of other module, and use it when processing a transaction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically we can create a QueryClient of other module, and use it when processing a transaction.
That doesn't make any sense. Gas and txs are not involved here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably I didn't express myself well enough. Here is the snippet (didn't test it but I believe it's possible):
/// in authz Grant Msg function
// let's imagine a scenario where we want to check spendable coins
func (k Keeper) Grant(goCtx context.Context, msg *authz.MsgGrant) (*authz.MsgGrantResponse, error) {
...
bc := banktypes.NewQueryClient(ctx)
resp, err := bc.SpendableBalances(ctx, types.QuerySpendableBalancesRequest{...})
....
BTW - I think this is general discussion if we should check if we should consider checking if context provides a gas meter in queries and charge gas (so feel free to merge)
* updates * cl++ * tests++ * updates * updates (cherry picked from commit 9e1ec7b) # Conflicts: # CHANGELOG.md # x/bank/keeper/grpc_query_test.go # x/bank/keeper/keeper_test.go # x/bank/types/query.pb.go
Description
It's often useful for users to know their current spendable balance. Currently there is only an endpoint that gives you your total balance and an endpoint that gives you full account details. In the context of vesting accounts, it is not possible to know what part of the balance is "spendable" without doing manual arithmetic. This PR adds a query to provide that data directly.
It operates the same way as all balance query does, but filters the balance value by what's spendable.
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change