Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blockchain stops when SBD supply is 0 #3258

Closed
joticajulian opened this issue Mar 13, 2019 · 2 comments · Fixed by #3319
Closed

Blockchain stops when SBD supply is 0 #3258

joticajulian opened this issue Mar 13, 2019 · 2 comments · Fixed by #3319

Comments

@joticajulian
Copy link
Contributor

joticajulian commented Mar 13, 2019

This issue is related with the function update_median_feed() in database.cpp.

Expected behavior

If the SBD supply is 0 the blockchain takes the median feed price from witnesses.

Actual behavior

When the SBD supply is 0 everyone stop producing blocks.

How to reproduce

  • Start a testnet a new chain with 21 witnesses.
  • Set a feed price on at least 7 witnesses.
  • Wait 1 hour for the update of the median feed price.
  • All witnesses stop producing blocks with this error:
Failed to push new block:
10 assert_exception: Assert Exception
base.amount > share_type(0): 
    {}
    asset.cpp:377 validate

    {"base":{"amount":"0","precision":3,"nai":"@@000000013"},"quote":{"amount":"250037129","precision":3,"nai":"@@000000021"}}
    asset.cpp:380 validate
Got exception while generating block:
10 assert_exception: Assert Exception
base.amount > share_type(0): 
    {}
    asset.cpp:377 validate

    {"base":{"amount":"0","precision":3,"nai":"@@000000013"},"quote":{"amount":"250037129","precision":3,"nai":"@@000000021"}}
    asset.cpp:380 validate

    {}
    database.cpp:3128 update_median_feed

Reason

The update_median_feed() function updates the feed price taking into account two things:

  • The median price given by the witnesses, and
  • The haircut price to force SBD to remain below 10% of the virtual supply.

However, if the SBD supply is zero, the haircut price throws an exception because both quote and base have to be greater than zero (to prevent division by 0). No witness can create the new block and therefore the blockchain freezes.

Line in question:

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

Low vulnerability

The unique way to reach 0 SBD in the mainnet is stopping printing SBD and converting all of them into STEEM, which is very unlikely. However, it becomes more relevant on testnets or private blockchains.

Solution

Only calculate the haircut price if the SBD supply is greater than zero, because in this case there is no risk of debt, the ratio is 0%.

@joticajulian
Copy link
Contributor Author

I realized that on testnets it is skipped by skip_price_feed_limit_check. So this bug is for new chains in non testnet mode.

@joticajulian
Copy link
Contributor Author

Just for the record:
This issue is related to PR #1350, where validate() was introduced in the explicit constructor of the price (version 0.19.10).
This means that in 0.19.6 (and before) there is no validation and then the blockchain does not throw an exception for this issue.

mvandeberg pushed a commit that referenced this issue May 21, 2019
Closes #3258 Fix update_median_feed when total sbd is 0
mvandeberg pushed a commit that referenced this issue May 21, 2019
Closes #3258 Fix update_median_feed when total sbd is 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant