-
Notifications
You must be signed in to change notification settings - Fork 378
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
[Docs] Minting coins in Render()
#1523
Comments
Maybe we can disable calling Follow up: So maybe the best solution here is no solution and the take away is don't put anything in your |
This issue extends beyond the current problem. The code can be executed on Render, which will cause further confusion. var counter
func Render() string {
counter++
return fmt.Sprintf("%d", counter)
} This will increment the counter before displaying, but the change will not be applied. I believe the same applies to the banker (incrementation is done in memory but not applied on disk). If it's not the case, then we have a bug. In my view, the issue is more about ambiguity than performance. I suggest creating a I recommend checking out this realm that heavily utilizes Render modification: https://staging.gno.land/r/demo/tamagotchi. |
@moul I was just taking a closer look at this. Calling So do we need to make changes to prevent any |
Is there any action to take or can we close this? |
Solution proposed by @moul on our test4 alignment call:
|
Moving to Triage until we choose a solution |
We're going with option 2: Render stays as it currently is. We just need to add a disclaimer in the documentation. |
<!-- please provide a detailed description of the changes made in this pull request. --> ## Description After discussions in #1523, we decided to add a disclaimer to `maketx call` which will let people know that a `call` to `Render()` will appliy state changes. Closes: #1523 <details><summary>Contributors' checklist...</summary> - [x] Added new tests, or not needed, or not feasible - [x] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [x] Updated the official documentation or not needed - [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [x] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details>
Description
You can mint coins via the Banker in the Render function of a Realm (or package!) currently. This is an issue because the Render function is supposed to be called a lot, and by minting coins, we are changing the state (a costly operation).
Render()
should be read-only.Deploy the following code under
p/demo/mint
:The point of this issue is to discuss the distinction between functions that change the state, and functions that do not change the state at all - and their respective gas costs. As you might know, Ethereum's approach is to have normal, gas-costing functions, and view functions that just read the state of the contract.
In order to not diverge from standard Go keywords (ie adding keywords to differentiate these), would it be possible to have the first line of the function define what type of function it is, similar to how you can define a helper in Go tests with
t.Helper()
?cc @moul @zivkovicmilos @MichaelFrazzy @thehowl
The text was updated successfully, but these errors were encountered: