-
Notifications
You must be signed in to change notification settings - Fork 373
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(gnovm): add Coin
constructor and more functionality
#2104
Conversation
b268311
to
10939cc
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2104 +/- ##
==========================================
+ Coverage 49.10% 49.74% +0.64%
==========================================
Files 576 576
Lines 77821 77822 +1
==========================================
+ Hits 38211 38712 +501
+ Misses 36515 35981 -534
- Partials 3095 3129 +34
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
I have some thoughts about this: Coins and their denoms are validated in the TM2 layer. The question is - should we also implement this validation in Gno, for example:
or, is it maybe a better option to not do "double" validation since it spends gas? basically leave the validation and panicking to TM2 instead of the VM? So, a constructor in Gno would be:
Need some input. |
While we're on this topic, I came across this issue I made some time ago: #1676 Thinking about this a bit, we should really make a good, smooth constructor for the One approach that I have is the following (in gnovm/stdlibs/std):
I'm aware that this is not the safest approach, but it's probably the most comfortable to use. With this, you can just do
and its very painless, instead of WDYT? |
If validation isn't conducted within constructor of coin.gno, it'll be deferred to tm2 coin.go, leading to additional gas consumption due to extra operations. However, the efficiency depends on how frequently invalid denominations or amounts are set. This consideration is pivotal in determining the optimal approach. These are just initial thoughts, so I'm not entirely certain. |
@ltzmaxwell thank you for your answer - it's possible that I wasn't fully clear - currently, there is no validation in the If we choose to add validation in My question is the following: should we just not check at the Gno level, and leave the errors & panics to TM2 in this case, exactly to avoid using more gas than needed? I will play around with this and measure the gas usage in both cases. BTW, do you have any opinions on this comment? |
what I see in tm2/pkg/std.coin.go, the validation happens in assume we are going to initiate a new coin with denominations of "Ugnot", which is obviously invalid,
On the other hand, I believe our priorities should be arranged as follows: security takes precedence, followed by readability and maintainability, and finally, gas consumption. |
I like this. |
I did some changes in this PR, starting from wanting to verify that the fix in #2168 did indeed fix the issue we were having here I saw some build issues and started investigating, but essentially stdshim was using math/overflow, which cannot be used right now because it is not in the stdlibWhitelist. (The error was not printed due to a swallowed error; this is fixed by #1695, but that PR is still stuck in review limbo) I changed the stdshim version not to use |
There are still some failing tests, but these seem in "userland" so I'll leave you to fix them |
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 are some txtar tests failing because they're out of gas, due to the fact that adding std
now uses more gas; just bump the count where needed.
@thehowl thanks for helping out. Fixed the tests, as well as @zivkovicmilos's comments. |
Not sure why CI is failing, txtar integration tests are all passing locally. |
Codecov broken? cc @ajnavarro |
) <!-- please provide a detailed description of the changes made in this pull request. --> ## Description This PR ports more functionality from [coin.go](https://github.com/gnolang/gno/blob/master/tm2/pkg/std/coin.go?rgh-link-date=2024-02-27T11%3A01%3A45Z), into Gno (std & stdshim). It will also update the concept & reference docs for Coins. Superseding gnolang#1696 <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 - [x] 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> --------- Co-authored-by: Morgan <[email protected]>
Description
This PR ports more functionality from coin.go, into Gno (std & stdshim). It will also update the concept & reference docs for Coins.
Superseding #1696
Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the description