未验证 提交 beb27432 编写于 作者: D Daniel Larimer 提交者: GitHub

Merge pull request #2891 from EOSIO/payment

Producer pay testing - test with 21 producers and a few standbys 
...@@ -116,8 +116,7 @@ ...@@ -116,8 +116,7 @@
"name": "eosio_parameters", "name": "eosio_parameters",
"base": "blockchain_parameters", "base": "blockchain_parameters",
"fields": [ "fields": [
{"name":"max_ram_size", "type":"uint64"}, {"name":"max_ram_size", "type":"uint64"}
{"name":"percent_of_max_inflation_rate", "type":"uint32"}
] ]
},{ },{
"name": "eosio_global_state", "name": "eosio_global_state",
...@@ -127,7 +126,7 @@ ...@@ -127,7 +126,7 @@
{"name":"total_ram_stake", "type":"asset"}, {"name":"total_ram_stake", "type":"asset"},
{"name":"last_producer_schedule_update", "type":"time"}, {"name":"last_producer_schedule_update", "type":"time"},
{"name":"last_pervote_bucket_fill", "type":"uint64"}, {"name":"last_pervote_bucket_fill", "type":"uint64"},
{"name":"eos_bucket", "type":"asset"}, {"name":"pervote_bucket", "type":"asset"},
{"name":"savings", "type":"asset"}, {"name":"savings", "type":"asset"},
{"name":"last_producer_schedule_id", "type":"checksum160"}, {"name":"last_producer_schedule_id", "type":"checksum160"},
{"name":"total_activatied_stake", "type":"int64"} {"name":"total_activatied_stake", "type":"int64"}
......
...@@ -33,7 +33,7 @@ namespace eosiosystem { ...@@ -33,7 +33,7 @@ namespace eosiosystem {
block_timestamp last_producer_schedule_update = 0; block_timestamp last_producer_schedule_update = 0;
uint64_t last_pervote_bucket_fill = 0; uint64_t last_pervote_bucket_fill = 0;
eosio::asset eos_bucket; eosio::asset pervote_bucket;
eosio::asset savings; eosio::asset savings;
checksum160 last_producer_schedule_id; checksum160 last_producer_schedule_id;
...@@ -43,7 +43,7 @@ namespace eosiosystem { ...@@ -43,7 +43,7 @@ namespace eosiosystem {
EOSLIB_SERIALIZE_DERIVED( eosio_global_state, eosio_parameters, (total_ram_bytes_reserved)(total_ram_stake) EOSLIB_SERIALIZE_DERIVED( eosio_global_state, eosio_parameters, (total_ram_bytes_reserved)(total_ram_stake)
(last_producer_schedule_update) (last_producer_schedule_update)
(last_pervote_bucket_fill) (last_pervote_bucket_fill)
(eos_bucket)(savings)(last_producer_schedule_id)(total_activated_stake) ) (pervote_bucket)(savings)(last_producer_schedule_id)(total_activated_stake) )
}; };
struct producer_info { struct producer_info {
...@@ -191,7 +191,7 @@ namespace eosiosystem { ...@@ -191,7 +191,7 @@ namespace eosiosystem {
private: private:
eosio::asset payment_per_block( double rate, const eosio::asset& token_supply, uint32_t num_blocks ); eosio::asset payment_per_block( double rate, const eosio::asset& token_supply, uint32_t num_blocks );
eosio::asset payment_per_vote( const account_name& owner, double owners_votes, const eosio::asset& eos_bucket ); eosio::asset payment_per_vote( const account_name& owner, double owners_votes, const eosio::asset& pervote_bucket );
eosio::asset supply_growth( double rate, const eosio::asset& token_supply, time seconds ); eosio::asset supply_growth( double rate, const eosio::asset& token_supply, time seconds );
......
...@@ -29,11 +29,11 @@ namespace eosiosystem { ...@@ -29,11 +29,11 @@ namespace eosiosystem {
using namespace eosio; using namespace eosio;
/** until activated stake crosses this threshold no new rewards are paid */ /** until activated stake crosses this threshold no new rewards are paid */
if( _gstate.total_activated_stake < 1500000000000 /* 150'000'000'0000 */ ) if( _gstate.total_activated_stake < 150'000'000'0000 )
return; return;
if( _gstate.last_pervote_bucket_fill == 0 ) /// start the presses if( _gstate.last_pervote_bucket_fill == 0 ) /// start the presses
_gstate.last_pervote_bucket_fill = timestamp; _gstate.last_pervote_bucket_fill = current_time();
auto prod = _producers.find(producer); auto prod = _producers.find(producer);
if ( prod != _producers.end() ) { if ( prod != _producers.end() ) {
...@@ -50,9 +50,10 @@ namespace eosiosystem { ...@@ -50,9 +50,10 @@ namespace eosiosystem {
} }
eosio::asset system_contract::payment_per_vote( const account_name& owner, double owners_votes, const eosio::asset& eos_bucket ) { eosio::asset system_contract::payment_per_vote( const account_name& owner, double owners_votes, const eosio::asset& pervote_bucket ) {
eosio::asset payment(0, S(4,EOS)); eosio::asset payment(0, S(4,EOS));
if ( eos_bucket.amount < min_daily_tokens ) { const int64_t min_daily_amount = 100 * 10000;
if ( pervote_bucket.amount < min_daily_tokens ) {
return payment; return payment;
} }
...@@ -74,8 +75,8 @@ namespace eosiosystem { ...@@ -74,8 +75,8 @@ namespace eosiosystem {
} }
total_producer_votes += itr->total_votes; total_producer_votes += itr->total_votes;
running_payment_amount = (itr->total_votes) * double(eos_bucket.amount) / total_producer_votes; running_payment_amount = (itr->total_votes) * double(pervote_bucket.amount) / total_producer_votes;
if ( running_payment_amount < min_daily_tokens ) { if ( running_payment_amount < min_daily_amount ) {
if ( itr->owner == owner ) { if ( itr->owner == owner ) {
to_be_payed = false; to_be_payed = false;
} }
...@@ -85,7 +86,7 @@ namespace eosiosystem { ...@@ -85,7 +86,7 @@ namespace eosiosystem {
} }
if ( to_be_payed ) { if ( to_be_payed ) {
payment.amount = static_cast<int64_t>( (double(eos_bucket.amount) * owners_votes) / total_producer_votes ); payment.amount = static_cast<int64_t>( (double(pervote_bucket.amount) * owners_votes) / total_producer_votes );
} }
return payment; return payment;
...@@ -102,24 +103,29 @@ namespace eosiosystem { ...@@ -102,24 +103,29 @@ namespace eosiosystem {
eosio_assert(current_time() >= prod->last_claim_time + useconds_per_day, "already claimed rewards within a day"); eosio_assert(current_time() >= prod->last_claim_time + useconds_per_day, "already claimed rewards within a day");
} }
auto parameters = _global.get();
const asset token_supply = token( N(eosio.token)).get_supply(symbol_type(system_token_symbol).name() ); const asset token_supply = token( N(eosio.token)).get_supply(symbol_type(system_token_symbol).name() );
const uint32_t secs_since_last_fill = static_cast<uint32_t>( (current_time() - parameters.last_pervote_bucket_fill) / 1000000 ); const uint32_t secs_since_last_fill = static_cast<uint32_t>( (current_time() - _gstate.last_pervote_bucket_fill) / 1000000 );
const asset to_eos_bucket = supply_growth( standby_rate, token_supply, secs_since_last_fill ); const asset to_pervote_bucket = supply_growth( standby_rate, token_supply, secs_since_last_fill );
const asset to_savings = supply_growth( continuous_rate - (perblock_rate + standby_rate), token_supply, secs_since_last_fill ); const asset to_savings = supply_growth( continuous_rate - (perblock_rate + standby_rate), token_supply, secs_since_last_fill );
const asset perblock_pay = payment_per_block( perblock_rate, token_supply, prod->produced_blocks ); const asset perblock_pay = payment_per_block( perblock_rate, token_supply, prod->produced_blocks );
const asset issue_amount = to_eos_bucket + to_savings + perblock_pay; const asset issue_amount = to_pervote_bucket + to_savings + perblock_pay;
const asset pervote_pay = payment_per_vote( owner, prod->total_votes, to_pervote_bucket + _gstate.pervote_bucket );
if ( perblock_pay.amount + pervote_pay.amount == 0 ) {
_producers.modify( prod, 0, [&](auto& p) {
p.last_claim_time = current_time();
});
return;
}
INLINE_ACTION_SENDER(eosio::token, issue)( N(eosio.token), {{N(eosio),N(active)}}, INLINE_ACTION_SENDER(eosio::token, issue)( N(eosio.token), {{N(eosio),N(active)}},
{N(eosio), issue_amount, std::string("issue tokens for producer pay and savings")} ); {N(eosio), issue_amount, std::string("issue tokens for producer pay and savings")} );
const asset pervote_pay = payment_per_vote( owner, prod->total_votes, to_eos_bucket + parameters.eos_bucket ); _gstate.pervote_bucket += ( to_pervote_bucket - pervote_pay );
_gstate.last_pervote_bucket_fill = current_time();
parameters.eos_bucket += ( to_eos_bucket - pervote_pay ); _gstate.savings += to_savings;
parameters.last_pervote_bucket_fill = current_time();
parameters.savings += to_savings;
_global.set( parameters, _self );
INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {N(eosio),N(active)}, INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {N(eosio),N(active)},
{ N(eosio), owner, perblock_pay + pervote_pay, std::string("producer claiming rewards") } ); { N(eosio), owner, perblock_pay + pervote_pay, std::string("producer claiming rewards") } );
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册