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

Add klay_getTotalSupply API #2148

Merged
merged 11 commits into from May 16, 2024
Merged

Add klay_getTotalSupply API #2148

merged 11 commits into from May 16, 2024

Conversation

blukat29
Copy link
Contributor

@blukat29 blukat29 commented May 7, 2024

Proposed changes

  • Add reward.GetTotalReward(num) -> <Minted, BurntFee> which is a lightweight version of reward.GetBlockReward that only returns the total minted and burnt amounts, oblivious of validator staking amounts.
  • Add DB schema AccRewards where
     db.ReadAccRewards(num) = <AccMinted(num), AccBurntFee(num)>
         AccMinted(num) = GenesisTotalSupply + sum(GetTotalReward(x).Minted for x in [1, num])
         AccBurntFee(num) = sum(GetTotalReward(x).BurntFee for x in [1, num])
  • Add the reward.SupplyManager object that maintains AccTotalRewards up to the latest block.
  • Add RPC klay_getTotalSupply(num)
    klay_getTotalSupply(num) = {
        "totalSupply": totalMinted - totalBurnt,
        "totalMinted": AccMinted(num),
        "totalBurnt": (sum of the below),
        "burntFee": AccBurntFee(num),
        "zeroBurn": State(num).GetBalance("0x0"),  # unsupported in Cypress, but return anyway because it's de-facto standard burn address in other chains
        "deadBurn": State(num).GetBalance("0xdead"),  # another de-facto standard burn address
        "kip103Burn": State("latest").Kip103Addr.memo.burnt,   # only if num >= Kip103Block
        "kip160Burn": State("latest").Kip160Addr.memo.burnt,   # only if num >= Kip160Block
    }

Cypress example

> klay.getTotalSupply('latest')
{
  burntFee: "0x28ee933736fa159f39364",
  deadBurn: "0x40bea489f3f8944d93efbd",
  kip103Burn: "0x111d0449fb2a238eca3b1720",
  kip160Burn: "0x0",
  totalBurnt: "0x116051d7b8918bc471c29a41",
  totalMinted: "0x24971a118ccfd6cbe4800000",
  totalSupply: "0x1336c839d43e4b0772bd65bf",
  zeroBurn: "0x0"
}

Types of changes

Please put an x in the boxes related to your change.

  • Bugfix
  • New feature or enhancement
  • Others

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING GUIDELINES doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes ($ make test)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Related issues

Further comments

  • In an instacne with warmed-up EBS volume, it took around 3 hours to accumulate rewards from block 0 to 153,600,000.
  • It's much slower in a cold EBS because of the time reading historic blocks.

@blukat29 blukat29 force-pushed the supply-api branch 4 times, most recently from 51233ef to 5c7cb0a Compare May 8, 2024 07:22
@blukat29 blukat29 self-assigned this May 8, 2024
@blukat29 blukat29 force-pushed the supply-api branch 20 times, most recently from fd37bed to a1bfd7f Compare May 13, 2024 01:48
@blukat29 blukat29 changed the title Add klay_getTotalSupply and klay_getCirculatingSupply API Add klay_getTotalSupply and klay_getTotalBurnt API May 13, 2024
@blukat29 blukat29 force-pushed the supply-api branch 3 times, most recently from 5c5acc4 to 2a95547 Compare May 13, 2024 09:57
@blukat29 blukat29 marked this pull request as ready for review May 13, 2024 13:49
ian0371
ian0371 previously approved these changes May 15, 2024
hyeonLewis
hyeonLewis previously approved these changes May 15, 2024
@ian0371 ian0371 added the need to merge Need to merge for the next time label May 16, 2024
@ian0371 ian0371 dismissed stale reviews from hyeonLewis and themself via 142b17f May 16, 2024 01:52
reward/supply_manager.go Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need to merge Need to merge for the next time
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants