提交 8d0417fd 编写于 作者: K Khaled Al-Hassanieh

Remove producer deactivation code and testing

上级 f7a17ee8
......@@ -270,16 +270,14 @@
"name": "producer_info",
"base": "",
"fields": [
{"name":"owner", "type":"account_name"},
{"name":"total_votes", "type":"float64"},
{"name":"producer_key", "type":"public_key"},
{"name":"is_active", "type":"bool"},
{"name":"url", "type":"string"},
{"name":"unpaid_blocks", "type":"uint32"},
{"name":"last_claim_time", "type":"uint64"},
{"name":"location", "type":"uint16"},
{"name":"time_became_active", "type":"uint32"},
{"name":"last_produced_block_time", "type":"uint32"}
{"name":"owner", "type":"account_name"},
{"name":"total_votes", "type":"float64"},
{"name":"producer_key", "type":"public_key"},
{"name":"is_active", "type":"bool"},
{"name":"url", "type":"string"},
{"name":"unpaid_blocks", "type":"uint32"},
{"name":"last_claim_time", "type":"uint64"},
{"name":"location", "type":"uint16"}
]
},{
"name": "regproducer",
......
......@@ -78,8 +78,6 @@ namespace eosiosystem {
uint32_t unpaid_blocks = 0;
uint64_t last_claim_time = 0;
uint16_t location = 0;
block_timestamp time_became_active;
block_timestamp last_produced_block_time;
uint64_t primary_key()const { return owner; }
double by_votes()const { return is_active ? -total_votes : total_votes; }
......@@ -88,8 +86,7 @@ namespace eosiosystem {
// explicit serialization macro is not necessary, used here only to improve compilation time
EOSLIB_SERIALIZE( producer_info, (owner)(total_votes)(producer_key)(is_active)(url)
(unpaid_blocks)(last_claim_time)(location)
(time_became_active)(last_produced_block_time) )
(unpaid_blocks)(last_claim_time)(location) )
};
struct voter_info {
......
......@@ -39,7 +39,6 @@ namespace eosiosystem {
_gstate.total_unpaid_blocks++;
_producers.modify( prod, 0, [&](auto& p ) {
p.unpaid_blocks++;
p.last_produced_block_time = timestamp;
});
}
......
......@@ -80,30 +80,7 @@ namespace eosiosystem {
std::vector< std::pair<eosio::producer_key,uint16_t> > top_producers;
top_producers.reserve(21);
std::vector<decltype(idx.cbegin())> inactive_iters;
for ( auto it = idx.cbegin(); it != idx.cend() && top_producers.size() < 21 && 0 < it->total_votes && it->active(); ++it ) {
/**
If it's the first time or it's been over a day since a producer was last voted in,
update his info. Otherwise, a producer gets a grace period of 7 hours after which
he gets deactivated if he hasn't produced in 24 hours.
*/
if ( it->time_became_active.slot == 0 ||
block_time.slot > it->time_became_active.slot + 23 * blocks_per_hour ) {
_producers.modify( *it, 0, [&](auto& p) {
p.time_became_active = block_time;
});
} else if ( block_time.slot > (2 * 21 * 12 * 100) + it->time_became_active.slot &&
block_time.slot > it->last_produced_block_time.slot + blocks_per_day ) {
// save producers that will be deactivated
inactive_iters.push_back(it);
continue;
} else {
_producers.modify( *it, 0, [&](auto& p) {
p.time_became_active = block_time;
});
}
top_producers.emplace_back( std::pair<eosio::producer_key,uint16_t>({{it->owner, it->producer_key}, it->location}) );
}
......@@ -111,13 +88,6 @@ namespace eosiosystem {
return;
}
for ( const auto& it: inactive_iters ) {
_producers.modify( *it, 0, [&](auto& p) {
p.deactivate();
p.time_became_active.slot = 0;
});
}
/// sort by producer name
std::sort( top_producers.begin(), top_producers.end() );
......
......@@ -1517,9 +1517,8 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni
push_action(prod_name, N(claimrewards), mvo()("owner", prod_name)));
}
// wait for 23 hours which is not enough for producers to get deactivated
// payment calculations don't change. By now, pervote_bucket has grown enough
// that a producer's share is more than 100 tokens
// Wait for 23 hours. By now, pervote_bucket has grown enough
// that a producer's share is more than 100 tokens.
produce_block(fc::seconds(23 * 3600));
{
......@@ -1593,56 +1592,6 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni
push_action(prod_name, N(claimrewards), mvo()("owner", prod_name)));
}
// wait two more hours, now most producers haven't produced in a day and will
// be deactivated
BOOST_REQUIRE_EQUAL(success(), push_action(N(producvotera), N(voteproducer), mvo()
("voter", "producvotera")
("proxy", name(0).to_string())
("producers", vector<account_name>(producer_names.begin(), producer_names.begin()+21))
)
);
produce_block(fc::hours(9));
produce_blocks(8 * 21 * 12);
{
bool all_newly_elected_produced = true;
for (uint32_t i = 21; i < producer_names.size(); ++i) {
if (0 == get_producer_info(producer_names[i])["unpaid_blocks"].as<uint32_t>()) {
all_newly_elected_produced = false;
}
}
BOOST_REQUIRE(all_newly_elected_produced);
}
{
uint32_t survived_active_producers = 0;
uint32_t one_inactive_index = 0;
for (uint32_t i = 0; i < 21; ++i) {
if (fc::crypto::public_key() != fc::crypto::public_key(get_producer_info(producer_names[i])["producer_key"].as_string())) {
++survived_active_producers;
} else {
one_inactive_index = i;
}
}
BOOST_REQUIRE(3 >= survived_active_producers);
auto inactive_prod_info = get_producer_info(producer_names[one_inactive_index]);
BOOST_REQUIRE_EQUAL(0, inactive_prod_info["time_became_active"].as<uint32_t>());
BOOST_REQUIRE_EQUAL(wasm_assert_msg("producer does not have an active key"),
push_action(producer_names[one_inactive_index], N(claimrewards), mvo()("owner", producer_names[one_inactive_index])));
// re-register deactivated producer and let him produce blocks again
const uint32_t initial_unpaid_blocks = inactive_prod_info["unpaid_blocks"].as<uint32_t>();
regproducer(producer_names[one_inactive_index]);
produce_blocks(8 * 21 * 12);
auto reactivated_prod_info = get_producer_info(producer_names[one_inactive_index]);
const uint32_t unpaid_blocks = reactivated_prod_info["unpaid_blocks"].as<uint32_t>();
BOOST_REQUIRE(initial_unpaid_blocks + 12 <= unpaid_blocks);
BOOST_REQUIRE_EQUAL(success(),
push_action(producer_names[one_inactive_index], N(claimrewards), mvo()("owner", producer_names[one_inactive_index])));
}
} FC_LOG_AND_RETHROW()
BOOST_FIXTURE_TEST_CASE(producers_upgrade_system_contract, eosio_system_tester) try {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册