Skip to content

Commit

Permalink
Merge pull request #759 from steemit/20170106-comment-bandwidth-refactor
Browse files Browse the repository at this point in the history
Refactor comment bandwidth rate limiting to remove possible corner ca…
  • Loading branch information
Michael Vandeberg authored Jan 6, 2017
2 parents eca2ad5 + 4ae7075 commit 99d4ddd
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,18 @@ void comment_evaluator::do_apply( const comment_operation& o )
}

uint16_t reward_weight = STEEMIT_100_PERCENT;
auto post_bandwidth = band->average_bandwidth;

if( _db.has_hardfork( STEEMIT_HARDFORK_0_12__176 ) && o.parent_author == STEEMIT_ROOT_POST_PARENT )
if( o.parent_author == STEEMIT_ROOT_POST_PARENT )
{
auto post_delta_time = std::min( now.sec_since_epoch() - band->last_bandwidth_update.sec_since_epoch(), STEEMIT_POST_AVERAGE_WINDOW );
auto old_weight = ( post_bandwidth * ( STEEMIT_POST_AVERAGE_WINDOW - post_delta_time ) ) / STEEMIT_POST_AVERAGE_WINDOW;
post_bandwidth = ( old_weight + STEEMIT_100_PERCENT );
reward_weight = uint16_t( std::min( ( STEEMIT_POST_WEIGHT_CONSTANT * STEEMIT_100_PERCENT ) / ( post_bandwidth.value * post_bandwidth.value ), uint64_t( STEEMIT_100_PERCENT ) ) );
auto post_bandwidth = band->average_bandwidth;

if( _db.has_hardfork( STEEMIT_HARDFORK_0_12__176 ) )
{
auto post_delta_time = std::min( now.sec_since_epoch() - band->last_bandwidth_update.sec_since_epoch(), STEEMIT_POST_AVERAGE_WINDOW );
auto old_weight = ( post_bandwidth * ( STEEMIT_POST_AVERAGE_WINDOW - post_delta_time ) ) / STEEMIT_POST_AVERAGE_WINDOW;
post_bandwidth = ( old_weight + STEEMIT_100_PERCENT );
reward_weight = uint16_t( std::min( ( STEEMIT_POST_WEIGHT_CONSTANT * STEEMIT_100_PERCENT ) / ( post_bandwidth.value * post_bandwidth.value ), uint64_t( STEEMIT_100_PERCENT ) ) );
}

_db.modify( *band, [&]( account_bandwidth_object& b )
{
Expand Down

0 comments on commit 99d4ddd

Please sign in to comment.