Skip to content

Commit

Permalink
Update constants #774
Browse files Browse the repository at this point in the history
  • Loading branch information
theoreticalbts committed Feb 28, 2017
1 parent db378d8 commit 3e46cf2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
4 changes: 2 additions & 2 deletions libraries/chain/database.cpp
Expand Up @@ -3853,7 +3853,7 @@ void database::apply_hardfork( uint32_t hardfork )
{
rfo.name = STEEMIT_POST_REWARD_FUND_NAME;
rfo.last_update = head_block_time();
rfo.content_constant = STEEMIT_CONTENT_CONSTANT_HF17;
rfo.content_constant = STEEMIT_CONTENT_CONSTANT_S_HF17;
rfo.percent_curation_rewards = STEEMIT_1_PERCENT * 25;
rfo.percent_content_rewards = 0;
});
Expand All @@ -3862,7 +3862,7 @@ void database::apply_hardfork( uint32_t hardfork )
{
rfo.name = STEEMIT_COMMENT_REWARD_FUND_NAME;
rfo.last_update = head_block_time();
rfo.content_constant = STEEMIT_CONTENT_CONSTANT_HF17;
rfo.content_constant = STEEMIT_CONTENT_CONSTANT_S_HF17;
rfo.percent_curation_rewards = STEEMIT_1_PERCENT * 25;
rfo.percent_content_rewards = 0;
});
Expand Down
20 changes: 15 additions & 5 deletions libraries/chain/util/reward.cpp
Expand Up @@ -93,11 +93,21 @@ uint128_t calculate_claims( const uint128_t& rshares, const reward_fund_object&
uint128_t result = 0;
if( rf.name == STEEMIT_POST_REWARD_FUND_NAME || rf.name == STEEMIT_COMMENT_REWARD_FUND_NAME )
{
// ( ( r + a )^2 - a^2 ) / ( r + g )
// In this implementation g = 40a
uint128_t rshares_plus_a = rshares + rf.content_constant;
uint128_t rshares_plus_g = rshares + rf.content_constant * STEEMIT_CONTENT_G_CONST;
result = ( rshares_plus_a * rshares_plus_a - rf.content_constant * rf.content_constant ) / rshares_plus_g;
//
// s = rf.content_constant
// alpha = beta * s
// gamma = 2 alpha beta mu
//
uint64_t s = rf.content_constant;
uint64_t two_alpha = (2 * STEEMIT_CONTENT_CONSTANT_BETA_HF17) * s;
uint64_t gamma = (2 * STEEMIT_CONTENT_CONSTANT_BETA_HF17 * STEEMIT_CONTENT_CONSTANT_BETA_HF17 * STEEMIT_CONTENT_CONSTANT_MU_HF17) * s;

// rshares is uint128_t so we don't have to upcast
uint128_t r_squared = rshares * rshares;
uint128_t two_alpha_r = rshares * two_alpha;
uint128_t beta_r_plus_gamma = STEEMIT_CONTENT_CONSTANT_BETA_HF17 * rshares + gamma;

result = ( r_squared + two_alpha_r ) / beta_r_plus_gamma;
}
else
{
Expand Down
6 changes: 4 additions & 2 deletions libraries/protocol/include/steemit/protocol/config.hpp
Expand Up @@ -162,8 +162,10 @@
#define STEEMIT_COMMENT_REWARD_FUND_NAME ("comment")
#define STEEMIT_RECENT_RSHARES_DECAY_RATE (fc::days(30))
#define STEEMIT_CONTENT_CONSTANT_HF0 (uint128_t(uint64_t(2000000000000ll)))
#define STEEMIT_CONTENT_CONSTANT_HF17 (uint64_t(277777777777ll)) // 1E13 / 36
#define STEEMIT_CONTENT_G_CONST (40)
// note, if redefining these constants make sure calculate_claims doesn't overflow
#define STEEMIT_CONTENT_CONSTANT_S_HF17 (uint64_t(1900000000000ll))
#define STEEMIT_CONTENT_CONSTANT_BETA_HF17 1
#define STEEMIT_CONTENT_CONSTANT_MU_HF17 4

// 5ccc e802 de5f
// int(expm1( log1p( 1 ) / BLOCKS_PER_YEAR ) * 2**STEEMIT_APR_PERCENT_SHIFT_PER_BLOCK / 100000 + 0.5)
Expand Down

0 comments on commit 3e46cf2

Please sign in to comment.