提交 e2280ac0 编写于 作者: W Wang Zhi

update system contract -- miscellaneous

上级 74a52daa
...@@ -608,7 +608,7 @@ ...@@ -608,7 +608,7 @@
"key_names" : ["owner"], "key_names" : ["owner"],
"key_types" : ["uint64"] "key_types" : ["uint64"]
},{ },{
"name": "producers2", "name": "producersext",
"type": "producer_info_ext", "type": "producer_info_ext",
"index_type": "i64", "index_type": "i64",
"key_names" : ["owner"], "key_names" : ["owner"],
......
...@@ -13,7 +13,7 @@ namespace eosiosystem { ...@@ -13,7 +13,7 @@ namespace eosiosystem {
:native(s), :native(s),
_voters(_self,_self), _voters(_self,_self),
_producers(_self,_self), _producers(_self,_self),
_producers2(_self,_self), _producersext(_self,_self),
_global(_self,_self), _global(_self,_self),
_rammarket(_self,_self) _rammarket(_self,_self)
{ {
......
...@@ -168,7 +168,7 @@ namespace eosiosystem { ...@@ -168,7 +168,7 @@ namespace eosiosystem {
> producers_table; > producers_table;
//##YTA-Change start: //##YTA-Change start:
typedef eosio::multi_index< N(producers2), producer_info_ext> producers_ext_table; typedef eosio::multi_index< N(producersext), producer_info_ext> producers_ext_table;
typedef eosio::multi_index< N(producerseq), producers_seq> producers_seq_table; typedef eosio::multi_index< N(producerseq), producers_seq> producers_seq_table;
//##YTA-Change end: //##YTA-Change end:
...@@ -188,7 +188,7 @@ namespace eosiosystem { ...@@ -188,7 +188,7 @@ namespace eosiosystem {
voters_table _voters; voters_table _voters;
producers_table _producers; producers_table _producers;
//##YTA-Change start: //##YTA-Change start:
producers_ext_table _producers2; producers_ext_table _producersext;
//##YTA-Change end: //##YTA-Change end:
global_state_singleton _global; global_state_singleton _global;
......
...@@ -8,7 +8,7 @@ namespace eosiosystem { ...@@ -8,7 +8,7 @@ namespace eosiosystem {
//##YTA-Change start: //##YTA-Change start:
//Change total vote rate from 15% to 1% for test network //Change total vote rate from 15% to 1% for test network
//const int64_t min_activated_stake = 150'000'000'0000; //const int64_t min_activated_stake = 150'000'000'0000;
const int64_t min_activated_stake = 0; const int64_t min_activated_stake = 150'000'0000;
//##YTA-Change end: //##YTA-Change end:
const uint32_t blocks_per_year = 52*7*24*2*3600; // half seconds per year const uint32_t blocks_per_year = 52*7*24*2*3600; // half seconds per year
const uint32_t seconds_per_year = 52*7*24*3600; const uint32_t seconds_per_year = 52*7*24*3600;
...@@ -70,6 +70,10 @@ namespace eosiosystem { ...@@ -70,6 +70,10 @@ namespace eosiosystem {
/// update block producers once every two minute due to election strategy is more complex than before /// update block producers once every two minute due to election strategy is more complex than before
if( timestamp.slot - _gstate.last_producer_schedule_update.slot > 240 ) { if( timestamp.slot - _gstate.last_producer_schedule_update.slot > 240 ) {
//##YTA-Change end: //##YTA-Change end:
print("update_elected_producers -------------------------------------\n");
print("--------------------------------------------------------------\n");
print("--------------------------------------------------------------\n");
print("--------------------------------------------------------------\n");
update_elected_producers( timestamp ); update_elected_producers( timestamp );
//update_elected_producers_yta( timestamp ); //update_elected_producers_yta( timestamp );
......
...@@ -37,6 +37,7 @@ namespace eosiosystem { ...@@ -37,6 +37,7 @@ namespace eosiosystem {
void system_contract::regproducer( const account_name producer, const eosio::public_key& producer_key, const std::string& url, uint16_t location ) { void system_contract::regproducer( const account_name producer, const eosio::public_key& producer_key, const std::string& url, uint16_t location ) {
eosio_assert( url.size() < 512, "url too long" ); eosio_assert( url.size() < 512, "url too long" );
eosio_assert( producer_key != eosio::public_key(), "public key should not be the default value" ); eosio_assert( producer_key != eosio::public_key(), "public key should not be the default value" );
/*
require_auth( producer ); require_auth( producer );
auto prod = _producers.find( producer ); auto prod = _producers.find( producer );
...@@ -60,6 +61,32 @@ namespace eosiosystem { ...@@ -60,6 +61,32 @@ namespace eosiosystem {
info.location = location; info.location = location;
}); });
} }
*/
require_auth( _self );
auto prod = _producers.find( producer );
if ( prod != _producers.end() ) {
_producers.modify( prod, _self, [&]( producer_info& info ){
info.producer_key = producer_key;
info.is_active = true;
info.url = url;
info.location = location;
});
change_producer_seq_info(producer, producer_key, true, true, url);
} else {
_producers.emplace( _self, [&]( producer_info& info ){
info.owner = producer;
info.total_votes = 0;
info.producer_key = producer_key;
info.is_active = true;
info.url = url;
info.location = location;
});
}
} }
void system_contract::unregprod( const account_name producer ) { void system_contract::unregprod( const account_name producer ) {
...@@ -77,8 +104,8 @@ namespace eosiosystem { ...@@ -77,8 +104,8 @@ namespace eosiosystem {
void system_contract::clsprods2() { void system_contract::clsprods2() {
require_auth( _self ); require_auth( _self );
while (_producers2.begin() != _producers2.end()) while (_producersext.begin() != _producersext.end())
_producers2.erase(_producers2.begin()); _producersext.erase(_producersext.begin());
for( uint16_t seq = 1; seq <= 21; seq++ ) { for( uint16_t seq = 1; seq <= 21; seq++ ) {
producers_seq_table _prod_seq( _self, seq ); producers_seq_table _prod_seq( _self, seq );
...@@ -98,16 +125,16 @@ namespace eosiosystem { ...@@ -98,16 +125,16 @@ namespace eosiosystem {
eosio_assert(level >= 1 && level <= 3 , "invalidate level number"); eosio_assert(level >= 1 && level <= 3 , "invalidate level number");
//const auto& prod = _producers.get( producer, "producer not found" ); //const auto& prod = _producers.get( producer, "producer not found" );
auto it = _producers2.find(producer); auto it = _producersext.find(producer);
if (it == _producers2.end()) { if (it == _producersext.end()) {
_producers2.emplace(_self, [&](auto &row) { _producersext.emplace(_self, [&](auto &row) {
row.owner = producer; row.owner = producer;
row.seq_num = seq; row.seq_num = seq;
}); });
add_producer_seq(producer, seq, level); add_producer_seq(producer, seq, level);
} else { } else {
uint16_t old_seq = it->seq_num; uint16_t old_seq = it->seq_num;
_producers2.modify(it, _self, [&](auto &row) { _producersext.modify(it, _self, [&](auto &row) {
row.seq_num = seq; row.seq_num = seq;
}); });
rm_producer_seq(producer, old_seq); rm_producer_seq(producer, old_seq);
...@@ -198,9 +225,9 @@ namespace eosiosystem { ...@@ -198,9 +225,9 @@ namespace eosiosystem {
} }
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) {
auto it = _producers2.find(producer); auto it = _producersext.find(producer);
if (it == _producers2.end()) if (it == _producersext.end())
return; return;
uint16_t seq = it->seq_num; uint16_t seq = it->seq_num;
...@@ -346,11 +373,11 @@ namespace eosiosystem { ...@@ -346,11 +373,11 @@ namespace eosiosystem {
_producers.modify( prod, 0, [&]( producer_info& info ){ _producers.modify( prod, 0, [&]( producer_info& info ){
int64_t vote_delta = 0; int64_t vote_delta = 0;
auto pitr2 = _producers2.find( producer); auto pitr2 = _producersext.find( producer);
if( pitr2 != _producers2.end() ) { if( pitr2 != _producersext.end() ) {
vote_delta = tickets - pitr2->out_votes; vote_delta = tickets - pitr2->out_votes;
info.total_votes += vote_delta; info.total_votes += vote_delta;
_producers2.modify( pitr2, 0, [&]( producer_info_ext& info2){ _producersext.modify( pitr2, 0, [&]( producer_info_ext& info2){
info2.out_votes = tickets; info2.out_votes = tickets;
}); });
update_producers_seq_totalvotes(pitr2->seq_num, producer, info.total_votes); update_producers_seq_totalvotes(pitr2->seq_num, producer, info.total_votes);
...@@ -362,13 +389,6 @@ namespace eosiosystem { ...@@ -362,13 +389,6 @@ namespace eosiosystem {
void system_contract::update_elected_producers_yta( block_timestamp block_time ) { void system_contract::update_elected_producers_yta( block_timestamp block_time ) {
_gstate.last_producer_schedule_update = block_time; _gstate.last_producer_schedule_update = block_time;
print("update_elected_producers_yta start------------------------------\n");
print("-----------------------------------------------\n");
print("-----------------------------------------------\n");
print("-----------------------------------------------\n");
print("-----------------------------------------------\n");
print("-----------------------------------------------\n");
print("-----------------------------------------------\n");
std::vector< std::pair<eosio::producer_key,uint16_t> > top_producers; std::vector< std::pair<eosio::producer_key,uint16_t> > top_producers;
top_producers.reserve(21); top_producers.reserve(21);
...@@ -396,13 +416,10 @@ namespace eosiosystem { ...@@ -396,13 +416,10 @@ namespace eosiosystem {
bytes packed_schedule = pack(producers); bytes packed_schedule = pack(producers);
print("set_proposed_producers start------------------------\n");
if( set_proposed_producers( packed_schedule.data(), packed_schedule.size() ) >= 0 ) { if( set_proposed_producers( packed_schedule.data(), packed_schedule.size() ) >= 0 ) {
_gstate.last_producer_schedule_size = static_cast<decltype(_gstate.last_producer_schedule_size)>( top_producers.size() ); _gstate.last_producer_schedule_size = static_cast<decltype(_gstate.last_producer_schedule_size)>( top_producers.size() );
print("set_proposed_producers succes-----------------------\n");
} }
print("update_elected_producers_yta end------------------------------\n");
} }
...@@ -416,10 +433,8 @@ namespace eosiosystem { ...@@ -416,10 +433,8 @@ namespace eosiosystem {
return std::pair<eosio::producer_key,uint16_t>({{0, eosio::public_key{}}, 0}); return std::pair<eosio::producer_key,uint16_t>({{0, eosio::public_key{}}, 0});
if(ps_itr->is_org) { if(ps_itr->is_org) {
print("getProducerForSeq use org------------------------------", seq_num, "\n");
//if(ps_itr->prods_l1.is_active && ps_itr->prods_l1.total_votes > 50000000000) { //if(ps_itr->prods_l1.is_active && ps_itr->prods_l1.total_votes > 50000000000) {
if(ps_itr->prods_l1.is_active && ps_itr->prods_l1.total_votes > 0) { if(ps_itr->prods_l1.is_active && ps_itr->prods_l1.total_votes > 0) {
print("getProducerForSeq org producer------------------------------", seq_num, "\n");
return std::pair<eosio::producer_key,uint16_t>({{ps_itr->prods_l1.owner, ps_itr->prods_l1.producer_key}, ps_itr->prods_l1.location}); return std::pair<eosio::producer_key,uint16_t>({{ps_itr->prods_l1.owner, ps_itr->prods_l1.producer_key}, ps_itr->prods_l1.location});
} else { } else {
_prodseq.modify(ps_itr, _self, [&](auto &row) { _prodseq.modify(ps_itr, _self, [&](auto &row) {
...@@ -460,6 +475,9 @@ namespace eosiosystem { ...@@ -460,6 +475,9 @@ namespace eosiosystem {
top_producers.emplace_back( std::pair<eosio::producer_key,uint16_t>({{it->owner, it->producer_key}, it->location}) ); top_producers.emplace_back( std::pair<eosio::producer_key,uint16_t>({{it->owner, it->producer_key}, it->location}) );
} }
print("update_elected_producers 1 -------------------------------------\n");
print("update_elected_producers top_producers.size() = " , top_producers.size() , "\n");
if ( top_producers.size() < _gstate.last_producer_schedule_size ) { if ( top_producers.size() < _gstate.last_producer_schedule_size ) {
return; return;
} }
...@@ -475,7 +493,10 @@ namespace eosiosystem { ...@@ -475,7 +493,10 @@ namespace eosiosystem {
bytes packed_schedule = pack(producers); bytes packed_schedule = pack(producers);
print("update_elected_producers 2 -------------------------------------\n");
if( set_proposed_producers( packed_schedule.data(), packed_schedule.size() ) >= 0 ) { if( set_proposed_producers( packed_schedule.data(), packed_schedule.size() ) >= 0 ) {
print("update_elected_producers 3 -------------------------------------\n");
_gstate.last_producer_schedule_size = static_cast<decltype(_gstate.last_producer_schedule_size)>( top_producers.size() ); _gstate.last_producer_schedule_size = static_cast<decltype(_gstate.last_producer_schedule_size)>( top_producers.size() );
} }
} }
...@@ -601,8 +622,8 @@ namespace eosiosystem { ...@@ -601,8 +622,8 @@ namespace eosiosystem {
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 start: //##YTA-Change start:
auto pitr2 = _producers2.find( pd.first ); auto pitr2 = _producersext.find( pd.first );
if( pitr2 != _producers2.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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册