-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 proto annotation for deterministic queries #13174
Conversation
I'll generate the code once I get a concept/API ack for namings. |
// | ||
// When set to true, the query can safely be called from within the state | ||
// machine, for example via ADR-033 calls or from CosmWasm contracts. | ||
bool deterministic = 11110001; |
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.
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.
Yeah not quite sure what the right word is
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.
We do need to communicate with the doc string (and possibly the name) that these queries need to do proper gas management. Determinism is necessary but not sufficient for ADR-033
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.
That's a great point!
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.
Added.
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.
Not sure if we should use deterministic, internal or some other name, but this seems like the right idea
Codecov Report
@@ Coverage Diff @@
## main #13174 +/- ##
==========================================
- Coverage 53.73% 53.63% -0.10%
==========================================
Files 652 647 -5
Lines 55349 55194 -155
==========================================
- Hits 29740 29605 -135
+ Misses 23227 23218 -9
+ Partials 2382 2371 -11
|
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 didn't verify all the queries to make sure they are deterministic, so I trust you. But the annotation LGTM!
Yes, me neither TBH. But these are the ones @atheeshp and I will audit through manually, and for each of them, add relevant tests. |
option (google.api.http).get = "/cosmos/bank/v1beta1/balances/{address}/by_denom"; | ||
} | ||
|
||
// AllBalances queries the balance of all coins for a single account. | ||
rpc AllBalances(QueryAllBalancesRequest) returns (QueryAllBalancesResponse) { | ||
option (cosmos.query.v1.deterministic) = true; |
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 would argue this is the type of query that we should be very cautious about exposing to the state machine. Without pagination it very gas intensive.
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 is true. But high gas costs, which smart contract devs should be aware of, is technically orthogonal to determinism. How do we express this to developers?
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.
Not sure.. the main point to communicate with the annotation should be "appropriate for queries from modules" which is both determinism + manageable gas.
I'm assuming this particular query does have proper gas tracking via the store so it would likely just run out of gas. But I do also question the usefulness of these expensive queries. I guess this query is less expensive than querying all holders of a denom (which is what I thought it was), but even there, there is a scenario where a module might want to airdrop to all holders of a coin so I guess that is a valid use case.
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 suppose then cosmos.query.v1.deterministic
is a misnomer
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.
@AmauryM any thoughts?
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.
ACK. Just leave it as-is and we can add warning comments saying gas could be high.
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.
Thinking about this a bit more, I actually think we should rename.
The three of us have the understanding regarding gas consumption, but we can't assume that about future users who might not read the docstring carefully. I think it is safer to use something like module_query_safe
which prompts users to think more carefully about what "safe" means and if they don't know they're likely to check the doc string. Most people think they know what determinism means and then mark a query as such without thinking about other potential issues.
I'm actually thinking of some concrete examples right now where I want to add queries around protobuf file descriptors which are probably deterministic but wouldn't track gas and I would want to mark them explicitly as module_query_safe = false
.
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.
which prompts users to think more carefully about what "safe" means and if they don't know they're likely to check the doc string
Or maybe the opposite might happen: module developer sees module_query_safe = true
on a high-gas query, and assumes it's safe to use, and ends up with unexpected high gas consumption.
If I want the user to check doc strings, I would actully put unsafe_
, or expert_
. unsafe_
wouldn't work here though, it has a different meaning.
I'm not opposed to Bez's idea of having 2 annotations.
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 just want to note again, that "high gas consumption" is relative to the chain. What one chain might consider high, another chain might deem as normal.
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.
Makes sense. Clearly the bigger issue is computation without gas consumption
option (google.api.http).get = "/cosmos/bank/v1beta1/spendable_balances/{address}"; | ||
} | ||
|
||
// TotalSupply queries the total supply of all coins. | ||
rpc TotalSupply(QueryTotalSupplyRequest) returns (QueryTotalSupplyResponse) { | ||
option (cosmos.query.v1.deterministic) = true; |
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.
ditto
Description
Add
option (cosmos.query.v1.deterministic) = true;
to auth, bank and staking queries.ref: #13041
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