Why SBD print rate is still 1% despite the haircut? Bug report, explanation, and suggestions

in #utopian-io5 years ago (edited)

Project Information

https://github.com/steemit/steem/issues/3184

Expected behavior

  • SBD print rate should be 0% now.

I believe this bug itself must be well-known now, so this is mainly for explanation in detail, and more importantly, some suggestions. This is a very important issue, so it shouldn't be fixed by a temporary measure.

While I'm not sure this is intended or not, get_feed_history() shows current_median_history as the value already discounted by the so-called haircut. I think this is highly confusing and where all the mess begins. You shouldn't do that way.

Suggestions
  • Use non-haircut value for current_median_history for consistency

    • All other real history values are non-haircut values, as you can see on https://api.steemjs.com/get_feed_history. This inconsistency can create lots of confusions, e.g., recent asset value error (steemit.com) / voting value error (busy.org which they still have)
    • Witnesses still need to report non-haircut prices, which again is very inconsistent and confusing. (https://steemd.com/witnesses)
  • Introduce a new variable such as "haircut discount" and show the value on steemd and get_feed_history as well.

    • For instance, https://api.steemjs.com/get_feed_history should show "base": "0.328 SBD", "quote": "1.000 STEEM", "haircut": "0.796"
    • This makes the code much more readable and much less prone to bugs such as the current one.

In reality, it might be already late to change the behavior of current_median_history in the code. Then introduce a new variable. In any case, UI (e.g., steemd.com) should show non-haircut value for the current feed price with haircut discount separately.

Actual behavior

SBD print rate is still 1%.

This bug is due to separate and inconsistent calculations for current_median_history and sbd_print_rate.

The sbd_print_rate is calculated here
https://github.com/steemit/steem/blob/7ebe3f8bddf9e58c943618f55136db6330dd95a0/libraries/chain/database.cpp#L3761-L3783

The first problem is current_median_history is already haircut (which I don't recommend doing so in Expected bahavior), so percent_sbd can never surpass 10%.

The second problem is due to the inflation between the time when current_median_history is calculated and the time when update_virtual_supply() (which updates sbd_print_rate) is called, percent_sbd is always strictly less than 10% just a bit.

I explain this in more detail below.

High-level

update_median_feed();
update_virtual_supply();

clear_null_account_balance();
process_funds();
process_conversions();
process_comment_cashout();
process_vesting_withdrawals();
process_savings_withdraws();
process_subsidized_accounts();
pay_liquidity_reward();
update_virtual_supply();

https://github.com/steemit/steem/blob/7ebe3f8bddf9e58c943618f55136db6330dd95a0/libraries/chain/database.cpp#L3093-L3104

As you can see in the above, update_virtual_supply() (which updates sbd_print_rate) is called twice.

The problem is update_median_feed() limit the current_median_history so that sbd_print_rate at most 10% already.

price min_price( asset( 9 * gpo.current_sbd_supply.amount, SBD_SYMBOL ), gpo.current_supply );

if( min_price > fho.current_median_history )
   fho.current_median_history = min_price;

https://github.com/steemit/steem/blob/7ebe3f8bddf9e58c943618f55136db6330dd95a0/libraries/chain/database.cpp#L3269-L3272

Unless you're very lucky due to floating point precision error, sbd_print_rate is already strictly less than 10% in the first call of update_virtual_supply().

But even if you were very lucky, now process_funds() inflates the supply.

(While there are other functions that change virtual_supply or current_sbd_supply, they don't change them in the direction of the sbd_print_rate increase. So let me skip too much details here.)

Thus, in the second update_virtual_supply(), sbd_print_rate is always strictly less than 10% regardless of your luck :)

How to reproduce

Don't need to explain, since it's always happening now.

Recording Of The Bug

steemd.com

GitHub Account

https://github.com/economicstudio

Sort:  

Hi @blockchainstudio, thanks for your report! Your post ist a great explanation why a 0% SBD print rate cannot be achieved and you've created a GitHub issue. You could have linked the issue here as well. The technical problem with the non-zero print rate was confirmed by TimCliff here, however there's a strong opinion that the economic effect is negligible. You've mentioned floating point rounding errors. To my knowledge, all asset arithmetic involved in these calculations is based on integer and fixed point data types, so there are no floating point effects. But division remainders get lost nevertheless.
The changed median price format was also mentioned in the linked issue. While unexpected for several frontends (and resulting in exceptionally high account values for example), the price as the quotient of base and quote is still correct and I think most frontends fixed their calculations in the meantime.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thanks a lot for your comment. Now I included github issue in my posts. This is my first utopian-io post so I'm not even sure I followed the direction well :)

BTW, floating point isn't my main point at all :) I just mentioned that there is a very tiny chance that the bug may not occur due to floating point precision problem. I know, internal calculation is mostly done by integers, but A/B is basically floating point operation even if both A and B are integers, which may lead to some unavoidable error. Again that's not my main point at all.

I agree that 1% isn't a big issue in practice. But in theory it's a big issue I believe. If one thing doesn't work as intended, who can believe the others work well? And that's why I suggested fixing it very carefully with enough time, not by a temporary measure. I still believe that the current inconsistent and not self-contained feed history is a pretty bad idea. I know Steemit is having a hard time, so maybe they don't have enough resources to handle this. I'm very sorry about it.

I'm not sure if you work for Steemit too or not, but I presume you're close to them. One suggestion is that Steemit should admit that it isn't sustainable without ads. I worked at facebook before (now I'm in the academia) and that's why I have much interests in Steemit. A decentralized SNS/Blog without ads is too unrealistic to me. While Steemit pretends to be decentralized, they are actually very centralized imho. Then why not having ads before it's too late? Let's face the reality.

Hey, I don't work for Steemit and I'm not even close to them. Actually I was just helping out with the Utopian bug-hunting category in this case :) I'm fully aware that the floating point aspects are not your main point and I didn't mean the review to sound that way, just a minor aspect I noticed besides your main message. I'm also very curious to see if/how the issue will be handled!
If you have any questions on Utopian in general, feel free to join our Discord - the link is in my initial comment above. Cheers!

Thanks and cheers! I'll try to make more english posts :) since now even kr community is getting smaller :(

Thank you for your review, @crokkon! Keep up the good work!

짱짱맨 호출에 응답하여 보팅하였습니다.

오늘 독자가 만드는 베스트셀러, 스팀달러 에어드랍 프로모션의 첫번째 도서 판매가 시작되었습니다. 북이오(@bukio)의 [스팀달러 에어드랍] 스팀잇 프리세일 「영어 잘하고 싶니?」를 확인하여, 여러분이 베스트셀러를 만들고 수익을 같이 누리세요.

「영어 잘하고 싶니?」 판매페이지

Hi @blockchainstudio!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 4.223 which ranks you at #2804 across all Steem accounts.
Your rank has improved 4 places in the last three days (old rank 2808).

In our last Algorithmic Curation Round, consisting of 339 contributions, your post is ranked at #58.

Evaluation of your UA score:
  • Some people are already following you, keep going!
  • The readers like your work!
  • Good user engagement!

Feel free to join our @steem-ua Discord server

Hey, @blockchainstudio!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Thank you and I just voted for @utopian-io :)

Coin Marketplace

STEEM 0.31
TRX 0.12
JST 0.034
BTC 64742.01
ETH 3172.49
USDT 1.00
SBD 4.10