From 948624df2a394ce5288dd3ee47698e446d1ea57d Mon Sep 17 00:00:00 2001 From: Pavel Baykov Date: Fri, 15 Apr 2022 09:44:06 -0300 Subject: [PATCH] enable sanitizers, enable debug dump, fix memory write errors in _p2p_network->close() , fix: disable _p2p_network->close() in shutdown, because of double invoking --- CMakeLists.txt | 3 +++ libraries/app/application.cpp | 5 ++--- libraries/chain/account_evaluator.cpp | 2 ++ libraries/chain/db_debug.cpp | 8 +++----- libraries/chain/db_update.cpp | 3 +++ libraries/net/peer_database.cpp | 8 ++++---- tests/cli/son.cpp | 6 ++++++ 7 files changed, 23 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f5dcd324..607afca1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,9 @@ set( GUI_CLIENT_EXECUTABLE_NAME Peerplays ) set( CUSTOM_URL_SCHEME "gcs" ) set( INSTALLER_APP_ID "68ad7005-8eee-49c9-95ce-9eed97e5b347" ) +add_compile_options(-fsanitize=address -fsanitize-recover=address) +add_link_options(-fsanitize=address -fsanitize-recover=address -static-libasan) + # http://stackoverflow.com/a/18369825 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 4fcd22e7..ef03a1b7 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -1009,11 +1009,10 @@ void application::shutdown_plugins() { return; } void application::shutdown() { - if (my->_p2p_network) - my->_p2p_network->close(); + //if (my->_p2p_network) + // my->_p2p_network->close(); if (my->_chain_db){ my->_chain_db->close(); - my->_chain_db.reset(); } } diff --git a/libraries/chain/account_evaluator.cpp b/libraries/chain/account_evaluator.cpp index aa199c84..a62dbda5 100644 --- a/libraries/chain/account_evaluator.cpp +++ b/libraries/chain/account_evaluator.cpp @@ -287,6 +287,8 @@ void_result account_update_evaluator::do_apply( const account_update_operation& { try { database& d = db(); + d.debug_dump(); + bool sa_before = acnt->has_special_authority(); // update account statistics diff --git a/libraries/chain/db_debug.cpp b/libraries/chain/db_debug.cpp index 27beb3ed..1898e436 100644 --- a/libraries/chain/db_debug.cpp +++ b/libraries/chain/db_debug.cpp @@ -50,12 +50,12 @@ void database::debug_dump() for( const account_balance_object& a : balance_index ) { - // idump(("balance")(a)); + idump(("balance")(a)); total_balances[a.asset_type] += a.balance; } for( const account_statistics_object& s : statistics_index ) { - // idump(("statistics")(s)); + idump(("statistics")(s)); reported_core_in_orders += s.total_core_in_orders; } for( const limit_order_object& o : db.get_index_type().indices() ) @@ -86,13 +86,11 @@ void database::debug_dump() } - /* const auto& vbidx = db.get_index_type>(); for( const auto& s : vbidx ) { -// idump(("vesting_balance")(s)); + idump(("vesting_balance")(s)); } - */ } void debug_apply_update( database& db, const fc::variant_object& vo ) diff --git a/libraries/chain/db_update.cpp b/libraries/chain/db_update.cpp index 0476982c..bc66d10b 100644 --- a/libraries/chain/db_update.cpp +++ b/libraries/chain/db_update.cpp @@ -89,6 +89,9 @@ void database::update_global_dynamic_data( const signed_block& b, const uint32_t ("recently_missed",_dgp.recently_missed_count)("max_undo",GRAPHENE_MAX_UNDO_HISTORY) ); } + ilog( "_dgp.head_block_number is ${head}", ("head", _dgp.head_block_number) ); + ilog( "_dgp.last_irreversible_block_num is ${lib}", ("lib", _dgp.last_irreversible_block_num) ); + _undo_db.set_max_size( _dgp.head_block_number - _dgp.last_irreversible_block_num + 1 ); _fork_db.set_max_size( _dgp.head_block_number - _dgp.last_irreversible_block_num + 1 ); } diff --git a/libraries/net/peer_database.cpp b/libraries/net/peer_database.cpp index 76ae9c8c..4d6e5fe6 100644 --- a/libraries/net/peer_database.cpp +++ b/libraries/net/peer_database.cpp @@ -114,16 +114,16 @@ namespace graphene { namespace net { void peer_database_impl::close() { - std::vector peer_records; - peer_records.reserve(_potential_peer_set.size()); - std::copy(_potential_peer_set.begin(), _potential_peer_set.end(), std::back_inserter(peer_records)); + //std::vector peer_records; + //peer_records.reserve(_potential_peer_set.size()); + //std::copy(_potential_peer_set.begin(), _potential_peer_set.end(), std::back_inserter(peer_records)); try { fc::path peer_database_filename_dir = _peer_database_filename.parent_path(); if (!fc::exists(peer_database_filename_dir)) fc::create_directories(peer_database_filename_dir); - fc::json::save_to_file( peer_records, _peer_database_filename, GRAPHENE_NET_MAX_NESTED_OBJECTS ); + fc::json::save_to_file( /*peer_records*/ _potential_peer_set, _peer_database_filename, GRAPHENE_NET_MAX_NESTED_OBJECTS ); } catch (const fc::exception& e) { diff --git a/tests/cli/son.cpp b/tests/cli/son.cpp index 491ec8f9..468f1740 100644 --- a/tests/cli/son.cpp +++ b/tests/cli/son.cpp @@ -664,11 +664,15 @@ BOOST_FIXTURE_TEST_CASE( cli_list_active_sons, cli_fixture ) } BOOST_CHECK(generate_maintenance_block()); + //con.wallet_api_ptr->debug_dump(); + BOOST_TEST_MESSAGE("Voting for SONs"); + for(unsigned int i = 1; i < son_number + 1; i++) { std::string name = "sonaccount" + fc::to_pretty_string(i); vote_tx = con.wallet_api_ptr->vote_for_son(name, name, true, true); + ilog("vote_tx is ${vote_tx}", ("vote_tx", vote_tx)); } BOOST_CHECK(generate_maintenance_block()); @@ -677,6 +681,7 @@ BOOST_FIXTURE_TEST_CASE( cli_list_active_sons, cli_fixture ) std::string name1 = "sonaccount" + fc::to_pretty_string(i); std::string name2 = "sonaccount" + fc::to_pretty_string(i + 1); vote_tx = con.wallet_api_ptr->vote_for_son(name1, name2, true, true); + ilog("2nd_vote_tx is ${vote_tx}", ("vote_tx", vote_tx)); } BOOST_CHECK(generate_maintenance_block()); gpo = con.wallet_api_ptr->get_global_properties(); @@ -693,6 +698,7 @@ BOOST_FIXTURE_TEST_CASE( cli_list_active_sons, cli_fixture ) } BOOST_CHECK_NO_THROW(con.wallet_api_ptr->list_active_sons()); + } catch( fc::exception& e ) { BOOST_TEST_MESSAGE("SON cli wallet tests exception"); edump((e.to_detail_string()));