alexdovzhanyn / elixium_core

A privacy-preserving decentralized application network
https://www.elixiumnetwork.org/
281 stars 37 forks source link

Replace decimal based representation of UTXO amount with integer based Ions #92

Closed alexdovzhanyn closed 5 years ago

alexdovzhanyn commented 5 years ago

Solves #91. Removes Decimal as a dependency, fixes tests, and uses scale of 1/10,000,000 for Elixir/Ion. UTXO amounts are only stored as ions.

Due to the shift from decimal to ions, we lose some precision when calculating block rewards, since we now have precision to 7 decimal places with ions, whereas Decimal was able to have a much higher precision. This isn't a big issue (tradeoff is that ions can be represented with fewer bits), but it does mean that our way of calculating block rewards was skewed, meaning that the total supply of elixir tokens was shifted down to 999999999.8686 rather than 1 billion. To keep the amount of total tokens as close to 1 billion as possible, I shifted the emission algorithm a bit:

Where x is total token supply, t is block at full emission, i is block index, and s is the sigma of the total_token_supply, the Smooth emission algorithm is as follows: Round(((x 10,000,000) max{0, t - i}) / s) (+1 if i % 172 = 0)

This brings us much closer to 1 billion total token supply, with a total of 1,000,000,000.0000028

Wallet, node, and miner need to be updated accordingly.