Skip to content
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: TotalCoin and TotalCoinKeeper implementation #2671

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

thinhnx-var
Copy link
Contributor

@thinhnx-var thinhnx-var commented Aug 9, 2024

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

Implementation of #2662

  • Implement a new TotalCoinKeeper
  • Implement logics where increasing or decreasing the amount of total coin whenever a token is issued or burned...

implementation of totalCoin
---------

Co-authored-by: ThinhNX <168700277+thinhnx-var@users.noreply.github.com>
@github-actions github-actions bot added 📦 🤖 gnovm Issues or PRs gnovm related 📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ gno.land Issues or PRs gno.land package related labels Aug 9, 2024
@thinhnx-var thinhnx-var changed the title Implement total coins (#8) feat: TotalCoin and TotalCoinKeeper implementation Aug 9, 2024
@thinhnx-var
Copy link
Contributor Author

@leohhhn
Hey Leon I see you have a help wanted label on issue 2662, so lets check this PR out 🚀

Copy link

codecov bot commented Aug 9, 2024

Codecov Report

Attention: Patch coverage is 72.34043% with 26 lines in your changes missing coverage. Please review.

Project coverage is 60.45%. Comparing base (dd2d374) to head (0f1fcd6).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
tm2/pkg/sdk/bank/keeper.go 76.71% 8 Missing and 9 partials ⚠️
gnovm/tests/file.go 46.66% 8 Missing ⚠️
gno.land/pkg/sdk/vm/builtins.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2671      +/-   ##
==========================================
+ Coverage   60.44%   60.45%   +0.01%     
==========================================
  Files         563      564       +1     
  Lines       75159    75224      +65     
==========================================
+ Hits        45431    45478      +47     
- Misses      26341    26352      +11     
- Partials     3387     3394       +7     
Flag Coverage Δ
contribs/gnodev 61.46% <ø> (ø)
contribs/gnofaucet 14.46% <ø> (ø)
gno.land 67.22% <75.00%> (+<0.01%) ⬆️
gnovm 64.46% <46.66%> (-0.01%) ⬇️
misc/genstd 80.54% <ø> (ø)
misc/logos 19.88% <ø> (ø)
tm2 62.08% <77.33%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sunspirit99
Copy link

I like this approach because we don't have to iterate through all accounts every time we query the TotalCoin

@ltzmaxwell
Copy link
Contributor

ltzmaxwell commented Aug 16, 2024

LGTM.
can you fix the CI.

@linhpn99
Copy link
Contributor

linhpn99 commented Aug 16, 2024

LGTM. can you fix the CI.

hey @ltzmaxwell , the CI is failing because some of my additions are not yet covered by tests. I will probably handle this after #2319 is merged. As for the functionality, I think it's ready for review

@@ -128,15 +130,18 @@ func (bank BankKeeper) SubtractCoins(ctx sdk.Context, addr crypto.Address, amt s
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if acc not exist, we can halt here, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's right, this's an exception that shouldn't happen

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

func (tb *testBanker) IssueCoin(addr crypto.Bech32Address, denom string, amt int64) {
coins, _ := tb.coinTable[addr]
sum := coins.Add(std.Coins{{denom, amt}})
tb.coinTable[addr] = sum
tb.totalCoin[denom] += amt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to check overflow/underflow, as what coins.Add/coins.Sub already did.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ltzmaxwell
Copy link
Contributor

CC: @deelawn, @leohhhn for more eyes.


totalCoin, ok := overflow.Sub64(tb.totalCoin[denom], amt)
if !ok {
panic(fmt.Sprintf("totalCoin overflow/underflow for denom %s while removing %d", denom, amt))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: here we can already distinguish whether it's overflow or underflow, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@linhpn99 linhpn99 Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the prev functions i used actually didn't bring panic info

@linhpn99 linhpn99 requested a review from a team as a code owner September 11, 2024 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ gno.land Issues or PRs gno.land package related 📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: In Progress
Status: In Review
Development

Successfully merging this pull request may close these issues.

4 participants