TotalSupply API partially works even when some information isn't available.
When the state trie isn't available at the given block (e.g. pruning node), do not return zeroBurn, deadBurn, totalBurnt, totalSupply. Not returning totalSupply to prevent misinformation.
When the TreasuryRebalance (KIP-103 or KIP-160) has been executed but the memo is not stored via the finalizeContract() function, do not return kip103Burn and/or kip160Burn, totalBurnt, totalSupply. Not returning totalSupply to prevent misinformation.
> klay.getTotalSupply(1)
{
burntFee: "0x0",
deadBurn: "0x0",
error: "cannot determine rebalance (kip103, kip160) burn amount: no contract code at given address\ncannot determine rebalance (kip103, kip160) burn amount: no contract code at given address",
kip103Burn: null,
kip160Burn: null,
number: "0x1",
totalBurnt: null,
totalMinted: "0x446c3b15f9926687d2c40534fdb564000000000000",
totalSupply: null,
zeroBurn: "0x0"
}
But don't worry. Regardless of the requested block, the API reads the memo from the latest block. Once the memo is stored at some point, the previous block's total supply also shows up correctly.
In all cases, the API additionally prints the block number
Please put an x in the boxes related to your change.
[x] 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.
Proposed changes
Harden the
kaia_getTotalSupply
API added in https://github.com/klaytn/klaytn/pull/2148.TotalSupply API partially works even when some information isn't available.
When the state trie isn't available at the given block (e.g. pruning node), do not return
zeroBurn, deadBurn, totalBurnt, totalSupply
. Not returning totalSupply to prevent misinformation.When the TreasuryRebalance (KIP-103 or KIP-160) has been executed but the
memo
is not stored via thefinalizeContract()
function, do not returnkip103Burn and/or kip160Burn, totalBurnt, totalSupply
. Not returning totalSupply to prevent misinformation.memo
is stored at some point, the previous block's total supply also shows up correctly.In all cases, the API additionally prints the block number
Types of changes
Please put an x in the boxes related to your change.
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.
$ make test
)Related issues
https://github.com/klaytn/klaytn/issues/1617
Further comments
Originally posted by @blukat29 in https://github.com/klaytn/klaytn/pull/2178