From 4284b3778d446b841bb8607becbde0e9f4a419ad Mon Sep 17 00:00:00 2001 From: Allen Han Date: Mon, 16 Mar 2020 11:05:32 -0400 Subject: [PATCH] merge minimize logging change to 2.0.x --- libraries/fc | 2 +- programs/cleos/main.cpp | 6 ++-- programs/eosio-blocklog/main.cpp | 2 +- programs/eosio-launcher/main.cpp | 4 +-- unittests/misc_tests.cpp | 59 +++++++++++++++++++++++++++++++- 5 files changed, 65 insertions(+), 8 deletions(-) diff --git a/libraries/fc b/libraries/fc index 89905627463..dc467524ce6 160000 --- a/libraries/fc +++ b/libraries/fc @@ -1 +1 @@ -Subproject commit 89905627463081c15bfa708a04cc7e68edb25dd0 +Subproject commit dc467524ce6d36b51184693646f60cba7360a6a6 diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index 876119bd1d9..b84174cfef0 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -429,7 +429,7 @@ fc::variant bin_to_variant( const account_name& account, const action_name& acti return abis->binary_to_variant( action_type, action_args, abi_serializer_max_time ); } -fc::variant json_from_file_or_string(const string& file_or_str, fc::json::parse_type ptype = fc::json::legacy_parser) +fc::variant json_from_file_or_string(const string& file_or_str, fc::json::parse_type ptype = fc::json::parse_type::legacy_parser) { regex r("^[ \t]*[\{\[]"); if ( !regex_search(file_or_str, r) && fc::is_regular_file(file_or_str) ) { @@ -447,7 +447,7 @@ fc::variant json_from_file_or_string(const string& file_or_str, fc::json::parse_ bytes json_or_file_to_bin( const account_name& account, const action_name& action, const string& data_or_filename ) { fc::variant action_args_var; if( !data_or_filename.empty() ) { - action_args_var = json_from_file_or_string(data_or_filename, fc::json::relaxed_parser); + action_args_var = json_from_file_or_string(data_or_filename, fc::json::parse_type::relaxed_parser); } return variant_to_bin( account, action, action_args_var ); } @@ -3446,7 +3446,7 @@ int main( int argc, char** argv ) { actionsSubcommand->set_callback([&] { fc::variant action_args_var; if( !data.empty() ) { - action_args_var = json_from_file_or_string(data, fc::json::relaxed_parser); + action_args_var = json_from_file_or_string(data, fc::json::parse_type::relaxed_parser); } auto accountPermissions = get_account_permissions(tx_permission); diff --git a/programs/eosio-blocklog/main.cpp b/programs/eosio-blocklog/main.cpp index 0220a2f23cb..20558a5b7a1 100644 --- a/programs/eosio-blocklog/main.cpp +++ b/programs/eosio-blocklog/main.cpp @@ -134,7 +134,7 @@ void blocklog::read_log() { (pretty_output.get_object()); fc::variant v(std::move(enhanced_object)); if (no_pretty_print) - fc::json::to_stream(*out, v, fc::time_point::maximum(), fc::json::stringify_large_ints_and_doubles); + fc::json::to_stream(*out, v, fc::time_point::maximum(), fc::json::output_formatting::stringify_large_ints_and_doubles); else *out << fc::json::to_pretty_string(v) << "\n"; }; diff --git a/programs/eosio-launcher/main.cpp b/programs/eosio-launcher/main.cpp index 8d1a4247b1b..039c4ca7f2a 100644 --- a/programs/eosio-launcher/main.cpp +++ b/programs/eosio-launcher/main.cpp @@ -1194,7 +1194,7 @@ launcher_def::write_logging_config_file(tn_node_def &node) { if( gelf_enabled ) pp.appenders.push_back( "net" ); log_config.loggers.emplace_back( pp ); - auto str = fc::json::to_pretty_string( log_config, fc::time_point::maximum(), fc::json::stringify_large_ints_and_doubles ); + auto str = fc::json::to_pretty_string( log_config, fc::time_point::maximum(), fc::json::output_formatting::stringify_large_ints_and_doubles ); cfg.write( str.c_str(), str.size() ); cfg.close(); } @@ -1244,7 +1244,7 @@ launcher_def::write_setprods_file() { if (p.producer_name != "eosio") no_bios.schedule.push_back(p); } - auto str = fc::json::to_pretty_string( no_bios, fc::time_point::maximum(), fc::json::stringify_large_ints_and_doubles ); + auto str = fc::json::to_pretty_string( no_bios, fc::time_point::maximum(), fc::json::output_formatting::stringify_large_ints_and_doubles ); psfile.write( str.c_str(), str.size() ); psfile.close(); } diff --git a/unittests/misc_tests.cpp b/unittests/misc_tests.cpp index 7414c8a104b..cb7a1ddc7fd 100644 --- a/unittests/misc_tests.cpp +++ b/unittests/misc_tests.cpp @@ -173,7 +173,10 @@ BOOST_AUTO_TEST_CASE(variant_format_string_limited) mu( "b", string( 1024, 'b' ) ); mu( "c", string( 1024, 'c' ) ); string result = fc::format_string( format, mu, true ); - BOOST_CHECK_EQUAL( result, string( 256, 'a' ) + "... " + string( 256, 'b' ) + "... " + string( 256, 'c' ) + "..." ); + BOOST_CHECK_LT(0, mu.size()); + BOOST_CHECK_LT(format.size(), 1024); + const size_t target_size = (1024 - format.size()) / mu.size(); + BOOST_CHECK_EQUAL( result, string( target_size, 'a' ) + "... " + string( target_size, 'b' ) + "... " + string( target_size, 'c' ) + "..." ); } { fc::mutable_variant_object mu; @@ -189,6 +192,60 @@ BOOST_AUTO_TEST_CASE(variant_format_string_limited) string result = fc::format_string( format, mu, true ); BOOST_CHECK_EQUAL( result, "${a} ${b} ${c}"); } + { + // test cases for issue #8741, short version, all fields being displayed + flat_set provided_permissions; + for(char ch = 'a'; ch < 'c'; ++ch) { + provided_permissions.insert( {name(std::string_view(string(4, ch))), name(std::string_view(string(4, ch + 1)))}); + } + flat_set provided_keys; + auto fill_keys = [](const flat_set & provided_permissions, flat_set & provided_keys) { + std::string digest = "1234567"; + for (auto &permission : provided_permissions) { + digest += "1"; + const std::string key_name_str = permission.actor.to_string() + permission.permission.to_string(); + auto sig_digest = digest_type::hash(std::make_pair("1234", "abcd")); + const fc::crypto::signature sig = private_key_type::regenerate( + fc::sha256::hash(key_name_str + "active")).sign(sig_digest); + provided_keys.insert(public_key_type{sig, fc::sha256{digest}, true}); + } + }; + fill_keys(provided_permissions, provided_keys); + const string format = "transaction declares authority '${auth}', provided permissions ${provided_permissions}, provided keys ${provided_keys}"; + fc::mutable_variant_object mu; + mu("auth", *provided_permissions.begin()); + mu("provided_permissions", provided_permissions); + mu("provided_keys", provided_keys); + BOOST_CHECK_LT(0, mu.size()); + const auto arg_limit_size = (1024 - format.size()) / mu.size(); + const string result = fc::format_string(format, mu, true); + BOOST_CHECK(provided_permissions.begin() != provided_permissions.end()); + const string auth_str = fc::json::to_string(*provided_permissions.begin(), fc::time_point::maximum()); + string target_str = "transaction declares authority '" + fc::json::to_string(*provided_permissions.begin(), fc::time_point::maximum()); + target_str += "', provided permissions " + fc::json::to_string(provided_permissions, fc::time_point::maximum()); + target_str += ", provided keys " + fc::json::to_string(provided_keys, fc::time_point::maximum()).substr(0, arg_limit_size); + BOOST_CHECK_EQUAL(result, target_str); + BOOST_CHECK_LT(result.size(), 1024 + 3 * mu.size()); + + // test cases for issue #8741, longer version, permission and keys field being folded + provided_permissions.clear(); + provided_keys.clear(); + for(char ch = 'c'; ch < 'z'; ++ch) { + provided_permissions.insert( {name(std::string_view(string(5, ch))), name(std::string_view(string(5, ch + 1)))}); + } + fill_keys(provided_permissions, provided_keys); + fc::mutable_variant_object mu_fold; + mu_fold("auth", *provided_permissions.begin()); + mu_fold("provided_permissions", provided_permissions); + mu_fold("provided_keys", provided_keys); + BOOST_CHECK_LT(0, mu_fold.size()); + string target_fold_str = "transaction declares authority '" + fc::json::to_string(*provided_permissions.begin(), fc::time_point::maximum()); + target_fold_str += "', provided permissions ${provided_permissions}"; + target_fold_str += ", provided keys ${provided_keys}"; + const string result_fold = fc::format_string(format, mu_fold, true); + BOOST_CHECK_EQUAL(result_fold, target_fold_str); + BOOST_CHECK_LT(result_fold.size(), 1024 + 3 * mu.size()); + } } // Test overflow handling in asset::from_string