提交 bf439d4c 编写于 作者: D Daniel Larimer

Merge branch 'slim' of github.com:EOSIO/eos into slim

......@@ -87,45 +87,49 @@ void resource_limits_manager::add_transaction_usage(const flat_set<account_name>
for( const auto& a : accounts ) {
const auto& usage = _db.get<resource_usage_object,by_owner>( a );
const auto& limits = _db.get<resource_limits_object,by_owner>( boost::make_tuple(false, a));
int64_t unused;
int64_t net_weight;
int64_t cpu_weight;
get_account_limits( a, unused, net_weight, cpu_weight );
_db.modify( usage, [&]( auto& bu ){
bu.net_usage.add( net_usage, time_slot, config.account_net_usage_average_window );
bu.cpu_usage.add( cpu_usage, time_slot, config.account_cpu_usage_average_window );
});
if (limits.cpu_weight >= 0 && state.total_cpu_weight > 0 ) {
if( cpu_weight >= 0 && state.total_cpu_weight > 0 ) {
uint128_t window_size = config.account_cpu_usage_average_window;
auto virtual_network_capacity_in_window = state.virtual_cpu_limit * window_size;
auto cpu_used_in_window = (usage.cpu_usage.value_ex * window_size) / config::rate_limiting_precision;
uint128_t user_weight = limits.cpu_weight;
uint128_t user_weight = cpu_weight;
uint128_t all_user_weight = state.total_cpu_weight;
auto max_user_use_in_window = (virtual_network_capacity_in_window * user_weight) / all_user_weight;
EOS_ASSERT( cpu_used_in_window <= max_user_use_in_window,
EOS_ASSERT( cpu_used_in_window <= max_user_use_in_window,
tx_cpu_usage_exceeded,
"authorizing account '${n}' has insufficient cpu resources for this transaction",
"authorizing account '${n}' has insufficient cpu resources for this transaction",
("n", name(a))
("cpu_used_in_window",cpu_used_in_window)
("max_user_use_in_window",max_user_use_in_window) );
}
if( limits.net_weight >= 0 && state.total_net_weight > 0) {
if( net_weight >= 0 && state.total_net_weight > 0) {
uint128_t window_size = config.account_net_usage_average_window;
auto virtual_network_capacity_in_window = state.virtual_net_limit * window_size;
auto net_used_in_window = (usage.net_usage.value_ex * window_size) / config::rate_limiting_precision;
uint128_t user_weight = limits.net_weight;
uint128_t user_weight = net_weight;
uint128_t all_user_weight = state.total_net_weight;
auto max_user_use_in_window = (virtual_network_capacity_in_window * user_weight) / all_user_weight;
EOS_ASSERT( net_used_in_window <= max_user_use_in_window,
EOS_ASSERT( net_used_in_window <= max_user_use_in_window,
tx_net_usage_exceeded,
"authorizing account '${n}' has insufficient net resources for this transaction",
"authorizing account '${n}' has insufficient net resources for this transaction",
("n", name(a))
("net_used_in_window",net_used_in_window)
("max_user_use_in_window",max_user_use_in_window) );
......
......@@ -32,11 +32,11 @@ add_dependencies(unit_test asserter test_api test_api_mem test_api_db test_api_m
#Manually run unit_test for all supported runtimes
#To run unit_test with all log from blockchain displayed, put --verbose after --, i.e. unit_test -- --verbose
add_test(NAME unit_test_binaryen COMMAND unit_test
-t \!eosio_system_tests/*
-t \!eosio_system_tests/elect_producers
-t \!wasm_tests/weighted_cpu_limit_tests
--report_level=detailed --color_output -- --binaryen)
add_test(NAME unit_test_wavm COMMAND unit_test
-t \!eosio_system_tests/*
-t \!eosio_system_tests/elect_producers
-t \!wasm_tests/weighted_cpu_limit_tests
--report_level=detailed --color_output --catch_system_errors=no -- --wavm)
......
......@@ -172,8 +172,8 @@ public:
account_name creator(N(eosio));
signed_transaction trx;
set_transaction_headers(trx);
asset cpu = asset::from_string("80.0000 EOS");
asset net = asset::from_string("80.0000 EOS");
asset cpu = asset::from_string("12000000.0000 EOS"); // why need to state too much CPU inorder to register inita-initz
asset net = asset::from_string("1000000.0000 EOS");
asset ram = asset::from_string("1.0000 EOS");
for (const auto& a: accounts) {
......@@ -290,12 +290,13 @@ public:
}
action_result regproducer( const account_name& acnt, int params_fixture = 1 ) {
wdump((acnt));
return push_action( acnt, N(regproducer), mvo()
action_result r = push_action( acnt, N(regproducer), mvo()
("producer", acnt )
("producer_key", get_public_key( acnt, "active" ) )
("url", "" )
);
BOOST_REQUIRE_EQUAL( success(), r);
return r;
}
uint32_t last_block_time() const {
......@@ -1689,6 +1690,198 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester) try {
} FC_LOG_AND_RETHROW()
BOOST_FIXTURE_TEST_CASE(producer_onblock_check, eosio_system_tester) try {
const auto tol = boost::test_tools::tolerance(0.0000000001);
const asset large_asset = asset::from_string("100000000.0000 EOS");
create_account_with_resources( N(vota), N(eosio), asset::from_string("1.0000 EOS"), false, large_asset, large_asset );
create_account_with_resources( N(votb), N(eosio), asset::from_string("1.0000 EOS"), false, large_asset, large_asset );
create_account_with_resources( N(votc), N(eosio), asset::from_string("1.0000 EOS"), false, large_asset, large_asset );
// create accounts {inita, initb, ..., initz} and register as producers
setup_producer_accounts();
std::vector<account_name> producer_names={N(inita),N(initb),N(initc),N(initd),N(inite),N(initf),N(initg),N(inith),
N(initi),N(initj),N(initk),N(initl),N(initm),N(initn),N(inito),N(initp),N(initq),N(initr),N(inits),N(initt),
N(initu),N(initv),N(initw),N(initx),N(inity),N(initz)};
for (auto a:producer_names)
regproducer(a);
BOOST_REQUIRE_EQUAL(0, get_producer_info( N(inita) )["total_votes"].as<double>());
BOOST_REQUIRE_EQUAL(0, get_producer_info( N(initz) )["total_votes"].as<double>());
issue( "vota", "100000000.0000 EOS", config::system_account_name);
BOOST_REQUIRE_EQUAL(success(), stake("vota", "30000000.0000 EOS", "30000000.0000 EOS"));
BOOST_REQUIRE_EQUAL(success(), push_action(N(vota), N(voteproducer), mvo()
("voter", "vota")
("proxy", name(0).to_string())
("producers", vector<account_name>(producer_names.begin(), producer_names.begin()+10))
));
// give a chance for everyone to produce blocks
{
produce_blocks(21 * 12);
bool all_21_produced = true;
for (uint32_t i = 0; i < 21; ++i) {
if (0 == get_producer_info(producer_names[i])["produced_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])["produced_blocks"].as<uint32_t>()) {
rest_didnt_produce = false;
}
}
BOOST_REQUIRE_EQUAL(false, all_21_produced);
BOOST_REQUIRE_EQUAL(true, rest_didnt_produce);
}
// issue across 15% boundary
issue( "votb", "100000000.0000 EOS", config::system_account_name);
BOOST_REQUIRE_EQUAL(success(), stake("votb", "30000000.0000 EOS", "30000000.0000 EOS"));
issue( "votc", "100000000.0000 EOS", config::system_account_name);
BOOST_REQUIRE_EQUAL(success(), stake("votc", "30000000.0000 EOS", "30000000.0000 EOS"));
BOOST_REQUIRE_EQUAL(success(), push_action(N(votb), N(voteproducer), mvo()
("voter", "votb")
("proxy", name(0).to_string())
("producers", vector<account_name>(producer_names.begin(), producer_names.begin()+21))
)
);
BOOST_REQUIRE_EQUAL(success(), push_action(N(votc), N(voteproducer), mvo()
("voter", "votc")
("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(21 * 12);
bool all_21_produced = true;
for (uint32_t i = 0; i < 21; ++i) {
if (0 == get_producer_info(producer_names[i])["produced_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])["produced_blocks"].as<uint32_t>()) {
rest_didnt_produce = false;
}
}
BOOST_REQUIRE_EQUAL(true, all_21_produced);
BOOST_REQUIRE_EQUAL(true, rest_didnt_produce);
}
} FC_LOG_AND_RETHROW()
BOOST_FIXTURE_TEST_CASE(multiple_producer_pay_unfair, eosio_system_tester) try {
const auto tol = boost::test_tools::tolerance(0.0000000001);
const int64_t secs_per_year = 52 * 7 * 24 * 3600;
const int64_t blocks_per_year = 52 * 7* 24 * 3600 * 2;
const double cont_rate = 4.879/100.;
const double standby_rate = 0.750/100.;
const double block_rate = 0.250/100.;
const asset large_asset = asset::from_string("100000000.0000 EOS");
create_account_with_resources( N(vota), N(eosio), asset::from_string("1.0000 EOS"), false, large_asset, large_asset );
create_account_with_resources( N(votb), N(eosio), asset::from_string("1.0000 EOS"), false, large_asset, large_asset );
create_account_with_resources( N(votc), N(eosio), asset::from_string("1.0000 EOS"), false, large_asset, large_asset );
// create accounts {inita, initb, ..., initz} and register as producers
setup_producer_accounts();
std::vector<account_name> producer_names={N(inita),N(initb),N(initc),N(initd),N(inite),N(initf),N(initg),N(inith),
N(initi),N(initj),N(initk),N(initl),N(initm),N(initn),N(inito),N(initp),N(initq),N(initr),N(inits),N(initt),
N(initu),N(initv),N(initw),N(initx),N(inity),N(initz)};
for (auto a:producer_names)
regproducer(a);
BOOST_REQUIRE_EQUAL(0, get_producer_info( N(inita) )["total_votes"].as<double>());
BOOST_REQUIRE_EQUAL(0, get_producer_info( N(initz) )["total_votes"].as<double>());
{
issue( "vota", "100000000.0000 EOS", config::system_account_name);
BOOST_REQUIRE_EQUAL(success(), stake("vota", "30000000.0000 EOS", "30000000.0000 EOS"));
issue( "votb", "100000000.0000 EOS", config::system_account_name);
BOOST_REQUIRE_EQUAL(success(), stake("votb", "30000000.0000 EOS", "30000000.0000 EOS"));
issue( "votc", "100000000.0000 EOS", config::system_account_name);
BOOST_REQUIRE_EQUAL(success(), stake("votc", "30000000.0000 EOS", "30000000.0000 EOS"));
}
// vota votes for inita ... initj
// votb votes for inita ... initu
// votc votes for inita ... initz
{
BOOST_REQUIRE_EQUAL(success(), push_action(N(vota), N(voteproducer), mvo()
("voter", "vota")
("proxy", name(0).to_string())
("producers", vector<account_name>(producer_names.begin(), producer_names.begin()+10))
)
);
BOOST_REQUIRE_EQUAL(success(), push_action(N(votb), N(voteproducer), mvo()
("voter", "votb")
("proxy", name(0).to_string())
("producers", vector<account_name>(producer_names.begin(), producer_names.begin()+21))
)
);
BOOST_REQUIRE_EQUAL(success(), push_action(N(votc), N(voteproducer), mvo()
("voter", "votc")
("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(21 * 12);
produce_block(fc::seconds(24 * 3600 * 3));
produce_blocks(21 * 12);
bool all_21_produced = true;
for (uint32_t i = 0; i < 21; ++i) {
if (0 == get_producer_info(producer_names[i])["produced_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])["produced_blocks"].as<uint32_t>()) {
rest_didnt_produce = false;
}
}
BOOST_REQUIRE(all_21_produced && rest_didnt_produce);
}
BOOST_REQUIRE_EQUAL( 0, get_balance( N(inita) ).amount );
BOOST_REQUIRE_EQUAL( 0, get_balance( N(initb) ).amount );
account_name prod = N(initb);
BOOST_REQUIRE_EQUAL(success(), push_action(prod, N(claimrewards), mvo()("owner", prod)));
BOOST_REQUIRE_EQUAL(42346751, get_balance( prod ).amount );
prod = N(initc);
BOOST_REQUIRE_EQUAL(success(), push_action(prod, N(claimrewards), mvo()("owner", prod)));
BOOST_REQUIRE_EQUAL(40118632, get_balance( prod ).amount );
prod = N(inita);
BOOST_REQUIRE_EQUAL(success(), push_action(prod, N(claimrewards), mvo()("owner", prod)));
BOOST_REQUIRE_EQUAL(38007778, get_balance( prod ).amount );
} FC_LOG_AND_RETHROW()
BOOST_FIXTURE_TEST_CASE( voters_actions_affect_proxy_and_producers, eosio_system_tester, * boost::unit_test::tolerance(1e+6) ) try {
create_accounts_with_resources( { N(donald), N(producer1), N(producer2), N(producer3) } );
BOOST_REQUIRE_EQUAL( success(), regproducer( "producer1", 1) );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册