diff --git a/contracts/eosio.system/delegate_bandwidth.cpp b/contracts/eosio.system/delegate_bandwidth.cpp index 29d0ba27ab949614cd24e930509a0c19d944b09b..177fcb1178bd75015f39d1eb2645949660c8db50 100644 --- a/contracts/eosio.system/delegate_bandwidth.cpp +++ b/contracts/eosio.system/delegate_bandwidth.cpp @@ -291,6 +291,17 @@ namespace eosiosystem { } } // 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, asset unstake_net_quantity, asset unstake_cpu_quantity ) { @@ -308,7 +319,9 @@ namespace eosiosystem { _voters.modify( _voters.get(from), 0, [&]( auto& v ) { v.staked -= uint64_t(total_refund); - print( " vote weight: ", v.last_vote_weight, "\n" ); + if( from == N(b1) ) { + validate_b1_vesting( v.staked ); + } }); diff --git a/contracts/eosio.system/eosio.system.hpp b/contracts/eosio.system/eosio.system.hpp index bde9ea7f2b997b6b7b18bae9209db287111c8bfc..3cd444e765ed48a80e4fea25a8af7ec63a734f47 100644 --- a/contracts/eosio.system/eosio.system.hpp +++ b/contracts/eosio.system/eosio.system.hpp @@ -34,10 +34,11 @@ namespace eosiosystem { block_timestamp last_producer_schedule_update = 0; eosio::asset eos_bucket; eosio::asset savings; + int64_t total_activiated_stake = 0; // 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) - (last_producer_schedule_update)(eos_bucket)(savings) ) + (last_producer_schedule_update)(eos_bucket)(savings)(total_activiated_stake) ) }; struct producer_info { diff --git a/contracts/eosio.system/voting.cpp b/contracts/eosio.system/voting.cpp index e24baeb5154801918dde6b05241230876bbd0cfb..a9d9cda655512d988358e0fe18cabf59d37bd66e 100644 --- a/contracts/eosio.system/voting.cpp +++ b/contracts/eosio.system/voting.cpp @@ -71,7 +71,7 @@ namespace eosiosystem { eosio::producer_schedule schedule; schedule.producers.reserve(21); 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() && it->time_became_active == 0 ) { @@ -104,13 +104,14 @@ namespace eosiosystem { } // 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() ); // not voted on _gstate.last_producer_schedule_update = block_time; } + /** * @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 @@ -145,6 +146,15 @@ namespace eosiosystem { auto voter = _voters.find(voter_name); 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 ); double new_vote_weight = double(voter->staked) * std::pow(2,weight); diff --git a/unittests/bootseq_tests.cpp b/unittests/bootseq_tests.cpp index f3c40b6561b5877037e3a4de5a7d8d5ac0e7a6e5..a29045d8a8a779f14d491b0d2167a53225d9d5e3 100644 --- a/unittests/bootseq_tests.cpp +++ b/unittests/bootseq_tests.cpp @@ -284,10 +284,13 @@ BOOST_FIXTURE_TEST_CASE( bootseq_test, bootseq_tester ) { produce_blocks(100); 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" ); - produce_block( fc::days(1) ); + produce_blocks(10); wdump((control->head_block_state()->active_schedule)); + return; produce_blocks(7000); /// produce blocks until virutal bandwidth can acomadate a small user wlog("minow" ); votepro( N(minow1), {N(p1), N(p2)} );