Beem 0.19.54 - Optimizing vote value calculations

in #beem6 years ago

Repository

https://github.com/holgern/beem

New Features

  • What feature(s) did you add?

To understand how my feature works I need to dive into how rewards are calculated in the steem blockchain. Whenever an account votes, the vote actually gets stored with a certain number of rshares in the database. To determine the value of a given number of rshares, you have to get both the recent_claims, the number of currently "active" rshares and the current size of the rewards pool. The formula that needs to be applied to get an estimation for the value is the following:
value = vote_rshares / recent_claims * reward_pool * sbd_price
To read up a bit more about this read the tutorial by steemit for thist
This also was how beem calculated the vote values, until I tweaked that calculation a bit. Because if were to calculate the value of a vote, which has not yet been broadcasted into the blockchain, the rshares of that vote would be missing in the recent_claims causing the upvote to seem bigger than it really is once it has been broadcasted. While the effect of this change is nearly not noticeable in the current Steem environment it has a lot of impact in an environment where one account has most of the steem power and does only vote rarely.
I made some graphs for this when I implemented this to visualize the impact:

This really shows that the higher the potential vote, the higher the impact on its value. But to be honest this graph already is in absurd levels, since @crokkon told me there are about 3e16 rshares being added each day, so this is really not that big of an impact in the current environment.

Another graph to show the same thing: impact gets higher, the bigger the hypothetical upvote is.

To further visualize this, I will show a REPL session checking the upvote value of the @steemit account. One time using my feature, one time without using it.

>>> from beem.account import Account
>>> steemit = Account('steemit')
>>> steemit.get_voting_value_SBD(not_broadcasted_vote=True)
2465.814621646523
>>> steemit.get_voting_value_SBD(not_broadcasted_vote=False)
2474.4767294899793

As you can see even for the biggest account on the blockchain, the difference is only 8 dollars, so it most likely doesn't matter a lot anyways.

I got a little fun fact for ending this point: every downvote is bigger than an upvote of the exact same size. To proof this, I got a little REPL session for you again:

>>> from beem.steem import Steem
>>> stm = Steem()
>>> stm.rshares_to_sbd(1e16, not_broadcasted_vote=True)
13474.605985050803
>>> stm.rshares_to_sbd(-1e16, not_broadcasted_vote=True)
-14010.700287696967
  • How did you implement it/them?

After I knew what I wanted to implement and how that will work, the implementation was rather easy. The first thing I did after looking into the beem code where the vote values get calculated was to fix a missed DRY (Don't Repeat Yourself) case, where the vests_to_sbd function was nearly the same as the rshares_to_sbd function. I changed the vests_to_sbd function to transform the vests to rshares using the built in function, and then transforming these to sbd using the rshares_to_sbd function

Then I went on to actually implement my feature. In fact all I had to do to get it working was to make this little change. In fact I only add the rshares of the vote whose value shall be calculated to the recent_claims. The rest of the changes I did were only changes to make it configurable. I chose the following defaults for the function because of the following reasons:

  1. rshares_to_sbd
    For the rshares_to_sbd function I chose the not_broadcasted_vote parameter to be False by default, since I think that normally users use that function when they e.g. stream votes from the blockchain.
  2. sp_to_sbd vests_to_sbd
    For the sp_to_sbd and vests_to_sbd functions I chose True as the default parameter setting, since I believe that when people use these functions, they rarely try to get the value of an already existing vote, but rather want to know how much an upvote with that much SP / vests would hypothetically be worth.
  3. get_voting_value_SBD
    For the get_voting_value_SBD function of the beem.account module, I also chose True, and I think it is pretty clear now why I chose this.

GitHub Account

https://github.com/flugschwein

Sort:  

Thank you for your contribution. It is a nice tweak. I wonder does Zero SBD print-out rate affect any of these calculations?

+1 for avoid re-inventing the wheel.

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]

Well the SBD print actually does not directly influence these calculations. The post values still get shown/calculated in SBD/USD (should be the same after all), and the SBD print rate magic only happens at payout.

Thank you for your review, @justyy!

So far this week you've reviewed 1 contributions. Keep up the good work!

Congratulations @flugschwein! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Hey, @flugschwein!

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!

Congratulations! This post has been upvoted from the communal account, @minnowsupport, by Flugschwein from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.

If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.

Congratulations @flugschwein! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

Award for the total payout received

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!