From 4a79aead347126c2b09da23c0b566dc4f885135c Mon Sep 17 00:00:00 2001 From: Anton Perkov Date: Thu, 8 Mar 2018 09:22:52 -0500 Subject: [PATCH] unregister producer, more tests for system contracts, change in static_variant reverted --- contracts/eosio.system/eosio.system.abi | 11 +++++- contracts/eosio.system/voting.hpp | 31 ++++++++++++--- contracts/eosiolib/privileged.hpp | 2 +- libraries/fc/include/fc/static_variant.hpp | 2 +- tests/wasm_tests/eosio.system_tests.cpp | 44 ++++++++++++++++++++-- 5 files changed, 77 insertions(+), 13 deletions(-) diff --git a/contracts/eosio.system/eosio.system.abi b/contracts/eosio.system/eosio.system.abi index e4740bbe5..aa83a00cb 100644 --- a/contracts/eosio.system/eosio.system.abi +++ b/contracts/eosio.system/eosio.system.abi @@ -95,13 +95,22 @@ {"name":"inflation_rate", "type":"uint32"}, {"name":"storage_reserve_ratio", "type":"uint32"}, ] - },,{ + },{ "name": "eosio_global_state", "base": "eosio_parameters", "fields": [ {"name":"total_storage_bytes_reserved", "type":"uint64"}, {"name":"total_storage_stake", "type":"uint64"} ] + },{ + "name": "producer_info", + "base": "", + "fields": [ + {"name":"owner", "type":"uint64"}, + {"name":"total_votes", "type":"uint128"}, + {"name":"prefs", "type":"eosio_parameters"}, + {"name":"packed_key", "type":"uint8[]"} + ] },{ "name": "regproducer", "base": "", diff --git a/contracts/eosio.system/voting.hpp b/contracts/eosio.system/voting.hpp index a113f5c7d..99ed959e1 100644 --- a/contracts/eosio.system/voting.hpp +++ b/contracts/eosio.system/voting.hpp @@ -43,11 +43,11 @@ namespace eosiosystem { static constexpr uint32_t unstake_payments = 26; // during 26 weeks struct producer_info { - account_name owner; - uint64_t padding = 0; - uint128_t total_votes = 0; + account_name owner; + uint64_t padding = 0; + uint128_t total_votes = 0; eosio_parameters prefs; - eosio::bytes packed_key; /// a packed public key object + eosio::bytes packed_key; /// a packed public key object uint64_t primary_key()const { return owner; } uint128_t by_votes()const { return total_votes; } @@ -82,8 +82,8 @@ namespace eosiosystem { typedef eosio::multi_index< N(voters), voter_info> voters_table; ACTION( SystemAccount, regproducer ) { - account_name producer; - bytes producer_key; + account_name producer; + bytes producer_key; eosio_parameters prefs; EOSLIB_SERIALIZE( regproducer, (producer)(producer_key)(prefs) ) @@ -106,6 +106,7 @@ namespace eosiosystem { if ( prod ) { producers_tbl.update( *prod, reg.producer, [&]( producer_info& info ){ info.prefs = reg.prefs; + info.packed_key = reg.producer_key; }); } else { producers_tbl.emplace( reg.producer, [&]( producer_info& info ){ @@ -117,6 +118,24 @@ namespace eosiosystem { } } + ACTION( SystemAccount, unregproducer ) { + account_name producer; + + EOSLIB_SERIALIZE( unregproducer, (producer) ) + }; + + static void on( const unregproducer& unreg ) { + require_auth( unreg.producer ); + + producers_table producers_tbl( SystemAccount, SystemAccount ); + const auto* prod = producers_tbl.find( unreg.producer ); + eosio_assert( bool(prod), "producer not found" ); + + producers_tbl.update( *prod, 0, [&]( producer_info& info ){ + info.packed_key.clear(); + }); + } + ACTION( SystemAccount, stakevote ) { account_name voter; system_token_type amount; diff --git a/contracts/eosiolib/privileged.hpp b/contracts/eosiolib/privileged.hpp index eae84dd4e..56e41c8b0 100644 --- a/contracts/eosiolib/privileged.hpp +++ b/contracts/eosiolib/privileged.hpp @@ -5,7 +5,7 @@ namespace eosio { struct blockchain_parameters : ::blockchain_parameters { - + EOSLIB_SERIALIZE( blockchain_parameters, (target_block_size)(max_block_size)(target_block_acts_per_scope) (max_block_acts_per_scope)(target_block_acts)(max_block_acts)(max_storage_size) (max_transaction_lifetime)(max_transaction_exec_time)(max_authority_depth) diff --git a/libraries/fc/include/fc/static_variant.hpp b/libraries/fc/include/fc/static_variant.hpp index 3801c7311..3a0a7ab72 100644 --- a/libraries/fc/include/fc/static_variant.hpp +++ b/libraries/fc/include/fc/static_variant.hpp @@ -195,7 +195,7 @@ class static_variant { static_assert(impl::type_info::no_reference_types, "Reference types are not permitted in static_variant."); static_assert(impl::type_info::no_duplicates, "static_variant type arguments contain duplicate types."); - uint32_t _tag; + int _tag; char storage[impl::type_info::size]; template diff --git a/tests/wasm_tests/eosio.system_tests.cpp b/tests/wasm_tests/eosio.system_tests.cpp index b1b827695..e10d4bd49 100644 --- a/tests/wasm_tests/eosio.system_tests.cpp +++ b/tests/wasm_tests/eosio.system_tests.cpp @@ -74,7 +74,7 @@ public: fc::variant get_producer_info( const account_name& act ) { vector data = get_row_by_account( config::system_account_name, config::system_account_name, N(producerinfo), act ); - return abi_ser.binary_to_variant( "eosio_global_state", data ); + return abi_ser.binary_to_variant( "producer_info", data ); } abi_serializer abi_ser; @@ -545,16 +545,52 @@ BOOST_FIXTURE_TEST_CASE( producer_register_unregister, eosio_system_tester ) try ("inflation_rate", 1051) ("storage_reserve_ratio", 1005); + vector key = fc::raw::pack( fc::crypto::public_key( std::string("EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV") ) ); BOOST_REQUIRE_EQUAL( success(), push_action(N(alice), N(regproducer), mvo() ("producer", "alice") - ("producer_key", fc::raw::pack( fc::crypto::public_key( std::string("EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV") ) ) ) + ("producer_key", key ) ("prefs", params) ) ); auto info = get_producer_info( "alice" ); - BOOST_REQUIRE_EQUAL( true, info.is_object() ); - REQUIRE_EQUAL_OBJECTS( params, info ); + BOOST_REQUIRE_EQUAL( N(alice), info["owner"].as_uint64() ); + BOOST_REQUIRE_EQUAL( 0, info["total_votes"].as_uint64() ); + REQUIRE_EQUAL_OBJECTS( params, info["prefs"] ); + BOOST_REQUIRE_EQUAL( string(key.begin(), key.end()), to_string(info["packed_key"]) ); + + + //do regproducer again to change parameters + fc::variant params2 = mutable_variant_object() + ("target_block_size", 1024 * 1024 + 1) + ("max_block_size", 10 * 1024 + 1) + ("target_block_acts_per_scope", 1002) + ("max_block_acts_per_scope", 10002) + ("target_block_acts", 1102) + ("max_block_acts", 11002) + ("max_storage_size", 2002) + ("max_transaction_lifetime", 3602) + ("max_transaction_exec_time", 9997) + ("max_authority_depth", 7) + ("max_inline_depth", 5) + ("max_inline_action_size", 4095) + ("max_generated_transaction_size", 64*1025) + ("inflation_rate", 1052) + ("storage_reserve_ratio", 1006); + + vector key2 = fc::raw::pack( fc::crypto::public_key( std::string("EOSR16EPHFSKVYHBjQgxVGQPrwCxTg7BbZ69H9i4gztN9deKTEXYne4") ) ); + BOOST_REQUIRE_EQUAL( success(), push_action(N(alice), N(regproducer), mvo() + ("producer", "alice") + ("producer_key", key2 ) + ("prefs", params2) + ) + ); + + info = get_producer_info( "alice" ); + BOOST_REQUIRE_EQUAL( N(alice), info["owner"].as_uint64() ); + BOOST_REQUIRE_EQUAL( 0, info["total_votes"].as_uint64() ); + REQUIRE_EQUAL_OBJECTS( params2, info["prefs"] ); + BOOST_REQUIRE_EQUAL( string(key2.begin(), key2.end()), to_string(info["packed_key"]) ); } FC_LOG_AND_RETHROW() -- GitLab