未验证 提交 0032b618 编写于 作者: D Daniel Larimer 提交者: GitHub

Merge pull request #3417 from EOSIO/k-misc

Change producer deactivation logic
......@@ -80,7 +80,13 @@ namespace eosiosystem {
for ( auto it = idx.cbegin(); it != idx.cend() && top_producers.size() < 21 && 0 < it->total_votes; ++it ) {
if( !it->active() ) continue;
if ( it->time_became_active.slot == 0 ) {
/**
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 + blocks_per_day ) {
_producers.modify( *it, 0, [&](auto& p) {
p.time_became_active = block_time;
});
......@@ -92,6 +98,10 @@ namespace eosiosystem {
});
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}));
......
......@@ -46,8 +46,8 @@ BOOST_FIXTURE_TEST_CASE( buysell, eosio_system_tester ) try {
transfer( "eosio", "alice1111111", core_from_string("100000000.0000"), "eosio" );
BOOST_REQUIRE_EQUAL( core_from_string("100000998.0050"), get_balance( "alice1111111" ) );
// alice buys ram for 10000000.0000, 0.5% = 50000.0000 got to ramfee
// after fee 9950000.0000 got to bought bytes
// alice buys ram for 10000000.0000, 0.5% = 50000.0000 go to ramfee
// after fee 9950000.0000 go to bought bytes
// when selling back bought bytes, pay 0.5% fee and get back 99.5% of 9950000.0000 = 9900250.0000
// expected account after that is 90000998.0050 + 9900250.0000 = 99901248.0050 with a difference
// of order 0.0001 due to rounding errors
......@@ -1298,7 +1298,6 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni
const double usecs_per_year = secs_per_year * 1000000;
const double cont_rate = 4.879/100.;
const asset net = core_from_string("80.0000");
const asset cpu = core_from_string("80.0000");
create_account_with_resources( N(producvotera), config::system_account_name, core_from_string("1.0000"), false, net, cpu );
......@@ -1549,7 +1548,14 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni
// wait two more hours, now most producers haven't produced in a day and will
// be deactivated
produce_block(fc::seconds(2 * 3600));
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);
{
......@@ -1706,8 +1712,6 @@ BOOST_FIXTURE_TEST_CASE(producer_onblock_check, eosio_system_tester) try {
create_account_with_resources( N(producvoterb), config::system_account_name, core_from_string("1.0000"), false, large_asset, large_asset );
create_account_with_resources( N(producvoterc), config::system_account_name, core_from_string("1.0000"), false, large_asset, large_asset );
// create accounts {defproducera, defproducerb, ..., defproducerz} and register as producers
std::vector<account_name> producer_names;
producer_names.reserve('z' - 'a' + 1);
......@@ -2284,7 +2288,7 @@ BOOST_FIXTURE_TEST_CASE( multiple_namebids, eosio_system_tester ) try {
produce_block( fc::days(14) );
produce_block();
// highest bid is from david for prefd but not bids can be closed yet
// highest bid is from david for prefd but no bids can be closed yet
BOOST_REQUIRE_EXCEPTION( create_account_with_resources( N(prefd), N(david) ),
fc::exception, fc_assert_exception_message_is( not_closed_message ) );
......@@ -2360,6 +2364,110 @@ BOOST_FIXTURE_TEST_CASE( multiple_namebids, eosio_system_tester ) try {
} FC_LOG_AND_RETHROW()
BOOST_FIXTURE_TEST_CASE( vote_producers_in_and_out, eosio_system_tester ) try {
const asset net = core_from_string("80.0000");
const asset cpu = core_from_string("80.0000");
std::vector<account_name> voters = { N(producvotera), N(producvoterb), N(producvoterc), N(producvoterd) };
for (const auto& v: voters) {
create_account_with_resources(v, config::system_account_name, core_from_string("1.0000"), false, net, cpu);
}
// create accounts {defproducera, defproducerb, ..., defproducerz} and register as producers
std::vector<account_name> producer_names;
{
producer_names.reserve('z' - 'a' + 1);
const std::string root("defproducer");
for ( char c = 'a'; c <= 'z'; ++c ) {
producer_names.emplace_back(root + std::string(1, c));
}
setup_producer_accounts(producer_names);
for (const auto& p: producer_names) {
BOOST_REQUIRE_EQUAL( success(), regproducer(p) );
produce_blocks(1);
ilog( "------ get pro----------" );
wdump((p));
BOOST_TEST(0 == get_producer_info(p)["total_votes"].as<double>());
}
}
for (const auto& v: voters) {
transfer( config::system_account_name, v, core_from_string("200000000.0000"), config::system_account_name );
BOOST_REQUIRE_EQUAL(success(), stake(v, core_from_string("30000000.0000"), core_from_string("30000000.0000")) );
}
{
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()+20))
)
);
BOOST_REQUIRE_EQUAL(success(), push_action(N(producvoterb), N(voteproducer), mvo()
("voter", "producvoterb")
("proxy", name(0).to_string())
("producers", vector<account_name>(producer_names.begin(), producer_names.begin()+21))
)
);
BOOST_REQUIRE_EQUAL(success(), push_action(N(producvoterc), N(voteproducer), mvo()
("voter", "producvoterc")
("proxy", name(0).to_string())
("producers", vector<account_name>(producer_names.begin(), producer_names.end()))
)
);
}
// give a chance for everyone to produce blocks
{
produce_blocks(23 * 12 + 20);
bool all_21_produced = true;
for (uint32_t i = 0; i < 21; ++i) {
if (0 == get_producer_info(producer_names[i])["unpaid_blocks"].as<uint32_t>()) {
all_21_produced = false;
}
}
bool rest_didnt_produce = true;
for (uint32_t i = 21; i < producer_names.size(); ++i) {
if (0 < get_producer_info(producer_names[i])["unpaid_blocks"].as<uint32_t>()) {
rest_didnt_produce = false;
}
}
BOOST_REQUIRE(all_21_produced && rest_didnt_produce);
}
{
produce_block(fc::hours(7));
const uint32_t voted_out_index = 20;
const uint32_t new_prod_index = 23;
BOOST_REQUIRE_EQUAL(success(), stake("producvoterd", core_from_string("40000000.0000"), core_from_string("40000000.0000")));
BOOST_REQUIRE_EQUAL(success(), push_action(N(producvoterd), N(voteproducer), mvo()
("voter", "producvoterd")
("proxy", name(0).to_string())
("producers", vector<account_name>{ producer_names[new_prod_index] })
)
);
BOOST_REQUIRE_EQUAL(0, get_producer_info(producer_names[new_prod_index])["unpaid_blocks"].as<uint32_t>());
produce_blocks(4 * 12 * 21);
BOOST_REQUIRE(0 < get_producer_info(producer_names[new_prod_index])["unpaid_blocks"]);
const uint32_t initial_unpaid_blocks = get_producer_info(producer_names[voted_out_index])["unpaid_blocks"].as<uint32_t>();
produce_blocks(2 * 12 * 21);
BOOST_REQUIRE_EQUAL(initial_unpaid_blocks, get_producer_info(producer_names[voted_out_index])["unpaid_blocks"].as<uint32_t>());
produce_block(fc::hours(24));
BOOST_REQUIRE_EQUAL(success(), push_action(N(producvoterd), N(voteproducer), mvo()
("voter", "producvoterd")
("proxy", name(0).to_string())
("producers", vector<account_name>{ producer_names[voted_out_index] })
)
);
produce_blocks(2 * 12 * 21);
BOOST_REQUIRE(fc::crypto::public_key() != fc::crypto::public_key(get_producer_info(producer_names[voted_out_index])["producer_key"].as_string()));
BOOST_REQUIRE_EQUAL(success(), push_action(producer_names[voted_out_index], N(claimrewards), mvo()("owner", producer_names[voted_out_index])));
}
} FC_LOG_AND_RETHROW()
BOOST_FIXTURE_TEST_CASE( setparams, eosio_system_tester ) try {
//install multisig contract
abi_serializer msig_abi_ser = initialize_multisig();
......
......@@ -40,7 +40,7 @@ BOOST_FIXTURE_TEST_CASE(ram_tests, eosio_system::eosio_system_tester) { try {
buyrambytes(N(eosio), N(eosio), 70000);
produce_blocks(10);
create_account_with_resources(N(testram11111),N(eosio), init_request_bytes);
create_account_with_resources(N(testram22222),N(eosio), init_request_bytes);
create_account_with_resources(N(testram22222),N(eosio), init_request_bytes + 1150);
produce_blocks(10);
BOOST_REQUIRE_EQUAL( success(), stake( "eosio.stake", "testram11111", core_from_string("10.0000"), core_from_string("5.0000") ) );
produce_blocks(10);
......@@ -189,7 +189,6 @@ BOOST_FIXTURE_TEST_CASE(ram_tests, eosio_system::eosio_system_tester) { try {
fc_exception_message_starts_with("account testram11111 has insufficient ram"));
produce_blocks(1);
#if 0
// verify that the new entry is under the allocation bytes limit
tester->push_action( N(testram11111), N(setentry), {N(testram11111),N(testram22222)}, mvo()
("payer", "testram22222")
......@@ -260,7 +259,7 @@ BOOST_FIXTURE_TEST_CASE(ram_tests, eosio_system::eosio_system_tester) { try {
("to", 22)
("size", 1910));
produce_blocks(1);
#endif
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_SUITE_END()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册