Skip to content

Commit

Permalink
Merge branch 'set-min-activated-stake' into 'beos-initial-release'
Browse files Browse the repository at this point in the history
`min_activated_stake` now is set in chain from inside `beos.init` and read from…

Closes EOSIO#16

See merge request blocktrades/beos-core!65
  • Loading branch information
vogel76 committed Nov 22, 2018
2 parents c23d52d + eedcd95 commit 1e8bc0e
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 25 deletions.
7 changes: 6 additions & 1 deletion contracts/beoslib/beos_privileged.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ struct block_producer_voting_info;
* Defined in distribution_api
*/
void reward_all(uint64_t, uint64_t, uint64_t, const void*, int, bool,
block_producer_voting_info* producerInfos, uint32_t producerInfoSize);
block_producer_voting_info* , uint32_t);
void reward_done(const void*, int, bool);

/**
* Defined in init_api
*/
void set_min_activated_stake(int64_t);

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions contracts/eosio.init/eosio.init.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ namespace eosio {
_beos_global( _self, _self )
{
_beos_gstate = _beos_global.exists() ? _beos_global.get() : get_beos_default_parameters();
set_min_activated_stake( 150'000'000'0000 ); // it should be: CORE_INITIAL_ISSUE * 15% * 10000 (precision)
}

void changeparams( beos_global_state new_params );
Expand Down
2 changes: 1 addition & 1 deletion contracts/eosio.system/delegate_bandwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ namespace eosiosystem {
eosio_assert( asset() <= unstake_cpu_quantity, "must unstake a positive amount" );
eosio_assert( asset() <= unstake_net_quantity, "must unstake a positive amount" );
eosio_assert( asset() < unstake_cpu_quantity + unstake_net_quantity, "must unstake a positive amount" );
eosio_assert( _gstate.total_activated_stake >= min_activated_stake,
eosio_assert( _gstate.total_activated_stake >= _min_activated_stake,
"cannot undelegate bandwidth until the chain is activated (at least 15% of all tokens participate in voting)" );

changebw( from, receiver, -unstake_net_quantity, -unstake_cpu_quantity, false);
Expand Down
4 changes: 3 additions & 1 deletion contracts/eosio.system/eosio.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace eosiosystem {

flush_voting_stats();

_min_activated_stake = get_min_activated_stake();

auto itr = _rammarket.find(S(4,RAMCORE));

if( itr == _rammarket.end() ) {
Expand Down Expand Up @@ -204,7 +206,7 @@ namespace eosiosystem {
_global.set(_gstate, _self);
}

} /// eosio.system
} /// eosiosystem


EOSIO_ABI( eosiosystem::system_contract,
Expand Down
2 changes: 2 additions & 0 deletions contracts/eosio.system/eosio.system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ namespace eosiosystem {
eosio_global_state _gstate;
rammarket _rammarket;

int64_t _min_activated_stake = 150'000'000'0000; // it should be: CORE_INITIAL_ISSUE * 15% * 10000 (precision)

public:
system_contract( account_name s );
~system_contract();
Expand Down
6 changes: 2 additions & 4 deletions contracts/eosio.system/producer_pay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace eosiosystem {

const int64_t min_pervote_daily_pay = 100'0000;
const int64_t min_activated_stake = 150'000'000'0000;
const double continuous_rate = 0.04879; // 5% annual rate (== ln(1.05))
const double perblock_rate = 0.0025; // 0.25%
const double standby_rate = 0.0075; // 0.75%
Expand All @@ -16,14 +15,13 @@ namespace eosiosystem {
const uint64_t useconds_per_day = 24 * 3600 * uint64_t(1000000);
const uint64_t useconds_per_year = seconds_per_year*1000000ll;


void system_contract::onblock( block_timestamp timestamp, account_name producer ) {
using namespace eosio;

require_auth(N(eosio));

/** until activated stake crosses this threshold no new rewards are paid */
if( _gstate.total_activated_stake < min_activated_stake )
if( _gstate.total_activated_stake < _min_activated_stake )
return;

if( _gstate.last_pervote_bucket_fill == 0 ) /// start the presses
Expand Down Expand Up @@ -71,7 +69,7 @@ namespace eosiosystem {
const auto& prod = _producers.get( owner );
eosio_assert( prod.active(), "producer does not have an active key" );

eosio_assert( _gstate.total_activated_stake >= min_activated_stake,
eosio_assert( _gstate.total_activated_stake >= _min_activated_stake,
"cannot claim rewards until the chain is activated (at least 15% of all tokens participate in voting)" );

auto ct = current_time();
Expand Down
2 changes: 2 additions & 0 deletions contracts/eosiolib/privileged.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ extern "C" {
void store_voting_stats(int64_t total_activated_stake, uint64_t thresh_activated_stake_time,
double total_producer_vote_weight);

int64_t get_min_activated_stake();

/** @brief Registers given account as a proxy (if is_proxy is true)
Part of system_contract implementation (regproxy action).
*/
Expand Down
6 changes: 6 additions & 0 deletions libraries/chain/include/eosio/chain/voting_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ class voting_manager final
*/
void process_voters(const account_name& lowerBound, const account_name& upperBound, voter_processor processor) const;

void set_min_activated_stake(int64_t _min_activated_stake)
{ min_activated_stake = _min_activated_stake; }

int64_t get_min_activated_stake() const { return min_activated_stake; }

private:
friend struct eosio::chain::controller_impl;
/// Can be instantiated only by controller.
Expand Down Expand Up @@ -158,6 +163,7 @@ class voting_manager final
private:
controller& _controller;
chainbase::database& _db;
int64_t min_activated_stake = 150'000'000'0000; // it should be: CORE_INITIAL_ISSUE * 15% * 10000 (precision)
};

} }
Expand Down
2 changes: 0 additions & 2 deletions libraries/chain/voting_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
namespace eosio {
namespace chain {

const int64_t min_activated_stake = 150'000'000'0000;

static constexpr uint32_t seconds_per_day = 24 * 3600;

using voting_manager_index_set = index_set<
Expand Down
64 changes: 48 additions & 16 deletions libraries/chain/wasm_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ class privileged_api : public context_aware_api {
total_producer_vote_weight);
}

int64_t get_min_activated_stake()
{
return context.control.get_mutable_voting_manager().get_min_activated_stake();
}

private:
inline void set_resource_limits_impl( account_name account, int64_t ram_bytes, int64_t net_weight, int64_t cpu_weight ) {
if( context.control.get_mutable_resource_limits_manager().set_account_limits(account, ram_bytes, net_weight, cpu_weight) ) {
Expand Down Expand Up @@ -1797,7 +1802,7 @@ class distribution_api : public context_aware_api {
/* [MK]: System account 'eosio' is the only account able to use distribution_api
(from inside 'onblock' pushed in implicit transaction)
*/
EOS_ASSERT( ctx.privileged && actor == config::system_account_name, unaccessible_api,
EOS_ASSERT( actor == config::system_account_name, unaccessible_api,
"${code} does not have permission to call this API", ("code",actor) );
}

Expand Down Expand Up @@ -1832,6 +1837,32 @@ REGISTER_INTRINSICS( distribution_api,
(reward_done, void(int, int, int) )
);

/*
* This api is dedicated for using from beos.init.
*/
class init_api : public context_aware_api {
public:
init_api( apply_context& ctx )
: context_aware_api( ctx )
{
name actor = ctx.trx_context.trx.first_authorizor();
DBG("init_api::init_api: actor = %s", actor.to_string().c_str());

EOS_ASSERT( ctx.privileged || actor == N(beos.init), unaccessible_api,
"${code} does not have permission to call this API", ("code",actor) );
}

void set_min_activated_stake(int64_t min_activated_stake)
{
context.control.get_mutable_voting_manager().set_min_activated_stake( min_activated_stake );
}

};

REGISTER_INTRINSICS(init_api,
(set_min_activated_stake, void(int64_t))
)

REGISTER_INJECTED_INTRINSICS(call_depth_api,
(call_depth_assert, void() )
);
Expand Down Expand Up @@ -1883,22 +1914,23 @@ REGISTER_INTRINSICS(compiler_builtins,
);

REGISTER_INTRINSICS(privileged_api,
(is_feature_active, int(int64_t) )
(activate_feature, void(int64_t) )
(get_resource_limits, void(int64_t,int,int,int) )
(set_resource_limits, void(int64_t,int64_t,int64_t,int64_t) )
(get_account_ram_usage, int64_t(int64_t) )
(change_resource_limits, void(int64_t,int64_t,int64_t,int64_t) )
(set_proposed_producers, int64_t(int,int) )
(get_blockchain_parameters_packed, int(int, int) )
(set_blockchain_parameters_packed, void(int,int) )
(is_privileged, int(int64_t) )
(set_privileged, void(int64_t, int) )
(register_voting_proxy, void(int64_t, int, int, int) )
(update_voting_power, void(int64_t, int64_t, int, int) )
(is_feature_active, int(int64_t) )
(activate_feature, void(int64_t) )
(get_resource_limits, void(int64_t,int,int,int) )
(set_resource_limits, void(int64_t,int64_t,int64_t,int64_t) )
(get_account_ram_usage, int64_t(int64_t) )
(change_resource_limits, void(int64_t,int64_t,int64_t,int64_t) )
(set_proposed_producers, int64_t(int,int) )
(get_blockchain_parameters_packed, int(int, int) )
(set_blockchain_parameters_packed, void(int,int) )
(is_privileged, int(int64_t) )
(set_privileged, void(int64_t, int) )
(register_voting_proxy, void(int64_t, int, int, int) )
(update_voting_power, void(int64_t, int64_t, int, int) )
(update_votes, void(int64_t, int64_t, int, int, int, int, int) )
(get_voting_stats, void(int, int, int) )
(store_voting_stats, void(int64_t, int64_t, double) )
(get_voting_stats, void(int, int, int) )
(store_voting_stats, void(int64_t, int64_t, double) )
(get_min_activated_stake, int64_t() )
);

REGISTER_INJECTED_INTRINSICS(transaction_context,
Expand Down

0 comments on commit 1e8bc0e

Please sign in to comment.