Skip to content

Minting calculations have low precision #36

@scottyeager

Description

@scottyeager

I noticed that the results produced by the minting code, as reflected in the receipts accessed through the receipts API, didn't match an independent calculation of the expected rewards based on the capacity figures. The differences I noticed are small enough that this isn't an urgent issue, but large enough that I think it warrants further investigation.

It's possible to demonstrate the issue with nothing more than the data from the receipts API. Here's a script that recomputes the TFT amount minted for a node based on the CU, SU, and uptime values in the receipt. It then prints the newly computed value along with the original TFT minted value from the receipt.

The following limitations are intentional:

  • Works for DIY only
  • NU calculation isn't implemented
import sys
import requests

REWARD_PER_CU = 2.4
REWARD_PER_SU = 1.0

TFT_SCALE = 1e7
TFT_ENTRY_PRICE = 0.08

STANDARD_PERIOD_DURATION = 2630880

rhash = sys.argv[1]

url_base = "https://alpha.minting.tfchain.grid.tf/api/v1/receipt/"
receipt = requests.get(url_base + rhash).json()["Minting"]

cu_reward = receipt["cloud_units"]["cu"] * REWARD_PER_CU
su_reward = receipt["cloud_units"]["su"] * REWARD_PER_SU
period_duration = STANDARD_PERIOD_DURATION
total_reward_tft = (cu_reward + su_reward) / TFT_ENTRY_PRICE
scaled_reward_tft = total_reward_tft * (receipt["measured_uptime"] / period_duration)
receipt_reward = receipt["reward"]["tft"] / TFT_SCALE

print("Calculated reward is:", scaled_reward_tft, "Receipt reward is:", receipt_reward)

We can run this script with some different receipt hashes to see what happens.

Here's an example that looks good. We expect a bit of precision loss due to minting using integer division, and this seems within acceptable ranges.

$ python check_receipt.py 4f7cc79e1aae9882fbfff3f539768710f429d35c0822b627f1eb3811e6727bdb
Calculated reward is: 3064.51192 Receipt reward is: 3064.5

Here's another example that's more problematic.

$ python check_receipt.py 0fe007734e7094d746e6c0be1bbbc9ea7104b8ddd3db071f5337f4caaf32461c
Calculated reward is: 3063.301175757617 Receipt reward is: 3061.410525

While a difference of 2 TFT is not catastrophic, this looks a lot less like a rounding error.

What's especially weird is that these nodes are basically identical, differing basically only by their uptime.

https://alpha.minting.tfchain.grid.tf/api/v1/receipt/0fe007734e7094d746e6c0be1bbbc9ea7104b8ddd3db071f5337f4caaf32461c

    "measured_uptime": 2629869,
    "tft_connection_price": 80,
    "cloud_units": {
      "cu": 94.200415,
      "su": 19.077308,
      "nu": 0
    },
    "reward": {
      "musd": 244912,
      "tft": 30614105250
    },

https://alpha.minting.tfchain.grid.tf/api/v1/receipt/4f7cc79e1aae9882fbfff3f539768710f429d35c0822b627f1eb3811e6727bdb

    "measured_uptime": 2630880,
    "tft_connection_price": 80,
    "cloud_units": {
      "cu": 94.201519,
      "su": 19.077308,
      "nu": 0
    },
    "reward": {
      "musd": 245160,
      "tft": 30645000000
    },

The difference in CUs is negligible. The difference in rewards for these nodes should therefore be determined by their uptime only. We can also notice that the second receipt has uptime equal to the standard period duration and therefore is precisely 100%.

So this should hold:

reward1 = reward2 * (uptime1 / uptime2)

However:

reward2 * (uptime1 / uptime2)
30645000000 * (2629869 / 2630880)
30633223676.10837

30614105250 = reward1

I don't understand why I can't reproduce the minting calculations based on the values in the receipts, and why the rewards of two nodes with practically identical specs don't seem to scale linearly with their uptimes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions