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 <[email protected]>
@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.

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 ⚠️

📢 Thoughts on this report? Let us know!

@sunspirit99
Copy link
Contributor

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
@Kouteki Kouteki added the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Oct 3, 2024
@jefft0 jefft0 removed the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Oct 4, 2024
@jefft0
Copy link
Contributor

jefft0 commented Oct 4, 2024

Removed the "review team" label because this is already reviewed by core devs.

@thinhnx-var
Copy link
Contributor Author

@jefft0 hi Sir.
I think there was not any comments since last change ( all request changes are addressed in new commit). So I think this PR is still need to be reviewed, by you or core team.

@Kouteki Kouteki requested a review from ltzmaxwell October 4, 2024 15:58
Copy link

github-actions bot commented Jan 4, 2025

This PR is stale because it has been open 3 months with no activity. Remove stale label or comment or this will be closed in 3 months.

@github-actions github-actions bot added Stale and removed Stale labels Jan 4, 2025
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.

6 participants