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

New BP election algorithm

上级 88ea4f01
......@@ -39,7 +39,8 @@
{"name":"total_votes", "type":"float64"},
{"name":"producer_key", "type":"public_key"},
{"name":"all_stake", "type":"int64"},
{"name":"is_active", "type":"bool"}
{"name":"is_active", "type":"bool"},
{"name":"location", "type":"uint16"}
]
},{
"name": "bidname",
......@@ -294,8 +295,7 @@
"base": "",
"fields": [
{"name":"owner", "type":"account_name"},
{"name":"seq_num", "type":"uint16"},
{"name":"all_stake", "type":"int64"}
{"name":"seq_num", "type":"uint16"}
]
},{
......@@ -337,6 +337,10 @@
{"name":"seq", "type":"uint16"},
{"name":"level", "type":"uint8"}
]
},{
"name": "testnewelec",
"base": "",
"fields": []
},{
"name": "setram",
"base": "",
......@@ -539,6 +543,10 @@
"name": "seqproducer",
"type": "seqproducer",
"ricardian_contract": ""
},{
"name": "testnewelec",
"type": "testnewelec",
"ricardian_contract": ""
},{
"name": "regproxy",
"type": "regproxy",
......
......@@ -93,6 +93,8 @@ namespace eosiosystem {
_producers.modify( prod, 0, [&](auto& p) {
p.deactivate();
});
active_producer_seq(producer, public_key(), false);
}
void system_contract::bidname( account_name bidder, account_name newname, asset bid ) {
......@@ -204,7 +206,7 @@ EOSIO_ABI( eosiosystem::system_contract,
// delegate_bandwidth.cpp
(buyrambytes)(buyram)(sellram)(delegatebw)(undelegatebw)(refund)
// voting.cpp
(regproducer)(unregprod)(voteproducer)(regproxy)(clsprods2)(seqproducer)
(regproducer)(unregprod)(voteproducer)(regproxy)(clsprods2)(seqproducer)(testnewelec)
// producer_pay.cpp
(onblock)(claimrewards)
)
......@@ -93,7 +93,6 @@ namespace eosiosystem {
struct producer_info_ext {
account_name owner;
uint16_t seq_num = 1; // from 1 to 21
int64_t all_stake = 0;
uint64_t primary_key()const { return owner; }
EOSLIB_SERIALIZE( producer_info_ext, (owner)(seq_num) )
......@@ -102,12 +101,13 @@ namespace eosiosystem {
struct prod_meta {
account_name owner;
double total_votes = 0;
double total_votes = 0; // total votes
eosio::public_key producer_key; /// a packed public key object
int64_t all_stake = 0;
int64_t all_stake = 0; // total original votes (buy yta amount)
bool is_active = true;
uint16_t location = 0;
EOSLIB_SERIALIZE( prod_meta, (owner)(total_votes)(producer_key)(all_stake)(is_active) )
EOSLIB_SERIALIZE( prod_meta, (owner)(total_votes)(producer_key)(all_stake)(is_active)(location) )
};
struct producers_seq {
......@@ -260,14 +260,8 @@ namespace eosiosystem {
void seqproducer( const account_name producer, uint16_t seq , uint8_t level );
void rm_producer_seq( const account_name producer, uint16_t seq );
void add_producer_seq( const account_name producer, uint16_t seq , uint8_t level );
void active_producer_seq( const account_name producer, const eosio::public_key& producer_key, bool isactive);
void update_producers_seq_totalvotes( uint16_t seq_num, account_name owner, double total_votes);
//##YTA-Change end:
void testnewelec();
//##YTA-Change end:
void setram( uint64_t max_ram_size );
......@@ -287,8 +281,19 @@ namespace eosiosystem {
void bidname( account_name bidder, account_name newname, asset bid );
private:
void update_elected_producers( block_timestamp timestamp );
//##YTA-Change start:
void update_elected_producers_yta( block_timestamp timestamp );
std::pair<eosio::producer_key,uint16_t> getProducerForSeq(uint64_t seq_num );
void rm_producer_seq( const account_name producer, uint16_t seq );
void add_producer_seq( const account_name producer, uint16_t seq , uint8_t level );
void active_producer_seq( const account_name producer, const eosio::public_key& producer_key, bool isactive);
void update_producers_seq_totalvotes( uint16_t seq_num, account_name owner, double total_votes);
//##YTA-Change end:
// Implementation details:
......
......@@ -269,10 +269,113 @@ namespace eosiosystem {
});
}
void system_contract::testnewelec() {
require_auth( _self );
std::vector< std::pair<eosio::producer_key,uint16_t> > top_producers;
top_producers.reserve(21);
for( uint16_t seq_num = 1; seq_num <= 21 ; seq_num++ ) {
std::pair<eosio::producer_key,uint16_t> ppinfo = getProducerForSeq( seq_num );
if( ppinfo.first.producer_name != 0 ) {
top_producers.emplace_back( ppinfo );
}
}
if ( top_producers.size() < _gstate.last_producer_schedule_size ) {
return;
}
/// sort by producer name
std::sort( top_producers.begin(), top_producers.end() );
std::vector<eosio::producer_key> producers;
producers.reserve(top_producers.size());
for( const auto& item : top_producers )
producers.push_back(item.first);
/*
print("producers start------------------------------\n");
for( const auto& item : producers ) {
print("producer -", (name{item.producer_name}), "--");
//std::string str(std::begin(item.block_signing_key.data), std::end(item.block_signing_key.data));
//for(size_t i=0; i<33; i++) {
// char c = item.block_signing_key.data[i];
// printf("%c",c);
//}
//print(str);
print("\n");
}
print("producers end------------------------------\n");
*/
}
void system_contract::update_elected_producers_yta( block_timestamp block_time ) {
_gstate.last_producer_schedule_update = block_time;
}
std::vector< std::pair<eosio::producer_key,uint16_t> > top_producers;
top_producers.reserve(21);
for( uint16_t seq_num = 1; seq_num <= 21 ; seq_num++ ) {
std::pair<eosio::producer_key,uint16_t> ppinfo = getProducerForSeq( seq_num );
if( ppinfo.first.producer_name != 0 ) {
top_producers.emplace_back( ppinfo );
}
}
if ( top_producers.size() < _gstate.last_producer_schedule_size ) {
return;
}
/// sort by producer name
std::sort( top_producers.begin(), top_producers.end() );
std::vector<eosio::producer_key> producers;
producers.reserve(top_producers.size());
for( const auto& item : top_producers )
producers.push_back(item.first);
bytes packed_schedule = pack(producers);
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() );
}
}
std::pair<eosio::producer_key,uint16_t> system_contract::getProducerForSeq(uint64_t seq_num ) {
producers_seq_table _prodseq(_self, seq_num);
auto ps_itr = _prodseq.find (seq_num);
if( ps_itr == _prodseq.end() )
return std::pair<eosio::producer_key,uint16_t>({{0, eosio::public_key{}}, 0});
if (ps_itr->prods_all.begin() == ps_itr->prods_all.end() )
return std::pair<eosio::producer_key,uint16_t>({{0, eosio::public_key{}}, 0});
double total_votes = 0;
bool is_find = false;
auto max = ps_itr->prods_all.begin();
for( auto it = ps_itr->prods_all.begin(); it != ps_itr->prods_all.end(); it++ ) {
if(it->is_active && it->total_votes > total_votes) {
max = it;
total_votes = it->total_votes;
is_find = true;
}
}
if(is_find)
return std::pair<eosio::producer_key,uint16_t>({{max->owner, max->producer_key}, max->location});
return std::pair<eosio::producer_key,uint16_t>({{0, eosio::public_key{}}, 0});
}
//##YTA-Change end:
void system_contract::update_elected_producers( block_timestamp block_time ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册