goat-systems/tzpay

Payout net calculations slightly below expected values

Closed this issue · 4 comments

If I call the report subcommand for cycle 103:

./payman report --delegate=tz1Z3KCf8CLGAYfvVWPEr562jDDyWkwNF7sT --cycle=103 --node=https://mainnet.tezrpc.me --fee=0.1 --payout-min=10000

One of the values I receive in the report is the following:

+--------------------------------------+-----------+------------+-----------+------------+
|               ADDRESS                |   SHARE   |   GROSS    |    FEE    |    NET     |
+--------------------------------------+-----------+------------+-----------+------------+
| KT1SZW1BpgPibbiRc9aqtqXeKKh4fe56XyZB |  1.571122 |   2.592351 |  0.259235 |   2.333116 |
...

This suggests that for delegator KT1SZW1BpgPibbiRc9aqtqXeKKh4fe56XyZB the following are the calculated values for cycle 103:

Gross Payout: 2.592351 ꜩ
Net Payout: 2.333116 ꜩ

However, if you call the TzScan API as follows:

http://api6.tzscan.io/v1/rewards_split/tz1Z3KCf8CLGAYfvVWPEr562jDDyWkwNF7sT?cycle=103&p=0

You will get the following values:

{
  "delegate_staking_balance":"210040925181",
  "delegators_nb":29,
  "delegators_balance":[
    [
      {
        "tz":"KT1SZW1BpgPibbiRc9aqtqXeKKh4fe56XyZB"
      },
      "3300000000"
    ],
    ...
  ],
  "blocks_rewards":80000000,
  "endorsements_rewards":85000000,
  "fees":12293,
  "future_blocks_rewards":0,
  "future_endorsements_rewards":0,
  "gain_from_denounciation":0,
  "lost_deposit_from_denounciation":0,
  "lost_rewards_denounciation":0,
  "lost_fees_denounciation":0,
  "revelation_rewards":0,
  "lost_revelation_rewards":0,
  "lost_revelation_fees":0
}

As we can see, this delegator should receive the following percentage of all rewards and fees:

3300000000 / 210040925181 = 0.01571122388 = %1.571122388

We can also see that the total rewards and fees accrued by the baker for this round are as follows:

80000000 + 85000000 + 12293 = 165012293

Finally, we can calculate that the gross payout for this delegator should be as follows:

0.01571122388 * 165012293 = 2592545.07827516

And by removing the bakers fee (10%), we get:

2592545.07827516 * 0.9 = 233329057044764.4

Finally, by switching back to XTZ and rounding to 6 decimal places, we get:

Gross Payout: 2.592545 ꜩ
Net Payout: 2.333291 ꜩ

Thus, we can see that there is a small discrepancy between the payouts that Payman is calculating and the values we manually calculated (0.000194 ꜩ discrepancy for the Gross Payout, or 0.000175 ꜩ of the Net Payout). Additionally, we can see that Baking Bad also shows an expected payout of 2.333291 ꜩ:

Baking Bad Calculated Payout

This payout discrepancy bug is present in all entries returned by a report.

Thanks for reporting! A couple thoughts, it could be a discrepancy between how tzscan.io's backend rounds to how GoLangs stdlib rounds. I do a lot of string conversions because the Tezos API uses strings instead of integers to display rewards, It's possible there's some data loss in there. What do you think?

This could probably be resolved easier by creating test cases that ping tzscan and then internally calculate, and compare. So I'm going to write those tests first.

@DefinitelyNotAGoat Yes, I agree that it seems like a rounding issue—probably a discrepancy arising from those conversations. I'll take a look also, happy to help with these tests 👍

This is resolved with the switch to TZKT.