提交 3a62db5d 编写于 作者: W Wang Zhi

add some extra election policy

上级 ebe00945
...@@ -322,6 +322,14 @@ ...@@ -322,6 +322,14 @@
{"name":"deposit_votes", "type":"int64"}, {"name":"deposit_votes", "type":"int64"},
{"name":"unpaid_base_cnt", "type":"uint32"} {"name":"unpaid_base_cnt", "type":"uint32"}
] ]
},{
"name": "master_sn_info",
"base": "",
"fields": [
{"name":"seq_num", "type":"uint16"},
{"name":"owner", "type":"account_name"},
{"name":"url", "type":"string"}
]
},{ },{
"name": "producers_seq", "name": "producers_seq",
"base": "", "base": "",
...@@ -648,6 +656,12 @@ ...@@ -648,6 +656,12 @@
"index_type": "i64", "index_type": "i64",
"key_names" : ["owner"], "key_names" : ["owner"],
"key_types" : ["uint64"] "key_types" : ["uint64"]
},{
"name": "mastersnlist",
"type": "master_sn_info",
"index_type": "i64",
"key_names" : ["seq_num"],
"key_types" : ["uint64"]
},{ },{
"name": "producerseq", "name": "producerseq",
"type": "producers_seq", "type": "producers_seq",
......
...@@ -133,6 +133,17 @@ namespace eosiosystem { ...@@ -133,6 +133,17 @@ namespace eosiosystem {
EOSLIB_SERIALIZE( producers_seq, (seq_num)(master)(voter_list)(prods_all) ) EOSLIB_SERIALIZE( producers_seq, (seq_num)(master)(voter_list)(prods_all) )
}; };
struct master_sn_info {
uint16_t seq_num = 1; // from 1 to 21
account_name owner;
std::string url;
uint64_t primary_key()const { return seq_num; }
EOSLIB_SERIALIZE( master_sn_info, (seq_num)(owner)(url))
};
typedef eosio::multi_index< N(mastersnlist), master_sn_info> master_sn_list;
//##YTA-Change end: //##YTA-Change end:
//##YTA-Change start: //##YTA-Change start:
...@@ -335,6 +346,10 @@ namespace eosiosystem { ...@@ -335,6 +346,10 @@ namespace eosiosystem {
void change_producer_seq_info( const account_name producer, const eosio::public_key& producer_key, bool isactive, bool seturl, const std::string& url); void change_producer_seq_info( const account_name producer, const eosio::public_key& producer_key, bool isactive, bool seturl, const std::string& url);
void update_producers_seq_totalvotes( uint16_t seq_num, account_name owner, double total_votes); void update_producers_seq_totalvotes( uint16_t seq_num, account_name owner, double total_votes);
void delproducer( const account_name producer );
void elect_new_sn_master( uint16_t seq_num );
//##YTA-Change end: //##YTA-Change end:
// Implementation details: // Implementation details:
......
...@@ -273,6 +273,28 @@ namespace eosiosystem { ...@@ -273,6 +273,28 @@ namespace eosiosystem {
uint32_t total_unpaid_blocks = _gstate.total_unpaid_blocks; uint32_t total_unpaid_blocks = _gstate.total_unpaid_blocks;
uint32_t total_unpaid_base_cnt = _gstateex.total_unpaid_base_cnt; uint32_t total_unpaid_base_cnt = _gstateex.total_unpaid_base_cnt;
/*
//double total_producer_vote_weight = _gstate.total_producer_vote_weight;
uint32_t total_unpaid_blocks = 0;
uint32_t total_unpaid_base_cnt = 0;
double total_producer_vote_weight = 0;
for( auto it = _producers.begin(); it != _producers.end(); it++ ) {
total_unpaid_blocks += it->unpaid_blocks;
total_producer_vote_weight += it->total_votes;
}
for( auto it = _producersext.begin(); it != _producersext.end(); it++ ) {
total_unpaid_base_cnt += it->unpaid_base_cnt;
}
_gstate.total_unpaid_blocks = total_unpaid_blocks;
_gstateex.total_unpaid_base_cnt = total_unpaid_base_cnt;
_gstate.total_producer_vote_weight = total_producer_vote_weight;
*/
for( auto it = _producers.begin(); it != _producers.end(); it++ ) { for( auto it = _producers.begin(); it != _producers.end(); it++ ) {
if(!(it->active())) if(!(it->active()))
continue; continue;
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
const uint64_t useconds_per_day_v = 24 * 3600 * uint64_t(1000000);
namespace eosiosystem { namespace eosiosystem {
using eosio::indexed_by; using eosio::indexed_by;
using eosio::const_mem_fun; using eosio::const_mem_fun;
...@@ -118,9 +120,8 @@ namespace eosiosystem { ...@@ -118,9 +120,8 @@ namespace eosiosystem {
_producersext.erase(_producersext.begin()); _producersext.erase(_producersext.begin());
} }
for( uint16_t seq = 1; seq <= 21; seq++ ) { producers_seq_table _prod_seq( _self, _self );
producers_seq_table _prod_seq( _self, seq ); while (_prod_seq.begin() != _prod_seq.end()) {
if( _prod_seq.begin() != _prod_seq.end() )
_prod_seq.erase(_prod_seq.begin()); _prod_seq.erase(_prod_seq.begin());
} }
...@@ -129,7 +130,7 @@ namespace eosiosystem { ...@@ -129,7 +130,7 @@ namespace eosiosystem {
all_prods_singleton _all_prods(_self, _self); all_prods_singleton _all_prods(_self, _self);
all_prods_level _all_prods_state; all_prods_level _all_prods_state;
if (_all_prods.exists()) if (_all_prods.exists()) {
_all_prods_state = _all_prods.get(); _all_prods_state = _all_prods.get();
_all_prods_state.prods_l1.clear(); _all_prods_state.prods_l1.clear();
_all_prods_state.prods_l2.clear(); _all_prods_state.prods_l2.clear();
...@@ -137,6 +138,77 @@ namespace eosiosystem { ...@@ -137,6 +138,77 @@ namespace eosiosystem {
_all_prods.set(_all_prods_state,_self); _all_prods.set(_all_prods_state,_self);
} }
master_sn_list _snlist( _self, _self );
while (_snlist.begin() != _snlist.end()) {
_snlist.erase(_snlist.begin());
}
}
void system_contract::delproducer( const account_name producer ) {
auto itp = _producers.find(producer);
if( itp != _producers.end() ) {
_gstate.total_unpaid_blocks -= itp->unpaid_blocks;
_gstate.total_producer_vote_weight -= itp->total_votes;
_producers.erase(itp);
}
auto itpex = _producersext.find(producer);
uint16_t seq_num = 0;
if( itpex != _producersext.end() ) {
_gstateex.total_unpaid_base_cnt -= itpex->unpaid_base_cnt;
seq_num = itpex->seq_num;
_producersext.erase(itpex);
} else {
return;
}
bool needNewSnMaster = false;
master_sn_list _snlist(_self, _self);
auto sn_itr = _snlist.find (seq_num);
if( sn_itr != _snlist.end() ) {
if(sn_itr->owner == producer) {
needNewSnMaster = true;
}
}
rm_producer_seq(producer, seq_num);
if( needNewSnMaster ) {
elect_new_sn_master( seq_num );
}
}
void system_contract::elect_new_sn_master( uint16_t seq_num ) {
producers_seq_table _prodseq(_self, _self);
auto ps_itr = _prodseq.find (seq_num);
if( ps_itr == _prodseq.end() )
return;
//account_name newMaster = 0;
_prodseq.modify( ps_itr, _self, [&]( producers_seq& info ){
std::sort(info.prods_all.begin(), info.prods_all.end(), [&](prod_meta lhs, prod_meta rhs){return lhs.total_votes > rhs.total_votes;});
for( auto it =info.prods_all.begin(); it != info.prods_all.end(); it++ ) {
if( it->is_active && (current_time()-it->last_crash_time) > useconds_per_day_v ) {
//newMaster = it->owner;
info.master = it->owner;
master_sn_list _snlist(_self, _self);
auto sn_itr = _snlist.find (seq_num);
if( sn_itr == _snlist.end() ) {
_snlist.emplace(_self, [&](auto &row) {
row.seq_num = seq_num;
row.owner = it->owner;
row.url = it->url;
});
} else {
_snlist.modify(sn_itr, _self, [&](auto &row) {
row.owner = it->owner;
row.url = it->url;
});
}
}
}
});
}
void system_contract::seqproducer( const account_name producer, uint16_t seq , uint8_t level ) { void system_contract::seqproducer( const account_name producer, uint16_t seq , uint8_t level ) {
require_auth( _self ); require_auth( _self );
...@@ -194,10 +266,9 @@ namespace eosiosystem { ...@@ -194,10 +266,9 @@ namespace eosiosystem {
} }
producers_seq_table _prodseq(_self, seq); producers_seq_table _prodseq(_self, _self);
auto ps_itr = _prodseq.find (seq); auto ps_itr = _prodseq.find (seq);
if( ps_itr == _prodseq.end() ) if( ps_itr != _prodseq.end() ) {
return;
_prodseq.modify( ps_itr, _self, [&]( producers_seq& info ){ _prodseq.modify( ps_itr, _self, [&]( producers_seq& info ){
if(info.master == producer) { if(info.master == producer) {
info.master = 0; info.master = 0;
...@@ -209,9 +280,25 @@ namespace eosiosystem { ...@@ -209,9 +280,25 @@ namespace eosiosystem {
break; break;
} }
} }
for( auto itvoter = info.voter_list.begin(); itvoter != info.voter_list.end(); itvoter++ ) {
if( *itvoter == producer ) {
info.voter_list.erase(itvoter);
break;
}
}
}); });
} }
master_sn_list _snlist(_self, _self);
auto sn_itr = _snlist.find (seq);
if( sn_itr != _snlist.end() ) {
if(sn_itr->owner == producer) {
_snlist.erase(sn_itr);
}
}
}
void system_contract::add_producer_seq( const account_name producer, uint16_t seq , uint8_t level ) { void system_contract::add_producer_seq( const account_name producer, uint16_t seq , uint8_t level ) {
//need retrive from system producers table //need retrive from system producers table
...@@ -244,7 +331,7 @@ namespace eosiosystem { ...@@ -244,7 +331,7 @@ namespace eosiosystem {
_all_prods.set(_all_prods_state,_self); _all_prods.set(_all_prods_state,_self);
producers_seq_table _prodseq(_self, seq); producers_seq_table _prodseq(_self, _self);
prod_meta prodm; prod_meta prodm;
prodm.owner = producer; prodm.owner = producer;
prodm.total_votes = prod.total_votes; prodm.total_votes = prod.total_votes;
...@@ -269,6 +356,23 @@ namespace eosiosystem { ...@@ -269,6 +356,23 @@ namespace eosiosystem {
} }
}); });
} }
if(level == 1) {
master_sn_list _snlist(_self, _self);
auto sn_itr = _snlist.find (seq);
if( sn_itr == _snlist.end() ) {
_snlist.emplace(_self, [&](auto &row) {
row.seq_num = seq;
row.owner = producer;
row.url = prod.url;
});
} else {
_snlist.modify(sn_itr, _self, [&](auto &row) {
row.owner = producer;
row.url = prod.url;
});
}
}
} }
void system_contract::change_producer_seq_info( const account_name producer, const eosio::public_key& producer_key, bool isactive, bool seturl, const std::string& url) { void system_contract::change_producer_seq_info( const account_name producer, const eosio::public_key& producer_key, bool isactive, bool seturl, const std::string& url) {
...@@ -311,7 +415,7 @@ namespace eosiosystem { ...@@ -311,7 +415,7 @@ namespace eosiosystem {
if (it == _producersext.end()) if (it == _producersext.end())
return; return;
uint16_t seq = it->seq_num; uint16_t seq = it->seq_num;
producers_seq_table _prodseq(_self, seq); producers_seq_table _prodseq(_self, _self);
auto ps_itr = _prodseq.find (seq); auto ps_itr = _prodseq.find (seq);
if( ps_itr == _prodseq.end() ) if( ps_itr == _prodseq.end() )
return; return;
...@@ -326,6 +430,17 @@ namespace eosiosystem { ...@@ -326,6 +430,17 @@ namespace eosiosystem {
} }
}); });
master_sn_list _snlist(_self, _self);
auto sn_itr = _snlist.find (seq);
if( sn_itr != _snlist.end() ) {
if(sn_itr->owner == producer) {
if(seturl) {
_snlist.modify(sn_itr, _self, [&](auto &row) {
row.url = url;
});
}
}
}
} }
void system_contract::update_producers_seq_totalvotes( uint16_t seq_num, account_name owner, double total_votes) { void system_contract::update_producers_seq_totalvotes( uint16_t seq_num, account_name owner, double total_votes) {
...@@ -358,8 +473,7 @@ namespace eosiosystem { ...@@ -358,8 +473,7 @@ namespace eosiosystem {
_all_prods.set(_all_prods_state,_self); _all_prods.set(_all_prods_state,_self);
} }
producers_seq_table _prodseq(_self, _self);
producers_seq_table _prodseq(_self, seq_num);
auto ps_itr = _prodseq.find (seq_num); auto ps_itr = _prodseq.find (seq_num);
if( ps_itr == _prodseq.end() ) if( ps_itr == _prodseq.end() )
return; return;
...@@ -405,8 +519,6 @@ namespace eosiosystem { ...@@ -405,8 +519,6 @@ namespace eosiosystem {
} }
const uint64_t useconds_per_day_v = 24 * 3600 * uint64_t(1000000);
void system_contract::update_elected_producers_yta( block_timestamp block_time ) { void system_contract::update_elected_producers_yta( block_timestamp block_time ) {
all_prods_singleton _all_prods(_self, _self); all_prods_singleton _all_prods(_self, _self);
...@@ -819,6 +931,8 @@ namespace eosiosystem { ...@@ -819,6 +931,8 @@ namespace eosiosystem {
} }
} }
account_name producer_not_fount = 0;
for( const auto& pd : producer_deltas ) { for( const auto& pd : producer_deltas ) {
double total_votes = 0; double total_votes = 0;
auto pitr = _producers.find( pd.first ); auto pitr = _producers.find( pd.first );
...@@ -834,24 +948,36 @@ namespace eosiosystem { ...@@ -834,24 +948,36 @@ namespace eosiosystem {
total_votes = p.total_votes; total_votes = p.total_votes;
}); });
} else { } else {
if(voting) {
eosio_assert( !pd.second.second /* not from new set */, "producer is not registered" ); //data corruption eosio_assert( !pd.second.second /* not from new set */, "producer is not registered" ); //data corruption
} }
producer_not_fount = pd.first;
}
//##YTA-Change start: //##YTA-Change start:
auto pitr2 = _producersext.find( pd.first ); auto pitr2 = _producersext.find( pd.first );
if( pitr2 != _producersext.end() ) { if( pitr2 != _producersext.end() ) {
//pitr2->seq_num //pitr2->seq_num
update_producers_seq_totalvotes(pitr2->seq_num, pd.first, total_votes); update_producers_seq_totalvotes(pitr2->seq_num, pd.first, total_votes);
} else { } else {
if(voting) {
eosio_assert( !pd.second.second /* not from new set */, "producer is not registered" ); //data corruption eosio_assert( !pd.second.second /* not from new set */, "producer is not registered" ); //data corruption
} }
}
//##YTA-Change end: //##YTA-Change end:
} }
//delete the last missing producer
_voters.modify( voter, 0, [&]( auto& av ) { _voters.modify( voter, 0, [&]( auto& av ) {
av.last_vote_weight = new_vote_weight; av.last_vote_weight = new_vote_weight;
av.producers = producers; av.producers = producers;
if(producer_not_fount) {
for( auto it= av.producers.begin(); it != av.producers.end(); it++ ) {
if(*it == producer_not_fount) {
av.producers.erase(it);
break;
}
}
}
av.proxy = proxy; av.proxy = proxy;
}); });
} }
...@@ -866,6 +992,9 @@ namespace eosiosystem { ...@@ -866,6 +992,9 @@ namespace eosiosystem {
* @pre new state must be different than current state * @pre new state must be different than current state
*/ */
void system_contract::regproxy( const account_name proxy, bool isproxy ) { void system_contract::regproxy( const account_name proxy, bool isproxy ) {
eosio_assert(1 == 2, "proxy not supported.");
require_auth( proxy ); require_auth( proxy );
auto pitr = _voters.find(proxy); auto pitr = _voters.find(proxy);
......
...@@ -116,7 +116,9 @@ void token::sub_balance_yta( account_name owner, asset value , account_name to) ...@@ -116,7 +116,9 @@ void token::sub_balance_yta( account_name owner, asset value , account_name to)
const auto& from = from_acnts.get( value.symbol.name(), "no balance object found" ); const auto& from = from_acnts.get( value.symbol.name(), "no balance object found" );
//todo : need consider lock_token situation //todo : need consider lock_token situation
if( to == N(eosio.stake) || to == hdd_deposit_account ) { if( to == hdd_deposit_account) {
eosio_assert( from.balance.amount >= value.amount, "overdrawn balance" );
} else if( to == N(eosio.stake) ) {
//forfeit can not use to delegatebw and vote //forfeit can not use to delegatebw and vote
auto deposit_and_forfeit = hdddeposit(hdd_deposit_account).get_deposit_and_forfeit(owner); auto deposit_and_forfeit = hdddeposit(hdd_deposit_account).get_deposit_and_forfeit(owner);
eosio_assert( deposit_and_forfeit.symbol == value.symbol, "symbol precision mismatch" ); eosio_assert( deposit_and_forfeit.symbol == value.symbol, "symbol precision mismatch" );
......
...@@ -129,8 +129,8 @@ private: ...@@ -129,8 +129,8 @@ private:
struct minerinfo struct minerinfo
{ {
uint64_t minerid; uint64_t minerid;
name owner; name owner; //收益账号
name admin; name admin; //管理员账号
name pool_id; name pool_id;
uint64_t max_space; uint64_t max_space;
uint64_t space_left; uint64_t space_left;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册