提交 f138b563 编写于 作者: K Khaled Al-Hassanieh

Use floating point in payment calculations

上级 2ca7ce51
......@@ -53,20 +53,4 @@ namespace eosiosystem {
}
};
std::pair<uint64_t, uint64_t> int_logarithm_one_plus(uint32_t x) {
static const uint64_t denom = 10000;
uint64_t ret = 0;
uint64_t x_power = x;
const uint64_t n = 4;
static const uint64_t ten_power = denom * denom * denom * denom;
for (uint64_t i = 0, p = ten_power; i < n; ++i) {
uint64_t factor = x_power * p / (i+1);
ret += factor;
ret -= 2 * (i % 2) * factor;
x_power *= x;
p /= denom;
}
return std::make_pair(ret / (denom * denom * denom), denom);
}
}
......@@ -19,6 +19,7 @@
#include <algorithm>
#include <array>
#include <cmath>
namespace eosiosystem {
using eosio::indexed_by;
......@@ -233,9 +234,10 @@ namespace eosiosystem {
static system_token_type payment_per_block(uint32_t percent_of_max_inflation_rate) {
const system_token_type token_supply = currency::get_total_supply();
const auto inflation_rate = max_inflation_rate * percent_of_max_inflation_rate;
const auto& inflation_ratio = int_logarithm_one_plus(inflation_rate);
return (token_supply * inflation_ratio.first) / (inflation_ratio.second * blocks_per_year);
const double annual_rate = double(max_inflation_rate * percent_of_max_inflation_rate) / double(10000);
double continuous_rate = std::log1p(annual_rate);
uint64_t payment = static_cast<uint64_t>((continuous_rate * double(token_supply.quantity)) / double(blocks_per_year));
return (system_token_type(payment));
}
static void update_elected_producers(time cycle_time) {
......
......@@ -1054,7 +1054,7 @@ BOOST_FIXTURE_TEST_CASE( proxy_actions_affect_producers, eosio_system_tester ) t
} FC_LOG_AND_RETHROW()
BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester) try {
issue( "alice", "100000.0000 EOS", config::system_account_name );
issue( "alice", "1000000.0000 EOS", config::system_account_name );
fc::variant params = producer_parameters_example(50);
vector<char> key = fc::raw::pack(get_public_key(N(alice), "active"));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册