Skip to content

Commit

Permalink
Fix integration steemit#2787
Browse files Browse the repository at this point in the history
  • Loading branch information
theoreticalbts committed Aug 23, 2018
1 parent 057fce4 commit f69464b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
17 changes: 9 additions & 8 deletions libraries/plugins/rc/rc_curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ void rc_curve_gen_params::validate()const
}

void generate_rc_curve_params(
rc_resource_params& resource_params,
rc_price_curve_params& price_curve_params,
const rd_dynamics_params& resource_dynamics_params,
const rc_curve_gen_params& curve_gen_params )
{
// Fillin curve_params based on computations
Expand Down Expand Up @@ -55,9 +56,9 @@ void generate_rc_curve_params(
// = (a_point_num * decay_per_time_unit * u_point_denom) / (a_point_denom * N * u_point_num ) - (a_point_num * decay_per_time_unit) / (a_point_denom * N)
// = (a_point_num * decay_per_time_unit * u_point_denom - a_point_num * decay_per_time_unit * u_point_num) / (a_point_denom * N * u_point_num)

FC_ASSERT( resource_params.decay_params.decay_per_time_unit > 0 );
FC_ASSERT( resource_dynamics_params.decay_params.decay_per_time_unit > 0 );

uint64_t A_num_cf = uint64_t( curve_gen_params.a_point_num ) * uint64_t( resource_params.decay_params.decay_per_time_unit );
uint64_t A_num_cf = uint64_t( curve_gen_params.a_point_num ) * uint64_t( resource_dynamics_params.decay_params.decay_per_time_unit );
uint64_t A_num = A_num_cf * (curve_gen_params.u_point_denom - curve_gen_params.u_point_num);
uint32_t A_denom = uint32_t( curve_gen_params.a_point_denom ) * uint32_t( curve_gen_params.u_point_num );

Expand All @@ -72,18 +73,18 @@ void generate_rc_curve_params(
// How many places are needed to shift A_1 left until leading 1 bit is in the top bit position of uint64_t?
int8_t shift2 = 63 - boost::multiprecision::detail::find_msb( A_1 );
fc::uint128_t u128_A = A_num;
resource_params.curve_params.shift = uint8_t( shift1+shift2 );
price_curve_params.shift = uint8_t( shift1+shift2 );
// We now know how much to shift A_num so that it's 64 bits, the only thing left to do is calculate A
// at 128-bit precision so we know what the low bits are.

u128_A <<= resource_params.curve_params.shift;
u128_A <<= price_curve_params.shift;
u128_A /= A_denom;
resource_params.curve_params.coeff_a = u128_A.to_uint64();
price_curve_params.coeff_a = u128_A.to_uint64();

fc::uint128_t u128_B = resource_params.pool_eq;
fc::uint128_t u128_B = resource_dynamics_params.pool_eq;
u128_B *= curve_gen_params.inelasticity_threshold_num;
u128_B /= curve_gen_params.inelasticity_threshold_denom;
resource_params.curve_params.coeff_b = u128_B.to_uint64();
price_curve_params.coeff_b = u128_B.to_uint64();
}

} } } //steed::plugins::rc
3 changes: 2 additions & 1 deletion libraries/plugins/rc/rc_curve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ struct rc_curve_gen_params
};

void generate_rc_curve_params(
rc_resource_params& resource_params,
rc_price_curve_params& price_curve_params,
const rd_dynamics_params& resource_dynamics_params,
const rc_curve_gen_params& curve_gen_params
);

Expand Down

0 comments on commit f69464b

Please sign in to comment.