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

Fixed producer pay and delegatebw, code cleaning - #1889

上级 e6496ca4
/**
* @file
* @copyright defined in eos/LICENSE.txt
*/
#pragma once
#include <eosiolib/eosio.hpp>
//#include <eosiolib/generic_currency.hpp>
#include <eosiolib/eosio.hpp>
#include <eosiolib/multi_index.hpp>
#include <eosiolib/privileged.hpp>
#include <eosiolib/singleton.hpp>
......@@ -11,22 +14,15 @@
namespace eosiosystem {
eosio::token _system_token(N(eosio.system));
template<account_name SystemAccount>
class common {
public:
static constexpr account_name system_account = SystemAccount;
// typedef eosio::generic_currency< eosio::token<system_account,S(4,EOS)> > currency;
// typedef typename currency::token_type system_token_type;
// static constexpr eosio::symbol_type system_symbol(S(4,EOS));
static constexpr uint32_t max_inflation_rate = 5; // 5% annual inflation
static constexpr uint32_t max_inflation_rate = 5; // 5% annual inflation
static constexpr uint32_t blocks_per_producer = 12;
static constexpr uint32_t seconds_per_day = 24 * 3600;
static constexpr uint32_t days_per_4years = 1461;
static constexpr uint32_t blocks_per_producer = 12;
static constexpr uint32_t seconds_per_day = 24 * 3600;
static constexpr uint32_t days_per_4years = 1461;
struct eosio_parameters : eosio::blockchain_parameters {
uint64_t max_storage_size = 10 * 1024 * 1024;
......
......@@ -7,10 +7,7 @@
#include "voting.hpp"
#include <eosiolib/eosio.hpp>
//#include <eosiolib/token.hpp>
#include <eosiolib/print.hpp>
//#include <eosiolib/generic_currency.hpp>
#include <eosiolib/datastream.hpp>
#include <eosiolib/serialize.hpp>
#include <eosiolib/multi_index.hpp>
......@@ -35,16 +32,11 @@ namespace eosiosystem {
static constexpr account_name system_account = SystemAccount;
static constexpr time refund_delay = 3*24*3600;
static constexpr time refund_expiration_time = 3600;
// using currency = typename common<SystemAccount>::currency;
// using system_token_type = typename common<SystemAccount>::system_token_type;
using eosio_parameters = typename common<SystemAccount>::eosio_parameters;
using global_state_singleton = typename common<SystemAccount>::global_state_singleton;
struct total_resources {
account_name owner;
// typename currency::token_type net_weight;
// typename currency::token_type cpu_weight;
// typename currency::token_type storage_stake;
asset net_weight;
asset cpu_weight;
asset storage_stake;
......@@ -62,9 +54,6 @@ namespace eosiosystem {
struct delegated_bandwidth {
account_name from;
account_name to;
// typename currency::token_type net_weight;
// typename currency::token_type cpu_weight;
// typename currency::token_type storage_stake;
asset net_weight;
asset cpu_weight;
asset storage_stake;
......@@ -79,7 +68,6 @@ namespace eosiosystem {
struct refund_request {
account_name owner;
time request_time;
// typename currency::token_type amount;
eosio::asset amount;
uint64_t primary_key()const { return owner; }
......@@ -123,7 +111,6 @@ namespace eosiosystem {
eosio_assert( del.stake_net_quantity.amount >= 0, "must stake a positive amount" );
eosio_assert( del.stake_storage_quantity.amount >= 0, "must stake a positive amount" );
// system_token_type total_stake = del.stake_cpu_quantity + del.stake_net_quantity + del.stake_storage_quantity;
asset total_stake = del.stake_cpu_quantity + del.stake_net_quantity + del.stake_storage_quantity;
eosio_assert( total_stake.amount > 0, "must stake a positive amount" );
......@@ -134,23 +121,16 @@ namespace eosiosystem {
if ( 0 < del.stake_storage_quantity.amount ) {
auto parameters = global_state_singleton::exists() ? global_state_singleton::get()
: common<SystemAccount>::get_default_parameters();
#warning "FIX THIS!"
// auto token_supply = currency::get_total_supply();
asset token_supply(1000000000, S(4,EOS));
eosio::symbol_name sym = eosio::symbol_type(S(4,EOS)).name();
eosio::token::stats stats_tbl(N(eosio.token), sym);
const auto& st = stats_tbl.get(sym);
const eosio::asset token_supply = st.supply;
//make sure that there is no posibility of overflow here
// uint64_t storage_bytes_estimated = ( parameters.max_storage_size - parameters.total_storage_bytes_reserved )
// * parameters.storage_reserve_ratio * system_token_type(del.stake_storage_quantity)
// / ( token_supply - parameters.total_storage_stake ) / 1000 /* reserve ratio coefficient */;
uint64_t storage_bytes_estimated = ( parameters.max_storage_size - parameters.total_storage_bytes_reserved )
* parameters.storage_reserve_ratio * del.stake_storage_quantity
/ ( token_supply - parameters.total_storage_stake ) / 1000 /* reserve ratio coefficient */;
// storage_bytes = ( parameters.max_storage_size - parameters.total_storage_bytes_reserved - storage_bytes_estimated )
// * parameters.storage_reserve_ratio * system_token_type(del.stake_storage_quantity)
// / ( token_supply - del.stake_storage_quantity - parameters.total_storage_stake ) / 1000 /* reserve ratio coefficient */;
storage_bytes = ( parameters.max_storage_size - parameters.total_storage_bytes_reserved - storage_bytes_estimated )
* parameters.storage_reserve_ratio * del.stake_storage_quantity
/ ( token_supply - del.stake_storage_quantity - parameters.total_storage_stake ) / 1000 /* reserve ratio coefficient */;
......@@ -203,8 +183,6 @@ namespace eosiosystem {
}
//set_resource_limits( tot_itr->owner, tot_itr->storage_bytes, tot_itr->net_weight.quantity, tot_itr->cpu_weight.quantity );
// currency::inline_transfer( del.from, SystemAccount, total_stake, "stake bandwidth" );
eosio::action act( eosio::permission_level{del.from,N(active)}, N(eosio.token), N(inlinetransfer),
std::make_tuple( del.from, N(eosio), total_stake, std::string("stake bandwidth") ) );
......@@ -230,7 +208,6 @@ namespace eosiosystem {
eosio_assert( dbw.cpu_weight >= del.unstake_cpu_quantity, "insufficient staked cpu bandwidth" );
eosio_assert( dbw.storage_bytes >= del.unstake_storage_bytes, "insufficient staked storage" );
// system_token_type storage_stake_decrease = system_token_type(0);
eosio::asset storage_stake_decrease(0, S(4,EOS));
if ( 0 < del.unstake_storage_bytes ) {
storage_stake_decrease = 0 < dbw.storage_bytes ?
......@@ -243,9 +220,6 @@ namespace eosiosystem {
global_state_singleton::set( parameters );
}
// auto total_refund = system_token_type(del.unstake_cpu_quantity)
// + system_token_type(del.unstake_net_quantity) + storage_stake_decrease;
eosio::asset total_refund = del.unstake_cpu_quantity + del.unstake_net_quantity + storage_stake_decrease;
eosio_assert( total_refund.amount > 0, "must unstake a positive amount" );
......@@ -309,7 +283,6 @@ namespace eosiosystem {
// allow people to get their tokens earlier than the 3 day delay if the unstake happened immediately after many
// consecutive missed blocks.
// currency::inline_transfer( SystemAccount, req->owner, req->amount, "unstake" );
{
eosio::action act( eosio::permission_level{N(eosio),N(active)}, N(eosio.token), N(inlinetransfer),
std::make_tuple( N(eosio), req->owner, req->amount, std::string("unstake") ) );
......
......@@ -6,10 +6,8 @@
#include "delegate_bandwidth.hpp"
#include "native.hpp"
#include <eosiolib/optional.hpp>
//#include <eosiolib/generic_currency.hpp>
#include <eosiolib/optional.hpp>
#include <eosio.token/eosio.token.hpp>
namespace eosiosystem {
......@@ -42,8 +40,6 @@ namespace eosiosystem {
using native<SystemAccount>::on;
using pe = voting<SystemAccount>;
using db = delegate_bandwidth<SystemAccount>;
// using currency = typename common<SystemAccount>::currency;
// using system_token_type = typename common<SystemAccount>::system_token_type;
using producers_table = typename pe::producers_table;
using global_state_singleton = typename voting<SystemAccount>::global_state_singleton;
static const uint32_t max_inflation_rate = common<SystemAccount>::max_inflation_rate;
......@@ -127,7 +123,7 @@ namespace eosiosystem {
if( prod->last_rewards_claim > 0 ) {
eosio_assert(now() >= prod->last_rewards_claim + seconds_per_day, "already claimed rewards within a day");
}
// system_token_type rewards = prod->per_block_payments;
eosio::asset rewards = prod->per_block_payments;
auto idx = producers_tbl.template get_index<N(prototalvote)>();
auto itr = --idx.end();
......@@ -153,7 +149,7 @@ namespace eosiosystem {
if (is_among_payed_producers && total_producer_votes > 0) {
if( global_state_singleton::exists() ) {
auto parameters = global_state_singleton::get();
// auto share_of_eos_bucket = system_token_type( static_cast<uint64_t>( (prod->total_votes * parameters.eos_bucket.quantity) / total_producer_votes ) ); // This will be improved in the future when total_votes becomes a double type.
// This will be improved in the future when total_votes becomes a double type.
auto share_of_eos_bucket = eosio::asset( static_cast<int64_t>( (prod->total_votes * parameters.eos_bucket.amount) / total_producer_votes ) );
rewards += share_of_eos_bucket;
parameters.eos_bucket -= share_of_eos_bucket;
......
......@@ -3,13 +3,11 @@
* @copyright defined in eos/LICENSE.txt
*/
#pragma once
#include "common.hpp"
#include <eosiolib/eosio.hpp>
//#include <eosiolib/token.hpp>
#include <eosiolib/print.hpp>
//#include <eosiolib/generic_currency.hpp>
#include <eosiolib/datastream.hpp>
#include <eosiolib/serialize.hpp>
#include <eosiolib/multi_index.hpp>
......@@ -17,8 +15,6 @@
#include <eosiolib/singleton.hpp>
#include <eosiolib/transaction.hpp>
#include <eosio.token/eosio.token.hpp>
#include <algorithm>
#include <array>
#include <cmath>
......@@ -35,10 +31,7 @@ namespace eosiosystem {
template<account_name SystemAccount>
class voting {
public:
static constexpr account_name system_account = SystemAccount;
// using currency = typename common<SystemAccount>::currency;
// using system_token_type = typename common<SystemAccount>::system_token_type;
using eosio_parameters = typename common<SystemAccount>::eosio_parameters;
using global_state_singleton = typename common<SystemAccount>::global_state_singleton;
......@@ -234,9 +227,10 @@ namespace eosiosystem {
}
static eosio::asset payment_per_block(uint32_t percent_of_max_inflation_rate) {
#warning "FIX THIS!"
// const system_token_type token_supply = currency::get_total_supply();
const eosio::asset token_supply(10000000000, S(4,EOS)); // = _system_token.get_total_supply(S(4,EOS));
eosio::symbol_name sym = eosio::symbol_type(S(4,EOS)).name();
eosio::token::stats stats_tbl(N(eosio.token), sym);
const auto& st = stats_tbl.get(sym);
const eosio::asset token_supply = st.supply;
const double annual_rate = double(max_inflation_rate * percent_of_max_inflation_rate) / double(10000);
double continuous_rate = std::log1p(annual_rate);
int64_t payment = static_cast<int64_t>((continuous_rate * double(token_supply.amount)) / double(blocks_per_year));
......@@ -383,7 +377,7 @@ namespace eosiosystem {
// currency::inline_issue(SystemAccount, issue_quantity);
#warning "FIX THIS!"
{
eosio::action act( eosio::permission_level{N(eosio.system),N(active)}, N(eosio.token), N(inline_issue),
eosio::action act( eosio::permission_level{N(eosio),N(active)}, N(eosio.token), N(inlineissue),
std::make_tuple( issue_quantity, std::string("producer pay") ) );
act.send();
}
......
......@@ -99,15 +99,10 @@ void token::inlinetransfer( account_name from,
string memo)
{
require_auth( from );
require_recipient( from );
require_recipient( to );
// dispatch_inline( permission_level{from,N(active)}, _self, N(transfer), &token::transfer, { from, to, quantity, memo } );
action act(permission_level{from,N(active)}, _self, N(transfer), std::make_tuple(from, to, quantity, memo));
act.send();
dispatch_inline( permission_level{from,N(active)}, _self, N(transfer), &token::transfer, { from, to, quantity, memo } );
}
asset token::get_total_supply( const symbol_type& symbol )
......
......@@ -6,9 +6,17 @@
#include <eosiolib/asset.hpp>
#include <eosiolib/eosio.hpp>
//#include <eosiolib/asset.hpp>
#include <string>
namespace eosiosystem {
template <account_name Account>
class voting;
template <account_name Account>
class delegate_bandwidth;
}
namespace eosio {
using std::string;
......@@ -34,13 +42,17 @@ namespace eosio {
string memo );
void inlinetransfer( account_name from,
account_name to,
asset quantity,
string memo );
account_name to,
asset quantity,
string memo );
asset get_total_supply( const symbol_type& symbol );
private:
friend eosiosystem::voting<N(eosio)>;
friend eosiosystem::delegate_bandwidth<N(eosio)>;
struct account {
asset balance;
bool frozen = false;
......
......@@ -47,10 +47,11 @@ public:
set_abi( N(eosio.token), eosio_token_abi );
create_currency( N(eosio.token), config::system_account_name, asset::from_string("20000000.0000 EOS") );
issue(config::system_account_name, "10000000.0000 EOS");
produce_blocks();
const auto& accnt = control->get_database().get<account_object,by_name>( config::system_account_name /*N(eosio.system)*/ );
const auto& accnt = control->get_database().get<account_object,by_name>( config::system_account_name );
abi_def abi;
BOOST_REQUIRE_EQUAL(abi_serializer::to_abi(accnt.abi, abi), true);
abi_ser.set_abi(abi);
......@@ -129,7 +130,7 @@ public:
action_result regproducer( const account_name& acnt, int params_fixture = 1 ) {
return push_action( acnt, N(regproducer), mvo()
("producer", acnt /*name(acnt).to_string()*/ )
("producer", acnt )
("producer_key", fc::raw::pack( get_public_key( acnt, "active" ) ) )
("prefs", producer_parameters_example( params_fixture ) )
);
......@@ -1098,8 +1099,8 @@ 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", "10000000.0000 EOS", config::system_account_name);
BOOST_REQUIRE_EQUAL( asset::from_string("10000000.0000 EOS"), get_balance( "alice" ) );
issue( "alice", "100.0000 EOS", config::system_account_name);
BOOST_REQUIRE_EQUAL( asset::from_string("100.0000 EOS"), get_balance( "alice" ) );
fc::variant params = producer_parameters_example(50);
vector<char> key = fc::raw::pack(get_public_key(N(alice), "active"));
......@@ -1127,7 +1128,7 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester) try {
// bob makes stake
// 1 block produced
BOOST_REQUIRE_EQUAL(success(), stake("bob", "11.0000 EOS", "00.1111 EOS", "00.1111 EOS"));
BOOST_REQUIRE_EQUAL(success(), stake("bob", "11.0000 EOS", "10.1111 EOS", "10.1111 EOS"));
// bob votes for alice
// 1 block produced
......@@ -1141,12 +1142,10 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester) try {
produce_blocks(10);
prod = get_producer_info("alice");
BOOST_REQUIRE(prod["per_block_payments"].as_uint64() > 0);
BOOST_REQUIRE_EQUAL(success(), push_action(N(alice), N(claimrewards), mvo()
("owner", "alice")
)
);
prod = get_producer_info("alice");
BOOST_REQUIRE_EQUAL(0, prod["per_block_payments"].as_uint64());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册