steemit / steem

The blockchain for Smart Media Tokens (SMTs) and decentralized applications.
https://steem.com
Other
1.95k stars 792 forks source link

Invalid net_votes value returned by condenser_api.get_content #3234

Open VIM-Arcange opened 5 years ago

VIM-Arcange commented 5 years ago

condenser_api.get_content return an invalid value for net_voteswhen there are "weight": 0 votes on a post/comment.

Here is an example: author = 'conformity' permlink = 'award-winning-cgi-3d-animated-short-film-le-gouffre-by-lightning-boy-studio-cgmeetup'

Calling get_content() returns:

{
  "id": 67448821,
  "author": "conformity",
  "permlink": "award-winning-cgi-3d-animated-short-film-le-gouffre-by-lightning-boy-studio-cgmeetup",
  ...
  "net_votes": -374,
   ...
}

If you check the "active_votes" array returned, you will notice there are exactly 374 upvotes with "weight": 0 value.

oflyhigh commented 5 years ago

This issue has existed since HF20. And I think it may be caused by "Vote Dust Threshold" which be removed in HF20. There are following codes in /libraries/chain/steem_evaluator.cpp

void hf20_vote_evaluator( const vote_operation& o, database& _db )`
{
....
      _db.modify( comment, [&]( comment_object& c )
      {
         c.net_rshares += rshares;
         c.abs_rshares += abs_rshares;
         if( rshares > 0 )
            c.vote_rshares += rshares;
         if( rshares > 0 )
            c.net_votes++;
         else
            c.net_votes--;
      });
...
}

There is not a issue before HF20, because before HF20 rshares is always greater than 0(upvote) or less than 0(downvote).

But after HF20, due to the removal of "Vote Dust Threshold", rshares can be zero.

   abs_rshares -= STEEM_VOTE_DUST_THRESHOLD;
   abs_rshares = std::max( int64_t(0), abs_rshares );

so right codes should be:

         if( rshares > 0 )
            c.net_votes++;
         else if ( rshares < 0 )
            c.net_votes--;

😀