iquidus / explorer

An open source block explorer
BSD 3-Clause "New" or "Revised" License
747 stars 1.33k forks source link

How is Coin Supply calculated? #472

Closed rsthomas100 closed 2 years ago

rsthomas100 commented 3 years ago

I have a coin (RSTCoin) that is mined on my Windows computer and displayed via a Windows Wallet. I can list the balance of each address using rstcoin-cli listaddressbalances that shows a total of 1,484,692 coins.

It is also mined on my server. Running rstcoin-cli listaddressbalances on the server shows a total of 1,285,305 coins. The two add up to 2,769,997 coins.

Meanwhile, the Explorer shows 3,992,820 coins. Where did that number come from, and where are the additional 1,222,823 coins located?

joeuhren commented 3 years ago

There are currently 5 supported options that can be used to determine how the coin supply is calculated which you can find in the settings.json file:

  // how to calculate current coin supply
  // COINBASE : total sent from coinbase (PoW)
  // GETINFO : retreive from getinfo api call (PoS)
  // HEAVY: retreive from heavys getsupply api call
  // BALANCES : total of all address balances
  // TXOUTSET : retreive from gettxoutsetinfo api call

The COINBASE and BALANCES options are two similar approaches that use the data available to the explorer database to calculate the total supply.

To retrieve the current supply from the blockchain itself, you can try one of the other options depending on which api calls your coin supports: GETINFO, HEAVY, TXOUTSET.

I would recommend experimenting with those options to determine which setting is the fastest and most accurate for your coin. Keep in mind that you will need to stop the explorer, make the config change, restart the explorer and then run a normal blockchain sync (cd /path/to/explorer && /usr/bin/nodejs scripts/sync.js index update) which will update the supply value right before the sync starts.

uaktags commented 3 years ago

I meant to reply to this previously, my apologies.

To add on to what @joeuhren mentioned and provide the code basis to this:

https://github.com/iquidus/explorer/blob/5f33fea620701db019f4bd4dae28bc0e28a53a67/lib/explorer.js#L393 This is the get_supply command which, depending on your selection, will calculate the supply based on what the Coin's Daemon says.

this value gets stored into the database via https://github.com/iquidus/explorer/blob/5f33fea620701db019f4bd4dae28bc0e28a53a67/lib/database.js#L683-L696, this is how the the value gets displayed via our API.

You can get these values yourself running the same cli/rpc commands.

To answer the question as to why listaddressbalances shows different than what your coin's supply is actually showing, I'd say to have a look at your coin's sourcecode for what this command is actually doing and how its coming with this number. Same thing for how it calculates the supply. One thing I would point out, I'm not sure what you mean by stating that listaddressbalances shows 1 value on your workstation, another value on your server, and then you're looking for where an "additional" amount comes from. The amount in both your workstation and server SHOULD be the same if they're sync'd up to the same height (unless, again, the coin's source code is deriving this number by something else).

uaktags commented 2 years ago

No further response, closing.