提交 77e14d3d 编写于 作者: K Khaled Al-Hassanieh

Fixed abi issues, part of producer pay tests

上级 b4407434
...@@ -87,30 +87,30 @@ ...@@ -87,30 +87,30 @@
"name": "blockchain_parameters", "name": "blockchain_parameters",
"base": "", "base": "",
"fields": [ "fields": [
{"name":"max_block_net_usage", "type": "uint32"}, {"name":"max_block_net_usage", "type":"uint64"},
{"name":"target_block_net_usage_pct", "type": "uint32"}, {"name":"target_block_net_usage_pct", "type":"uint32"},
{"name":"max_transaction_net_usage", "type":"uint32"}, {"name":"max_transaction_net_usage", "type":"uint32"},
{"name":"base_per_transaction_net_usage", "type":"uint32"}, {"name":"base_per_transaction_net_usage", "type":"uint32"},
{"name":"net_usage_leeway", "type":"uint32"}, {"name":"net_usage_leeway", "type":"uint32"},
{"name":"context_free_discount_net_usage_num", "type":"uint32"}, {"name":"context_free_discount_net_usage_num", "type":"uint32"},
{"name":"context_free_discount_net_usage_den", "type":"uint32"}, {"name":"context_free_discount_net_usage_den", "type":"uint32"},
{"name":"max_block_cpu_usage", "type": "uint64"}, {"name":"max_block_cpu_usage", "type":"uint32"},
{"name":"target_block_cpu_usage_pct", "type": "uint32"}, {"name":"target_block_cpu_usage_pct", "type":"uint32"},
{"name":"max_transaction_cpu_usage", "type":"uint32"}, {"name":"max_transaction_cpu_usage", "type":"uint32"},
{"name":"base_per_transaction_cpu_usage", "type":"uint32"}, {"name":"base_per_transaction_cpu_usage", "type":"uint32"},
{"name":"base_per_action_cpu_usage", "type":"uint32"}, {"name":"base_per_action_cpu_usage", "type":"uint32"},
{"name":"base_setcode_cpu_usage", "type":"uint32"}, {"name":"base_setcode_cpu_usage", "type":"uint32"},
{"name":"per_signature_cpu_usage", "type":"uint32"}, {"name":"per_signature_cpu_usage", "type":"uint32"},
{"name":"cpu_usage_leeway", "type":"uint32"}, {"name":"cpu_usage_leeway", "type":"uint32"},
{"name":"context_free_discount_cpu_usage_num", "type":"uint32"}, {"name":"context_free_discount_cpu_usage_num", "type":"uint32"},
{"name":"context_free_discount_cpu_usage_den", "type":"uint32"}, {"name":"context_free_discount_cpu_usage_den", "type":"uint32"},
{"name":"max_transaction_lifetime", "type":"uint32"}, {"name":"max_transaction_lifetime", "type":"uint32"},
{"name":"deferred_trx_expiration_window", "type":"uint32"}, {"name":"deferred_trx_expiration_window", "type":"uint32"},
{"name":"max_transaction_delay", "type":"uint32"}, {"name":"max_transaction_delay", "type":"uint32"},
{"name":"max_inline_action_size", "type":"uint32"}, {"name":"max_inline_action_size", "type":"uint32"},
{"name":"max_inline_action_depth", "type":"uint16"}, {"name":"max_inline_action_depth", "type":"uint16"},
{"name":"max_authority_depth", "type":"uint16"}, {"name":"max_authority_depth", "type":"uint16"},
{"name":"max_generated_transaction_count", "type":"uint32"} {"name":"max_generated_transaction_count", "type":"uint32"}
] ]
},{ },{
"name": "eosio_parameters", "name": "eosio_parameters",
...@@ -123,16 +123,16 @@ ...@@ -123,16 +123,16 @@
"base": "eosio_parameters", "base": "eosio_parameters",
"fields": [ "fields": [
{"name":"total_ram_bytes_reserved", "type":"uint64"}, {"name":"total_ram_bytes_reserved", "type":"uint64"},
{"name":"total_ram_stake", "type":"uint64"}, {"name":"total_ram_stake", "type":"int64"},
{"name":"last_producer_schedule_update", "type":"time"}, {"name":"last_producer_schedule_update", "type":"time"},
{"name":"last_pervote_bucket_fill", "type":"uint64"}, {"name":"last_pervote_bucket_fill", "type":"uint64"},
{"name":"pervote_bucket", "type":"int64"}, {"name":"pervote_bucket", "type":"int64"},
{"name":"perblock_bucket", "type":"int64"}, {"name":"perblock_bucket", "type":"int64"},
{"name":"savings", "type":"int64"}, {"name":"savings", "type":"int64"},
{"name":"last_producer_schedule_id", "type":"checksum160"},
{"name":"total_activatied_stake", "type":"int64"},
{"name":"total_producer_vote_weight", "type":"float64"},
{"name":"total_unpaid_blocks", "type":"uint32"} {"name":"total_unpaid_blocks", "type":"uint32"}
{"name":"total_activated_stake", "type":"int64"},
{"name":"last_producer_schedule_id", "type":"checksum160"},
{"name":"total_producer_vote_weight", "type":"float64"}
] ]
},{ },{
"name": "producer_info", "name": "producer_info",
......
...@@ -36,17 +36,17 @@ namespace eosiosystem { ...@@ -36,17 +36,17 @@ namespace eosiosystem {
int64_t pervote_bucket; int64_t pervote_bucket;
int64_t perblock_bucket; int64_t perblock_bucket;
int64_t savings; int64_t savings;
checksum160 last_producer_schedule_id; uint32_t total_unpaid_blocks = 0; /// all blocks which have been produced but not paid
int64_t total_activated_stake = 0; int64_t total_activated_stake = 0;
checksum160 last_producer_schedule_id;
double total_producer_vote_weight = 0; /// the sum of all producer votes double total_producer_vote_weight = 0; /// the sum of all producer votes
int32_t total_unpaid_blocks = 0; /// all blocks which have been produced but not paid // checksum160 last_producer_schedule_id;
// explicit serialization macro is not necessary, used here only to improve compilation time // explicit serialization macro is not necessary, used here only to improve compilation time
EOSLIB_SERIALIZE_DERIVED( eosio_global_state, eosio_parameters, (total_ram_bytes_reserved)(total_ram_stake) EOSLIB_SERIALIZE_DERIVED( eosio_global_state, eosio_parameters, (total_ram_bytes_reserved)(total_ram_stake)
(last_producer_schedule_update) (last_producer_schedule_update)
(last_pervote_bucket_fill) (last_pervote_bucket_fill)
(pervote_bucket)(perblock_bucket)(savings)(last_producer_schedule_id)(total_activated_stake)(total_producer_vote_weight)(total_unpaid_blocks) ) (pervote_bucket)(perblock_bucket)(savings)(total_unpaid_blocks)(total_activated_stake)(last_producer_schedule_id)(total_producer_vote_weight) )
}; };
struct producer_info { struct producer_info {
......
...@@ -85,7 +85,7 @@ namespace eosiosystem { ...@@ -85,7 +85,7 @@ namespace eosiosystem {
int64_t producer_per_vote_pay = int64_t((_gstate.pervote_bucket * prod.total_votes ) / _gstate.total_producer_vote_weight); int64_t producer_per_vote_pay = int64_t((_gstate.pervote_bucket * prod.total_votes ) / _gstate.total_producer_vote_weight);
int64_t total_pay = producer_per_block_pay + producer_per_vote_pay; int64_t total_pay = producer_per_block_pay + producer_per_vote_pay;
eosio_assert( total_pay > 100'0000, "insufficient pay to claim, require at least 100.0000 EOS" ); eosio_assert( total_pay > 1000000 /* 100'0000 */, "insufficient pay to claim, require at least 100.0000 EOS" );
_gstate.pervote_bucket -= producer_per_vote_pay; _gstate.pervote_bucket -= producer_per_vote_pay;
_gstate.perblock_bucket -= producer_per_block_pay; _gstate.perblock_bucket -= producer_per_block_pay;
......
...@@ -209,7 +209,7 @@ inline datastream<Stream>& operator>>(datastream<Stream>& ds, bool& d) { ...@@ -209,7 +209,7 @@ inline datastream<Stream>& operator>>(datastream<Stream>& ds, bool& d) {
*/ */
template<typename Stream> template<typename Stream>
inline datastream<Stream>& operator<<(datastream<Stream>& ds, const checksum256& d) { inline datastream<Stream>& operator<<(datastream<Stream>& ds, const checksum256& d) {
ds.write( (const char*)&d, sizeof(d) ); ds.write( (const char*)&d.hash[0], sizeof(d.hash) );
return ds; return ds;
} }
/** /**
...@@ -220,7 +220,7 @@ inline datastream<Stream>& operator<<(datastream<Stream>& ds, const checksum256& ...@@ -220,7 +220,7 @@ inline datastream<Stream>& operator<<(datastream<Stream>& ds, const checksum256&
*/ */
template<typename Stream> template<typename Stream>
inline datastream<Stream>& operator>>(datastream<Stream>& ds, checksum256& d) { inline datastream<Stream>& operator>>(datastream<Stream>& ds, checksum256& d) {
ds.read((char*)&d, sizeof(d) ); ds.read((char*)&d.hash[0], sizeof(d.hash) );
return ds; return ds;
} }
...@@ -514,25 +514,25 @@ bytes pack( const T& value ) { ...@@ -514,25 +514,25 @@ bytes pack( const T& value ) {
template<typename Stream> template<typename Stream>
inline datastream<Stream>& operator<<(datastream<Stream>& ds, const checksum160& cs) { inline datastream<Stream>& operator<<(datastream<Stream>& ds, const checksum160& cs) {
ds.write((const char*)&cs, sizeof(cs)); ds.write((const char*)&cs.hash[0], sizeof(cs.hash));
return ds; return ds;
} }
template<typename Stream> template<typename Stream>
inline datastream<Stream>& operator>>(datastream<Stream>& ds, checksum160& cs) { inline datastream<Stream>& operator>>(datastream<Stream>& ds, checksum160& cs) {
ds.read((char*)&cs, sizeof(cs)); ds.read((char*)&cs.hash[0], sizeof(cs.hash));
return ds; return ds;
} }
template<typename Stream> template<typename Stream>
inline datastream<Stream>& operator<<(datastream<Stream>& ds, const checksum512& cs) { inline datastream<Stream>& operator<<(datastream<Stream>& ds, const checksum512& cs) {
ds.write((const char*)&cs, sizeof(cs)); ds.write((const char*)&cs.hash[0], sizeof(cs.hash));
return ds; return ds;
} }
template<typename Stream> template<typename Stream>
inline datastream<Stream>& operator>>(datastream<Stream>& ds, checksum512& cs) { inline datastream<Stream>& operator>>(datastream<Stream>& ds, checksum512& cs) {
ds.read((char*)&cs, sizeof(cs)); ds.read((char*)&cs.hash[0], sizeof(cs.hash));
return ds; return ds;
} }
......
...@@ -1299,6 +1299,10 @@ BOOST_FIXTURE_TEST_CASE( proxy_actions_affect_producers, eosio_system_tester, * ...@@ -1299,6 +1299,10 @@ BOOST_FIXTURE_TEST_CASE( proxy_actions_affect_producers, eosio_system_tester, *
} FC_LOG_AND_RETHROW() } FC_LOG_AND_RETHROW()
BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester, * boost::unit_test::tolerance(1e-10)) try { BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester, * boost::unit_test::tolerance(1e-10)) try {
const double continuous_rate = 4.879 / 100.;
const double usecs_per_year = 52 * 7 * 24 * 3600 * 1000000ll;
const asset large_asset = asset::from_string("80.0000 EOS"); const asset large_asset = asset::from_string("80.0000 EOS");
create_account_with_resources( N(inita), N(eosio), asset::from_string("1.0000 EOS"), false, large_asset, large_asset ); create_account_with_resources( N(inita), N(eosio), asset::from_string("1.0000 EOS"), false, large_asset, large_asset );
create_account_with_resources( N(initb), N(eosio), asset::from_string("1.0000 EOS"), false, large_asset, large_asset ); create_account_with_resources( N(initb), N(eosio), asset::from_string("1.0000 EOS"), false, large_asset, large_asset );
...@@ -1311,7 +1315,7 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester, * boost::unit_test::t ...@@ -1311,7 +1315,7 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester, * boost::unit_test::t
BOOST_REQUIRE_EQUAL("inita", prod["owner"].as_string()); BOOST_REQUIRE_EQUAL("inita", prod["owner"].as_string());
BOOST_REQUIRE_EQUAL(0, prod["total_votes"].as_double()); BOOST_REQUIRE_EQUAL(0, prod["total_votes"].as_double());
issue( "vota", "400000000.0000 EOS", config::system_account_name); transfer( config::system_account_name, "vota", "400000000.0000 EOS", config::system_account_name);
BOOST_REQUIRE_EQUAL(success(), stake("vota", "100000000.0000 EOS", "100000000.0000 EOS")); BOOST_REQUIRE_EQUAL(success(), stake("vota", "100000000.0000 EOS", "100000000.0000 EOS"));
BOOST_REQUIRE_EQUAL(success(), push_action(N(vota), N(voteproducer), mvo() BOOST_REQUIRE_EQUAL(success(), push_action(N(vota), N(voteproducer), mvo()
...@@ -1326,41 +1330,51 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester, * boost::unit_test::t ...@@ -1326,41 +1330,51 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester, * boost::unit_test::t
{ {
produce_blocks(1000); produce_blocks(1000);
const auto initial_global_state = get_global_state(); const auto initial_global_state = get_global_state();
const uint64_t initial_claim_time = initial_global_state["last_pervote_bucket_fill"].as_uint64(); const uint64_t initial_claim_time = initial_global_state["last_pervote_bucket_fill"].as_uint64();
const int64_t initial_pervote_bucket = initial_global_state["pervote_bucket"].as<int64_t>(); const int64_t initial_pervote_bucket = initial_global_state["pervote_bucket"].as<int64_t>();
const int64_t initial_savings = initial_global_state["savings"].as<int64_t>(); const int64_t initial_perblock_bucket = initial_global_state["perblock_bucket"].as<int64_t>();
const int64_t initial_savings = initial_global_state["savings"].as<int64_t>();
const uint32_t initial_tot_unpaid_blocks = initial_global_state["total_unpaid_blocks"].as<uint32_t>();
prod = get_producer_info("inita"); prod = get_producer_info("inita");
const uint32_t produced_blocks = prod["produced_blocks"].as<uint32_t>(); const uint32_t unpaid_blocks = prod["produced_blocks"].as<uint32_t>();
BOOST_REQUIRE(1 < produced_blocks); BOOST_REQUIRE(1 < unpaid_blocks);
BOOST_REQUIRE_EQUAL(0, prod["last_claim_time"].as<uint64_t>()); BOOST_REQUIRE_EQUAL(0, prod["last_claim_time"].as<uint64_t>());
BOOST_REQUIRE_EQUAL(initial_tot_unpaid_blocks, unpaid_blocks);
const asset initial_supply = get_token_supply(); const asset initial_supply = get_token_supply();
const asset initial_balance = get_balance(N(inita)); const asset initial_balance = get_balance(N(inita));
BOOST_REQUIRE_EQUAL(success(), push_action(N(inita), N(claimrewards), mvo()("owner", "inita"))); BOOST_REQUIRE_EQUAL(success(), push_action(N(inita), N(claimrewards), mvo()("owner", "inita")));
const auto global_state = get_global_state(); const auto global_state = get_global_state();
const uint64_t claim_time = global_state["last_pervote_bucket_fill"].as_uint64(); const uint64_t claim_time = global_state["last_pervote_bucket_fill"].as_uint64();
const int64_t pervote_bucket = global_state["pervote_bucket"].as<int64_t>(); const int64_t pervote_bucket = global_state["pervote_bucket"].as<int64_t>();
const int64_t savings = global_state["savings"].as<int64_t>(); const int64_t perblock_bucket = global_state["perblock_bucket"].as<int64_t>();
const int64_t savings = global_state["savings"].as<int64_t>();
const uint32_t tot_unpaid_blocks = global_state["total_unpaid_blocks"].as<uint32_t>();
prod = get_producer_info("inita"); prod = get_producer_info("inita");
BOOST_REQUIRE_EQUAL(1, prod["produced_blocks"].as<uint32_t>()); BOOST_REQUIRE_EQUAL(1, prod["produced_blocks"].as<uint32_t>());
BOOST_REQUIRE_EQUAL(1, tot_unpaid_blocks);
const asset supply = get_token_supply(); const asset supply = get_token_supply();
const asset balance = get_balance(N(inita)); const asset balance = get_balance(N(inita));
BOOST_REQUIRE_EQUAL(claim_time, prod["last_claim_time"].as<uint64_t>()); BOOST_REQUIRE_EQUAL(claim_time, prod["last_claim_time"].as<uint64_t>());
const int32_t secs_between_fills = static_cast<int32_t>((claim_time - initial_claim_time) / 1000000); auto usecs_between_fills = claim_time - initial_claim_time;
BOOST_REQUIRE_EQUAL(0, initial_pervote_bucket); BOOST_REQUIRE_EQUAL(0, initial_pervote_bucket);
BOOST_REQUIRE_EQUAL(int64_t( ( initial_supply.amount * double(usecs_between_fills) * continuous_rate ) / usecs_per_year ),
// BOOST_REQUIRE_EQUAL(int64_t( (initial_supply.amount * secs_between_fills * ((4.879-1.0)/100.0)) / (52*7*24*3600) ), supply.amount - initial_supply.amount);
// savings - initial_savings); BOOST_REQUIRE_EQUAL(int64_t( ( initial_supply.amount * double(usecs_between_fills) * (4. * continuous_rate/ 5.) / usecs_per_year ) ),
savings - initial_savings);
/* int64_t block_payments = int64_t( initial_supply.amount * unpaid_blocks * (0.25/100.0) / (52*7*24*3600*2) );
int64_t block_payments = int64_t( initial_supply.amount * produced_blocks * (0.25/100.0) / (52*7*24*3600*2) ); int64_t from_pervote_bucket = int64_t( initial_supply.amount * usecs_between_fills * (0.75/100.0) / (52*7*24*3600) );
int64_t from_pervote_bucket = int64_t( initial_supply.amount * secs_between_fills * (0.75/100.0) / (52*7*24*3600) ); return;
/*
if (from_pervote_bucket >= 100 * 10000) { if (from_pervote_bucket >= 100 * 10000) {
BOOST_REQUIRE_EQUAL(block_payments + from_pervote_bucket, balance.amount - initial_balance.amount); BOOST_REQUIRE_EQUAL(block_payments + from_pervote_bucket, balance.amount - initial_balance.amount);
BOOST_REQUIRE_EQUAL(0, pervote_bucket); BOOST_REQUIRE_EQUAL(0, pervote_bucket);
...@@ -1369,9 +1383,8 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester, * boost::unit_test::t ...@@ -1369,9 +1383,8 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester, * boost::unit_test::t
BOOST_REQUIRE_EQUAL(from_pervote_bucket, pervote_bucket); BOOST_REQUIRE_EQUAL(from_pervote_bucket, pervote_bucket);
} }
*/ */
// const int64_t max_supply_growth = int64_t( (initial_supply.amount * usecs_between_fills * (4.879/100.0)) / (52*7*24*3600) );
const int64_t max_supply_growth = int64_t( (initial_supply.amount * secs_between_fills * (4.879/100.0)) / (52*7*24*3600) ); // BOOST_REQUIRE(max_supply_growth >= supply.amount - initial_supply.amount);
BOOST_REQUIRE(max_supply_growth >= supply.amount - initial_supply.amount);
} }
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册