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

reward: SupplyManager reaccumulates from nearest persisted AccReward #62

Merged
merged 2 commits into from
Aug 9, 2024

Conversation

blukat29
Copy link
Contributor

@blukat29 blukat29 commented Aug 9, 2024

Proposed changes

  • Address the issue where an archive node not serving kaia_getTotalSupply for non-128-multiple blocks.
  • Cause
    • SupplyManager writes AccReward every BlockInterval. The intention was to make full nodes write every BlockInterval whereas archive nodes write every 1 block.
    • In reality, archive nodes may set BlockInterval == 128 (default) because it didn't matter so far. The writeStateTrie loop ignores BlockInterval when gcmode is archive.
    • Therefore, SupplyManager didn't store AccReward every 1 block. Rather it stored every 128 blocks in archive nodes with default settings.
  • Fix
    • Have SupplyManager calculate AccReward for any given block, by re-accumulating from the nearest persisted AccReward.
    • Note that the re-accumulation only requires blocks and receipts which should be available in an archive node.

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 read the CLA and signed by comment I have read the CLA Document and I hereby sign the CLA in first time contribute
  • 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

  • Prepare a Kairos archive node
> admin.nodeConfig.TrieBlockInterval
128
> num = 157740851
> num % 128
51
> eth.getBalance("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", num)
49924765500000000000
> kaia.getTotalSupply(num)
Error: accumulated reward not stored
	at web3.js:6812:9(39)
	at send (web3.js:5223:62(29))
	at <eval>:1:20(3)
> eth.getBalance("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", num)
49924765500000000000
> kaia.getTotalSupply(num)
{
  burntFee: "0x899be299255df6283350",
  deadBurn: "0x35a29f8b3e27ba28cd",
  kip103Burn: "0x6a15eef7e3a354cf657913",
  kip160Burn: "-0xbf82646906be407e42a4800",
  number: "0x966ef33",
  totalBurnt: "-0xb8d8029a1f5dc275c85f9f6",
  totalMinted: "0x446c3b15f9926687d2c87232559657244007b80000",
  totalSupply: "0x446c3b15f9926687d2d3ffb27f384d0067643df9f6",
  zeroBurn: "0x65c7159b3ef9a5c78da"
}

Fix the side effect s.chain.Config().X = Y breaks other tests
reward/supply_manager.go Show resolved Hide resolved
reward/supply_manager.go Outdated Show resolved Hide resolved
@blukat29 blukat29 merged commit a8b7a99 into kaiachain:dev Aug 9, 2024
11 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 9, 2024
@blukat29 blukat29 deleted the supply-api-reacc branch August 21, 2024 11:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants