提交 b0e8337b 编写于 作者: D Daniel Larimer

start work on b1 vesting and network activation

上级 62fa1bfc
...@@ -291,6 +291,17 @@ namespace eosiosystem { ...@@ -291,6 +291,17 @@ namespace eosiosystem {
} }
} // delegatebw } // delegatebw
void validate_b1_vesting( uint64_t stake ) {
const int64_t seconds_per_year = 60*60*24*365;
const int64_t base_time = 1527811200; /// 2018-06-01
const int64_t end_time = seconds_per_year*10 + 1527811200; /// 2018-06-01
const int64_t max_claimable = 100'000'000'0000ll;
const int64_t claimable = int64_t(max_claimable * double(now()-base_time) / seconds_per_year);
eosio_assert( max_claimable - claimable <= stake, "b1 can only claim their tokens over 10 years" );
}
void system_contract::undelegatebw( account_name from, account_name receiver, void system_contract::undelegatebw( account_name from, account_name receiver,
asset unstake_net_quantity, asset unstake_cpu_quantity ) asset unstake_net_quantity, asset unstake_cpu_quantity )
{ {
...@@ -308,7 +319,9 @@ namespace eosiosystem { ...@@ -308,7 +319,9 @@ namespace eosiosystem {
_voters.modify( _voters.get(from), 0, [&]( auto& v ) { _voters.modify( _voters.get(from), 0, [&]( auto& v ) {
v.staked -= uint64_t(total_refund); v.staked -= uint64_t(total_refund);
print( " vote weight: ", v.last_vote_weight, "\n" ); if( from == N(b1) ) {
validate_b1_vesting( v.staked );
}
}); });
......
...@@ -34,10 +34,11 @@ namespace eosiosystem { ...@@ -34,10 +34,11 @@ namespace eosiosystem {
block_timestamp last_producer_schedule_update = 0; block_timestamp last_producer_schedule_update = 0;
eosio::asset eos_bucket; eosio::asset eos_bucket;
eosio::asset savings; eosio::asset savings;
int64_t total_activiated_stake = 0;
// explicit serialization macro is not necessary, used here only to improve compilation time // explicit serialization macro is not necessary, used here only to improve compilation time
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)(eos_bucket)(savings) ) (last_producer_schedule_update)(eos_bucket)(savings)(total_activiated_stake) )
}; };
struct producer_info { struct producer_info {
......
...@@ -71,7 +71,7 @@ namespace eosiosystem { ...@@ -71,7 +71,7 @@ namespace eosiosystem {
eosio::producer_schedule schedule; eosio::producer_schedule schedule;
schedule.producers.reserve(21); schedule.producers.reserve(21);
size_t n = 0; size_t n = 0;
for ( auto it = idx.crbegin(); it != idx.crend() && n < 21 && 0 < it->total_votes; ++it ) { for ( auto it = idx.cbegin(); it != idx.cend() && n < 21 && 0 < it->total_votes; ++it ) {
if ( it->active() && if ( it->active() &&
it->time_became_active == 0 ) { it->time_became_active == 0 ) {
...@@ -104,13 +104,14 @@ namespace eosiosystem { ...@@ -104,13 +104,14 @@ namespace eosiosystem {
} }
// should use producer_schedule_type from libraries/chain/include/eosio/chain/producer_schedule.hpp // should use producer_schedule_type from libraries/chain/include/eosio/chain/producer_schedule.hpp
bytes packed_schedule = pack(schedule); bytes packed_schedule = pack(schedule.producers);
set_active_producers( packed_schedule.data(), packed_schedule.size() ); set_active_producers( packed_schedule.data(), packed_schedule.size() );
// not voted on // not voted on
_gstate.last_producer_schedule_update = block_time; _gstate.last_producer_schedule_update = block_time;
} }
/** /**
* @pre producers must be sorted from lowest to highest and must be registered and active * @pre producers must be sorted from lowest to highest and must be registered and active
* @pre if proxy is set then no producers can be voted for * @pre if proxy is set then no producers can be voted for
...@@ -145,6 +146,15 @@ namespace eosiosystem { ...@@ -145,6 +146,15 @@ namespace eosiosystem {
auto voter = _voters.find(voter_name); auto voter = _voters.find(voter_name);
eosio_assert( voter != _voters.end(), "user must stake before they can vote" ); /// staking creates voter object eosio_assert( voter != _voters.end(), "user must stake before they can vote" ); /// staking creates voter object
/**
* The first time someone votes we calculate and set last_vote_weight, since they cannot unstake until
* after total_activiated_stake hits threshold, we can use last_vote_weight to determine that this is
* their first vote and should consider their stake activated.
*/
if( voter->last_vote_weight <= 0.0 ) {
_gstate.total_activiated_stake += voter->staked;
}
auto weight = int64_t(now() / (seconds_per_day * 7)) / double( 52 ); auto weight = int64_t(now() / (seconds_per_day * 7)) / double( 52 );
double new_vote_weight = double(voter->staked) * std::pow(2,weight); double new_vote_weight = double(voter->staked) * std::pow(2,weight);
......
...@@ -284,10 +284,13 @@ BOOST_FIXTURE_TEST_CASE( bootseq_test, bootseq_tester ) { ...@@ -284,10 +284,13 @@ BOOST_FIXTURE_TEST_CASE( bootseq_test, bootseq_tester ) {
produce_blocks(100); produce_blocks(100);
votepro( N(b1), {N(p1), N(p2)} ); votepro( N(b1), {N(p1), N(p2)} );
votepro( N(whale2), {N(p2), N(p3)} );
votepro( N(whale3), {N(p2), N(p4), N(p5)} );
wlog("pb" ); wlog("pb" );
produce_block( fc::days(1) ); produce_blocks(10);
wdump((control->head_block_state()->active_schedule)); wdump((control->head_block_state()->active_schedule));
return;
produce_blocks(7000); /// produce blocks until virutal bandwidth can acomadate a small user produce_blocks(7000); /// produce blocks until virutal bandwidth can acomadate a small user
wlog("minow" ); wlog("minow" );
votepro( N(minow1), {N(p1), N(p2)} ); votepro( N(minow1), {N(p1), N(p2)} );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册