From 9da846cbcc9d8e43018d192e55374181a18e0871 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sun, 3 Nov 2019 11:41:26 +0100 Subject: [PATCH 001/147] Disable p2p network when delayed_node plugin is enabled --- libraries/app/api.cpp | 14 +++++++++++--- libraries/app/application.cpp | 3 ++- libraries/app/include/graphene/app/plugin.hpp | 2 +- .../witness/include/graphene/witness/witness.hpp | 3 ++- libraries/plugins/witness/witness.cpp | 8 +++++++- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 99564106a2..d10ed283df 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -218,6 +218,7 @@ namespace graphene { namespace app { fc::variant_object network_node_api::get_info() const { + FC_ASSERT( _app.p2p_node() != nullptr, "No P2P network!" ); fc::mutable_variant_object result = _app.p2p_node()->network_get_info(); result["connection_count"] = _app.p2p_node()->get_connection_count(); return result; @@ -225,26 +226,33 @@ namespace graphene { namespace app { void network_node_api::add_node(const fc::ip::endpoint& ep) { - _app.p2p_node()->add_node(ep); + if( _app.p2p_node() != nullptr ) + _app.p2p_node()->add_node(ep); } std::vector network_node_api::get_connected_peers() const { - return _app.p2p_node()->get_connected_peers(); + if( _app.p2p_node() != nullptr ) + return _app.p2p_node()->get_connected_peers(); + return {}; } std::vector network_node_api::get_potential_peers() const { - return _app.p2p_node()->get_potential_peers(); + if( _app.p2p_node() != nullptr ) + return _app.p2p_node()->get_potential_peers(); + return {}; } fc::variant_object network_node_api::get_advanced_node_parameters() const { + FC_ASSERT( _app.p2p_node() != nullptr, "No P2P network!" ); return _app.p2p_node()->get_advanced_node_parameters(); } void network_node_api::set_advanced_node_parameters(const fc::variant_object& params) { + FC_ASSERT( _app.p2p_node() != nullptr, "No P2P network!" ); return _app.p2p_node()->set_advanced_node_parameters(params); } diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index de5bf8a334..42b8778e20 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -537,7 +537,8 @@ void application_impl::startup() _apiaccess.permission_map["*"] = wild_access; } - reset_p2p_node(_data_dir); + if( _active_plugins.find( "delayed_node" ) == _active_plugins.end() ) + reset_p2p_node(_data_dir); reset_websocket_server(); reset_websocket_tls_server(); } FC_LOG_AND_RETHROW() } diff --git a/libraries/app/include/graphene/app/plugin.hpp b/libraries/app/include/graphene/app/plugin.hpp index 45336f677c..a4286d9c75 100644 --- a/libraries/app/include/graphene/app/plugin.hpp +++ b/libraries/app/include/graphene/app/plugin.hpp @@ -114,7 +114,7 @@ class plugin : public abstract_plugin chain::database& database() { return *app().chain_database(); } application& app()const { assert(_app); return *_app; } protected: - net::node& p2p_node() { return *app().p2p_node(); } + net::node_ptr p2p_node() { return app().p2p_node(); } private: application* _app = nullptr; diff --git a/libraries/plugins/witness/include/graphene/witness/witness.hpp b/libraries/plugins/witness/include/graphene/witness/witness.hpp index 8ca09a5b27..8f7a8b61de 100644 --- a/libraries/plugins/witness/include/graphene/witness/witness.hpp +++ b/libraries/plugins/witness/include/graphene/witness/witness.hpp @@ -42,7 +42,8 @@ namespace block_production_condition low_participation = 5, lag = 6, exception_producing_block = 7, - shutdown = 8 + shutdown = 8, + no_network = 9 }; } diff --git a/libraries/plugins/witness/witness.cpp b/libraries/plugins/witness/witness.cpp index d2609625ab..26b8b232f9 100644 --- a/libraries/plugins/witness/witness.cpp +++ b/libraries/plugins/witness/witness.cpp @@ -300,6 +300,9 @@ block_production_condition::block_production_condition_enum witness_plugin::bloc case block_production_condition::shutdown: ilog( "shutdown producing block" ); return result; + case block_production_condition::no_network: + ilog( "not connected to P2P network" ); + return result; default: elog( "unknown condition ${result} while producing block", ("result", (unsigned char)result) ); break; @@ -374,6 +377,9 @@ block_production_condition::block_production_condition_enum witness_plugin::mayb return block_production_condition::lag; } + if( p2p_node() == nullptr ) + return block_production_condition::no_network; + auto block = db.generate_block( scheduled_time, scheduled_witness, @@ -381,7 +387,7 @@ block_production_condition::block_production_condition_enum witness_plugin::mayb _production_skip_flags ); capture("n", block.block_num())("t", block.timestamp)("c", now)("x", block.transactions.size()); - fc::async( [this,block](){ p2p_node().broadcast(net::block_message(block)); } ); + fc::async( [this,block](){ p2p_node()->broadcast(net::block_message(block)); } ); return block_production_condition::produced; } From 6eb5b2242fa3ea9a43f41b63c94e294e637f2d35 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Mon, 4 Nov 2019 18:49:32 +0100 Subject: [PATCH 002/147] Fail in network_broadcast_api when not connected to P2P network --- libraries/app/api.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index d10ed283df..e02229881f 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -180,9 +180,9 @@ namespace graphene { namespace app { void network_broadcast_api::broadcast_transaction(const precomputable_transaction& trx) { _app.chain_database()->precompute_parallel( trx ).wait(); + FC_ASSERT( _app.p2p_node() != nullptr, "Not connected to P2P network, can't broadcast!" ); _app.chain_database()->push_transaction(trx); - if( _app.p2p_node() != nullptr ) - _app.p2p_node()->broadcast_transaction(trx); + _app.p2p_node()->broadcast_transaction(trx); } fc::variant network_broadcast_api::broadcast_transaction_synchronous(const precomputable_transaction& trx) @@ -198,18 +198,18 @@ namespace graphene { namespace app { void network_broadcast_api::broadcast_block( const signed_block& b ) { _app.chain_database()->precompute_parallel( b ).wait(); + FC_ASSERT( _app.p2p_node() != nullptr, "Not connected to P2P network, can't broadcast!" ); _app.chain_database()->push_block(b); - if( _app.p2p_node() != nullptr ) - _app.p2p_node()->broadcast( net::block_message( b )); + _app.p2p_node()->broadcast( net::block_message( b )); } void network_broadcast_api::broadcast_transaction_with_callback(confirmation_callback cb, const precomputable_transaction& trx) { _app.chain_database()->precompute_parallel( trx ).wait(); + FC_ASSERT( _app.p2p_node() != nullptr, "Not connected to P2P network, can't broadcast!" ); _callbacks[trx.id()] = cb; _app.chain_database()->push_transaction(trx); - if( _app.p2p_node() != nullptr ) - _app.p2p_node()->broadcast_transaction(trx); + _app.p2p_node()->broadcast_transaction(trx); } network_node_api::network_node_api( application& a ) : _app( a ) From 359af02b2d6a73570a582a55d44d6eb2343a51b2 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 6 Nov 2019 08:34:26 +0100 Subject: [PATCH 003/147] Refactored database_fixture for better customization --- tests/common/database_fixture.cpp | 364 ++++++++++++++---------------- tests/common/database_fixture.hpp | 67 +++++- tests/elasticsearch/main.cpp | 6 +- tests/tests/block_tests.cpp | 9 +- 4 files changed, 237 insertions(+), 209 deletions(-) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 211957ce2a..52344bad54 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -22,7 +22,6 @@ * THE SOFTWARE. */ #include -#include #include #include @@ -43,8 +42,6 @@ #include #include -#include - #include #include @@ -69,10 +66,13 @@ void clearable_block::clear() _block_id = block_id_type(); } -database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) - : app(), db( *app.chain_database() ) -{ - try { +database_fixture_base::database_fixture_base() + : app(), db( *app.chain_database() ), + init_account_pub_key( init_account_priv_key.get_public_key() ), + current_test_name( buf::current_test_case().p_name.value ), + current_suite_name( buf::get(buf::current_test_case().p_parent_id).p_name + .value ) +{ try { int argc = buf::master_test_suite().argc; char** argv = buf::master_test_suite().argv; for( int i=1; i(current_test_suite_id).p_name.value; - auto mhplugin = app.register_plugin(); - auto goplugin = app.register_plugin(); - init_account_pub_key = init_account_priv_key.get_public_key(); - - boost::program_options::variables_map options; - - genesis_state.initial_timestamp = initial_timestamp; +database_fixture_base::~database_fixture_base() +{ + try { + // If we're unwinding due to an exception, don't do any more checks. + // This way, boost test's last checkpoint tells us approximately where the error was. + if( !std::uncaught_exception() ) + { + verify_asset_supplies(db); + BOOST_CHECK( db.get_node_properties().skip_flags == database::skip_nothing ); + } + return; + } catch (fc::exception& ex) { + BOOST_FAIL( std::string("fc::exception in ~database_fixture: ") + ex.to_detail_string() ); + } catch (std::exception& e) { + BOOST_FAIL( std::string("std::exception in ~database_fixture:") + e.what() ); + } catch (...) { + BOOST_FAIL( "Uncaught exception in ~database_fixture" ); + } +} - if(current_test_name == "hf_1270_test") +void database_fixture_base::init_genesis( database_fixture_base& fixture ) +{ + fixture.genesis_state.initial_timestamp = fc::time_point_sec(GRAPHENE_TESTING_GENESIS_TIMESTAMP); + if( fixture.current_test_name == "hf_1270_test" ) { - genesis_state.initial_active_witnesses = 20; + fixture.genesis_state.initial_active_witnesses = 20; } else { - genesis_state.initial_active_witnesses = 10; - genesis_state.immutable_parameters.min_committee_member_count = INITIAL_COMMITTEE_MEMBER_COUNT; - genesis_state.immutable_parameters.min_witness_count = INITIAL_WITNESS_COUNT; + fixture.genesis_state.initial_active_witnesses = 10; + fixture.genesis_state.immutable_parameters.min_committee_member_count = INITIAL_COMMITTEE_MEMBER_COUNT; + fixture.genesis_state.immutable_parameters.min_witness_count = INITIAL_WITNESS_COUNT; } - for( unsigned int i = 0; i < genesis_state.initial_active_witnesses; ++i ) + for( unsigned int i = 0; i < fixture.genesis_state.initial_active_witnesses; ++i ) { auto name = "init"+fc::to_string(i); - genesis_state.initial_accounts.emplace_back(name, - init_account_priv_key.get_public_key(), - init_account_priv_key.get_public_key(), - true); - genesis_state.initial_committee_candidates.push_back({name}); - genesis_state.initial_witness_candidates.push_back({name, init_account_priv_key.get_public_key()}); + fixture.genesis_state.initial_accounts.emplace_back( name, fixture.init_account_pub_key, + fixture.init_account_pub_key, true); + fixture.genesis_state.initial_committee_candidates.push_back({name}); + fixture.genesis_state.initial_witness_candidates.push_back({ name, fixture.init_account_pub_key }); } - genesis_state.initial_parameters.get_mutable_fees().zero_all_fees(); + fixture.genesis_state.initial_parameters.get_mutable_fees().zero_all_fees(); genesis_state_type::initial_asset_type init_mpa1; init_mpa1.symbol = "INITMPA"; @@ -125,142 +136,144 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) init_mpa1.max_supply = GRAPHENE_MAX_SHARE_SUPPLY; init_mpa1.accumulated_fees = 0; init_mpa1.is_bitasset = true; - // TODO add initial UIA's; add initial short positions; test non-zero accumulated_fees - genesis_state.initial_assets.push_back( init_mpa1 ); - - open_database(); + fixture.genesis_state.initial_assets.push_back( init_mpa1 ); +} +boost::program_options::variables_map database_fixture_base::init_options( database_fixture_base& fixture ) +{ + boost::program_options::variables_map options; + set_option( options, "seed-nodes", std::string("[]") ); /** * Test specific settings */ - if (current_test_name == "get_account_history_operations") + if (fixture.current_test_name == "get_account_history_operations") { options.insert(std::make_pair("max-ops-per-account", boost::program_options::variable_value((uint64_t)75, false))); } - if (current_test_name == "api_limit_get_account_history_operations") + if (fixture.current_test_name == "api_limit_get_account_history_operations") { options.insert(std::make_pair("max-ops-per-account", boost::program_options::variable_value((uint64_t)125, false))); options.insert(std::make_pair("api-limit-get-account-history-operations", boost::program_options::variable_value((uint64_t)300, false))); } - if(current_test_name =="api_limit_get_account_history") + if(fixture.current_test_name =="api_limit_get_account_history") { options.insert(std::make_pair("max-ops-per-account", boost::program_options::variable_value((uint64_t)125, false))); options.insert(std::make_pair("api-limit-get-account-history", boost::program_options::variable_value((uint64_t)250, false))); } - if(current_test_name =="api_limit_get_grouped_limit_orders") + if(fixture.current_test_name =="api_limit_get_grouped_limit_orders") { options.insert(std::make_pair("api-limit-get-grouped-limit-orders", boost::program_options::variable_value((uint64_t)250, false))); } - if(current_test_name =="api_limit_get_relative_account_history") + if(fixture.current_test_name =="api_limit_get_relative_account_history") { options.insert(std::make_pair("max-ops-per-account", boost::program_options::variable_value((uint64_t)125, false))); options.insert(std::make_pair("api-limit-get-relative-account-history", boost::program_options::variable_value((uint64_t)250, false))); } - if(current_test_name =="api_limit_get_account_history_by_operations") + if(fixture.current_test_name =="api_limit_get_account_history_by_operations") { options.insert(std::make_pair("api-limit-get-account-history-by-operations", boost::program_options::variable_value((uint64_t)250, false))); options.insert(std::make_pair("api-limit-get-relative-account-history", boost::program_options::variable_value((uint64_t)250, false))); } - if(current_test_name =="api_limit_get_asset_holders") + if(fixture.current_test_name =="api_limit_get_asset_holders") { options.insert(std::make_pair("api-limit-get-asset-holders", boost::program_options::variable_value((uint64_t)250, false))); } - if(current_test_name =="api_limit_get_key_references") + if(fixture.current_test_name =="api_limit_get_key_references") { options.insert(std::make_pair("api-limit-get-key-references", boost::program_options::variable_value((uint64_t)200, false))); } - if(current_test_name =="api_limit_get_limit_orders") + if(fixture.current_test_name =="api_limit_get_limit_orders") { options.insert(std::make_pair("api-limit-get-limit-orders", boost::program_options::variable_value( (uint64_t)350, false))); } - if(current_test_name =="api_limit_get_call_orders") + if(fixture.current_test_name =="api_limit_get_call_orders") { options.insert(std::make_pair("api-limit-get-call-orders", boost::program_options::variable_value( (uint64_t)350, false))); } - if(current_test_name =="api_limit_get_settle_orders") + if(fixture.current_test_name =="api_limit_get_settle_orders") { options.insert(std::make_pair("api-limit-get-settle-orders", boost::program_options::variable_value( (uint64_t)350, false))); } - if(current_test_name =="api_limit_get_order_book") + if(fixture.current_test_name =="api_limit_get_order_book") { options.insert(std::make_pair("api-limit-get-order-book", boost::program_options::variable_value( (uint64_t)80, false))); } - if( current_test_name == "asset_in_collateral" ) + if( fixture.current_test_name == "asset_in_collateral" ) { options.insert( std::make_pair( "plugins", boost::program_options::variable_value( string("api_helper_indexes"), false ) ) ); } - if(current_test_name =="api_limit_lookup_accounts") + if(fixture.current_test_name =="api_limit_lookup_accounts") { options.insert(std::make_pair("api-limit-lookup-accounts", boost::program_options::variable_value ((uint64_t)200, false))); } - if(current_test_name =="api_limit_lookup_witness_accounts") + if(fixture.current_test_name =="api_limit_lookup_witness_accounts") { options.insert(std::make_pair("api-limit-lookup-witness-accounts", boost::program_options::variable_value ((uint64_t)200, false))); } - if(current_test_name =="api_limit_lookup_committee_member_accounts") + if(fixture.current_test_name =="api_limit_lookup_committee_member_accounts") { options.insert(std::make_pair("api-limit-lookup-committee-member-accounts", boost::program_options::variable_value ((uint64_t)200, false))); } - if(current_test_name =="api_limit_lookup_committee_member_accounts") + if(fixture.current_test_name =="api_limit_lookup_committee_member_accounts") { options.insert(std::make_pair("api-limit-lookup-committee-member-accounts", boost::program_options::variable_value ((uint64_t)200, false))); } - if(current_test_name =="api_limit_lookup_vote_ids") + if(fixture.current_test_name =="api_limit_lookup_vote_ids") { options.insert(std::make_pair("api-limit-lookup-vote-ids", boost::program_options::variable_value ((uint64_t)3, false))); } - if(current_test_name =="api_limit_get_account_limit_orders") + if(fixture.current_test_name =="api_limit_get_account_limit_orders") { options.insert(std::make_pair("api-limit-get-account-limit-orders", boost::program_options::variable_value ((uint64_t)250, false))); } - if(current_test_name =="api_limit_get_collateral_bids") + if(fixture.current_test_name =="api_limit_get_collateral_bids") { options.insert(std::make_pair("api-limit-get-collateral-bids", boost::program_options::variable_value ((uint64_t)250, false))); } - if(current_test_name =="api_limit_get_top_markets") + if(fixture.current_test_name =="api_limit_get_top_markets") { options.insert(std::make_pair("api-limit-get-top-markets", boost::program_options::variable_value ((uint64_t)250, false))); } - if(current_test_name =="api_limit_get_trade_history") + if(fixture.current_test_name =="api_limit_get_trade_history") { options.insert(std::make_pair("api-limit-get-trade-history", boost::program_options::variable_value ((uint64_t)250, false))); } - if(current_test_name =="api_limit_get_trade_history_by_sequence") + if(fixture.current_test_name =="api_limit_get_trade_history_by_sequence") { options.insert(std::make_pair("api-limit-get-trade-history-by-sequence", boost::program_options::variable_value ((uint64_t)250, false))); } - if(current_test_name =="api_limit_get_withdraw_permissions_by_giver") + if(fixture.current_test_name =="api_limit_get_withdraw_permissions_by_giver") { options.insert(std::make_pair("api-limit-get-withdraw-permissions-by-giver", boost::program_options::variable_value ((uint64_t)250, false))); } - if(current_test_name =="api_limit_get_withdraw_permissions_by_recipient") + if(fixture.current_test_name =="api_limit_get_withdraw_permissions_by_recipient") { options.insert(std::make_pair("api-limit-get-withdraw-permissions-by-recipient", boost::program_options::variable_value ((uint64_t)250, false))); } - if(current_test_name =="api_limit_get_full_accounts2") + if(fixture.current_test_name =="api_limit_get_full_accounts2") { options.insert(std::make_pair("api-limit-get-full-accounts", boost::program_options::variable_value ((uint64_t)200, false))); } // add account tracking for ahplugin for special test case with track-account enabled - if( !options.count("track-account") && current_test_name == "track_account") { + if( !options.count("track-account") && fixture.current_test_name == "track_account") { std::vector track_account; std::string track = "\"1.2.17\""; track_account.push_back(track); @@ -268,7 +281,7 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) options.insert(std::make_pair("partial-operations", boost::program_options::variable_value(true, false))); } // account tracking 2 accounts - if( !options.count("track-account") && current_test_name == "track_account2") { + if( !options.count("track-account") && fixture.current_test_name == "track_account2") { std::vector track_account; std::string track = "\"1.2.0\""; track_account.push_back(track); @@ -277,14 +290,14 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) options.insert(std::make_pair("track-account", boost::program_options::variable_value(track_account, false))); } // standby votes tracking - if( current_test_name == "track_votes_witnesses_disabled" - || current_test_name == "track_votes_committee_disabled") { - app.chain_database()->enable_standby_votes_tracking( false ); + if( fixture.current_test_name == "track_votes_witnesses_disabled" + || fixture.current_test_name == "track_votes_committee_disabled") { + fixture.app.chain_database()->enable_standby_votes_tracking( false ); } - if(current_test_name == "elasticsearch_account_history" || current_test_name == "elasticsearch_suite" || - current_test_name == "elasticsearch_history_api") { - auto esplugin = app.register_plugin(); - esplugin->plugin_set_app(&app); + if(fixture.current_test_name == "elasticsearch_account_history" || fixture.current_test_name == "elasticsearch_suite" || + fixture.current_test_name == "elasticsearch_history_api") { + auto esplugin = fixture.app.register_plugin(); + esplugin->plugin_set_app(&fixture.app); options.insert(std::make_pair("elasticsearch-node-url", boost::program_options::variable_value(string("http://localhost:9200/"), false))); options.insert(std::make_pair("elasticsearch-bulk-replay", boost::program_options::variable_value(uint32_t(2), false))); @@ -298,23 +311,23 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) esplugin->plugin_initialize(options); esplugin->plugin_startup(); } - else if( current_suite_name != "performance_tests" ) + else if( fixture.current_suite_name != "performance_tests" ) { - auto ahplugin = app.register_plugin(); - ahplugin->plugin_set_app(&app); + auto ahplugin = fixture.app.register_plugin(); + ahplugin->plugin_set_app(&fixture.app); ahplugin->plugin_initialize(options); ahplugin->plugin_startup(); - if(validation_current_test_name_for_setting_api_limit(current_test_name)) + if(validation_current_test_name_for_setting_api_limit(fixture.current_test_name)) { - app.initialize(graphene::utilities::temp_directory_path(), options); - app.set_api_limit(); + fixture.app.initialize(graphene::utilities::temp_directory_path(), options); + fixture.app.set_api_limit(); } } - if(current_test_name == "elasticsearch_objects" || current_test_name == "elasticsearch_suite") { - auto esobjects_plugin = app.register_plugin(); - esobjects_plugin->plugin_set_app(&app); + if(fixture.current_test_name == "elasticsearch_objects" || fixture.current_test_name == "elasticsearch_suite") { + auto esobjects_plugin = fixture.app.register_plugin(); + esobjects_plugin->plugin_set_app(&fixture.app); options.insert(std::make_pair("es-objects-elasticsearch-url", boost::program_options::variable_value(string("http://localhost:9200/"), false))); options.insert(std::make_pair("es-objects-bulk-replay", boost::program_options::variable_value(uint32_t(2), false))); @@ -329,71 +342,41 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) esobjects_plugin->plugin_initialize(options); esobjects_plugin->plugin_startup(); } - else if( current_test_name == "asset_in_collateral" - || current_test_name == "htlc_database_api" - || current_suite_name == "database_api_tests" ) + else if( fixture.current_test_name == "asset_in_collateral" + || fixture.current_test_name == "htlc_database_api" + || fixture.current_suite_name == "database_api_tests" ) { - auto ahiplugin = app.register_plugin(); - ahiplugin->plugin_set_app(&app); + auto ahiplugin = fixture.app.register_plugin(); + ahiplugin->plugin_set_app(&fixture.app); ahiplugin->plugin_initialize(options); ahiplugin->plugin_startup(); } - if(current_test_name == "custom_operations_account_storage_map_test" || - current_test_name == "custom_operations_account_storage_list_test") { - auto custom_operations_plugin = app.register_plugin(); - custom_operations_plugin->plugin_set_app(&app); + if(fixture.current_test_name == "custom_operations_account_storage_map_test" || + fixture.current_test_name == "custom_operations_account_storage_list_test") { + auto custom_operations_plugin = fixture.app.register_plugin(); + custom_operations_plugin->plugin_set_app(&fixture.app); custom_operations_plugin->plugin_initialize(options); custom_operations_plugin->plugin_startup(); } options.insert(std::make_pair("bucket-size", boost::program_options::variable_value(string("[15]"),false))); - mhplugin->plugin_set_app(&app); + + auto mhplugin = fixture.app.register_plugin(); + auto goplugin = fixture.app.register_plugin(); + mhplugin->plugin_set_app(&fixture.app); mhplugin->plugin_initialize(options); - goplugin->plugin_set_app(&app); + goplugin->plugin_set_app(&fixture.app); goplugin->plugin_initialize(options); mhplugin->plugin_startup(); goplugin->plugin_startup(); - generate_block(); - - asset_id_type mpa1_id(1); - BOOST_REQUIRE( mpa1_id(db).is_market_issued() ); - BOOST_CHECK( mpa1_id(db).bitasset_data(db).asset_id == mpa1_id ); - - set_expiration( db, trx ); - } catch ( const fc::exception& e ) - { - edump( (e.to_detail_string()) ); - throw; - } - - return; + return options; } -database_fixture::~database_fixture() -{ - try { - // If we're unwinding due to an exception, don't do any more checks. - // This way, boost test's last checkpoint tells us approximately where the error was. - if( !std::uncaught_exception() ) - { - verify_asset_supplies(db); - BOOST_CHECK( db.get_node_properties().skip_flags == database::skip_nothing ); - } - return; - } catch (fc::exception& ex) { - BOOST_FAIL( std::string("fc::exception in ~database_fixture: ") + ex.to_detail_string() ); - } catch (std::exception& e) { - BOOST_FAIL( std::string("std::exception in ~database_fixture:") + e.what() ); - } catch (...) { - BOOST_FAIL( "Uncaught exception in ~database_fixture" ); - } -} - -void database_fixture::vote_for_committee_and_witnesses(uint16_t num_committee, uint16_t num_witness) +void database_fixture_base::vote_for_committee_and_witnesses(uint16_t num_committee, uint16_t num_witness) { try { auto &init0 = get_account("init0"); @@ -433,7 +416,7 @@ void database_fixture::vote_for_committee_and_witnesses(uint16_t num_committee, } FC_CAPTURE_AND_RETHROW() } -fc::ecc::private_key database_fixture::generate_private_key(string seed) +fc::ecc::private_key database_fixture_base::generate_private_key(string seed) { static const fc::ecc::private_key committee = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key"))); if( seed == "null_key" ) @@ -441,13 +424,13 @@ fc::ecc::private_key database_fixture::generate_private_key(string seed) return fc::ecc::private_key::regenerate(fc::sha256::hash(seed)); } -string database_fixture::generate_anon_acct_name() +string database_fixture_base::generate_anon_acct_name() { // names of the form "anon-acct-x123" ; the "x" is necessary // to workaround issue #46 return "anon-acct-x" + std::to_string( anon_acct_count++ ); } -bool database_fixture::validation_current_test_name_for_setting_api_limit( const string& current_test_name ) const +bool database_fixture_base::validation_current_test_name_for_setting_api_limit( const string& current_test_name ) { vector valid_testcase {"api_limit_get_account_history_operations","api_limit_get_account_history" ,"api_limit_get_grouped_limit_orders","api_limit_get_relative_account_history" @@ -471,7 +454,7 @@ bool database_fixture::validation_current_test_name_for_setting_api_limit( const return false; } -void database_fixture::verify_asset_supplies( const database& db ) +void database_fixture_base::verify_asset_supplies( const database& db ) { //wlog("*** Begin asset supply verification ***"); const asset_dynamic_data_object& core_asset_data = db.get_core_asset().dynamic_asset_data_id(db); @@ -554,15 +537,7 @@ void database_fixture::verify_asset_supplies( const database& db ) // wlog("*** End asset supply verification ***"); } -void database_fixture::open_database() -{ - if( !data_dir ) { - data_dir = fc::temp_directory( graphene::utilities::temp_directory_path() ); - db.open(data_dir->path(), [this]{return genesis_state;}, "test"); - } -} - -signed_block database_fixture::generate_block(uint32_t skip, const fc::ecc::private_key& key, int miss_blocks) +signed_block database_fixture_base::generate_block(uint32_t skip, const fc::ecc::private_key& key, int miss_blocks) { skip |= database::skip_undo_history_check; // skip == ~0 will skip checks specified in database::validation_steps @@ -573,13 +548,13 @@ signed_block database_fixture::generate_block(uint32_t skip, const fc::ecc::priv return block; } -void database_fixture::generate_blocks( uint32_t block_count ) +void database_fixture_base::generate_blocks( uint32_t block_count ) { for( uint32_t i = 0; i < block_count; ++i ) generate_block(); } -uint32_t database_fixture::generate_blocks(fc::time_point_sec timestamp, bool miss_intermediate_blocks, uint32_t skip) +uint32_t database_fixture_base::generate_blocks(fc::time_point_sec timestamp, bool miss_intermediate_blocks, uint32_t skip) { if( miss_intermediate_blocks ) { @@ -600,7 +575,7 @@ uint32_t database_fixture::generate_blocks(fc::time_point_sec timestamp, bool mi return blocks; } -account_create_operation database_fixture::make_account( +account_create_operation database_fixture_base::make_account( const std::string& name /* = "nathan" */, public_key_type key /* = key_id_type() */ ) @@ -631,7 +606,7 @@ account_create_operation database_fixture::make_account( return create_account; } FC_CAPTURE_AND_RETHROW() } -account_create_operation database_fixture::make_account( +account_create_operation database_fixture_base::make_account( const std::string& name, const account_object& registrar, const account_object& referrer, @@ -672,7 +647,7 @@ account_create_operation database_fixture::make_account( FC_CAPTURE_AND_RETHROW((name)(referrer_percent)) } -const asset_object& database_fixture::get_asset( const string& symbol )const +const asset_object& database_fixture_base::get_asset( const string& symbol )const { const auto& idx = db.get_index_type().indices().get(); const auto itr = idx.find(symbol); @@ -680,7 +655,7 @@ const asset_object& database_fixture::get_asset( const string& symbol )const return *itr; } -const account_object& database_fixture::get_account( const string& name )const +const account_object& database_fixture_base::get_account( const string& name )const { const auto& idx = db.get_index_type().indices().get(); const auto itr = idx.find(name); @@ -688,7 +663,7 @@ const account_object& database_fixture::get_account( const string& name )const return *itr; } -const asset_object& database_fixture::create_bitasset( +const asset_object& database_fixture_base::create_bitasset( const string& name, account_id_type issuer /* = GRAPHENE_WITNESS_ACCOUNT */, uint16_t market_fee_percent /* = 100 */ /* 1% */, @@ -719,7 +694,7 @@ const asset_object& database_fixture::create_bitasset( return db.get(ptx.operation_results[0].get()); } FC_CAPTURE_AND_RETHROW( (name)(flags) ) } -const asset_object& database_fixture::create_prediction_market( +const asset_object& database_fixture_base::create_prediction_market( const string& name, account_id_type issuer /* = GRAPHENE_WITNESS_ACCOUNT */, uint16_t market_fee_percent /* = 100 */ /* 1% */, @@ -751,7 +726,7 @@ const asset_object& database_fixture::create_prediction_market( } FC_CAPTURE_AND_RETHROW( (name)(flags) ) } -const asset_object& database_fixture::create_user_issued_asset( const string& name ) +const asset_object& database_fixture_base::create_user_issued_asset( const string& name ) { asset_create_operation creator; creator.issuer = account_id_type(); @@ -770,7 +745,7 @@ const asset_object& database_fixture::create_user_issued_asset( const string& na return db.get(ptx.operation_results[0].get()); } -const asset_object& database_fixture::create_user_issued_asset( const string& name, const account_object& issuer, +const asset_object& database_fixture_base::create_user_issued_asset( const string& name, const account_object& issuer, uint16_t flags, const price& core_exchange_rate, uint8_t precision, uint16_t market_fee_percent, additional_asset_options_t additional_options) @@ -796,7 +771,7 @@ const asset_object& database_fixture::create_user_issued_asset( const string& na return db.get(ptx.operation_results[0].get()); } -void database_fixture::issue_uia( const account_object& recipient, asset amount ) +void database_fixture_base::issue_uia( const account_object& recipient, asset amount ) { BOOST_TEST_MESSAGE( "Issuing UIA" ); asset_issue_operation op; @@ -808,12 +783,12 @@ void database_fixture::issue_uia( const account_object& recipient, asset amount trx.operations.clear(); } -void database_fixture::issue_uia( account_id_type recipient_id, asset amount ) +void database_fixture_base::issue_uia( account_id_type recipient_id, asset amount ) { issue_uia( recipient_id(db), amount ); } -void database_fixture::change_fees( +void database_fixture_base::change_fees( const fee_parameters::flat_set_type& new_params, uint32_t new_scale /* = 0 */ ) @@ -843,7 +818,7 @@ void database_fixture::change_fees( }); } -const account_object& database_fixture::create_account( +const account_object& database_fixture_base::create_account( const string& name, const public_key_type& key /* = public_key_type() */ ) @@ -856,7 +831,7 @@ const account_object& database_fixture::create_account( return result; } -const account_object& database_fixture::create_account( +const account_object& database_fixture_base::create_account( const string& name, const account_object& registrar, const account_object& referrer, @@ -877,7 +852,7 @@ const account_object& database_fixture::create_account( FC_CAPTURE_AND_RETHROW( (name)(registrar)(referrer) ) } -const account_object& database_fixture::create_account( +const account_object& database_fixture_base::create_account( const string& name, const private_key_type& key, const account_id_type& registrar_id /* = account_id_type() */, @@ -911,7 +886,7 @@ const account_object& database_fixture::create_account( FC_CAPTURE_AND_RETHROW( (name)(registrar_id)(referrer_id) ) } -const committee_member_object& database_fixture::create_committee_member( const account_object& owner ) +const committee_member_object& database_fixture_base::create_committee_member( const account_object& owner ) { committee_member_create_operation op; op.committee_member_account = owner.id; @@ -922,14 +897,14 @@ const committee_member_object& database_fixture::create_committee_member( const return db.get(ptx.operation_results[0].get()); } -const witness_object&database_fixture::create_witness(account_id_type owner, +const witness_object& database_fixture_base::create_witness(account_id_type owner, const fc::ecc::private_key& signing_private_key, uint32_t skip_flags ) { return create_witness(owner(db), signing_private_key, skip_flags ); } -const witness_object& database_fixture::create_witness( const account_object& owner, +const witness_object& database_fixture_base::create_witness( const account_object& owner, const fc::ecc::private_key& signing_private_key, uint32_t skip_flags ) { try { @@ -943,7 +918,7 @@ const witness_object& database_fixture::create_witness( const account_object& ow return db.get(ptx.operation_results[0].get()); } FC_CAPTURE_AND_RETHROW() } -const worker_object& database_fixture::create_worker( const account_id_type owner, const share_type daily_pay, const fc::microseconds& duration ) +const worker_object& database_fixture_base::create_worker( const account_id_type owner, const share_type daily_pay, const fc::microseconds& duration ) { try { worker_create_operation op; op.owner = owner; @@ -958,7 +933,7 @@ const worker_object& database_fixture::create_worker( const account_id_type owne return db.get(ptx.operation_results[0].get()); } FC_CAPTURE_AND_RETHROW() } -uint64_t database_fixture::fund( +uint64_t database_fixture_base::fund( const account_object& account, const asset& amount /* = asset(500000) */ ) @@ -967,17 +942,17 @@ uint64_t database_fixture::fund( return get_balance(account, amount.asset_id(db)); } -void database_fixture::sign(signed_transaction& trx, const fc::ecc::private_key& key) +void database_fixture_base::sign(signed_transaction& trx, const fc::ecc::private_key& key) { trx.sign( key, db.get_chain_id() ); } -digest_type database_fixture::digest( const transaction& tx ) +digest_type database_fixture_base::digest( const transaction& tx ) { return tx.digest(); } -const limit_order_object*database_fixture::create_sell_order(account_id_type user, const asset& amount, const asset& recv, +const limit_order_object* database_fixture_base::create_sell_order(account_id_type user, const asset& amount, const asset& recv, const time_point_sec order_expiration, const price& fee_core_exchange_rate ) { @@ -986,7 +961,7 @@ const limit_order_object*database_fixture::create_sell_order(account_id_type use return r; } -const limit_order_object* database_fixture::create_sell_order( const account_object& user, const asset& amount, const asset& recv, +const limit_order_object* database_fixture_base::create_sell_order( const account_object& user, const asset& amount, const asset& recv, const time_point_sec order_expiration, const price& fee_core_exchange_rate ) { @@ -1007,7 +982,7 @@ const limit_order_object* database_fixture::create_sell_order( const account_obj return db.find( processed.operation_results[0].get() ); } -asset database_fixture::cancel_limit_order( const limit_order_object& order ) +asset database_fixture_base::cancel_limit_order( const limit_order_object& order ) { limit_order_cancel_operation cancel_order; cancel_order.fee_paying_account = order.seller; @@ -1021,7 +996,7 @@ asset database_fixture::cancel_limit_order( const limit_order_object& order ) return processed.operation_results[0].get(); } -void database_fixture::transfer( +void database_fixture_base::transfer( account_id_type from, account_id_type to, const asset& amount, @@ -1031,7 +1006,7 @@ void database_fixture::transfer( transfer(from(db), to(db), amount, fee); } -void database_fixture::transfer( +void database_fixture_base::transfer( const account_object& from, const account_object& to, const asset& amount, @@ -1057,7 +1032,7 @@ void database_fixture::transfer( } FC_CAPTURE_AND_RETHROW( (from.id)(to.id)(amount)(fee) ) } -void database_fixture::update_feed_producers( const asset_object& mia, flat_set producers ) +void database_fixture_base::update_feed_producers( const asset_object& mia, flat_set producers ) { try { set_expiration( db, trx ); trx.operations.clear(); @@ -1074,7 +1049,7 @@ void database_fixture::update_feed_producers( const asset_object& mia, flat_set< verify_asset_supplies(db); } FC_CAPTURE_AND_RETHROW( (mia)(producers) ) } -void database_fixture::publish_feed( const asset_object& mia, const account_object& by, const price_feed& f ) +void database_fixture_base::publish_feed( const asset_object& mia, const account_object& by, const price_feed& f ) { set_expiration( db, trx ); trx.operations.clear(); @@ -1099,7 +1074,6 @@ void database_fixture::publish_feed( const asset_object& mia, const account_obje * * Adds a price feed for asset2, pushes the transaction, and generates the block * - * @param fixture the database_fixture * @param publisher who is publishing the feed * @param asset1 the base asset * @param amount1 the amount of the base asset @@ -1107,7 +1081,7 @@ void database_fixture::publish_feed( const asset_object& mia, const account_obje * @param amount2 the amount of the quote asset * @param core_id id of core (helps with core_exchange_rate) */ -void database_fixture::publish_feed(const account_id_type& publisher, +void database_fixture_base::publish_feed(const account_id_type& publisher, const asset_id_type& asset1, int64_t amount1, const asset_id_type& asset2, int64_t amount2, const asset_id_type& core_id) @@ -1126,7 +1100,7 @@ void database_fixture::publish_feed(const account_id_type& publisher, trx.clear(); } -void database_fixture::force_global_settle( const asset_object& what, const price& p ) +void database_fixture_base::force_global_settle( const asset_object& what, const price& p ) { try { set_expiration( db, trx ); trx.operations.clear(); @@ -1142,7 +1116,7 @@ void database_fixture::force_global_settle( const asset_object& what, const pric verify_asset_supplies(db); } FC_CAPTURE_AND_RETHROW( (what)(p) ) } -operation_result database_fixture::force_settle( const account_object& who, asset what ) +operation_result database_fixture_base::force_settle( const account_object& who, asset what ) { try { set_expiration( db, trx ); trx.operations.clear(); @@ -1159,7 +1133,7 @@ operation_result database_fixture::force_settle( const account_object& who, asse return op_result; } FC_CAPTURE_AND_RETHROW( (who)(what) ) } -const call_order_object* database_fixture::borrow( const account_object& who, asset what, asset collateral, +const call_order_object* database_fixture_base::borrow( const account_object& who, asset what, asset collateral, optional target_cr ) { try { set_expiration( db, trx ); @@ -1185,7 +1159,7 @@ const call_order_object* database_fixture::borrow( const account_object& who, as return call_obj; } FC_CAPTURE_AND_RETHROW( (who.name)(what)(collateral)(target_cr) ) } -void database_fixture::cover(const account_object& who, asset what, asset collateral, optional target_cr) +void database_fixture_base::cover(const account_object& who, asset what, asset collateral, optional target_cr) { try { set_expiration( db, trx ); trx.operations.clear(); @@ -1202,7 +1176,7 @@ void database_fixture::cover(const account_object& who, asset what, asset collat verify_asset_supplies(db); } FC_CAPTURE_AND_RETHROW( (who.name)(what)(collateral)(target_cr) ) } -void database_fixture::bid_collateral(const account_object& who, const asset& to_bid, const asset& to_cover) +void database_fixture_base::bid_collateral(const account_object& who, const asset& to_bid, const asset& to_cover) { try { set_expiration( db, trx ); trx.operations.clear(); @@ -1218,7 +1192,7 @@ void database_fixture::bid_collateral(const account_object& who, const asset& to verify_asset_supplies(db); } FC_CAPTURE_AND_RETHROW( (who.name)(to_bid)(to_cover) ) } -void database_fixture::fund_fee_pool( const account_object& from, const asset_object& asset_to_fund, const share_type amount ) +void database_fixture_base::fund_fee_pool( const account_object& from, const asset_object& asset_to_fund, const share_type amount ) { asset_fund_fee_pool_operation fund; fund.from_account = from.id; @@ -1234,7 +1208,7 @@ void database_fixture::fund_fee_pool( const account_object& from, const asset_ob verify_asset_supplies(db); } -void database_fixture::enable_fees() +void database_fixture_base::enable_fees() { db.modify(global_property_id_type()(db), [](global_property_object& gpo) { @@ -1242,12 +1216,12 @@ void database_fixture::enable_fees() }); } -void database_fixture::upgrade_to_lifetime_member(account_id_type account) +void database_fixture_base::upgrade_to_lifetime_member(account_id_type account) { upgrade_to_lifetime_member(account(db)); } -void database_fixture::upgrade_to_lifetime_member( const account_object& account ) +void database_fixture_base::upgrade_to_lifetime_member( const account_object& account ) { try { @@ -1264,12 +1238,12 @@ void database_fixture::upgrade_to_lifetime_member( const account_object& account FC_CAPTURE_AND_RETHROW((account)) } -void database_fixture::upgrade_to_annual_member(account_id_type account) +void database_fixture_base::upgrade_to_annual_member(account_id_type account) { upgrade_to_annual_member(account(db)); } -void database_fixture::upgrade_to_annual_member(const account_object& account) +void database_fixture_base::upgrade_to_annual_member(const account_object& account) { try { account_upgrade_operation op; @@ -1283,7 +1257,7 @@ void database_fixture::upgrade_to_annual_member(const account_object& account) } FC_CAPTURE_AND_RETHROW((account)) } -void database_fixture::print_market( const string& syma, const string& symb )const +void database_fixture_base::print_market( const string& syma, const string& symb )const { const auto& limit_idx = db.get_index_type(); const auto& price_idx = limit_idx.indices().get(); @@ -1311,7 +1285,7 @@ void database_fixture::print_market( const string& syma, const string& symb )con } } -string database_fixture::pretty( const asset& a )const +string database_fixture_base::pretty( const asset& a )const { std::stringstream ss; ss << a.amount.value << " "; @@ -1319,7 +1293,7 @@ string database_fixture::pretty( const asset& a )const return ss.str(); } -void database_fixture::print_limit_order( const limit_order_object& cur )const +void database_fixture_base::print_limit_order( const limit_order_object& cur )const { std::cout << std::setw(10) << cur.seller(db).name << " "; std::cout << std::setw(10) << "LIMIT" << " "; @@ -1328,7 +1302,7 @@ void database_fixture::print_limit_order( const limit_order_object& cur )const std::cout << std::setw(16) << cur.sell_price.to_real() << " "; } -void database_fixture::print_call_orders()const +void database_fixture_base::print_call_orders()const { cout << std::fixed; cout.precision(5); @@ -1356,7 +1330,7 @@ void database_fixture::print_call_orders()const std::cout << "\n"; } -void database_fixture::print_joint_market( const string& syma, const string& symb )const +void database_fixture_base::print_joint_market( const string& syma, const string& symb )const { cout << std::fixed; cout.precision(5); @@ -1380,27 +1354,27 @@ void database_fixture::print_joint_market( const string& syma, const string& sym } } -int64_t database_fixture::get_balance( account_id_type account, asset_id_type a )const +int64_t database_fixture_base::get_balance( account_id_type account, asset_id_type a )const { return db.get_balance(account, a).amount.value; } -int64_t database_fixture::get_balance( const account_object& account, const asset_object& a )const +int64_t database_fixture_base::get_balance( const account_object& account, const asset_object& a )const { return db.get_balance(account.get_id(), a.get_id()).amount.value; } -int64_t database_fixture::get_market_fee_reward( account_id_type account_id, asset_id_type asset_id)const +int64_t database_fixture_base::get_market_fee_reward( account_id_type account_id, asset_id_type asset_id)const { return db.get_market_fee_vesting_balance(account_id, asset_id).amount.value; } -int64_t database_fixture::get_market_fee_reward( const account_object& account, const asset_object& asset )const +int64_t database_fixture_base::get_market_fee_reward( const account_object& account, const asset_object& asset )const { return get_market_fee_reward(account.get_id(), asset.get_id()); } -vector< operation_history_object > database_fixture::get_operation_history( account_id_type account_id )const +vector< operation_history_object > database_fixture_base::get_operation_history( account_id_type account_id )const { vector< operation_history_object > result; const auto& stats = account_id(db).statistics(db); @@ -1418,7 +1392,7 @@ vector< operation_history_object > database_fixture::get_operation_history( acco return result; } -vector< graphene::market_history::order_history_object > database_fixture::get_market_order_history( asset_id_type a, asset_id_type b )const +vector< graphene::market_history::order_history_object > database_fixture_base::get_market_order_history( asset_id_type a, asset_id_type b )const { const auto& history_idx = db.get_index_type().indices().get(); graphene::market_history::history_key hkey; @@ -1436,7 +1410,7 @@ vector< graphene::market_history::order_history_object > database_fixture::get_m return result; } -flat_map< uint64_t, graphene::chain::fee_parameters > database_fixture::get_htlc_fee_parameters() +flat_map< uint64_t, graphene::chain::fee_parameters > database_fixture_base::get_htlc_fee_parameters() { flat_map ret_val; @@ -1458,7 +1432,7 @@ flat_map< uint64_t, graphene::chain::fee_parameters > database_fixture::get_htlc return ret_val; } -void database_fixture::set_htlc_committee_parameters() +void database_fixture_base::set_htlc_committee_parameters() { // htlc fees // get existing fee_schedule @@ -1530,7 +1504,7 @@ bool _push_block( database& db, const signed_block& b, uint32_t skip_flags /* = processed_transaction _push_transaction( database& db, const signed_transaction& tx, uint32_t skip_flags /* = 0 */ ) { try { auto pt = db.push_transaction( precomputable_transaction(tx), skip_flags ); - database_fixture::verify_asset_supplies(db); + database_fixture_base::verify_asset_supplies(db); return pt; } FC_CAPTURE_AND_RETHROW((tx)) } diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index a3cc5624df..4a2e848d53 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -25,6 +25,9 @@ #include +#include +#include + #include #include @@ -34,6 +37,7 @@ #include #include #include +#include #include @@ -182,7 +186,7 @@ class clearable_block : public signed_block { void clear(); }; -struct database_fixture { +struct database_fixture_base { // the reason we use an app is to exercise the indexes of built-in // plugins graphene::app::application app; @@ -191,23 +195,33 @@ struct database_fixture { signed_transaction trx; public_key_type committee_key; account_id_type committee_account; - fc::ecc::private_key private_key = fc::ecc::private_key::generate(); - fc::ecc::private_key init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ); - public_key_type init_account_pub_key; + const fc::ecc::private_key private_key = fc::ecc::private_key::generate(); + const fc::ecc::private_key init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ); + const public_key_type init_account_pub_key; - optional data_dir; + fc::temp_directory data_dir; bool skip_key_index_test = false; uint32_t anon_acct_count; bool hf1270 = false; - database_fixture(const fc::time_point_sec &initial_timestamp = - fc::time_point_sec(GRAPHENE_TESTING_GENESIS_TIMESTAMP)); - ~database_fixture(); + const std::string current_test_name; + const std::string current_suite_name; + + database_fixture_base(); + ~database_fixture_base(); + + template + static void set_option( boost::program_options::variables_map& options, const std::string& name, const T& value ) + { + options.insert( std::make_pair( name, boost::program_options::variable_value( value, false ) ) ); + } + + static void init_genesis( database_fixture_base& fixture ); + static boost::program_options::variables_map init_options( database_fixture_base& fixture ); static fc::ecc::private_key generate_private_key(string seed); string generate_anon_acct_name(); static void verify_asset_supplies( const database& db ); - void open_database(); void vote_for_committee_and_witnesses(uint16_t num_committee, uint16_t num_witness); signed_block generate_block(uint32_t skip = ~0, const fc::ecc::private_key& key = generate_private_key("null_key"), @@ -371,7 +385,7 @@ struct database_fixture { vector< operation_history_object > get_operation_history( account_id_type account_id )const; vector< graphene::market_history::order_history_object > get_market_order_history( asset_id_type a, asset_id_type b )const; - bool validation_current_test_name_for_setting_api_limit( const string& current_test_name )const; + static bool validation_current_test_name_for_setting_api_limit( const string& current_test_name ); /**** * @brief return htlc fee parameters @@ -400,6 +414,39 @@ void set_expiration( const database& db, transaction& tx ); bool _push_block( database& db, const signed_block& b, uint32_t skip_flags = 0 ); processed_transaction _push_transaction( database& db, const signed_transaction& tx, uint32_t skip_flags = 0 ); + } +template +struct database_fixture_init : database_fixture_base { + database_fixture_init() + { + F::init( *this ); + + asset_id_type mpa1_id(1); + BOOST_REQUIRE( mpa1_id(db).is_market_issued() ); + BOOST_CHECK( mpa1_id(db).bitasset_data(db).asset_id == mpa1_id ); + } + + static void init( database_fixture_init& fixture ) + { try { + fixture.data_dir = fc::temp_directory( graphene::utilities::temp_directory_path() ); + fc::create_directories( fixture.data_dir.path() ); + F::init_genesis( fixture ); + fc::json::save_to_file( fixture.genesis_state, fixture.data_dir.path() / "genesis.json" ); + boost::program_options::variables_map options = F::init_options( fixture ); + set_option( options, "genesis-json", boost::filesystem::path(fixture.data_dir.path() / "genesis.json") ); + fixture.app.initialize( fixture.data_dir.path(), options ); + fixture.app.startup(); + + fixture.generate_block(); + + test::set_expiration( fixture.db, fixture.trx ); + } FC_LOG_AND_RETHROW() } +}; + +struct database_fixture : database_fixture_init +{ +}; + } } diff --git a/tests/elasticsearch/main.cpp b/tests/elasticsearch/main.cpp index 24eb9382e8..bcd11cae96 100644 --- a/tests/elasticsearch/main.cpp +++ b/tests/elasticsearch/main.cpp @@ -22,6 +22,9 @@ * THE SOFTWARE. */ +#define BOOST_TEST_MODULE Elastic Search Database Tests +#include + #include #include #include @@ -31,9 +34,6 @@ #include "../common/database_fixture.hpp" -#define BOOST_TEST_MODULE Elastic Search Database Tests -#include - using namespace graphene::chain; using namespace graphene::chain::test; using namespace graphene::app; diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index c36455361f..c83ef29e7b 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -39,6 +39,7 @@ #include #include +#include #include "../common/database_fixture.hpp" @@ -1246,7 +1247,13 @@ BOOST_FIXTURE_TEST_CASE( transaction_invalidated_in_cache, database_fixture ) fc::temp_directory data_dir2( graphene::utilities::temp_directory_path() ); database db2; - db2.open(data_dir2.path(), make_genesis, "TEST"); + { + std::string genesis_json; + fc::read_file_contents( data_dir.path() / "genesis.json", genesis_json ); + genesis_state_type genesis = fc::json::from_string( genesis_json ).as( 50 ); + genesis.initial_chain_id = fc::sha256::hash( genesis_json ); + db2.open(data_dir2.path(), [&genesis] () { return genesis; }, "TEST"); + } BOOST_CHECK( db.get_chain_id() == db2.get_chain_id() ); while( db2.head_block_num() < db.head_block_num() ) From 33e538a548bd58ea490fa059e14011a7773ae3c2 Mon Sep 17 00:00:00 2001 From: abitmore Date: Fri, 29 Jan 2021 10:04:33 +0000 Subject: [PATCH 004/147] Bump FC for Ubuntu 20.04 --- libraries/fc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/fc b/libraries/fc index 07ef37736a..eed0e9ec80 160000 --- a/libraries/fc +++ b/libraries/fc @@ -1 +1 @@ -Subproject commit 07ef37736a5685b09443b51175bf291a38931f7b +Subproject commit eed0e9ec80df18689913ad8327328edd331d6809 From fb9e54ee1ed14d00540ebcf93c286456eb89886a Mon Sep 17 00:00:00 2001 From: abitmore Date: Fri, 29 Jan 2021 10:06:06 +0000 Subject: [PATCH 005/147] Add Ubuntu 20.04 into Github Actions build matrix --- .github/workflows/build-and-test.ubuntu-debug.yml | 2 +- .github/workflows/build-and-test.ubuntu-release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-test.ubuntu-debug.yml b/.github/workflows/build-and-test.ubuntu-debug.yml index 031c644851..27298ea218 100644 --- a/.github/workflows/build-and-test.ubuntu-debug.yml +++ b/.github/workflows/build-and-test.ubuntu-debug.yml @@ -8,7 +8,7 @@ jobs: name: Build and test in Debug mode strategy: matrix: - os: [ ubuntu-16.04, ubuntu-18.04 ] + os: [ ubuntu-16.04, ubuntu-18.04, ubuntu-20.04 ] runs-on: ${{ matrix.os }} services: elasticsearch: diff --git a/.github/workflows/build-and-test.ubuntu-release.yml b/.github/workflows/build-and-test.ubuntu-release.yml index 5627c005ce..b7df124a2c 100644 --- a/.github/workflows/build-and-test.ubuntu-release.yml +++ b/.github/workflows/build-and-test.ubuntu-release.yml @@ -8,7 +8,7 @@ jobs: name: Build and test in Release mode strategy: matrix: - os: [ ubuntu-16.04, ubuntu-18.04 ] + os: [ ubuntu-16.04, ubuntu-18.04, ubuntu-20.04 ] runs-on: ${{ matrix.os }} services: elasticsearch: From b8559ca2edca821b2116cde523af8f8c37ee50a6 Mon Sep 17 00:00:00 2001 From: Abit Date: Sat, 30 Jan 2021 00:08:40 +0100 Subject: [PATCH 006/147] Update README for Ubuntu 20.04 support and etc --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b5ce0029d7..48a9c3961c 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ The web browser based wallet is [BitShares UI](https://github.com/bitshares/bits Visit [BitShares.org](https://bitshares.org/) to learn about BitShares and join the community at [BitSharesTalk.org](https://bitsharestalk.org/). -Information for developers can be found in the [BitShares Developer Portal](https://dev.bitshares.works/). Users interested in how BitShares works can go to the [BitShares Documentation](https://how.bitshares.works/) site. +Information for developers can be found in the [Wiki](https://github.com/bitshares/bitshares-core/wiki) and the [BitShares Developer Portal](https://dev.bitshares.works/). Users interested in how BitShares works can go to the [BitShares Documentation](https://how.bitshares.works/) site. Visit [Awesome BitShares](https://github.com/bitshares/awesome-bitshares) to find more resources and links. @@ -30,9 +30,11 @@ Getting Started Build instructions and additional documentation are available in the [Wiki](https://github.com/bitshares/bitshares-core/wiki). +Prebuilt binaries can be found in the [releases page](https://github.com/bitshares/bitshares-core/releases) for download. + ### Build -We recommend building on Ubuntu 16.04 LTS (64-bit) +We recommend building on Ubuntu 20.04 LTS (64-bit) **Build Dependencies:** @@ -63,12 +65,12 @@ We recommend building on Ubuntu 16.04 LTS (64-bit) **NOTE:** * BitShares requires a 64-bit operating system to build, and will not build on a 32-bit OS. Tested operating systems: - * Linux (heavily tested with Ubuntu 18.04 LTS and Ubuntu 16.04 LTS) + * Linux (heavily tested with Ubuntu LTS releases) * macOS (various versions) * Windows (various versions, Visual Studio and MinGW) * OpenBSD (various versions) -* BitShares requires [Boost](https://www.boost.org/) libraries to build, supports version `1.58` to `1.69`. +* BitShares requires [Boost](https://www.boost.org/) libraries to build, supports version `1.58` to `1.71`. Newer versions may work, but have not been tested. If your system came pre-installed with a version of Boost libraries that you do not wish to use, you may manually build your preferred version and use it with BitShares by specifying it on the CMake command line. From 3621a3b96443774eaa9c51485338dcaadf059834 Mon Sep 17 00:00:00 2001 From: Abit Date: Thu, 11 Feb 2021 12:10:34 +0100 Subject: [PATCH 007/147] Remove a dead seed node --- libraries/egenesis/seed-nodes.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/egenesis/seed-nodes.txt b/libraries/egenesis/seed-nodes.txt index cace834c9e..4816708ad3 100644 --- a/libraries/egenesis/seed-nodes.txt +++ b/libraries/egenesis/seed-nodes.txt @@ -1,6 +1,5 @@ // https://bitsharestalk.org/index.php/topic,23715.0.html "seed01.liondani.com:1776", // liondani (Germany) -"bts.lafona.net:1776", // lafona (France) "bts-seed1.abit-more.com:62015", // abit (China) "seed.roelandp.nl:1776", // roelandp (Canada) "seed1.xbts.io:1776", // xbts.io (Germany) From 4b5b320942f78e3eaedff18250b7ce7fe1c65e28 Mon Sep 17 00:00:00 2001 From: Abit Date: Fri, 12 Feb 2021 15:53:01 +0100 Subject: [PATCH 008/147] Skip normalizing brain key when deriving keys --- libraries/wallet/wallet.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index bd17742c5a..1ece5e741d 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -103,7 +103,6 @@ namespace graphene { namespace wallet { // Create as many derived owner keys as requested vector results; - brain_key = graphene::wallet::detail::normalize_brain_key(brain_key); for (int i = 0; i < number_of_desired_keys; ++i) { fc::ecc::private_key priv_key = graphene::wallet::detail::derive_private_key( brain_key, i ); From 03d53e6703f8460838298094692638c424444075 Mon Sep 17 00:00:00 2001 From: Abit Date: Mon, 15 Feb 2021 01:21:20 +0100 Subject: [PATCH 009/147] Improve market ticker read performance via chunks --- libraries/plugins/market_history/market_history_plugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/plugins/market_history/market_history_plugin.cpp b/libraries/plugins/market_history/market_history_plugin.cpp index ff69b7f144..819f38ff59 100644 --- a/libraries/plugins/market_history/market_history_plugin.cpp +++ b/libraries/plugins/market_history/market_history_plugin.cpp @@ -780,7 +780,7 @@ void market_history_plugin::plugin_initialize(const boost::program_options::vari database().add_index< primary_index< bucket_index > >(); database().add_index< primary_index< history_index > >(); - database().add_index< primary_index< market_ticker_index > >(); + database().add_index< primary_index< market_ticker_index, 8 > >(); // 256 markets per chunk database().add_index< primary_index< simple_index< market_ticker_meta_object > > >(); database().add_index< primary_index< liquidity_pool_history_index > >(); From e5129f435dc59337937800d8ca01aa6d8fd8a0d9 Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 16 Feb 2021 09:45:29 +0000 Subject: [PATCH 010/147] Fix CLI get_account_history_by_operations ordering --- libraries/wallet/wallet.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 1ece5e741d..467cb157f9 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -393,7 +393,9 @@ account_history_operation_detail wallet_api::get_account_history_by_operations( while (limit > 0 && start <= stats.total_ops) { uint32_t min_limit = std::min (100, limit); auto current = my->_remote_hist->get_account_history_by_operations(name, operation_types, start, min_limit); - for (auto& obj : current.operation_history_objs) { + for( auto it = current.operation_history_objs.rbegin(); it != current.operation_history_objs.rend(); ++it ) + { + auto& obj = *it; std::stringstream ss; auto memo = obj.op.visit(detail::operation_printer(ss, *my, obj)); From 72eb281f684497fd772f4825c8cee4371ff5159a Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 16 Feb 2021 10:20:45 +0000 Subject: [PATCH 011/147] Print more info in account history in CLI --- libraries/wallet/operation_printer.cpp | 164 +++++++++++++++++++++---- libraries/wallet/operation_printer.hpp | 39 +++--- 2 files changed, 164 insertions(+), 39 deletions(-) diff --git a/libraries/wallet/operation_printer.cpp b/libraries/wallet/operation_printer.cpp index 30c11b41e2..65ee4b4336 100644 --- a/libraries/wallet/operation_printer.cpp +++ b/libraries/wallet/operation_printer.cpp @@ -53,9 +53,24 @@ class htlc_hash_to_string_visitor } }; -std::string operation_printer::fee(const graphene::protocol::asset& a)const { - out << " (Fee: " << wallet.get_asset(a.asset_id).amount_to_pretty_string(a) << ")"; - return ""; +std::string operation_printer::format_asset(const graphene::protocol::asset& a)const +{ + return wallet.get_asset(a.asset_id).amount_to_pretty_string(a); +} + +void operation_printer::print_fee(const graphene::protocol::asset& a)const +{ + out << " (Fee: " << format_asset(a) << ")"; +} + +void operation_printer::print_result()const +{ + operation_result_printer rprinter(wallet); + std::string str_result = result.visit(rprinter); + if( str_result != "" ) + { + out << " result: " << str_result; + } } string operation_printer::print_memo( const fc::optional& memo )const @@ -86,8 +101,8 @@ string operation_printer::print_memo( const fc::optional& preimage)const @@ -106,57 +121,69 @@ void operation_printer::print_preimage(const std::vector& preimage)const out << "\""; } -string operation_printer::print_redeem(const graphene::protocol::htlc_id_type& id, - const std::string& redeemer, const std::vector& preimage, +void operation_printer::print_redeem(const graphene::protocol::htlc_id_type& id, + const std::string& redeemer, const std::vector& preimage, const graphene::protocol::asset& op_fee)const { out << redeemer << " redeemed HTLC with id " << std::string( static_cast(id)); print_preimage( preimage ); - return fee(op_fee); + print_fee(op_fee); } std::string operation_printer::operator()(const transfer_from_blind_operation& op)const { - auto a = wallet.get_asset( op.fee.asset_id ); auto receiver = wallet.get_account( op.to ); out << receiver.name - << " received " << a.amount_to_pretty_string( op.amount ) << " from blinded balance"; + << " received " << format_asset( op.amount ) << " from blinded balance"; return ""; } std::string operation_printer::operator()(const transfer_to_blind_operation& op)const { - auto fa = wallet.get_asset( op.fee.asset_id ); - auto a = wallet.get_asset( op.amount.asset_id ); auto sender = wallet.get_account( op.from ); out << sender.name - << " sent " << a.amount_to_pretty_string( op.amount ) << " to " << op.outputs.size() - << " blinded balance" << (op.outputs.size()>1?"s":"") - << " fee: " << fa.amount_to_pretty_string( op.fee ); + << " sent " << format_asset( op.amount ) << " to " << op.outputs.size() + << " blinded balance" << (op.outputs.size()>1?"s":""); + print_fee( op.fee ); return ""; } string operation_printer::operator()(const transfer_operation& op) const { - out << "Transfer " << wallet.get_asset(op.amount.asset_id).amount_to_pretty_string(op.amount) + out << "Transfer " << format_asset(op.amount) << " from " << wallet.get_account(op.from).name << " to " << wallet.get_account(op.to).name; std::string memo = print_memo( op.memo ); - fee(op.fee); + print_fee(op.fee); + return memo; +} + +string operation_printer::operator()(const override_transfer_operation& op) const +{ + out << wallet.get_account(op.issuer).name + << " transfer " << format_asset(op.amount) + << " from " << wallet.get_account(op.from).name << " to " << wallet.get_account(op.to).name; + std::string memo = print_memo( op.memo ); + print_fee(op.fee); return memo; } std::string operation_printer::operator()(const account_create_operation& op) const { - out << "Create Account '" << op.name << "'"; - return fee(op.fee); + out << "Create Account '" << op.name << "' with registrar " + << wallet.get_account(op.registrar).name << " and referrer " + << wallet.get_account(op.referrer).name; + print_fee(op.fee); + print_result(); + return ""; } std::string operation_printer::operator()(const account_update_operation& op) const { out << "Update Account '" << wallet.get_account(op.account).name << "'"; - return fee(op.fee); + print_fee(op.fee); + return ""; } std::string operation_printer::operator()(const asset_create_operation& op) const @@ -167,17 +194,103 @@ std::string operation_printer::operator()(const asset_create_operation& op) cons else out << "User-Issue Asset "; out << "'" << op.symbol << "' with issuer " << wallet.get_account(op.issuer).name; - return fee(op.fee); + print_fee(op.fee); + print_result(); + return ""; +} + +std::string operation_printer::operator()(const asset_update_operation& op) const +{ + out << "Update asset '" << wallet.get_asset(op.asset_to_update).symbol << "'"; + print_fee(op.fee); + return ""; +} + +std::string operation_printer::operator()(const asset_update_bitasset_operation& op) const +{ + out << "Update bitasset options of '" << wallet.get_asset(op.asset_to_update).symbol << "'"; + print_fee(op.fee); + return ""; +} + +string operation_printer::operator()(const asset_issue_operation& op) const +{ + out << wallet.get_account(op.issuer).name + << " issue " << format_asset(op.asset_to_issue) + << " to " << wallet.get_account(op.issue_to_account).name; + std::string memo = print_memo( op.memo ); + print_fee(op.fee); + return memo; +} + +string operation_printer::operator()(const asset_reserve_operation& op) const +{ + out << "Reserve (burn) " << format_asset(op.amount_to_reserve); + print_fee(op.fee); + return ""; +} + +std::string operation_printer::operator()(const asset_settle_operation& op) const +{ + out << "Force-settle " << format_asset(op.amount); + print_fee(op.fee); + print_result(); + return ""; +} + +std::string operation_printer::operator()(const call_order_update_operation& op) const +{ + out << "Adjust debt position with delta debt amount " << format_asset(op.delta_debt) + << " and delta collateral amount " << format_asset(op.delta_collateral); + print_fee(op.fee); + print_result(); + return ""; +} + +std::string operation_printer::operator()(const limit_order_create_operation& op) const +{ + out << "Create limit order to sell " << format_asset(op.amount_to_sell) + << " for " << format_asset(op.min_to_receive); + print_fee(op.fee); + print_result(); + return ""; +} + +std::string operation_printer::operator()(const limit_order_cancel_operation& op) const +{ + out << "Cancel limit order " << std::string( static_cast(op.order) ); + print_fee(op.fee); + print_result(); + return ""; +} + +std::string operation_printer::operator()(const fill_order_operation& op) const +{ + out << "Pays " << format_asset(op.pays) << " for " << format_asset(op.receives) + << " for order " << std::string( static_cast(op.order_id) ) + << " as " << ( op.is_maker ? "maker" : "taker" ); + print_fee(op.fee); + print_result(); + return ""; +} + +std::string operation_printer::operator()(const proposal_update_operation& op) const +{ + out << "Update proposal " << std::string( static_cast(op.proposal) ); + print_fee(op.fee); + return ""; } std::string operation_printer::operator()(const htlc_redeem_operation& op) const { - return print_redeem(op.htlc_id, wallet.get_account(op.redeemer).name, op.preimage, op.fee); + print_redeem(op.htlc_id, wallet.get_account(op.redeemer).name, op.preimage, op.fee); + return ""; } std::string operation_printer::operator()(const htlc_redeemed_operation& op) const { - return print_redeem(op.htlc_id, wallet.get_account(op.redeemer).name, op.preimage, op.fee); + print_redeem(op.htlc_id, wallet.get_account(op.redeemer).name, op.preimage, op.fee); + return ""; } std::string operation_printer::operator()(const htlc_create_operation& op) const @@ -190,7 +303,7 @@ std::string operation_printer::operator()(const htlc_create_operation& op) const operation_result_printer rprinter(wallet); std::string database_id = result.visit(rprinter); - out << "Create HTLC from " << from.name << " to " << to.name + out << "Create HTLC from " << from.name << " to " << to.name << " with id " << database_id << " preimage hash: [" << op.preimage_hash.visit( vtor ) << "] "; print_memo( op.extensions.value.memo ); @@ -198,7 +311,8 @@ std::string operation_printer::operator()(const htlc_create_operation& op) const int32_t pending_blocks = hist.block_num - wallet.get_dynamic_global_properties().last_irreversible_block_num; if (pending_blocks > 0) out << " (pending " << std::to_string(pending_blocks) << " blocks)"; - return fee(op.fee); + print_fee(op.fee); + return ""; } std::string operation_result_printer::operator()(const void_result& x) const diff --git a/libraries/wallet/operation_printer.hpp b/libraries/wallet/operation_printer.hpp index 1af15fd04d..335734faee 100644 --- a/libraries/wallet/operation_printer.hpp +++ b/libraries/wallet/operation_printer.hpp @@ -60,53 +60,64 @@ struct operation_printer graphene::protocol::operation_result result; graphene::chain::operation_history_object hist; - std::string fee(const graphene::protocol::asset& a) const; + std::string format_asset(const graphene::protocol::asset& a) const; + void print_fee(const graphene::protocol::asset& a) const; public: - operation_printer( std::ostream& out, const wallet_api_impl& wallet, + operation_printer( std::ostream& out, const wallet_api_impl& wallet, const graphene::chain::operation_history_object& obj ) : out(out), wallet(wallet), result(obj.result), hist(obj) {} + + /// Return the decrypted memo if a memo exists, otherwise return an empty string typedef std::string result_type; template std::string operator()(const T& op)const { - auto a = wallet.get_asset( op.fee.asset_id ); auto payer = wallet.get_account( op.fee_payer() ); std::string op_name = fc::get_typename::name(); if( op_name.find_last_of(':') != std::string::npos ) op_name.erase(0, op_name.find_last_of(':')+1); - out << op_name <<" "; - out << payer.name << " fee: " << a.amount_to_pretty_string( op.fee ); - operation_result_printer rprinter(wallet); - std::string str_result = result.visit(rprinter); - if( str_result != "" ) - { - out << " result: " << str_result; - } + out << op_name << " "; + out << payer.name; + print_fee( op.fee ); + print_result(); return ""; } std::string operator()(const graphene::protocol::transfer_operation& op)const; + std::string operator()(const graphene::protocol::override_transfer_operation& op)const; std::string operator()(const graphene::protocol::transfer_from_blind_operation& op)const; std::string operator()(const graphene::protocol::transfer_to_blind_operation& op)const; std::string operator()(const graphene::protocol::account_create_operation& op)const; std::string operator()(const graphene::protocol::account_update_operation& op)const; std::string operator()(const graphene::protocol::asset_create_operation& op)const; + std::string operator()(const graphene::protocol::asset_update_operation& op)const; + std::string operator()(const graphene::protocol::asset_update_bitasset_operation& op)const; + std::string operator()(const graphene::protocol::asset_issue_operation& op)const; + std::string operator()(const graphene::protocol::asset_reserve_operation& op)const; + std::string operator()(const graphene::protocol::asset_settle_operation& op)const; + std::string operator()(const graphene::protocol::call_order_update_operation& op)const; + std::string operator()(const graphene::protocol::limit_order_create_operation& op)const; + std::string operator()(const graphene::protocol::limit_order_cancel_operation& op)const; + std::string operator()(const graphene::protocol::fill_order_operation& op)const; + std::string operator()(const graphene::protocol::proposal_update_operation& op)const; std::string operator()(const graphene::protocol::htlc_create_operation& op)const; std::string operator()(const graphene::protocol::htlc_redeem_operation& op)const; std::string operator()(const graphene::protocol::htlc_redeemed_operation& op)const; - protected: + +protected: std::string print_memo( const fc::optional& memo)const; void print_preimage( const std::vector& preimage)const; - std::string print_redeem(const graphene::protocol::htlc_id_type& id, - const std::string& redeemer, const std::vector& preimage, + void print_redeem(const graphene::protocol::htlc_id_type& id, + const std::string& redeemer, const std::vector& preimage, const graphene::protocol::asset& op_fee)const; + void print_result()const; }; }}} // namespace graphene::wallet::detail From b5e7993736f15feee2a86fda2dbf10fca54d1cc4 Mon Sep 17 00:00:00 2001 From: abitmore Date: Mon, 22 Feb 2021 17:04:03 +0000 Subject: [PATCH 012/147] Fix data error in (virtual) execute_bid_operation --- libraries/chain/db_market.cpp | 4 ++-- libraries/chain/include/graphene/chain/config.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/chain/db_market.cpp b/libraries/chain/db_market.cpp index d24598b372..f0c07435c1 100644 --- a/libraries/chain/db_market.cpp +++ b/libraries/chain/db_market.cpp @@ -214,8 +214,8 @@ void database::execute_bid( const collateral_bid_object& bid, share_type debt_co stats.total_core_in_orders += call_obj.collateral; }); - push_applied_operation( execute_bid_operation( bid.bidder, asset( call_obj.collateral, bid.inv_swan_price.base.asset_id ), - asset( debt_covered, bid.inv_swan_price.quote.asset_id ) ) ); + push_applied_operation( execute_bid_operation( bid.bidder, asset( debt_covered, bid.inv_swan_price.quote.asset_id ), + asset( call_obj.collateral, bid.inv_swan_price.base.asset_id ) ) ); remove(bid); } diff --git a/libraries/chain/include/graphene/chain/config.hpp b/libraries/chain/include/graphene/chain/config.hpp index cb0b381dc7..1c85d78aac 100644 --- a/libraries/chain/include/graphene/chain/config.hpp +++ b/libraries/chain/include/graphene/chain/config.hpp @@ -30,7 +30,7 @@ #define GRAPHENE_MAX_NESTED_OBJECTS (200) -#define GRAPHENE_CURRENT_DB_VERSION "20201105" +#define GRAPHENE_CURRENT_DB_VERSION "20210222" #define GRAPHENE_RECENTLY_MISSED_COUNT_INCREMENT 4 #define GRAPHENE_RECENTLY_MISSED_COUNT_DECREMENT 3 From 3f1e08f7fd91d1b6fc7f974c3a2a8a0924c2007a Mon Sep 17 00:00:00 2001 From: abitmore Date: Fri, 26 Feb 2021 15:04:12 +0000 Subject: [PATCH 013/147] Add CLI cmds get_account_name and get_asset_symbol and update in-code docs for CLI commands. --- .../wallet/include/graphene/wallet/wallet.hpp | 240 ++++++++++-------- 1 file changed, 135 insertions(+), 105 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 90cc6fd2c2..c7933a58ea 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -98,10 +98,10 @@ class wallet_api * Each account can have multiple balances, one for each type of asset owned by that * account. The returned list will only contain assets for which the account has a * nonzero balance - * @param id the name or id of the account whose balances you want + * @param account_name_or_id the name or id of the account whose balances you want * @returns a list of the given account's balances */ - vector list_account_balances(const string& id); + vector list_account_balances(const string& account_name_or_id); /** Lists all assets registered on the blockchain. * * To list all assets, pass the empty string \c "" for the lowerbound to start @@ -122,21 +122,21 @@ class wallet_api * * This returns a list of operation history objects, which describe activity on the account. * - * @param name the name or id of the account + * @param account_name_or_id the name or id of the account * @param limit the number of entries to return (starting from the most recent) * @returns a list of \c operation_history_objects */ - vector get_account_history(string name, int limit)const; + vector get_account_history(string account_name_or_id, int limit)const; /** Returns the relative operations on the named account from start number. * - * @param name the name or id of the account + * @param account_name_or_id the name or id of the account * @param stop Sequence number of earliest operation. * @param limit the number of entries to return * @param start the sequence number where to start looping back throw the history * @returns a list of \c operation_history_objects */ - vector get_relative_account_history( string name, uint32_t stop, + vector get_relative_account_history( string account_name_or_id, uint32_t stop, int limit, uint32_t start )const; /** @@ -152,8 +152,8 @@ class wallet_api /** * @brief Get OHLCV data of a trading pair in a time range - * @param symbol name or ID of the base asset - * @param symbol2 name or ID of the quote asset + * @param symbol symbol or ID of the base asset + * @param symbol2 symbol or ID of the quote asset * @param bucket length of each time bucket in seconds. * @param start the start of a time range, E.G. "2018-01-01T00:00:00" * @param end the end of the time range @@ -198,11 +198,11 @@ class wallet_api /** * @brief Get call orders (aka margin positions) for a given asset - * @param a symbol name or ID of the debt asset + * @param asset_symbol_or_id symbol or ID of the debt asset * @param limit Maximum number of orders to retrieve * @return The call orders, ordered from earliest to be called to latest */ - vector get_call_orders(string a, uint32_t limit)const; + vector get_call_orders(string asset_symbol_or_id, uint32_t limit)const; /** * @brief Get forced settlement orders in a given asset @@ -214,12 +214,13 @@ class wallet_api /** Returns the collateral_bid object for the given MPA * - * @param asset the name or id of the asset + * @param asset_symbol_or_id the symbol or id of the asset * @param limit the number of entries to return * @param start the sequence number where to start looping back throw the history * @returns a list of \c collateral_bid_objects */ - vector get_collateral_bids(string asset, uint32_t limit = 100, uint32_t start = 0)const; + vector get_collateral_bids(string asset_symbol_or_id, uint32_t limit = 100, + uint32_t start = 0)const; /** Returns the block chain's slowly-changing settings. * This object contains all of the properties of the blockchain that are fixed @@ -233,14 +234,14 @@ class wallet_api /** * Get operations relevant to the specified account filtering by operation type, with transaction id * - * @param name the name or id of the account, whose history shoulde be queried + * @param account_name_or_id the name or id of the account, whose history shoulde be queried * @param operation_types The IDs of the operation we want to get operations in the account * ( 0 = transfer , 1 = limit order create, ...) * @param start the sequence number where to start looping back throw the history * @param limit the max number of entries to return (from start number) * @returns account_history_operation_detail */ - account_history_operation_detail get_account_history_by_operations( string name, + account_history_operation_detail get_account_history_by_operations( string account_name_or_id, flat_set operation_types, uint32_t start, int limit); @@ -260,18 +261,18 @@ class wallet_api account_object get_account(string account_name_or_id) const; /** Returns information about the given asset. - * @param asset_name_or_id the symbol or id of the asset in question + * @param asset_symbol_or_id the symbol or id of the asset in question * @returns the information about the asset stored in the block chain */ - extended_asset_object get_asset(string asset_name_or_id) const; + extended_asset_object get_asset(string asset_symbol_or_id) const; /** Returns the BitAsset-specific data for a given asset. * Market-issued assets's behavior are determined both by their "BitAsset Data" and * their basic asset data, as returned by \c get_asset(). - * @param asset_name_or_id the symbol or id of the BitAsset in question + * @param asset_symbol_or_id the symbol or id of the BitAsset in question * @returns the BitAsset-specific data for this asset */ - asset_bitasset_data_object get_bitasset_data(string asset_name_or_id)const; + asset_bitasset_data_object get_bitasset_data(string asset_symbol_or_id)const; /** * Returns information about the given HTLC object. @@ -286,12 +287,35 @@ class wallet_api */ account_id_type get_account_id(string account_name_or_id) const; + /** Lookup the name of an account. + * @param account_name_or_id the name or ID of the account to look up + * @returns the name of the account + */ + string get_account_name(string account_name_or_id) const + { return get_account( account_name_or_id ).name; } + /** - * Lookup the id of a named asset. - * @param asset_name_or_id the symbol or ID of an asset to look up + * Lookup the id of an asset. + * @param asset_symbol_or_id the symbol or ID of an asset to look up * @returns the id of the given asset */ - asset_id_type get_asset_id(string asset_name_or_id) const; + asset_id_type get_asset_id(string asset_symbol_or_id) const; + + /** + * Lookup the symbol of an asset. + * @param asset_symbol_or_id the symbol or ID of an asset to look up + * @returns the symbol of the given asset + */ + string get_asset_symbol(string asset_symbol_or_id) const + { return get_asset( asset_symbol_or_id ).symbol; } + + /** + * Lookup the symbol of an asset. Synonym of @ref get_asset_symbol. + * @param asset_symbol_or_id the symbol or ID of an asset to look up + * @returns the symbol of the given asset + */ + string get_asset_name(string asset_symbol_or_id) const + { return get_asset_symbol( asset_symbol_or_id ); } /** * Returns the blockchain object corresponding to the given id. @@ -354,7 +378,7 @@ class wallet_api * * Calculate and update fees for the operations in a transaction builder. * @param handle handle of the transaction builder - * @param fee_asset name or ID of an asset that to be used to pay fees + * @param fee_asset symbol or ID of an asset that to be used to pay fees * @return total fees */ asset set_fees_on_builder_transaction(transaction_handle_type handle, string fee_asset = GRAPHENE_SYMBOL); @@ -694,11 +718,11 @@ class wallet_api * Upgrades an account to prime status. * This makes the account holder a 'lifetime member'. * - * @param name the name or id of the account to upgrade + * @param account_name_or_id the name or id of the account to upgrade * @param broadcast true to broadcast the transaction on the network * @returns the signed transaction upgrading the account */ - signed_transaction upgrade_account(string name, bool broadcast); + signed_transaction upgrade_account(string account_name_or_id, bool broadcast); /** Creates a new account and registers it on the blockchain. * @@ -708,9 +732,11 @@ class wallet_api * @see register_account() * * @param brain_key the brain key used for generating the account's private keys - * @param account_name the name of the account, must be unique on the blockchain. Shorter names - * are more expensive to register; the rules are still in flux, but in general - * names of more than 8 characters with at least one digit will be cheap. + * @param account_name the name of the account, must be unique on the blockchain. + * Names with only latin letters and at least one vowel are + * premium names and expensive to register; + * names with only consonants, or at least with a digit, a dot or + * a minus sign are cheap. * @param registrar_account the account which will pay the fee to register the user * @param referrer_account the account who is acting as a referrer, and may receive a * portion of the user's transaction fees. This can be the @@ -728,7 +754,7 @@ class wallet_api * @param from the name or id of the account sending the funds * @param to the name or id of the account receiving the funds * @param amount the amount to send (in nominal units -- to send half of a BTS, specify 0.5) - * @param asset_symbol the symbol or id of the asset to send + * @param asset_symbol_or_id the symbol or id of the asset to send * @param memo a memo to attach to the transaction. The memo will be encrypted in the * transaction and readable for the receiver. There is no length limit * other than the limit imposed by maximum transaction size, but transaction @@ -739,7 +765,7 @@ class wallet_api signed_transaction transfer(string from, string to, string amount, - string asset_symbol, + string asset_symbol_or_id, string memo, bool broadcast = false); @@ -749,7 +775,7 @@ class wallet_api * @param from the name or id of the account sending the funds * @param to the name or id of the account receiving the funds * @param amount the amount to send (in nominal units -- to send half of a BTS, specify 0.5) - * @param asset_symbol the symbol or id of the asset to send + * @param asset_symbol_or_id the symbol or id of the asset to send * @param memo a memo to attach to the transaction. The memo will be encrypted in the * transaction and readable for the receiver. There is no length limit * other than the limit imposed by maximum transaction size, but transaction @@ -759,9 +785,9 @@ class wallet_api pair transfer2(string from, string to, string amount, - string asset_symbol, + string asset_symbol_or_id, string memo ) { - auto trx = transfer( from, to, amount, asset_symbol, memo, true ); + auto trx = transfer( from, to, amount, asset_symbol_or_id, memo, true ); return std::make_pair(trx.id(),trx); } @@ -899,33 +925,33 @@ class wallet_api blind_receipt receive_blind_transfer( string confirmation_receipt, string opt_from, string opt_memo ); /** - * Transfers a public balance from \c from_account_id_or_name to one or more blinded balances using a + * Transfers a public balance from \c from_account_name_or_id to one or more blinded balances using a * stealth transfer. - * @param from_account_id_or_name ID or name of an account to transfer from - * @param asset_symbol symbol or ID of the asset to be transferred + * @param from_account_name_or_id name or ID of an account to transfer from + * @param asset_symbol_or_id symbol or ID of the asset to be transferred * @param to_amounts map from key or label to amount * @param broadcast true to broadcast the transaction on the network * @return a blind confirmation */ - blind_confirmation transfer_to_blind( string from_account_id_or_name, - string asset_symbol, + blind_confirmation transfer_to_blind( string from_account_name_or_id, + string asset_symbol_or_id, vector> to_amounts, bool broadcast = false ); /** * Transfers funds from a set of blinded balances to a public account balance. * @param from_blind_account_key_or_label a public key in Base58 format or a label to transfer from - * @param to_account_id_or_name ID or name of an account to transfer to + * @param to_account_name_or_id name or ID of an account to transfer to * @param amount the amount to be transferred - * @param asset_symbol symbol or ID of the asset to be transferred + * @param asset_symbol_or_id symbol or ID of the asset to be transferred * @param broadcast true to broadcast the transaction on the network * @return a blind confirmation */ blind_confirmation transfer_from_blind( string from_blind_account_key_or_label, - string to_account_id_or_name, + string to_account_name_or_id, string amount, - string asset_symbol, + string asset_symbol_or_id, bool broadcast = false ); /** @@ -933,14 +959,14 @@ class wallet_api * @param from_key_or_label a public key in Base58 format or a label to transfer from * @param to_key_or_label a public key in Base58 format or a label to transfer to * @param amount the amount to be transferred - * @param symbol symbol or ID of the asset to be transferred + * @param symbol_or_id symbol or ID of the asset to be transferred * @param broadcast true to broadcast the transaction on the network * @return a blind confirmation */ blind_confirmation blind_transfer( string from_key_or_label, string to_key_or_label, string amount, - string symbol, + string symbol_or_id, bool broadcast = false ); /** Place a limit order attempting to sell one asset for another. @@ -948,8 +974,8 @@ class wallet_api * Buying and selling are the same operation on BitShares; if you want to buy BTS * with USD, you should sell USD for BTS. * - * The blockchain will attempt to sell the \c symbol_to_sell for as - * much \c symbol_to_receive as possible, as long as the price is at + * The blockchain will attempt to sell the \c symbol_or_id_to_sell for as + * much \c symbol_or_id_to_receive as possible, as long as the price is at * least \c min_to_receive / \c amount_to_sell. * * In addition to the transaction fees, market fees will apply as specified @@ -968,10 +994,10 @@ class wallet_api * @param seller_account the account providing the asset being sold, and which will * receive the proceeds of the sale. * @param amount_to_sell the amount of the asset being sold to sell (in nominal units) - * @param symbol_to_sell the name or id of the asset to sell + * @param symbol_or_id_to_sell the symbol or id of the asset to sell * @param min_to_receive the minimum amount you are willing to receive in return for * selling the entire amount_to_sell - * @param symbol_to_receive the name or id of the asset you wish to receive + * @param symbol_or_id_to_receive the symbol or id of the asset you wish to receive * @param timeout_sec if the order does not fill immediately, this is the length of * time the order will remain on the order books before it is * cancelled and the un-spent funds are returned to the seller's @@ -985,9 +1011,9 @@ class wallet_api */ signed_transaction sell_asset(string seller_account, string amount_to_sell, - string symbol_to_sell, + string symbol_or_id_to_sell, string min_to_receive, - string symbol_to_receive, + string symbol_or_id_to_receive, uint32_t timeout_sec = 0, bool fill_or_kill = false, bool broadcast = false); @@ -996,27 +1022,27 @@ class wallet_api * * This is the first step in shorting an asset. Call \c sell_asset() to complete the short. * - * @param borrower_name the name or id of the account associated with the transaction. + * @param borrower the name or id of the account associated with the transaction. * @param amount_to_borrow the amount of the asset being borrowed. Make this value * negative to pay back debt. - * @param asset_symbol the symbol or id of the asset being borrowed. + * @param asset_symbol_or_id the symbol or id of the asset being borrowed. * @param amount_of_collateral the amount of the backing asset to add to your collateral * position. Make this negative to claim back some of your collateral. * The backing asset is defined in the \c bitasset_options for the asset being borrowed. * @param broadcast true to broadcast the transaction on the network * @returns the signed transaction borrowing the asset */ - signed_transaction borrow_asset(string borrower_name, string amount_to_borrow, string asset_symbol, + signed_transaction borrow_asset(string borrower, string amount_to_borrow, string asset_symbol_or_id, string amount_of_collateral, bool broadcast = false); /** Borrow an asset or update the debt/collateral ratio for the loan, with additional options. * * This is the first step in shorting an asset. Call \c sell_asset() to complete the short. * - * @param borrower_name the name or id of the account associated with the transaction. + * @param borrower the name or id of the account associated with the transaction. * @param amount_to_borrow the amount of the asset being borrowed. Make this value * negative to pay back debt. - * @param asset_symbol the symbol or id of the asset being borrowed. + * @param asset_symbol_or_id the symbol or id of the asset being borrowed. * @param amount_of_collateral the amount of the backing asset to add to your collateral * position. Make this negative to claim back some of your collateral. * The backing asset is defined in the \c bitasset_options for the asset being borrowed. @@ -1024,7 +1050,7 @@ class wallet_api * @param broadcast true to broadcast the transaction on the network * @returns the signed transaction borrowing the asset */ - signed_transaction borrow_asset_ext( string borrower_name, string amount_to_borrow, string asset_symbol, + signed_transaction borrow_asset_ext( string borrower, string amount_to_borrow, string asset_symbol_or_id, string amount_of_collateral, call_order_update_operation::extensions_type extensions, bool broadcast = false ); @@ -1066,17 +1092,17 @@ class wallet_api fc::optional bitasset_opts, bool broadcast = false); - /** Issue new shares of an asset. + /** Create the specified amount of the specified asset and credit into the specified account. * - * @param to_account the name or id of the account to receive the new shares + * @param to_account the name or id of the account to receive the new supply * @param amount the amount to issue, in nominal units - * @param symbol the ticker symbol of the asset to issue + * @param symbol_or_id the ticker symbol or id of the asset to issue * @param memo a memo to include in the transaction, readable by the recipient * @param broadcast true to broadcast the transaction on the network - * @returns the signed transaction issuing the new shares + * @returns the signed transaction issuing the new supply */ signed_transaction issue_asset(string to_account, string amount, - string symbol, + string symbol_or_id, string memo, bool broadcast = false); @@ -1088,7 +1114,7 @@ class wallet_api * @note This operation cannot be used to update BitAsset-specific options. For these options, * \c update_bitasset() instead. * - * @param symbol the name or id of the asset to update + * @param symbol_or_id the symbol or id of the asset to update * @param new_issuer if changing the asset's issuer, the name or id of the new issuer. * null if you wish to remain the issuer of the asset * @param new_options the new asset_options object, which will entirely replace the existing @@ -1096,7 +1122,7 @@ class wallet_api * @param broadcast true to broadcast the transaction on the network * @returns the signed transaction updating the asset */ - signed_transaction update_asset(string symbol, + signed_transaction update_asset(string symbol_or_id, optional new_issuer, asset_options new_options, bool broadcast = false); @@ -1107,12 +1133,12 @@ class wallet_api * * @note This operation requires the owner key to be available in the wallet. * - * @param symbol the name or id of the asset to update + * @param symbol_or_id the symbol or id of the asset to update * @param new_issuer if changing the asset's issuer, the name or id of the new issuer. * @param broadcast true to broadcast the transaction on the network * @returns the signed transaction updating the asset */ - signed_transaction update_asset_issuer(string symbol, + signed_transaction update_asset_issuer(string symbol_or_id, string new_issuer, bool broadcast = false); @@ -1123,13 +1149,13 @@ class wallet_api * * @see update_asset() * - * @param symbol the name or id of the asset to update, which must be a market-issued asset + * @param symbol_or_id the symbol or id of the asset to update, which must be a market-issued asset * @param new_options the new bitasset_options object, which will entirely replace the existing * options. * @param broadcast true to broadcast the transaction on the network * @returns the signed transaction updating the bitasset */ - signed_transaction update_bitasset(string symbol, + signed_transaction update_bitasset(string symbol_or_id, bitasset_options new_options, bool broadcast = false); @@ -1137,13 +1163,13 @@ class wallet_api * * BitAssets have price feeds selected by taking the median values of recommendations from a set of feed producers. * This command is used to specify which accounts may produce feeds for a given BitAsset. - * @param symbol the name or id of the asset to update + * @param symbol_or_id the symbol or id of the asset to update * @param new_feed_producers a list of account names or ids which are authorized to produce feeds for the asset. * this list will completely replace the existing list * @param broadcast true to broadcast the transaction on the network * @returns the signed transaction updating the bitasset's feed producers */ - signed_transaction update_asset_feed_producers(string symbol, + signed_transaction update_asset_feed_producers(string symbol_or_id, flat_set new_feed_producers, bool broadcast = false); @@ -1162,13 +1188,13 @@ class wallet_api * its collateral. * * @param publishing_account the account publishing the price feed - * @param symbol the name or id of the asset whose feed we're publishing + * @param symbol_or_id the symbol or id of the asset whose feed we're publishing * @param feed the price_feed object containing the three prices making up the feed * @param broadcast true to broadcast the transaction on the network * @returns the signed transaction updating the price feed for the given asset */ signed_transaction publish_asset_feed(string publishing_account, - string symbol, + string symbol_or_id, price_feed feed, bool broadcast = false); @@ -1181,13 +1207,13 @@ class wallet_api * This command allows anyone to deposit the core asset into this fee pool. * * @param from the name or id of the account sending the core asset - * @param symbol the name or id of the asset whose fee pool you wish to fund + * @param symbol_or_id the symbol or id of the asset whose fee pool you wish to fund * @param amount the amount of the core asset to deposit * @param broadcast true to broadcast the transaction on the network * @returns the signed transaction funding the fee pool */ signed_transaction fund_asset_fee_pool(string from, - string symbol, + string symbol_or_id, string amount, bool broadcast = false); @@ -1199,33 +1225,33 @@ class wallet_api * * This command allows the issuer to withdraw those funds from the fee pool. * - * @param symbol the name or id of the asset whose fee pool you wish to claim + * @param symbol_or_id the symbol or id of the asset whose fee pool you wish to claim * @param amount the amount of the core asset to withdraw * @param broadcast true to broadcast the transaction on the network * @returns the signed transaction claiming from the fee pool */ - signed_transaction claim_asset_fee_pool(string symbol, + signed_transaction claim_asset_fee_pool(string symbol_or_id, string amount, bool broadcast = false); - /** Burns an amount of given asset. + /** Burns an amount of given asset to its reserve pool. * * This command burns an amount of given asset to reduce the amount in circulation. * @note you cannot burn market-issued assets. * @param from the account containing the asset you wish to burn * @param amount the amount to burn, in nominal units - * @param symbol the name or id of the asset to burn + * @param symbol_or_id the symbol or id of the asset to burn * @param broadcast true to broadcast the transaction on the network * @returns the signed transaction burning the asset */ signed_transaction reserve_asset(string from, string amount, - string symbol, + string symbol_or_id, bool broadcast = false); /** Forces a global settling of the given asset (black swan or prediction markets). * - * In order to use this operation, asset_to_settle must have the global_settle flag set + * In order to use this operation, asset_to_settle must have the \c global_settle permission set * * When this operation is executed all open margin positions are called at the settle price. * A pool will be formed containing the collateral got from the margin positions. @@ -1235,12 +1261,12 @@ class wallet_api * * @note this operation is used only by the asset issuer. * - * @param symbol the name or id of the asset to globally settle + * @param symbol_or_id the symbol or id of the asset to globally settle * @param settle_price the price at which to settle * @param broadcast true to broadcast the transaction on the network * @returns the signed transaction settling the named asset */ - signed_transaction global_settle_asset(string symbol, + signed_transaction global_settle_asset(string symbol_or_id, price settle_price, bool broadcast = false); @@ -1254,17 +1280,17 @@ class wallet_api * will be based on the feed price for the market-issued asset being settled. * The exact settlement price will be the * feed price at the time of settlement with an offset in favor of the margin position, where the offset is a - * blockchain parameter set in the global_property_object. + * blockchain parameter set in the asset's bitasset options. * * @param account_to_settle the name or id of the account owning the asset - * @param amount_to_settle the amount of the named asset to schedule for settlement - * @param symbol the name or id of the asset to settle + * @param amount_to_settle the amount of the asset to schedule for settlement + * @param symbol_or_id the symbol or id of the asset to settle * @param broadcast true to broadcast the transaction on the network * @returns the signed transaction settling the named asset */ signed_transaction settle_asset(string account_to_settle, string amount_to_settle, - string symbol, + string symbol_or_id, bool broadcast = false); /** Creates or updates a bid on an MPA after global settlement. @@ -1274,16 +1300,16 @@ class wallet_api * the debt and the settlement fund, see BSIP-0018. Updating an existing * bid to cover 0 debt will delete the bid. * - * @param bidder_name the name or id of the account making the bid + * @param bidder the name or id of the account making the bid * @param debt_amount the amount of debt of the named asset to bid for - * @param debt_symbol the name or id of the MPA to bid for + * @param debt_symbol_or_id the symbol or id of the MPA to bid for * @param additional_collateral the amount of additional collateral to bid * for taking over debt_amount. The asset type of this amount is - * determined automatically from debt_symbol. + * determined automatically from \c debt_symbol_or_id. * @param broadcast true to broadcast the transaction on the network * @returns the signed transaction creating/updating the bid */ - signed_transaction bid_collateral(string bidder_name, string debt_amount, string debt_symbol, + signed_transaction bid_collateral(string bidder, string debt_amount, string debt_symbol_or_id, string additional_collateral, bool broadcast = false); /** Whitelist and blacklist accounts, primarily for transacting in whitelisted assets. @@ -1441,7 +1467,7 @@ class wallet_api * @param source The account that will reserve the funds (and pay the fee) * @param destination The account that will receive the funds if the preimage is presented * @param amount the amount of the asset that is to be traded - * @param asset_symbol The asset that is to be traded + * @param asset_symbol_or_id The asset that is to be traded * @param hash_algorithm the algorithm used to generate the hash from the preimage. Can be RIPEMD160, SHA1 or SHA256. * @param preimage_hash the hash of the preimage * @param preimage_size the size of the preimage in bytes @@ -1450,7 +1476,7 @@ class wallet_api * @param broadcast true if you wish to broadcast the transaction * @return the signed transaction */ - signed_transaction htlc_create( string source, string destination, string amount, string asset_symbol, + signed_transaction htlc_create( string source, string destination, string amount, string asset_symbol_or_id, string hash_algorithm, const std::string& preimage_hash, uint32_t preimage_size, const uint32_t claim_period_seconds, const std::string& memo, bool broadcast = false ); @@ -1490,28 +1516,28 @@ class wallet_api * * @param witness_name The account name of the witness, also accepts account ID or vesting balance ID type. * @param amount The amount to withdraw. - * @param asset_symbol The symbol of the asset to withdraw. + * @param asset_symbol_or_id The symbol or id of the asset to withdraw. * @param broadcast true if you wish to broadcast the transaction * @return the signed transaction */ signed_transaction withdraw_vesting( string witness_name, string amount, - string asset_symbol, + string asset_symbol_or_id, bool broadcast = false); /** Vote for a given committee_member. * * An account can publish a list of all committee_members they approve of. This * command allows you to add or remove committee_members from this list. - * Each account's vote is weighted according to the number of shares of the - * core asset owned by that account at the time the votes are tallied. + * Each account's vote is weighted according to the number of voting stake + * owned by that account at the time the votes are tallied. * * @note you cannot vote against a committee_member, you can only vote for the committee_member * or not vote for the committee_member. * - * @param voting_account the name or id of the account who is voting with their shares - * @param committee_member the name or id of the committee_member' owner account + * @param voting_account the name or id of the account who is voting with their stake + * @param committee_member the name or id of the committee_member's owner account * @param approve true if you wish to vote in favor of that committee_member, false to * remove your vote in favor of that committee_member * @param broadcast true if you wish to broadcast the transaction @@ -1526,13 +1552,13 @@ class wallet_api * * An account can publish a list of all witnesses they approve of. This * command allows you to add or remove witnesses from this list. - * Each account's vote is weighted according to the number of shares of the - * core asset owned by that account at the time the votes are tallied. + * Each account's vote is weighted according to the number of voting stake + * owned by that account at the time the votes are tallied. * * @note you cannot vote against a witness, you can only vote for the witness * or not vote for the witness. * - * @param voting_account the name or id of the account who is voting with their shares + * @param voting_account the name or id of the account who is voting with their stake * @param witness the name or id of the witness' owner account * @param approve true if you wish to vote in favor of that witness, false to * remove your vote in favor of that witness @@ -1556,8 +1582,8 @@ class wallet_api * This setting can be changed at any time. * * @param account_to_modify the name or id of the account to update - * @param voting_account the name or id of an account authorized to vote account_to_modify's shares, - * or null to vote your own shares + * @param voting_account the name or id of an account authorized to vote account_to_modify's stake, + * or null to vote your own stake * * @param broadcast true if you wish to broadcast the transaction * @return the signed transaction changing your vote proxy settings @@ -1701,8 +1727,8 @@ class wallet_api /** * Returns the order book for the market base:quote. - * @param base symbol name or ID of the base asset - * @param quote symbol name or ID of the quote asset + * @param base symbol or ID of the base asset + * @param quote symbol or ID of the quote asset * @param limit depth of the order book to retrieve, for bids and asks each, capped at 50 * @return Order book of the market */ @@ -1757,7 +1783,7 @@ class wallet_api * Each account can optionally add random information in the form of a key-value map * to be retrieved by any interested party. * - * @param account The account ID or name that we are adding additional information to. + * @param account The account name or ID that we are adding additional information to. * @param catalog The name of the catalog the operation will insert data to. * @param remove true if you want to remove stuff from a catalog. * @param key_values The map to be inserted/removed to/from the catalog @@ -1773,7 +1799,7 @@ class wallet_api * * Storage data added to the map with @ref account_store_map will be returned. * - * @param account Account ID or name to get contact data from. + * @param account Account name or ID to get stored data from. * @param catalog The catalog to retrieve. * * @return An \c account_storage_object or empty. @@ -1836,6 +1862,9 @@ FC_API( graphene::wallet::wallet_api, (publish_asset_feed) (issue_asset) (get_asset) + (get_asset_id) + (get_asset_name) + (get_asset_symbol) (get_bitasset_data) (fund_asset_fee_pool) (claim_asset_fee_pool) @@ -1864,6 +1893,7 @@ FC_API( graphene::wallet::wallet_api, (set_desired_witness_and_committee_member_count) (get_account) (get_account_id) + (get_account_name) (get_block) (get_account_count) (get_account_history) From f637d32dbb62d9d20235e742b00bad5ac8eb8d9a Mon Sep 17 00:00:00 2001 From: abitmore Date: Fri, 26 Feb 2021 12:35:53 -0500 Subject: [PATCH 014/147] Add secondary index for assets in liquidity pools --- .../api_helper_indexes/api_helper_indexes.cpp | 56 ++++++++++++++++--- .../api_helper_indexes/api_helper_indexes.hpp | 25 ++++++++- 2 files changed, 72 insertions(+), 9 deletions(-) diff --git a/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp b/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp index 25644b3f65..91959bd7a4 100644 --- a/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp +++ b/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp @@ -23,6 +23,7 @@ */ #include +#include #include #include @@ -78,19 +79,51 @@ void amount_in_collateral_index::object_modified( const object& objct ) object_inserted( objct ); } FC_CAPTURE_AND_RETHROW( (objct) ); } -share_type amount_in_collateral_index::get_amount_in_collateral( const asset_id_type& asset )const +share_type amount_in_collateral_index::get_amount_in_collateral( const asset_id_type& asst )const { try { - auto itr = in_collateral.find( asset ); + auto itr = in_collateral.find( asst ); if( itr == in_collateral.end() ) return 0; return itr->second; -} FC_CAPTURE_AND_RETHROW( (asset) ); } +} FC_CAPTURE_AND_RETHROW( (asst) ); } -share_type amount_in_collateral_index::get_backing_collateral( const asset_id_type& asset )const +share_type amount_in_collateral_index::get_backing_collateral( const asset_id_type& asst )const { try { - auto itr = backing_collateral.find( asset ); + auto itr = backing_collateral.find( asst ); if( itr == backing_collateral.end() ) return 0; return itr->second; -} FC_CAPTURE_AND_RETHROW( (asset) ); } +} FC_CAPTURE_AND_RETHROW( (asst) ); } + +void asset_in_liquidity_pools_index::object_inserted( const object& objct ) +{ try { + const liquidity_pool_object& o = static_cast( objct ); + asset_in_pools_map[ o.asset_a ].insert( o.id ); // Note: [] operator will create an entry if not found + asset_in_pools_map[ o.asset_b ].insert( o.id ); +} FC_CAPTURE_AND_RETHROW( (objct) ); } + +void asset_in_liquidity_pools_index::object_removed( const object& objct ) +{ try { + const liquidity_pool_object& o = static_cast( objct ); + asset_in_pools_map[ o.asset_a ].erase( o.id ); + asset_in_pools_map[ o.asset_b ].erase( o.id ); + // Note: do not erase entries with an empty set from the map in order to avoid read/write race conditions +} FC_CAPTURE_AND_RETHROW( (objct) ); } + +void asset_in_liquidity_pools_index::about_to_modify( const object& objct ) +{ +} + +void asset_in_liquidity_pools_index::object_modified( const object& objct ) +{ +} + +const flat_set& asset_in_liquidity_pools_index::get_liquidity_pools_by_asset( + const asset_id_type& a )const +{ + auto itr = asset_in_pools_map.find( a ); + if( itr != asset_in_pools_map.end() ) + return itr->second; + return empty_set; +} namespace detail { @@ -147,9 +180,10 @@ void api_helper_indexes::plugin_initialize(const boost::program_options::variabl void api_helper_indexes::plugin_startup() { ilog("api_helper_indexes: plugin_startup() begin"); - amount_in_collateral = database().add_secondary_index< primary_index, amount_in_collateral_index >(); + amount_in_collateral_idx = database().add_secondary_index< primary_index, + amount_in_collateral_index >(); for( const auto& call : database().get_index_type().indices() ) - amount_in_collateral->object_inserted( call ); + amount_in_collateral_idx->object_inserted( call ); auto& account_members = *database().add_secondary_index< primary_index, account_member_index >(); for( const auto& account : database().get_index_type< account_index >().indices() ) @@ -158,6 +192,12 @@ void api_helper_indexes::plugin_startup() auto& approvals = *database().add_secondary_index< primary_index, required_approval_index >(); for( const auto& proposal : database().get_index_type< proposal_index >().indices() ) approvals.object_inserted( proposal ); + + asset_in_liquidity_pools_idx = database().add_secondary_index< primary_index, + asset_in_liquidity_pools_index >(); + for( const auto& pool : database().get_index_type().indices() ) + asset_in_liquidity_pools_idx->object_inserted( pool ); + } } } diff --git a/libraries/plugins/api_helper_indexes/include/graphene/api_helper_indexes/api_helper_indexes.hpp b/libraries/plugins/api_helper_indexes/include/graphene/api_helper_indexes/api_helper_indexes.hpp index 400b3000b1..216f85d594 100644 --- a/libraries/plugins/api_helper_indexes/include/graphene/api_helper_indexes/api_helper_indexes.hpp +++ b/libraries/plugins/api_helper_indexes/include/graphene/api_helper_indexes/api_helper_indexes.hpp @@ -32,6 +32,8 @@ using namespace chain; /** * @brief This secondary index tracks how much of each asset is locked up as collateral for MPAs, and how much * collateral is backing an MPA in total. + * @note This is implemented with \c flat_map considering there aren't too many MPAs and PMs in the system thus + * the performance would be acceptable. */ class amount_in_collateral_index : public secondary_index { @@ -49,6 +51,26 @@ class amount_in_collateral_index : public secondary_index flat_map backing_collateral; }; +/** + * @brief This secondary index maintains a map to make it easier to find liquidity pools by any asset in the pool. + * @note This is implemented with \c flat_map and \c flat_set considering there aren't too many liquidity pools + * in the system thus the performance would be acceptable. + */ +class asset_in_liquidity_pools_index: public secondary_index +{ + public: + virtual void object_inserted( const object& obj ) override; + virtual void object_removed( const object& obj ) override; + virtual void about_to_modify( const object& before ) override; + virtual void object_modified( const object& after ) override; + + const flat_set& get_liquidity_pools_by_asset( const asset_id_type& a )const; + + private: + flat_set empty_set; + flat_map> asset_in_pools_map; +}; + namespace detail { class api_helper_indexes_impl; @@ -72,7 +94,8 @@ class api_helper_indexes : public graphene::app::plugin std::unique_ptr my; private: - amount_in_collateral_index* amount_in_collateral = nullptr; + amount_in_collateral_index* amount_in_collateral_idx = nullptr; + asset_in_liquidity_pools_index* asset_in_liquidity_pools_idx = nullptr; }; } } //graphene::template From 5b4cb7d8f30b32d4ac938b626ae0ba16202c9ac4 Mon Sep 17 00:00:00 2001 From: abitmore Date: Fri, 26 Feb 2021 13:02:18 -0500 Subject: [PATCH 015/147] Add db API to find liquidity pools by one asset --- libraries/app/database_api.cpp | 61 +++++++++++++++++++ libraries/app/database_api_impl.hxx | 6 ++ .../app/include/graphene/app/database_api.hpp | 21 +++++++ 3 files changed, 88 insertions(+) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 60bf4980b9..45b9445fd2 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -84,6 +84,16 @@ database_api_impl::database_api_impl( graphene::chain::database& db, const appli { amount_in_collateral_index = nullptr; } + + try + { + asset_in_liquidity_pools_index = &_db.get_index_type< primary_index< liquidity_pool_index > >() + .get_secondary_index(); + } + catch( fc::assert_exception& e ) + { + asset_in_liquidity_pools_index = nullptr; + } } database_api_impl::~database_api_impl() @@ -1816,6 +1826,57 @@ vector database_api_impl::get_liquidity_pools_by with_statistics ); } +vector database_api::get_liquidity_pools_by_one_asset( + std::string asset_symbol_or_id, + optional limit, + optional start_id, + optional with_statistics )const +{ + return my->get_liquidity_pools_by_one_asset( + asset_symbol_or_id, + limit, + start_id, + with_statistics ); +} + +vector database_api_impl::get_liquidity_pools_by_one_asset( + std::string asset_symbol_or_id, + optional olimit, + optional ostart_id, + optional with_statistics )const +{ + // api_helper_indexes plugin is required for accessing the secondary index + FC_ASSERT( _app_options && _app_options->has_api_helper_indexes_plugin, + "api_helper_indexes plugin is not enabled on this server." ); + + uint32_t limit = olimit.valid() ? *olimit : 101; + const auto configured_limit = _app_options->api_limit_get_liquidity_pools; + FC_ASSERT( limit <= configured_limit, + "limit can not be greater than ${configured_limit}", + ("configured_limit", configured_limit) ); + + asset_id_type aid = get_asset_from_string(asset_symbol_or_id)->id; + + FC_ASSERT( asset_in_liquidity_pools_index, "Internal error" ); + const auto& pools = asset_in_liquidity_pools_index->get_liquidity_pools_by_asset( aid ); + + liquidity_pool_id_type start_id = ostart_id.valid() ? *ostart_id : liquidity_pool_id_type(); + + auto itr = pools.lower_bound( start_id ); + + bool with_stats = ( with_statistics.valid() && *with_statistics ); + + vector results; + + results.reserve( limit ); + for ( ; itr != pools.end() && results.size() < limit; ++itr ) + { + results.emplace_back( extend_liquidity_pool( (*itr)(_db), with_stats ) ); + } + + return results; +} + vector database_api::get_liquidity_pools_by_both_assets( std::string asset_symbol_or_id_a, std::string asset_symbol_or_id_b, diff --git a/libraries/app/database_api_impl.hxx b/libraries/app/database_api_impl.hxx index d6d8dd12ed..36379ae8de 100644 --- a/libraries/app/database_api_impl.hxx +++ b/libraries/app/database_api_impl.hxx @@ -153,6 +153,11 @@ class database_api_impl : public std::enable_shared_from_this optional limit = 101, optional start_id = optional(), optional with_statistics = false )const; + vector get_liquidity_pools_by_one_asset( + std::string asset_symbol_or_id, + optional limit = 101, + optional start_id = optional(), + optional with_statistics = false )const; vector get_liquidity_pools_by_both_assets( std::string asset_symbol_or_id_a, std::string asset_symbol_or_id_b, @@ -465,6 +470,7 @@ class database_api_impl : public std::enable_shared_from_this const application_options* _app_options = nullptr; const graphene::api_helper_indexes::amount_in_collateral_index* amount_in_collateral_index; + const graphene::api_helper_indexes::asset_in_liquidity_pools_index* asset_in_liquidity_pools_index; }; } } // graphene::app diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index 6b397f1882..86b44e3cb9 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -691,6 +691,26 @@ class database_api optional start_id = optional(), optional with_statistics = false )const; + /** + * @brief Get a list of liquidity pools by the symbol or ID of one asset in the pool + * @param asset_symbol_or_id symbol name or ID of the asset + * @param limit The limitation of items each query can fetch, not greater than a configured value + * @param start_id Start liquidity pool id, fetch pools whose IDs are greater than or equal to this ID + * @param with_statistics Whether to return statistics + * @return The liquidity pools + * + * @note + * 1. if @p asset_symbol_or_id cannot be tied to an asset, an error will be returned + * 2. @p limit can be omitted or be null, if so the default value 101 will be used + * 3. @p start_id can be omitted or be null, if so the api will return the "first page" of pools + * 4. can only omit one or more arguments in the end of the list, but not one or more in the middle + */ + vector get_liquidity_pools_by_one_asset( + std::string asset_symbol_or_id, + optional limit = 101, + optional start_id = optional(), + optional with_statistics = false )const; + /** * @brief Get a list of liquidity pools by the symbols or IDs of the two assets in the pool * @param asset_symbol_or_id_a symbol name or ID of one asset @@ -1179,6 +1199,7 @@ FC_API(graphene::app::database_api, (list_liquidity_pools) (get_liquidity_pools_by_asset_a) (get_liquidity_pools_by_asset_b) + (get_liquidity_pools_by_one_asset) (get_liquidity_pools_by_both_assets) (get_liquidity_pools) (get_liquidity_pools_by_share_asset) From 7f985c5d6fff17275be733ca93267a7a9be9e78b Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 27 Feb 2021 23:08:13 +0000 Subject: [PATCH 016/147] Fix cache for matrix in Github Actions --- .github/workflows/build-and-test.mac.yml | 8 ++++---- .github/workflows/build-and-test.ubuntu-debug.yml | 8 ++++---- .github/workflows/build-and-test.ubuntu-release.yml | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-and-test.mac.yml b/.github/workflows/build-and-test.mac.yml index a08db11241..17c99cf982 100644 --- a/.github/workflows/build-and-test.mac.yml +++ b/.github/workflows/build-and-test.mac.yml @@ -31,13 +31,13 @@ jobs: -D OPENSSL_ROOT_DIR=/usr/local/opt/openssl \ .. - name: Load Cache - uses: actions/cache@v1 + uses: actions/cache@v2 with: path: ccache - key: ccache-osx-${{ github.ref }}-${{ github.sha }} + key: ccache-${{ matrix.os }}-${{ github.ref }}-${{ github.sha }} restore-keys: | - ccache-osx-${{ github.ref }}- - ccache-osx- + ccache-${{ matrix.os }}-${{ github.ref }}- + ccache-${{ matrix.os }}- - name: Build run: | export CCACHE_DIR="$GITHUB_WORKSPACE/ccache" diff --git a/.github/workflows/build-and-test.ubuntu-debug.yml b/.github/workflows/build-and-test.ubuntu-debug.yml index 27298ea218..d2c8b3e14a 100644 --- a/.github/workflows/build-and-test.ubuntu-debug.yml +++ b/.github/workflows/build-and-test.ubuntu-debug.yml @@ -71,13 +71,13 @@ jobs: .. popd - name: Load Cache - uses: actions/cache@v1 + uses: actions/cache@v2 with: path: ccache - key: ccache-debug-${{ github.ref }}-${{ github.sha }} + key: ccache-debug-${{ matrix.os }}-${{ github.ref }}-${{ github.sha }} restore-keys: | - ccache-debug-${{ github.ref }}- - ccache-debug- + ccache-debug-${{ matrix.os }}-${{ github.ref }}- + ccache-debug-${{ matrix.os }}- - name: Build run: | export CCACHE_DIR="$GITHUB_WORKSPACE/ccache" diff --git a/.github/workflows/build-and-test.ubuntu-release.yml b/.github/workflows/build-and-test.ubuntu-release.yml index b7df124a2c..5ef0ffaa08 100644 --- a/.github/workflows/build-and-test.ubuntu-release.yml +++ b/.github/workflows/build-and-test.ubuntu-release.yml @@ -57,13 +57,13 @@ jobs: .. popd - name: Load Cache - uses: actions/cache@v1 + uses: actions/cache@v2 with: path: ccache - key: ccache-release-${{ github.ref }}-${{ github.sha }} + key: ccache-release-${{ matrix.os }}-${{ github.ref }}-${{ github.sha }} restore-keys: | - ccache-release-${{ github.ref }}- - ccache-release- + ccache-release-${{ matrix.os }}-${{ github.ref }}- + ccache-release-${{ matrix.os }}- - name: Build run: | export CCACHE_DIR="$GITHUB_WORKSPACE/ccache" From 4e5670b21a1f63bb06a32073395655c97b1bf8d7 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 28 Feb 2021 15:25:13 +0000 Subject: [PATCH 017/147] Integrate SonarScanner in Github Actions workflow --- .github/workflows/sonar-scan.yml | 138 ++++++++++++++++++ .../set_sonar_branch_for_github_actions | 82 +++++++++++ sonar-project.properties | 14 +- 3 files changed, 230 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/sonar-scan.yml create mode 100755 programs/build_helpers/set_sonar_branch_for_github_actions diff --git a/.github/workflows/sonar-scan.yml b/.github/workflows/sonar-scan.yml new file mode 100644 index 0000000000..b2e561dcba --- /dev/null +++ b/.github/workflows/sonar-scan.yml @@ -0,0 +1,138 @@ +name: Scan with SonarScanner +on: [ push, pull_request ] +env: + CCACHE_COMPRESS: exists means true + CCACHE_SLOPPINESS: include_file_ctime,include_file_mtime,time_macros +jobs: + sonar-scan: + name: Scan with SonarScanner + strategy: + matrix: + os: [ ubuntu-latest ] + runs-on: ${{ matrix.os }} + services: + elasticsearch: + image: docker://elasticsearch:7.4.2 + options: --env discovery.type=single-node --publish 9200:9200 --publish 9300:9300 + steps: + - name: Download and install latest SonarScanner CLI tool + run: | + SONAR_SCANNER_VERSION=`curl https://github.com/SonarSource/sonar-scanner-cli/releases/latest \ + 2>/dev/null | cut -f2 -d'"' | cut -f8 -d'/'` + SONAR_DOWNLOAD_PATH=https://binaries.sonarsource.com/Distribution/sonar-scanner-cli + curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip \ + $SONAR_DOWNLOAD_PATH/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip + unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ + curl --create-dirs -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip \ + https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip + unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/ + SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux + echo "SONAR_SCANNER_VERSION=$SONAR_SCANNER_VERSION" >> $GITHUB_ENV + echo "SONAR_SCANNER_HOME=$SONAR_SCANNER_HOME" >> $GITHUB_ENV + echo "SONAR_SCANNER_OPTS=-server" >> $GITHUB_ENV + echo "$SONAR_SCANNER_HOME/bin" >> $GITHUB_PATH + echo "$HOME/.sonar/build-wrapper-linux-x86" >> $GITHUB_PATH + - name: Install dependencies + run: | + df -h + sudo apt-get update + openssl_ver=`sudo apt-cache madison openssl | grep xenial-updates | awk '{print $3}'` + libssl_ver=`sudo apt-cache madison libssl-dev | grep xenial-updates | awk '{print $3}'` + [ -n "${openssl_ver}" ] && [ -n "${libssl_ver}" ] && \ + sudo apt-get install -y --allow-downgrades openssl=${openssl_ver} libssl-dev=${libssl_ver} + sudo apt-get install -y \ + ccache \ + parallel \ + libboost-thread-dev \ + libboost-iostreams-dev \ + libboost-date-time-dev \ + libboost-system-dev \ + libboost-filesystem-dev \ + libboost-program-options-dev \ + libboost-chrono-dev \ + libboost-test-dev \ + libboost-context-dev \ + libboost-regex-dev \ + libboost-coroutine-dev \ + libcurl4-openssl-dev + sudo apt-get auto-remove -y + sudo apt-get clean -y + df -h + sudo du -hs /mnt/* + sudo ls -alr /mnt/ + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + submodules: recursive + - name: Configure + run: | + pwd + df -h . + mkdir -p _build + sudo mkdir -p /_build/libraries /_build/programs /mnt/_build/tests + sudo chmod a+rwx /_build/libraries /_build/programs /mnt/_build/tests + ln -s /_build/libraries _build/libraries + ln -s /_build/programs _build/programs + ln -s /mnt/_build/tests _build/tests + sudo ln -s /_build/libraries /mnt/_build/libraries + sudo ln -s /_build/programs /mnt/_build/programs + sudo ln -s /mnt/_build/tests /_build/tests + ls -al _build + sed -i '/tests/d' libraries/fc/CMakeLists.txt + pushd _build + export -n BOOST_ROOT BOOST_INCLUDEDIR BOOST_LIBRARYDIR + cmake -D CMAKE_BUILD_TYPE=Debug \ + -D CMAKE_CXX_OUTPUT_EXTENSION_REPLACE=ON \ + -D CMAKE_C_COMPILER=gcc \ + -D CMAKE_C_COMPILER_LAUNCHER=ccache \ + -D CMAKE_CXX_COMPILER=g++ \ + -D CMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -D CMAKE_C_FLAGS=--coverage \ + -D CMAKE_CXX_FLAGS=--coverage \ + -D Boost_USE_STATIC_LIBS=OFF \ + .. + popd + - name: Load Cache + uses: actions/cache@v2 + with: + path: | + ccache + sonar_cache + key: sonar-${{ github.ref }}-${{ github.sha }} + restore-keys: | + sonar-${{ github.ref }}- + sonar- + - name: Build + run: | + export CCACHE_DIR="$GITHUB_WORKSPACE/ccache" + mkdir -p "$CCACHE_DIR" + df -h + programs/build_helpers/make_with_sonar bw-output -j 2 -C _build \ + witness_node cli_wallet js_operation_serializer get_dev_key network_mapper \ + app_test chain_test cli_test es_test + df -h + du -hs _build/libraries/* _build/programs/* _build/tests/* + du -hs _build/* + du -hs /_build/* + - name: Unit-Tests + run: | + _build/tests/app_test -l test_suite + df -h + _build/tests/es_test -l test_suite + df -h + libraries/fc/tests/run-parallel-tests.sh _build/tests/chain_test -l test_suite + _build/tests/cli_test -l test_suite + df -h + - name: Prepare for scanning with SonarScanner + run: | + mkdir -p sonar_cache + find _build/libraries/[acdenptuw]*/CMakeFiles/*.dir _build/programs/[cdgjsw]*/CMakeFiles/*.dir -type d -print \ + | while read d; do srcd="${d:7}"; gcov -o "$d" "${srcd/CMakeFiles*.dir//}"/*.cpp; done >/dev/null + programs/build_helpers/set_sonar_branch_for_github_actions sonar-project.properties + - name: Scan with SonarScanner + env: + # to get access to secrets.SONAR_TOKEN, provide GITHUB_TOKEN + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + sonar-scanner \ + -Dsonar.login=${{ secrets.SONAR_TOKEN }} diff --git a/programs/build_helpers/set_sonar_branch_for_github_actions b/programs/build_helpers/set_sonar_branch_for_github_actions new file mode 100755 index 0000000000..e4745d2466 --- /dev/null +++ b/programs/build_helpers/set_sonar_branch_for_github_actions @@ -0,0 +1,82 @@ +#!/bin/bash + +# Relevant variables set by Github Actions: +# GITHUB_HEAD_REF: Only set for pull request events. +# The name of the head branch. +# GITHUB_BASE_REF: Only set for pull request events. +# The name of the base branch. +# GITHUB_REF: The branch or tag ref that triggered the workflow. +# For example, refs/heads/feature-branch-1. +# If neither a branch or tag is available for the event type, +# the variable will not exist. + +if [ "$#" != 1 ]; then + echo "Usage: $0 " 1>&2 + exit 1 +fi + +clear_branch () { + sed -i '/sonar\.branch/d' "$1" +} + +if [ -n "$GITHUB_HEAD_REF" ]; then + # PRs work per default, remove sonar.branch.* and add sonar.pullrequest.* + echo "Detected PR '$GITHUB_REF' from '$GITHUB_HEAD_REF' to '$GITHUB_BASE_REF'" + PULLREF=${GITHUB_REF#refs/pull/} + PULLKEY=${PULLREF%/merge} + clear_branch "$1" + echo "sonar.pullrequest.key=$PULLKEY" >>"$1" + echo "sonar.pullrequest.base=$GITHUB_BASE_REF" >>"$1" + echo "sonar.pullrequest.branch=$GITHUB_HEAD_REF" >>"$1" +else + ORIGINAL_TARGET="$( grep 'sonar\.branch\.target' "$1" | sed 's=^.*[:=] *==' )" + TARGET="$ORIGINAL_TARGET" + + if [[ ${GITHUB_REF} == "refs/tags/"* ]]; then + # Tag build is either master or testnet + echo "Detected tag '${GITHUB_REF}'" + BRANCH="${GITHUB_REF#refs/}" + case "$BRANCH" in + *test*) TARGET=testnet; ;; + *) TARGET=master; ;; + esac + else + BRANCH="${GITHUB_REF#refs/heads/}" + case "$BRANCH" in + master|develop|testnet|hardfork) + # Long-lived branches stand for themselves, no target + echo "Detected long-lived branch '$BRANCH'" + TARGET= + ;; + *test*release*) + # Testnet release branch will be merged into testnet + echo "Detected testnet release branch '$BRANCH'" + TARGET=testnet + ;; + *release*) + # Release branch will be merged into default (master) + echo "Detected release branch '$BRANCH'" + TARGET=master + ;; + *) + # All other branches should have sonar.branch.target in their + # sonar.properties, leave it unchanged + echo "Detected normal branch '$BRANCH'" + esac + fi + + echo "Branch '$BRANCH', target '$TARGET'" + + if [ "x$TARGET" != "x$ORIGINAL_TARGET" ]; then + clear_branch "$1" + if [ -n "$TARGET" ]; then + echo "sonar.branch.target=$TARGET" >>"$1" + fi + fi + if [ -n "$BRANCH" ]; then + echo "sonar.branch.name=$BRANCH" >>"$1" + fi + +fi + +exit 0 diff --git a/sonar-project.properties b/sonar-project.properties index 4bd7ecc25a..91e5a755d7 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,8 +1,14 @@ -sonar.projectKey=BitShares_Core -sonar.projectName=BitShares Core +sonar.organization=bitshares-on-github + +sonar.projectKey=bitshares_bitshares-core +sonar.projectName=BitShares-Core +sonar.projectDescription=BitShares Blockchain implementation and command-line interface +sonar.projectVersion=5.2.0 + +sonar.host.url=https://sonarcloud.io sonar.links.homepage=https://bitshares.org -sonar.links.ci=https://travis-ci.org/bitshares/bitshares-core/ +sonar.links.ci=https://github.com/bitshares/bitshares-core/actions sonar.links.issue=https://github.com/bitshares/bitshares-core/issues sonar.links.scm=https://github.com/bitshares/bitshares-core/tree/master @@ -19,5 +25,5 @@ sonar.cfamily.cache.enabled=true sonar.cfamily.cache.path=sonar_cache # Decide which tree the current build belongs to in SonarCloud. -# Managed by the `set_sonar_branch` script when building with Travis CI. +# Managed by the `set_sonar_branch*` script when building with CI. sonar.branch.target=develop From 2736be3eeb21422e0274e7e6bd9322e6f41c4852 Mon Sep 17 00:00:00 2001 From: abitmore Date: Wed, 3 Mar 2021 00:37:52 +0000 Subject: [PATCH 018/147] Update gcov path --- .github/workflows/sonar-scan.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonar-scan.yml b/.github/workflows/sonar-scan.yml index b2e561dcba..c30fe6439b 100644 --- a/.github/workflows/sonar-scan.yml +++ b/.github/workflows/sonar-scan.yml @@ -127,7 +127,7 @@ jobs: run: | mkdir -p sonar_cache find _build/libraries/[acdenptuw]*/CMakeFiles/*.dir _build/programs/[cdgjsw]*/CMakeFiles/*.dir -type d -print \ - | while read d; do srcd="${d:7}"; gcov -o "$d" "${srcd/CMakeFiles*.dir//}"/*.cpp; done >/dev/null + | while read d; do srcd="${d:7}"; gcov -o "$d" "${srcd/CMakeFiles*.dir/.}"/*.cpp; done >/dev/null programs/build_helpers/set_sonar_branch_for_github_actions sonar-project.properties - name: Scan with SonarScanner env: From 72a8f4a5700fa716081b4410e15c0afcb2731e9d Mon Sep 17 00:00:00 2001 From: abitmore Date: Wed, 3 Mar 2021 00:38:11 +0000 Subject: [PATCH 019/147] Bump FC --- libraries/fc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/fc b/libraries/fc index eed0e9ec80..0954033fa5 160000 --- a/libraries/fc +++ b/libraries/fc @@ -1 +1 @@ -Subproject commit eed0e9ec80df18689913ad8327328edd331d6809 +Subproject commit 0954033fa5f2991352a922114fdf4a0667ec5a18 From 189fa772310e07d3c093f85f0f2178d26a17e528 Mon Sep 17 00:00:00 2001 From: abitmore Date: Thu, 4 Mar 2021 18:39:15 +0000 Subject: [PATCH 020/147] Force TLSv1.2 or above when using libcurl --- libraries/plugins/elasticsearch/elasticsearch_plugin.cpp | 5 ++++- libraries/plugins/es_objects/es_objects.cpp | 5 ++++- tests/elasticsearch/main.cpp | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp index 2860057f3a..9d61cd2fee 100644 --- a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp +++ b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp @@ -38,7 +38,10 @@ class elasticsearch_plugin_impl public: elasticsearch_plugin_impl(elasticsearch_plugin& _plugin) : _self( _plugin ) - { curl = curl_easy_init(); } + { + curl = curl_easy_init(); + curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); + } virtual ~elasticsearch_plugin_impl(); bool update_account_histories( const signed_block& b ); diff --git a/libraries/plugins/es_objects/es_objects.cpp b/libraries/plugins/es_objects/es_objects.cpp index 9aec0f574d..f89a11065b 100644 --- a/libraries/plugins/es_objects/es_objects.cpp +++ b/libraries/plugins/es_objects/es_objects.cpp @@ -43,7 +43,10 @@ class es_objects_plugin_impl public: es_objects_plugin_impl(es_objects_plugin& _plugin) : _self( _plugin ) - { curl = curl_easy_init(); } + { + curl = curl_easy_init(); + curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); + } virtual ~es_objects_plugin_impl(); bool index_database(const vector& ids, std::string action); diff --git a/tests/elasticsearch/main.cpp b/tests/elasticsearch/main.cpp index 5e3b0458f2..e747de5b07 100644 --- a/tests/elasticsearch/main.cpp +++ b/tests/elasticsearch/main.cpp @@ -51,6 +51,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_account_history) { CURL *curl; // curl handler curl = curl_easy_init(); + curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); graphene::utilities::ES es; es.curl = curl; @@ -140,6 +141,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_objects) { CURL *curl; // curl handler curl = curl_easy_init(); + curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); graphene::utilities::ES es; es.curl = curl; @@ -195,6 +197,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_suite) { CURL *curl; // curl handler curl = curl_easy_init(); + curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); graphene::utilities::ES es; es.curl = curl; @@ -221,6 +224,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { try { CURL *curl; // curl handler curl = curl_easy_init(); + curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); graphene::utilities::ES es; es.curl = curl; From f11fc1b49e9401ff8f4883c8698c84200614fe44 Mon Sep 17 00:00:00 2001 From: Abit Date: Fri, 5 Mar 2021 17:56:29 +0100 Subject: [PATCH 021/147] Reduce the allowable range of negative latency --- libraries/app/application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index a1403e2c7f..3a388befcd 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -571,7 +571,7 @@ bool application_impl::handle_block(const graphene::net::block_message& blk_msg, ("w",witness_account.name) ("i",last_irr)("d",blk_msg.block.block_num()-last_irr) ); } - GRAPHENE_ASSERT( latency.count()/1000 > -5000, + GRAPHENE_ASSERT( latency.count()/1000 > -2500, // 2.5 seconds graphene::net::block_timestamp_in_future_exception, "Rejecting block with timestamp in the future", ); From 4500401a76c9ce5c3b6dbb4c3d4ca9688b950d1f Mon Sep 17 00:00:00 2001 From: abitmore Date: Fri, 5 Mar 2021 17:41:03 +0000 Subject: [PATCH 022/147] Force TLSv1.2 or above when using libcurl (more) --- libraries/plugins/elasticsearch/elasticsearch_plugin.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp index 9d61cd2fee..07189c9af5 100644 --- a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp +++ b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp @@ -653,6 +653,7 @@ graphene::utilities::ES elasticsearch_plugin::prepareHistoryQuery(string query) { CURL *curl; curl = curl_easy_init(); + curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); graphene::utilities::ES es; es.curl = curl; From bd552fdbf81be4a7e2b81261690e9705c992c886 Mon Sep 17 00:00:00 2001 From: Abit Date: Fri, 5 Mar 2021 22:25:09 +0100 Subject: [PATCH 023/147] Update test case for negative latency change --- tests/app/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/app/main.cpp b/tests/app/main.cpp index a0d1b9b168..afd1cf0f61 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -336,6 +336,11 @@ BOOST_AUTO_TEST_CASE( two_node_network ) BOOST_TEST_MESSAGE( "Generating block on db2" ); fc::ecc::private_key committee_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("nathan"))); + // the other node will reject the block if its timestamp is in the future, so we wait + fc::wait_for( BROADCAST_WAIT_TIME, [db2] () { + return db2->get_slot_time(1) <= fc::time_point::now(); + }); + auto block_1 = db2->generate_block( db2->get_slot_time(1), db2->get_scheduled_witness(1), From d7b8faea5e0c87b18a90ebdac9151e393b93135c Mon Sep 17 00:00:00 2001 From: abitmore Date: Fri, 5 Mar 2021 22:21:00 +0000 Subject: [PATCH 024/147] Randomize index prefixes in ES tests --- tests/common/database_fixture.cpp | 10 ++++++++++ tests/common/database_fixture.hpp | 3 +++ tests/elasticsearch/main.cpp | 12 ++++++------ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index a3da81d32b..c70ed4cca1 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -301,6 +301,11 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) options.insert(std::make_pair("elasticsearch-operation-string", boost::program_options::variable_value(true, false))); options.insert(std::make_pair("elasticsearch-mode", boost::program_options::variable_value(uint16_t(2), false))); + es_index_prefix = string("bitshares-") + fc::to_string(uint64_t(rand())) + "-"; + BOOST_TEST_MESSAGE( string("ES index prefix is ") + es_index_prefix ); + options.insert(std::make_pair("elasticsearch-index-prefix", + boost::program_options::variable_value(es_index_prefix, false))); + esplugin->plugin_initialize(options); esplugin->plugin_startup(); } @@ -324,6 +329,11 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) options.insert(std::make_pair("es-objects-limit-orders", boost::program_options::variable_value(true, false))); options.insert(std::make_pair("es-objects-asset-bitasset", boost::program_options::variable_value(true, false))); + es_obj_index_prefix = string("objects-") + fc::to_string(uint64_t(rand())) + "-"; + BOOST_TEST_MESSAGE( string("ES_OBJ index prefix is ") + es_obj_index_prefix ); + options.insert(std::make_pair("es-objects-index-prefix", + boost::program_options::variable_value(es_obj_index_prefix, false))); + esobjects_plugin->plugin_initialize(options); esobjects_plugin->plugin_startup(); } diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index 4d596d8687..45aa1e6e27 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -211,6 +211,9 @@ struct database_fixture { bool hf1270 = false; bool bsip77 = false; + string es_index_prefix; ///< Index prefix for elasticsearch plugin + string es_obj_index_prefix; ///< Index prefix for es_objects plugin + database_fixture(const fc::time_point_sec &initial_timestamp = fc::time_point_sec(GRAPHENE_TESTING_GENESIS_TIMESTAMP)); ~database_fixture(); diff --git a/tests/elasticsearch/main.cpp b/tests/elasticsearch/main.cpp index 5e3b0458f2..2935a047d8 100644 --- a/tests/elasticsearch/main.cpp +++ b/tests/elasticsearch/main.cpp @@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_account_history) { graphene::utilities::ES es; es.curl = curl; es.elasticsearch_url = "http://localhost:9200/"; - es.index_prefix = "bitshares-"; + es.index_prefix = es_index_prefix; //es.auth = "elastic:changeme"; // delete all first @@ -120,7 +120,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_account_history) { // check the visitor data auto block_date = db.head_block_time(); - std::string index_name = graphene::utilities::generateIndexName(block_date, "bitshares-"); + std::string index_name = graphene::utilities::generateIndexName(block_date, es_index_prefix); es.endpoint = index_name + "/data/2.9.12"; // we know last op is a transfer of amount 300 res = graphene::utilities::getEndPoint(es); @@ -144,7 +144,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_objects) { graphene::utilities::ES es; es.curl = curl; es.elasticsearch_url = "http://localhost:9200/"; - es.index_prefix = "objects-"; + es.index_prefix = es_obj_index_prefix; //es.auth = "elastic:changeme"; // delete all first @@ -199,10 +199,10 @@ BOOST_AUTO_TEST_CASE(elasticsearch_suite) { graphene::utilities::ES es; es.curl = curl; es.elasticsearch_url = "http://localhost:9200/"; - es.index_prefix = "bitshares-"; + es.index_prefix = es_index_prefix; auto delete_account_history = graphene::utilities::deleteAll(es); fc::usleep(ES_WAIT_TIME); - es.index_prefix = "objects-"; + es.index_prefix = es_obj_index_prefix; auto delete_objects = graphene::utilities::deleteAll(es); fc::usleep(ES_WAIT_TIME); @@ -225,7 +225,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { graphene::utilities::ES es; es.curl = curl; es.elasticsearch_url = "http://localhost:9200/"; - es.index_prefix = "bitshares-"; + es.index_prefix = es_index_prefix; auto delete_account_history = graphene::utilities::deleteAll(es); From a035c6b7d5a092d03afdfd6ae3afeeb186eedc30 Mon Sep 17 00:00:00 2001 From: abitmore Date: Fri, 5 Mar 2021 22:34:46 +0000 Subject: [PATCH 025/147] Bump ES version to 7.10.1 in Github Actions --- .github/workflows/build-and-test.ubuntu-debug.yml | 2 +- .github/workflows/build-and-test.ubuntu-release.yml | 2 +- .github/workflows/sonar-scan.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-test.ubuntu-debug.yml b/.github/workflows/build-and-test.ubuntu-debug.yml index d2c8b3e14a..92eca92eb7 100644 --- a/.github/workflows/build-and-test.ubuntu-debug.yml +++ b/.github/workflows/build-and-test.ubuntu-debug.yml @@ -12,7 +12,7 @@ jobs: runs-on: ${{ matrix.os }} services: elasticsearch: - image: docker://elasticsearch:7.4.2 + image: docker://elasticsearch:7.10.1 options: --env discovery.type=single-node --publish 9200:9200 --publish 9300:9300 steps: - name: Install dependencies diff --git a/.github/workflows/build-and-test.ubuntu-release.yml b/.github/workflows/build-and-test.ubuntu-release.yml index 5ef0ffaa08..9f30bf55ba 100644 --- a/.github/workflows/build-and-test.ubuntu-release.yml +++ b/.github/workflows/build-and-test.ubuntu-release.yml @@ -12,7 +12,7 @@ jobs: runs-on: ${{ matrix.os }} services: elasticsearch: - image: docker://elasticsearch:7.4.2 + image: docker://elasticsearch:7.10.1 options: --env discovery.type=single-node --publish 9200:9200 --publish 9300:9300 steps: - name: Install dependencies diff --git a/.github/workflows/sonar-scan.yml b/.github/workflows/sonar-scan.yml index c30fe6439b..f1afc20f3c 100644 --- a/.github/workflows/sonar-scan.yml +++ b/.github/workflows/sonar-scan.yml @@ -12,7 +12,7 @@ jobs: runs-on: ${{ matrix.os }} services: elasticsearch: - image: docker://elasticsearch:7.4.2 + image: docker://elasticsearch:7.10.1 options: --env discovery.type=single-node --publish 9200:9200 --publish 9300:9300 steps: - name: Download and install latest SonarScanner CLI tool From 44345ce4c91f4b7d52a929ae4962963482ddc5cd Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 6 Mar 2021 01:48:54 +0000 Subject: [PATCH 026/147] Init unit test suite for all unit test apps Move the init_unit_test_suite(...) function to a hpp file and include it in every unit test app: - app_test - chain_test - cli_test - es_test - performance_test --- tests/app/main.cpp | 5 +-- tests/cli/main.cpp | 5 +-- tests/common/init_unit_test_suite.hpp | 42 +++++++++++++++++++++++++ tests/elasticsearch/main.cpp | 3 +- tests/performance/performance_tests.cpp | 8 +---- tests/tests/main.cpp | 20 +----------- 6 files changed, 51 insertions(+), 32 deletions(-) create mode 100644 tests/common/init_unit_test_suite.hpp diff --git a/tests/app/main.cpp b/tests/app/main.cpp index a0d1b9b168..6afc8969a8 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -42,11 +42,12 @@ #include "../../libraries/app/application_impl.hxx" -#define BOOST_TEST_MODULE Test Application -#include +#include "../common/init_unit_test_suite.hpp" #include "../common/genesis_file_util.hpp" +uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP = 1431700000; // needed for compiling, not used + using namespace graphene; namespace bpo = boost::program_options; diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index cdaa707e3b..c0f3396ee5 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -60,8 +60,9 @@ #include -#define BOOST_TEST_MODULE Test Application -#include +#include "../common/init_unit_test_suite.hpp" + +uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP = 1431700000; // needed for compiling, not used /***** * Global Initialization for Windows diff --git a/tests/common/init_unit_test_suite.hpp b/tests/common/init_unit_test_suite.hpp new file mode 100644 index 0000000000..0c3e9f7644 --- /dev/null +++ b/tests/common/init_unit_test_suite.hpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include +#include +#include +#include + +extern uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP; + +boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { + const auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count(); + std::srand( seed ); + std::cout << "Random number generator seeded to " << seed << std::endl; + const char* genesis_timestamp_str = getenv("GRAPHENE_TESTING_GENESIS_TIMESTAMP"); + if( genesis_timestamp_str != nullptr ) + { + GRAPHENE_TESTING_GENESIS_TIMESTAMP = std::stoul( genesis_timestamp_str ); + } + std::cout << "GRAPHENE_TESTING_GENESIS_TIMESTAMP is " << GRAPHENE_TESTING_GENESIS_TIMESTAMP << std::endl; + return nullptr; +} diff --git a/tests/elasticsearch/main.cpp b/tests/elasticsearch/main.cpp index 2935a047d8..2b1836a31b 100644 --- a/tests/elasticsearch/main.cpp +++ b/tests/elasticsearch/main.cpp @@ -31,8 +31,7 @@ #include "../common/database_fixture.hpp" -#define BOOST_TEST_MODULE Elastic Search Database Tests -#include +#include "../common/init_unit_test_suite.hpp" #ifdef NDEBUG #define ES_WAIT_TIME (fc::milliseconds(1000)) diff --git a/tests/performance/performance_tests.cpp b/tests/performance/performance_tests.cpp index 152f672189..35d0a1b7cc 100644 --- a/tests/performance/performance_tests.cpp +++ b/tests/performance/performance_tests.cpp @@ -22,13 +22,7 @@ * THE SOFTWARE. */ -#include - -boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { - std::srand(time(NULL)); - std::cout << "Random number generator seeded to " << time(NULL) << std::endl; - return nullptr; -} +#include "../common/init_unit_test_suite.hpp" #include diff --git a/tests/tests/main.cpp b/tests/tests/main.cpp index 0c3e9f7644..48ba3b7e4b 100644 --- a/tests/tests/main.cpp +++ b/tests/tests/main.cpp @@ -21,22 +21,4 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include -#include -#include -#include - -extern uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP; - -boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { - const auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count(); - std::srand( seed ); - std::cout << "Random number generator seeded to " << seed << std::endl; - const char* genesis_timestamp_str = getenv("GRAPHENE_TESTING_GENESIS_TIMESTAMP"); - if( genesis_timestamp_str != nullptr ) - { - GRAPHENE_TESTING_GENESIS_TIMESTAMP = std::stoul( genesis_timestamp_str ); - } - std::cout << "GRAPHENE_TESTING_GENESIS_TIMESTAMP is " << GRAPHENE_TESTING_GENESIS_TIMESTAMP << std::endl; - return nullptr; -} +#include "../common/init_unit_test_suite.hpp" From 9de407b788023f8df96361e5007ac90660edbf85 Mon Sep 17 00:00:00 2001 From: Abit Date: Sat, 6 Mar 2021 04:13:08 +0100 Subject: [PATCH 027/147] Wait longer in es_test, and fix crashes --- tests/elasticsearch/main.cpp | 76 ++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/tests/elasticsearch/main.cpp b/tests/elasticsearch/main.cpp index 2b1836a31b..96efef7358 100644 --- a/tests/elasticsearch/main.cpp +++ b/tests/elasticsearch/main.cpp @@ -34,9 +34,9 @@ #include "../common/init_unit_test_suite.hpp" #ifdef NDEBUG - #define ES_WAIT_TIME (fc::milliseconds(1000)) + #define ES_WAIT_TIME (fc::milliseconds(2000)) #else - #define ES_WAIT_TIME (fc::milliseconds(3000)) + #define ES_WAIT_TIME (fc::milliseconds(5000)) #endif using namespace graphene::chain; @@ -250,7 +250,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { // f(A, 0, 4, 9) = { 5, 3, 1, 0 } auto histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 4, operation_history_id_type(9)); - BOOST_CHECK_EQUAL(histories.size(), 4u); + BOOST_REQUIRE_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); @@ -258,7 +258,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { // f(A, 0, 4, 6) = { 5, 3, 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 4, operation_history_id_type(6)); - BOOST_CHECK_EQUAL(histories.size(), 4u); + BOOST_REQUIRE_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); @@ -266,7 +266,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { // f(A, 0, 4, 5) = { 5, 3, 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 4, operation_history_id_type(5)); - BOOST_CHECK_EQUAL(histories.size(), 4u); + BOOST_REQUIRE_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); @@ -274,33 +274,33 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { // f(A, 0, 4, 4) = { 3, 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 4, operation_history_id_type(4)); - BOOST_CHECK_EQUAL(histories.size(), 3u); + BOOST_REQUIRE_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u); // f(A, 0, 4, 3) = { 3, 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 4, operation_history_id_type(3)); - BOOST_CHECK_EQUAL(histories.size(), 3u); + BOOST_REQUIRE_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u); // f(A, 0, 4, 2) = { 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 4, operation_history_id_type(2)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u); // f(A, 0, 4, 1) = { 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 4, operation_history_id_type(1)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u); // f(A, 0, 4, 0) = { 5, 3, 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 4, operation_history_id_type()); - BOOST_CHECK_EQUAL(histories.size(), 4u); + BOOST_REQUIRE_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); @@ -308,30 +308,30 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { // f(A, 1, 5, 9) = { 5, 3 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(1), 5, operation_history_id_type(9)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); // f(A, 1, 5, 6) = { 5, 3 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(1), 5, operation_history_id_type(6)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); // f(A, 1, 5, 5) = { 5, 3 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(1), 5, operation_history_id_type(5)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); // f(A, 1, 5, 4) = { 3 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(1), 5, operation_history_id_type(4)); - BOOST_CHECK_EQUAL(histories.size(), 1u); + BOOST_REQUIRE_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); // f(A, 1, 5, 3) = { 3 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(1), 5, operation_history_id_type(3)); - BOOST_CHECK_EQUAL(histories.size(), 1u); + BOOST_REQUIRE_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); // f(A, 1, 5, 2) = { } @@ -344,67 +344,67 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { // f(A, 1, 5, 0) = { 5, 3 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(1), 5, operation_history_id_type(0)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); // f(A, 0, 3, 9) = { 5, 3, 1 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 3, operation_history_id_type(9)); - BOOST_CHECK_EQUAL(histories.size(), 3u); + BOOST_REQUIRE_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); // f(A, 0, 3, 6) = { 5, 3, 1 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 3, operation_history_id_type(6)); - BOOST_CHECK_EQUAL(histories.size(), 3u); + BOOST_REQUIRE_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); // f(A, 0, 3, 5) = { 5, 3, 1 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 3, operation_history_id_type(5)); - BOOST_CHECK_EQUAL(histories.size(), 3u); + BOOST_REQUIRE_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); // f(A, 0, 3, 4) = { 3, 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 3, operation_history_id_type(4)); - BOOST_CHECK_EQUAL(histories.size(), 3u); + BOOST_REQUIRE_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u); // f(A, 0, 3, 3) = { 3, 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 3, operation_history_id_type(3)); - BOOST_CHECK_EQUAL(histories.size(), 3u); + BOOST_REQUIRE_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u); // f(A, 0, 3, 2) = { 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 3, operation_history_id_type(2)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u); // f(A, 0, 3, 1) = { 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 3, operation_history_id_type(1)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u); // f(A, 0, 3, 0) = { 5, 3, 1 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 3, operation_history_id_type()); - BOOST_CHECK_EQUAL(histories.size(), 3u); + BOOST_REQUIRE_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); // f(B, 0, 4, 9) = { 6, 4, 2, 1 } histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type(9)); - BOOST_CHECK_EQUAL(histories.size(), 4u); + BOOST_REQUIRE_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 2u); @@ -412,7 +412,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { // f(B, 0, 4, 6) = { 6, 4, 2, 1 } histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type(6)); - BOOST_CHECK_EQUAL(histories.size(), 4u); + BOOST_REQUIRE_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 2u); @@ -420,38 +420,38 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { // f(B, 0, 4, 5) = { 4, 2, 1 } histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type(5)); - BOOST_CHECK_EQUAL(histories.size(), 3u); + BOOST_REQUIRE_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 2u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); // f(B, 0, 4, 4) = { 4, 2, 1 } histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type(4)); - BOOST_CHECK_EQUAL(histories.size(), 3u); + BOOST_REQUIRE_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 2u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); // f(B, 0, 4, 3) = { 2, 1 } histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type(3)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 2u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); // f(B, 0, 4, 2) = { 2, 1 } histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type(2)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 2u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); // f(B, 0, 4, 1) = { 1 } histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type(1)); - BOOST_CHECK_EQUAL(histories.size(), 1u); + BOOST_REQUIRE_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u); // f(B, 0, 4, 0) = { 6, 4, 2, 1 } histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type()); - BOOST_CHECK_EQUAL(histories.size(), 4u); + BOOST_REQUIRE_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 2u); @@ -459,24 +459,24 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { // f(B, 2, 4, 9) = { 6, 4 } histories = hist_api.get_account_history("dan", operation_history_id_type(2), 4, operation_history_id_type(9)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); // f(B, 2, 4, 6) = { 6, 4 } histories = hist_api.get_account_history("dan", operation_history_id_type(2), 4, operation_history_id_type(6)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); // f(B, 2, 4, 5) = { 4 } histories = hist_api.get_account_history("dan", operation_history_id_type(2), 4, operation_history_id_type(5)); - BOOST_CHECK_EQUAL(histories.size(), 1u); + BOOST_REQUIRE_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u); // f(B, 2, 4, 4) = { 4 } histories = hist_api.get_account_history("dan", operation_history_id_type(2), 4, operation_history_id_type(4)); - BOOST_CHECK_EQUAL(histories.size(), 1u); + BOOST_REQUIRE_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u); // f(B, 2, 4, 3) = { } @@ -493,7 +493,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { // f(B, 2, 4, 0) = { 6, 4 } histories = hist_api.get_account_history("dan", operation_history_id_type(2), 4, operation_history_id_type(0)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); @@ -524,7 +524,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { // f(A, 0, 10, 0) = { 7, 5, 3, 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(0), 10, operation_history_id_type(0)); - BOOST_CHECK_EQUAL(histories.size(), 5u); + BOOST_REQUIRE_EQUAL(histories.size(), 5u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 7u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 3u); From be285dc28c6452228b8698b0e7005ceb592bdcba Mon Sep 17 00:00:00 2001 From: Abit Date: Sat, 6 Mar 2021 04:44:17 +0100 Subject: [PATCH 028/147] Require successful deletion in es_test --- tests/elasticsearch/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/elasticsearch/main.cpp b/tests/elasticsearch/main.cpp index 96efef7358..58ea00c07c 100644 --- a/tests/elasticsearch/main.cpp +++ b/tests/elasticsearch/main.cpp @@ -61,6 +61,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_account_history) { auto delete_account_history = graphene::utilities::deleteAll(es); fc::usleep(ES_WAIT_TIME); // this is because index.refresh_interval, nothing to worry + BOOST_REQUIRE(delete_account_history); // require successful deletion if(delete_account_history) { // all records deleted //account_id_type() do 3 ops @@ -152,6 +153,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_objects) { generate_block(); fc::usleep(ES_WAIT_TIME); + BOOST_REQUIRE(delete_objects); // require successful deletion if(delete_objects) { // all records deleted // asset and bitasset @@ -200,9 +202,11 @@ BOOST_AUTO_TEST_CASE(elasticsearch_suite) { es.elasticsearch_url = "http://localhost:9200/"; es.index_prefix = es_index_prefix; auto delete_account_history = graphene::utilities::deleteAll(es); + BOOST_REQUIRE(delete_account_history); // require successful deletion fc::usleep(ES_WAIT_TIME); es.index_prefix = es_obj_index_prefix; auto delete_objects = graphene::utilities::deleteAll(es); + BOOST_REQUIRE(delete_objects); // require successful deletion fc::usleep(ES_WAIT_TIME); if(delete_account_history && delete_objects) { // all records deleted @@ -227,6 +231,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { es.index_prefix = es_index_prefix; auto delete_account_history = graphene::utilities::deleteAll(es); + BOOST_REQUIRE(delete_account_history); // require successful deletion generate_block(); fc::usleep(ES_WAIT_TIME); From 99e1453e16c66970dd3100b4c328ad16557d59f2 Mon Sep 17 00:00:00 2001 From: Abit Date: Sat, 6 Mar 2021 05:06:13 +0100 Subject: [PATCH 029/147] Wait even longer for the first writes in es_test --- tests/elasticsearch/main.cpp | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/tests/elasticsearch/main.cpp b/tests/elasticsearch/main.cpp index 58ea00c07c..901021b018 100644 --- a/tests/elasticsearch/main.cpp +++ b/tests/elasticsearch/main.cpp @@ -34,9 +34,11 @@ #include "../common/init_unit_test_suite.hpp" #ifdef NDEBUG - #define ES_WAIT_TIME (fc::milliseconds(2000)) + #define ES_FIRST_WAIT_TIME (fc::milliseconds(3000)) + #define ES_WAIT_TIME (fc::milliseconds(1000)) #else - #define ES_WAIT_TIME (fc::milliseconds(5000)) + #define ES_FIRST_WAIT_TIME (fc::milliseconds(6000)) + #define ES_WAIT_TIME (fc::milliseconds(3000)) #endif using namespace graphene::chain; @@ -55,11 +57,9 @@ BOOST_AUTO_TEST_CASE(elasticsearch_account_history) { es.curl = curl; es.elasticsearch_url = "http://localhost:9200/"; es.index_prefix = es_index_prefix; - //es.auth = "elastic:changeme"; // delete all first auto delete_account_history = graphene::utilities::deleteAll(es); - fc::usleep(ES_WAIT_TIME); // this is because index.refresh_interval, nothing to worry BOOST_REQUIRE(delete_account_history); // require successful deletion if(delete_account_history) { // all records deleted @@ -70,11 +70,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_account_history) { auto bob = create_account("bob"); generate_block(); - fc::usleep(ES_WAIT_TIME); - - // for later use - //int asset_create_op_id = operation::tag::value; - //int account_create_op_id = operation::tag::value; + fc::usleep(ES_FIRST_WAIT_TIME); // this is because index.refresh_interval, nothing to worry string query = "{ \"query\" : { \"bool\" : { \"must\" : [{\"match_all\": {}}] } } }"; es.endpoint = es.index_prefix + "*/data/_count"; @@ -145,13 +141,11 @@ BOOST_AUTO_TEST_CASE(elasticsearch_objects) { es.curl = curl; es.elasticsearch_url = "http://localhost:9200/"; es.index_prefix = es_obj_index_prefix; - //es.auth = "elastic:changeme"; // delete all first auto delete_objects = graphene::utilities::deleteAll(es); generate_block(); - fc::usleep(ES_WAIT_TIME); BOOST_REQUIRE(delete_objects); // require successful deletion if(delete_objects) { // all records deleted @@ -159,7 +153,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_objects) { // asset and bitasset create_bitasset("USD", account_id_type()); generate_block(); - fc::usleep(ES_WAIT_TIME); + fc::usleep(ES_FIRST_WAIT_TIME); string query = "{ \"query\" : { \"bool\" : { \"must\" : [{\"match_all\": {}}] } } }"; es.endpoint = es.index_prefix + "*/data/_count"; @@ -203,11 +197,13 @@ BOOST_AUTO_TEST_CASE(elasticsearch_suite) { es.index_prefix = es_index_prefix; auto delete_account_history = graphene::utilities::deleteAll(es); BOOST_REQUIRE(delete_account_history); // require successful deletion - fc::usleep(ES_WAIT_TIME); - es.index_prefix = es_obj_index_prefix; - auto delete_objects = graphene::utilities::deleteAll(es); + + graphene::utilities::ES es_obj; + es_obj.curl = curl; + es_obj.elasticsearch_url = "http://localhost:9200/"; + es_obj.index_prefix = es_obj_index_prefix; + auto delete_objects = graphene::utilities::deleteAll(es_obj); BOOST_REQUIRE(delete_objects); // require successful deletion - fc::usleep(ES_WAIT_TIME); if(delete_account_history && delete_objects) { // all records deleted @@ -234,7 +230,6 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { BOOST_REQUIRE(delete_account_history); // require successful deletion generate_block(); - fc::usleep(ES_WAIT_TIME); if(delete_account_history) { @@ -247,7 +242,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { create_bitasset("OIL", dan.id); // create op 6 generate_block(); - fc::usleep(ES_WAIT_TIME); + fc::usleep(ES_FIRST_WAIT_TIME); graphene::app::history_api hist_api(app); app.enable_plugin("elasticsearch"); From 8304df47427a6e0621fb5537e852b40948789659 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 6 Mar 2021 14:57:48 +0000 Subject: [PATCH 030/147] Tweak ES settings before test in Github Actions --- .github/workflows/build-and-test.ubuntu-debug.yml | 4 ++++ .github/workflows/build-and-test.ubuntu-release.yml | 4 ++++ .github/workflows/sonar-scan.yml | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/.github/workflows/build-and-test.ubuntu-debug.yml b/.github/workflows/build-and-test.ubuntu-debug.yml index 92eca92eb7..31826748e3 100644 --- a/.github/workflows/build-and-test.ubuntu-debug.yml +++ b/.github/workflows/build-and-test.ubuntu-debug.yml @@ -94,6 +94,10 @@ jobs: run: | _build/tests/app_test -l test_suite df -h + curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings \ + -d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }' + curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings \ + -d '{"index.blocks.read_only_allow_delete": null}' _build/tests/es_test -l test_suite df -h libraries/fc/tests/run-parallel-tests.sh _build/tests/chain_test -l test_suite diff --git a/.github/workflows/build-and-test.ubuntu-release.yml b/.github/workflows/build-and-test.ubuntu-release.yml index 9f30bf55ba..cb5480b70f 100644 --- a/.github/workflows/build-and-test.ubuntu-release.yml +++ b/.github/workflows/build-and-test.ubuntu-release.yml @@ -73,6 +73,10 @@ jobs: - name: Unit-Tests run: | _build/tests/app_test -l test_suite + curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings \ + -d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }' + curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings \ + -d '{"index.blocks.read_only_allow_delete": null}' _build/tests/es_test -l test_suite libraries/fc/tests/run-parallel-tests.sh _build/tests/chain_test -l test_suite _build/tests/cli_test -l test_suite diff --git a/.github/workflows/sonar-scan.yml b/.github/workflows/sonar-scan.yml index f1afc20f3c..d63213559d 100644 --- a/.github/workflows/sonar-scan.yml +++ b/.github/workflows/sonar-scan.yml @@ -118,6 +118,10 @@ jobs: run: | _build/tests/app_test -l test_suite df -h + curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings \ + -d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }' + curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings \ + -d '{"index.blocks.read_only_allow_delete": null}' _build/tests/es_test -l test_suite df -h libraries/fc/tests/run-parallel-tests.sh _build/tests/chain_test -l test_suite From 665c170ed72e3a5d09c139da59837307b673c0a9 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 6 Mar 2021 15:07:16 +0000 Subject: [PATCH 031/147] Move wait_for() from app_test/main to a hpp file --- tests/app/main.cpp | 13 +------------ tests/common/utils.hpp | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 tests/common/utils.hpp diff --git a/tests/app/main.cpp b/tests/app/main.cpp index 6afc8969a8..0d052b15d8 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -43,8 +43,8 @@ #include "../../libraries/app/application_impl.hxx" #include "../common/init_unit_test_suite.hpp" - #include "../common/genesis_file_util.hpp" +#include "../common/utils.hpp" uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP = 1431700000; // needed for compiling, not used @@ -54,17 +54,6 @@ namespace bpo = boost::program_options; namespace fc { extern std::unordered_map &get_logger_map(); extern std::unordered_map &get_appender_map(); - - /** Waits for F() to return true before max_duration has passed. - */ - template - static void wait_for( const fc::microseconds max_duration, const Functor&& f ) - { - const auto start = fc::time_point::now(); - while( !f() && fc::time_point::now() < start + max_duration ) - fc::usleep(fc::milliseconds(100)); - BOOST_REQUIRE( f() ); - } } BOOST_AUTO_TEST_CASE(load_configuration_options_test_config_logging_files_created) diff --git a/tests/common/utils.hpp b/tests/common/utils.hpp new file mode 100644 index 0000000000..b590331f64 --- /dev/null +++ b/tests/common/utils.hpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include + +namespace fc { + + /** Waits for F() to return true before max_duration has passed. + */ + template + static void wait_for( const fc::microseconds max_duration, const Functor&& f ) + { + const auto start = fc::time_point::now(); + while( !f() && fc::time_point::now() < start + max_duration ) + fc::usleep(fc::milliseconds(100)); + BOOST_REQUIRE( f() ); + } +} From 78d86ced220b2a1ad37355f94d8c9b4d84d5a9de Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 6 Mar 2021 16:10:34 +0000 Subject: [PATCH 032/147] Get ES URL from env (if exist) in es_test --- tests/app/main.cpp | 2 - tests/cli/main.cpp | 2 - tests/common/database_fixture.cpp | 54 ++++++++++++++++++--------- tests/common/init_unit_test_suite.hpp | 12 +++++- tests/elasticsearch/main.cpp | 12 +++--- 5 files changed, 54 insertions(+), 28 deletions(-) diff --git a/tests/app/main.cpp b/tests/app/main.cpp index 0d052b15d8..ba4b944819 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -46,8 +46,6 @@ #include "../common/genesis_file_util.hpp" #include "../common/utils.hpp" -uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP = 1431700000; // needed for compiling, not used - using namespace graphene; namespace bpo = boost::program_options; diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index c0f3396ee5..91c0af7cc6 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -62,8 +62,6 @@ #include "../common/init_unit_test_suite.hpp" -uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP = 1431700000; // needed for compiling, not used - /***** * Global Initialization for Windows * ( sets up Winsock stuf ) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index c70ed4cca1..afe12c365e 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -54,7 +54,8 @@ using namespace graphene::chain::test; -uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP = 1431700000; +extern uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP; +extern std::string GRAPHENE_TESTING_ES_URL; namespace graphene { namespace chain { @@ -292,14 +293,22 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) current_test_name == "elasticsearch_history_api") { auto esplugin = app.register_plugin(true); - options.insert(std::make_pair("elasticsearch-node-url", boost::program_options::variable_value(string("http://localhost:9200/"), false))); - options.insert(std::make_pair("elasticsearch-bulk-replay", boost::program_options::variable_value(uint32_t(2), false))); - options.insert(std::make_pair("elasticsearch-bulk-sync", boost::program_options::variable_value(uint32_t(2), false))); - options.insert(std::make_pair("elasticsearch-start-es-after-block", boost::program_options::variable_value(uint32_t(0), false))); - options.insert(std::make_pair("elasticsearch-visitor", boost::program_options::variable_value(false, false))); - options.insert(std::make_pair("elasticsearch-operation-object", boost::program_options::variable_value(true, false))); - options.insert(std::make_pair("elasticsearch-operation-string", boost::program_options::variable_value(true, false))); - options.insert(std::make_pair("elasticsearch-mode", boost::program_options::variable_value(uint16_t(2), false))); + options.insert(std::make_pair("elasticsearch-node-url", + boost::program_options::variable_value(GRAPHENE_TESTING_ES_URL, false))); + options.insert(std::make_pair("elasticsearch-bulk-replay", + boost::program_options::variable_value(uint32_t(2), false))); + options.insert(std::make_pair("elasticsearch-bulk-sync", + boost::program_options::variable_value(uint32_t(2), false))); + options.insert(std::make_pair("elasticsearch-start-es-after-block", + boost::program_options::variable_value(uint32_t(0), false))); + options.insert(std::make_pair("elasticsearch-visitor", + boost::program_options::variable_value(false, false))); + options.insert(std::make_pair("elasticsearch-operation-object", + boost::program_options::variable_value(true, false))); + options.insert(std::make_pair("elasticsearch-operation-string", + boost::program_options::variable_value(true, false))); + options.insert(std::make_pair("elasticsearch-mode", + boost::program_options::variable_value(uint16_t(2), false))); es_index_prefix = string("bitshares-") + fc::to_string(uint64_t(rand())) + "-"; BOOST_TEST_MESSAGE( string("ES index prefix is ") + es_index_prefix ); @@ -319,15 +328,24 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) if(current_test_name == "elasticsearch_objects" || current_test_name == "elasticsearch_suite") { auto esobjects_plugin = app.register_plugin(true); - options.insert(std::make_pair("es-objects-elasticsearch-url", boost::program_options::variable_value(string("http://localhost:9200/"), false))); - options.insert(std::make_pair("es-objects-bulk-replay", boost::program_options::variable_value(uint32_t(2), false))); - options.insert(std::make_pair("es-objects-bulk-sync", boost::program_options::variable_value(uint32_t(2), false))); - options.insert(std::make_pair("es-objects-proposals", boost::program_options::variable_value(true, false))); - options.insert(std::make_pair("es-objects-accounts", boost::program_options::variable_value(true, false))); - options.insert(std::make_pair("es-objects-assets", boost::program_options::variable_value(true, false))); - options.insert(std::make_pair("es-objects-balances", boost::program_options::variable_value(true, false))); - options.insert(std::make_pair("es-objects-limit-orders", boost::program_options::variable_value(true, false))); - options.insert(std::make_pair("es-objects-asset-bitasset", boost::program_options::variable_value(true, false))); + options.insert(std::make_pair("es-objects-elasticsearch-url", + boost::program_options::variable_value(GRAPHENE_TESTING_ES_URL, false))); + options.insert(std::make_pair("es-objects-bulk-replay", + boost::program_options::variable_value(uint32_t(2), false))); + options.insert(std::make_pair("es-objects-bulk-sync", + boost::program_options::variable_value(uint32_t(2), false))); + options.insert(std::make_pair("es-objects-proposals", + boost::program_options::variable_value(true, false))); + options.insert(std::make_pair("es-objects-accounts", + boost::program_options::variable_value(true, false))); + options.insert(std::make_pair("es-objects-assets", + boost::program_options::variable_value(true, false))); + options.insert(std::make_pair("es-objects-balances", + boost::program_options::variable_value(true, false))); + options.insert(std::make_pair("es-objects-limit-orders", + boost::program_options::variable_value(true, false))); + options.insert(std::make_pair("es-objects-asset-bitasset", + boost::program_options::variable_value(true, false))); es_obj_index_prefix = string("objects-") + fc::to_string(uint64_t(rand())) + "-"; BOOST_TEST_MESSAGE( string("ES_OBJ index prefix is ") + es_obj_index_prefix ); diff --git a/tests/common/init_unit_test_suite.hpp b/tests/common/init_unit_test_suite.hpp index 0c3e9f7644..3732ba25c7 100644 --- a/tests/common/init_unit_test_suite.hpp +++ b/tests/common/init_unit_test_suite.hpp @@ -25,8 +25,10 @@ #include #include #include +#include -extern uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP; +uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP = 1431700000; +std::string GRAPHENE_TESTING_ES_URL = "http://127.0.0.1:9200"; boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { const auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count(); @@ -38,5 +40,13 @@ boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { GRAPHENE_TESTING_GENESIS_TIMESTAMP = std::stoul( genesis_timestamp_str ); } std::cout << "GRAPHENE_TESTING_GENESIS_TIMESTAMP is " << GRAPHENE_TESTING_GENESIS_TIMESTAMP << std::endl; + const char* env_es_url = getenv("GRAPHENE_TESTING_ES_URL"); + if( env_es_url != nullptr ) + { + std::string tmp_es_url( env_es_url ); + if( tmp_es_url.substr(0, 7) == "http://" || tmp_es_url.substr(0, 8) == "https://" ) + GRAPHENE_TESTING_ES_URL = tmp_es_url; + } + std::cout << "GRAPHENE_TESTING_ES_URL is " << GRAPHENE_TESTING_ES_URL << std::endl; return nullptr; } diff --git a/tests/elasticsearch/main.cpp b/tests/elasticsearch/main.cpp index 901021b018..c35bd870da 100644 --- a/tests/elasticsearch/main.cpp +++ b/tests/elasticsearch/main.cpp @@ -45,6 +45,8 @@ using namespace graphene::chain; using namespace graphene::chain::test; using namespace graphene::app; +extern std::string GRAPHENE_TESTING_ES_URL; + BOOST_FIXTURE_TEST_SUITE( elasticsearch_tests, database_fixture ) BOOST_AUTO_TEST_CASE(elasticsearch_account_history) { @@ -55,7 +57,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_account_history) { graphene::utilities::ES es; es.curl = curl; - es.elasticsearch_url = "http://localhost:9200/"; + es.elasticsearch_url = GRAPHENE_TESTING_ES_URL; es.index_prefix = es_index_prefix; // delete all first @@ -139,7 +141,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_objects) { graphene::utilities::ES es; es.curl = curl; - es.elasticsearch_url = "http://localhost:9200/"; + es.elasticsearch_url = GRAPHENE_TESTING_ES_URL; es.index_prefix = es_obj_index_prefix; // delete all first @@ -193,14 +195,14 @@ BOOST_AUTO_TEST_CASE(elasticsearch_suite) { graphene::utilities::ES es; es.curl = curl; - es.elasticsearch_url = "http://localhost:9200/"; + es.elasticsearch_url = GRAPHENE_TESTING_ES_URL; es.index_prefix = es_index_prefix; auto delete_account_history = graphene::utilities::deleteAll(es); BOOST_REQUIRE(delete_account_history); // require successful deletion graphene::utilities::ES es_obj; es_obj.curl = curl; - es_obj.elasticsearch_url = "http://localhost:9200/"; + es_obj.elasticsearch_url = GRAPHENE_TESTING_ES_URL; es_obj.index_prefix = es_obj_index_prefix; auto delete_objects = graphene::utilities::deleteAll(es_obj); BOOST_REQUIRE(delete_objects); // require successful deletion @@ -223,7 +225,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { graphene::utilities::ES es; es.curl = curl; - es.elasticsearch_url = "http://localhost:9200/"; + es.elasticsearch_url = GRAPHENE_TESTING_ES_URL; es.index_prefix = es_index_prefix; auto delete_account_history = graphene::utilities::deleteAll(es); From c24a4275a06f34b96574ace379af2e0e0f0dbb8f Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 6 Mar 2021 16:29:04 +0000 Subject: [PATCH 033/147] Replace sleep() with wait_for() in es_test --- tests/elasticsearch/main.cpp | 85 +++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/tests/elasticsearch/main.cpp b/tests/elasticsearch/main.cpp index c35bd870da..eb254c559c 100644 --- a/tests/elasticsearch/main.cpp +++ b/tests/elasticsearch/main.cpp @@ -32,14 +32,9 @@ #include "../common/database_fixture.hpp" #include "../common/init_unit_test_suite.hpp" +#include "../common/utils.hpp" -#ifdef NDEBUG - #define ES_FIRST_WAIT_TIME (fc::milliseconds(3000)) - #define ES_WAIT_TIME (fc::milliseconds(1000)) -#else - #define ES_FIRST_WAIT_TIME (fc::milliseconds(6000)) - #define ES_WAIT_TIME (fc::milliseconds(3000)) -#endif +#define ES_WAIT_TIME (fc::milliseconds(10000)) using namespace graphene::chain; using namespace graphene::chain::test; @@ -72,16 +67,21 @@ BOOST_AUTO_TEST_CASE(elasticsearch_account_history) { auto bob = create_account("bob"); generate_block(); - fc::usleep(ES_FIRST_WAIT_TIME); // this is because index.refresh_interval, nothing to worry string query = "{ \"query\" : { \"bool\" : { \"must\" : [{\"match_all\": {}}] } } }"; es.endpoint = es.index_prefix + "*/data/_count"; es.query = query; - auto res = graphene::utilities::simpleQuery(es); - variant j = fc::json::from_string(res); - auto total = j["count"].as_string(); - BOOST_CHECK_EQUAL(total, "5"); + string res; + variant j; + string total; + + fc::wait_for( ES_WAIT_TIME, [&]() { + res = graphene::utilities::simpleQuery(es); + j = fc::json::from_string(res); + total = j["count"].as_string(); + return (total == "5"); + }); es.endpoint = es.index_prefix + "*/data/_search"; res = graphene::utilities::simpleQuery(es); @@ -93,14 +93,14 @@ BOOST_AUTO_TEST_CASE(elasticsearch_account_history) { auto willie = create_account("willie"); generate_block(); - fc::usleep(ES_WAIT_TIME); // index.refresh_interval - es.endpoint = es.index_prefix + "*/data/_count"; - res = graphene::utilities::simpleQuery(es); - j = fc::json::from_string(res); - total = j["count"].as_string(); - BOOST_CHECK_EQUAL(total, "7"); + fc::wait_for( ES_WAIT_TIME, [&]() { + res = graphene::utilities::simpleQuery(es); + j = fc::json::from_string(res); + total = j["count"].as_string(); + return (total == "7"); + }); // do some transfers in 1 block transfer(account_id_type()(db), bob, asset(100)); @@ -108,13 +108,13 @@ BOOST_AUTO_TEST_CASE(elasticsearch_account_history) { transfer(account_id_type()(db), bob, asset(300)); generate_block(); - fc::usleep(ES_WAIT_TIME); // index.refresh_interval - - res = graphene::utilities::simpleQuery(es); - j = fc::json::from_string(res); - total = j["count"].as_string(); - BOOST_CHECK_EQUAL(total, "13"); + fc::wait_for( ES_WAIT_TIME, [&]() { + res = graphene::utilities::simpleQuery(es); + j = fc::json::from_string(res); + total = j["count"].as_string(); + return (total == "13"); + }); // check the visitor data auto block_date = db.head_block_time(); @@ -146,25 +146,30 @@ BOOST_AUTO_TEST_CASE(elasticsearch_objects) { // delete all first auto delete_objects = graphene::utilities::deleteAll(es); + BOOST_REQUIRE(delete_objects); // require successful deletion generate_block(); - BOOST_REQUIRE(delete_objects); // require successful deletion if(delete_objects) { // all records deleted // asset and bitasset create_bitasset("USD", account_id_type()); generate_block(); - fc::usleep(ES_FIRST_WAIT_TIME); string query = "{ \"query\" : { \"bool\" : { \"must\" : [{\"match_all\": {}}] } } }"; es.endpoint = es.index_prefix + "*/data/_count"; es.query = query; - auto res = graphene::utilities::simpleQuery(es); - variant j = fc::json::from_string(res); - auto total = j["count"].as_string(); - BOOST_CHECK_EQUAL(total, "2"); + string res; + variant j; + string total; + + fc::wait_for( ES_WAIT_TIME, [&]() { + res = graphene::utilities::simpleQuery(es); + j = fc::json::from_string(res); + total = j["count"].as_string(); + return (total == "2"); + }); es.endpoint = es.index_prefix + "asset/data/_search"; res = graphene::utilities::simpleQuery(es); @@ -244,14 +249,19 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { create_bitasset("OIL", dan.id); // create op 6 generate_block(); - fc::usleep(ES_FIRST_WAIT_TIME); graphene::app::history_api hist_api(app); app.enable_plugin("elasticsearch"); // f(A, 0, 4, 9) = { 5, 3, 1, 0 } - auto histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 4, operation_history_id_type(9)); - + auto histories = hist_api.get_account_history( + "1.2.0", operation_history_id_type(), 4, operation_history_id_type(9)); + + fc::wait_for( ES_WAIT_TIME, [&]() { + histories = hist_api.get_account_history( + "1.2.0", operation_history_id_type(), 4, operation_history_id_type(9)); + return (histories.size() == 4u); + }); BOOST_REQUIRE_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); @@ -513,11 +523,14 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { create_account("alice"); generate_block(); - fc::usleep(ES_WAIT_TIME); // f(C, 0, 4, 10) = { 7 } - histories = hist_api.get_account_history("alice", operation_history_id_type(0), 4, operation_history_id_type(10)); - BOOST_CHECK_EQUAL(histories.size(), 1u); + fc::wait_for( ES_WAIT_TIME, [&]() { + histories = hist_api.get_account_history( + "alice", operation_history_id_type(0), 4, operation_history_id_type(10)); + return (histories.size() == 1u); + }); + BOOST_REQUIRE_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 7u); // f(C, 8, 4, 10) = { } From 7772a01395a808940282eefe383037e8b20210fd Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 6 Mar 2021 17:09:18 +0000 Subject: [PATCH 034/147] Cleanup ES data after testing --- tests/common/database_fixture.cpp | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index afe12c365e..a5f3e7b40d 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -419,6 +419,41 @@ database_fixture::~database_fixture() } catch (...) { BOOST_FAIL( "Uncaught exception in ~database_fixture" ); } + + // cleanup data in ES + if( !es_index_prefix.empty() || !es_obj_index_prefix.empty() ) + { + CURL *curl; // curl handler + curl = curl_easy_init(); + curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); + + graphene::utilities::ES es; + es.curl = curl; + es.elasticsearch_url = GRAPHENE_TESTING_ES_URL; + + if( !es_index_prefix.empty() ) + { + es.index_prefix = es_index_prefix; + // delete all + try { + graphene::utilities::deleteAll(es); + } catch (...) { + // nothing to do + } + } + + if( !es_obj_index_prefix.empty() ) + { + es.index_prefix = es_obj_index_prefix; + // delete all + try { + graphene::utilities::deleteAll(es); + } catch (...) { + // nothing to do + } + } + } + } void database_fixture::vote_for_committee_and_witnesses(uint16_t num_committee, uint16_t num_witness) From c54db3ad3b92e43c1674e56536f5ece2130f300e Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 6 Mar 2021 17:34:29 +0000 Subject: [PATCH 035/147] Fix ES URL in tests, and remove unnecessary tweak --- .github/workflows/build-and-test.ubuntu-debug.yml | 2 -- .github/workflows/build-and-test.ubuntu-release.yml | 2 -- .github/workflows/sonar-scan.yml | 2 -- tests/common/init_unit_test_suite.hpp | 2 +- 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/build-and-test.ubuntu-debug.yml b/.github/workflows/build-and-test.ubuntu-debug.yml index 31826748e3..d7caf3c271 100644 --- a/.github/workflows/build-and-test.ubuntu-debug.yml +++ b/.github/workflows/build-and-test.ubuntu-debug.yml @@ -96,8 +96,6 @@ jobs: df -h curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings \ -d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }' - curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings \ - -d '{"index.blocks.read_only_allow_delete": null}' _build/tests/es_test -l test_suite df -h libraries/fc/tests/run-parallel-tests.sh _build/tests/chain_test -l test_suite diff --git a/.github/workflows/build-and-test.ubuntu-release.yml b/.github/workflows/build-and-test.ubuntu-release.yml index cb5480b70f..8213775750 100644 --- a/.github/workflows/build-and-test.ubuntu-release.yml +++ b/.github/workflows/build-and-test.ubuntu-release.yml @@ -75,8 +75,6 @@ jobs: _build/tests/app_test -l test_suite curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings \ -d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }' - curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings \ - -d '{"index.blocks.read_only_allow_delete": null}' _build/tests/es_test -l test_suite libraries/fc/tests/run-parallel-tests.sh _build/tests/chain_test -l test_suite _build/tests/cli_test -l test_suite diff --git a/.github/workflows/sonar-scan.yml b/.github/workflows/sonar-scan.yml index d63213559d..9803b0030b 100644 --- a/.github/workflows/sonar-scan.yml +++ b/.github/workflows/sonar-scan.yml @@ -120,8 +120,6 @@ jobs: df -h curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings \ -d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }' - curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings \ - -d '{"index.blocks.read_only_allow_delete": null}' _build/tests/es_test -l test_suite df -h libraries/fc/tests/run-parallel-tests.sh _build/tests/chain_test -l test_suite diff --git a/tests/common/init_unit_test_suite.hpp b/tests/common/init_unit_test_suite.hpp index 3732ba25c7..472d1e7f14 100644 --- a/tests/common/init_unit_test_suite.hpp +++ b/tests/common/init_unit_test_suite.hpp @@ -28,7 +28,7 @@ #include uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP = 1431700000; -std::string GRAPHENE_TESTING_ES_URL = "http://127.0.0.1:9200"; +std::string GRAPHENE_TESTING_ES_URL = "http://127.0.0.1:9200/"; boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { const auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count(); From d8c91310f84a07ee89dc960e6526c7034d0b3e97 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 6 Mar 2021 17:39:18 +0000 Subject: [PATCH 036/147] Output a new line before es_test in Github Actions --- .github/workflows/build-and-test.ubuntu-debug.yml | 1 + .github/workflows/build-and-test.ubuntu-release.yml | 1 + .github/workflows/sonar-scan.yml | 1 + 3 files changed, 3 insertions(+) diff --git a/.github/workflows/build-and-test.ubuntu-debug.yml b/.github/workflows/build-and-test.ubuntu-debug.yml index d7caf3c271..3ca8a0d347 100644 --- a/.github/workflows/build-and-test.ubuntu-debug.yml +++ b/.github/workflows/build-and-test.ubuntu-debug.yml @@ -96,6 +96,7 @@ jobs: df -h curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings \ -d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }' + echo _build/tests/es_test -l test_suite df -h libraries/fc/tests/run-parallel-tests.sh _build/tests/chain_test -l test_suite diff --git a/.github/workflows/build-and-test.ubuntu-release.yml b/.github/workflows/build-and-test.ubuntu-release.yml index 8213775750..5f5be7fd12 100644 --- a/.github/workflows/build-and-test.ubuntu-release.yml +++ b/.github/workflows/build-and-test.ubuntu-release.yml @@ -75,6 +75,7 @@ jobs: _build/tests/app_test -l test_suite curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings \ -d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }' + echo _build/tests/es_test -l test_suite libraries/fc/tests/run-parallel-tests.sh _build/tests/chain_test -l test_suite _build/tests/cli_test -l test_suite diff --git a/.github/workflows/sonar-scan.yml b/.github/workflows/sonar-scan.yml index 9803b0030b..f9e07e8c0c 100644 --- a/.github/workflows/sonar-scan.yml +++ b/.github/workflows/sonar-scan.yml @@ -120,6 +120,7 @@ jobs: df -h curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings \ -d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }' + echo _build/tests/es_test -l test_suite df -h libraries/fc/tests/run-parallel-tests.sh _build/tests/chain_test -l test_suite From bf84fc69fa9f24733a30d8b021489edcbb112f93 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 6 Mar 2021 00:21:59 +0000 Subject: [PATCH 037/147] Avoid potential object slicing at trx_message init --- libraries/app/application.cpp | 4 ++-- libraries/net/include/graphene/net/core_messages.hpp | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 3a388befcd..b28fc7bb30 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -598,9 +598,9 @@ bool application_impl::handle_block(const graphene::net::block_message& blk_msg, // during sync, it is unlikely that we'll see any old contained_transaction_message_ids.reserve( contained_transaction_message_ids.size() + blk_msg.block.transactions.size() ); - for (const processed_transaction& transaction : blk_msg.block.transactions) + for (const processed_transaction& ptrx : blk_msg.block.transactions) { - graphene::net::trx_message transaction_message(transaction); + graphene::net::trx_message transaction_message(ptrx); contained_transaction_message_ids.emplace_back(graphene::net::message(transaction_message).id()); } } diff --git a/libraries/net/include/graphene/net/core_messages.hpp b/libraries/net/include/graphene/net/core_messages.hpp index 88d563e683..27607832de 100644 --- a/libraries/net/include/graphene/net/core_messages.hpp +++ b/libraries/net/include/graphene/net/core_messages.hpp @@ -96,8 +96,11 @@ namespace graphene { namespace net { graphene::protocol::precomputable_transaction trx; trx_message() {} - trx_message(graphene::protocol::signed_transaction transaction) : - trx(std::move(transaction)) + trx_message(const graphene::protocol::signed_transaction& signed_trx) : + trx(signed_trx) + {} + trx_message(graphene::protocol::signed_transaction&& signed_trx) : + trx(std::move(signed_trx)) {} }; From 8f013a16c59520b5904f98036f72abba8fa58936 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 6 Mar 2021 00:36:37 +0000 Subject: [PATCH 038/147] Change get_transaction_hex_without_sig param type Fixes an object slicing warning. --- libraries/app/database_api.cpp | 6 +++--- libraries/app/database_api_impl.hxx | 2 +- libraries/app/include/graphene/app/database_api.hpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 45b9445fd2..16e0ae97c4 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -2409,15 +2409,15 @@ std::string database_api_impl::get_transaction_hex(const signed_transaction& trx } std::string database_api::get_transaction_hex_without_sig( - const signed_transaction &trx) const + const transaction &trx) const { return my->get_transaction_hex_without_sig(trx); } std::string database_api_impl::get_transaction_hex_without_sig( - const signed_transaction &trx) const + const transaction &trx) const { - return fc::to_hex(fc::raw::pack(static_cast(trx))); + return fc::to_hex(fc::raw::pack(trx)); } set database_api::get_required_signatures( const signed_transaction& trx, diff --git a/libraries/app/database_api_impl.hxx b/libraries/app/database_api_impl.hxx index 36379ae8de..4aff5ccb33 100644 --- a/libraries/app/database_api_impl.hxx +++ b/libraries/app/database_api_impl.hxx @@ -203,7 +203,7 @@ class database_api_impl : public std::enable_shared_from_this // Authority / validation std::string get_transaction_hex(const signed_transaction& trx)const; - std::string get_transaction_hex_without_sig(const signed_transaction& trx)const; + std::string get_transaction_hex_without_sig(const transaction& trx)const; set get_required_signatures( const signed_transaction& trx, const flat_set& available_keys )const; diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index 86b44e3cb9..dff253c99b 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -915,7 +915,7 @@ class database_api * @param trx a transaction to get hexdump from * @return the hexdump of the transaction without the signatures */ - std::string get_transaction_hex_without_sig( const signed_transaction &trx ) const; + std::string get_transaction_hex_without_sig( const transaction &trx ) const; /** * This API will take a partially signed transaction and a set of public keys that the owner From 921bf82273e40319f58e0126bd2d04bb7ae38cab Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 6 Mar 2021 00:54:23 +0000 Subject: [PATCH 039/147] Fix object slicing warnings in wallet*.cpp --- libraries/wallet/wallet_asset.cpp | 4 ++-- libraries/wallet/wallet_results.cpp | 8 ++++---- libraries/wallet/wallet_transfer.cpp | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libraries/wallet/wallet_asset.cpp b/libraries/wallet/wallet_asset.cpp index 36bef268da..a73755750c 100644 --- a/libraries/wallet/wallet_asset.cpp +++ b/libraries/wallet/wallet_asset.cpp @@ -225,7 +225,7 @@ namespace graphene { namespace wallet { namespace detail { optional asset_to_fund = find_asset(symbol); if (!asset_to_fund) FC_THROW("No asset with that symbol exists!"); - asset_object core_asset = get_asset(asset_id_type()); + auto core_asset = get_asset(asset_id_type()); asset_fund_fee_pool_operation fund_op; fund_op.from_account = from_account.id; @@ -246,7 +246,7 @@ namespace graphene { namespace wallet { namespace detail { optional asset_pool_to_claim = find_asset(symbol); if (!asset_pool_to_claim) FC_THROW("No asset with that symbol exists!"); - asset_object core_asset = get_asset(asset_id_type()); + auto core_asset = get_asset(asset_id_type()); asset_claim_pool_operation claim_op; claim_op.issuer = asset_pool_to_claim->issuer; diff --git a/libraries/wallet/wallet_results.cpp b/libraries/wallet/wallet_results.cpp index 6dd31a3dcb..f3f4df221a 100644 --- a/libraries/wallet/wallet_results.cpp +++ b/libraries/wallet/wallet_results.cpp @@ -138,7 +138,7 @@ std::map> wallet_a ss << "\n"; for( const auto& out : r.outputs ) { - asset_object a = get_asset( out.decrypted_memo.amount.asset_id ); + auto a = get_asset( out.decrypted_memo.amount.asset_id ); ss << a.amount_to_pretty_string( out.decrypted_memo.amount ) << " to " << out.label << "\n\t receipt: " << out.confirmation_receipt << "\n\n"; } @@ -152,7 +152,7 @@ std::map> wallet_a ss << "\n"; for( const auto& out : r.outputs ) { - asset_object a = get_asset( out.decrypted_memo.amount.asset_id ); + auto a = get_asset( out.decrypted_memo.amount.asset_id ); ss << a.amount_to_pretty_string( out.decrypted_memo.amount ) << " to " << out.label << "\n\t receipt: " << out.confirmation_receipt << "\n\n"; } @@ -162,7 +162,7 @@ std::map> wallet_a { auto r = result.as( GRAPHENE_MAX_NESTED_OBJECTS ); std::stringstream ss; - asset_object as = get_asset( r.amount.asset_id ); + auto as = get_asset( r.amount.asset_id ); ss << as.amount_to_pretty_string( r.amount ) << " " << r.from_label << " => " << r.to_label << " " << r.memo <<"\n"; return ss.str(); @@ -176,7 +176,7 @@ std::map> wallet_a ss << "====================================================================================\n"; for( auto& r : records ) { - asset_object as = get_asset( r.amount.asset_id ); + auto as = get_asset( r.amount.asset_id ); ss << fc::get_approximate_relative_time_string( r.date ) << " " << as.amount_to_pretty_string( r.amount ) << " " << r.from_label << " => " << r.to_label << " " << r.memo <<"\n"; diff --git a/libraries/wallet/wallet_transfer.cpp b/libraries/wallet/wallet_transfer.cpp index 57a8ae4960..56cd7c75c9 100644 --- a/libraries/wallet/wallet_transfer.cpp +++ b/libraries/wallet/wallet_transfer.cpp @@ -210,9 +210,9 @@ namespace graphene { namespace wallet { namespace detail { string asset_symbol, string amount_of_collateral, bool broadcast ) { account_object seller = get_account(seller_name); - asset_object mia = get_asset(asset_symbol); + auto mia = get_asset(asset_symbol); FC_ASSERT(mia.is_market_issued()); - asset_object collateral = get_asset(get_object(*mia.bitasset_data_id).options.short_backing_asset); + auto collateral = get_asset(get_object(*mia.bitasset_data_id).options.short_backing_asset); call_order_update_operation op; op.funding_account = seller.id; @@ -232,9 +232,9 @@ namespace graphene { namespace wallet { namespace detail { call_order_update_operation::extensions_type extensions, bool broadcast ) { account_object seller = get_account(seller_name); - asset_object mia = get_asset(asset_symbol); + auto mia = get_asset(asset_symbol); FC_ASSERT(mia.is_market_issued()); - asset_object collateral = get_asset(get_object(*mia.bitasset_data_id).options.short_backing_asset); + auto collateral = get_asset(get_object(*mia.bitasset_data_id).options.short_backing_asset); call_order_update_operation op; op.funding_account = seller.id; @@ -268,7 +268,7 @@ namespace graphene { namespace wallet { namespace detail { signed_transaction wallet_api_impl::withdraw_vesting( string witness_name, string amount, string asset_symbol, bool broadcast ) { try { - asset_object asset_obj = get_asset( asset_symbol ); + auto asset_obj = get_asset( asset_symbol ); fc::optional vbid = maybe_id(witness_name); if( !vbid ) { From bd0d891f8fa2f39bb0306532bc8181772b3ff53d Mon Sep 17 00:00:00 2001 From: Abit Date: Sat, 6 Mar 2021 05:43:33 +0100 Subject: [PATCH 040/147] Fix duplicate code in CLI borrow_asset command by calling borrow_asset_ext(...) directly. --- libraries/wallet/wallet_transfer.cpp | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/libraries/wallet/wallet_transfer.cpp b/libraries/wallet/wallet_transfer.cpp index 56cd7c75c9..524764500e 100644 --- a/libraries/wallet/wallet_transfer.cpp +++ b/libraries/wallet/wallet_transfer.cpp @@ -209,22 +209,8 @@ namespace graphene { namespace wallet { namespace detail { signed_transaction wallet_api_impl::borrow_asset(string seller_name, string amount_to_borrow, string asset_symbol, string amount_of_collateral, bool broadcast ) { - account_object seller = get_account(seller_name); - auto mia = get_asset(asset_symbol); - FC_ASSERT(mia.is_market_issued()); - auto collateral = get_asset(get_object(*mia.bitasset_data_id).options.short_backing_asset); - - call_order_update_operation op; - op.funding_account = seller.id; - op.delta_debt = mia.amount_from_string(amount_to_borrow); - op.delta_collateral = collateral.amount_from_string(amount_of_collateral); - - signed_transaction trx; - trx.operations = {op}; - set_operation_fees( trx, _remote_db->get_global_properties().parameters.get_current_fees()); - trx.validate(); - - return sign_transaction(trx, broadcast); + return borrow_asset_ext( seller_name, amount_to_borrow, asset_symbol, amount_of_collateral, + {}, broadcast ); } signed_transaction wallet_api_impl::borrow_asset_ext( string seller_name, string amount_to_borrow, From fbb4893c4ecc9dfed911d0df803cb4638e590ef3 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 6 Mar 2021 13:09:03 -0500 Subject: [PATCH 041/147] Fix code smells in net/core_messages.hpp --- libraries/net/include/graphene/net/core_messages.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/net/include/graphene/net/core_messages.hpp b/libraries/net/include/graphene/net/core_messages.hpp index 27607832de..4e686e4513 100644 --- a/libraries/net/include/graphene/net/core_messages.hpp +++ b/libraries/net/include/graphene/net/core_messages.hpp @@ -95,12 +95,12 @@ namespace graphene { namespace net { static const core_message_type_enum type; graphene::protocol::precomputable_transaction trx; - trx_message() {} - trx_message(const graphene::protocol::signed_transaction& signed_trx) : + trx_message() = default; + explicit trx_message(const graphene::protocol::signed_transaction& signed_trx) : trx(signed_trx) {} - trx_message(graphene::protocol::signed_transaction&& signed_trx) : - trx(std::move(signed_trx)) + explicit trx_message(graphene::protocol::signed_transaction&& signed_trx) : + trx(signed_trx) {} }; From 988c19f8efb76816d0268c4568b317ab9ba39a5d Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 6 Mar 2021 13:23:10 -0500 Subject: [PATCH 042/147] Fix duplicate code in wallet_results.cpp --- libraries/wallet/wallet_results.cpp | 61 +++++++---------------------- 1 file changed, 14 insertions(+), 47 deletions(-) diff --git a/libraries/wallet/wallet_results.cpp b/libraries/wallet/wallet_results.cpp index f3f4df221a..8912d0354c 100644 --- a/libraries/wallet/wallet_results.cpp +++ b/libraries/wallet/wallet_results.cpp @@ -30,6 +30,7 @@ namespace graphene { namespace wallet { namespace detail { std::map> wallet_api_impl::get_result_formatters() const { std::map > m; + m["help"] = [](variant result, const fc::variants& a) { return result.get_string(); @@ -40,7 +41,7 @@ std::map> wallet_a return result.get_string(); }; - m["get_account_history"] = [this](variant result, const fc::variants& a) + auto format_account_history = [this](variant result, const fc::variants& a) { auto r = result.as>( GRAPHENE_MAX_NESTED_OBJECTS ); std::stringstream ss; @@ -58,24 +59,9 @@ std::map> wallet_a return ss.str(); }; - m["get_relative_account_history"] = [this](variant result, const fc::variants& a) - { - auto r = result.as>( GRAPHENE_MAX_NESTED_OBJECTS ); - std::stringstream ss; - for( operation_detail& d : r ) - { - operation_history_object& i = d.op; - auto b = _remote_db->get_block_header(i.block_num); - FC_ASSERT(b); - ss << i.block_num << " "; - ss << b->timestamp.to_iso_string() << " "; - i.op.visit(operation_printer(ss, *this, i)); - ss << " \n"; - } - - return ss.str(); - }; + m["get_account_history"] = format_account_history; + m["get_relative_account_history"] = format_account_history; m["get_account_history_by_operations"] = [this](variant result, const fc::variants& a) { auto r = result.as( GRAPHENE_MAX_NESTED_OBJECTS ); @@ -101,7 +87,7 @@ std::map> wallet_a return ss.str(); }; - m["list_account_balances"] = [this](variant result, const fc::variants& a) + auto format_balances = [this](variant result, const fc::variants& a) { auto r = result.as>( GRAPHENE_MAX_NESTED_OBJECTS ); vector asset_recs; @@ -116,35 +102,10 @@ std::map> wallet_a return ss.str(); }; - m["get_blind_balances"] = [this](variant result, const fc::variants& a) - { - auto r = result.as>( GRAPHENE_MAX_NESTED_OBJECTS ); - vector asset_recs; - std::transform(r.begin(), r.end(), std::back_inserter(asset_recs), [this](const asset& a) { - return get_asset(a.asset_id); - }); - - std::stringstream ss; - for( unsigned i = 0; i < asset_recs.size(); ++i ) - ss << asset_recs[i].amount_to_pretty_string(r[i]) << "\n"; + m["list_account_balances"] = format_balances; + m["get_blind_balances"] = format_balances; - return ss.str(); - }; - m["transfer_to_blind"] = [this](variant result, const fc::variants& a) - { - auto r = result.as( GRAPHENE_MAX_NESTED_OBJECTS ); - std::stringstream ss; - r.trx.operations[0].visit( operation_printer( ss, *this, operation_history_object() ) ); - ss << "\n"; - for( const auto& out : r.outputs ) - { - auto a = get_asset( out.decrypted_memo.amount.asset_id ); - ss << a.amount_to_pretty_string( out.decrypted_memo.amount ) << " to " << out.label - << "\n\t receipt: " << out.confirmation_receipt << "\n\n"; - } - return ss.str(); - }; - m["blind_transfer"] = [this](variant result, const fc::variants& a) + auto format_blind_transfers = [this](variant result, const fc::variants& a) { auto r = result.as( GRAPHENE_MAX_NESTED_OBJECTS ); std::stringstream ss; @@ -158,6 +119,10 @@ std::map> wallet_a } return ss.str(); }; + + m["transfer_to_blind"] = format_blind_transfers; + m["blind_transfer"] = format_blind_transfers; + m["receive_blind_transfer"] = [this](variant result, const fc::variants& a) { auto r = result.as( GRAPHENE_MAX_NESTED_OBJECTS ); @@ -167,6 +132,7 @@ std::map> wallet_a << r.to_label << " " << r.memo <<"\n"; return ss.str(); }; + m["blind_history"] = [this](variant result, const fc::variants& a) { auto records = result.as>( GRAPHENE_MAX_NESTED_OBJECTS ); @@ -183,6 +149,7 @@ std::map> wallet_a } return ss.str(); }; + m["get_order_book"] = [](variant result, const fc::variants& a) { auto orders = result.as( GRAPHENE_MAX_NESTED_OBJECTS ); From 519350d848b6395206e570fa5a10769fb63fb8e3 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 6 Mar 2021 16:22:59 -0500 Subject: [PATCH 043/147] Remove an unnecessary constructor from trx_message --- libraries/net/include/graphene/net/core_messages.hpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/libraries/net/include/graphene/net/core_messages.hpp b/libraries/net/include/graphene/net/core_messages.hpp index 4e686e4513..e270dbb249 100644 --- a/libraries/net/include/graphene/net/core_messages.hpp +++ b/libraries/net/include/graphene/net/core_messages.hpp @@ -99,9 +99,6 @@ namespace graphene { namespace net { explicit trx_message(const graphene::protocol::signed_transaction& signed_trx) : trx(signed_trx) {} - explicit trx_message(graphene::protocol::signed_transaction&& signed_trx) : - trx(signed_trx) - {} }; struct block_message From f6bacde0279b9d1d633f452ee76cf5f8d62b2ab9 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 6 Mar 2021 16:37:09 -0500 Subject: [PATCH 044/147] Make unused parameters unnamed, fix code smells --- libraries/wallet/wallet_results.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libraries/wallet/wallet_results.cpp b/libraries/wallet/wallet_results.cpp index 8912d0354c..b8116195d0 100644 --- a/libraries/wallet/wallet_results.cpp +++ b/libraries/wallet/wallet_results.cpp @@ -31,17 +31,17 @@ std::map> wallet_a { std::map > m; - m["help"] = [](variant result, const fc::variants& a) + m["help"] = [](variant result, const fc::variants&) { return result.get_string(); }; - m["gethelp"] = [](variant result, const fc::variants& a) + m["gethelp"] = [](variant result, const fc::variants&) { return result.get_string(); }; - auto format_account_history = [this](variant result, const fc::variants& a) + auto format_account_history = [this](variant result, const fc::variants&) { auto r = result.as>( GRAPHENE_MAX_NESTED_OBJECTS ); std::stringstream ss; @@ -63,7 +63,7 @@ std::map> wallet_a m["get_account_history"] = format_account_history; m["get_relative_account_history"] = format_account_history; - m["get_account_history_by_operations"] = [this](variant result, const fc::variants& a) { + m["get_account_history_by_operations"] = [this](variant result, const fc::variants&) { auto r = result.as( GRAPHENE_MAX_NESTED_OBJECTS ); std::stringstream ss; ss << "total_count : "; @@ -87,7 +87,7 @@ std::map> wallet_a return ss.str(); }; - auto format_balances = [this](variant result, const fc::variants& a) + auto format_balances = [this](variant result, const fc::variants&) { auto r = result.as>( GRAPHENE_MAX_NESTED_OBJECTS ); vector asset_recs; @@ -105,7 +105,7 @@ std::map> wallet_a m["list_account_balances"] = format_balances; m["get_blind_balances"] = format_balances; - auto format_blind_transfers = [this](variant result, const fc::variants& a) + auto format_blind_transfers = [this](variant result, const fc::variants&) { auto r = result.as( GRAPHENE_MAX_NESTED_OBJECTS ); std::stringstream ss; @@ -123,7 +123,7 @@ std::map> wallet_a m["transfer_to_blind"] = format_blind_transfers; m["blind_transfer"] = format_blind_transfers; - m["receive_blind_transfer"] = [this](variant result, const fc::variants& a) + m["receive_blind_transfer"] = [this](variant result, const fc::variants&) { auto r = result.as( GRAPHENE_MAX_NESTED_OBJECTS ); std::stringstream ss; @@ -133,7 +133,7 @@ std::map> wallet_a return ss.str(); }; - m["blind_history"] = [this](variant result, const fc::variants& a) + m["blind_history"] = [this](variant result, const fc::variants&) { auto records = result.as>( GRAPHENE_MAX_NESTED_OBJECTS ); std::stringstream ss; @@ -150,7 +150,7 @@ std::map> wallet_a return ss.str(); }; - m["get_order_book"] = [](variant result, const fc::variants& a) + m["get_order_book"] = [](variant result, const fc::variants&) { auto orders = result.as( GRAPHENE_MAX_NESTED_OBJECTS ); auto bids = orders.bids; @@ -238,7 +238,7 @@ std::map> wallet_a return ss.str(); }; - m["sign_message"] = [](variant result, const fc::variants& a) + m["sign_message"] = [](variant result, const fc::variants&) { auto r = result.as( GRAPHENE_MAX_NESTED_OBJECTS ); From 6ebdbfa489d3f9a295cd248bbdcd5df6d32d8ca0 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 6 Mar 2021 19:29:50 -0500 Subject: [PATCH 045/147] Fix SonarScanner coverage report by checking more directories with gcov --- .github/workflows/sonar-scan.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sonar-scan.yml b/.github/workflows/sonar-scan.yml index f9e07e8c0c..3236d95a55 100644 --- a/.github/workflows/sonar-scan.yml +++ b/.github/workflows/sonar-scan.yml @@ -129,7 +129,10 @@ jobs: - name: Prepare for scanning with SonarScanner run: | mkdir -p sonar_cache - find _build/libraries/[acdenptuw]*/CMakeFiles/*.dir _build/programs/[cdgjsw]*/CMakeFiles/*.dir -type d -print \ + find _build/libraries/[acdenptuw]*/CMakeFiles/*.dir \ + _build/libraries/plugins/*/CMakeFiles/*.dir \ + _build/programs/[cdgjsw]*/CMakeFiles/*.dir \ + -type d -print \ | while read d; do srcd="${d:7}"; gcov -o "$d" "${srcd/CMakeFiles*.dir/.}"/*.cpp; done >/dev/null programs/build_helpers/set_sonar_branch_for_github_actions sonar-project.properties - name: Scan with SonarScanner From 4b169408f7ef797d991429c70e87bea91e33fd0d Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 6 Mar 2021 21:59:40 -0500 Subject: [PATCH 046/147] Add CLI tests for some MPA commands --- tests/cli/main.cpp | 122 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 121 insertions(+), 1 deletion(-) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index 91c0af7cc6..8c1cb2731c 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -431,6 +431,126 @@ BOOST_FIXTURE_TEST_CASE( create_new_account, cli_fixture ) } } +BOOST_FIXTURE_TEST_CASE( mpa_tests, cli_fixture ) +{ + try + { + BOOST_TEST_MESSAGE("Cli MPA Tests"); + + INVOKE(upgrade_nathan_account); + + account_object nathan_acct = con.wallet_api_ptr->get_account("nathan"); + + // Create new asset called BOBCOIN backed by CORE + try + { + BOOST_TEST_MESSAGE("Create MPA 'BOBCOIN'"); + graphene::chain::asset_options asset_ops; + asset_ops.issuer_permissions = ASSET_ISSUER_PERMISSION_ENABLE_BITS_MASK; + asset_ops.flags = charge_market_fee; + asset_ops.max_supply = 1000000; + asset_ops.core_exchange_rate = price(asset(2),asset(1,asset_id_type(1))); + graphene::chain::bitasset_options bit_opts; + con.wallet_api_ptr->create_asset("nathan", "BOBCOIN", 4, asset_ops, bit_opts, true); + } + catch(exception& e) + { + BOOST_FAIL(e.what()); + } + catch(...) + { + BOOST_FAIL("Unknown exception creating BOBCOIN"); + } + + auto bobcoin = con.wallet_api_ptr->get_asset("BOBCOIN"); + { + // Play with asset fee pool + auto objs = con.wallet_api_ptr->get_object( bobcoin.dynamic_asset_data_id ) + .as>( FC_PACK_MAX_DEPTH ); + idump( (objs) ); + BOOST_REQUIRE_EQUAL( objs.size(), 1u ); + asset_dynamic_data_object bobcoin_dyn = objs[0]; + idump( (bobcoin_dyn) ); + share_type old_pool = bobcoin_dyn.fee_pool; + + BOOST_TEST_MESSAGE("Fund fee pool"); + con.wallet_api_ptr->fund_asset_fee_pool("nathan", "BOBCOIN", "2", true); + objs = con.wallet_api_ptr->get_object( bobcoin.dynamic_asset_data_id ) + .as>( FC_PACK_MAX_DEPTH ); + BOOST_REQUIRE_EQUAL( objs.size(), 1u ); + bobcoin_dyn = objs[0]; + share_type funded_pool = bobcoin_dyn.fee_pool; + BOOST_CHECK_EQUAL( funded_pool.value, old_pool.value + GRAPHENE_BLOCKCHAIN_PRECISION * 2 ); + + BOOST_TEST_MESSAGE("Claim fee pool"); + con.wallet_api_ptr->claim_asset_fee_pool("BOBCOIN", "1", true); + objs = con.wallet_api_ptr->get_object( bobcoin.dynamic_asset_data_id ) + .as>( FC_PACK_MAX_DEPTH ); + BOOST_REQUIRE_EQUAL( objs.size(), 1u ); + bobcoin_dyn = objs[0]; + share_type claimed_pool = bobcoin_dyn.fee_pool; + BOOST_CHECK_EQUAL( claimed_pool.value, old_pool.value + GRAPHENE_BLOCKCHAIN_PRECISION ); + } + + { + // Set price feed producer + BOOST_TEST_MESSAGE("Set price feed producer"); + asset_bitasset_data_object bob_bitasset = con.wallet_api_ptr->get_bitasset_data( "BOBCOIN" ); + BOOST_CHECK_EQUAL( bob_bitasset.feeds.size(), 0u ); + + auto handle = con.wallet_api_ptr->begin_builder_transaction(); + asset_update_feed_producers_operation aufp_op; + aufp_op.issuer = nathan_acct.id; + aufp_op.asset_to_update = bobcoin.id; + aufp_op.new_feed_producers = { nathan_acct.id }; + con.wallet_api_ptr->add_operation_to_builder_transaction( handle, aufp_op ); + con.wallet_api_ptr->set_fees_on_builder_transaction( handle, "1.3.0" ); + con.wallet_api_ptr->sign_builder_transaction( handle, true ); + + bob_bitasset = con.wallet_api_ptr->get_bitasset_data( "BOBCOIN" ); + BOOST_CHECK_EQUAL( bob_bitasset.feeds.size(), 1u ); + BOOST_CHECK( bob_bitasset.current_feed.settlement_price.is_null() ); + } + + { + // Publish price feed + BOOST_TEST_MESSAGE("Publish price feed"); + price_feed feed; + feed.settlement_price = price( asset(1,bobcoin.id), asset(2) ); + feed.core_exchange_rate = price( asset(1,bobcoin.id), asset(1) ); + con.wallet_api_ptr->publish_asset_feed( "nathan", "BOBCOIN", feed, true ); + asset_bitasset_data_object bob_bitasset = con.wallet_api_ptr->get_bitasset_data( "BOBCOIN" ); + BOOST_CHECK( bob_bitasset.current_feed.settlement_price == feed.settlement_price ); + } + + { + // Borrow + BOOST_TEST_MESSAGE("Borrow BOBCOIN"); + auto calls = con.wallet_api_ptr->get_call_orders( "BOBCOIN", 10 ); + BOOST_CHECK_EQUAL( calls.size(), 0u ); + con.wallet_api_ptr->borrow_asset( "nathan", "1", "BOBCOIN", "10", true ); + calls = con.wallet_api_ptr->get_call_orders( "BOBCOIN", 10 ); + BOOST_CHECK_EQUAL( calls.size(), 1u ); + + auto nathan_balances = con.wallet_api_ptr->list_account_balances( "nathan" ); + size_t count = 0; + for( auto& bal : nathan_balances ) + { + if( bal.asset_id == bobcoin.id ) + { + ++count; + BOOST_CHECK_EQUAL( bal.amount.value, 10000 ); + } + } + BOOST_CHECK_EQUAL(count, 1u); + } + + } catch( fc::exception& e ) { + edump((e.to_detail_string())); + throw; + } +} + /////////////////////// // Start a server and connect using the same calls as the CLI // Vote for two witnesses, and make sure they both stay there @@ -800,7 +920,7 @@ BOOST_FIXTURE_TEST_CASE( cli_confidential_tx_test, cli_fixture ) std::map to_list = {{"alice",100000000000}, {"bob", 1000000000}}; vector bconfs; - asset_object core_asset = W.get_asset("1.3.0"); + auto core_asset = W.get_asset("1.3.0"); BOOST_TEST_MESSAGE("Sending blind transactions to alice and bob"); for (auto to : to_list) { string amount = core_asset.amount_to_string(to.second); From a298068def967956ed64fb858282bad145376e7e Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 6 Mar 2021 22:01:04 -0500 Subject: [PATCH 047/147] Remove trailing whitespaces --- tests/cli/main.cpp | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index 8c1cb2731c..d5e44b3ebb 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -159,7 +159,7 @@ std::shared_ptr start_application(fc::temp_directory /// @param returned_block the signed block /// @returns true on success /////////// -bool generate_block(std::shared_ptr app, graphene::chain::signed_block& returned_block) +bool generate_block(std::shared_ptr app, graphene::chain::signed_block& returned_block) { try { fc::ecc::private_key committee_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("nathan"))); @@ -787,8 +787,8 @@ BOOST_FIXTURE_TEST_CASE( cli_get_available_transaction_signers, cli_fixture ) trx.sign( privkey_2, con.wallet_data.chain_id ); // verify expected result - flat_set expected_signers = {test_bki.pub_key, - privkey_1.get_public_key(), + flat_set expected_signers = {test_bki.pub_key, + privkey_1.get_public_key(), privkey_2.get_public_key()}; auto signers = con.wallet_api_ptr->get_transaction_signers(trx); @@ -836,7 +836,7 @@ BOOST_FIXTURE_TEST_CASE( cli_cant_get_signers_from_modified_transaction, cli_fix // modify transaction (MITM-attack) trx.operations.clear(); - // verify if transaction has no valid signature of test account + // verify if transaction has no valid signature of test account flat_set expected_signers_of_valid_transaction = {test_bki.pub_key}; auto signers = con.wallet_api_ptr->get_transaction_signers(trx); BOOST_CHECK(signers != expected_signers_of_valid_transaction); @@ -879,10 +879,10 @@ BOOST_FIXTURE_TEST_CASE( cli_confidential_tx_test, cli_fixture ) try { // we need to increase the default max transaction size to run this test. this->app1->chain_database()->modify( - this->app1->chain_database()->get_global_properties(), + this->app1->chain_database()->get_global_properties(), []( global_property_object& p) { p.parameters.maximum_transaction_size = 8192; - }); + }); std::vector import_txs; BOOST_TEST_MESSAGE("Importing nathan's balance"); @@ -1219,7 +1219,7 @@ BOOST_AUTO_TEST_CASE( cli_create_htlc ) BOOST_CHECK(nathan_acct_after_upgrade.is_lifetime_member()); // Create new asset called BOBCOIN - try + try { graphene::chain::asset_options asset_ops; asset_ops.max_supply = 1000000; @@ -1240,12 +1240,12 @@ BOOST_AUTO_TEST_CASE( cli_create_htlc ) { graphene::wallet::brain_key_info bki = con.wallet_api_ptr->suggest_brain_key(); BOOST_CHECK(!bki.brain_priv_key.empty()); - signed_transaction create_acct_tx = con.wallet_api_ptr->create_account_with_brain_key(bki.brain_priv_key, "alice", + signed_transaction create_acct_tx = con.wallet_api_ptr->create_account_with_brain_key(bki.brain_priv_key, "alice", "nathan", "nathan", true); con.wallet_api_ptr->save_wallet_file(con.wallet_filename); // attempt to give alice some bitshares BOOST_TEST_MESSAGE("Transferring bitshares from Nathan to alice"); - signed_transaction transfer_tx = con.wallet_api_ptr->transfer("nathan", "alice", "10000", "1.3.0", + signed_transaction transfer_tx = con.wallet_api_ptr->transfer("nathan", "alice", "10000", "1.3.0", "Here are some CORE token for your new account", true); } @@ -1253,13 +1253,13 @@ BOOST_AUTO_TEST_CASE( cli_create_htlc ) { graphene::wallet::brain_key_info bki = con.wallet_api_ptr->suggest_brain_key(); BOOST_CHECK(!bki.brain_priv_key.empty()); - signed_transaction create_acct_tx = con.wallet_api_ptr->create_account_with_brain_key(bki.brain_priv_key, "bob", + signed_transaction create_acct_tx = con.wallet_api_ptr->create_account_with_brain_key(bki.brain_priv_key, "bob", "nathan", "nathan", true); // this should cause resync which will import the keys of alice and bob generate_block(app1); // attempt to give bob some bitshares BOOST_TEST_MESSAGE("Transferring bitshares from Nathan to Bob"); - signed_transaction transfer_tx = con.wallet_api_ptr->transfer("nathan", "bob", "10000", "1.3.0", + signed_transaction transfer_tx = con.wallet_api_ptr->transfer("nathan", "bob", "10000", "1.3.0", "Here are some CORE token for your new account", true); con.wallet_api_ptr->issue_asset("bob", "5", "BOBCOIN", "Here are your BOBCOINs", true); } @@ -1278,8 +1278,8 @@ BOOST_AUTO_TEST_CASE( cli_create_htlc ) std::string hash_str = ss.str(); BOOST_TEST_MESSAGE("Secret is " + preimage_string + " and hash is " + hash_str); uint32_t timelock = fc::days(1).to_seconds(); - graphene::chain::signed_transaction result_tx - = con.wallet_api_ptr->htlc_create("alice", "bob", + graphene::chain::signed_transaction result_tx + = con.wallet_api_ptr->htlc_create("alice", "bob", "3", "1.3.0", "SHA256", hash_str, preimage_string.size(), timelock, "", true); // normally, a wallet would watch block production, and find the transaction. Here, we can cheat: @@ -1746,13 +1746,13 @@ BOOST_AUTO_TEST_CASE( cli_create_htlc_bsip64 ) account_object nathan_acct_after_upgrade = con.wallet_api_ptr->get_account("nathan"); // verify that the upgrade was successful - BOOST_CHECK_PREDICATE( std::not_equal_to(), + BOOST_CHECK_PREDICATE( std::not_equal_to(), (nathan_acct_before_upgrade.membership_expiration_date.sec_since_epoch()) (nathan_acct_after_upgrade.membership_expiration_date.sec_since_epoch()) ); BOOST_CHECK(nathan_acct_after_upgrade.is_lifetime_member()); // Create new asset called BOBCOIN - try + try { graphene::chain::asset_options asset_ops; asset_ops.max_supply = 1000000; @@ -1778,7 +1778,7 @@ BOOST_AUTO_TEST_CASE( cli_create_htlc_bsip64 ) con.wallet_api_ptr->save_wallet_file(con.wallet_filename); // attempt to give alice some bitshares BOOST_TEST_MESSAGE("Transferring bitshares from Nathan to alice"); - signed_transaction transfer_tx = con.wallet_api_ptr->transfer("nathan", "alice", "10000", "1.3.0", + signed_transaction transfer_tx = con.wallet_api_ptr->transfer("nathan", "alice", "10000", "1.3.0", "Here are some CORE token for your new account", true); } @@ -1792,7 +1792,7 @@ BOOST_AUTO_TEST_CASE( cli_create_htlc_bsip64 ) generate_block(app1); // attempt to give bob some bitshares BOOST_TEST_MESSAGE("Transferring bitshares from Nathan to Bob"); - signed_transaction transfer_tx = con.wallet_api_ptr->transfer("nathan", "bob", "10000", "1.3.0", + signed_transaction transfer_tx = con.wallet_api_ptr->transfer("nathan", "bob", "10000", "1.3.0", "Here are some CORE token for your new account", true); con.wallet_api_ptr->issue_asset("bob", "5", "BOBCOIN", "Here are your BOBCOINs", true); } @@ -1811,8 +1811,8 @@ BOOST_AUTO_TEST_CASE( cli_create_htlc_bsip64 ) std::string hash_str = ss.str(); BOOST_TEST_MESSAGE("Secret is " + preimage_string + " and hash is " + hash_str); uint32_t timelock = fc::days(1).to_seconds(); - graphene::chain::signed_transaction result_tx - = con.wallet_api_ptr->htlc_create("alice", "bob", + graphene::chain::signed_transaction result_tx + = con.wallet_api_ptr->htlc_create("alice", "bob", "3", "1.3.0", "HASH160", hash_str, preimage_string.size(), timelock, "Alice to Bob", true); // normally, a wallet would watch block production, and find the transaction. Here, we can cheat: @@ -1872,7 +1872,7 @@ BOOST_AUTO_TEST_CASE( cli_create_htlc_bsip64 ) std::vector hist = con.wallet_api_ptr->get_account_history("alice", 1); BOOST_CHECK( hist[0].description.find("with preimage \"4d792") != hist[0].description.npos); } - + // Bob can also look at his own history to see Alice's preimage { BOOST_TEST_MESSAGE("Bob can look at his own history to see the preimage"); @@ -1915,8 +1915,8 @@ BOOST_AUTO_TEST_CASE( cli_create_htlc_bsip64 ) { BOOST_CHECK( str.find("HASH160 620e4d5ba") != std::string::npos ); } - } - con.wallet_api_ptr->unlock("supersecret"); + } + con.wallet_api_ptr->unlock("supersecret"); } catch( fc::exception& e ) { edump((e.to_detail_string())); From 330c37e1704dca877efbb096a7e000ea9ff72c86 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 6 Mar 2021 22:05:12 -0500 Subject: [PATCH 048/147] Wrap long lines --- tests/cli/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index d5e44b3ebb..665c43c27b 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -1240,8 +1240,8 @@ BOOST_AUTO_TEST_CASE( cli_create_htlc ) { graphene::wallet::brain_key_info bki = con.wallet_api_ptr->suggest_brain_key(); BOOST_CHECK(!bki.brain_priv_key.empty()); - signed_transaction create_acct_tx = con.wallet_api_ptr->create_account_with_brain_key(bki.brain_priv_key, "alice", - "nathan", "nathan", true); + signed_transaction create_acct_tx = con.wallet_api_ptr->create_account_with_brain_key(bki.brain_priv_key, + "alice", "nathan", "nathan", true); con.wallet_api_ptr->save_wallet_file(con.wallet_filename); // attempt to give alice some bitshares BOOST_TEST_MESSAGE("Transferring bitshares from Nathan to alice"); @@ -1253,8 +1253,8 @@ BOOST_AUTO_TEST_CASE( cli_create_htlc ) { graphene::wallet::brain_key_info bki = con.wallet_api_ptr->suggest_brain_key(); BOOST_CHECK(!bki.brain_priv_key.empty()); - signed_transaction create_acct_tx = con.wallet_api_ptr->create_account_with_brain_key(bki.brain_priv_key, "bob", - "nathan", "nathan", true); + signed_transaction create_acct_tx = con.wallet_api_ptr->create_account_with_brain_key(bki.brain_priv_key, + "bob", "nathan", "nathan", true); // this should cause resync which will import the keys of alice and bob generate_block(app1); // attempt to give bob some bitshares From 7032a8ec5234b78cc677377010c8d47ad01cf79b Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 6 Mar 2021 23:34:34 -0500 Subject: [PATCH 049/147] Add tests for CLI result formatters --- tests/cli/main.cpp | 97 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 2 deletions(-) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index 665c43c27b..6a96ddb389 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -372,6 +372,30 @@ BOOST_FIXTURE_TEST_CASE( cli_quit, cli_fixture ) BOOST_CHECK_THROW( con.wallet_api_ptr->quit(), fc::canceled_exception ); } +BOOST_FIXTURE_TEST_CASE( cli_help_gethelp, cli_fixture ) +{ + BOOST_TEST_MESSAGE("Testing help and gethelp commands."); + auto formatters = con.wallet_api_ptr->get_result_formatters(); + + string result = con.wallet_api_ptr->help(); + BOOST_CHECK( result.find("gethelp") != string::npos ); + if( formatters.find("help") != formatters.end() ) + { + BOOST_TEST_MESSAGE("Testing formatter of help"); + string output = formatters["help"](fc::variant(result), fc::variants()); + BOOST_CHECK( output.find("gethelp") != string::npos ); + } + + result = con.wallet_api_ptr->gethelp( "transfer" ); + BOOST_CHECK( result.find("usage") != string::npos ); + if( formatters.find("gethelp") != formatters.end() ) + { + BOOST_TEST_MESSAGE("Testing formatter of gethelp"); + string output = formatters["gethelp"](fc::variant(result), fc::variants()); + BOOST_CHECK( output.find("usage") != string::npos ); + } +} + BOOST_FIXTURE_TEST_CASE( upgrade_nathan_account, cli_fixture ) { try @@ -441,6 +465,8 @@ BOOST_FIXTURE_TEST_CASE( mpa_tests, cli_fixture ) account_object nathan_acct = con.wallet_api_ptr->get_account("nathan"); + auto formatters = con.wallet_api_ptr->get_result_formatters(); + // Create new asset called BOBCOIN backed by CORE try { @@ -451,7 +477,14 @@ BOOST_FIXTURE_TEST_CASE( mpa_tests, cli_fixture ) asset_ops.max_supply = 1000000; asset_ops.core_exchange_rate = price(asset(2),asset(1,asset_id_type(1))); graphene::chain::bitasset_options bit_opts; - con.wallet_api_ptr->create_asset("nathan", "BOBCOIN", 4, asset_ops, bit_opts, true); + auto result = con.wallet_api_ptr->create_asset("nathan", "BOBCOIN", 4, asset_ops, bit_opts, true); + if( formatters.find("create_asset") != formatters.end() ) + { + BOOST_TEST_MESSAGE("Testing formatter of create_asset"); + string output = formatters["create_asset"]( + fc::variant(result, FC_PACK_MAX_DEPTH), fc::variants()); + BOOST_CHECK( output.find("BOBCOIN") != string::npos ); + } } catch(exception& e) { @@ -543,6 +576,15 @@ BOOST_FIXTURE_TEST_CASE( mpa_tests, cli_fixture ) } } BOOST_CHECK_EQUAL(count, 1u); + + // Testing result formatter + if( formatters.find("list_account_balances") != formatters.end() ) + { + BOOST_TEST_MESSAGE("Testing formatter of list_account_balances"); + string output = formatters["list_account_balances"]( + fc::variant(nathan_balances, FC_PACK_MAX_DEPTH ), fc::variants()); + BOOST_CHECK( output.find("BOBCOIN") != string::npos ); + } } } catch( fc::exception& e ) { @@ -891,6 +933,8 @@ BOOST_FIXTURE_TEST_CASE( cli_confidential_tx_test, cli_fixture ) unsigned int head_block = 0; auto & W = *con.wallet_api_ptr; // Wallet alias + auto formatters = con.wallet_api_ptr->get_result_formatters(); + BOOST_TEST_MESSAGE("Creating blind accounts"); graphene::wallet::brain_key_info bki_nathan = W.suggest_brain_key(); graphene::wallet::brain_key_info bki_alice = W.suggest_brain_key(); @@ -909,7 +953,17 @@ BOOST_FIXTURE_TEST_CASE( cli_confidential_tx_test, cli_fixture ) // ** Block 2: Nathan will blind 100M CORE token: BOOST_TEST_MESSAGE("Blinding a large balance"); - W.transfer_to_blind("nathan", GRAPHENE_SYMBOL, {{"nathan","100000000"}}, true); + { + auto result = W.transfer_to_blind("nathan", GRAPHENE_SYMBOL, {{"nathan","100000000"}}, true); + // Testing result formatter + if( formatters.find("transfer_to_blind") != formatters.end() ) + { + BOOST_TEST_MESSAGE("Testing formatter of transfer_to_blind"); + string output = formatters["transfer_to_blind"]( + fc::variant(result, FC_PACK_MAX_DEPTH), fc::variants()); + BOOST_CHECK( output.find("receipt") != string::npos ); + } + } BOOST_CHECK( W.get_blind_balances("nathan")[0].amount == 10000000000000 ); generate_block(app1); head_block++; @@ -953,6 +1007,35 @@ BOOST_FIXTURE_TEST_CASE( cli_confidential_tx_test, cli_fixture ) BOOST_TEST_MESSAGE("Check that all expected blocks have processed"); dynamic_global_property_object dgp = W.get_dynamic_global_properties(); BOOST_CHECK(dgp.head_block_number == head_block); + + // Receive blind transfer + { + auto result = W.receive_blind_transfer(bconfs[1].outputs[1].confirmation_receipt, "", "bob_receive"); + BOOST_CHECK_EQUAL( result.amount.amount.value, 1000000000 ); + // Testing result formatter + if( formatters.find("receive_blind_transfer") != formatters.end() ) + { + BOOST_TEST_MESSAGE("Testing formatter of receive_blind_transfer"); + string output = formatters["receive_blind_transfer"]( + fc::variant(result, FC_PACK_MAX_DEPTH), fc::variants()); + BOOST_CHECK( output.find("bob_receive") != string::npos ); + } + } + + // Check blind history + { + auto result = W.blind_history("nathan"); + BOOST_CHECK_EQUAL( result.size(), 5u ); // 1 transfer_to_blind + 2 outputs * 2 blind_transfers + // Testing result formatter + if( formatters.find("blind_history") != formatters.end() ) + { + BOOST_TEST_MESSAGE("Testing formatter of blind_history"); + string output = formatters["blind_history"]( + fc::variant(result, FC_PACK_MAX_DEPTH), fc::variants()); + BOOST_CHECK( output.find("WHEN") != string::npos ); + BOOST_TEST_MESSAGE( output ); + } + } } catch( fc::exception& e ) { edump((e.to_detail_string())); throw; @@ -992,6 +1075,16 @@ BOOST_FIXTURE_TEST_CASE( account_history_pagination, cli_fixture ) } operation_ids.insert(op.op.id); } + + // Testing result formatter + auto formatters = con.wallet_api_ptr->get_result_formatters(); + if( formatters.find("get_account_history") != formatters.end() ) + { + BOOST_TEST_MESSAGE("Testing formatter of get_account_history"); + string output = formatters["get_account_history"]( + fc::variant(history, FC_PACK_MAX_DEPTH), fc::variants()); + BOOST_CHECK( output.find("Here are some") != string::npos ); + } } catch( fc::exception& e ) { edump((e.to_detail_string())); throw; From 3573bb5cd856dcf26f397c832306c42882c10a02 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 7 Mar 2021 10:34:37 -0500 Subject: [PATCH 050/147] Fix OOM when building in Github Actions debug mode --- .github/workflows/build-and-test.ubuntu-debug.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build-and-test.ubuntu-debug.yml b/.github/workflows/build-and-test.ubuntu-debug.yml index 3ca8a0d347..ddec5bdec3 100644 --- a/.github/workflows/build-and-test.ubuntu-debug.yml +++ b/.github/workflows/build-and-test.ubuntu-debug.yml @@ -84,7 +84,9 @@ jobs: mkdir -p "$CCACHE_DIR" df -h make -j 2 -C _build chain_test + make -j 2 -C _build cli_test make -j 2 -C _build cli_wallet + make -j 2 -C _build witness_node make -j 2 -C _build df -h du -hs _build/libraries/* _build/programs/* _build/tests/* From e876ed6ed0e5c428712dcfda108c05a4188da3f2 Mon Sep 17 00:00:00 2001 From: abitmore Date: Mon, 8 Mar 2021 17:28:26 -0500 Subject: [PATCH 051/147] Print p2p log messages to console in app_test --- tests/app/main.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/app/main.cpp b/tests/app/main.cpp index 5e14602f79..5a77b12b88 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -36,7 +36,9 @@ #include #include +#include #include +#include #include @@ -216,6 +218,20 @@ BOOST_AUTO_TEST_CASE( two_node_network ) using namespace graphene::chain; using namespace graphene::app; try { + // Configure logging + fc::logging_config logging_config; + logging_config.appenders.push_back( fc::appender_config( "stderr", "console", + fc::variant( fc::console_appender::config(), GRAPHENE_MAX_NESTED_OBJECTS ) ) ); + + fc::logger_config logger_config("p2p"); + logger_config.level = fc::log_level::debug; + logger_config.appenders.push_back("stderr"); + + logging_config.loggers.push_back(logger_config); + + fc::configure_logging(logging_config); + + // Start app1 BOOST_TEST_MESSAGE( "Creating and initializing app1" ); fc::temp_directory app_dir( graphene::utilities::temp_directory_path() ); @@ -243,6 +259,7 @@ BOOST_AUTO_TEST_CASE( two_node_network ) return status["listening_on"].as( 5 ).port() == 3939; }); + // Start app2 BOOST_TEST_MESSAGE( "Creating and initializing app2" ); fc::temp_directory app2_dir( graphene::utilities::temp_directory_path() ); @@ -273,6 +290,7 @@ BOOST_AUTO_TEST_CASE( two_node_network ) BOOST_CHECK_EQUAL( db1->get_balance( GRAPHENE_NULL_ACCOUNT, asset_id_type() ).amount.value, 0 ); BOOST_CHECK_EQUAL( db2->get_balance( GRAPHENE_NULL_ACCOUNT, asset_id_type() ).amount.value, 0 ); + // Transaction test BOOST_TEST_MESSAGE( "Creating transfer tx" ); graphene::chain::precomputable_transaction trx; { @@ -321,6 +339,7 @@ BOOST_AUTO_TEST_CASE( two_node_network ) BOOST_CHECK_EQUAL( db1->get_balance( GRAPHENE_NULL_ACCOUNT, asset_id_type() ).amount.value, 1000000 ); BOOST_CHECK_EQUAL( db2->get_balance( GRAPHENE_NULL_ACCOUNT, asset_id_type() ).amount.value, 1000000 ); + // Block test BOOST_TEST_MESSAGE( "Generating block on db2" ); fc::ecc::private_key committee_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("nathan"))); From e74fde899f531bfa75598817e36081d9bd5f2bcd Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 9 Mar 2021 07:41:15 -0500 Subject: [PATCH 052/147] Use the same genesis file for 2 nodes in app_test to fix a node connection issue --- tests/app/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/app/main.cpp b/tests/app/main.cpp index 5a77b12b88..11601da99d 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -235,6 +235,7 @@ BOOST_AUTO_TEST_CASE( two_node_network ) BOOST_TEST_MESSAGE( "Creating and initializing app1" ); fc::temp_directory app_dir( graphene::utilities::temp_directory_path() ); + auto genesis_file = create_genesis_file(app_dir); graphene::app::application app1; app1.register_plugin< graphene::account_history::account_history_plugin>(); @@ -244,7 +245,7 @@ BOOST_AUTO_TEST_CASE( two_node_network ) app1.startup_plugins(); boost::program_options::variables_map cfg; cfg.emplace("p2p-endpoint", boost::program_options::variable_value(string("127.0.0.1:3939"), false)); - cfg.emplace("genesis-json", boost::program_options::variable_value(create_genesis_file(app_dir), false)); + cfg.emplace("genesis-json", boost::program_options::variable_value(genesis_file, false)); cfg.emplace("seed-nodes", boost::program_options::variable_value(string("[]"), false)); app1.initialize(app_dir.path(), cfg); BOOST_TEST_MESSAGE( "Starting app1 and waiting 500 ms" ); @@ -271,7 +272,7 @@ BOOST_AUTO_TEST_CASE( two_node_network ) app2.startup_plugins(); boost::program_options::variables_map cfg2; cfg2.emplace("p2p-endpoint", boost::program_options::variable_value(string("127.0.0.1:4040"), false)); - cfg2.emplace("genesis-json", boost::program_options::variable_value(create_genesis_file(app_dir), false)); + cfg2.emplace("genesis-json", boost::program_options::variable_value(genesis_file, false)); cfg2.emplace("seed-nodes", boost::program_options::variable_value(string("[\"127.0.0.1:3939\"]"), false)); app2.initialize(app2_dir.path(), cfg2); From 667a18d93d23a0f629f7c3ef66b3bdf3c69a5bf2 Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 9 Mar 2021 10:38:25 -0500 Subject: [PATCH 053/147] Add pragma once to hpp files in tests/common --- tests/common/init_unit_test_suite.hpp | 2 ++ tests/common/utils.hpp | 1 + 2 files changed, 3 insertions(+) diff --git a/tests/common/init_unit_test_suite.hpp b/tests/common/init_unit_test_suite.hpp index 472d1e7f14..1db6b5c18c 100644 --- a/tests/common/init_unit_test_suite.hpp +++ b/tests/common/init_unit_test_suite.hpp @@ -21,6 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#pragma once + #include #include #include diff --git a/tests/common/utils.hpp b/tests/common/utils.hpp index b590331f64..9371457850 100644 --- a/tests/common/utils.hpp +++ b/tests/common/utils.hpp @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#pragma once #include #include From e491d1eddf9ec690e5250c0f62cbbf69984fbe89 Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 9 Mar 2021 10:53:58 -0500 Subject: [PATCH 054/147] Move get_available_port from cli_test to utils.hpp --- tests/cli/main.cpp | 34 ++++--------------------------- tests/common/utils.hpp | 45 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 31 deletions(-) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index 6a96ddb389..87ec50c757 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -61,12 +61,14 @@ #include #include "../common/init_unit_test_suite.hpp" +#include "../common/genesis_file_util.hpp" +#include "../common/utils.hpp" +#ifdef _WIN32 /***** * Global Initialization for Windows * ( sets up Winsock stuf ) */ -#ifdef _WIN32 int sockInit(void) { WSADATA wsa_data; @@ -82,39 +84,11 @@ int sockQuit(void) * Helper Methods *********************/ -#include "../common/genesis_file_util.hpp" - using std::exception; using std::cerr; #define INVOKE(test) ((struct test*)this)->test_method(); -////// -/// @brief attempt to find an available port on localhost -/// @returns an available port number, or -1 on error -///// -int get_available_port() -{ - struct sockaddr_in sin; - int socket_fd = socket(AF_INET, SOCK_STREAM, 0); - if (socket_fd == -1) - return -1; - sin.sin_family = AF_INET; - sin.sin_port = 0; - sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - if (::bind(socket_fd, (struct sockaddr*)&sin, sizeof(struct sockaddr_in)) == -1) - return -1; - socklen_t len = sizeof(sin); - if (getsockname(socket_fd, (struct sockaddr *)&sin, &len) == -1) - return -1; -#ifdef _WIN32 - closesocket(socket_fd); -#else - close(socket_fd); -#endif - return ntohs(sin.sin_port); -} - /////////// /// @brief Start the application /// @param app_dir the temporary directory to use @@ -135,7 +109,7 @@ std::shared_ptr start_application(fc::temp_directory #ifdef _WIN32 sockInit(); #endif - server_port_number = get_available_port(); + server_port_number = fc::network::get_available_port(); cfg.emplace( "rpc-endpoint", boost::program_options::variable_value(string("127.0.0.1:" + std::to_string(server_port_number)), false) diff --git a/tests/common/utils.hpp b/tests/common/utils.hpp index 9371457850..b5bbd1d681 100644 --- a/tests/common/utils.hpp +++ b/tests/common/utils.hpp @@ -26,6 +26,19 @@ #include #include +#ifdef _WIN32 + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0501 + #endif + #include + #include +#else + #include + #include + #include + #include +#endif + namespace fc { /** Waits for F() to return true before max_duration has passed. @@ -38,4 +51,34 @@ namespace fc { fc::usleep(fc::milliseconds(100)); BOOST_REQUIRE( f() ); } -} + +namespace network { + ////// + /// @brief attempt to find an available port on localhost + /// @returns an available port number, or -1 on error + ///// + int get_available_port() + { + struct sockaddr_in sin; + int socket_fd = socket(AF_INET, SOCK_STREAM, 0); + if (socket_fd == -1) + return -1; + sin.sin_family = AF_INET; + sin.sin_port = 0; + sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + if (::bind(socket_fd, (struct sockaddr*)&sin, sizeof(struct sockaddr_in)) == -1) + return -1; + socklen_t len = sizeof(sin); + if (getsockname(socket_fd, (struct sockaddr *)&sin, &len) == -1) + return -1; + #ifdef _WIN32 + closesocket(socket_fd); + #else + close(socket_fd); + #endif + return ntohs(sin.sin_port); + } + +} // namespace fc::network + +} // namespace fc From 3f44cf9db1a4b952be33f64c921047b6f9be1703 Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 9 Mar 2021 11:02:17 -0500 Subject: [PATCH 055/147] Use random P2P ports in two_node_network test case --- tests/app/main.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/app/main.cpp b/tests/app/main.cpp index 11601da99d..7920916e3d 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -231,6 +231,10 @@ BOOST_AUTO_TEST_CASE( two_node_network ) fc::configure_logging(logging_config); + auto port = fc::network::get_available_port(); + auto app1_p2p_endpoint_str = string("127.0.0.1:") + std::to_string(port); + auto app2_seed_nodes_str = string("[\"") + app1_p2p_endpoint_str + "\"]"; + // Start app1 BOOST_TEST_MESSAGE( "Creating and initializing app1" ); @@ -244,7 +248,7 @@ BOOST_AUTO_TEST_CASE( two_node_network ) app1.register_plugin< graphene::grouped_orders::grouped_orders_plugin>(); app1.startup_plugins(); boost::program_options::variables_map cfg; - cfg.emplace("p2p-endpoint", boost::program_options::variable_value(string("127.0.0.1:3939"), false)); + cfg.emplace("p2p-endpoint", boost::program_options::variable_value(app1_p2p_endpoint_str, false)); cfg.emplace("genesis-json", boost::program_options::variable_value(genesis_file, false)); cfg.emplace("seed-nodes", boost::program_options::variable_value(string("[]"), false)); app1.initialize(app_dir.path(), cfg); @@ -255,9 +259,9 @@ BOOST_AUTO_TEST_CASE( two_node_network ) #else #define NODE_STARTUP_WAIT_TIME (fc::milliseconds(120000)) #endif - fc::wait_for( NODE_STARTUP_WAIT_TIME, [&app1] () { + fc::wait_for( NODE_STARTUP_WAIT_TIME, [&app1,port] () { const auto status = app1.p2p_node()->network_get_info(); - return status["listening_on"].as( 5 ).port() == 3939; + return status["listening_on"].as( 5 ).port() == port; }); // Start app2 @@ -271,9 +275,8 @@ BOOST_AUTO_TEST_CASE( two_node_network ) app2.register_plugin< graphene::grouped_orders::grouped_orders_plugin>(); app2.startup_plugins(); boost::program_options::variables_map cfg2; - cfg2.emplace("p2p-endpoint", boost::program_options::variable_value(string("127.0.0.1:4040"), false)); cfg2.emplace("genesis-json", boost::program_options::variable_value(genesis_file, false)); - cfg2.emplace("seed-nodes", boost::program_options::variable_value(string("[\"127.0.0.1:3939\"]"), false)); + cfg2.emplace("seed-nodes", boost::program_options::variable_value(app2_seed_nodes_str, false)); app2.initialize(app2_dir.path(), cfg2); BOOST_TEST_MESSAGE( "Starting app2 and waiting for connection" ); From 92a73a57ef34079094c6f97ef38ad495624e38e6 Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 9 Mar 2021 11:12:52 -0500 Subject: [PATCH 056/147] Update maximum wait time in two_node_network test --- tests/app/main.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/tests/app/main.cpp b/tests/app/main.cpp index 7920916e3d..5467e03e89 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -254,12 +254,10 @@ BOOST_AUTO_TEST_CASE( two_node_network ) app1.initialize(app_dir.path(), cfg); BOOST_TEST_MESSAGE( "Starting app1 and waiting 500 ms" ); app1.startup(); - #ifdef NDEBUG - #define NODE_STARTUP_WAIT_TIME (fc::milliseconds(30000)) - #else - #define NODE_STARTUP_WAIT_TIME (fc::milliseconds(120000)) - #endif - fc::wait_for( NODE_STARTUP_WAIT_TIME, [&app1,port] () { + + auto node_startup_wait_time = fc::seconds(15); + + fc::wait_for( node_startup_wait_time, [&app1,port] () { const auto status = app1.p2p_node()->network_get_info(); return status["listening_on"].as( 5 ).port() == port; }); @@ -282,7 +280,7 @@ BOOST_AUTO_TEST_CASE( two_node_network ) BOOST_TEST_MESSAGE( "Starting app2 and waiting for connection" ); app2.startup(); - fc::wait_for( NODE_STARTUP_WAIT_TIME, [&app1] () { return app1.p2p_node()->get_connection_count() > 0; } ); + fc::wait_for( node_startup_wait_time, [&app1] () { return app1.p2p_node()->get_connection_count() > 0; } ); BOOST_REQUIRE_EQUAL(app1.p2p_node()->get_connection_count(), 1u); BOOST_CHECK_EQUAL(std::string(app1.p2p_node()->get_connected_peers().front().host.get_address()), "127.0.0.1"); @@ -331,12 +329,9 @@ BOOST_AUTO_TEST_CASE( two_node_network ) BOOST_TEST_MESSAGE( "Broadcasting tx" ); app1.p2p_node()->broadcast(graphene::net::trx_message(trx)); - #ifdef NDEBUG - #define BROADCAST_WAIT_TIME (fc::milliseconds(15000)) - #else - #define BROADCAST_WAIT_TIME (fc::milliseconds(60000)) - #endif - fc::wait_for( BROADCAST_WAIT_TIME, [db2] () { + auto broadcast_wait_time = fc::seconds(15); + + fc::wait_for( broadcast_wait_time, [db2] () { return db2->get_balance( GRAPHENE_NULL_ACCOUNT, asset_id_type() ).amount.value == 1000000; }); @@ -348,7 +343,7 @@ BOOST_AUTO_TEST_CASE( two_node_network ) fc::ecc::private_key committee_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("nathan"))); // the other node will reject the block if its timestamp is in the future, so we wait - fc::wait_for( BROADCAST_WAIT_TIME, [db2] () { + fc::wait_for( broadcast_wait_time, [db2] () { return db2->get_slot_time(1) <= fc::time_point::now(); }); @@ -365,7 +360,7 @@ BOOST_AUTO_TEST_CASE( two_node_network ) BOOST_TEST_MESSAGE( "Broadcasting block" ); app2.p2p_node()->broadcast(graphene::net::block_message( block_1 )); - fc::wait_for( BROADCAST_WAIT_TIME, [db1] () { + fc::wait_for( broadcast_wait_time, [db1] () { return db1->head_block_num() == 1; }); From 63a6a304630e26a6ea16fc687b4f13048b126699 Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 9 Mar 2021 11:14:55 -0500 Subject: [PATCH 057/147] Update and move messages in two_node_network test --- tests/app/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/app/main.cpp b/tests/app/main.cpp index 5467e03e89..93cf02fabf 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -231,13 +231,13 @@ BOOST_AUTO_TEST_CASE( two_node_network ) fc::configure_logging(logging_config); + // Start app1 + BOOST_TEST_MESSAGE( "Creating and initializing app1" ); + auto port = fc::network::get_available_port(); auto app1_p2p_endpoint_str = string("127.0.0.1:") + std::to_string(port); auto app2_seed_nodes_str = string("[\"") + app1_p2p_endpoint_str + "\"]"; - // Start app1 - BOOST_TEST_MESSAGE( "Creating and initializing app1" ); - fc::temp_directory app_dir( graphene::utilities::temp_directory_path() ); auto genesis_file = create_genesis_file(app_dir); @@ -252,7 +252,7 @@ BOOST_AUTO_TEST_CASE( two_node_network ) cfg.emplace("genesis-json", boost::program_options::variable_value(genesis_file, false)); cfg.emplace("seed-nodes", boost::program_options::variable_value(string("[]"), false)); app1.initialize(app_dir.path(), cfg); - BOOST_TEST_MESSAGE( "Starting app1 and waiting 500 ms" ); + BOOST_TEST_MESSAGE( "Starting app1 and waiting" ); app1.startup(); auto node_startup_wait_time = fc::seconds(15); From ecc8a0dec542548c7a3f8b8b944f9eb2464bf4b8 Mon Sep 17 00:00:00 2001 From: abitmore Date: Wed, 10 Mar 2021 14:07:59 -0500 Subject: [PATCH 058/147] Return peer sync status in get_connected_peers() and use it in app_test --- libraries/net/node.cpp | 3 +++ tests/app/main.cpp | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 16d16e5468..f9ec45f0d8 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -4653,6 +4653,9 @@ namespace graphene { namespace net { namespace detail { peer_details["current_head_block_number"] = _delegate->get_block_number(peer->last_block_delegate_has_seen); peer_details["current_head_block_time"] = peer->last_block_time_delegate_has_seen; + peer_details["peer_needs_sync_items_from_us"] = peer->peer_needs_sync_items_from_us; + peer_details["we_need_sync_items_from_peer"] = peer->we_need_sync_items_from_peer; + this_peer_status.info = peer_details; statuses.push_back(this_peer_status); } diff --git a/tests/app/main.cpp b/tests/app/main.cpp index 93cf02fabf..27291dee98 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -280,7 +280,19 @@ BOOST_AUTO_TEST_CASE( two_node_network ) BOOST_TEST_MESSAGE( "Starting app2 and waiting for connection" ); app2.startup(); - fc::wait_for( node_startup_wait_time, [&app1] () { return app1.p2p_node()->get_connection_count() > 0; } ); + fc::wait_for( node_startup_wait_time, [&app1] () { + if( app1.p2p_node()->get_connection_count() > 0 ) + { + auto peers = app1.p2p_node()->get_connected_peers(); + BOOST_REQUIRE_EQUAL( peers.size(), 1u ); + const auto& peer_info = peers.front().info; + auto itr = peer_info.find( "peer_needs_sync_items_from_us" ); + if( itr == peer_info.end() ) + return false; + return !itr->value().as(1); + } + return false; + }); BOOST_REQUIRE_EQUAL(app1.p2p_node()->get_connection_count(), 1u); BOOST_CHECK_EQUAL(std::string(app1.p2p_node()->get_connected_peers().front().host.get_address()), "127.0.0.1"); From c3b7662e9dc5f505581a3cba8358b47f2cd7ef49 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 14 Mar 2021 16:43:56 -0400 Subject: [PATCH 059/147] Remove actor from htlc_hardfork_test, fix the test The actor is not used in the test case, however the random votes it casts causes random failures. --- tests/tests/htlc_tests.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/tests/htlc_tests.cpp b/tests/tests/htlc_tests.cpp index 1e27e051d1..ce8a1430a8 100644 --- a/tests/tests/htlc_tests.cpp +++ b/tests/tests/htlc_tests.cpp @@ -665,9 +665,7 @@ try { BOOST_AUTO_TEST_CASE( htlc_hardfork_test ) { try { - ACTORS( (alice) ); - int64_t init_balance(10000 * GRAPHENE_BLOCKCHAIN_PRECISION); - transfer( committee_account, alice_id, graphene::chain::asset(init_balance) ); + { // try to set committee parameters before hardfork proposal_create_operation cop = proposal_create_operation::committee_proposal( From 3ea93ba0d67797119afc1bb6248f00d165fd5427 Mon Sep 17 00:00:00 2001 From: Abit Date: Mon, 15 Mar 2021 23:43:13 +0100 Subject: [PATCH 060/147] Update comment about lp_exch_op market fee sharing --- libraries/chain/liquidity_pool_evaluator.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/chain/liquidity_pool_evaluator.cpp b/libraries/chain/liquidity_pool_evaluator.cpp index 07fba7d53c..0a18e40526 100644 --- a/libraries/chain/liquidity_pool_evaluator.cpp +++ b/libraries/chain/liquidity_pool_evaluator.cpp @@ -374,7 +374,9 @@ generic_exchange_operation_result liquidity_pool_exchange_evaluator::do_apply( d.adjust_balance( op.account, -op.amount_to_sell ); d.adjust_balance( op.account, _account_receives ); - // TODO whose registrar and referrer should receive the shared maker market fee? + // For _pool_receives_asset, if market fee sharing is enabled, + // the share asset owner's registrar and referrer get the shared maker market fee; + // for _pool_pays_asset, it's the trader's registrar and referrer. d.pay_market_fees( &_pool->share_asset(d).issuer(d), *_pool_receives_asset, op.amount_to_sell, true, _maker_market_fee ); d.pay_market_fees( fee_paying_account, *_pool_pays_asset, _pool_pays, false, _taker_market_fee ); From 06aace89d929fea04777f7843c29053f207ad307 Mon Sep 17 00:00:00 2001 From: Abit Date: Tue, 16 Mar 2021 01:30:22 +0100 Subject: [PATCH 061/147] Avoid using semicolons in comments --- libraries/chain/liquidity_pool_evaluator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/chain/liquidity_pool_evaluator.cpp b/libraries/chain/liquidity_pool_evaluator.cpp index 0a18e40526..f17da5636b 100644 --- a/libraries/chain/liquidity_pool_evaluator.cpp +++ b/libraries/chain/liquidity_pool_evaluator.cpp @@ -375,8 +375,8 @@ generic_exchange_operation_result liquidity_pool_exchange_evaluator::do_apply( d.adjust_balance( op.account, _account_receives ); // For _pool_receives_asset, if market fee sharing is enabled, - // the share asset owner's registrar and referrer get the shared maker market fee; - // for _pool_pays_asset, it's the trader's registrar and referrer. + // the share asset owner's registrar and referrer get the shared maker market fee. + // For _pool_pays_asset, it's the trader's registrar and referrer. d.pay_market_fees( &_pool->share_asset(d).issuer(d), *_pool_receives_asset, op.amount_to_sell, true, _maker_market_fee ); d.pay_market_fees( fee_paying_account, *_pool_pays_asset, _pool_pays, false, _taker_market_fee ); From f0f586e7a6dfc240d11709bf5ffe6b99a5c31496 Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 16 Mar 2021 14:21:19 -0400 Subject: [PATCH 062/147] Use concurrent_unordered_set for _new_inventory --- libraries/net/node.cpp | 2 +- libraries/net/node_impl.hxx | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index f9ec45f0d8..cdabcf6ba2 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -780,7 +780,7 @@ namespace graphene { namespace net { namespace detail { dlog("beginning an iteration of advertise inventory"); // swap inventory into local variable, clearing the node's copy std::unordered_set inventory_to_advertise; - inventory_to_advertise.swap(_new_inventory); + _new_inventory.swap( inventory_to_advertise ); // process all inventory to advertise and construct the inventory messages we'll send // first, then send them all in a batch (to avoid any fiber interruption points while diff --git a/libraries/net/node_impl.hxx b/libraries/net/node_impl.hxx index a106cbc019..1d4b0ac63a 100644 --- a/libraries/net/node_impl.hxx +++ b/libraries/net/node_impl.hxx @@ -64,6 +64,12 @@ public: fc::scoped_lock lock(mux); return std::unordered_set::erase( key ); } + // swap + void swap( typename std::unordered_set& other ) + { + fc::scoped_lock lock(mux); + std::unordered_set::swap( other ); + } // iteration typename std::unordered_set::iterator begin() noexcept { @@ -335,11 +341,12 @@ class node_impl : public peer_connection_delegate // @} /// used by the task that advertises inventory during normal operation - // @{ + /// @{ fc::promise::ptr _retrigger_advertise_inventory_loop_promise; fc::future _advertise_inventory_loop_done; - std::unordered_set _new_inventory; /// list of items we have received but not yet advertised to our peers - // @} + /// list of items we have received but not yet advertised to our peers + concurrent_unordered_set _new_inventory; + /// @} fc::future _terminate_inactive_connections_loop_done; uint8_t _recent_block_interval_in_seconds; // a cached copy of the block interval, to avoid a thread hop to the blockchain to get the current value From 46d9bb0c13500c40a3aa5437676195154a4db09f Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 16 Mar 2021 16:47:17 -0400 Subject: [PATCH 063/147] Let concurrent_unordered_set::swap() be noexcept --- libraries/net/node_impl.hxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/net/node_impl.hxx b/libraries/net/node_impl.hxx index 1d4b0ac63a..f1f44b6046 100644 --- a/libraries/net/node_impl.hxx +++ b/libraries/net/node_impl.hxx @@ -65,7 +65,7 @@ public: return std::unordered_set::erase( key ); } // swap - void swap( typename std::unordered_set& other ) + void swap( typename std::unordered_set& other ) noexcept { fc::scoped_lock lock(mux); std::unordered_set::swap( other ); From b323f27d329476bd6170c07af1b97c004fb16605 Mon Sep 17 00:00:00 2001 From: Abit Date: Wed, 17 Mar 2021 23:17:35 +0100 Subject: [PATCH 064/147] Update comment --- libraries/chain/liquidity_pool_evaluator.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/chain/liquidity_pool_evaluator.cpp b/libraries/chain/liquidity_pool_evaluator.cpp index f17da5636b..24619e725d 100644 --- a/libraries/chain/liquidity_pool_evaluator.cpp +++ b/libraries/chain/liquidity_pool_evaluator.cpp @@ -375,8 +375,9 @@ generic_exchange_operation_result liquidity_pool_exchange_evaluator::do_apply( d.adjust_balance( op.account, _account_receives ); // For _pool_receives_asset, if market fee sharing is enabled, - // the share asset owner's registrar and referrer get the shared maker market fee. - // For _pool_pays_asset, it's the trader's registrar and referrer. + // the share asset owner's registrar and referrer will get the shared maker market fee. + // For _pool_pays_asset, if market fee sharing is enabled, + // the trader's registrar and referrer will get the shared taker market fee. d.pay_market_fees( &_pool->share_asset(d).issuer(d), *_pool_receives_asset, op.amount_to_sell, true, _maker_market_fee ); d.pay_market_fees( fee_paying_account, *_pool_pays_asset, _pool_pays, false, _taker_market_fee ); From d2f0ac1f69c9c5849e1332c923f5ce79a73ab972 Mon Sep 17 00:00:00 2001 From: abitmore Date: Thu, 18 Mar 2021 19:29:48 -0400 Subject: [PATCH 065/147] Prettify more operations in account history in CLI - asset_update_feed_producers_operation - asset_publish_feed_operation - asset_fund_fee_pool_operation - asset_claim_pool_operation --- libraries/wallet/operation_printer.cpp | 44 ++++++++++++++++++++++++++ libraries/wallet/operation_printer.hpp | 4 +++ 2 files changed, 48 insertions(+) diff --git a/libraries/wallet/operation_printer.cpp b/libraries/wallet/operation_printer.cpp index 65ee4b4336..9faa2ee047 100644 --- a/libraries/wallet/operation_printer.cpp +++ b/libraries/wallet/operation_printer.cpp @@ -238,6 +238,50 @@ std::string operation_printer::operator()(const asset_settle_operation& op) cons return ""; } +std::string operation_printer::operator()(const asset_fund_fee_pool_operation& op) const +{ + out << "Fund " << format_asset(op.amount) << " into asset fee pool of " + << wallet.get_asset(op.asset_id).symbol; + print_fee(op.fee); + print_result(); + return ""; +} + +std::string operation_printer::operator()(const asset_claim_pool_operation& op) const +{ + out << "Claim " << format_asset(op.amount_to_claim) << " from asset fee pool of " + << wallet.get_asset(op.asset_id).symbol; + print_fee(op.fee); + print_result(); + return ""; +} + +std::string operation_printer::operator()(const asset_update_feed_producers_operation& op) const +{ + out << "Update price feed producers of asset " << wallet.get_asset(op.asset_to_update).symbol + << " to "; + vector accounts; + accounts.reserve( op.new_feed_producers.size() ); + for( const auto& account_id : op.new_feed_producers ) + { + accounts.push_back( wallet.get_account( account_id ).name ); + } + out << fc::json::to_string(accounts); + print_fee(op.fee); + print_result(); + return ""; +} + +std::string operation_printer::operator()(const asset_publish_feed_operation& op) const +{ + // TODO prettify the price + out << "Publish price feed " << format_asset(op.feed.settlement_price.base) + << " / " << format_asset(op.feed.settlement_price.quote); + print_fee(op.fee); + print_result(); + return ""; +} + std::string operation_printer::operator()(const call_order_update_operation& op) const { out << "Adjust debt position with delta debt amount " << format_asset(op.delta_debt) diff --git a/libraries/wallet/operation_printer.hpp b/libraries/wallet/operation_printer.hpp index 335734faee..a0520dc5ab 100644 --- a/libraries/wallet/operation_printer.hpp +++ b/libraries/wallet/operation_printer.hpp @@ -99,6 +99,10 @@ struct operation_printer std::string operator()(const graphene::protocol::asset_create_operation& op)const; std::string operator()(const graphene::protocol::asset_update_operation& op)const; std::string operator()(const graphene::protocol::asset_update_bitasset_operation& op)const; + std::string operator()(const graphene::protocol::asset_update_feed_producers_operation& op)const; + std::string operator()(const graphene::protocol::asset_publish_feed_operation& op)const; + std::string operator()(const graphene::protocol::asset_fund_fee_pool_operation& op)const; + std::string operator()(const graphene::protocol::asset_claim_pool_operation& op)const; std::string operator()(const graphene::protocol::asset_issue_operation& op)const; std::string operator()(const graphene::protocol::asset_reserve_operation& op)const; std::string operator()(const graphene::protocol::asset_settle_operation& op)const; From 6465f162b92ff4026a3d6a51344eec79d21ceb73 Mon Sep 17 00:00:00 2001 From: abitmore Date: Thu, 18 Mar 2021 19:32:35 -0400 Subject: [PATCH 066/147] Add CLI test cases --- tests/cli/main.cpp | 144 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 133 insertions(+), 11 deletions(-) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index 87ec50c757..5b856916db 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -468,8 +468,47 @@ BOOST_FIXTURE_TEST_CASE( mpa_tests, cli_fixture ) { BOOST_FAIL("Unknown exception creating BOBCOIN"); } + BOOST_CHECK(generate_block(app1)); + + auto check_nathan_last_history = [&]( string keyword ) { + auto history = con.wallet_api_ptr->get_relative_account_history("nathan", 0, 1, 0); + BOOST_REQUIRE_GT( history.size(), 0 ); + BOOST_CHECK( history[0].description.find( keyword ) != string::npos ); + }; + + check_nathan_last_history( "Create BitAsset" ); + check_nathan_last_history( "BOBCOIN" ); auto bobcoin = con.wallet_api_ptr->get_asset("BOBCOIN"); + { + // Update asset + BOOST_TEST_MESSAGE("Update asset"); + auto options = bobcoin.options; + BOOST_CHECK_EQUAL( options.max_supply.value, 1000000 ); + options.max_supply = 2000000; + con.wallet_api_ptr->update_asset("BOBCOIN", {}, options, true); + // Check + bobcoin = con.wallet_api_ptr->get_asset("BOBCOIN"); + BOOST_CHECK_EQUAL( bobcoin.options.max_supply.value, 2000000 ); + } + BOOST_CHECK(generate_block(app1)); + check_nathan_last_history( "Update asset" ); + + auto bitbobcoin = con.wallet_api_ptr->get_bitasset_data("BOBCOIN"); + { + // Update bitasset + BOOST_TEST_MESSAGE("Update bitasset"); + auto bitoptions = bitbobcoin.options; + BOOST_CHECK_EQUAL( bitoptions.feed_lifetime_sec, uint32_t(GRAPHENE_DEFAULT_PRICE_FEED_LIFETIME) ); + bitoptions.feed_lifetime_sec = 3600u; + con.wallet_api_ptr->update_bitasset("BOBCOIN", bitoptions, true); + // Check + bitbobcoin = con.wallet_api_ptr->get_bitasset_data("BOBCOIN"); + BOOST_CHECK_EQUAL( bitbobcoin.options.feed_lifetime_sec, 3600u ); + } + BOOST_CHECK(generate_block(app1)); + check_nathan_last_history( "Update bitasset" ); + { // Play with asset fee pool auto objs = con.wallet_api_ptr->get_object( bobcoin.dynamic_asset_data_id ) @@ -489,6 +528,9 @@ BOOST_FIXTURE_TEST_CASE( mpa_tests, cli_fixture ) share_type funded_pool = bobcoin_dyn.fee_pool; BOOST_CHECK_EQUAL( funded_pool.value, old_pool.value + GRAPHENE_BLOCKCHAIN_PRECISION * 2 ); + BOOST_CHECK(generate_block(app1)); + check_nathan_last_history( "Fund" ); + BOOST_TEST_MESSAGE("Claim fee pool"); con.wallet_api_ptr->claim_asset_fee_pool("BOBCOIN", "1", true); objs = con.wallet_api_ptr->get_object( bobcoin.dynamic_asset_data_id ) @@ -497,6 +539,9 @@ BOOST_FIXTURE_TEST_CASE( mpa_tests, cli_fixture ) bobcoin_dyn = objs[0]; share_type claimed_pool = bobcoin_dyn.fee_pool; BOOST_CHECK_EQUAL( claimed_pool.value, old_pool.value + GRAPHENE_BLOCKCHAIN_PRECISION ); + + BOOST_CHECK(generate_block(app1)); + check_nathan_last_history( "Claim" ); } { @@ -517,6 +562,9 @@ BOOST_FIXTURE_TEST_CASE( mpa_tests, cli_fixture ) bob_bitasset = con.wallet_api_ptr->get_bitasset_data( "BOBCOIN" ); BOOST_CHECK_EQUAL( bob_bitasset.feeds.size(), 1u ); BOOST_CHECK( bob_bitasset.current_feed.settlement_price.is_null() ); + + BOOST_CHECK(generate_block(app1)); + check_nathan_last_history( "Update price feed producers" ); } { @@ -528,17 +576,13 @@ BOOST_FIXTURE_TEST_CASE( mpa_tests, cli_fixture ) con.wallet_api_ptr->publish_asset_feed( "nathan", "BOBCOIN", feed, true ); asset_bitasset_data_object bob_bitasset = con.wallet_api_ptr->get_bitasset_data( "BOBCOIN" ); BOOST_CHECK( bob_bitasset.current_feed.settlement_price == feed.settlement_price ); - } - { - // Borrow - BOOST_TEST_MESSAGE("Borrow BOBCOIN"); - auto calls = con.wallet_api_ptr->get_call_orders( "BOBCOIN", 10 ); - BOOST_CHECK_EQUAL( calls.size(), 0u ); - con.wallet_api_ptr->borrow_asset( "nathan", "1", "BOBCOIN", "10", true ); - calls = con.wallet_api_ptr->get_call_orders( "BOBCOIN", 10 ); - BOOST_CHECK_EQUAL( calls.size(), 1u ); + BOOST_CHECK(generate_block(app1)); + check_nathan_last_history( "Publish price feed" ); + } + bool balance_formatter_tested = false; + auto check_nathan_bobcoin_balance = [&](int64_t amount) { auto nathan_balances = con.wallet_api_ptr->list_account_balances( "nathan" ); size_t count = 0; for( auto& bal : nathan_balances ) @@ -546,19 +590,97 @@ BOOST_FIXTURE_TEST_CASE( mpa_tests, cli_fixture ) if( bal.asset_id == bobcoin.id ) { ++count; - BOOST_CHECK_EQUAL( bal.amount.value, 10000 ); + BOOST_CHECK_EQUAL( bal.amount.value, amount ); } } BOOST_CHECK_EQUAL(count, 1u); // Testing result formatter - if( formatters.find("list_account_balances") != formatters.end() ) + if( !balance_formatter_tested && formatters.find("list_account_balances") != formatters.end() ) { BOOST_TEST_MESSAGE("Testing formatter of list_account_balances"); string output = formatters["list_account_balances"]( fc::variant(nathan_balances, FC_PACK_MAX_DEPTH ), fc::variants()); BOOST_CHECK( output.find("BOBCOIN") != string::npos ); + balance_formatter_tested = true; } + }; + + { + // Borrow + BOOST_TEST_MESSAGE("Borrow BOBCOIN"); + auto calls = con.wallet_api_ptr->get_call_orders( "BOBCOIN", 10 ); + BOOST_CHECK_EQUAL( calls.size(), 0u ); + con.wallet_api_ptr->borrow_asset( "nathan", "1", "BOBCOIN", "10", true ); + calls = con.wallet_api_ptr->get_call_orders( "BOBCOIN", 10 ); + BOOST_REQUIRE_EQUAL( calls.size(), 1u ); + BOOST_CHECK_EQUAL( calls.front().debt.value, 10000 ); + + BOOST_CHECK(generate_block(app1)); + check_nathan_bobcoin_balance( 10000 ); + check_nathan_last_history( "Adjust debt position" ); + } + + { + // Settle + BOOST_TEST_MESSAGE("Settle BOBCOIN"); + auto settles = con.wallet_api_ptr->get_settle_orders( "BOBCOIN", 10 ); + BOOST_CHECK_EQUAL( settles.size(), 0u ); + con.wallet_api_ptr->settle_asset( "nathan", "0.2", "BOBCOIN", true ); + settles = con.wallet_api_ptr->get_settle_orders( "BOBCOIN", 10 ); + BOOST_REQUIRE_EQUAL( settles.size(), 1u ); + BOOST_CHECK_EQUAL( settles.front().balance.amount.value, 2000 ); + + BOOST_CHECK(generate_block(app1)); + check_nathan_bobcoin_balance( 8000 ); + check_nathan_last_history( "Force-settle" ); + } + + { + // Transfer + BOOST_TEST_MESSAGE("Transfer some BOBCOIN to init0"); + con.wallet_api_ptr->transfer2( "nathan", "init0", "0.5", "BOBCOIN", "" ); + con.wallet_api_ptr->transfer( "nathan", "init0", "10000", "1.3.0", "" ); + + BOOST_CHECK(generate_block(app1)); + check_nathan_bobcoin_balance( 3000 ); + check_nathan_last_history( "Transfer" ); + + } + + { + // Nathan places an order + BOOST_TEST_MESSAGE("Nathan place an order to buy BOBCOIN"); + auto orders = con.wallet_api_ptr->get_limit_orders( "BOBCOIN", "1.3.0", 10 ); + BOOST_CHECK_EQUAL( orders.size(), 0u ); + con.wallet_api_ptr->sell_asset( "nathan", "100", "1.3.0", "1", "BOBCOIN", 300, false, true ); + orders = con.wallet_api_ptr->get_limit_orders( "BOBCOIN", "1.3.0", 10 ); + BOOST_REQUIRE_EQUAL( orders.size(), 1u ); + BOOST_CHECK_EQUAL( orders.front().for_sale.value, 100 * GRAPHENE_BLOCKCHAIN_PRECISION ); + limit_order_id_type nathan_order_id = orders.front().id; + + BOOST_CHECK(generate_block(app1)); + check_nathan_bobcoin_balance( 3000 ); + check_nathan_last_history( "Create limit order" ); + + // init0 place an order to partially fill Nathan's order + BOOST_TEST_MESSAGE("init0 place an order to sell BOBCOIN"); + con.wallet_api_ptr->sell_asset( "init0", "0.1", "BOBCOIN", "1", "1.3.0", 200, true, true ); + orders = con.wallet_api_ptr->get_limit_orders( "BOBCOIN", "1.3.0", 10 ); + BOOST_REQUIRE_EQUAL( orders.size(), 1u ); + BOOST_CHECK_EQUAL( orders.front().for_sale.value, 90 * GRAPHENE_BLOCKCHAIN_PRECISION ); + + BOOST_CHECK(generate_block(app1)); + check_nathan_bobcoin_balance( 4000 ); + check_nathan_last_history( "as maker" ); + + // Nathan cancel order + BOOST_TEST_MESSAGE("Nathan cancel order"); + con.wallet_api_ptr->cancel_order( nathan_order_id, true ); + + BOOST_CHECK(generate_block(app1)); + check_nathan_bobcoin_balance( 4000 ); + check_nathan_last_history( "Cancel limit order" ); } } catch( fc::exception& e ) { From 69f395eb688d91abcf671c0aaa55aa0b633cbdc4 Mon Sep 17 00:00:00 2001 From: abitmore Date: Thu, 18 Mar 2021 19:43:57 -0400 Subject: [PATCH 067/147] Update CLI limit order tests --- tests/cli/main.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index 5b856916db..ca24aff710 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -582,10 +582,10 @@ BOOST_FIXTURE_TEST_CASE( mpa_tests, cli_fixture ) } bool balance_formatter_tested = false; - auto check_nathan_bobcoin_balance = [&](int64_t amount) { - auto nathan_balances = con.wallet_api_ptr->list_account_balances( "nathan" ); + auto check_bobcoin_balance = [&](string account, int64_t amount) { + auto balances = con.wallet_api_ptr->list_account_balances( account ); size_t count = 0; - for( auto& bal : nathan_balances ) + for( auto& bal : balances ) { if( bal.asset_id == bobcoin.id ) { @@ -600,11 +600,14 @@ BOOST_FIXTURE_TEST_CASE( mpa_tests, cli_fixture ) { BOOST_TEST_MESSAGE("Testing formatter of list_account_balances"); string output = formatters["list_account_balances"]( - fc::variant(nathan_balances, FC_PACK_MAX_DEPTH ), fc::variants()); + fc::variant(balances, FC_PACK_MAX_DEPTH ), fc::variants()); BOOST_CHECK( output.find("BOBCOIN") != string::npos ); balance_formatter_tested = true; } }; + auto check_nathan_bobcoin_balance = [&](int64_t amount) { + check_bobcoin_balance( "nathan", amount ); + }; { // Borrow @@ -643,6 +646,7 @@ BOOST_FIXTURE_TEST_CASE( mpa_tests, cli_fixture ) con.wallet_api_ptr->transfer( "nathan", "init0", "10000", "1.3.0", "" ); BOOST_CHECK(generate_block(app1)); + check_bobcoin_balance( "init0", 5000 ); check_nathan_bobcoin_balance( 3000 ); check_nathan_last_history( "Transfer" ); @@ -671,12 +675,15 @@ BOOST_FIXTURE_TEST_CASE( mpa_tests, cli_fixture ) BOOST_CHECK_EQUAL( orders.front().for_sale.value, 90 * GRAPHENE_BLOCKCHAIN_PRECISION ); BOOST_CHECK(generate_block(app1)); + check_bobcoin_balance( "init0", 4000 ); check_nathan_bobcoin_balance( 4000 ); check_nathan_last_history( "as maker" ); // Nathan cancel order BOOST_TEST_MESSAGE("Nathan cancel order"); con.wallet_api_ptr->cancel_order( nathan_order_id, true ); + orders = con.wallet_api_ptr->get_limit_orders( "BOBCOIN", "1.3.0", 10 ); + BOOST_CHECK_EQUAL( orders.size(), 0u ); BOOST_CHECK(generate_block(app1)); check_nathan_bobcoin_balance( 4000 ); From 974190010d0457989ea4c54ec8eb88feedbc37e7 Mon Sep 17 00:00:00 2001 From: abitmore Date: Fri, 19 Mar 2021 08:50:27 -0400 Subject: [PATCH 068/147] Remove temp files in sonar-scan workflow --- .github/workflows/sonar-scan.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/sonar-scan.yml b/.github/workflows/sonar-scan.yml index 3236d95a55..8f045a361f 100644 --- a/.github/workflows/sonar-scan.yml +++ b/.github/workflows/sonar-scan.yml @@ -126,6 +126,9 @@ jobs: libraries/fc/tests/run-parallel-tests.sh _build/tests/chain_test -l test_suite _build/tests/cli_test -l test_suite df -h + echo "Cleanup" + rm -rf /tmp/graphene* + df -h - name: Prepare for scanning with SonarScanner run: | mkdir -p sonar_cache From aecfed0c1f0e96325ab7860caaf0d2275efc3f9f Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 21 Mar 2021 08:28:27 -0400 Subject: [PATCH 069/147] Fix typo in docs of CLI read_memo command --- libraries/wallet/include/graphene/wallet/wallet.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index c7933a58ea..c3a0d3a561 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -811,7 +811,7 @@ class wallet_api /** Read a memo. * - * @param memo JSON-enconded memo. + * @param memo JSON-encoded memo. * @returns string with decrypted message. */ string read_memo(const memo_data& memo); From 021dd8c9242ccd6464debbc94301cf080b32a993 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 21 Mar 2021 08:29:00 -0400 Subject: [PATCH 070/147] Update formatter of override_transfer in CLI --- libraries/wallet/operation_printer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/wallet/operation_printer.cpp b/libraries/wallet/operation_printer.cpp index 9faa2ee047..8d5baace58 100644 --- a/libraries/wallet/operation_printer.cpp +++ b/libraries/wallet/operation_printer.cpp @@ -162,7 +162,7 @@ string operation_printer::operator()(const transfer_operation& op) const string operation_printer::operator()(const override_transfer_operation& op) const { out << wallet.get_account(op.issuer).name - << " transfer " << format_asset(op.amount) + << " force-transfer " << format_asset(op.amount) << " from " << wallet.get_account(op.from).name << " to " << wallet.get_account(op.to).name; std::string memo = print_memo( op.memo ); print_fee(op.fee); From bd8bd2b86ae240bf3a9511aba3af05dd65478d43 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 21 Mar 2021 08:29:47 -0400 Subject: [PATCH 071/147] Add uia_tests in cli_test --- tests/cli/main.cpp | 131 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index ca24aff710..6063f6fed3 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -429,6 +429,137 @@ BOOST_FIXTURE_TEST_CASE( create_new_account, cli_fixture ) } } +BOOST_FIXTURE_TEST_CASE( uia_tests, cli_fixture ) +{ + try + { + BOOST_TEST_MESSAGE("Cli UIA Tests"); + + INVOKE(upgrade_nathan_account); + + account_object nathan_acct = con.wallet_api_ptr->get_account("nathan"); + + auto formatters = con.wallet_api_ptr->get_result_formatters(); + + auto check_account_last_history = [&]( string account, string keyword ) { + auto history = con.wallet_api_ptr->get_relative_account_history(account, 0, 1, 0); + BOOST_REQUIRE_GT( history.size(), 0 ); + BOOST_CHECK( history[0].description.find( keyword ) != string::npos ); + }; + auto check_nathan_last_history = [&]( string keyword ) { + check_account_last_history( "nathan", keyword ); + }; + + // Create new asset called BOBCOIN + { + BOOST_TEST_MESSAGE("Create UIA 'BOBCOIN'"); + graphene::chain::asset_options asset_ops; + asset_ops.issuer_permissions = DEFAULT_UIA_ASSET_ISSUER_PERMISSION; + asset_ops.flags = charge_market_fee | override_authority; + asset_ops.max_supply = 1000000; + asset_ops.core_exchange_rate = price(asset(2),asset(1,asset_id_type(1))); + auto result = con.wallet_api_ptr->create_asset("nathan", "BOBCOIN", 4, asset_ops, {}, true); + if( formatters.find("create_asset") != formatters.end() ) + { + BOOST_TEST_MESSAGE("Testing formatter of create_asset"); + string output = formatters["create_asset"]( + fc::variant(result, FC_PACK_MAX_DEPTH), fc::variants()); + BOOST_CHECK( output.find("BOBCOIN") != string::npos ); + } + } + BOOST_CHECK(generate_block(app1)); + + check_nathan_last_history( "Create User-Issue Asset" ); + check_nathan_last_history( "BOBCOIN" ); + + auto bobcoin = con.wallet_api_ptr->get_asset("BOBCOIN"); + + bool balance_formatter_tested = false; + auto check_bobcoin_balance = [&](string account, int64_t amount) { + auto balances = con.wallet_api_ptr->list_account_balances( account ); + size_t count = 0; + for( auto& bal : balances ) + { + if( bal.asset_id == bobcoin.id ) + { + ++count; + BOOST_CHECK_EQUAL( bal.amount.value, amount ); + } + } + BOOST_CHECK_EQUAL(count, 1u); + + // Testing result formatter + if( !balance_formatter_tested && formatters.find("list_account_balances") != formatters.end() ) + { + BOOST_TEST_MESSAGE("Testing formatter of list_account_balances"); + string output = formatters["list_account_balances"]( + fc::variant(balances, FC_PACK_MAX_DEPTH ), fc::variants()); + BOOST_CHECK( output.find("BOBCOIN") != string::npos ); + balance_formatter_tested = true; + } + }; + auto check_nathan_bobcoin_balance = [&](int64_t amount) { + check_bobcoin_balance( "nathan", amount ); + }; + + { + // Issue asset + BOOST_TEST_MESSAGE("Issue asset"); + con.wallet_api_ptr->issue_asset("init0", "3", "BOBCOIN", "new coin for you", true); + } + BOOST_CHECK(generate_block(app1)); + + check_nathan_last_history( "nathan issue 3 BOBCOIN to init0" ); + check_nathan_last_history( "new coin for you" ); + check_account_last_history( "init0", "nathan issue 3 BOBCOIN to init0" ); + check_account_last_history( "init0", "new coin for you" ); + + check_bobcoin_balance( "init0", 30000 ); + + { + // Override transfer + BOOST_TEST_MESSAGE("Override-transfer BOBCOIN from init0"); + auto handle = con.wallet_api_ptr->begin_builder_transaction(); + override_transfer_operation op; + op.issuer = con.wallet_api_ptr->get_account( "nathan" ).id; + op.from = con.wallet_api_ptr->get_account( "init0" ).id; + op.to = con.wallet_api_ptr->get_account( "nathan" ).id; + op.amount = bobcoin.amount(10000); + op.memo = con.wallet_api_ptr->sign_memo( "nathan", "init0", "get back some coin" ); + con.wallet_api_ptr->add_operation_to_builder_transaction( handle, op ); + con.wallet_api_ptr->set_fees_on_builder_transaction( handle, "1.3.0" ); + con.wallet_api_ptr->sign_builder_transaction( handle, true ); + + auto memo = con.wallet_api_ptr->read_memo( *op.memo ); + BOOST_CHECK_EQUAL( memo, "get back some coin" ); + } + BOOST_CHECK(generate_block(app1)); + + check_nathan_last_history( "nathan force-transfer 1 BOBCOIN from init0 to nathan" ); + check_nathan_last_history( "get back some coin" ); + check_account_last_history( "init0", "nathan force-transfer 1 BOBCOIN from init0 to nathan" ); + check_account_last_history( "init0", "get back some coin" ); + + check_bobcoin_balance( "init0", 20000 ); + check_bobcoin_balance( "nathan", 10000 ); + + { + // Reserve / burn asset + BOOST_TEST_MESSAGE("Reserve/burn asset"); + con.wallet_api_ptr->reserve_asset("nathan", "1", "BOBCOIN", true); + } + BOOST_CHECK(generate_block(app1)); + + check_nathan_last_history( "Reserve (burn) 1 BOBCOIN" ); + + check_nathan_bobcoin_balance( 0 ); + + } catch( fc::exception& e ) { + edump((e.to_detail_string())); + throw; + } +} + BOOST_FIXTURE_TEST_CASE( mpa_tests, cli_fixture ) { try From a46e3c6a64812bef7892b04274148a781ba5584e Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 21 Mar 2021 11:19:13 -0400 Subject: [PATCH 072/147] Fix sign_memo command for signing with public keys --- .../wallet/include/graphene/wallet/wallet.hpp | 4 ++-- libraries/wallet/wallet_sign.cpp | 23 ++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index c3a0d3a561..eb7b6b6f1d 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -802,8 +802,8 @@ class wallet_api /** Sign a memo message. * - * @param from the name or id of signing account; or a public key - * @param to the name or id of receiving account; or a public key + * @param from the name or id of signing account, or a public key, or a label of a public key + * @param to the name or id of receiving account, or a public key, or a label of a public key * @param memo text to sign * @return the signed memo data */ diff --git a/libraries/wallet/wallet_sign.cpp b/libraries/wallet/wallet_sign.cpp index e34dae7ed8..091815463d 100644 --- a/libraries/wallet/wallet_sign.cpp +++ b/libraries/wallet/wallet_sign.cpp @@ -139,17 +139,34 @@ namespace graphene { namespace wallet { namespace detail { account_object from_account = get_account(from); md.from = from_account.options.memo_key; } catch (const fc::exception& e) { - md.from = self.get_public_key( from ); + // check if the string itself is a pubkey, if not, consider it as a label + try { + md.from = public_key_type( from ); + } catch (const fc::exception& e) { + md.from = self.get_public_key( from ); + } } // same as above, for destination key try { account_object to_account = get_account(to); md.to = to_account.options.memo_key; } catch (const fc::exception& e) { - md.to = self.get_public_key( to ); + // check if the string itself is a pubkey, if not, consider it as a label + try { + md.to = public_key_type( to ); + } catch (const fc::exception& e) { + md.to = self.get_public_key( to ); + } } - md.set_message(get_private_key(md.from), md.to, memo); + // try to get private key of from and sign, if that fails, try to sign with to + try { + md.set_message(get_private_key(md.from), md.to, memo); + } catch (const fc::exception& e) { + std::swap( md.from, md.to ); + md.set_message(get_private_key(md.from), md.to, memo); + std::swap( md.from, md.to ); + } return md; } From 61bdcf0d31b0b4b0b6f9c1213a39b98cd81ddbdf Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 21 Mar 2021 11:28:32 -0400 Subject: [PATCH 073/147] Add CLI test cases - more tests about read_memo and sign_memo - formatter of account_update_operation in account history - result formatter for SHA256 hashes in HTLC operations --- tests/cli/main.cpp | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index 6063f6fed3..e4253121ea 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -517,7 +517,7 @@ BOOST_FIXTURE_TEST_CASE( uia_tests, cli_fixture ) check_bobcoin_balance( "init0", 30000 ); { - // Override transfer + // Override transfer, and test sign_memo and read_memo by the way BOOST_TEST_MESSAGE("Override-transfer BOBCOIN from init0"); auto handle = con.wallet_api_ptr->begin_builder_transaction(); override_transfer_operation op; @@ -525,13 +525,29 @@ BOOST_FIXTURE_TEST_CASE( uia_tests, cli_fixture ) op.from = con.wallet_api_ptr->get_account( "init0" ).id; op.to = con.wallet_api_ptr->get_account( "nathan" ).id; op.amount = bobcoin.amount(10000); - op.memo = con.wallet_api_ptr->sign_memo( "nathan", "init0", "get back some coin" ); + + const auto test_bki = con.wallet_api_ptr->suggest_brain_key(); + auto test_pubkey = fc::json::to_string( test_bki.pub_key ); + test_pubkey = test_pubkey.substr( 1, test_pubkey.size() - 2 ); + idump( (test_pubkey) ); + op.memo = con.wallet_api_ptr->sign_memo( test_pubkey, "nathan", "get back some coin" ); + idump( (op.memo) ); con.wallet_api_ptr->add_operation_to_builder_transaction( handle, op ); con.wallet_api_ptr->set_fees_on_builder_transaction( handle, "1.3.0" ); con.wallet_api_ptr->sign_builder_transaction( handle, true ); auto memo = con.wallet_api_ptr->read_memo( *op.memo ); BOOST_CHECK_EQUAL( memo, "get back some coin" ); + + op.memo = con.wallet_api_ptr->sign_memo( "nathan", test_pubkey, "another test" ); + idump( (op.memo) ); + memo = con.wallet_api_ptr->read_memo( *op.memo ); + BOOST_CHECK_EQUAL( memo, "another test" ); + + BOOST_CHECK_THROW( con.wallet_api_ptr->sign_memo( "non-exist-account-or-label", "nathan", "some text" ), + fc::exception ); + BOOST_CHECK_THROW( con.wallet_api_ptr->sign_memo( "nathan", "non-exist-account-or-label", "some text" ), + fc::exception ); } BOOST_CHECK(generate_block(app1)); @@ -875,6 +891,15 @@ BOOST_FIXTURE_TEST_CASE( cli_vote_for_2_witnesses, cli_fixture ) int init1_last_votes = init1_obj.total_votes; if( !is_hf2262_passed(app1) ) BOOST_CHECK(init1_last_votes > init1_start_votes); + + auto check_account_last_history = [&]( string account, string keyword ) { + auto history = con.wallet_api_ptr->get_relative_account_history(account, 0, 1, 0); + BOOST_REQUIRE_GT( history.size(), 0 ); + BOOST_CHECK( history[0].description.find( keyword ) != string::npos ); + }; + + check_account_last_history( "jmjatlanta", "Update Account 'jmjatlanta'" ); + } catch( fc::exception& e ) { edump((e.to_detail_string())); throw; @@ -1668,6 +1693,20 @@ BOOST_AUTO_TEST_CASE( cli_create_htlc ) BOOST_CHECK(generate_block(app1)); } + // test operation_printer + auto hist = con.wallet_api_ptr->get_account_history("alice", 10); + for(size_t i = 0; i < hist.size(); ++i) + { + auto obj = hist[i]; + std::stringstream ss; + ss << "Description: " << obj.description << "\n"; + auto str = ss.str(); + BOOST_TEST_MESSAGE( str ); + if (i == 3 || i == 4) + { + BOOST_CHECK( str.find("SHA256 8a45f62f47") != std::string::npos ); + } + } } catch( fc::exception& e ) { edump((e.to_detail_string())); throw; From 5b450becd49998d7653ff8cfc3d622f90197a370 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 21 Mar 2021 13:15:24 -0400 Subject: [PATCH 074/147] Add test cases for liquidity pool APIs --- tests/common/database_fixture.cpp | 1 + tests/tests/liquidity_pool_tests.cpp | 138 +++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index a5f3e7b40d..69f2099b3a 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -358,6 +358,7 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) if( current_test_name == "asset_in_collateral" || current_test_name == "htlc_database_api" + || current_test_name == "liquidity_pool_apis_test" || current_suite_name == "database_api_tests" || current_suite_name == "api_limit_tests" ) { diff --git a/tests/tests/liquidity_pool_tests.cpp b/tests/tests/liquidity_pool_tests.cpp index fccc58b81e..04fe5abf7e 100644 --- a/tests/tests/liquidity_pool_tests.cpp +++ b/tests/tests/liquidity_pool_tests.cpp @@ -997,4 +997,142 @@ BOOST_AUTO_TEST_CASE( liquidity_pool_exchange_test ) } } +BOOST_AUTO_TEST_CASE( liquidity_pool_apis_test ) +{ try { + + // Pass the hard fork time + generate_blocks( HARDFORK_LIQUIDITY_POOL_TIME ); + set_expiration( db, trx ); + + ACTORS((sam)(ted)); + + const asset_object sam_eur = create_user_issued_asset( "SAMEUR", sam, charge_market_fee ); + const asset_object sam_usd = create_user_issued_asset( "SAMUSD", sam, charge_market_fee ); + const asset_object sam_lp1 = create_user_issued_asset( "SAMLP1", sam, charge_market_fee ); + const asset_object sam_lp2 = create_user_issued_asset( "SAMLP2", sam, charge_market_fee ); + + const asset_object ted_eur = create_user_issued_asset( "TEDEUR", ted, charge_market_fee ); + const asset_object ted_usd = create_user_issued_asset( "TEDUSD", ted, charge_market_fee ); + const asset_object ted_lp1 = create_user_issued_asset( "TEDLP1", ted, charge_market_fee ); + const asset_object ted_lp2 = create_user_issued_asset( "TEDLP2", ted, charge_market_fee ); + const asset_object ted_lp3 = create_user_issued_asset( "TEDLP3", ted, charge_market_fee ); + + // create liquidity pools + const liquidity_pool_object sam_lpo1 = create_liquidity_pool( sam_id, sam_eur.id, sam_usd.id, + sam_lp1.id, 100, 310 ); + const liquidity_pool_object sam_lpo2 = create_liquidity_pool( sam_id, sam_usd.id, ted_usd.id, + sam_lp2.id, 200, 320 ); + const liquidity_pool_object ted_lpo1 = create_liquidity_pool( ted_id, sam_usd.id, ted_usd.id, + ted_lp1.id, 300, 330 ); + const liquidity_pool_object ted_lpo2 = create_liquidity_pool( ted_id, sam_usd.id, ted_eur.id, + ted_lp2.id, 400, 340 ); + const liquidity_pool_object ted_lpo3 = create_liquidity_pool( ted_id, ted_eur.id, ted_usd.id, + ted_lp3.id, 500, 350 ); + + generate_block(); + + // Check database API + graphene::app::database_api db_api( db, &( app.get_options() ) ); + + // list all pools + auto pools = db_api.list_liquidity_pools(); + BOOST_REQUIRE_EQUAL( pools.size(), 5u ); + BOOST_CHECK( !pools.front().statistics.valid() ); + BOOST_CHECK( pools.front().id == sam_lpo1.id ); + BOOST_CHECK( pools.back().id == ted_lpo3.id ); + + // pagination + pools = db_api.list_liquidity_pools( 5, sam_lpo2.id ); + BOOST_REQUIRE_EQUAL( pools.size(), 4u ); + BOOST_CHECK( !pools.front().statistics.valid() ); + BOOST_CHECK( pools.front().id == sam_lpo2.id ); + BOOST_CHECK( pools.back().id == ted_lpo3.id ); + + // with statistics + pools = db_api.list_liquidity_pools( 2, sam_lpo2.id, true ); + BOOST_REQUIRE_EQUAL( pools.size(), 2u ); + BOOST_CHECK( pools.front().statistics.valid() ); + BOOST_CHECK( pools.front().id == sam_lpo2.id ); + BOOST_CHECK( pools.back().id == ted_lpo1.id ); + + // get_liquidity_pools_by_asset_a + pools = db_api.get_liquidity_pools_by_asset_a( "SAMUSD" ); + BOOST_REQUIRE_EQUAL( pools.size(), 3u ); + BOOST_CHECK( !pools.front().statistics.valid() ); + BOOST_CHECK( pools.front().id == sam_lpo2.id ); + BOOST_CHECK( pools.back().id == ted_lpo2.id ); + + // pagination and with statistics + pools = db_api.get_liquidity_pools_by_asset_a( "SAMUSD", 2, ted_lpo2.id, true ); + BOOST_REQUIRE_EQUAL( pools.size(), 1u ); + BOOST_CHECK( pools.front().statistics.valid() ); + BOOST_CHECK( pools.front().id == ted_lpo2.id ); + + // get_liquidity_pools_by_asset_b + pools = db_api.get_liquidity_pools_by_asset_b( "TEDUSD" ); + BOOST_REQUIRE_EQUAL( pools.size(), 3u ); + BOOST_CHECK( !pools.front().statistics.valid() ); + BOOST_CHECK( pools.front().id == sam_lpo2.id ); + BOOST_CHECK( pools.back().id == ted_lpo3.id ); + + // pagination and with statistics + pools = db_api.get_liquidity_pools_by_asset_b( "TEDUSD", 2, sam_lpo1.id, true ); + BOOST_REQUIRE_EQUAL( pools.size(), 2u ); + BOOST_CHECK( pools.front().statistics.valid() ); + BOOST_CHECK( pools.front().id == sam_lpo2.id ); + BOOST_CHECK( pools.back().id == ted_lpo1.id ); + + // get_liquidity_pools_by_one_asset + pools = db_api.get_liquidity_pools_by_one_asset( "SAMUSD" ); + BOOST_REQUIRE_EQUAL( pools.size(), 4u ); + BOOST_CHECK( !pools.front().statistics.valid() ); + BOOST_CHECK( pools.front().id == sam_lpo1.id ); + BOOST_CHECK( pools.back().id == ted_lpo2.id ); + + // pagination and with statistics + pools = db_api.get_liquidity_pools_by_one_asset( "SAMUSD", 3, liquidity_pool_id_type(), true ); + BOOST_REQUIRE_EQUAL( pools.size(), 3u ); + BOOST_CHECK( pools.front().statistics.valid() ); + BOOST_CHECK( pools.front().id == sam_lpo1.id ); + BOOST_CHECK( pools.back().id == ted_lpo1.id ); + + // get_liquidity_pools_by_both_asset + pools = db_api.get_liquidity_pools_by_both_assets( "SAMUSD", "TEDUSD" ); + BOOST_REQUIRE_EQUAL( pools.size(), 2u ); + BOOST_CHECK( !pools.front().statistics.valid() ); + BOOST_CHECK( pools.front().id == sam_lpo2.id ); + BOOST_CHECK( pools.back().id == ted_lpo1.id ); + + // pagination and with statistics + pools = db_api.get_liquidity_pools_by_both_assets( "SAMUSD", "TEDUSD", 3, ted_lpo2.id, true ); + BOOST_REQUIRE_EQUAL( pools.size(), 0u ); + + // get_liquidity_pools_by_share_asset + auto opools = db_api.get_liquidity_pools_by_share_asset( { "SAMLP1", "SAMEUR" }, true, true ); + BOOST_REQUIRE_EQUAL( opools.size(), 2u ); + BOOST_CHECK( opools.front().valid() ); + BOOST_CHECK( opools.front()->statistics.valid() ); + BOOST_CHECK( opools.front()->id == sam_lpo1.id ); + BOOST_CHECK( !opools.back().valid() ); + + // get_liquidity_pools_by_owner + pools = db_api.get_liquidity_pools_by_owner( "sam" ); + BOOST_REQUIRE_EQUAL( pools.size(), 2u ); + BOOST_CHECK( !pools.front().statistics.valid() ); + BOOST_CHECK( pools.front().id == sam_lpo1.id ); + BOOST_CHECK( pools.back().id == sam_lpo2.id ); + + // pagination and with statistics + pools = db_api.get_liquidity_pools_by_owner( "ted", 5, sam_lpo1.id, true ); + BOOST_REQUIRE_EQUAL( pools.size(), 3u ); + BOOST_CHECK( pools.front().statistics.valid() ); + BOOST_CHECK( pools.front().id == ted_lpo1.id ); + BOOST_CHECK( pools.back().id == ted_lpo3.id ); + + } catch (fc::exception& e) { + edump((e.to_detail_string())); + throw; + } +} + BOOST_AUTO_TEST_SUITE_END() From 0f3571ced1afc56408bba0279a36a7d2e0665b30 Mon Sep 17 00:00:00 2001 From: Abit Date: Sun, 21 Mar 2021 18:19:43 +0100 Subject: [PATCH 075/147] Remove unused variables --- libraries/wallet/wallet_sign.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/wallet/wallet_sign.cpp b/libraries/wallet/wallet_sign.cpp index 091815463d..f4893a10c6 100644 --- a/libraries/wallet/wallet_sign.cpp +++ b/libraries/wallet/wallet_sign.cpp @@ -138,11 +138,11 @@ namespace graphene { namespace wallet { namespace detail { try { account_object from_account = get_account(from); md.from = from_account.options.memo_key; - } catch (const fc::exception& e) { + } catch (const fc::exception&) { // check if the string itself is a pubkey, if not, consider it as a label try { md.from = public_key_type( from ); - } catch (const fc::exception& e) { + } catch (const fc::exception&) { md.from = self.get_public_key( from ); } } @@ -150,11 +150,11 @@ namespace graphene { namespace wallet { namespace detail { try { account_object to_account = get_account(to); md.to = to_account.options.memo_key; - } catch (const fc::exception& e) { + } catch (const fc::exception&) { // check if the string itself is a pubkey, if not, consider it as a label try { md.to = public_key_type( to ); - } catch (const fc::exception& e) { + } catch (const fc::exception&) { md.to = self.get_public_key( to ); } } @@ -162,7 +162,7 @@ namespace graphene { namespace wallet { namespace detail { // try to get private key of from and sign, if that fails, try to sign with to try { md.set_message(get_private_key(md.from), md.to, memo); - } catch (const fc::exception& e) { + } catch (const fc::exception&) { std::swap( md.from, md.to ); md.set_message(get_private_key(md.from), md.to, memo); std::swap( md.from, md.to ); From 55e101f2b79a70bbc4f1378ef8064e462f9ef538 Mon Sep 17 00:00:00 2001 From: abitmore Date: Mon, 22 Mar 2021 00:13:59 +0000 Subject: [PATCH 076/147] Add CLI tests for account_upgrade_op in history --- tests/cli/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index e4253121ea..904cc97e18 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -437,6 +437,8 @@ BOOST_FIXTURE_TEST_CASE( uia_tests, cli_fixture ) INVOKE(upgrade_nathan_account); + BOOST_CHECK(generate_block(app1)); + account_object nathan_acct = con.wallet_api_ptr->get_account("nathan"); auto formatters = con.wallet_api_ptr->get_result_formatters(); @@ -450,6 +452,8 @@ BOOST_FIXTURE_TEST_CASE( uia_tests, cli_fixture ) check_account_last_history( "nathan", keyword ); }; + check_nathan_last_history( "account_upgrade_operation" ); + // Create new asset called BOBCOIN { BOOST_TEST_MESSAGE("Create UIA 'BOBCOIN'"); From fa9b7933a19d808534466cec4a19ff9e548a1d5e Mon Sep 17 00:00:00 2001 From: abitmore Date: Mon, 22 Mar 2021 15:17:56 +0000 Subject: [PATCH 077/147] Update uia_tests in cli_test for better coverage --- tests/cli/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index 904cc97e18..6581ec5d61 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -534,7 +534,7 @@ BOOST_FIXTURE_TEST_CASE( uia_tests, cli_fixture ) auto test_pubkey = fc::json::to_string( test_bki.pub_key ); test_pubkey = test_pubkey.substr( 1, test_pubkey.size() - 2 ); idump( (test_pubkey) ); - op.memo = con.wallet_api_ptr->sign_memo( test_pubkey, "nathan", "get back some coin" ); + op.memo = con.wallet_api_ptr->sign_memo( "nathan", test_pubkey, "get back some coin" ); idump( (op.memo) ); con.wallet_api_ptr->add_operation_to_builder_transaction( handle, op ); con.wallet_api_ptr->set_fees_on_builder_transaction( handle, "1.3.0" ); @@ -543,7 +543,7 @@ BOOST_FIXTURE_TEST_CASE( uia_tests, cli_fixture ) auto memo = con.wallet_api_ptr->read_memo( *op.memo ); BOOST_CHECK_EQUAL( memo, "get back some coin" ); - op.memo = con.wallet_api_ptr->sign_memo( "nathan", test_pubkey, "another test" ); + op.memo = con.wallet_api_ptr->sign_memo( test_pubkey, "nathan", "another test" ); idump( (op.memo) ); memo = con.wallet_api_ptr->read_memo( *op.memo ); BOOST_CHECK_EQUAL( memo, "another test" ); From 1b4b01172aa9f7784306b6154b9806c1548f4545 Mon Sep 17 00:00:00 2001 From: abitmore Date: Mon, 22 Mar 2021 15:46:28 +0000 Subject: [PATCH 078/147] Update cli_test for better code coverage --- tests/cli/main.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index 6581ec5d61..ca825e2d30 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -470,6 +470,14 @@ BOOST_FIXTURE_TEST_CASE( uia_tests, cli_fixture ) fc::variant(result, FC_PACK_MAX_DEPTH), fc::variants()); BOOST_CHECK( output.find("BOBCOIN") != string::npos ); } + + BOOST_CHECK_THROW( con.wallet_api_ptr->get_asset_name("BOBCOI"), fc::exception ); + BOOST_CHECK_EQUAL( con.wallet_api_ptr->get_asset_name("BOBCOIN"), "BOBCOIN" ); + BOOST_CHECK_EQUAL( con.wallet_api_ptr->get_asset_symbol("BOBCOIN"), "BOBCOIN" ); + + BOOST_CHECK_THROW( con.wallet_api_ptr->get_account_name("nath"), fc::exception ); + BOOST_CHECK_EQUAL( con.wallet_api_ptr->get_account_name("nathan"), "nathan" ); + BOOST_CHECK( con.wallet_api_ptr->get_account_id("nathan") == con.wallet_api_ptr->get_account("nathan").id ); } BOOST_CHECK(generate_block(app1)); @@ -478,6 +486,8 @@ BOOST_FIXTURE_TEST_CASE( uia_tests, cli_fixture ) auto bobcoin = con.wallet_api_ptr->get_asset("BOBCOIN"); + BOOST_CHECK( con.wallet_api_ptr->get_asset_id("BOBCOIN") == bobcoin.id ); + bool balance_formatter_tested = false; auto check_bobcoin_balance = [&](string account, int64_t amount) { auto balances = con.wallet_api_ptr->list_account_balances( account ); @@ -896,13 +906,12 @@ BOOST_FIXTURE_TEST_CASE( cli_vote_for_2_witnesses, cli_fixture ) if( !is_hf2262_passed(app1) ) BOOST_CHECK(init1_last_votes > init1_start_votes); - auto check_account_last_history = [&]( string account, string keyword ) { - auto history = con.wallet_api_ptr->get_relative_account_history(account, 0, 1, 0); - BOOST_REQUIRE_GT( history.size(), 0 ); - BOOST_CHECK( history[0].description.find( keyword ) != string::npos ); - }; - - check_account_last_history( "jmjatlanta", "Update Account 'jmjatlanta'" ); + { + auto history = con.wallet_api_ptr->get_account_history_by_operations( + "jmjatlanta", {6}, 0, 1); // 6 - account_update_operation + BOOST_REQUIRE_GT( history.details.size(), 0 ); + BOOST_CHECK( history.details[0].description.find( "Update Account 'jmjatlanta'" ) != string::npos ); + } } catch( fc::exception& e ) { edump((e.to_detail_string())); From 0897efe2eb053c6690a3cc80cca4733c1bcbe88e Mon Sep 17 00:00:00 2001 From: abitmore Date: Mon, 22 Mar 2021 12:48:56 -0400 Subject: [PATCH 079/147] Add tests for result formatter of get_acc_his_by_o for get_account_history_by_operations command --- tests/cli/main.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index ca825e2d30..9626c5ecd2 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -911,6 +911,16 @@ BOOST_FIXTURE_TEST_CASE( cli_vote_for_2_witnesses, cli_fixture ) "jmjatlanta", {6}, 0, 1); // 6 - account_update_operation BOOST_REQUIRE_GT( history.details.size(), 0 ); BOOST_CHECK( history.details[0].description.find( "Update Account 'jmjatlanta'" ) != string::npos ); + + // Testing result formatter + auto formatters = con.wallet_api_ptr->get_result_formatters(); + if( formatters.find("get_account_history_by_operations") != formatters.end() ) + { + BOOST_TEST_MESSAGE("Testing formatter of get_account_history_by_operations"); + string output = formatters["get_account_history_by_operations"]( + fc::variant(history, FC_PACK_MAX_DEPTH), fc::variants()); + BOOST_CHECK( output.find("Update Account 'jmjatlanta'") != string::npos ); + } } } catch( fc::exception& e ) { From 2c30e204c46b3496c95f591f7f426b326a30ea04 Mon Sep 17 00:00:00 2001 From: abitmore Date: Mon, 22 Mar 2021 16:01:42 +0000 Subject: [PATCH 080/147] Fix code smells --- libraries/app/api.cpp | 10 +++---- libraries/app/database_api.cpp | 21 ++++++------- libraries/app/database_api_impl.hxx | 8 ++--- libraries/app/include/graphene/app/api.hpp | 10 +++---- .../app/include/graphene/app/database_api.hpp | 8 ++--- .../chain/include/graphene/chain/config.hpp | 4 ++- .../api_helper_indexes/api_helper_indexes.cpp | 22 +++++++------- .../api_helper_indexes/api_helper_indexes.hpp | 24 +++++++-------- .../wallet/include/graphene/wallet/wallet.hpp | 28 ++++++++--------- libraries/wallet/wallet.cpp | 30 +++++++++++-------- libraries/wallet/wallet_api_impl.hpp | 2 +- libraries/wallet/wallet_asset.cpp | 2 +- libraries/wallet/wallet_results.cpp | 8 ++--- 13 files changed, 92 insertions(+), 85 deletions(-) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 62cb9317e8..ba97a82d62 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -340,7 +340,7 @@ namespace graphene { namespace app { vector history_api::get_account_history( const std::string account_id_or_name, operation_history_id_type stop, - unsigned limit, + uint32_t limit, operation_history_id_type start ) const { FC_ASSERT( _app.chain_database() ); @@ -391,10 +391,10 @@ namespace graphene { namespace app { } vector history_api::get_account_history_operations( const std::string account_id_or_name, - int operation_type, + int64_t operation_type, operation_history_id_type start, operation_history_id_type stop, - unsigned limit ) const + uint32_t limit ) const { FC_ASSERT( _app.chain_database() ); const auto& db = *_app.chain_database(); @@ -437,7 +437,7 @@ namespace graphene { namespace app { vector history_api::get_relative_account_history( const std::string account_id_or_name, uint64_t stop, - unsigned limit, + uint32_t limit, uint64_t start ) const { FC_ASSERT( _app.chain_database() ); @@ -486,7 +486,7 @@ namespace graphene { namespace app { history_operation_detail history_api::get_account_history_by_operations( const std::string account_id_or_name, flat_set operation_types, - uint32_t start, unsigned limit )const + uint32_t start, uint32_t limit )const { const auto configured_limit = _app.get_options().api_limit_get_account_history_by_operations; FC_ASSERT( limit <= configured_limit, diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 16e0ae97c4..7be68e4b4f 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -90,7 +90,7 @@ database_api_impl::database_api_impl( graphene::chain::database& db, const appli asset_in_liquidity_pools_index = &_db.get_index_type< primary_index< liquidity_pool_index > >() .get_secondary_index(); } - catch( fc::assert_exception& e ) + catch( const fc::assert_exception& ) { asset_in_liquidity_pools_index = nullptr; } @@ -1827,10 +1827,10 @@ vector database_api_impl::get_liquidity_pools_by } vector database_api::get_liquidity_pools_by_one_asset( - std::string asset_symbol_or_id, - optional limit, - optional start_id, - optional with_statistics )const + const std::string& asset_symbol_or_id, + const optional& limit, + const optional& start_id, + const optional& with_statistics )const { return my->get_liquidity_pools_by_one_asset( asset_symbol_or_id, @@ -1840,10 +1840,10 @@ vector database_api::get_liquidity_pools_by_one_ } vector database_api_impl::get_liquidity_pools_by_one_asset( - std::string asset_symbol_or_id, - optional olimit, - optional ostart_id, - optional with_statistics )const + const std::string& asset_symbol_or_id, + const optional& olimit, + const optional& ostart_id, + const optional& with_statistics )const { // api_helper_indexes plugin is required for accessing the secondary index FC_ASSERT( _app_options && _app_options->has_api_helper_indexes_plugin, @@ -1869,7 +1869,8 @@ vector database_api_impl::get_liquidity_pools_by vector results; results.reserve( limit ); - for ( ; itr != pools.end() && results.size() < limit; ++itr ) + auto pools_end = pools.end(); + for ( ; itr != pools_end && results.size() < limit; ++itr ) { results.emplace_back( extend_liquidity_pool( (*itr)(_db), with_stats ) ); } diff --git a/libraries/app/database_api_impl.hxx b/libraries/app/database_api_impl.hxx index 4aff5ccb33..2088045245 100644 --- a/libraries/app/database_api_impl.hxx +++ b/libraries/app/database_api_impl.hxx @@ -154,10 +154,10 @@ class database_api_impl : public std::enable_shared_from_this optional start_id = optional(), optional with_statistics = false )const; vector get_liquidity_pools_by_one_asset( - std::string asset_symbol_or_id, - optional limit = 101, - optional start_id = optional(), - optional with_statistics = false )const; + const std::string& asset_symbol_or_id, + const optional& limit = 101, + const optional& start_id = optional(), + const optional& with_statistics = false )const; vector get_liquidity_pools_by_both_assets( std::string asset_symbol_or_id_a, std::string asset_symbol_or_id_b, diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index af2dc3c1fd..acc82c350b 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -136,7 +136,7 @@ namespace graphene { namespace app { vector get_account_history( const std::string account_name_or_id, operation_history_id_type stop = operation_history_id_type(), - unsigned limit = 100, + uint32_t limit = 100, operation_history_id_type start = operation_history_id_type() )const; @@ -153,7 +153,7 @@ namespace graphene { namespace app { const std::string account_name_or_id, flat_set operation_types, uint32_t start, - unsigned limit + uint32_t limit )const; /** @@ -168,10 +168,10 @@ namespace graphene { namespace app { */ vector get_account_history_operations( const std::string account_name_or_id, - int operation_type, + int64_t operation_type, operation_history_id_type start = operation_history_id_type(), operation_history_id_type stop = operation_history_id_type(), - unsigned limit = 100 + uint32_t limit = 100 )const; /** @@ -188,7 +188,7 @@ namespace graphene { namespace app { */ vector get_relative_account_history( const std::string account_name_or_id, uint64_t stop = 0, - unsigned limit = 100, + uint32_t limit = 100, uint64_t start = 0) const; /** diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index dff253c99b..fed25b05d5 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -706,10 +706,10 @@ class database_api * 4. can only omit one or more arguments in the end of the list, but not one or more in the middle */ vector get_liquidity_pools_by_one_asset( - std::string asset_symbol_or_id, - optional limit = 101, - optional start_id = optional(), - optional with_statistics = false )const; + const std::string& asset_symbol_or_id, + const optional& limit = 101, + const optional& start_id = optional(), + const optional& with_statistics = false )const; /** * @brief Get a list of liquidity pools by the symbols or IDs of the two assets in the pool diff --git a/libraries/chain/include/graphene/chain/config.hpp b/libraries/chain/include/graphene/chain/config.hpp index 1c85d78aac..7fd7f42cef 100644 --- a/libraries/chain/include/graphene/chain/config.hpp +++ b/libraries/chain/include/graphene/chain/config.hpp @@ -25,12 +25,14 @@ #include +#include + #define GRAPHENE_MIN_UNDO_HISTORY 10 #define GRAPHENE_MAX_UNDO_HISTORY 10000 #define GRAPHENE_MAX_NESTED_OBJECTS (200) -#define GRAPHENE_CURRENT_DB_VERSION "20210222" +const std::string GRAPHENE_CURRENT_DB_VERSION = "20210222"; #define GRAPHENE_RECENTLY_MISSED_COUNT_INCREMENT 4 #define GRAPHENE_RECENTLY_MISSED_COUNT_DECREMENT 3 diff --git a/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp b/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp index 91959bd7a4..9c95c8e4ff 100644 --- a/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp +++ b/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp @@ -49,7 +49,7 @@ void amount_in_collateral_index::object_inserted( const object& objct ) itr->second += o.collateral; } -} FC_CAPTURE_AND_RETHROW( (objct) ); } +} FC_CAPTURE_AND_RETHROW( (objct) ) } void amount_in_collateral_index::object_removed( const object& objct ) { try { @@ -67,53 +67,55 @@ void amount_in_collateral_index::object_removed( const object& objct ) itr->second -= o.collateral; } -} FC_CAPTURE_AND_RETHROW( (objct) ); } +} FC_CAPTURE_AND_RETHROW( (objct) ) } void amount_in_collateral_index::about_to_modify( const object& objct ) { try { object_removed( objct ); -} FC_CAPTURE_AND_RETHROW( (objct) ); } +} FC_CAPTURE_AND_RETHROW( (objct) ) } void amount_in_collateral_index::object_modified( const object& objct ) { try { object_inserted( objct ); -} FC_CAPTURE_AND_RETHROW( (objct) ); } +} FC_CAPTURE_AND_RETHROW( (objct) ) } share_type amount_in_collateral_index::get_amount_in_collateral( const asset_id_type& asst )const { try { auto itr = in_collateral.find( asst ); if( itr == in_collateral.end() ) return 0; return itr->second; -} FC_CAPTURE_AND_RETHROW( (asst) ); } +} FC_CAPTURE_AND_RETHROW( (asst) ) } share_type amount_in_collateral_index::get_backing_collateral( const asset_id_type& asst )const { try { auto itr = backing_collateral.find( asst ); if( itr == backing_collateral.end() ) return 0; return itr->second; -} FC_CAPTURE_AND_RETHROW( (asst) ); } +} FC_CAPTURE_AND_RETHROW( (asst) ) } void asset_in_liquidity_pools_index::object_inserted( const object& objct ) { try { - const liquidity_pool_object& o = static_cast( objct ); + const auto& o = static_cast( objct ); asset_in_pools_map[ o.asset_a ].insert( o.id ); // Note: [] operator will create an entry if not found asset_in_pools_map[ o.asset_b ].insert( o.id ); -} FC_CAPTURE_AND_RETHROW( (objct) ); } +} FC_CAPTURE_AND_RETHROW( (objct) ) } void asset_in_liquidity_pools_index::object_removed( const object& objct ) { try { - const liquidity_pool_object& o = static_cast( objct ); + const auto& o = static_cast( objct ); asset_in_pools_map[ o.asset_a ].erase( o.id ); asset_in_pools_map[ o.asset_b ].erase( o.id ); // Note: do not erase entries with an empty set from the map in order to avoid read/write race conditions -} FC_CAPTURE_AND_RETHROW( (objct) ); } +} FC_CAPTURE_AND_RETHROW( (objct) ) } void asset_in_liquidity_pools_index::about_to_modify( const object& objct ) { + // this secondary index has no interest in the modifications, nothing to do here } void asset_in_liquidity_pools_index::object_modified( const object& objct ) { + // this secondary index has no interest in the modifications, nothing to do here } const flat_set& asset_in_liquidity_pools_index::get_liquidity_pools_by_asset( diff --git a/libraries/plugins/api_helper_indexes/include/graphene/api_helper_indexes/api_helper_indexes.hpp b/libraries/plugins/api_helper_indexes/include/graphene/api_helper_indexes/api_helper_indexes.hpp index 216f85d594..49b79bee90 100644 --- a/libraries/plugins/api_helper_indexes/include/graphene/api_helper_indexes/api_helper_indexes.hpp +++ b/libraries/plugins/api_helper_indexes/include/graphene/api_helper_indexes/api_helper_indexes.hpp @@ -38,10 +38,10 @@ using namespace chain; class amount_in_collateral_index : public secondary_index { public: - virtual void object_inserted( const object& obj ) override; - virtual void object_removed( const object& obj ) override; - virtual void about_to_modify( const object& before ) override; - virtual void object_modified( const object& after ) override; + void object_inserted( const object& obj ) override; + void object_removed( const object& obj ) override; + void about_to_modify( const object& before ) override; + void object_modified( const object& after ) override; share_type get_amount_in_collateral( const asset_id_type& asset )const; share_type get_backing_collateral( const asset_id_type& asset )const; @@ -59,10 +59,10 @@ class amount_in_collateral_index : public secondary_index class asset_in_liquidity_pools_index: public secondary_index { public: - virtual void object_inserted( const object& obj ) override; - virtual void object_removed( const object& obj ) override; - virtual void about_to_modify( const object& before ) override; - virtual void object_modified( const object& after ) override; + void object_inserted( const object& obj ) override; + void object_removed( const object& obj ) override; + void about_to_modify( const object& before ) override; + void object_modified( const object& after ) override; const flat_set& get_liquidity_pools_by_asset( const asset_id_type& a )const; @@ -84,16 +84,16 @@ class api_helper_indexes : public graphene::app::plugin std::string plugin_name()const override; std::string plugin_description()const override; - virtual void plugin_set_program_options( + void plugin_set_program_options( boost::program_options::options_description& cli, boost::program_options::options_description& cfg) override; - virtual void plugin_initialize(const boost::program_options::variables_map& options) override; - virtual void plugin_startup() override; + void plugin_initialize(const boost::program_options::variables_map& options) override; + void plugin_startup() override; friend class detail::api_helper_indexes_impl; - std::unique_ptr my; private: + std::unique_ptr my; amount_in_collateral_index* amount_in_collateral_idx = nullptr; asset_in_liquidity_pools_index* asset_in_liquidity_pools_idx = nullptr; }; diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index eb7b6b6f1d..321f7609a2 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -126,7 +126,7 @@ class wallet_api * @param limit the number of entries to return (starting from the most recent) * @returns a list of \c operation_history_objects */ - vector get_account_history(string account_name_or_id, int limit)const; + vector get_account_history(string account_name_or_id, uint32_t limit)const; /** Returns the relative operations on the named account from start number. * @@ -137,7 +137,7 @@ class wallet_api * @returns a list of \c operation_history_objects */ vector get_relative_account_history( string account_name_or_id, uint32_t stop, - int limit, uint32_t start )const; + uint32_t limit, uint32_t start )const; /** * @brief Fetch all objects relevant to the specified account @@ -243,7 +243,7 @@ class wallet_api */ account_history_operation_detail get_account_history_by_operations( string account_name_or_id, flat_set operation_types, - uint32_t start, int limit); + uint32_t start, uint32_t limit); /** Returns the block chain's rapidly-changing properties. * The returned object contains information that changes every block interval @@ -291,7 +291,7 @@ class wallet_api * @param account_name_or_id the name or ID of the account to look up * @returns the name of the account */ - string get_account_name(string account_name_or_id) const + string get_account_name(const string& account_name_or_id) const { return get_account( account_name_or_id ).name; } /** @@ -299,14 +299,14 @@ class wallet_api * @param asset_symbol_or_id the symbol or ID of an asset to look up * @returns the id of the given asset */ - asset_id_type get_asset_id(string asset_symbol_or_id) const; + asset_id_type get_asset_id(const string& asset_symbol_or_id) const; /** * Lookup the symbol of an asset. * @param asset_symbol_or_id the symbol or ID of an asset to look up * @returns the symbol of the given asset */ - string get_asset_symbol(string asset_symbol_or_id) const + string get_asset_symbol(const string& asset_symbol_or_id) const { return get_asset( asset_symbol_or_id ).symbol; } /** @@ -314,7 +314,7 @@ class wallet_api * @param asset_symbol_or_id the symbol or ID of an asset to look up * @returns the symbol of the given asset */ - string get_asset_name(string asset_symbol_or_id) const + string get_asset_name(const string& asset_symbol_or_id) const { return get_asset_symbol( asset_symbol_or_id ); } /** @@ -734,8 +734,8 @@ class wallet_api * @param brain_key the brain key used for generating the account's private keys * @param account_name the name of the account, must be unique on the blockchain. * Names with only latin letters and at least one vowel are - * premium names and expensive to register; - * names with only consonants, or at least with a digit, a dot or + * premium names and expensive to register. + * Names with only consonants, or at least with a digit, a dot or * a minus sign are cheap. * @param registrar_account the account which will pay the fee to register the user * @param referrer_account the account who is acting as a referrer, and may receive a @@ -782,11 +782,11 @@ class wallet_api * increase with transaction size * @returns the transaction ID (hash) along with the signed transaction transferring funds */ - pair transfer2(string from, - string to, - string amount, - string asset_symbol_or_id, - string memo ) { + pair transfer2(const string& from, + const string& to, + const string& amount, + const string& asset_symbol_or_id, + const string& memo ) { auto trx = transfer( from, to, amount, asset_symbol_or_id, memo, true ); return std::make_pair(trx.id(),trx); } diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 467cb157f9..1413867510 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -276,7 +276,7 @@ signed_transaction wallet_api::htlc_extend ( std::string htlc_id, std::string is return my->htlc_extend(htlc_id, issuer, seconds_to_add, broadcast); } -vector wallet_api::get_account_history(string name, int limit)const +vector wallet_api::get_account_history(string name, uint32_t limit)const { vector result; @@ -298,7 +298,9 @@ vector wallet_api::get_account_history(string name, int limit) } } - int page_limit = skip_first_row ? std::min( 100, limit + 1 ) : std::min( 100, limit ); + uint32_t default_page_size = 100; + uint32_t page_limit = skip_first_row ? std::min( default_page_size, limit + 1 ) + : std::min( default_page_size, limit ); vector current = my->_remote_hist->get_account_history( name, @@ -321,7 +323,7 @@ vector wallet_api::get_account_history(string name, int limit) result.push_back( operation_detail{ memo, ss.str(), o } ); } - if( int(current.size()) < page_limit ) + if( current.size() < page_limit ) break; limit -= current.size(); @@ -335,7 +337,7 @@ vector wallet_api::get_account_history(string name, int limit) vector wallet_api::get_relative_account_history( string name, uint32_t stop, - int limit, + uint32_t limit, uint32_t start)const { vector result; @@ -349,22 +351,24 @@ vector wallet_api::get_relative_account_history( else start = std::min(start, stats.total_ops); + uint32_t default_page_size = 100; while( limit > 0 ) { + uint32_t page_size = std::min(default_page_size, limit); vector current = my->_remote_hist->get_relative_account_history( name, stop, - std::min(100, limit), + page_size, start); for (auto &o : current) { std::stringstream ss; auto memo = o.op.visit(detail::operation_printer(ss, *my, o)); result.push_back(operation_detail{memo, ss.str(), o}); } - if (current.size() < std::min(100, limit)) + if (current.size() < page_size) break; - limit -= current.size(); - start -= 100; + limit -= page_size; + start -= page_size; if( start == 0 ) break; } return result; @@ -374,7 +378,7 @@ account_history_operation_detail wallet_api::get_account_history_by_operations( string name, flat_set operation_types, uint32_t start, - int limit) + uint32_t limit) { account_history_operation_detail result; auto account_id = get_account(name).get_id(); @@ -390,10 +394,12 @@ account_history_operation_detail wallet_api::get_account_history_by_operations( result.total_count =stats.removed_ops; } + uint32_t default_page_size = 100; while (limit > 0 && start <= stats.total_ops) { - uint32_t min_limit = std::min (100, limit); + uint32_t min_limit = std::min(default_page_size, limit); auto current = my->_remote_hist->get_account_history_by_operations(name, operation_types, start, min_limit); - for( auto it = current.operation_history_objs.rbegin(); it != current.operation_history_objs.rend(); ++it ) + auto his_rend = current.operation_history_objs.rend(); + for( auto it = current.operation_history_objs.rbegin(); it != his_rend; ++it ) { auto& obj = *it; std::stringstream ss; @@ -591,7 +597,7 @@ account_id_type wallet_api::get_account_id(string account_name_or_id) const return my->get_account_id(account_name_or_id); } -asset_id_type wallet_api::get_asset_id(string asset_symbol_or_id) const +asset_id_type wallet_api::get_asset_id(const string& asset_symbol_or_id) const { return my->get_asset_id(asset_symbol_or_id); } diff --git a/libraries/wallet/wallet_api_impl.hpp b/libraries/wallet/wallet_api_impl.hpp index 2ee1de89d8..663efccaaf 100644 --- a/libraries/wallet/wallet_api_impl.hpp +++ b/libraries/wallet/wallet_api_impl.hpp @@ -169,7 +169,7 @@ class wallet_api_impl fc::optional get_htlc(string htlc_id) const; - asset_id_type get_asset_id(string asset_symbol_or_id) const; + asset_id_type get_asset_id(const string& asset_symbol_or_id) const; string get_wallet_filename() const; diff --git a/libraries/wallet/wallet_asset.cpp b/libraries/wallet/wallet_asset.cpp index a73755750c..80bd89e2c1 100644 --- a/libraries/wallet/wallet_asset.cpp +++ b/libraries/wallet/wallet_asset.cpp @@ -74,7 +74,7 @@ namespace graphene { namespace wallet { namespace detail { return *opt; } - asset_id_type wallet_api_impl::get_asset_id(string asset_symbol_or_id) const + asset_id_type wallet_api_impl::get_asset_id(const string& asset_symbol_or_id) const { FC_ASSERT( asset_symbol_or_id.size() > 0 ); vector> opt_asset; diff --git a/libraries/wallet/wallet_results.cpp b/libraries/wallet/wallet_results.cpp index b8116195d0..3f881d4138 100644 --- a/libraries/wallet/wallet_results.cpp +++ b/libraries/wallet/wallet_results.cpp @@ -66,12 +66,8 @@ std::map> wallet_a m["get_account_history_by_operations"] = [this](variant result, const fc::variants&) { auto r = result.as( GRAPHENE_MAX_NESTED_OBJECTS ); std::stringstream ss; - ss << "total_count : "; - ss << r.total_count; - ss << " \n"; - ss << "result_count : "; - ss << r.result_count; - ss << " \n"; + ss << "total_count : " << r.total_count << " \n"; + ss << "result_count : " << r.result_count << " \n"; for (operation_detail_ex& d : r.details) { operation_history_object& i = d.op; auto b = _remote_db->get_block_header(i.block_num); From f1a03f8f02ace653147b375e1bf69a48b92a90b0 Mon Sep 17 00:00:00 2001 From: abitmore Date: Mon, 22 Mar 2021 18:25:37 -0400 Subject: [PATCH 081/147] Analyze more files with gcov for sonar-scan --- .github/workflows/sonar-scan.yml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sonar-scan.yml b/.github/workflows/sonar-scan.yml index 8f045a361f..e7af75ea45 100644 --- a/.github/workflows/sonar-scan.yml +++ b/.github/workflows/sonar-scan.yml @@ -134,9 +134,20 @@ jobs: mkdir -p sonar_cache find _build/libraries/[acdenptuw]*/CMakeFiles/*.dir \ _build/libraries/plugins/*/CMakeFiles/*.dir \ - _build/programs/[cdgjsw]*/CMakeFiles/*.dir \ -type d -print \ - | while read d; do srcd="${d:7}"; gcov -o "$d" "${srcd/CMakeFiles*.dir/.}"/*.cpp; done >/dev/null + | while read d; do \ + tmpd="${d:7}"; \ + srcd="${tmpd/CMakeFiles*.dir/.}"; \ + gcov -o "$d" "${srcd}"/*.[ch][px][px] \ + "${srcd}"/include/graphene/*/*.[ch][px][px] ; \ + done >/dev/null + find _build/programs/[cdgjsw]*/CMakeFiles/*.dir \ + -type d -print \ + | while read d; do \ + tmpd="${d:7}"; \ + srcd="${tmpd/CMakeFiles*.dir/.}"; \ + gcov -o "$d" "${srcd}"/*.[ch][px][px] ; \ + done >/dev/null programs/build_helpers/set_sonar_branch_for_github_actions sonar-project.properties - name: Scan with SonarScanner env: From cb488f0c7e221601d650f269daf9a3587273ca86 Mon Sep 17 00:00:00 2001 From: abitmore Date: Mon, 22 Mar 2021 22:39:26 +0000 Subject: [PATCH 082/147] Fix code smells about for loop --- libraries/app/database_api.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 7be68e4b4f..919b7fe3d3 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -1869,10 +1869,10 @@ vector database_api_impl::get_liquidity_pools_by vector results; results.reserve( limit ); - auto pools_end = pools.end(); - for ( ; itr != pools_end && results.size() < limit; ++itr ) + while( itr != pools.end() && results.size() < limit ) { results.emplace_back( extend_liquidity_pool( (*itr)(_db), with_stats ) ); + ++itr; } return results; From 9ecddd079501617c3de131c2751effae8ff91503 Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 23 Mar 2021 13:28:13 +0000 Subject: [PATCH 083/147] Fix code smells about passing large objects --- libraries/wallet/include/graphene/wallet/wallet.hpp | 8 ++++---- libraries/wallet/wallet.cpp | 11 +++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 321f7609a2..9bb26c686b 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -126,7 +126,7 @@ class wallet_api * @param limit the number of entries to return (starting from the most recent) * @returns a list of \c operation_history_objects */ - vector get_account_history(string account_name_or_id, uint32_t limit)const; + vector get_account_history(const string& account_name_or_id, uint32_t limit)const; /** Returns the relative operations on the named account from start number. * @@ -136,7 +136,7 @@ class wallet_api * @param start the sequence number where to start looping back throw the history * @returns a list of \c operation_history_objects */ - vector get_relative_account_history( string account_name_or_id, uint32_t stop, + vector get_relative_account_history( const string& account_name_or_id, uint32_t stop, uint32_t limit, uint32_t start )const; /** @@ -241,8 +241,8 @@ class wallet_api * @param limit the max number of entries to return (from start number) * @returns account_history_operation_detail */ - account_history_operation_detail get_account_history_by_operations( string account_name_or_id, - flat_set operation_types, + account_history_operation_detail get_account_history_by_operations( const string& account_name_or_id, + const flat_set& operation_types, uint32_t start, uint32_t limit); /** Returns the block chain's rapidly-changing properties. diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 1413867510..65218e6998 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -276,7 +276,7 @@ signed_transaction wallet_api::htlc_extend ( std::string htlc_id, std::string is return my->htlc_extend(htlc_id, issuer, seconds_to_add, broadcast); } -vector wallet_api::get_account_history(string name, uint32_t limit)const +vector wallet_api::get_account_history(const string& name, uint32_t limit)const { vector result; @@ -335,7 +335,7 @@ vector wallet_api::get_account_history(string name, uint32_t l } vector wallet_api::get_relative_account_history( - string name, + const string& name, uint32_t stop, uint32_t limit, uint32_t start)const @@ -375,15 +375,14 @@ vector wallet_api::get_relative_account_history( } account_history_operation_detail wallet_api::get_account_history_by_operations( - string name, - flat_set operation_types, + const string& name, + const flat_set& operation_types, uint32_t start, uint32_t limit) { account_history_operation_detail result; - auto account_id = get_account(name).get_id(); - const auto& account = my->get_account(account_id); + const auto& account = my->get_account(name); const auto& stats = my->get_object(account.statistics); // sequence of account_transaction_history_object start with 1 From edd8cdbd3ab9ac7763ba4290bd50213a1eda6ae1 Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 23 Mar 2021 13:50:50 +0000 Subject: [PATCH 084/147] Replace exit with return in main() --- programs/network_mapper/network_mapper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/network_mapper/network_mapper.cpp b/programs/network_mapper/network_mapper.cpp index 68b5f526f2..91ed8f2fc8 100644 --- a/programs/network_mapper/network_mapper.cpp +++ b/programs/network_mapper/network_mapper.cpp @@ -173,7 +173,7 @@ int main(int argc, char** argv) if ( argc < 3 ) { std::cerr << "Usage: " << argv[0] << " [ ...]\n"; - exit(1); + return 1; } const graphene::chain::chain_id_type chain_id( argv[1] ); From 78815cbe3af1abb3a87eac900c758ec11fc1e7c8 Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 23 Mar 2021 14:35:08 +0000 Subject: [PATCH 085/147] Avoid operator new, use make_shared or make_unique --- libraries/app/application.cpp | 2 +- libraries/app/database_api.cpp | 2 +- .../chain/include/graphene/chain/database.hpp | 4 ++-- libraries/db/include/graphene/db/index.hpp | 2 +- libraries/db/include/graphene/db/object.hpp | 2 +- .../db/include/graphene/db/object_database.hpp | 2 +- .../db/include/graphene/db/simple_index.hpp | 4 ++-- .../net/include/graphene/net/peer_database.hpp | 2 +- libraries/net/message_oriented_connection.cpp | 4 ++-- libraries/net/peer_connection.cpp | 16 ++++++++++++---- libraries/net/peer_database.cpp | 12 +++++++----- .../account_history/account_history_plugin.cpp | 2 +- .../api_helper_indexes/api_helper_indexes.cpp | 2 +- .../custom_operations_plugin.cpp | 2 +- .../plugins/delayed_node/delayed_node_plugin.cpp | 2 +- .../elasticsearch/elasticsearch_plugin.cpp | 2 +- libraries/plugins/es_objects/es_objects.cpp | 2 +- .../grouped_orders/grouped_orders_plugin.cpp | 2 +- .../market_history/market_history_plugin.cpp | 2 +- libraries/wallet/wallet.cpp | 2 +- programs/network_mapper/network_mapper.cpp | 2 +- programs/witness_node/main.cpp | 8 ++++---- 22 files changed, 45 insertions(+), 35 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index b28fc7bb30..d78b9c1df6 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -975,7 +975,7 @@ uint8_t application_impl::get_current_block_interval_in_seconds() const namespace graphene { namespace app { application::application() - : my(new detail::application_impl(this)) + : my(std::make_unique(this)) {} application::~application() diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 919b7fe3d3..a86305005e 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -48,7 +48,7 @@ namespace graphene { namespace app { ////////////////////////////////////////////////////////////////////// database_api::database_api( graphene::chain::database& db, const application_options* app_options ) - : my( new database_api_impl( db, app_options ) ) {} + : my( std::make_unique( db, app_options ) ) {} database_api::~database_api() {} diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index 3429625598..3804701be0 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -306,8 +306,8 @@ namespace graphene { namespace chain { template void register_evaluator() { - _operation_evaluators[ - operation::tag::value].reset( new op_evaluator_impl() ); + _operation_evaluators[operation::tag::value] + = std::make_unique>(); } //////////////////// db_balance.cpp //////////////////// diff --git a/libraries/db/include/graphene/db/index.hpp b/libraries/db/include/graphene/db/index.hpp index b54e7266c7..a5f4ff1e7a 100644 --- a/libraries/db/include/graphene/db/index.hpp +++ b/libraries/db/include/graphene/db/index.hpp @@ -169,7 +169,7 @@ namespace graphene { namespace db { template T* add_secondary_index(Args... args) { - _sindex.emplace_back( new T(args...) ); + _sindex.emplace_back( std::make_unique(args...) ); return static_cast(_sindex.back().get()); } diff --git a/libraries/db/include/graphene/db/object.hpp b/libraries/db/include/graphene/db/object.hpp index 254b43483d..125ff4293e 100644 --- a/libraries/db/include/graphene/db/object.hpp +++ b/libraries/db/include/graphene/db/object.hpp @@ -88,7 +88,7 @@ namespace graphene { namespace db { public: virtual unique_ptr clone()const { - return unique_ptr(new DerivedClass( *static_cast(this) )); + return unique_ptr( std::make_unique( *static_cast(this) ) ); } virtual void move_from( object& obj ) diff --git a/libraries/db/include/graphene/db/object_database.hpp b/libraries/db/include/graphene/db/object_database.hpp index c7825572fb..d189cd1b1a 100644 --- a/libraries/db/include/graphene/db/object_database.hpp +++ b/libraries/db/include/graphene/db/object_database.hpp @@ -138,7 +138,7 @@ namespace graphene { namespace db { if( _index[ObjectType::space_id].size() <= ObjectType::type_id ) _index[ObjectType::space_id].resize( 255 ); assert(!_index[ObjectType::space_id][ObjectType::type_id]); - unique_ptr indexptr( new IndexType(*this) ); + unique_ptr indexptr( std::make_unique(*this) ); _index[ObjectType::space_id][ObjectType::type_id] = std::move(indexptr); return static_cast(_index[ObjectType::space_id][ObjectType::type_id].get()); } diff --git a/libraries/db/include/graphene/db/simple_index.hpp b/libraries/db/include/graphene/db/simple_index.hpp index 51679be2ad..7cbdb538f1 100644 --- a/libraries/db/include/graphene/db/simple_index.hpp +++ b/libraries/db/include/graphene/db/simple_index.hpp @@ -45,7 +45,7 @@ namespace graphene { namespace db { auto id = get_next_id(); auto instance = id.instance(); if( instance >= _objects.size() ) _objects.resize( instance + 1 ); - _objects[instance].reset(new T); + _objects[instance] = std::make_unique(); _objects[instance]->id = id; constructor( *_objects[instance] ); _objects[instance]->id = id; // just in case it changed @@ -65,7 +65,7 @@ namespace graphene { namespace db { assert( nullptr != dynamic_cast(&obj) ); if( _objects.size() <= instance ) _objects.resize( instance+1 ); assert( !_objects[instance] ); - _objects[instance].reset( new T( std::move( static_cast(obj) ) ) ); + _objects[instance] = std::make_unique( std::move( static_cast(obj) ) ); return *_objects[instance]; } diff --git a/libraries/net/include/graphene/net/peer_database.hpp b/libraries/net/include/graphene/net/peer_database.hpp index 8b7e18b894..3ca4d1b4d7 100644 --- a/libraries/net/include/graphene/net/peer_database.hpp +++ b/libraries/net/include/graphene/net/peer_database.hpp @@ -79,7 +79,7 @@ namespace graphene { namespace net { public: peer_database_iterator(); ~peer_database_iterator(); - explicit peer_database_iterator(peer_database_iterator_impl* impl); + explicit peer_database_iterator( std::unique_ptr&& impl ); peer_database_iterator( const peer_database_iterator& c ); private: diff --git a/libraries/net/message_oriented_connection.cpp b/libraries/net/message_oriented_connection.cpp index b62651fa76..804d53b115 100644 --- a/libraries/net/message_oriented_connection.cpp +++ b/libraries/net/message_oriented_connection.cpp @@ -273,7 +273,7 @@ namespace graphene { namespace net { elog("Trying to send a message larger than MAX_MESSAGE_SIZE. This probably won't work..."); //pad the message we send to a multiple of 16 bytes size_t size_with_padding = 16 * ((size_of_message_and_header + 15) / 16); - std::unique_ptr padded_message(new char[size_with_padding]); + std::unique_ptr padded_message( std::make_unique(size_with_padding) ); memcpy(padded_message.get(), (char*)&message_to_send, sizeof(message_header)); memcpy(padded_message.get() + sizeof(message_header), message_to_send.data.data(), message_to_send.size.value() ); @@ -355,7 +355,7 @@ namespace graphene { namespace net { message_oriented_connection::message_oriented_connection(message_oriented_connection_delegate* delegate) : - my(new detail::message_oriented_connection_impl(this, delegate)) + my( std::make_unique(this, delegate) ) { } diff --git a/libraries/net/peer_connection.cpp b/libraries/net/peer_connection.cpp index 12a0eccdb4..3485468204 100644 --- a/libraries/net/peer_connection.cpp +++ b/libraries/net/peer_connection.cpp @@ -107,8 +107,14 @@ namespace graphene { namespace net // current task yields. In the (not uncommon) case where it is the task executing // connect_to or read_loop, this allows the task to finish before the destructor is forced // to cancel it. - return peer_connection_ptr(new peer_connection(delegate)); - //, [](peer_connection* peer_to_delete){ fc::async([peer_to_delete](){delete peer_to_delete;}); }); + + // Implementation: derive peer_connection so that make_shared has access to the constructor + class peer_connection_subclass : public peer_connection + { + public: + peer_connection_subclass(peer_connection_delegate* delegate) : peer_connection(delegate) {} + }; + return std::make_shared(delegate); } void peer_connection::destroy() @@ -375,7 +381,8 @@ namespace graphene { namespace net VERIFY_CORRECT_THREAD(); //dlog("peer_connection::send_message() enqueueing message of type ${type} for peer ${endpoint}", // ("type", message_to_send.msg_type)("endpoint", get_remote_endpoint())); - std::unique_ptr message_to_enqueue(new real_queued_message(message_to_send, message_send_time_field_offset)); + std::unique_ptr message_to_enqueue( + std::make_unique(message_to_send, message_send_time_field_offset) ); send_queueable_message(std::move(message_to_enqueue)); } @@ -384,7 +391,8 @@ namespace graphene { namespace net VERIFY_CORRECT_THREAD(); //dlog("peer_connection::send_item() enqueueing message of type ${type} for peer ${endpoint}", // ("type", item_to_send.item_type)("endpoint", get_remote_endpoint())); - std::unique_ptr message_to_enqueue(new virtual_queued_message(item_to_send)); + std::unique_ptr message_to_enqueue( + std::make_unique(item_to_send) ); send_queueable_message(std::move(message_to_enqueue)); } diff --git a/libraries/net/peer_database.cpp b/libraries/net/peer_database.cpp index ac8c9eeb19..f5fff7ac9e 100644 --- a/libraries/net/peer_database.cpp +++ b/libraries/net/peer_database.cpp @@ -173,12 +173,14 @@ namespace graphene { namespace net { peer_database::iterator peer_database_impl::begin() const { - return peer_database::iterator(new peer_database_iterator_impl(_potential_peer_set.get().begin())); + return peer_database::iterator( std::make_unique( + _potential_peer_set.get().begin() ) ); } peer_database::iterator peer_database_impl::end() const { - return peer_database::iterator(new peer_database_iterator_impl(_potential_peer_set.get().end())); + return peer_database::iterator( std::make_unique( + _potential_peer_set.get().end() ) ); } size_t peer_database_impl::size() const @@ -194,8 +196,8 @@ namespace graphene { namespace net { { } - peer_database_iterator::peer_database_iterator(peer_database_iterator_impl* impl) : - my(impl) + peer_database_iterator::peer_database_iterator( std::unique_ptr&& impl) : + my( std::move(impl) ) { } @@ -217,7 +219,7 @@ namespace graphene { namespace net { } // end namespace detail peer_database::peer_database() : - my(new detail::peer_database_impl) + my( std::make_unique() ) { } diff --git a/libraries/plugins/account_history/account_history_plugin.cpp b/libraries/plugins/account_history/account_history_plugin.cpp index 5f9e4c67f6..c0bbcebc2e 100644 --- a/libraries/plugins/account_history/account_history_plugin.cpp +++ b/libraries/plugins/account_history/account_history_plugin.cpp @@ -283,7 +283,7 @@ void account_history_plugin_impl::add_account_history( const account_id_type acc account_history_plugin::account_history_plugin() : - my( new detail::account_history_plugin_impl(*this) ) + my( std::make_unique(*this) ) { } diff --git a/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp b/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp index 9c95c8e4ff..548c5fc689 100644 --- a/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp +++ b/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp @@ -151,7 +151,7 @@ class api_helper_indexes_impl } // end namespace detail api_helper_indexes::api_helper_indexes() : - my( new detail::api_helper_indexes_impl(*this) ) + my( std::make_unique(*this) ) { } diff --git a/libraries/plugins/custom_operations/custom_operations_plugin.cpp b/libraries/plugins/custom_operations/custom_operations_plugin.cpp index 70f898fa49..c9c6b21f18 100644 --- a/libraries/plugins/custom_operations/custom_operations_plugin.cpp +++ b/libraries/plugins/custom_operations/custom_operations_plugin.cpp @@ -106,7 +106,7 @@ custom_operations_plugin_impl::~custom_operations_plugin_impl() } // end namespace detail custom_operations_plugin::custom_operations_plugin() : - my( new detail::custom_operations_plugin_impl(*this) ) + my( std::make_unique(*this) ) { } diff --git a/libraries/plugins/delayed_node/delayed_node_plugin.cpp b/libraries/plugins/delayed_node/delayed_node_plugin.cpp index 4f08260207..d85b6291e7 100644 --- a/libraries/plugins/delayed_node/delayed_node_plugin.cpp +++ b/libraries/plugins/delayed_node/delayed_node_plugin.cpp @@ -89,7 +89,7 @@ void delayed_node_plugin::connect() void delayed_node_plugin::plugin_initialize(const boost::program_options::variables_map& options) { FC_ASSERT(options.count("trusted-node") > 0); - my = std::unique_ptr{ new detail::delayed_node_plugin_impl() }; + my = std::make_unique(); my->remote_endpoint = "ws://" + options.at("trusted-node").as(); } diff --git a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp index 07189c9af5..3d80c64f1c 100644 --- a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp +++ b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp @@ -434,7 +434,7 @@ void elasticsearch_plugin_impl::populateESstruct() } // end namespace detail elasticsearch_plugin::elasticsearch_plugin() : - my( new detail::elasticsearch_plugin_impl(*this) ) + my( std::make_unique(*this) ) { } diff --git a/libraries/plugins/es_objects/es_objects.cpp b/libraries/plugins/es_objects/es_objects.cpp index f89a11065b..7be78a2630 100644 --- a/libraries/plugins/es_objects/es_objects.cpp +++ b/libraries/plugins/es_objects/es_objects.cpp @@ -275,7 +275,7 @@ es_objects_plugin_impl::~es_objects_plugin_impl() } // end namespace detail es_objects_plugin::es_objects_plugin() : - my( new detail::es_objects_plugin_impl(*this) ) + my( std::make_unique(*this) ) { } diff --git a/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp b/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp index 96705ca22d..b83ee7d8f7 100644 --- a/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp +++ b/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp @@ -242,7 +242,7 @@ grouped_orders_plugin_impl::~grouped_orders_plugin_impl() grouped_orders_plugin::grouped_orders_plugin() : - my( new detail::grouped_orders_plugin_impl(*this) ) + my( std::make_unique(*this) ) { } diff --git a/libraries/plugins/market_history/market_history_plugin.cpp b/libraries/plugins/market_history/market_history_plugin.cpp index 819f38ff59..b6d3800d4a 100644 --- a/libraries/plugins/market_history/market_history_plugin.cpp +++ b/libraries/plugins/market_history/market_history_plugin.cpp @@ -736,7 +736,7 @@ void market_history_plugin_impl::update_liquidity_pool_histories( market_history_plugin::market_history_plugin() : - my( new detail::market_history_plugin_impl(*this) ) + my( std::make_unique(*this) ) { } diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 65218e6998..5662592264 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -151,7 +151,7 @@ namespace graphene { namespace wallet { namespace graphene { namespace wallet { wallet_api::wallet_api(const wallet_data& initial_data, fc::api rapi) - : my(new detail::wallet_api_impl(*this, initial_data, rapi)) + : my( std::make_unique(*this, initial_data, rapi) ) { } diff --git a/programs/network_mapper/network_mapper.cpp b/programs/network_mapper/network_mapper.cpp index 91ed8f2fc8..8b99a47fd6 100644 --- a/programs/network_mapper/network_mapper.cpp +++ b/programs/network_mapper/network_mapper.cpp @@ -211,7 +211,7 @@ int main(int argc, char** argv) try { - std::shared_ptr probe(new peer_probe()); + std::shared_ptr probe = std::make_shared(); probe->start(remote, my_node_id, chain_id); probes.emplace_back( std::move( probe ) ); } diff --git a/programs/witness_node/main.cpp b/programs/witness_node/main.cpp index d8f6547233..b57a7b0e1f 100644 --- a/programs/witness_node/main.cpp +++ b/programs/witness_node/main.cpp @@ -62,7 +62,7 @@ namespace bpo = boost::program_options; int main(int argc, char** argv) { fc::print_stacktrace_on_segfault(); - app::application* node = new app::application(); + std::unique_ptr node = std::make_unique(); fc::oexception unhandled_exception; try { bpo::options_description app_options("BitShares Witness Node"); @@ -158,7 +158,7 @@ int main(int argc, char** argv) { return 1; } - std::for_each(plugins.begin(), plugins.end(), [node](const std::string& plug) mutable { + std::for_each(plugins.begin(), plugins.end(), [&node](const std::string& plug) mutable { if (!plug.empty()) { node->enable_plugin(plug); } @@ -191,7 +191,7 @@ int main(int argc, char** argv) { ilog("Exiting from signal ${n}", ("n", signal)); node->shutdown_plugins(); node->shutdown(); - delete node; + node.reset(); return EXIT_SUCCESS; } catch( const fc::exception& e ) { // deleting the node can yield, so do this outside the exception handler @@ -202,7 +202,7 @@ int main(int argc, char** argv) { { elog("Exiting with error:\n${e}", ("e", unhandled_exception->to_detail_string())); node->shutdown(); - delete node; + node.reset(); return EXIT_FAILURE; } } From 0aa383154ce191d708f7d143b27662bc171ed239 Mon Sep 17 00:00:00 2001 From: abitmore Date: Wed, 24 Mar 2021 09:23:25 +0000 Subject: [PATCH 086/147] Replace dynamic-length raw char array with vector --- libraries/net/message_oriented_connection.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libraries/net/message_oriented_connection.cpp b/libraries/net/message_oriented_connection.cpp index 804d53b115..3ddc54a34a 100644 --- a/libraries/net/message_oriented_connection.cpp +++ b/libraries/net/message_oriented_connection.cpp @@ -273,17 +273,18 @@ namespace graphene { namespace net { elog("Trying to send a message larger than MAX_MESSAGE_SIZE. This probably won't work..."); //pad the message we send to a multiple of 16 bytes size_t size_with_padding = 16 * ((size_of_message_and_header + 15) / 16); - std::unique_ptr padded_message( std::make_unique(size_with_padding) ); + std::vector padded_message( size_with_padding ); - memcpy(padded_message.get(), (char*)&message_to_send, sizeof(message_header)); - memcpy(padded_message.get() + sizeof(message_header), message_to_send.data.data(), message_to_send.size.value() ); - char* padding_space = padded_message.get() + sizeof(message_header) + message_to_send.size.value(); + memcpy( padded_message.data(), (const char*)&message_to_send, sizeof(message_header) ); + memcpy( padded_message.data() + sizeof(message_header), message_to_send.data.data(), + message_to_send.size.value() ); + char* padding_space = padded_message.data() + sizeof(message_header) + message_to_send.size.value(); memset(padding_space, 0, size_with_padding - size_of_message_and_header); - _sock.write(padded_message.get(), size_with_padding); + _sock.write( padded_message.data(), size_with_padding ); _sock.flush(); _bytes_sent += size_with_padding; _last_message_sent_time = fc::time_point::now(); - } FC_RETHROW_EXCEPTIONS( warn, "unable to send message" ); + } FC_RETHROW_EXCEPTIONS( warn, "unable to send message" ) } void message_oriented_connection_impl::close_connection() From bd02ee1fef686e92f3b6bb571e862cf9303fe478 Mon Sep 17 00:00:00 2001 From: abitmore Date: Wed, 24 Mar 2021 09:49:00 +0000 Subject: [PATCH 087/147] Fix code smells --- .../net/include/graphene/net/peer_connection.hpp | 11 +++++------ .../net/include/graphene/net/peer_database.hpp | 4 ++-- libraries/net/peer_connection.cpp | 13 ++++++------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/libraries/net/include/graphene/net/peer_connection.hpp b/libraries/net/include/graphene/net/peer_connection.hpp index 88fdba62f5..dab894ce76 100644 --- a/libraries/net/include/graphene/net/peer_connection.hpp +++ b/libraries/net/include/graphene/net/peer_connection.hpp @@ -69,8 +69,7 @@ namespace graphene { namespace net virtual message get_message_for_item(const item_id& item) = 0; }; - class peer_connection; - typedef std::shared_ptr peer_connection_ptr; + using peer_connection_ptr = std::shared_ptr; class peer_connection : public message_oriented_connection_delegate, public std::enable_shared_from_this { @@ -117,7 +116,7 @@ namespace graphene { namespace net fc::time_point transmission_start_time; fc::time_point transmission_finish_time; - queued_message(fc::time_point enqueue_time = fc::time_point::now()) : + explicit queued_message(fc::time_point enqueue_time = fc::time_point::now()) : enqueue_time(enqueue_time) {} @@ -126,7 +125,7 @@ namespace graphene { namespace net * it is sitting on the queue */ virtual size_t get_size_in_queue() = 0; - virtual ~queued_message() {} + virtual ~queued_message() = default; }; /* when you queue up a 'real_queued_message', a full copy of the message is @@ -155,8 +154,8 @@ namespace graphene { namespace net { item_id item_to_send; - virtual_queued_message(item_id item_to_send) : - item_to_send(std::move(item_to_send)) + explicit virtual_queued_message(item_id the_item_to_send) : + item_to_send(std::move(the_item_to_send)) {} message get_message(peer_connection_delegate* node) override; diff --git a/libraries/net/include/graphene/net/peer_database.hpp b/libraries/net/include/graphene/net/peer_database.hpp index 3ca4d1b4d7..edc046e7c8 100644 --- a/libraries/net/include/graphene/net/peer_database.hpp +++ b/libraries/net/include/graphene/net/peer_database.hpp @@ -97,7 +97,7 @@ namespace graphene { namespace net { { public: peer_database(); - ~peer_database(); + virtual ~peer_database(); void open(const fc::path& databaseFilename); void close(); @@ -109,7 +109,7 @@ namespace graphene { namespace net { potential_peer_record lookup_or_create_entry_for_endpoint(const fc::ip::endpoint& endpointToLookup); fc::optional lookup_entry_for_endpoint(const fc::ip::endpoint& endpointToLookup); - typedef detail::peer_database_iterator iterator; + using iterator = detail::peer_database_iterator; iterator begin() const; iterator end() const; size_t size() const; diff --git a/libraries/net/peer_connection.cpp b/libraries/net/peer_connection.cpp index 3485468204..d613979726 100644 --- a/libraries/net/peer_connection.cpp +++ b/libraries/net/peer_connection.cpp @@ -112,7 +112,7 @@ namespace graphene { namespace net class peer_connection_subclass : public peer_connection { public: - peer_connection_subclass(peer_connection_delegate* delegate) : peer_connection(delegate) {} + explicit peer_connection_subclass(peer_connection_delegate* delegate) : peer_connection(delegate) {} }; return std::make_shared(delegate); } @@ -380,9 +380,9 @@ namespace graphene { namespace net { VERIFY_CORRECT_THREAD(); //dlog("peer_connection::send_message() enqueueing message of type ${type} for peer ${endpoint}", - // ("type", message_to_send.msg_type)("endpoint", get_remote_endpoint())); - std::unique_ptr message_to_enqueue( - std::make_unique(message_to_send, message_send_time_field_offset) ); + // ("type", message_to_send.msg_type)("endpoint", get_remote_endpoint())); // for debug + auto message_to_enqueue = std::make_unique( + message_to_send, message_send_time_field_offset ); send_queueable_message(std::move(message_to_enqueue)); } @@ -390,9 +390,8 @@ namespace graphene { namespace net { VERIFY_CORRECT_THREAD(); //dlog("peer_connection::send_item() enqueueing message of type ${type} for peer ${endpoint}", - // ("type", item_to_send.item_type)("endpoint", get_remote_endpoint())); - std::unique_ptr message_to_enqueue( - std::make_unique(item_to_send) ); + // ("type", item_to_send.item_type)("endpoint", get_remote_endpoint())); // for debug + auto message_to_enqueue = std::make_unique(item_to_send); send_queueable_message(std::move(message_to_enqueue)); } From 4d452191360db5b0d59e87200d1df9f4a0c8c4f3 Mon Sep 17 00:00:00 2001 From: abitmore Date: Wed, 24 Mar 2021 09:51:10 +0000 Subject: [PATCH 088/147] Replace redundant type with auto --- programs/network_mapper/network_mapper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/network_mapper/network_mapper.cpp b/programs/network_mapper/network_mapper.cpp index 8b99a47fd6..81272fd4e7 100644 --- a/programs/network_mapper/network_mapper.cpp +++ b/programs/network_mapper/network_mapper.cpp @@ -211,7 +211,7 @@ int main(int argc, char** argv) try { - std::shared_ptr probe = std::make_shared(); + auto probe = std::make_shared(); probe->start(remote, my_node_id, chain_id); probes.emplace_back( std::move( probe ) ); } From 38800ff746c19f77d0e551f85c2c22a991dc6fd9 Mon Sep 17 00:00:00 2001 From: abitmore Date: Wed, 24 Mar 2021 14:19:58 +0000 Subject: [PATCH 089/147] Replace another redundant type with auto --- programs/witness_node/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/witness_node/main.cpp b/programs/witness_node/main.cpp index b57a7b0e1f..b2dd6d77d6 100644 --- a/programs/witness_node/main.cpp +++ b/programs/witness_node/main.cpp @@ -62,7 +62,7 @@ namespace bpo = boost::program_options; int main(int argc, char** argv) { fc::print_stacktrace_on_segfault(); - std::unique_ptr node = std::make_unique(); + auto node = std::make_unique(); fc::oexception unhandled_exception; try { bpo::options_description app_options("BitShares Witness Node"); From afd64de9834e8ef2bdec2a07e00bc31940730f0f Mon Sep 17 00:00:00 2001 From: abitmore Date: Fri, 26 Mar 2021 14:54:23 +0000 Subject: [PATCH 090/147] Update database_fixture_base destructor To cleanup properly. --- tests/common/database_fixture.cpp | 33 +++++++++++++++---------------- tests/common/database_fixture.hpp | 2 +- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index fbc6d7e3b6..92bdfabc36 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -89,23 +89,6 @@ database_fixture_base::database_fixture_base() database_fixture_base::~database_fixture_base() { - try { - // If we're unwinding due to an exception, don't do any more checks. - // This way, boost test's last checkpoint tells us approximately where the error was. - if( !std::uncaught_exception() ) - { - verify_asset_supplies(db); - BOOST_CHECK( db.get_node_properties().skip_flags == database::skip_nothing ); - } - return; - } catch (fc::exception& ex) { - BOOST_FAIL( std::string("fc::exception in ~database_fixture: ") + ex.to_detail_string() ); - } catch (std::exception& e) { - BOOST_FAIL( std::string("std::exception in ~database_fixture:") + e.what() ); - } catch (...) { - BOOST_FAIL( "Uncaught exception in ~database_fixture" ); - } - // cleanup data in ES if( !es_index_prefix.empty() || !es_obj_index_prefix.empty() ) { @@ -140,6 +123,22 @@ database_fixture_base::~database_fixture_base() } } + try { + // If we're unwinding due to an exception, don't do any more checks. + // This way, boost test's last checkpoint tells us approximately where the error was. + if( !std::uncaught_exception() ) + { + verify_asset_supplies(db); + BOOST_CHECK( db.get_node_properties().skip_flags == database::skip_nothing ); + } + } catch (fc::exception& ex) { + BOOST_FAIL( std::string("fc::exception in ~database_fixture: ") + ex.to_detail_string() ); + } catch (std::exception& e) { + BOOST_FAIL( std::string("std::exception in ~database_fixture:") + e.what() ); + } catch (...) { + BOOST_FAIL( "Uncaught exception in ~database_fixture" ); + } + } void database_fixture_base::init_genesis( database_fixture_base& fixture ) diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index 000016050e..a8338b27b5 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -224,7 +224,7 @@ struct database_fixture_base { const std::string current_suite_name; database_fixture_base(); - ~database_fixture_base(); + virtual ~database_fixture_base(); template static void set_option( boost::program_options::variables_map& options, const std::string& name, const T& value ) From 00d8c7b6b055e546d8a32f42df0177c8d4706906 Mon Sep 17 00:00:00 2001 From: abitmore Date: Fri, 26 Mar 2021 16:32:45 +0000 Subject: [PATCH 091/147] Move db_fixture_base member init to constructor --- tests/common/database_fixture.cpp | 2 ++ tests/common/database_fixture.hpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 92bdfabc36..cca8b293a9 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -70,6 +70,8 @@ void clearable_block::clear() database_fixture_base::database_fixture_base() : app(), db( *app.chain_database() ), + private_key( fc::ecc::private_key::generate() ), + init_account_priv_key( fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ) ), init_account_pub_key( init_account_priv_key.get_public_key() ), current_test_name( buf::current_test_case().p_name.value ), current_suite_name( buf::get(buf::current_test_case().p_parent_id).p_name diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index a8338b27b5..339388d123 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -207,8 +207,8 @@ struct database_fixture_base { signed_transaction trx; public_key_type committee_key; account_id_type committee_account; - const fc::ecc::private_key private_key = fc::ecc::private_key::generate(); - const fc::ecc::private_key init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ); + const fc::ecc::private_key private_key; + const fc::ecc::private_key init_account_priv_key; const public_key_type init_account_pub_key; fc::temp_directory data_dir; From 1db990562716f0ab96607be44ad8380a8c4049ac Mon Sep 17 00:00:00 2001 From: abitmore Date: Fri, 26 Mar 2021 16:48:41 +0000 Subject: [PATCH 092/147] Remove Extra initialization of db_fixture.app --- tests/common/database_fixture.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index cca8b293a9..19a7b9bc5f 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -427,9 +427,6 @@ boost::program_options::variables_map database_fixture_base::init_options( datab options.insert(std::make_pair("bucket-size", boost::program_options::variable_value(string("[15]"),false))); - // apply api limits, initialize the "has_market_history_plugin" variable and etc in app_options - fixture.app.initialize(graphene::utilities::temp_directory_path(), options); - auto mhplugin = fixture.app.register_plugin(true); auto goplugin = fixture.app.register_plugin(true); From 10b64a23f017b77dd4cb16c71463483ddc16364d Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 27 Mar 2021 01:04:57 +0000 Subject: [PATCH 093/147] Fix typo in logging --- libraries/db/object_database.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/db/object_database.cpp b/libraries/db/object_database.cpp index 75b7090be4..6767051264 100644 --- a/libraries/db/object_database.cpp +++ b/libraries/db/object_database.cpp @@ -98,7 +98,7 @@ void object_database::wipe(const fc::path& data_dir) close(); ilog("Wiping object database..."); fc::remove_all(data_dir / "object_database"); - ilog("Done wiping object databse."); + ilog("Done wiping object database."); } void object_database::open(const fc::path& data_dir) From 8ed1ce29dc4b2bea0841806fe13a1eff92640005 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 28 Mar 2021 03:04:13 +0000 Subject: [PATCH 094/147] Refactor application and plugin framework --- libraries/app/application.cpp | 171 +++++++++++------- libraries/app/application_impl.hxx | 25 ++- .../app/include/graphene/app/application.hpp | 15 +- libraries/app/include/graphene/app/plugin.hpp | 42 ++--- libraries/app/plugin.cpp | 25 +-- .../account_history_plugin.cpp | 10 +- .../account_history_plugin.hpp | 10 +- .../api_helper_indexes/api_helper_indexes.cpp | 3 +- .../api_helper_indexes/api_helper_indexes.hpp | 4 +- .../custom_operations_plugin.cpp | 5 +- .../custom_operations_plugin.hpp | 10 +- libraries/plugins/debug_witness/debug_api.cpp | 4 +- .../plugins/debug_witness/debug_witness.cpp | 12 +- .../graphene/debug_witness/debug_witness.hpp | 12 +- .../delayed_node/delayed_node_plugin.cpp | 5 +- .../delayed_node/delayed_node_plugin.hpp | 10 +- .../elasticsearch/elasticsearch_plugin.cpp | 3 +- .../elasticsearch/elasticsearch_plugin.hpp | 10 +- libraries/plugins/es_objects/es_objects.cpp | 3 +- .../graphene/es_objects/es_objects.hpp | 10 +- .../grouped_orders/grouped_orders_plugin.cpp | 3 +- .../grouped_orders/grouped_orders_plugin.hpp | 10 +- .../market_history/market_history_plugin.hpp | 10 +- .../market_history/market_history_plugin.cpp | 3 +- .../include/graphene/snapshot/snapshot.hpp | 8 +- libraries/plugins/snapshot/snapshot.cpp | 4 - .../template_plugin/template_plugin.hpp | 13 +- .../template_plugin/template_plugin.cpp | 26 ++- .../include/graphene/witness/witness.hpp | 13 +- libraries/plugins/witness/witness.cpp | 5 - programs/witness_node/main.cpp | 88 +++++---- 31 files changed, 313 insertions(+), 259 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index e1ff23f2ce..827c5c4144 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -114,6 +114,11 @@ namespace detail { namespace graphene { namespace app { namespace detail { +application_impl::~application_impl() +{ + this->shutdown(); +} + void application_impl::reset_p2p_node(const fc::path& data_dir) { try { _p2p_network = std::make_shared("BitShares Reference Implementation"); @@ -158,7 +163,7 @@ void application_impl::reset_p2p_node(const fc::path& data_dir) void application_impl::new_connection( const fc::http::websocket_connection_ptr& c ) { auto wsc = std::make_shared(c, GRAPHENE_NET_MAX_NESTED_OBJECTS); - auto login = std::make_shared( std::ref(*_self) ); + auto login = std::make_shared( _self ); login->enable_api("database_api"); wsc->register_api(login->database()); @@ -236,8 +241,17 @@ void application_impl::set_dbg_init_key( graphene::chain::genesis_state_type& ge genesis.initial_witness_candidates[i].block_signing_key = init_pubkey; } -void application_impl::initialize() +void application_impl::initialize(const fc::path& data_dir, shared_ptr options) { + _data_dir = data_dir; + _options = options; + + if ( _options->count("io-threads") > 0 ) + { + const uint16_t num_threads = _options->at("io-threads").as(); + fc::asio::default_io_service_scope::set_num_threads(num_threads); + } + if( _options->count("force-validate") > 0 ) { ilog( "All transaction signatures will be validated" ); @@ -287,6 +301,7 @@ void application_impl::initialize() _apiaccess.permission_map["*"] = wild_access; } + initialize_plugins(); } void application_impl::set_api_limit() { @@ -501,8 +516,11 @@ void application_impl::startup() throw; } + startup_plugins(); + if( _active_plugins.find( "delayed_node" ) == _active_plugins.end() ) reset_p2p_node(_data_dir); + reset_websocket_server(); reset_websocket_tls_server(); } FC_LOG_AND_RETHROW() } @@ -621,7 +639,7 @@ bool application_impl::handle_block(const graphene::net::block_message& blk_msg, if( !_is_finished_syncing && !sync_mode ) { _is_finished_syncing = true; - _self->syncing_finished(); + _self.syncing_finished(); } } FC_CAPTURE_AND_RETHROW( (blk_msg)(sync_mode) ) return false; } @@ -969,29 +987,92 @@ uint8_t application_impl::get_current_block_interval_in_seconds() const return _chain_db->get_global_properties().parameters.block_interval; } +void application_impl::shutdown() +{ + if( _websocket_tls_server ) + _websocket_tls_server.reset(); + if( _websocket_server ) + _websocket_server.reset(); + // TODO wait until all connections are closed and messages handled? + // plugins E.G. witness_plugin may send data to p2p network, so shutdown them first + shutdown_plugins(); -} } } // namespace graphene namespace app namespace detail + if( _p2p_network ) + { + _p2p_network->close(); + _p2p_network.reset(); + // TODO wait until all connections are closed and messages handled? + } -namespace graphene { namespace app { + if( _chain_db ) + { + _chain_db->close(); + _chain_db.reset(); + } +} -application::application() - : my(std::make_unique(this)) -{} +void application_impl::enable_plugin( const string& name ) +{ + FC_ASSERT(_available_plugins[name], "Unknown plugin '" + name + "'"); + _active_plugins[name] = _available_plugins[name]; +} -application::~application() +void application_impl::initialize_plugins() { - if( my->_p2p_network ) + for( auto& entry : _active_plugins ) { - my->_p2p_network->close(); - my->_p2p_network.reset(); + ilog( "Initializing plugin ${name}", ( "name", entry.second->plugin_name() ) ); + entry.second->plugin_initialize( *_options ); + ilog( "Initialized plugin ${name}", ( "name", entry.second->plugin_name() ) ); } - if( my->_chain_db ) +} + +void application_impl::startup_plugins() +{ + for( auto& entry : _active_plugins ) { - my->_chain_db->close(); + ilog( "Starting plugin ${name}", ( "name", entry.second->plugin_name() ) ); + entry.second->plugin_startup(); + ilog( "Started plugin ${name}", ( "name", entry.second->plugin_name() ) ); } } +void application_impl::shutdown_plugins() +{ + for( auto& entry : _active_plugins ) + { + ilog( "Stopping plugin ${name}", ( "name", entry.second->plugin_name() ) ); + entry.second->plugin_shutdown(); + ilog( "Stopped plugin ${name}", ( "name", entry.second->plugin_name() ) ); + } +} + +void application_impl::add_available_plugin(std::shared_ptr p) +{ + _available_plugins[p->plugin_name()] = p; +} + +void application_impl::set_block_production(bool producing_blocks) +{ + _is_block_producer = producing_blocks; +} + +} } } // namespace graphene namespace app namespace detail + +namespace graphene { namespace app { + +application::application() + : my(std::make_unique(*this)) +{ + //nothing else to do +} + +application::~application() +{ + //nothing to do +} + void application::set_program_options(boost::program_options::options_description& command_line_options, boost::program_options::options_description& configuration_file_options) const { @@ -1097,18 +1178,9 @@ void application::set_program_options(boost::program_options::options_descriptio configuration_file_options.add(_cfg_options); } -void application::initialize(const fc::path& data_dir, const boost::program_options::variables_map& options) +void application::initialize(const fc::path& data_dir, std::shared_ptr options) { - my->_data_dir = data_dir; - my->_options = &options; - - if ( options.count("io-threads") > 0 ) - { - const uint16_t num_threads = options["io-threads"].as(); - fc::asio::default_io_service_scope::set_num_threads(num_threads); - } - - my->initialize(); + my->initialize( data_dir, options ); } void application::startup() @@ -1158,7 +1230,7 @@ std::shared_ptr application::chain_database() const void application::set_block_production(bool producing_blocks) { - my->_is_block_producer = producing_blocks; + my->set_block_production(producing_blocks); } optional< api_access_info > application::get_api_access_info( const string& username )const @@ -1176,56 +1248,19 @@ bool application::is_finished_syncing() const return my->_is_finished_syncing; } -void graphene::app::application::enable_plugin(const string& name) +void application::enable_plugin(const string& name) { - FC_ASSERT(my->_available_plugins[name], "Unknown plugin '" + name + "'"); - my->_active_plugins[name] = my->_available_plugins[name]; - my->_active_plugins[name]->plugin_set_app(this); + my->enable_plugin(name); } -void graphene::app::application::add_available_plugin(std::shared_ptr p) +void application::add_available_plugin(std::shared_ptr p) { - my->_available_plugins[p->plugin_name()] = p; + my->add_available_plugin(p); } -void application::shutdown_plugins() -{ - for( auto& entry : my->_active_plugins ) - { - ilog( "Stopping plugin ${name}", ( "name", entry.second->plugin_name() ) ); - entry.second->plugin_shutdown(); - ilog( "Stopped plugin ${name}", ( "name", entry.second->plugin_name() ) ); - } -} void application::shutdown() { - if( my->_p2p_network ) - my->_p2p_network->close(); - if( my->_chain_db ) - { - my->_chain_db->close(); - my->_chain_db = nullptr; - } -} - -void application::initialize_plugins( const boost::program_options::variables_map& options ) -{ - for( auto& entry : my->_active_plugins ) - { - ilog( "Initializing plugin ${name}", ( "name", entry.second->plugin_name() ) ); - entry.second->plugin_initialize( options ); - ilog( "Initialized plugin ${name}", ( "name", entry.second->plugin_name() ) ); - } -} - -void application::startup_plugins() -{ - for( auto& entry : my->_active_plugins ) - { - ilog( "Starting plugin ${name}", ( "name", entry.second->plugin_name() ) ); - entry.second->plugin_startup(); - ilog( "Started plugin ${name}", ( "name", entry.second->plugin_name() ) ); - } + my->shutdown(); } const application_options& application::get_options() diff --git a/libraries/app/application_impl.hxx b/libraries/app/application_impl.hxx index 9218770c7c..e95e7b6ed1 100644 --- a/libraries/app/application_impl.hxx +++ b/libraries/app/application_impl.hxx @@ -28,21 +28,22 @@ class application_impl : public net::node_delegate void reset_websocket_tls_server(); - explicit application_impl(application* self) + explicit application_impl(application& self) : _self(self), _chain_db(std::make_shared()) { } - virtual ~application_impl() - { - } + virtual ~application_impl(); + + void set_block_production(bool producing_blocks); void set_dbg_init_key( graphene::chain::genesis_state_type& genesis, const std::string& init_key ); void set_api_limit(); - void initialize(); + void initialize(const fc::path& data_dir, std::shared_ptr options); void startup(); + void shutdown(); fc::optional< api_access_info > get_api_access_info(const string& username)const; @@ -183,13 +184,19 @@ class application_impl : public net::node_delegate uint8_t get_current_block_interval_in_seconds() const override; + /// Add an available plugin + void add_available_plugin( std::shared_ptr p ); + + /// Enables a plugin + void enable_plugin(const string& name); + /// Returns whether a plugin is enabled bool is_plugin_enabled(const string& name) const; - application* _self; + application& _self; fc::path _data_dir; - const boost::program_options::variables_map* _options = nullptr; + std::shared_ptr _options; api_access _apiaccess; std::shared_ptr _chain_db; @@ -202,6 +209,10 @@ class application_impl : public net::node_delegate bool _is_finished_syncing = false; private: + void initialize_plugins(); + void startup_plugins(); + void shutdown_plugins(); + fc::serial_valve valve; }; diff --git a/libraries/app/include/graphene/app/application.hpp b/libraries/app/include/graphene/app/application.hpp index f3f54ae54e..4ccd8b031d 100644 --- a/libraries/app/include/graphene/app/application.hpp +++ b/libraries/app/include/graphene/app/application.hpp @@ -85,20 +85,17 @@ namespace graphene { namespace app { void set_program_options(boost::program_options::options_description& command_line_options, boost::program_options::options_description& configuration_file_options)const; - void initialize(const fc::path& data_dir, const boost::program_options::variables_map& options); - void initialize_plugins(const boost::program_options::variables_map& options); + void initialize(const fc::path& data_dir, std::shared_ptr options); void startup(); void shutdown(); - void startup_plugins(); - void shutdown_plugins(); template std::shared_ptr register_plugin(bool auto_load = false) { - auto plug = std::make_shared(); - plug->plugin_set_app(this); + auto plug = std::make_shared(*this); string cli_plugin_desc = plug->plugin_name() + " plugin. " + plug->plugin_description() + "\nOptions"; - boost::program_options::options_description plugin_cli_options( cli_plugin_desc ), plugin_cfg_options; + boost::program_options::options_description plugin_cli_options( cli_plugin_desc ); + boost::program_options::options_description plugin_cfg_options; plug->plugin_set_program_options(plugin_cli_options, plugin_cfg_options); if( !plugin_cli_options.options().empty() ) @@ -150,8 +147,10 @@ namespace graphene { namespace app { std::shared_ptr elasticsearch_thread; private: + /// Add an available plugin void add_available_plugin( std::shared_ptr p ); - std::shared_ptr my; + + std::unique_ptr my; boost::program_options::options_description _cli_options; boost::program_options::options_description _cfg_options; diff --git a/libraries/app/include/graphene/app/plugin.hpp b/libraries/app/include/graphene/app/plugin.hpp index 12e0fce798..b2809723ad 100644 --- a/libraries/app/include/graphene/app/plugin.hpp +++ b/libraries/app/include/graphene/app/plugin.hpp @@ -33,10 +33,18 @@ namespace graphene { namespace app { class abstract_plugin { public: - virtual ~abstract_plugin(){} + explicit abstract_plugin(application& a) : _app(a) {} + virtual ~abstract_plugin() = default; + + /// Get the name of the plugin virtual std::string plugin_name()const = 0; + + /// Get the description of the plugin virtual std::string plugin_description()const = 0; + /// Get a reference of the application bound to the plugin + application& app()const { return _app; } + /** * @brief Perform early startup routines and register plugin indexes, callbacks, etc. * @@ -66,13 +74,6 @@ class abstract_plugin */ virtual void plugin_shutdown() = 0; - /** - * @brief Register the application instance with the plugin. - * - * This is called by the framework to set the application. - */ - virtual void plugin_set_app( application* a ) = 0; - /** * @brief Fill in command line parameters used by the plugin. * @@ -88,6 +89,8 @@ class abstract_plugin boost::program_options::options_description& command_line_options, boost::program_options::options_description& config_file_options ) = 0; + protected: + application& _app; }; /** @@ -97,27 +100,22 @@ class abstract_plugin class plugin : public abstract_plugin { public: - plugin(); - virtual ~plugin() override; - - virtual std::string plugin_name()const override; - virtual std::string plugin_description()const override; - virtual void plugin_initialize( const boost::program_options::variables_map& options ) override; - virtual void plugin_startup() override; - virtual void plugin_shutdown() override; - virtual void plugin_set_app( application* app ) override; - virtual void plugin_set_program_options( + explicit plugin(application& a) : abstract_plugin(a) {} + ~plugin() override = default; + + std::string plugin_name()const override; + std::string plugin_description()const override; + void plugin_initialize( const boost::program_options::variables_map& options ) override; + void plugin_startup() override; + void plugin_shutdown() override; + void plugin_set_program_options( boost::program_options::options_description& command_line_options, boost::program_options::options_description& config_file_options ) override; chain::database& database() { return *app().chain_database(); } - application& app()const { assert(_app); return *_app; } protected: net::node_ptr p2p_node() { return app().p2p_node(); } - - private: - application* _app = nullptr; }; /// @ingroup Some useful tools for boost::program_options arguments using vectors of JSON strings diff --git a/libraries/app/plugin.cpp b/libraries/app/plugin.cpp index 02d1fdb828..58e781f3dd 100644 --- a/libraries/app/plugin.cpp +++ b/libraries/app/plugin.cpp @@ -27,17 +27,6 @@ namespace graphene { namespace app { -plugin::plugin() -{ - _app = nullptr; - return; -} - -plugin::~plugin() -{ - return; -} - std::string plugin::plugin_name()const { return ""; @@ -50,23 +39,17 @@ std::string plugin::plugin_description()const void plugin::plugin_initialize( const boost::program_options::variables_map& options ) { - return; + // nothing to do } void plugin::plugin_startup() { - return; + // nothing to do } void plugin::plugin_shutdown() { - return; -} - -void plugin::plugin_set_app( application* app ) -{ - _app = app; - return; + // nothing to do } void plugin::plugin_set_program_options( @@ -74,7 +57,7 @@ void plugin::plugin_set_program_options( boost::program_options::options_description& config_file_options ) { - return; + // nothing to do } } } // graphene::app diff --git a/libraries/plugins/account_history/account_history_plugin.cpp b/libraries/plugins/account_history/account_history_plugin.cpp index c0bbcebc2e..19e384a171 100644 --- a/libraries/plugins/account_history/account_history_plugin.cpp +++ b/libraries/plugins/account_history/account_history_plugin.cpp @@ -49,8 +49,6 @@ class account_history_plugin_impl account_history_plugin_impl(account_history_plugin& _plugin) : _self( _plugin ) { } - virtual ~account_history_plugin_impl(); - /** this method is called as a callback after a block is applied * and will process/index all operations that were applied in the block. @@ -76,11 +74,6 @@ class account_history_plugin_impl }; -account_history_plugin_impl::~account_history_plugin_impl() -{ - return; -} - void account_history_plugin_impl::update_account_histories( const signed_block& b ) { graphene::chain::database& db = database(); @@ -282,7 +275,8 @@ void account_history_plugin_impl::add_account_history( const account_id_type acc -account_history_plugin::account_history_plugin() : +account_history_plugin::account_history_plugin(graphene::app::application& app) : + plugin(app), my( std::make_unique(*this) ) { } diff --git a/libraries/plugins/account_history/include/graphene/account_history/account_history_plugin.hpp b/libraries/plugins/account_history/include/graphene/account_history/account_history_plugin.hpp index 99492768ce..9676869fbf 100644 --- a/libraries/plugins/account_history/include/graphene/account_history/account_history_plugin.hpp +++ b/libraries/plugins/account_history/include/graphene/account_history/account_history_plugin.hpp @@ -64,15 +64,15 @@ namespace detail class account_history_plugin : public graphene::app::plugin { public: - account_history_plugin(); - virtual ~account_history_plugin(); + account_history_plugin(graphene::app::application& app); + ~account_history_plugin() override; std::string plugin_name()const override; - virtual void plugin_set_program_options( + void plugin_set_program_options( boost::program_options::options_description& cli, boost::program_options::options_description& cfg) override; - virtual void plugin_initialize(const boost::program_options::variables_map& options) override; - virtual void plugin_startup() override; + void plugin_initialize(const boost::program_options::variables_map& options) override; + void plugin_startup() override; flat_set tracked_accounts()const; diff --git a/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp b/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp index 548c5fc689..00fbbf3e16 100644 --- a/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp +++ b/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp @@ -150,7 +150,8 @@ class api_helper_indexes_impl } // end namespace detail -api_helper_indexes::api_helper_indexes() : +api_helper_indexes::api_helper_indexes(graphene::app::application& app) : + plugin(app), my( std::make_unique(*this) ) { } diff --git a/libraries/plugins/api_helper_indexes/include/graphene/api_helper_indexes/api_helper_indexes.hpp b/libraries/plugins/api_helper_indexes/include/graphene/api_helper_indexes/api_helper_indexes.hpp index 49b79bee90..a6bb59b307 100644 --- a/libraries/plugins/api_helper_indexes/include/graphene/api_helper_indexes/api_helper_indexes.hpp +++ b/libraries/plugins/api_helper_indexes/include/graphene/api_helper_indexes/api_helper_indexes.hpp @@ -79,8 +79,8 @@ namespace detail class api_helper_indexes : public graphene::app::plugin { public: - api_helper_indexes(); - virtual ~api_helper_indexes(); + api_helper_indexes(graphene::app::application& app); + ~api_helper_indexes() override; std::string plugin_name()const override; std::string plugin_description()const override; diff --git a/libraries/plugins/custom_operations/custom_operations_plugin.cpp b/libraries/plugins/custom_operations/custom_operations_plugin.cpp index c9c6b21f18..1696b98f50 100644 --- a/libraries/plugins/custom_operations/custom_operations_plugin.cpp +++ b/libraries/plugins/custom_operations/custom_operations_plugin.cpp @@ -100,12 +100,13 @@ void custom_operations_plugin_impl::onBlock() custom_operations_plugin_impl::~custom_operations_plugin_impl() { - return; + // nothing to do } } // end namespace detail -custom_operations_plugin::custom_operations_plugin() : +custom_operations_plugin::custom_operations_plugin(graphene::app::application& app) : + plugin(app), my( std::make_unique(*this) ) { } diff --git a/libraries/plugins/custom_operations/include/graphene/custom_operations/custom_operations_plugin.hpp b/libraries/plugins/custom_operations/include/graphene/custom_operations/custom_operations_plugin.hpp index f4baacd573..e2a5fd9633 100644 --- a/libraries/plugins/custom_operations/include/graphene/custom_operations/custom_operations_plugin.hpp +++ b/libraries/plugins/custom_operations/include/graphene/custom_operations/custom_operations_plugin.hpp @@ -41,16 +41,16 @@ namespace detail class custom_operations_plugin : public graphene::app::plugin { public: - custom_operations_plugin(); - virtual ~custom_operations_plugin(); + custom_operations_plugin(graphene::app::application& app); + ~custom_operations_plugin() override; std::string plugin_name()const override; std::string plugin_description()const override; - virtual void plugin_set_program_options( + void plugin_set_program_options( boost::program_options::options_description& cli, boost::program_options::options_description& cfg) override; - virtual void plugin_initialize(const boost::program_options::variables_map& options) override; - virtual void plugin_startup() override; + void plugin_initialize(const boost::program_options::variables_map& options) override; + void plugin_startup() override; friend class detail::custom_operations_plugin_impl; std::unique_ptr my; diff --git a/libraries/plugins/debug_witness/debug_api.cpp b/libraries/plugins/debug_witness/debug_api.cpp index 43ffd6cd38..7fd8792af5 100644 --- a/libraries/plugins/debug_witness/debug_api.cpp +++ b/libraries/plugins/debug_witness/debug_api.cpp @@ -34,7 +34,9 @@ class debug_api_impl }; debug_api_impl::debug_api_impl( graphene::app::application& _app ) : app( _app ) -{} +{ + // Nothing else to do +} void debug_api_impl::debug_push_blocks( const std::string& src_filename, uint32_t count ) diff --git a/libraries/plugins/debug_witness/debug_witness.cpp b/libraries/plugins/debug_witness/debug_witness.cpp index ea7f209fa6..1a9533166a 100644 --- a/libraries/plugins/debug_witness/debug_witness.cpp +++ b/libraries/plugins/debug_witness/debug_witness.cpp @@ -38,7 +38,10 @@ using std::vector; namespace bpo = boost::program_options; -debug_witness_plugin::~debug_witness_plugin() {} +debug_witness_plugin::~debug_witness_plugin() +{ + cleanup(); +} void debug_witness_plugin::plugin_set_program_options( boost::program_options::options_description& command_line_options, @@ -100,7 +103,6 @@ void debug_witness_plugin::plugin_startup() _changed_objects_conn = db.changed_objects.connect([this](const std::vector& ids, const fc::flat_set& impacted_accounts){ on_changed_objects(ids, impacted_accounts); }); _removed_objects_conn = db.removed_objects.connect([this](const std::vector& ids, const std::vector& objs, const fc::flat_set& impacted_accounts){ on_removed_objects(ids, objs, impacted_accounts); }); - return; } void debug_witness_plugin::on_changed_objects( const std::vector& ids, const fc::flat_set& impacted_accounts ) @@ -155,11 +157,15 @@ void debug_witness_plugin::flush_json_object_stream() } void debug_witness_plugin::plugin_shutdown() +{ + cleanup(); +} + +void debug_witness_plugin::cleanup() { if( _json_object_stream ) { _json_object_stream->close(); _json_object_stream.reset(); } - return; } diff --git a/libraries/plugins/debug_witness/include/graphene/debug_witness/debug_witness.hpp b/libraries/plugins/debug_witness/include/graphene/debug_witness/debug_witness.hpp index 4b5369211a..e7d4f734d1 100644 --- a/libraries/plugins/debug_witness/include/graphene/debug_witness/debug_witness.hpp +++ b/libraries/plugins/debug_witness/include/graphene/debug_witness/debug_witness.hpp @@ -34,23 +34,25 @@ namespace graphene { namespace debug_witness_plugin { class debug_witness_plugin : public graphene::app::plugin { public: - ~debug_witness_plugin(); + debug_witness_plugin(graphene::app::application& app) : graphene::app::plugin(app) {} + ~debug_witness_plugin() override; std::string plugin_name()const override; - virtual void plugin_set_program_options( + void plugin_set_program_options( boost::program_options::options_description &command_line_options, boost::program_options::options_description &config_file_options ) override; - virtual void plugin_initialize( const boost::program_options::variables_map& options ) override; - virtual void plugin_startup() override; - virtual void plugin_shutdown() override; + void plugin_initialize( const boost::program_options::variables_map& options ) override; + void plugin_startup() override; + void plugin_shutdown() override; void set_json_object_stream( const std::string& filename ); void flush_json_object_stream(); private: + void cleanup(); void on_changed_objects( const std::vector& ids, const fc::flat_set& impacted_accounts ); void on_removed_objects( const std::vector& ids, const std::vector objs, const fc::flat_set& impacted_accounts ); diff --git a/libraries/plugins/delayed_node/delayed_node_plugin.cpp b/libraries/plugins/delayed_node/delayed_node_plugin.cpp index d85b6291e7..18ef6b26b1 100644 --- a/libraries/plugins/delayed_node/delayed_node_plugin.cpp +++ b/libraries/plugins/delayed_node/delayed_node_plugin.cpp @@ -46,8 +46,9 @@ struct delayed_node_plugin_impl { }; } -delayed_node_plugin::delayed_node_plugin() - : my(nullptr) +delayed_node_plugin::delayed_node_plugin(graphene::app::application& app) : + plugin(app), + my(nullptr) {} delayed_node_plugin::~delayed_node_plugin() diff --git a/libraries/plugins/delayed_node/include/graphene/delayed_node/delayed_node_plugin.hpp b/libraries/plugins/delayed_node/include/graphene/delayed_node/delayed_node_plugin.hpp index 509ef4c717..4e06c7fcfc 100644 --- a/libraries/plugins/delayed_node/include/graphene/delayed_node/delayed_node_plugin.hpp +++ b/libraries/plugins/delayed_node/include/graphene/delayed_node/delayed_node_plugin.hpp @@ -32,14 +32,14 @@ class delayed_node_plugin : public graphene::app::plugin { std::unique_ptr my; public: - delayed_node_plugin(); - virtual ~delayed_node_plugin(); + delayed_node_plugin(graphene::app::application& app); + ~delayed_node_plugin() override; std::string plugin_name()const override { return "delayed_node"; } - virtual void plugin_set_program_options(boost::program_options::options_description&, + void plugin_set_program_options(boost::program_options::options_description&, boost::program_options::options_description& cfg) override; - virtual void plugin_initialize(const boost::program_options::variables_map& options) override; - virtual void plugin_startup() override; + void plugin_initialize(const boost::program_options::variables_map& options) override; + void plugin_startup() override; void mainloop(); protected: diff --git a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp index 3d80c64f1c..4eaa6643e9 100644 --- a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp +++ b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp @@ -433,7 +433,8 @@ void elasticsearch_plugin_impl::populateESstruct() } // end namespace detail -elasticsearch_plugin::elasticsearch_plugin() : +elasticsearch_plugin::elasticsearch_plugin(graphene::app::application& app) : + plugin(app), my( std::make_unique(*this) ) { } diff --git a/libraries/plugins/elasticsearch/include/graphene/elasticsearch/elasticsearch_plugin.hpp b/libraries/plugins/elasticsearch/include/graphene/elasticsearch/elasticsearch_plugin.hpp index 7b08e1d73f..61f385efa0 100644 --- a/libraries/plugins/elasticsearch/include/graphene/elasticsearch/elasticsearch_plugin.hpp +++ b/libraries/plugins/elasticsearch/include/graphene/elasticsearch/elasticsearch_plugin.hpp @@ -55,16 +55,16 @@ enum mode { only_save = 0 , only_query = 1, all = 2 }; class elasticsearch_plugin : public graphene::app::plugin { public: - elasticsearch_plugin(); - virtual ~elasticsearch_plugin(); + elasticsearch_plugin(graphene::app::application& app); + ~elasticsearch_plugin() override; std::string plugin_name()const override; std::string plugin_description()const override; - virtual void plugin_set_program_options( + void plugin_set_program_options( boost::program_options::options_description& cli, boost::program_options::options_description& cfg) override; - virtual void plugin_initialize(const boost::program_options::variables_map& options) override; - virtual void plugin_startup() override; + void plugin_initialize(const boost::program_options::variables_map& options) override; + void plugin_startup() override; operation_history_object get_operation_by_id(operation_history_id_type id); vector get_account_history(const account_id_type account_id, diff --git a/libraries/plugins/es_objects/es_objects.cpp b/libraries/plugins/es_objects/es_objects.cpp index 7be78a2630..e538edd370 100644 --- a/libraries/plugins/es_objects/es_objects.cpp +++ b/libraries/plugins/es_objects/es_objects.cpp @@ -274,7 +274,8 @@ es_objects_plugin_impl::~es_objects_plugin_impl() } // end namespace detail -es_objects_plugin::es_objects_plugin() : +es_objects_plugin::es_objects_plugin(graphene::app::application& app) : + plugin(app), my( std::make_unique(*this) ) { } diff --git a/libraries/plugins/es_objects/include/graphene/es_objects/es_objects.hpp b/libraries/plugins/es_objects/include/graphene/es_objects/es_objects.hpp index fa91e3bde4..b9bc339681 100644 --- a/libraries/plugins/es_objects/include/graphene/es_objects/es_objects.hpp +++ b/libraries/plugins/es_objects/include/graphene/es_objects/es_objects.hpp @@ -38,16 +38,16 @@ namespace detail class es_objects_plugin : public graphene::app::plugin { public: - es_objects_plugin(); - virtual ~es_objects_plugin(); + es_objects_plugin(graphene::app::application& app); + ~es_objects_plugin(); std::string plugin_name()const override; std::string plugin_description()const override; - virtual void plugin_set_program_options( + void plugin_set_program_options( boost::program_options::options_description& cli, boost::program_options::options_description& cfg) override; - virtual void plugin_initialize(const boost::program_options::variables_map& options) override; - virtual void plugin_startup() override; + void plugin_initialize(const boost::program_options::variables_map& options) override; + void plugin_startup() override; friend class detail::es_objects_plugin_impl; std::unique_ptr my; diff --git a/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp b/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp index b83ee7d8f7..da655026fd 100644 --- a/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp +++ b/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp @@ -241,7 +241,8 @@ grouped_orders_plugin_impl::~grouped_orders_plugin_impl() } // end namespace detail -grouped_orders_plugin::grouped_orders_plugin() : +grouped_orders_plugin::grouped_orders_plugin(graphene::app::application& app) : + plugin(app), my( std::make_unique(*this) ) { } diff --git a/libraries/plugins/grouped_orders/include/graphene/grouped_orders/grouped_orders_plugin.hpp b/libraries/plugins/grouped_orders/include/graphene/grouped_orders/grouped_orders_plugin.hpp index 8f91ccbd9c..637e6e7925 100644 --- a/libraries/plugins/grouped_orders/include/graphene/grouped_orders/grouped_orders_plugin.hpp +++ b/libraries/plugins/grouped_orders/include/graphene/grouped_orders/grouped_orders_plugin.hpp @@ -69,16 +69,16 @@ namespace detail class grouped_orders_plugin : public graphene::app::plugin { public: - grouped_orders_plugin(); - virtual ~grouped_orders_plugin(); + grouped_orders_plugin(graphene::app::application& app); + ~grouped_orders_plugin() override; std::string plugin_name()const override; - virtual void plugin_set_program_options( + void plugin_set_program_options( boost::program_options::options_description& cli, boost::program_options::options_description& cfg) override; - virtual void plugin_initialize( + void plugin_initialize( const boost::program_options::variables_map& options) override; - virtual void plugin_startup() override; + void plugin_startup() override; const flat_set& tracked_groups()const; diff --git a/libraries/plugins/market_history/include/graphene/market_history/market_history_plugin.hpp b/libraries/plugins/market_history/include/graphene/market_history/market_history_plugin.hpp index 4007b11d15..4021dad75e 100644 --- a/libraries/plugins/market_history/include/graphene/market_history/market_history_plugin.hpp +++ b/libraries/plugins/market_history/include/graphene/market_history/market_history_plugin.hpp @@ -380,16 +380,16 @@ namespace detail class market_history_plugin : public graphene::app::plugin { public: - market_history_plugin(); - virtual ~market_history_plugin(); + market_history_plugin(graphene::app::application& app); + ~market_history_plugin() override; std::string plugin_name()const override; - virtual void plugin_set_program_options( + void plugin_set_program_options( boost::program_options::options_description& cli, boost::program_options::options_description& cfg) override; - virtual void plugin_initialize( + void plugin_initialize( const boost::program_options::variables_map& options) override; - virtual void plugin_startup() override; + void plugin_startup() override; uint32_t max_history()const; const flat_set& tracked_buckets()const; diff --git a/libraries/plugins/market_history/market_history_plugin.cpp b/libraries/plugins/market_history/market_history_plugin.cpp index b6d3800d4a..f9211d1d36 100644 --- a/libraries/plugins/market_history/market_history_plugin.cpp +++ b/libraries/plugins/market_history/market_history_plugin.cpp @@ -735,7 +735,8 @@ void market_history_plugin_impl::update_liquidity_pool_histories( -market_history_plugin::market_history_plugin() : +market_history_plugin::market_history_plugin(graphene::app::application& app) : + plugin(app), my( std::make_unique(*this) ) { } diff --git a/libraries/plugins/snapshot/include/graphene/snapshot/snapshot.hpp b/libraries/plugins/snapshot/include/graphene/snapshot/snapshot.hpp index eb8d3a16cb..5f62a0a678 100644 --- a/libraries/plugins/snapshot/include/graphene/snapshot/snapshot.hpp +++ b/libraries/plugins/snapshot/include/graphene/snapshot/snapshot.hpp @@ -32,19 +32,17 @@ namespace graphene { namespace snapshot_plugin { class snapshot_plugin : public graphene::app::plugin { public: - ~snapshot_plugin() {} + snapshot_plugin(graphene::app::application& app) : graphene::app::plugin(app) {} std::string plugin_name()const override; std::string plugin_description()const override; - virtual void plugin_set_program_options( + void plugin_set_program_options( boost::program_options::options_description &command_line_options, boost::program_options::options_description &config_file_options ) override; - virtual void plugin_initialize( const boost::program_options::variables_map& options ) override; - virtual void plugin_startup() override; - virtual void plugin_shutdown() override; + void plugin_initialize( const boost::program_options::variables_map& options ) override; private: void check_snapshot( const graphene::chain::signed_block& b); diff --git a/libraries/plugins/snapshot/snapshot.cpp b/libraries/plugins/snapshot/snapshot.cpp index a7e9d5138c..12a0553417 100644 --- a/libraries/plugins/snapshot/snapshot.cpp +++ b/libraries/plugins/snapshot/snapshot.cpp @@ -82,10 +82,6 @@ void snapshot_plugin::plugin_initialize(const boost::program_options::variables_ ilog("snapshot plugin: plugin_initialize() end"); } FC_LOG_AND_RETHROW() } -void snapshot_plugin::plugin_startup() {} - -void snapshot_plugin::plugin_shutdown() {} - static void create_snapshot( const graphene::chain::database& db, const fc::path& dest ) { ilog("snapshot plugin: creating snapshot"); diff --git a/libraries/plugins/template_plugin/include/graphene/template_plugin/template_plugin.hpp b/libraries/plugins/template_plugin/include/graphene/template_plugin/template_plugin.hpp index 168dac42bf..12d4ae4d1e 100644 --- a/libraries/plugins/template_plugin/include/graphene/template_plugin/template_plugin.hpp +++ b/libraries/plugins/template_plugin/include/graphene/template_plugin/template_plugin.hpp @@ -52,18 +52,21 @@ namespace detail class template_plugin : public graphene::app::plugin { public: - template_plugin(); - virtual ~template_plugin(); + template_plugin(graphene::app::application& app); + ~template_plugin() override; std::string plugin_name()const override; std::string plugin_description()const override; - virtual void plugin_set_program_options( + void plugin_set_program_options( boost::program_options::options_description& cli, boost::program_options::options_description& cfg) override; - virtual void plugin_initialize(const boost::program_options::variables_map& options) override; - virtual void plugin_startup() override; + void plugin_initialize(const boost::program_options::variables_map& options) override; + void plugin_startup() override; + void plugin_shutdown() override; friend class detail::template_plugin_impl; + private: + void cleanup(); std::unique_ptr my; }; diff --git a/libraries/plugins/template_plugin/template_plugin.cpp b/libraries/plugins/template_plugin/template_plugin.cpp index 7c2cfbc831..3f96a79081 100644 --- a/libraries/plugins/template_plugin/template_plugin.cpp +++ b/libraries/plugins/template_plugin/template_plugin.cpp @@ -37,7 +37,7 @@ class template_plugin_impl { } virtual ~template_plugin_impl(); - void onBlock( const signed_block& b ); + void on_block( const signed_block& b ); graphene::chain::database& database() { @@ -52,25 +52,28 @@ class template_plugin_impl }; -void template_plugin_impl::onBlock( const signed_block& b ) +void template_plugin_impl::on_block( const signed_block& b ) { wdump((b.block_num())); } template_plugin_impl::~template_plugin_impl() { - return; + // Put the real code here } } // end namespace detail -template_plugin::template_plugin() : - my( new detail::template_plugin_impl(*this) ) +template_plugin::template_plugin(graphene::app::application& app) : + plugin(app), + my( std::make_unique(*this) ) { + // Add needed code here } template_plugin::~template_plugin() { + cleanup(); } std::string template_plugin::plugin_name()const @@ -96,7 +99,7 @@ void template_plugin::plugin_set_program_options( void template_plugin::plugin_initialize(const boost::program_options::variables_map& options) { database().applied_block.connect( [&]( const signed_block& b) { - my->onBlock(b); + my->on_block(b); } ); if (options.count("template_plugin") > 0) { @@ -109,4 +112,15 @@ void template_plugin::plugin_startup() ilog("template_plugin: plugin_startup() begin"); } +void template_plugin::plugin_shutdown() +{ + ilog("template_plugin: plugin_shutdown() begin"); + cleanup(); +} + +void template_plugin::cleanup() +{ + // Add cleanup code here +} + } } diff --git a/libraries/plugins/witness/include/graphene/witness/witness.hpp b/libraries/plugins/witness/include/graphene/witness/witness.hpp index 8f7a8b61de..40c4fe87c8 100644 --- a/libraries/plugins/witness/include/graphene/witness/witness.hpp +++ b/libraries/plugins/witness/include/graphene/witness/witness.hpp @@ -49,11 +49,12 @@ namespace block_production_condition class witness_plugin : public graphene::app::plugin { public: - ~witness_plugin() { stop_block_production(); } + witness_plugin(graphene::app::application& app) : graphene::app::plugin(app) {} + ~witness_plugin() override { cleanup(); } std::string plugin_name()const override; - virtual void plugin_set_program_options( + void plugin_set_program_options( boost::program_options::options_description &command_line_options, boost::program_options::options_description &config_file_options ) override; @@ -61,14 +62,16 @@ class witness_plugin : public graphene::app::plugin { void set_block_production(bool allow) { _production_enabled = allow; } void stop_block_production(); - virtual void plugin_initialize( const boost::program_options::variables_map& options ) override; - virtual void plugin_startup() override; - virtual void plugin_shutdown() override; + void plugin_initialize( const boost::program_options::variables_map& options ) override; + void plugin_startup() override; + void plugin_shutdown() override { cleanup(); } inline const fc::flat_map< chain::witness_id_type, fc::optional >& get_witness_key_cache() { return _witness_key_cache; } private: + void cleanup() { stop_block_production(); } + void schedule_production_loop(); block_production_condition::block_production_condition_enum block_production_loop(); block_production_condition::block_production_condition_enum maybe_produce_block( fc::limited_mutable_variant_object& capture ); diff --git a/libraries/plugins/witness/witness.cpp b/libraries/plugins/witness/witness.cpp index 9cf7df428b..1d9ad36c9e 100644 --- a/libraries/plugins/witness/witness.cpp +++ b/libraries/plugins/witness/witness.cpp @@ -195,11 +195,6 @@ void witness_plugin::plugin_startup() ilog("witness plugin: plugin_startup() end"); } FC_CAPTURE_AND_RETHROW() } -void witness_plugin::plugin_shutdown() -{ - stop_block_production(); -} - void witness_plugin::stop_block_production() { _shutting_down = true; diff --git a/programs/witness_node/main.cpp b/programs/witness_node/main.cpp index b2dd6d77d6..b0ca998e20 100644 --- a/programs/witness_node/main.cpp +++ b/programs/witness_node/main.cpp @@ -52,17 +52,16 @@ #include #ifdef WIN32 -# include +# include #else # include #endif -using namespace graphene; namespace bpo = boost::program_options; int main(int argc, char** argv) { fc::print_stacktrace_on_segfault(); - auto node = std::make_unique(); + auto node = std::make_unique(); fc::oexception unhandled_exception; try { bpo::options_description app_options("BitShares Witness Node"); @@ -78,9 +77,11 @@ int main(int argc, char** argv) { "Space-separated list of plugins to activate") ("ignore-api-helper-indexes-warning", "Do not exit if api_helper_indexes plugin is not enabled."); - bpo::variables_map options; + auto sharable_options = std::make_shared(); + auto& options = *sharable_options; - bpo::options_description cli, cfg; + bpo::options_description cli; + bpo::options_description cfg; node->set_program_options(cli, cfg); cfg_options.add(cfg); @@ -89,47 +90,50 @@ int main(int argc, char** argv) { "Space-separated list of plugins to activate") ("ignore-api-helper-indexes-warning", "Do not exit if api_helper_indexes plugin is not enabled."); - auto witness_plug = node->register_plugin(); - auto debug_witness_plug = node->register_plugin(); - auto history_plug = node->register_plugin(); - auto elasticsearch_plug = node->register_plugin(); - auto market_history_plug = node->register_plugin(); - auto delayed_plug = node->register_plugin(); - auto snapshot_plug = node->register_plugin(); - auto es_objects_plug = node->register_plugin(); - auto grouped_orders_plug = node->register_plugin(); - auto api_helper_indexes_plug = node->register_plugin(); - auto custom_operations_plug = node->register_plugin(); + node->register_plugin(); + node->register_plugin(); + node->register_plugin(); + node->register_plugin(); + node->register_plugin(); + node->register_plugin(); + node->register_plugin(); + node->register_plugin(); + node->register_plugin(); + node->register_plugin(); + node->register_plugin(); // add plugin options to config try { - bpo::options_description cli, cfg; - node->set_program_options(cli, cfg); - app_options.add(cli); - cfg_options.add(cfg); + bpo::options_description tmp_cli; + bpo::options_description tmp_cfg; + node->set_program_options(tmp_cli, tmp_cfg); + app_options.add(tmp_cli); + cfg_options.add(tmp_cfg); bpo::store(bpo::parse_command_line(argc, argv, app_options), options); } catch (const boost::program_options::error& e) { std::cerr << "Error parsing command line: " << e.what() << "\n"; - return 1; + return EXIT_FAILURE; } if( options.count("version") > 0 ) { std::cout << "Version: " << graphene::utilities::git_revision_description << "\n"; std::cout << "SHA: " << graphene::utilities::git_revision_sha << "\n"; - std::cout << "Timestamp: " << fc::get_approximate_relative_time_string(fc::time_point_sec(graphene::utilities::git_revision_unix_timestamp)) << "\n"; + std::cout << "Timestamp: " << fc::get_approximate_relative_time_string(fc::time_point_sec( + graphene::utilities::git_revision_unix_timestamp)) << "\n"; std::cout << "SSL: " << OPENSSL_VERSION_TEXT << "\n"; std::cout << "Boost: " << boost::replace_all_copy(std::string(BOOST_LIB_VERSION), "_", ".") << "\n"; - std::cout << "Websocket++: " << websocketpp::major_version << "." << websocketpp::minor_version << "." << websocketpp::patch_version << "\n"; - return 0; + std::cout << "Websocket++: " << websocketpp::major_version << "." << websocketpp::minor_version + << "." << websocketpp::patch_version << "\n"; + return EXIT_SUCCESS; } if( options.count("help") > 0 ) { std::cout << app_options << "\n"; - return 0; + return EXIT_SUCCESS; } fc::path data_dir; @@ -139,14 +143,14 @@ int main(int argc, char** argv) { if( data_dir.is_relative() ) data_dir = fc::current_path() / data_dir; } - app::load_configuration_options(data_dir, cfg_options, options); + graphene::app::load_configuration_options(data_dir, cfg_options, options); std::set plugins; boost::split(plugins, options.at("plugins").as(), [](char c){return c == ' ';}); if( plugins.count("account_history") > 0 && plugins.count("elasticsearch") > 0 ) { std::cerr << "Plugin conflict: Cannot load both account_history plugin and elasticsearch plugin\n"; - return 1; + return EXIT_FAILURE; } if( plugins.count("api_helper_indexes") == 0 && options.count("ignore-api-helper-indexes-warning") == 0 @@ -155,7 +159,7 @@ int main(int argc, char** argv) { std::cerr << "\nIf this is an API node, please enable api_helper_indexes plugin." "\nIf this is not an API node, please start with \"--ignore-api-helper-indexes-warning\"" " or enable it in config.ini file.\n\n"; - return 1; + return EXIT_FAILURE; } std::for_each(plugins.begin(), plugins.end(), [&node](const std::string& plug) mutable { @@ -166,30 +170,34 @@ int main(int argc, char** argv) { bpo::notify(options); - node->initialize(data_dir, options); - node->initialize_plugins( options ); + node->initialize(data_dir, sharable_options); node->startup(); - node->startup_plugins(); fc::promise::ptr exit_promise = fc::promise::create("UNIX Signal Handler"); - fc::set_signal_handler([&exit_promise](int signal) { - elog( "Caught SIGINT attempting to exit cleanly" ); - exit_promise->set_value(signal); + fc::set_signal_handler([&exit_promise](int the_signal) { + elog( "Caught SIGINT, attempting to exit cleanly" ); + exit_promise->set_value(the_signal); }, SIGINT); - fc::set_signal_handler([&exit_promise](int signal) { - elog( "Caught SIGTERM attempting to exit cleanly" ); - exit_promise->set_value(signal); + fc::set_signal_handler([&exit_promise](int the_signal) { + elog( "Caught SIGTERM, attempting to exit cleanly" ); + exit_promise->set_value(the_signal); }, SIGTERM); +#ifdef SIGQUIT + fc::set_signal_handler( [&exit_promise](int the_signal) { + elog( "Caught SIGQUIT, attempting to exit cleanly" ); + exit_promise->set_value(the_signal); + }, SIGQUIT ); +#endif + ilog("Started BitShares node on a chain with ${h} blocks.", ("h", node->chain_database()->head_block_num())); ilog("Chain ID is ${id}", ("id", node->chain_database()->get_chain_id()) ); - int signal = exit_promise->wait(); - ilog("Exiting from signal ${n}", ("n", signal)); - node->shutdown_plugins(); + auto caught_signal = exit_promise->wait(); + ilog("Exiting from signal ${n}", ("n", caught_signal)); node->shutdown(); node.reset(); return EXIT_SUCCESS; From 81208392137e0eb877ed35440c22d609d149776f Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 28 Mar 2021 10:34:27 +0000 Subject: [PATCH 095/147] Update tests to adapt the plugin framework changes --- tests/app/main.cpp | 16 ++++++----- tests/cli/main.cpp | 11 +++----- tests/common/database_fixture.cpp | 44 ++++++++++--------------------- tests/common/database_fixture.hpp | 6 ++--- tests/tests/operation_tests2.cpp | 1 - 5 files changed, 30 insertions(+), 48 deletions(-) diff --git a/tests/app/main.cpp b/tests/app/main.cpp index 27291dee98..9a91139b67 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -246,12 +246,12 @@ BOOST_AUTO_TEST_CASE( two_node_network ) app1.register_plugin< graphene::market_history::market_history_plugin >(); app1.register_plugin< graphene::witness_plugin::witness_plugin >(); app1.register_plugin< graphene::grouped_orders::grouped_orders_plugin>(); - app1.startup_plugins(); - boost::program_options::variables_map cfg; + auto sharable_cfg = std::make_shared(); + auto& cfg = *sharable_cfg; cfg.emplace("p2p-endpoint", boost::program_options::variable_value(app1_p2p_endpoint_str, false)); cfg.emplace("genesis-json", boost::program_options::variable_value(genesis_file, false)); cfg.emplace("seed-nodes", boost::program_options::variable_value(string("[]"), false)); - app1.initialize(app_dir.path(), cfg); + app1.initialize(app_dir.path(), sharable_cfg); BOOST_TEST_MESSAGE( "Starting app1 and waiting" ); app1.startup(); @@ -271,11 +271,11 @@ BOOST_AUTO_TEST_CASE( two_node_network ) app2.register_plugin< graphene::market_history::market_history_plugin >(); app2.register_plugin< graphene::witness_plugin::witness_plugin >(); app2.register_plugin< graphene::grouped_orders::grouped_orders_plugin>(); - app2.startup_plugins(); - boost::program_options::variables_map cfg2; + auto sharable_cfg2 = std::make_shared(); + auto& cfg2 = *sharable_cfg2; cfg2.emplace("genesis-json", boost::program_options::variable_value(genesis_file, false)); cfg2.emplace("seed-nodes", boost::program_options::variable_value(app2_seed_nodes_str, false)); - app2.initialize(app2_dir.path(), cfg2); + app2.initialize(app2_dir.path(), sharable_cfg2); BOOST_TEST_MESSAGE( "Starting app2 and waiting for connection" ); app2.startup(); @@ -396,10 +396,12 @@ BOOST_AUTO_TEST_CASE(application_impl_breakout) { class test_impl : public graphene::app::detail::application_impl { // override the constructor, just to test that we can public: - test_impl() : application_impl(nullptr) {} + test_impl() : my_app(),application_impl(my_app) {} bool has_item(const net::item_id& id) override { return true; } + private: + graphene::app::application my_app; }; test_impl impl; diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index 9626c5ecd2..6032d26449 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -96,7 +96,7 @@ using std::cerr; /// @returns the application object ////////// std::shared_ptr start_application(fc::temp_directory& app_dir, int& server_port_number) { - std::shared_ptr app1(new graphene::app::application{}); + auto app1 = std::make_shared(); app1->register_plugin(true); app1->register_plugin< graphene::market_history::market_history_plugin >(true); @@ -104,8 +104,8 @@ std::shared_ptr start_application(fc::temp_directory app1->register_plugin< graphene::api_helper_indexes::api_helper_indexes>(true); app1->register_plugin(true); - app1->startup_plugins(); - boost::program_options::variables_map cfg; + auto sharable_cfg = std::make_shared(); + auto& cfg = *sharable_cfg; #ifdef _WIN32 sockInit(); #endif @@ -117,10 +117,7 @@ std::shared_ptr start_application(fc::temp_directory cfg.emplace("genesis-json", boost::program_options::variable_value(create_genesis_file(app_dir), false)); cfg.emplace("seed-nodes", boost::program_options::variable_value(string("[]"), false)); cfg.emplace("custom-operations-start-block", boost::program_options::variable_value(uint32_t(1), false)); - app1->initialize(app_dir.path(), cfg); - - app1->initialize_plugins(cfg); - app1->startup_plugins(); + app1->initialize(app_dir.path(), sharable_cfg); app1->startup(); diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 19a7b9bc5f..ef30b1d302 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -178,9 +178,11 @@ void database_fixture_base::init_genesis( database_fixture_base& fixture ) // TODO add initial UIA's; add initial short positions; test non-zero accumulated_fees } -boost::program_options::variables_map database_fixture_base::init_options( database_fixture_base& fixture ) +std::shared_ptr database_fixture_base::init_options( + database_fixture_base& fixture ) { - boost::program_options::variables_map options; + auto sharable_options = std::make_shared(); + auto& options = *sharable_options; set_option( options, "seed-nodes", std::string("[]") ); /** * Test specific settings @@ -340,7 +342,7 @@ boost::program_options::variables_map database_fixture_base::init_options( datab if(fixture.current_test_name == "elasticsearch_account_history" || fixture.current_test_name == "elasticsearch_suite" || fixture.current_test_name == "elasticsearch_history_api") { - auto esplugin = fixture.app.register_plugin(true); + fixture.app.register_plugin(true); options.insert(std::make_pair("elasticsearch-node-url", boost::program_options::variable_value(GRAPHENE_TESTING_ES_URL, false))); @@ -363,19 +365,14 @@ boost::program_options::variables_map database_fixture_base::init_options( datab BOOST_TEST_MESSAGE( string("ES index prefix is ") + fixture.es_index_prefix ); options.insert(std::make_pair("elasticsearch-index-prefix", boost::program_options::variable_value(fixture.es_index_prefix, false))); - - esplugin->plugin_initialize(options); - esplugin->plugin_startup(); } else if( fixture.current_suite_name != "performance_tests" ) { - auto ahplugin = fixture.app.register_plugin(true); - ahplugin->plugin_initialize(options); - ahplugin->plugin_startup(); + fixture.app.register_plugin(true); } if(fixture.current_test_name == "elasticsearch_objects" || fixture.current_test_name == "elasticsearch_suite") { - auto esobjects_plugin = fixture.app.register_plugin(true); + fixture.app.register_plugin(true); options.insert(std::make_pair("es-objects-elasticsearch-url", boost::program_options::variable_value(GRAPHENE_TESTING_ES_URL, false))); @@ -400,9 +397,6 @@ boost::program_options::variables_map database_fixture_base::init_options( datab BOOST_TEST_MESSAGE( string("ES_OBJ index prefix is ") + fixture.es_obj_index_prefix ); options.insert(std::make_pair("es-objects-index-prefix", boost::program_options::variable_value(fixture.es_obj_index_prefix, false))); - - esobjects_plugin->plugin_initialize(options); - esobjects_plugin->plugin_startup(); } if( fixture.current_test_name == "asset_in_collateral" @@ -411,32 +405,22 @@ boost::program_options::variables_map database_fixture_base::init_options( datab || fixture.current_suite_name == "database_api_tests" || fixture.current_suite_name == "api_limit_tests" ) { - auto ahiplugin = fixture.app.register_plugin(true); - ahiplugin->plugin_initialize(options); - ahiplugin->plugin_startup(); + fixture.app.register_plugin(true); } if(fixture.current_test_name == "custom_operations_account_storage_map_test" || fixture.current_test_name == "custom_operations_account_storage_list_test") { - auto custom_operations_plugin = - fixture.app.register_plugin(true); - options.insert(std::make_pair("custom-operations-start-block", boost::program_options::variable_value(uint32_t(1), false))); - custom_operations_plugin->plugin_initialize(options); - custom_operations_plugin->plugin_startup(); + fixture.app.register_plugin(true); + options.insert(std::make_pair("custom-operations-start-block", + boost::program_options::variable_value(uint32_t(1), false))); } options.insert(std::make_pair("bucket-size", boost::program_options::variable_value(string("[15]"),false))); - auto mhplugin = fixture.app.register_plugin(true); - auto goplugin = fixture.app.register_plugin(true); - - mhplugin->plugin_initialize(options); - goplugin->plugin_initialize(options); - - mhplugin->plugin_startup(); - goplugin->plugin_startup(); + fixture.app.register_plugin(true); + fixture.app.register_plugin(true); - return options; + return sharable_options; } void database_fixture_base::vote_for_committee_and_witnesses(uint16_t num_committee, uint16_t num_witness) diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index 339388d123..5c9f746af4 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -233,7 +233,7 @@ struct database_fixture_base { } static void init_genesis( database_fixture_base& fixture ); - static boost::program_options::variables_map init_options( database_fixture_base& fixture ); + static std::shared_ptr init_options( database_fixture_base& fixture ); static fc::ecc::private_key generate_private_key(string seed); string generate_anon_acct_name(); @@ -516,8 +516,8 @@ struct database_fixture_init : database_fixture_base { fc::create_directories( fixture.data_dir.path() ); F::init_genesis( fixture ); fc::json::save_to_file( fixture.genesis_state, fixture.data_dir.path() / "genesis.json" ); - boost::program_options::variables_map options = F::init_options( fixture ); - set_option( options, "genesis-json", boost::filesystem::path(fixture.data_dir.path() / "genesis.json") ); + auto options = F::init_options( fixture ); + set_option( *options, "genesis-json", boost::filesystem::path(fixture.data_dir.path() / "genesis.json") ); fixture.app.initialize( fixture.data_dir.path(), options ); fixture.app.startup(); diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index e99182f02e..1e97b41207 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -829,7 +829,6 @@ BOOST_AUTO_TEST_CASE( witness_create ) generate_block(skip); auto wtplugin = app.register_plugin(); - wtplugin->plugin_set_app(&app); boost::program_options::variables_map options; // init witness key cahce From 5db63f5fe998b3019074b6e0ab924a75b8a5ec94 Mon Sep 17 00:00:00 2001 From: abitmore Date: Mon, 29 Mar 2021 08:28:08 +0000 Subject: [PATCH 096/147] Remove application::shutdown() Since it's always called before destruction, it's good to just cleanup everything in the destructor. --- libraries/app/application.cpp | 5 ----- libraries/app/application_impl.hxx | 2 +- libraries/app/include/graphene/app/application.hpp | 1 - programs/witness_node/main.cpp | 4 ---- tests/cli/main.cpp | 7 ------- 5 files changed, 1 insertion(+), 18 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 827c5c4144..dfeaa9dcdb 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -1258,11 +1258,6 @@ void application::add_available_plugin(std::shared_ptradd_available_plugin(p); } -void application::shutdown() -{ - my->shutdown(); -} - const application_options& application::get_options() { return my->_app_options; diff --git a/libraries/app/application_impl.hxx b/libraries/app/application_impl.hxx index e95e7b6ed1..b344fdb8ee 100644 --- a/libraries/app/application_impl.hxx +++ b/libraries/app/application_impl.hxx @@ -43,7 +43,6 @@ class application_impl : public net::node_delegate void initialize(const fc::path& data_dir, std::shared_ptr options); void startup(); - void shutdown(); fc::optional< api_access_info > get_api_access_info(const string& username)const; @@ -209,6 +208,7 @@ class application_impl : public net::node_delegate bool _is_finished_syncing = false; private: + void shutdown(); void initialize_plugins(); void startup_plugins(); void shutdown_plugins(); diff --git a/libraries/app/include/graphene/app/application.hpp b/libraries/app/include/graphene/app/application.hpp index 4ccd8b031d..3c8c63bd10 100644 --- a/libraries/app/include/graphene/app/application.hpp +++ b/libraries/app/include/graphene/app/application.hpp @@ -87,7 +87,6 @@ namespace graphene { namespace app { boost::program_options::options_description& configuration_file_options)const; void initialize(const fc::path& data_dir, std::shared_ptr options); void startup(); - void shutdown(); template std::shared_ptr register_plugin(bool auto_load = false) { diff --git a/programs/witness_node/main.cpp b/programs/witness_node/main.cpp index b0ca998e20..846d8cd71e 100644 --- a/programs/witness_node/main.cpp +++ b/programs/witness_node/main.cpp @@ -198,8 +198,6 @@ int main(int argc, char** argv) { auto caught_signal = exit_promise->wait(); ilog("Exiting from signal ${n}", ("n", caught_signal)); - node->shutdown(); - node.reset(); return EXIT_SUCCESS; } catch( const fc::exception& e ) { // deleting the node can yield, so do this outside the exception handler @@ -209,8 +207,6 @@ int main(int argc, char** argv) { if (unhandled_exception) { elog("Exiting with error:\n${e}", ("e", unhandled_exception->to_detail_string())); - node->shutdown(); - node.reset(); return EXIT_FAILURE; } } diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index 6032d26449..11e30391fd 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -314,7 +314,6 @@ struct cli_fixture ~cli_fixture() { BOOST_TEST_MESSAGE("Cleanup cli_wallet::boost_fixture_test_case"); - app1->shutdown(); #ifdef _WIN32 sockQuit(); #endif @@ -1497,8 +1496,6 @@ BOOST_AUTO_TEST_CASE( cli_multisig_transaction ) edump((e.to_detail_string())); throw; } - app1->shutdown(); - app1.reset(); } graphene::wallet::plain_keys decrypt_keys( const std::string& password, const vector& cipher_keys ) @@ -1731,8 +1728,6 @@ BOOST_AUTO_TEST_CASE( cli_create_htlc ) edump((e.to_detail_string())); throw; } - app1->shutdown(); - app1.reset(); } static string encapsulate( const graphene::wallet::signed_message& msg ) @@ -2308,6 +2303,4 @@ BOOST_AUTO_TEST_CASE( cli_create_htlc_bsip64 ) edump((e.to_detail_string())); throw; } - app1->shutdown(); - app1.reset(); } From d4441b05176ed69ba94a0de63de60e654dde543b Mon Sep 17 00:00:00 2001 From: abitmore Date: Mon, 29 Mar 2021 08:49:25 +0000 Subject: [PATCH 097/147] Add option in app to enable or disable P2P network --- libraries/app/application.cpp | 38 ++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index dfeaa9dcdb..aee0716864 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -410,13 +410,13 @@ void application_impl::startup() auto initial_state = [this] { ilog("Initializing database..."); - if( _options->count("genesis-json") ) + if( _options->count("genesis-json") > 0 ) { std::string genesis_str; fc::read_file_contents( _options->at("genesis-json").as(), genesis_str ); graphene::chain::genesis_state_type genesis = fc::json::from_string( genesis_str ).as( 20 ); bool modified_genesis = false; - if( _options->count("genesis-timestamp") ) + if( _options->count("genesis-timestamp") > 0 ) { genesis.initial_timestamp = fc::time_point_sec( fc::time_point::now() ) + genesis.initial_parameters.block_interval @@ -430,7 +430,7 @@ void application_impl::startup() ("timestamp", genesis.initial_timestamp.to_iso_string()) ); } - if( _options->count("dbg-init-key") ) + if( _options->count("dbg-init-key") > 0 ) { std::string init_key = _options->at( "dbg-init-key" ).as(); FC_ASSERT( genesis.initial_witness_candidates.size() >= genesis.initial_active_witnesses ); @@ -460,11 +460,11 @@ void application_impl::startup() } }; - if( _options->count("resync-blockchain") ) + if( _options->count("resync-blockchain") > 0 ) _chain_db->wipe(_data_dir / "blockchain", true); flat_map loaded_checkpoints; - if( _options->count("checkpoint") ) + if( _options->count("checkpoint") > 0 ) { auto cps = _options->at("checkpoint").as>(); loaded_checkpoints.reserve( cps.size() ); @@ -476,23 +476,23 @@ void application_impl::startup() } _chain_db->add_checkpoints( loaded_checkpoints ); - if( _options->count("enable-standby-votes-tracking") ) + if( _options->count("enable-standby-votes-tracking") > 0 ) { _chain_db->enable_standby_votes_tracking( _options->at("enable-standby-votes-tracking").as() ); } - if( _options->count("replay-blockchain") || _options->count("revalidate-blockchain") ) + if( _options->count("replay-blockchain") > 0 || _options->count("revalidate-blockchain") > 0 ) _chain_db->wipe( _data_dir / "blockchain", false ); try { // these flags are used in open() only, i. e. during replay uint32_t skip; - if( _options->count("revalidate-blockchain") ) // see also handle_block() + if( _options->count("revalidate-blockchain") > 0 ) // see also handle_block() { if( !loaded_checkpoints.empty() ) wlog( "Warning - revalidate will not validate before last checkpoint" ); - if( _options->count("force-validate") ) + if( _options->count("force-validate") > 0 ) skip = graphene::chain::database::skip_nothing; else skip = graphene::chain::database::skip_transaction_signatures; @@ -518,7 +518,10 @@ void application_impl::startup() startup_plugins(); - if( _active_plugins.find( "delayed_node" ) == _active_plugins.end() ) + bool enable_p2p_network = true; + if( _options->count("enable-p2p-network") > 0 ) + enable_p2p_network = _options->at("enable-p2p-network").as(); + if( enable_p2p_network && _active_plugins.find( "delayed_node" ) == _active_plugins.end() ) reset_p2p_node(_data_dir); reset_websocket_server(); @@ -1077,6 +1080,9 @@ void application::set_program_options(boost::program_options::options_descriptio boost::program_options::options_description& configuration_file_options) const { configuration_file_options.add_options() + ("enable-p2p-network", bpo::value()->implicit_value(true), + "Whether to enable P2P network. Note: if delayed_node plugin is enabled, " + "this option will be ignored and P2P network will always be disabled.") ("p2p-endpoint", bpo::value(), "Endpoint for P2P node to listen on") ("seed-node,s", bpo::value>()->composing(), "P2P nodes to connect to on startup (may specify multiple times)") @@ -1088,15 +1094,18 @@ void application::set_program_options(boost::program_options::options_descriptio "Endpoint for websocket RPC to listen on") ("rpc-tls-endpoint", bpo::value()->implicit_value("127.0.0.1:8089"), "Endpoint for TLS websocket RPC to listen on") - ("server-pem,p", bpo::value()->implicit_value("server.pem"), "The TLS certificate file for this server") + ("server-pem,p", bpo::value()->implicit_value("server.pem"), + "The TLS certificate file for this server") ("server-pem-password,P", bpo::value()->implicit_value(""), "Password for this certificate") ("proxy-forwarded-for-header", bpo::value()->implicit_value("X-Forwarded-For-Client"), "A HTTP header similar to X-Forwarded-For (XFF), used by the RPC server to extract clients' address info, " "usually added by a trusted reverse proxy") ("genesis-json", bpo::value(), "File to read Genesis State from") - ("dbg-init-key", bpo::value(), "Block signing key to use for init witnesses, overrides genesis file") + ("dbg-init-key", bpo::value(), + "Block signing key to use for init witnesses, overrides genesis file, for debug") ("api-access", bpo::value(), "JSON file specifying API permissions") - ("io-threads", bpo::value()->implicit_value(0), "Number of IO threads, default to 0 for auto-configuration") + ("io-threads", bpo::value()->implicit_value(0), + "Number of IO threads, default to 0 for auto-configuration") ("enable-subscribe-to-all", bpo::value()->implicit_value(true), "Whether allow API clients to subscribe to universal object creation and removal events") ("enable-standby-votes-tracking", bpo::value()->implicit_value(true), @@ -1156,7 +1165,8 @@ void application::set_program_options(boost::program_options::options_descriptio "For database_api_impl::get_trade_history_by_sequence to set max limit value") ("api-limit-get-withdraw-permissions-by-giver",boost::program_options::value()->default_value(101), "For database_api_impl::get_withdraw_permissions_by_giver to set max limit value") - ("api-limit-get-withdraw-permissions-by-recipient",boost::program_options::value()->default_value(101), + ("api-limit-get-withdraw-permissions-by-recipient", + boost::program_options::value()->default_value(101), "For database_api_impl::get_withdraw_permissions_by_recipient to set max limit value") ("api-limit-get-tickets", boost::program_options::value()->default_value(101), "Set maximum limit value for database APIs which query for tickets") From 290b3d09afb5f7db07c887e0cea1327c0a4f691f Mon Sep 17 00:00:00 2001 From: abitmore Date: Mon, 29 Mar 2021 09:21:57 +0000 Subject: [PATCH 098/147] Refactor application_impl::startup() Split it into several functions. --- libraries/app/application.cpp | 49 ++++++++++--------- libraries/app/application_impl.hxx | 20 +++++--- libraries/chain/genesis_state.cpp | 9 ++++ .../include/graphene/chain/genesis_state.hpp | 4 ++ 4 files changed, 53 insertions(+), 29 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index aee0716864..6bac4fe328 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -233,14 +233,6 @@ void application_impl::reset_websocket_tls_server() _websocket_tls_server->start_accept(); } FC_CAPTURE_AND_RETHROW() } -void application_impl::set_dbg_init_key( graphene::chain::genesis_state_type& genesis, const std::string& init_key ) -{ - flat_set< std::string > initial_witness_names; - public_key_type init_pubkey( init_key ); - for( uint64_t i=0; i options) { _data_dir = data_dir; @@ -404,17 +396,15 @@ void application_impl::set_api_limit() { } } -void application_impl::startup() -{ try { - fc::create_directories(_data_dir / "blockchain"); - - auto initial_state = [this] { +graphene::chain::genesis_state_type application_impl::initialize_genesis_state() const +{ + try { ilog("Initializing database..."); if( _options->count("genesis-json") > 0 ) { std::string genesis_str; fc::read_file_contents( _options->at("genesis-json").as(), genesis_str ); - graphene::chain::genesis_state_type genesis = fc::json::from_string( genesis_str ).as( 20 ); + auto genesis = fc::json::from_string( genesis_str ).as( 20 ); bool modified_genesis = false; if( _options->count("genesis-timestamp") > 0 ) { @@ -434,7 +424,7 @@ void application_impl::startup() { std::string init_key = _options->at( "dbg-init-key" ).as(); FC_ASSERT( genesis.initial_witness_candidates.size() >= genesis.initial_active_witnesses ); - set_dbg_init_key( genesis, init_key ); + genesis.override_witness_signing_keys( init_key ); modified_genesis = true; ilog("Set init witness key to ${init_key}", ("init_key", init_key)); } @@ -442,10 +432,8 @@ void application_impl::startup() { wlog("WARNING: GENESIS WAS MODIFIED, YOUR CHAIN ID MAY BE DIFFERENT"); genesis_str += "BOGUS"; - genesis.initial_chain_id = fc::sha256::hash( genesis_str ); } - else - genesis.initial_chain_id = fc::sha256::hash( genesis_str ); + genesis.initial_chain_id = fc::sha256::hash( genesis_str ); return genesis; } else @@ -458,7 +446,12 @@ void application_impl::startup() genesis.initial_chain_id = fc::sha256::hash( egenesis_json ); return genesis; } - }; + } FC_CAPTURE_AND_RETHROW() +} + +void application_impl::open_chain_database() +{ try { + fc::create_directories(_data_dir / "blockchain"); if( _options->count("resync-blockchain") > 0 ) _chain_db->wipe(_data_dir / "blockchain", true); @@ -506,8 +499,12 @@ void application_impl::startup() graphene::chain::database::skip_tapos_check | graphene::chain::database::skip_witness_schedule_check; - graphene::chain::detail::with_skip_flags( *_chain_db, skip, [this,&initial_state] () { - _chain_db->open( _data_dir / "blockchain", initial_state, GRAPHENE_CURRENT_DB_VERSION ); + auto genesis_loader = [this](){ + return initialize_genesis_state(); + }; + + graphene::chain::detail::with_skip_flags( *_chain_db, skip, [this, &genesis_loader] () { + _chain_db->open( _data_dir / "blockchain", genesis_loader, GRAPHENE_CURRENT_DB_VERSION ); }); } catch( const fc::exception& e ) @@ -515,12 +512,18 @@ void application_impl::startup() elog( "Caught exception ${e} in open(), you might want to force a replay", ("e", e.to_detail_string()) ); throw; } +} FC_LOG_AND_RETHROW() } - startup_plugins(); - +void application_impl::startup() +{ try { bool enable_p2p_network = true; if( _options->count("enable-p2p-network") > 0 ) enable_p2p_network = _options->at("enable-p2p-network").as(); + + open_chain_database(); + + startup_plugins(); + if( enable_p2p_network && _active_plugins.find( "delayed_node" ) == _active_plugins.end() ) reset_p2p_node(_data_dir); diff --git a/libraries/app/application_impl.hxx b/libraries/app/application_impl.hxx index b344fdb8ee..7084f69f31 100644 --- a/libraries/app/application_impl.hxx +++ b/libraries/app/application_impl.hxx @@ -38,7 +38,6 @@ class application_impl : public net::node_delegate void set_block_production(bool producing_blocks); - void set_dbg_init_key( graphene::chain::genesis_state_type& genesis, const std::string& init_key ); void set_api_limit(); void initialize(const fc::path& data_dir, std::shared_ptr options); @@ -192,6 +191,20 @@ class application_impl : public net::node_delegate /// Returns whether a plugin is enabled bool is_plugin_enabled(const string& name) const; + private: + void shutdown(); + + void initialize_plugins(); + void startup_plugins(); + void shutdown_plugins(); + + /// Initialize genesis state. Called by @ref open_chain_database. + graphene::chain::genesis_state_type initialize_genesis_state() const; + /// Open the chain database. Called by @ref startup. + void open_chain_database(); + + friend graphene::app::application; + application& _self; fc::path _data_dir; @@ -207,11 +220,6 @@ class application_impl : public net::node_delegate std::map> _available_plugins; bool _is_finished_syncing = false; - private: - void shutdown(); - void initialize_plugins(); - void startup_plugins(); - void shutdown_plugins(); fc::serial_valve valve; }; diff --git a/libraries/chain/genesis_state.cpp b/libraries/chain/genesis_state.cpp index ae6b015990..78771a8a93 100644 --- a/libraries/chain/genesis_state.cpp +++ b/libraries/chain/genesis_state.cpp @@ -34,6 +34,15 @@ chain_id_type genesis_state_type::compute_chain_id() const return initial_chain_id; } +void genesis_state_type::override_witness_signing_keys( const std::string& new_key ) +{ + public_key_type new_pubkey( new_key ); + for( auto& wit : initial_witness_candidates ) + { + wit.block_signing_key = new_pubkey; + } +} + } } // graphene::chain FC_REFLECT_DERIVED_NO_TYPENAME(graphene::chain::genesis_state_type::initial_account_type, BOOST_PP_SEQ_NIL, diff --git a/libraries/chain/include/graphene/chain/genesis_state.hpp b/libraries/chain/include/graphene/chain/genesis_state.hpp index 98538e824e..391e3e58d4 100644 --- a/libraries/chain/include/graphene/chain/genesis_state.hpp +++ b/libraries/chain/include/graphene/chain/genesis_state.hpp @@ -124,6 +124,10 @@ struct genesis_state_type { * This is the SHA256 serialization of the genesis_state. */ chain_id_type compute_chain_id() const; + + /// Method to override initial witness signing keys for debug + void override_witness_signing_keys( const std::string& new_key ); + }; } } // namespace graphene::chain From c19a676f97a094bd7c975eaa37b4a7faa0dcfbad Mon Sep 17 00:00:00 2001 From: abitmore Date: Mon, 29 Mar 2021 10:37:34 +0000 Subject: [PATCH 099/147] Fix a compiler warning --- tests/app/main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/app/main.cpp b/tests/app/main.cpp index 9a91139b67..b07eda1736 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -390,18 +390,18 @@ BOOST_AUTO_TEST_CASE( two_node_network ) } } -// a contrived example to test the breaking out of application_impl to a header file - +/// a contrived example to test the breaking out of application_impl to a header file BOOST_AUTO_TEST_CASE(application_impl_breakout) { + + static graphene::app::application my_app; + class test_impl : public graphene::app::detail::application_impl { // override the constructor, just to test that we can public: - test_impl() : my_app(),application_impl(my_app) {} + test_impl() : application_impl(my_app) {} bool has_item(const net::item_id& id) override { return true; } - private: - graphene::app::application my_app; }; test_impl impl; From 3d6803095eabec643cc0f45e029f754b6b662998 Mon Sep 17 00:00:00 2001 From: abitmore Date: Mon, 29 Mar 2021 10:44:49 +0000 Subject: [PATCH 100/147] Remove redundant 'virtual' declarations --- libraries/app/application_impl.hxx | 39 ++++++++++++++++-------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/libraries/app/application_impl.hxx b/libraries/app/application_impl.hxx index 7084f69f31..7d23ac326a 100644 --- a/libraries/app/application_impl.hxx +++ b/libraries/app/application_impl.hxx @@ -50,7 +50,7 @@ class application_impl : public net::node_delegate /** * If delegate has the item, the network has no need to fetch it. */ - virtual bool has_item(const net::item_id& id) override; + bool has_item(const net::item_id& id) override; /** * @brief allows the application to validate an item prior to broadcasting to peers. @@ -62,10 +62,10 @@ class application_impl : public net::node_delegate * * @throws exception if error validating the item, otherwise the item is safe to broadcast on. */ - virtual bool handle_block(const graphene::net::block_message& blk_msg, bool sync_mode, + bool handle_block(const graphene::net::block_message& blk_msg, bool sync_mode, std::vector& contained_transaction_message_ids) override; - virtual void handle_transaction(const graphene::net::trx_message& transaction_message) override; + void handle_transaction(const graphene::net::trx_message& transaction_message) override; void handle_message(const graphene::net::message& message_to_process) override; @@ -80,16 +80,17 @@ class application_impl : public net::node_delegate * in our blockchain after the last item returned in the result, * or 0 if the result contains the last item in the blockchain */ - virtual std::vector get_block_ids(const std::vector& blockchain_synopsis, - uint32_t& remaining_item_count, - uint32_t limit) override; + std::vector get_block_ids( + const std::vector& blockchain_synopsis, + uint32_t& remaining_item_count, + uint32_t limit) override; /** * Given the hash of the requested data, fetch the body. */ - virtual graphene::net::message get_item(const graphene::net::item_id& id) override; + graphene::net::message get_item(const graphene::net::item_id& id) override; - virtual graphene::chain::chain_id_type get_chain_id()const override; + graphene::chain::chain_id_type get_chain_id()const override; /** * Returns a synopsis of the blockchain used for syncing. This consists of a list of @@ -149,36 +150,38 @@ class application_impl : public net::node_delegate * successfully pushed to the blockchain, so that tells us whether the peer is on a fork or on * the main chain. */ - virtual std::vector get_blockchain_synopsis(const graphene::net::item_hash_t& reference_point, - uint32_t number_of_blocks_after_reference_point) override; + std::vector get_blockchain_synopsis( + const graphene::net::item_hash_t& reference_point, + uint32_t number_of_blocks_after_reference_point) override; /** * Call this after the call to handle_message succeeds. * - * @param item_type the type of the item we're synchronizing, will be the same as item passed to the sync_from() call + * @param item_type the type of the item we're synchronizing, + * will be the same as item passed to the sync_from() call * @param item_count the number of items known to the node that haven't been sent to handle_item() yet. * After `item_count` more calls to handle_item(), the node will be in sync */ - virtual void sync_status(uint32_t item_type, uint32_t item_count) override; + void sync_status(uint32_t item_type, uint32_t item_count) override; /** * Call any time the number of connected peers changes. */ - virtual void connection_count_changed(uint32_t c) override; + void connection_count_changed(uint32_t c) override; - virtual uint32_t get_block_number(const graphene::net::item_hash_t& block_id) override; + uint32_t get_block_number(const graphene::net::item_hash_t& block_id) override; /** * Returns the time a block was produced (if block_id = 0, returns genesis time). * If we don't know about the block, returns time_point_sec::min() */ - virtual fc::time_point_sec get_block_time(const graphene::net::item_hash_t& block_id) override; + fc::time_point_sec get_block_time(const graphene::net::item_hash_t& block_id) override; - virtual graphene::net::item_hash_t get_head_block_id() const override; + graphene::net::item_hash_t get_head_block_id() const override; - virtual uint32_t estimate_last_known_fork_from_git_revision_timestamp(uint32_t unix_timestamp) const override; + uint32_t estimate_last_known_fork_from_git_revision_timestamp(uint32_t unix_timestamp) const override; - virtual void error_encountered(const std::string& message, const fc::oexception& error) override; + void error_encountered(const std::string& message, const fc::oexception& error) override; uint8_t get_current_block_interval_in_seconds() const override; From d135a9c7ae7d02c0aec420e53543a40ac73808f2 Mon Sep 17 00:00:00 2001 From: abitmore Date: Mon, 29 Mar 2021 13:39:31 +0000 Subject: [PATCH 101/147] Pass a shared_ptr of node_delegate to node instead of a raw pointer. By the way, - move simulated_network from node.hpp and node.cpp to tests, - avoid referencing uint160_t, use message_hash_type or ripemd160. --- libraries/app/application.cpp | 9 +- libraries/app/application_impl.hxx | 4 +- .../app/include/graphene/app/application.hpp | 2 +- .../net/include/graphene/net/message.hpp | 4 +- libraries/net/include/graphene/net/node.hpp | 34 +---- libraries/net/node.cpp | 138 ++++++------------ libraries/net/node_impl.hxx | 55 ++++--- tests/common/simulated_network.cpp | 93 ++++++++++++ tests/common/simulated_network.hpp | 56 +++++++ 9 files changed, 244 insertions(+), 151 deletions(-) create mode 100644 tests/common/simulated_network.cpp create mode 100644 tests/common/simulated_network.hpp diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 6bac4fe328..5f3df7f67c 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -124,7 +124,7 @@ void application_impl::reset_p2p_node(const fc::path& data_dir) _p2p_network = std::make_shared("BitShares Reference Implementation"); _p2p_network->load_configuration(data_dir / "p2p"); - _p2p_network->set_node_delegate(this); + _p2p_network->set_node_delegate(shared_from_this()); if( _options->count("seed-node") ) { @@ -578,7 +578,7 @@ bool application_impl::has_item(const net::item_id& id) * @throws exception if error validating the item, otherwise the item is safe to broadcast on. */ bool application_impl::handle_block(const graphene::net::block_message& blk_msg, bool sync_mode, - std::vector& contained_transaction_message_ids) + std::vector& contained_transaction_message_ids) { try { auto latency = fc::time_point::now() - blk_msg.block.timestamp; @@ -587,7 +587,8 @@ bool application_impl::handle_block(const graphene::net::block_message& blk_msg, const auto& witness = blk_msg.block.witness(*_chain_db); const auto& witness_account = witness.witness_account(*_chain_db); auto last_irr = _chain_db->get_dynamic_global_properties().last_irreversible_block_num; - ilog("Got block: #${n} ${bid} time: ${t} transaction(s): ${x} latency: ${l} ms from: ${w} irreversible: ${i} (-${d})", + ilog("Got block: #${n} ${bid} time: ${t} transaction(s): ${x} " + "latency: ${l} ms from: ${w} irreversible: ${i} (-${d})", ("t",blk_msg.block.timestamp) ("n", blk_msg.block.block_num()) ("bid", blk_msg.block.id()) @@ -1069,7 +1070,7 @@ void application_impl::set_block_production(bool producing_blocks) namespace graphene { namespace app { application::application() - : my(std::make_unique(*this)) + : my(std::make_shared(*this)) { //nothing else to do } diff --git a/libraries/app/application_impl.hxx b/libraries/app/application_impl.hxx index 7d23ac326a..829a7fdd6f 100644 --- a/libraries/app/application_impl.hxx +++ b/libraries/app/application_impl.hxx @@ -12,7 +12,7 @@ namespace graphene { namespace app { namespace detail { -class application_impl : public net::node_delegate +class application_impl : public net::node_delegate, public std::enable_shared_from_this { public: fc::optional _lock_file; @@ -63,7 +63,7 @@ class application_impl : public net::node_delegate * @throws exception if error validating the item, otherwise the item is safe to broadcast on. */ bool handle_block(const graphene::net::block_message& blk_msg, bool sync_mode, - std::vector& contained_transaction_message_ids) override; + std::vector& contained_transaction_message_ids) override; void handle_transaction(const graphene::net::trx_message& transaction_message) override; diff --git a/libraries/app/include/graphene/app/application.hpp b/libraries/app/include/graphene/app/application.hpp index 3c8c63bd10..6478a97a31 100644 --- a/libraries/app/include/graphene/app/application.hpp +++ b/libraries/app/include/graphene/app/application.hpp @@ -149,7 +149,7 @@ namespace graphene { namespace app { /// Add an available plugin void add_available_plugin( std::shared_ptr p ); - std::unique_ptr my; + std::shared_ptr my; boost::program_options::options_description _cli_options; boost::program_options::options_description _cfg_options; diff --git a/libraries/net/include/graphene/net/message.hpp b/libraries/net/include/graphene/net/message.hpp index 6d254b6120..b6463aaa4a 100644 --- a/libraries/net/include/graphene/net/message.hpp +++ b/libraries/net/include/graphene/net/message.hpp @@ -51,7 +51,7 @@ namespace graphene { namespace net { } }; - typedef fc::uint160_t message_hash_type; + using message_hash_type = fc::ripemd160; /** * Abstracts the process of packing/unpacking a message for a @@ -80,7 +80,7 @@ namespace graphene { namespace net { size = (uint32_t)data.size(); } - fc::uint160_t id()const + message_hash_type id()const { return fc::ripemd160::hash( data.data(), (uint32_t)data.size() ); } diff --git a/libraries/net/include/graphene/net/node.hpp b/libraries/net/include/graphene/net/node.hpp index 0d4d5159d9..7c80d09b1f 100644 --- a/libraries/net/include/graphene/net/node.hpp +++ b/libraries/net/include/graphene/net/node.hpp @@ -29,8 +29,6 @@ #include -#include - namespace graphene { namespace net { using fc::variant_object; @@ -61,7 +59,7 @@ namespace graphene { namespace net { class node_delegate { public: - virtual ~node_delegate(){} + virtual ~node_delegate() = default; /** * If delegate has the item, the network has no need to fetch it. @@ -80,7 +78,7 @@ namespace graphene { namespace net { * safe to broadcast on. */ virtual bool handle_block( const graphene::net::block_message& blk_msg, bool sync_mode, - std::vector& contained_transaction_message_ids ) = 0; + std::vector& contained_transaction_message_ids ) = 0; /** * @brief Called when a new transaction comes in from the network @@ -199,7 +197,7 @@ namespace graphene { namespace net { void close(); - void set_node_delegate( node_delegate* del ); + void set_node_delegate( std::shared_ptr del ); void load_configuration( const fc::path& configuration_directory ); @@ -321,31 +319,7 @@ namespace graphene { namespace net { std::unique_ptr my; }; - class simulated_network : public node - { - public: - ~simulated_network(); - simulated_network(const std::string& user_agent) : node(user_agent) {} - void listen_to_p2p_network() override {} - void connect_to_p2p_network() override {} - void connect_to_endpoint(const fc::ip::endpoint& ep) override {} - - fc::ip::endpoint get_actual_listening_endpoint() const override { return fc::ip::endpoint(); } - - void sync_from(const item_id& current_head_block, const std::vector& hard_fork_block_numbers) override {} - void broadcast(const message& item_to_broadcast) override; - void add_node_delegate(node_delegate* node_delegate_to_add); - - virtual uint32_t get_connection_count() const override { return 8; } - private: - struct node_info; - void message_sender(node_info* destination_node); - std::list network_nodes; - }; - - - typedef std::shared_ptr node_ptr; - typedef std::shared_ptr simulated_network_ptr; + using node_ptr = std::shared_ptr; } } // graphene::net diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index cdabcf6ba2..812ba66e69 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -146,13 +146,15 @@ namespace graphene { namespace net { // for network performance stats message_propagation_data propagation_data; - fc::uint160_t message_contents_hash; // hash of whatever the message contains (if it's a transaction, this is the transaction id, if it's a block, it's the block_id) + /// hash of whatever the message contains + /// (if it's a transaction, this is the transaction id, if it's a block, it's the block_id) + message_hash_type message_contents_hash; message_info( const message_hash_type& message_hash, const message& message_body, uint32_t block_clock_when_received, const message_propagation_data& propagation_data, - fc::uint160_t message_contents_hash ) : + message_hash_type message_contents_hash ) : message_hash( message_hash ), message_body( message_body ), block_clock_when_received( block_clock_when_received ), @@ -160,15 +162,14 @@ namespace graphene { namespace net { message_contents_hash( message_contents_hash ) {} }; - typedef boost::multi_index_container - < message_info, - bmi::indexed_by< bmi::ordered_unique< bmi::tag, - bmi::member >, - bmi::ordered_non_unique< bmi::tag, - bmi::member >, - bmi::ordered_non_unique< bmi::tag, - bmi::member > > - > message_cache_container; + using message_cache_container = boost::multi_index_container < message_info, + bmi::indexed_by< + bmi::ordered_unique< bmi::tag, + bmi::member >, + bmi::ordered_non_unique< bmi::tag, + bmi::member >, + bmi::ordered_non_unique< bmi::tag, + bmi::member > > >; message_cache_container _message_cache; @@ -179,10 +180,13 @@ namespace graphene { namespace net { block_clock( 0 ) {} void block_accepted(); - void cache_message( const message& message_to_cache, const message_hash_type& hash_of_message_to_cache, - const message_propagation_data& propagation_data, const fc::uint160_t& message_content_hash ); + void cache_message( const message& message_to_cache, + const message_hash_type& hash_of_message_to_cache, + const message_propagation_data& propagation_data, + const message_hash_type& message_content_hash ); message get_message( const message_hash_type& hash_of_message_to_lookup ); - message_propagation_data get_message_propagation_data( const fc::uint160_t& hash_of_message_contents_to_lookup ) const; + message_propagation_data get_message_propagation_data( + const message_hash_type& hash_of_message_contents_to_lookup ) const; size_t size() const { return _message_cache.size(); } }; @@ -190,14 +194,14 @@ namespace graphene { namespace net { { ++block_clock; if( block_clock > cache_duration_in_blocks ) - _message_cache.get().erase(_message_cache.get().begin(), - _message_cache.get().lower_bound(block_clock - cache_duration_in_blocks ) ); + _message_cache.get().erase(_message_cache.get().begin(), + _message_cache.get().lower_bound(block_clock - cache_duration_in_blocks ) ); } void blockchain_tied_message_cache::cache_message( const message& message_to_cache, - const message_hash_type& hash_of_message_to_cache, - const message_propagation_data& propagation_data, - const fc::uint160_t& message_content_hash ) + const message_hash_type& hash_of_message_to_cache, + const message_propagation_data& propagation_data, + const message_hash_type& message_content_hash ) { _message_cache.insert( message_info(hash_of_message_to_cache, message_to_cache, @@ -215,9 +219,10 @@ namespace graphene { namespace net { FC_THROW_EXCEPTION( fc::key_not_found_exception, "Requested message not in cache" ); } - message_propagation_data blockchain_tied_message_cache::get_message_propagation_data( const fc::uint160_t& hash_of_message_contents_to_lookup ) const + message_propagation_data blockchain_tied_message_cache::get_message_propagation_data( + const message_hash_type& hash_of_message_contents_to_lookup ) const { - if( hash_of_message_contents_to_lookup != fc::uint160_t() ) + if( hash_of_message_contents_to_lookup != message_hash_type() ) { message_cache_container::index::type::const_iterator iter = _message_cache.get().find(hash_of_message_contents_to_lookup ); @@ -2658,7 +2663,7 @@ namespace graphene { namespace net { namespace detail { try { - std::vector contained_transaction_message_ids; + std::vector contained_transaction_message_ids; _delegate->handle_block(block_message_to_send, true, contained_transaction_message_ids); ilog("Successfully pushed sync block ${num} (id:${id})", ("num", block_message_to_send.block.block_num()) @@ -2981,11 +2986,13 @@ namespace graphene { namespace net { namespace detail { { if (!_node_is_shutting_down && (!_process_backlog_of_sync_blocks_done.valid() || _process_backlog_of_sync_blocks_done.ready())) - _process_backlog_of_sync_blocks_done = fc::async([=](){ process_backlog_of_sync_blocks(); }, "process_backlog_of_sync_blocks"); + _process_backlog_of_sync_blocks_done = fc::async( [=](){ process_backlog_of_sync_blocks(); }, + "process_backlog_of_sync_blocks" ); } void node_impl::process_block_during_sync( peer_connection* originating_peer, - const graphene::net::block_message& block_message_to_process, const message_hash_type& message_hash ) + const graphene::net::block_message& block_message_to_process, + const message_hash_type& message_hash ) { VERIFY_CORRECT_THREAD(); dlog( "received a sync block from peer ${endpoint}", ("endpoint", originating_peer->get_remote_endpoint() ) ); @@ -2997,12 +3004,13 @@ namespace graphene { namespace net { namespace detail { } void node_impl::process_block_during_normal_operation( peer_connection* originating_peer, - const graphene::net::block_message& block_message_to_process, - const message_hash_type& message_hash ) + const graphene::net::block_message& block_message_to_process, + const message_hash_type& message_hash ) { fc::time_point message_receive_time = fc::time_point::now(); - dlog( "received a block from peer ${endpoint}, passing it to client", ("endpoint", originating_peer->get_remote_endpoint() ) ); + dlog( "received a block from peer ${endpoint}, passing it to client", + ("endpoint", originating_peer->get_remote_endpoint() ) ); std::set peers_to_disconnect; std::string disconnect_reason; fc::oexception disconnect_exception; @@ -3019,7 +3027,7 @@ namespace graphene { namespace net { namespace detail { if (std::find(_most_recent_blocks_accepted.begin(), _most_recent_blocks_accepted.end(), block_message_to_process.block_id) == _most_recent_blocks_accepted.end()) { - std::vector contained_transaction_message_ids; + std::vector contained_transaction_message_ids; _delegate->handle_block(block_message_to_process, false, contained_transaction_message_ids); message_validated_time = fc::time_point::now(); ilog("Successfully pushed block ${num} (id:${id})", @@ -3150,7 +3158,8 @@ namespace graphene { namespace net { namespace detail { for (const peer_connection_ptr& peer : peers_to_disconnect) { - wlog("disconnecting client ${endpoint} because it offered us the rejected block", ("endpoint", peer->get_remote_endpoint())); + wlog("disconnecting client ${endpoint} because it offered us the rejected block", + ("endpoint", peer->get_remote_endpoint())); disconnect_from_peer(peer.get(), disconnect_reason, true, *disconnect_exception); } } @@ -4120,12 +4129,12 @@ namespace graphene { namespace net { namespace detail { } // methods implementing node's public interface - void node_impl::set_node_delegate(node_delegate* del, fc::thread* thread_for_delegate_calls) + void node_impl::set_node_delegate(std::shared_ptr del, fc::thread* thread_for_delegate_calls) { VERIFY_CORRECT_THREAD(); _delegate.reset(); if (del) - _delegate.reset(new statistics_gathering_node_delegate_wrapper(del, thread_for_delegate_calls)); + _delegate = std::make_unique(del, thread_for_delegate_calls); if( _delegate ) _chain_id = del->get_chain_id(); } @@ -4671,7 +4680,7 @@ namespace graphene { namespace net { namespace detail { void node_impl::broadcast( const message& item_to_broadcast, const message_propagation_data& propagation_data ) { VERIFY_CORRECT_THREAD(); - fc::uint160_t hash_of_message_contents; + message_hash_type hash_of_message_contents; if( item_to_broadcast.msg_type.value() == graphene::net::block_message_type ) { graphene::net::block_message block_message_to_broadcast = item_to_broadcast.as(); @@ -4897,7 +4906,7 @@ namespace graphene { namespace net { namespace detail { { } - void node::set_node_delegate( node_delegate* del ) + void node::set_node_delegate( std::shared_ptr del ) { fc::thread* delegate_thread = &fc::thread::current(); INVOKE_IN_IMPL(set_node_delegate, del, delegate_thread); @@ -5044,63 +5053,6 @@ namespace graphene { namespace net { namespace detail { INVOKE_IN_IMPL(close); } - struct simulated_network::node_info - { - node_delegate* delegate; - fc::future message_sender_task_done; - std::queue messages_to_deliver; - node_info(node_delegate* delegate) : delegate(delegate) {} - }; - - simulated_network::~simulated_network() - { - for( node_info* network_node_info : network_nodes ) - { - network_node_info->message_sender_task_done.cancel_and_wait("~simulated_network()"); - delete network_node_info; - } - } - - void simulated_network::message_sender(node_info* destination_node) - { - while (!destination_node->messages_to_deliver.empty()) - { - try - { - const message& message_to_deliver = destination_node->messages_to_deliver.front(); - if (message_to_deliver.msg_type.value() == trx_message_type) - destination_node->delegate->handle_transaction(message_to_deliver.as()); - else if (message_to_deliver.msg_type.value() == block_message_type) - { - std::vector contained_transaction_message_ids; - destination_node->delegate->handle_block(message_to_deliver.as(), false, contained_transaction_message_ids); - } - else - destination_node->delegate->handle_message(message_to_deliver); - } - catch ( const fc::exception& e ) - { - elog( "${r}", ("r",e) ); - } - destination_node->messages_to_deliver.pop(); - } - } - - void simulated_network::broadcast( const message& item_to_broadcast ) - { - for (node_info* network_node_info : network_nodes) - { - network_node_info->messages_to_deliver.emplace(item_to_broadcast); - if (!network_node_info->message_sender_task_done.valid() || network_node_info->message_sender_task_done.ready()) - network_node_info->message_sender_task_done = fc::async([=](){ message_sender(network_node_info); }, "simulated_network_sender"); - } - } - - void simulated_network::add_node_delegate( node_delegate* node_delegate_to_add ) - { - network_nodes.push_back(new node_info(node_delegate_to_add)); - } - namespace detail { #define ROLLING_WINDOW_SIZE 1000 @@ -5110,7 +5062,8 @@ namespace graphene { namespace net { namespace detail { , BOOST_PP_CAT(_, BOOST_PP_CAT(method_name, _delay_after_accumulator))(boost::accumulators::tag::rolling_window::window_size = ROLLING_WINDOW_SIZE) - statistics_gathering_node_delegate_wrapper::statistics_gathering_node_delegate_wrapper(node_delegate* delegate, fc::thread* thread_for_delegate_calls) : + statistics_gathering_node_delegate_wrapper::statistics_gathering_node_delegate_wrapper( + std::shared_ptr delegate, fc::thread* thread_for_delegate_calls) : _node_delegate(delegate), _thread(thread_for_delegate_calls) BOOST_PP_SEQ_FOR_EACH(INITIALIZE_ACCUMULATOR, unused, NODE_DELEGATE_METHOD_NAMES) @@ -5213,7 +5166,8 @@ namespace graphene { namespace net { namespace detail { INVOKE_AND_COLLECT_STATISTICS(handle_message, message_to_handle); } - bool statistics_gathering_node_delegate_wrapper::handle_block( const graphene::net::block_message& block_message, bool sync_mode, std::vector& contained_transaction_message_ids) + bool statistics_gathering_node_delegate_wrapper::handle_block( const graphene::net::block_message& block_message, + bool sync_mode, std::vector& contained_transaction_message_ids) { INVOKE_AND_COLLECT_STATISTICS(handle_block, block_message, sync_mode, contained_transaction_message_ids); } diff --git a/libraries/net/node_impl.hxx b/libraries/net/node_impl.hxx index f1f44b6046..9590f8c149 100644 --- a/libraries/net/node_impl.hxx +++ b/libraries/net/node_impl.hxx @@ -144,15 +144,16 @@ struct prioritized_item_id class statistics_gathering_node_delegate_wrapper : public node_delegate { -private: - node_delegate *_node_delegate; - fc::thread *_thread; - - typedef boost::accumulators::accumulator_set > call_stats_accumulator; + private: + std::shared_ptr _node_delegate; + fc::thread *_thread; + + using call_stats_accumulator = boost::accumulators::accumulator_set< int64_t, + boost::accumulators::stats< boost::accumulators::tag::min, + boost::accumulators::tag::rolling_mean, + boost::accumulators::tag::max, + boost::accumulators::tag::sum, + boost::accumulators::tag::count> >; #define NODE_DELEGATE_METHOD_NAMES (has_item) \ (handle_message) \ (handle_block) \ @@ -194,7 +195,7 @@ private: { std::shared_ptr _collector; public: - actual_execution_measurement_helper(std::shared_ptr collector) : + explicit actual_execution_measurement_helper(std::shared_ptr collector) : _collector(collector) { _collector->starting_execution(); @@ -245,14 +246,16 @@ private: _execution_completed_time = fc::time_point::now(); } }; - public: - statistics_gathering_node_delegate_wrapper(node_delegate* delegate, fc::thread* thread_for_delegate_calls); + public: + statistics_gathering_node_delegate_wrapper(std::shared_ptr delegate, + fc::thread* thread_for_delegate_calls); fc::variant_object get_call_statistics(); bool has_item( const graphene::net::item_id& id ) override; void handle_message( const message& ) override; - bool handle_block( const graphene::net::block_message& block_message, bool sync_mode, std::vector& contained_transaction_message_ids ) override; + bool handle_block( const graphene::net::block_message& block_message, bool sync_mode, + std::vector& contained_transaction_message_ids ) override; void handle_transaction( const graphene::net::trx_message& transaction_message ) override; std::vector get_block_ids(const std::vector& blockchain_synopsis, uint32_t& remaining_item_count, @@ -269,7 +272,7 @@ private: uint32_t estimate_last_known_fork_from_git_revision_timestamp(uint32_t unix_timestamp) const override; void error_encountered(const std::string& message, const fc::oexception& error) override; uint8_t get_current_block_interval_in_seconds() const override; - }; +}; class node_impl : public peer_connection_delegate { @@ -558,11 +561,23 @@ class node_impl : public peer_connection_delegate void send_sync_block_to_node_delegate(const graphene::net::block_message& block_message_to_send); void process_backlog_of_sync_blocks(); void trigger_process_backlog_of_sync_blocks(); - void process_block_during_sync(peer_connection* originating_peer, const graphene::net::block_message& block_message, const message_hash_type& message_hash); - void process_block_during_normal_operation(peer_connection* originating_peer, const graphene::net::block_message& block_message, const message_hash_type& message_hash); - void process_block_message(peer_connection* originating_peer, const message& message_to_process, const message_hash_type& message_hash); - - void process_ordinary_message(peer_connection* originating_peer, const message& message_to_process, const message_hash_type& message_hash); + void process_block_during_sync( + peer_connection* originating_peer, + const graphene::net::block_message& block_message, + const message_hash_type& message_hash); + void process_block_during_normal_operation( + peer_connection* originating_peer, + const graphene::net::block_message& block_message, + const message_hash_type& message_hash); + void process_block_message( + peer_connection* originating_peer, + const message& message_to_process, + const message_hash_type& message_hash); + + void process_ordinary_message( + peer_connection* originating_peer, + const message& message_to_process, + const message_hash_type& message_hash); void start_synchronizing(); void start_synchronizing_with_peer(const peer_connection_ptr& peer); @@ -594,7 +609,7 @@ class node_impl : public peer_connection_delegate const fc::oexception& additional_data = fc::oexception() ); // methods implementing node's public interface - void set_node_delegate(node_delegate* del, fc::thread* thread_for_delegate_calls); + void set_node_delegate(std::shared_ptr del, fc::thread* thread_for_delegate_calls); void load_configuration( const fc::path& configuration_directory ); void listen_to_p2p_network(); void connect_to_p2p_network(); diff --git a/tests/common/simulated_network.cpp b/tests/common/simulated_network.cpp new file mode 100644 index 0000000000..1ea1f357d5 --- /dev/null +++ b/tests/common/simulated_network.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include +#include + +#include "simulated_network.hpp" + +#include + +namespace graphene { namespace net { + + struct simulated_network::node_info + { + std::shared_ptr delegate; + fc::future message_sender_task_done; + std::queue messages_to_deliver; + explicit node_info(std::shared_ptr del) : delegate(del) {} + }; + + simulated_network::~simulated_network() + { + for( auto network_node_info : network_nodes ) + { + network_node_info->message_sender_task_done.cancel_and_wait("~simulated_network()"); + } + } + + void simulated_network::message_sender(std::shared_ptr destination_node) + { + while (!destination_node->messages_to_deliver.empty()) + { + try + { + const message& message_to_deliver = destination_node->messages_to_deliver.front(); + if (message_to_deliver.msg_type.value() == trx_message_type) + destination_node->delegate->handle_transaction(message_to_deliver.as()); + else if (message_to_deliver.msg_type.value() == block_message_type) + { + std::vector contained_transaction_message_ids; + destination_node->delegate->handle_block(message_to_deliver.as(), false, + contained_transaction_message_ids); + } + else + destination_node->delegate->handle_message(message_to_deliver); + } + catch ( const fc::exception& e ) + { + elog( "${r}", ("r",e) ); + } + destination_node->messages_to_deliver.pop(); + } + } + + void simulated_network::broadcast( const message& item_to_broadcast ) + { + for (auto network_node_info : network_nodes) + { + network_node_info->messages_to_deliver.emplace(item_to_broadcast); + if (!network_node_info->message_sender_task_done.valid() || network_node_info->message_sender_task_done.ready()) + network_node_info->message_sender_task_done = fc::async([=](){ message_sender(network_node_info); }, + "simulated_network_sender"); + } + } + + void simulated_network::add_node_delegate( std::shared_ptr node_delegate_to_add ) + { + network_nodes.push_back(std::make_shared(node_delegate_to_add)); + } + +} } // graphene::net diff --git a/tests/common/simulated_network.hpp b/tests/common/simulated_network.hpp new file mode 100644 index 0000000000..85f59e213a --- /dev/null +++ b/tests/common/simulated_network.hpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include + +#include + +namespace graphene { namespace net { + +class simulated_network : public node +{ +public: + ~simulated_network() override; + explicit simulated_network(const std::string& user_agent) : node(user_agent) {} + void listen_to_p2p_network() override {} + void connect_to_p2p_network() override {} + void connect_to_endpoint(const fc::ip::endpoint& ep) override {} + + fc::ip::endpoint get_actual_listening_endpoint() const override { return fc::ip::endpoint(); } + + void sync_from(const item_id& current_head_block, const std::vector& hard_fork_block_numbers) override {} + void broadcast(const message& item_to_broadcast) override; + void add_node_delegate(std::shared_ptr node_delegate_to_add); + + uint32_t get_connection_count() const override { return 8; } +private: + struct node_info; + void message_sender(std::shared_ptr destination_node); + std::list> network_nodes; +}; + +using simulated_network_ptr = std::shared_ptr; + +} } // graphene::net From c147536a82d225bb3fdaacfb82f80fca4afb8259 Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 6 Apr 2021 18:43:07 +0000 Subject: [PATCH 102/147] Manage node_impl object with shared_ptr and explicitly close chain database in destructor of application class --- libraries/app/application.cpp | 17 ++++++++++++-- libraries/net/include/graphene/net/node.hpp | 7 ++---- libraries/net/node.cpp | 26 ++++++++++++++------- libraries/net/node_impl.hxx | 11 ++++++--- 4 files changed, 42 insertions(+), 19 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 5f3df7f67c..e6b34b26e2 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -996,6 +996,7 @@ uint8_t application_impl::get_current_block_interval_in_seconds() const void application_impl::shutdown() { + ilog( "Shutting down application" ); if( _websocket_tls_server ) _websocket_tls_server.reset(); if( _websocket_server ) @@ -1003,20 +1004,27 @@ void application_impl::shutdown() // TODO wait until all connections are closed and messages handled? // plugins E.G. witness_plugin may send data to p2p network, so shutdown them first + ilog( "Shutting down plugins" ); shutdown_plugins(); if( _p2p_network ) { + ilog( "Disconnecting from P2P network" ); + // FIXME wait() is called in close() but it doesn't block this thread _p2p_network->close(); _p2p_network.reset(); - // TODO wait until all connections are closed and messages handled? } + else + ilog( "P2P network is disabled" ); if( _chain_db ) { + ilog( "Closing chain database" ); _chain_db->close(); _chain_db.reset(); } + else + ilog( "Chain database is not open" ); } void application_impl::enable_plugin( const string& name ) @@ -1077,7 +1085,8 @@ application::application() application::~application() { - //nothing to do + ilog("Application quitting"); + my->shutdown(); } void application::set_program_options(boost::program_options::options_description& command_line_options, @@ -1194,13 +1203,17 @@ void application::set_program_options(boost::program_options::options_descriptio void application::initialize(const fc::path& data_dir, std::shared_ptr options) { + ilog( "Initializing application" ); my->initialize( data_dir, options ); + ilog( "Done initializing application" ); } void application::startup() { try { + ilog( "Starting up application" ); my->startup(); + ilog( "Done starting up application" ); } catch ( const fc::exception& e ) { elog( "${e}", ("e",e.to_detail_string()) ); throw; diff --git a/libraries/net/include/graphene/net/node.hpp b/libraries/net/include/graphene/net/node.hpp index 7c80d09b1f..d22b5c800e 100644 --- a/libraries/net/include/graphene/net/node.hpp +++ b/libraries/net/include/graphene/net/node.hpp @@ -37,11 +37,8 @@ namespace graphene { namespace net { namespace detail { class node_impl; - struct node_impl_deleter - { - void operator()(node_impl*); - }; } + using node_impl_ptr = std::shared_ptr; // during network development, we need to track message propagation across the network // using a structure like this: @@ -316,7 +313,7 @@ namespace graphene { namespace net { void disable_peer_advertising(); fc::variant_object get_call_statistics() const; private: - std::unique_ptr my; + node_impl_ptr my; }; using node_ptr = std::shared_ptr; diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 812ba66e69..db14b34386 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -859,7 +859,7 @@ namespace graphene { namespace net { namespace detail { _retrigger_advertise_inventory_loop_promise->set_value(); } - void node_impl::terminate_inactive_connections_loop() + void node_impl::terminate_inactive_connections_loop(node_impl_ptr self) { VERIFY_CORRECT_THREAD(); std::list peers_to_disconnect_gently; @@ -1077,9 +1077,12 @@ namespace graphene { namespace net { namespace detail { peers_to_send_keep_alive.clear(); if (!_node_is_shutting_down && !_terminate_inactive_connections_loop_done.canceled()) - _terminate_inactive_connections_loop_done = fc::schedule( [this](){ terminate_inactive_connections_loop(); }, - fc::time_point::now() + fc::seconds(GRAPHENE_NET_PEER_HANDSHAKE_INACTIVITY_TIMEOUT / 2), - "terminate_inactive_connections_loop" ); + { + _terminate_inactive_connections_loop_done = fc::schedule( + [this,self](){ terminate_inactive_connections_loop(self); }, + fc::time_point::now() + fc::seconds(GRAPHENE_NET_PEER_HANDSHAKE_INACTIVITY_TIMEOUT / 2), + "terminate_inactive_connections_loop" ); + } } void node_impl::fetch_updated_peer_lists_loop() @@ -4307,7 +4310,7 @@ namespace graphene { namespace net { namespace detail { } } - void node_impl::connect_to_p2p_network() + void node_impl::connect_to_p2p_network(node_impl_ptr self) { VERIFY_CORRECT_THREAD(); assert(_node_public_key != fc::ecc::public_key_data()); @@ -4324,12 +4327,15 @@ namespace graphene { namespace net { namespace detail { !_dump_node_status_task_done.valid()); if (_node_configuration.accept_incoming_connections) _accept_loop_complete = fc::async( [=](){ accept_loop(); }, "accept_loop"); + _p2p_network_connect_loop_done = fc::async( [=]() { p2p_network_connect_loop(); }, "p2p_network_connect_loop" ); _fetch_sync_items_loop_done = fc::async( [=]() { fetch_sync_items_loop(); }, "fetch_sync_items_loop" ); _fetch_item_loop_done = fc::async( [=]() { fetch_items_loop(); }, "fetch_items_loop" ); _advertise_inventory_loop_done = fc::async( [=]() { advertise_inventory_loop(); }, "advertise_inventory_loop" ); - _terminate_inactive_connections_loop_done = fc::async( [=]() { terminate_inactive_connections_loop(); }, "terminate_inactive_connections_loop" ); - _fetch_updated_peer_lists_loop_done = fc::async([=](){ fetch_updated_peer_lists_loop(); }, "fetch_updated_peer_lists_loop"); + _terminate_inactive_connections_loop_done = fc::async( [=]() { terminate_inactive_connections_loop(self); }, + "terminate_inactive_connections_loop" ); + _fetch_updated_peer_lists_loop_done = fc::async([=](){ fetch_updated_peer_lists_loop(); }, + "fetch_updated_peer_lists_loop"); _bandwidth_monitor_loop_done = fc::async([=](){ bandwidth_monitor_loop(); }, "bandwidth_monitor_loop"); _dump_node_status_task_done = fc::async([=](){ dump_node_status_task(); }, "dump_node_status_task"); schedule_next_update_seed_nodes_task(); @@ -4898,12 +4904,14 @@ namespace graphene { namespace net { namespace detail { #endif // P2P_IN_DEDICATED_THREAD node::node(const std::string& user_agent) : - my(new detail::node_impl(user_agent)) + my(new detail::node_impl(user_agent), detail::node_impl_deleter()) { + // nothing else to do } node::~node() { + // nothing to do } void node::set_node_delegate( std::shared_ptr del ) @@ -4924,7 +4932,7 @@ namespace graphene { namespace net { namespace detail { void node::connect_to_p2p_network() { - INVOKE_IN_IMPL(connect_to_p2p_network); + INVOKE_IN_IMPL(connect_to_p2p_network, my); } void node::add_node( const fc::ip::endpoint& ep ) diff --git a/libraries/net/node_impl.hxx b/libraries/net/node_impl.hxx index 9590f8c149..ad4b937ada 100644 --- a/libraries/net/node_impl.hxx +++ b/libraries/net/node_impl.hxx @@ -274,7 +274,7 @@ class statistics_gathering_node_delegate_wrapper : public node_delegate uint8_t get_current_block_interval_in_seconds() const override; }; -class node_impl : public peer_connection_delegate +class node_impl : public peer_connection_delegate, public std::enable_shared_from_this { public: #ifdef P2P_IN_DEDICATED_THREAD @@ -478,7 +478,7 @@ class node_impl : public peer_connection_delegate void advertise_inventory_loop(); void trigger_advertise_inventory_loop(); - void terminate_inactive_connections_loop(); + void terminate_inactive_connections_loop(node_impl_ptr self); void fetch_updated_peer_lists_loop(); void update_bandwidth_data(uint32_t bytes_read_this_second, uint32_t bytes_written_this_second); @@ -612,7 +612,7 @@ class node_impl : public peer_connection_delegate void set_node_delegate(std::shared_ptr del, fc::thread* thread_for_delegate_calls); void load_configuration( const fc::path& configuration_directory ); void listen_to_p2p_network(); - void connect_to_p2p_network(); + void connect_to_p2p_network(node_impl_ptr self); void add_node( const fc::ip::endpoint& ep ); void add_seed_node( const std::string& seed_string ); void resolve_seed_node_and_add( const std::string& seed_string ); @@ -652,4 +652,9 @@ class node_impl : public peer_connection_delegate uint32_t get_next_known_hard_fork_block_number(uint32_t block_number) const; }; // end class node_impl + struct node_impl_deleter + { + void operator()(node_impl*); + }; + }}} // end of namespace graphene::net::detail From 24f424d037f155020ae3c5f550b74f0ba9630e3f Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 6 Apr 2021 20:59:10 +0000 Subject: [PATCH 103/147] Add try catch in _terminate_inactive_conn_loop to try to avoid accessing freed memory when node is shutting down --- libraries/app/application.cpp | 1 + libraries/net/node.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index e6b34b26e2..879b02b7f6 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -991,6 +991,7 @@ void application_impl::error_encountered(const std::string& message, const fc::o uint8_t application_impl::get_current_block_interval_in_seconds() const { + FC_ASSERT( _chain_db, "Chain database is not operational" ); return _chain_db->get_global_properties().parameters.block_interval; } diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index db14b34386..a4fddaaed3 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -867,6 +867,9 @@ namespace graphene { namespace net { namespace detail { std::list peers_to_send_keep_alive; std::list peers_to_terminate; + try { + // Note: if the node is shutting down, it's possible that _delegate is already unusable, + // in this case, we'll get an exception _recent_block_interval_in_seconds = _delegate->get_current_block_interval_in_seconds(); // Disconnect peers that haven't sent us any data recently @@ -1076,6 +1079,14 @@ namespace graphene { namespace net { namespace detail { offsetof(current_time_request_message, request_sent_time)); peers_to_send_keep_alive.clear(); + } catch( const fc::exception& e ) { + wlog( "Exception caught in terminate_inactive_connections_loop: ${e}", ("e",e.to_detail_string()) ); + // If the node is shutting down, we just quit, no need to throw. + // If the node is not shutting down, the old code will throw, which means we won't schedule a new loop, + // likely it's unexpected behavior. + // Thus we don't throw here. + } + if (!_node_is_shutting_down && !_terminate_inactive_connections_loop_done.canceled()) { _terminate_inactive_connections_loop_done = fc::schedule( From 197adf7695f91460bd4c8085d730669aedf73cc2 Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 6 Apr 2021 21:02:09 +0000 Subject: [PATCH 104/147] Explicitly shutdown witness plugin in unit test to avoid accessing freed memory --- tests/tests/operation_tests2.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index 1e97b41207..26d2215b2d 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -994,6 +994,8 @@ BOOST_AUTO_TEST_CASE( witness_create ) produced++; } BOOST_CHECK_GE( produced, 1 ); + + wtplugin->plugin_shutdown(); } FC_LOG_AND_RETHROW() } /** From 2384ecb2bf1ece9df8e83181a05d2fa9394bbeec Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 6 Apr 2021 22:09:50 +0000 Subject: [PATCH 105/147] Cleanup socket after app in CLI tests for windows --- tests/cli/main.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index 11e30391fd..d5ed125e09 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -106,9 +106,6 @@ std::shared_ptr start_application(fc::temp_directory auto sharable_cfg = std::make_shared(); auto& cfg = *sharable_cfg; -#ifdef _WIN32 - sockInit(); -#endif server_port_number = fc::network::get_available_port(); cfg.emplace( "rpc-endpoint", @@ -277,6 +274,16 @@ class client_connection struct cli_fixture { +#ifdef _WIN32 + struct socket_maintainer { + socket_maintainer() { + sockInit(); + } + ~socket_maintainer() { + sockQuit(); + } + } sock_maintainer; +#endif int server_port_number; fc::temp_directory app_dir; std::shared_ptr app1; @@ -314,9 +321,6 @@ struct cli_fixture ~cli_fixture() { BOOST_TEST_MESSAGE("Cleanup cli_wallet::boost_fixture_test_case"); -#ifdef _WIN32 - sockQuit(); -#endif } }; From 1476bc6e628c8a213ff37d42b418182560ec76d6 Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 6 Apr 2021 23:04:59 +0000 Subject: [PATCH 106/147] Add tests for enable-p2p-network option --- tests/common/database_fixture.cpp | 11 +++++++- tests/tests/network_broadcast_api_tests.cpp | 30 +++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index ef30b1d302..847181c5cf 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -183,10 +183,19 @@ std::shared_ptr database_fixture_base::in { auto sharable_options = std::make_shared(); auto& options = *sharable_options; - set_option( options, "seed-nodes", std::string("[]") ); + set_option( options, "seed-nodes", std::string("[]") ); // Do not connect to default seed nodes /** * Test specific settings */ + if (fixture.current_test_name == "broadcast_transaction_with_callback_test") + set_option( options, "enable-p2p-network", true ); + else if (fixture.current_test_name == "broadcast_transaction_disabled_p2p_test") + set_option( options, "enable-p2p-network", false ); + else if( rand() % 100 >= 50 ) // Disable P2P network randomly for test cases + set_option( options, "enable-p2p-network", false ); + else if( rand() % 100 >= 50 ) // this should lead to no change + set_option( options, "enable-p2p-network", true ); + if (fixture.current_test_name == "get_account_history_operations") { options.insert(std::make_pair("max-ops-per-account", boost::program_options::variable_value((uint64_t)75, false))); diff --git a/tests/tests/network_broadcast_api_tests.cpp b/tests/tests/network_broadcast_api_tests.cpp index a40c112662..9a4a264492 100644 --- a/tests/tests/network_broadcast_api_tests.cpp +++ b/tests/tests/network_broadcast_api_tests.cpp @@ -72,6 +72,36 @@ BOOST_AUTO_TEST_CASE( broadcast_transaction_with_callback_test ) { } FC_LOG_AND_RETHROW() } +BOOST_AUTO_TEST_CASE( broadcast_transaction_disabled_p2p_test ) { + try { + + uint32_t called = 0; + auto callback = [&]( const variant& v ) + { + ++called; + }; + + fc::ecc::private_key cid_key = fc::ecc::private_key::regenerate( fc::digest("key") ); + const account_id_type cid_id = create_account( "cid", cid_key.get_public_key() ).id; + fund( cid_id(db) ); + + auto nb_api = std::make_shared< graphene::app::network_broadcast_api >( app ); + + set_expiration( db, trx ); + transfer_operation trans; + trans.from = cid_id; + trans.to = account_id_type(); + trans.amount = asset(1); + trx.operations.push_back( trans ); + sign( trx, cid_key ); + + BOOST_CHECK_THROW( nb_api->broadcast_transaction( trx ), fc::exception ); + BOOST_CHECK_THROW( nb_api->broadcast_transaction_with_callback( callback, trx ), fc::exception ); + BOOST_CHECK_EQUAL( called, 0u ); + + } FC_LOG_AND_RETHROW() +} + BOOST_AUTO_TEST_CASE( broadcast_transaction_too_large ) { try { From e659a631d5f1da5cda90bbb7465758dff58256c6 Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 6 Apr 2021 23:30:36 +0000 Subject: [PATCH 107/147] Update order of includes in es_test --- tests/elasticsearch/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/elasticsearch/main.cpp b/tests/elasticsearch/main.cpp index 7bbb090ea5..315c9f3dc2 100644 --- a/tests/elasticsearch/main.cpp +++ b/tests/elasticsearch/main.cpp @@ -29,9 +29,10 @@ #include #include +#include "../common/init_unit_test_suite.hpp" + #include "../common/database_fixture.hpp" -#include "../common/init_unit_test_suite.hpp" #include "../common/utils.hpp" #define ES_WAIT_TIME (fc::milliseconds(10000)) From b013559fad6ad904ee38fe8e3e0ea29bfbf8758b Mon Sep 17 00:00:00 2001 From: abitmore Date: Wed, 7 Apr 2021 00:31:56 +0000 Subject: [PATCH 108/147] Refuse to broadcast sooner if no P2P network --- libraries/app/api.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 3fd59676f9..5906ea63c2 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -179,8 +179,8 @@ namespace graphene { namespace app { void network_broadcast_api::broadcast_transaction(const precomputable_transaction& trx) { - _app.chain_database()->precompute_parallel( trx ).wait(); FC_ASSERT( _app.p2p_node() != nullptr, "Not connected to P2P network, can't broadcast!" ); + _app.chain_database()->precompute_parallel( trx ).wait(); _app.chain_database()->push_transaction(trx); _app.p2p_node()->broadcast_transaction(trx); } @@ -197,16 +197,16 @@ namespace graphene { namespace app { void network_broadcast_api::broadcast_block( const signed_block& b ) { - _app.chain_database()->precompute_parallel( b ).wait(); FC_ASSERT( _app.p2p_node() != nullptr, "Not connected to P2P network, can't broadcast!" ); + _app.chain_database()->precompute_parallel( b ).wait(); _app.chain_database()->push_block(b); _app.p2p_node()->broadcast( net::block_message( b )); } void network_broadcast_api::broadcast_transaction_with_callback(confirmation_callback cb, const precomputable_transaction& trx) { - _app.chain_database()->precompute_parallel( trx ).wait(); FC_ASSERT( _app.p2p_node() != nullptr, "Not connected to P2P network, can't broadcast!" ); + _app.chain_database()->precompute_parallel( trx ).wait(); _callbacks[trx.id()] = cb; _app.chain_database()->push_transaction(trx); _app.p2p_node()->broadcast_transaction(trx); From 67026f6dc5b2dfa69718d02a92ba08624a9de6ce Mon Sep 17 00:00:00 2001 From: abitmore Date: Wed, 7 Apr 2021 10:39:43 +0000 Subject: [PATCH 109/147] Rename long variable names --- libraries/app/application.cpp | 6 +++--- libraries/app/application_impl.hxx | 4 ++-- libraries/net/include/graphene/net/node.hpp | 4 ++-- libraries/net/node.cpp | 14 +++++++------- libraries/net/node_impl.hxx | 2 +- tests/common/simulated_network.cpp | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 879b02b7f6..73e3174e82 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -578,7 +578,7 @@ bool application_impl::has_item(const net::item_id& id) * @throws exception if error validating the item, otherwise the item is safe to broadcast on. */ bool application_impl::handle_block(const graphene::net::block_message& blk_msg, bool sync_mode, - std::vector& contained_transaction_message_ids) + std::vector& contained_transaction_msg_ids) { try { auto latency = fc::time_point::now() - blk_msg.block.timestamp; @@ -622,12 +622,12 @@ bool application_impl::handle_block(const graphene::net::block_message& blk_msg, // happens, there's no reason to fetch the transactions, so construct a list of the // transaction message ids we no longer need. // during sync, it is unlikely that we'll see any old - contained_transaction_message_ids.reserve( contained_transaction_message_ids.size() + contained_transaction_msg_ids.reserve( contained_transaction_msg_ids.size() + blk_msg.block.transactions.size() ); for (const processed_transaction& ptrx : blk_msg.block.transactions) { graphene::net::trx_message transaction_message(ptrx); - contained_transaction_message_ids.emplace_back(graphene::net::message(transaction_message).id()); + contained_transaction_msg_ids.emplace_back(graphene::net::message(transaction_message).id()); } } diff --git a/libraries/app/application_impl.hxx b/libraries/app/application_impl.hxx index 829a7fdd6f..9f42800494 100644 --- a/libraries/app/application_impl.hxx +++ b/libraries/app/application_impl.hxx @@ -57,13 +57,13 @@ class application_impl : public net::node_delegate, public std::enable_shared_fr * * @param blk_msg the message which contains the block * @param sync_mode true if the message was fetched through the sync process, false during normal operation - * @param contained_transaction_message_ids container for the transactions to write back into + * @param contained_transaction_msg_ids container for the transactions to write back into * @returns true if this message caused the blockchain to switch forks, false if it did not * * @throws exception if error validating the item, otherwise the item is safe to broadcast on. */ bool handle_block(const graphene::net::block_message& blk_msg, bool sync_mode, - std::vector& contained_transaction_message_ids) override; + std::vector& contained_transaction_msg_ids) override; void handle_transaction(const graphene::net::trx_message& transaction_message) override; diff --git a/libraries/net/include/graphene/net/node.hpp b/libraries/net/include/graphene/net/node.hpp index d22b5c800e..55d2df782f 100644 --- a/libraries/net/include/graphene/net/node.hpp +++ b/libraries/net/include/graphene/net/node.hpp @@ -68,14 +68,14 @@ namespace graphene { namespace net { * * @param blk_msg the message which contains the block * @param sync_mode true if the message was fetched through the sync process, false during normal operation - * @param contained_transaction_message_ids container for the transactions to write back into + * @param contained_transaction_msg_ids container for the transactions to write back into * @returns true if this message caused the blockchain to switch forks, false if it did not * * @throws exception if error validating the item, otherwise the item is * safe to broadcast on. */ virtual bool handle_block( const graphene::net::block_message& blk_msg, bool sync_mode, - std::vector& contained_transaction_message_ids ) = 0; + std::vector& contained_transaction_msg_ids ) = 0; /** * @brief Called when a new transaction comes in from the network diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index a4fddaaed3..adb4f6c4be 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -2677,8 +2677,8 @@ namespace graphene { namespace net { namespace detail { try { - std::vector contained_transaction_message_ids; - _delegate->handle_block(block_message_to_send, true, contained_transaction_message_ids); + std::vector contained_transaction_msg_ids; + _delegate->handle_block(block_message_to_send, true, contained_transaction_msg_ids); ilog("Successfully pushed sync block ${num} (id:${id})", ("num", block_message_to_send.block.block_num()) ("id", block_message_to_send.block_id)); @@ -3041,8 +3041,8 @@ namespace graphene { namespace net { namespace detail { if (std::find(_most_recent_blocks_accepted.begin(), _most_recent_blocks_accepted.end(), block_message_to_process.block_id) == _most_recent_blocks_accepted.end()) { - std::vector contained_transaction_message_ids; - _delegate->handle_block(block_message_to_process, false, contained_transaction_message_ids); + std::vector contained_transaction_msg_ids; + _delegate->handle_block(block_message_to_process, false, contained_transaction_msg_ids); message_validated_time = fc::time_point::now(); ilog("Successfully pushed block ${num} (id:${id})", ("num", block_message_to_process.block.block_num()) @@ -3050,7 +3050,7 @@ namespace graphene { namespace net { namespace detail { _most_recent_blocks_accepted.push_back(block_message_to_process.block_id); bool new_transaction_discovered = false; - for (const item_hash_t& transaction_message_hash : contained_transaction_message_ids) + for (const item_hash_t& transaction_message_hash : contained_transaction_msg_ids) { /*size_t items_erased =*/ _items_to_fetch.get().erase(item_id(trx_message_type, transaction_message_hash)); // there are two ways we could behave here: we could either act as if we received @@ -5186,9 +5186,9 @@ namespace graphene { namespace net { namespace detail { } bool statistics_gathering_node_delegate_wrapper::handle_block( const graphene::net::block_message& block_message, - bool sync_mode, std::vector& contained_transaction_message_ids) + bool sync_mode, std::vector& contained_transaction_msg_ids) { - INVOKE_AND_COLLECT_STATISTICS(handle_block, block_message, sync_mode, contained_transaction_message_ids); + INVOKE_AND_COLLECT_STATISTICS(handle_block, block_message, sync_mode, contained_transaction_msg_ids); } void statistics_gathering_node_delegate_wrapper::handle_transaction( const graphene::net::trx_message& transaction_message ) diff --git a/libraries/net/node_impl.hxx b/libraries/net/node_impl.hxx index ad4b937ada..f217ec72f8 100644 --- a/libraries/net/node_impl.hxx +++ b/libraries/net/node_impl.hxx @@ -255,7 +255,7 @@ class statistics_gathering_node_delegate_wrapper : public node_delegate bool has_item( const graphene::net::item_id& id ) override; void handle_message( const message& ) override; bool handle_block( const graphene::net::block_message& block_message, bool sync_mode, - std::vector& contained_transaction_message_ids ) override; + std::vector& contained_transaction_msg_ids ) override; void handle_transaction( const graphene::net::trx_message& transaction_message ) override; std::vector get_block_ids(const std::vector& blockchain_synopsis, uint32_t& remaining_item_count, diff --git a/tests/common/simulated_network.cpp b/tests/common/simulated_network.cpp index 1ea1f357d5..91557b1f25 100644 --- a/tests/common/simulated_network.cpp +++ b/tests/common/simulated_network.cpp @@ -59,9 +59,9 @@ namespace graphene { namespace net { destination_node->delegate->handle_transaction(message_to_deliver.as()); else if (message_to_deliver.msg_type.value() == block_message_type) { - std::vector contained_transaction_message_ids; + std::vector contained_transaction_msg_ids; destination_node->delegate->handle_block(message_to_deliver.as(), false, - contained_transaction_message_ids); + contained_transaction_msg_ids); } else destination_node->delegate->handle_message(message_to_deliver); From 628f93ba7199998a3e25a0c3fc1e515a0877d930 Mon Sep 17 00:00:00 2001 From: abitmore Date: Wed, 7 Apr 2021 10:58:12 +0000 Subject: [PATCH 110/147] Replace duplicate constructors with using clauses and remove the unnecessary destructor from the plugin class --- libraries/app/include/graphene/app/plugin.hpp | 3 +-- .../include/graphene/debug_witness/debug_witness.hpp | 2 +- .../plugins/snapshot/include/graphene/snapshot/snapshot.hpp | 2 +- libraries/plugins/witness/include/graphene/witness/witness.hpp | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/libraries/app/include/graphene/app/plugin.hpp b/libraries/app/include/graphene/app/plugin.hpp index b2809723ad..10a750e28a 100644 --- a/libraries/app/include/graphene/app/plugin.hpp +++ b/libraries/app/include/graphene/app/plugin.hpp @@ -100,8 +100,7 @@ class abstract_plugin class plugin : public abstract_plugin { public: - explicit plugin(application& a) : abstract_plugin(a) {} - ~plugin() override = default; + using abstract_plugin::abstract_plugin; std::string plugin_name()const override; std::string plugin_description()const override; diff --git a/libraries/plugins/debug_witness/include/graphene/debug_witness/debug_witness.hpp b/libraries/plugins/debug_witness/include/graphene/debug_witness/debug_witness.hpp index e7d4f734d1..92f1b21d74 100644 --- a/libraries/plugins/debug_witness/include/graphene/debug_witness/debug_witness.hpp +++ b/libraries/plugins/debug_witness/include/graphene/debug_witness/debug_witness.hpp @@ -34,7 +34,7 @@ namespace graphene { namespace debug_witness_plugin { class debug_witness_plugin : public graphene::app::plugin { public: - debug_witness_plugin(graphene::app::application& app) : graphene::app::plugin(app) {} + using graphene::app::plugin::plugin; ~debug_witness_plugin() override; std::string plugin_name()const override; diff --git a/libraries/plugins/snapshot/include/graphene/snapshot/snapshot.hpp b/libraries/plugins/snapshot/include/graphene/snapshot/snapshot.hpp index 5f62a0a678..c4de7b7624 100644 --- a/libraries/plugins/snapshot/include/graphene/snapshot/snapshot.hpp +++ b/libraries/plugins/snapshot/include/graphene/snapshot/snapshot.hpp @@ -32,7 +32,7 @@ namespace graphene { namespace snapshot_plugin { class snapshot_plugin : public graphene::app::plugin { public: - snapshot_plugin(graphene::app::application& app) : graphene::app::plugin(app) {} + using graphene::app::plugin::plugin; std::string plugin_name()const override; std::string plugin_description()const override; diff --git a/libraries/plugins/witness/include/graphene/witness/witness.hpp b/libraries/plugins/witness/include/graphene/witness/witness.hpp index 40c4fe87c8..e3e1497af2 100644 --- a/libraries/plugins/witness/include/graphene/witness/witness.hpp +++ b/libraries/plugins/witness/include/graphene/witness/witness.hpp @@ -49,7 +49,7 @@ namespace block_production_condition class witness_plugin : public graphene::app::plugin { public: - witness_plugin(graphene::app::application& app) : graphene::app::plugin(app) {} + using graphene::app::plugin::plugin; ~witness_plugin() override { cleanup(); } std::string plugin_name()const override; From aac5f43b127603b0e63ee4f0c1d99cb190ac1135 Mon Sep 17 00:00:00 2001 From: abitmore Date: Wed, 7 Apr 2021 11:12:23 +0000 Subject: [PATCH 111/147] Rename long variable names and function names --- libraries/net/node.cpp | 22 +++++++++++----------- libraries/net/node_impl.hxx | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index adb4f6c4be..317a9212c9 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -859,7 +859,7 @@ namespace graphene { namespace net { namespace detail { _retrigger_advertise_inventory_loop_promise->set_value(); } - void node_impl::terminate_inactive_connections_loop(node_impl_ptr self) + void node_impl::kill_inactive_conns_loop(node_impl_ptr self) { VERIFY_CORRECT_THREAD(); std::list peers_to_disconnect_gently; @@ -1080,19 +1080,19 @@ namespace graphene { namespace net { namespace detail { peers_to_send_keep_alive.clear(); } catch( const fc::exception& e ) { - wlog( "Exception caught in terminate_inactive_connections_loop: ${e}", ("e",e.to_detail_string()) ); + wlog( "Exception caught in kill_inactive_conns_loop: ${e}", ("e",e.to_detail_string()) ); // If the node is shutting down, we just quit, no need to throw. // If the node is not shutting down, the old code will throw, which means we won't schedule a new loop, // likely it's unexpected behavior. // Thus we don't throw here. } - if (!_node_is_shutting_down && !_terminate_inactive_connections_loop_done.canceled()) + if (!_node_is_shutting_down && !_kill_inactive_conns_loop_done.canceled()) { - _terminate_inactive_connections_loop_done = fc::schedule( - [this,self](){ terminate_inactive_connections_loop(self); }, + _kill_inactive_conns_loop_done = fc::schedule( + [this,self](){ kill_inactive_conns_loop(self); }, fc::time_point::now() + fc::seconds(GRAPHENE_NET_PEER_HANDSHAKE_INACTIVITY_TIMEOUT / 2), - "terminate_inactive_connections_loop" ); + "kill_inactive_conns_loop" ); } } @@ -3884,8 +3884,8 @@ namespace graphene { namespace net { namespace detail { // our loops now try { - _terminate_inactive_connections_loop_done.cancel_and_wait("node_impl::close()"); - dlog("Terminate inactive connections loop terminated"); + _kill_inactive_conns_loop_done.cancel_and_wait("node_impl::close()"); + dlog("Kill inactive connections loop terminated"); } catch ( const fc::exception& e ) { @@ -4332,7 +4332,7 @@ namespace graphene { namespace net { namespace detail { !_fetch_sync_items_loop_done.valid() && !_fetch_item_loop_done.valid() && !_advertise_inventory_loop_done.valid() && - !_terminate_inactive_connections_loop_done.valid() && + !_kill_inactive_conns_loop_done.valid() && !_fetch_updated_peer_lists_loop_done.valid() && !_bandwidth_monitor_loop_done.valid() && !_dump_node_status_task_done.valid()); @@ -4343,8 +4343,8 @@ namespace graphene { namespace net { namespace detail { _fetch_sync_items_loop_done = fc::async( [=]() { fetch_sync_items_loop(); }, "fetch_sync_items_loop" ); _fetch_item_loop_done = fc::async( [=]() { fetch_items_loop(); }, "fetch_items_loop" ); _advertise_inventory_loop_done = fc::async( [=]() { advertise_inventory_loop(); }, "advertise_inventory_loop" ); - _terminate_inactive_connections_loop_done = fc::async( [=]() { terminate_inactive_connections_loop(self); }, - "terminate_inactive_connections_loop" ); + _kill_inactive_conns_loop_done = fc::async( [=]() { kill_inactive_conns_loop(self); }, + "kill_inactive_conns_loop" ); _fetch_updated_peer_lists_loop_done = fc::async([=](){ fetch_updated_peer_lists_loop(); }, "fetch_updated_peer_lists_loop"); _bandwidth_monitor_loop_done = fc::async([=](){ bandwidth_monitor_loop(); }, "bandwidth_monitor_loop"); diff --git a/libraries/net/node_impl.hxx b/libraries/net/node_impl.hxx index f217ec72f8..8a4ad5fa67 100644 --- a/libraries/net/node_impl.hxx +++ b/libraries/net/node_impl.hxx @@ -351,7 +351,7 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro concurrent_unordered_set _new_inventory; /// @} - fc::future _terminate_inactive_connections_loop_done; + fc::future _kill_inactive_conns_loop_done; uint8_t _recent_block_interval_in_seconds; // a cached copy of the block interval, to avoid a thread hop to the blockchain to get the current value std::string _user_agent_string; @@ -478,7 +478,7 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro void advertise_inventory_loop(); void trigger_advertise_inventory_loop(); - void terminate_inactive_connections_loop(node_impl_ptr self); + void kill_inactive_conns_loop(node_impl_ptr self); void fetch_updated_peer_lists_loop(); void update_bandwidth_data(uint32_t bytes_read_this_second, uint32_t bytes_written_this_second); From 52ebad42a3010385ad8827aaab544e3cdc791724 Mon Sep 17 00:00:00 2001 From: abitmore Date: Wed, 7 Apr 2021 12:28:37 +0000 Subject: [PATCH 112/147] Fix code smells --- .../account_history_plugin.cpp | 12 +++++++----- .../account_history_plugin.hpp | 4 ++-- .../api_helper_indexes/api_helper_indexes.cpp | 11 ++++------- .../api_helper_indexes/api_helper_indexes.hpp | 2 +- .../custom_operations_plugin.cpp | 19 ++++++------------- .../custom_operations_plugin.hpp | 4 ++-- .../delayed_node/delayed_node_plugin.cpp | 13 +++++++------ .../delayed_node/delayed_node_plugin.hpp | 4 ++-- .../elasticsearch/elasticsearch_plugin.cpp | 8 +++----- .../elasticsearch/elasticsearch_plugin.hpp | 2 +- libraries/plugins/es_objects/es_objects.cpp | 8 +++----- .../graphene/es_objects/es_objects.hpp | 6 +++--- .../grouped_orders/grouped_orders_plugin.cpp | 11 +++-------- .../grouped_orders/grouped_orders_plugin.hpp | 3 +-- .../market_history/market_history_plugin.hpp | 3 +-- .../market_history/market_history_plugin.cpp | 15 +++------------ .../template_plugin/template_plugin.hpp | 3 +-- .../template_plugin/template_plugin.cpp | 17 +++++++++++------ 18 files changed, 61 insertions(+), 84 deletions(-) diff --git a/libraries/plugins/account_history/account_history_plugin.cpp b/libraries/plugins/account_history/account_history_plugin.cpp index 19e384a171..dd8a5c6215 100644 --- a/libraries/plugins/account_history/account_history_plugin.cpp +++ b/libraries/plugins/account_history/account_history_plugin.cpp @@ -46,7 +46,7 @@ namespace detail class account_history_plugin_impl { public: - account_history_plugin_impl(account_history_plugin& _plugin) + explicit account_history_plugin_impl(account_history_plugin& _plugin) : _self( _plugin ) { } @@ -60,6 +60,9 @@ class account_history_plugin_impl return _self.database(); } + friend class graphene::account_history::account_history_plugin; + + private: account_history_plugin& _self; flat_set _tracked_accounts; flat_set _extended_history_accounts; @@ -68,7 +71,7 @@ class account_history_plugin_impl primary_index< operation_history_index >* _oho_index; uint64_t _max_ops_per_account = -1; uint64_t _extended_max_ops_per_account = -1; - private: + /** add one history record, then check and remove the earliest history record */ void add_account_history( const account_id_type account_id, const operation_history_id_type op_id ); @@ -279,11 +282,10 @@ account_history_plugin::account_history_plugin(graphene::app::application& app) plugin(app), my( std::make_unique(*this) ) { + // Nothing else to do } -account_history_plugin::~account_history_plugin() -{ -} +account_history_plugin::~account_history_plugin() = default; std::string account_history_plugin::plugin_name()const { diff --git a/libraries/plugins/account_history/include/graphene/account_history/account_history_plugin.hpp b/libraries/plugins/account_history/include/graphene/account_history/account_history_plugin.hpp index 9676869fbf..6ceda572a7 100644 --- a/libraries/plugins/account_history/include/graphene/account_history/account_history_plugin.hpp +++ b/libraries/plugins/account_history/include/graphene/account_history/account_history_plugin.hpp @@ -64,7 +64,7 @@ namespace detail class account_history_plugin : public graphene::app::plugin { public: - account_history_plugin(graphene::app::application& app); + explicit account_history_plugin(graphene::app::application& app); ~account_history_plugin() override; std::string plugin_name()const override; @@ -76,7 +76,7 @@ class account_history_plugin : public graphene::app::plugin flat_set tracked_accounts()const; - friend class detail::account_history_plugin_impl; + private: std::unique_ptr my; }; diff --git a/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp b/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp index 00fbbf3e16..79c996399c 100644 --- a/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp +++ b/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp @@ -133,7 +133,7 @@ namespace detail class api_helper_indexes_impl { public: - api_helper_indexes_impl(api_helper_indexes& _plugin) + explicit api_helper_indexes_impl(api_helper_indexes& _plugin) : _self( _plugin ) { } @@ -142,10 +142,8 @@ class api_helper_indexes_impl return _self.database(); } - api_helper_indexes& _self; - private: - + api_helper_indexes& _self; }; } // end namespace detail @@ -154,11 +152,10 @@ api_helper_indexes::api_helper_indexes(graphene::app::application& app) : plugin(app), my( std::make_unique(*this) ) { + // Nothing else to do } -api_helper_indexes::~api_helper_indexes() -{ -} +api_helper_indexes::~api_helper_indexes() = default; std::string api_helper_indexes::plugin_name()const { diff --git a/libraries/plugins/api_helper_indexes/include/graphene/api_helper_indexes/api_helper_indexes.hpp b/libraries/plugins/api_helper_indexes/include/graphene/api_helper_indexes/api_helper_indexes.hpp index a6bb59b307..bfd7502ab1 100644 --- a/libraries/plugins/api_helper_indexes/include/graphene/api_helper_indexes/api_helper_indexes.hpp +++ b/libraries/plugins/api_helper_indexes/include/graphene/api_helper_indexes/api_helper_indexes.hpp @@ -79,7 +79,7 @@ namespace detail class api_helper_indexes : public graphene::app::plugin { public: - api_helper_indexes(graphene::app::application& app); + explicit api_helper_indexes(graphene::app::application& app); ~api_helper_indexes() override; std::string plugin_name()const override; diff --git a/libraries/plugins/custom_operations/custom_operations_plugin.cpp b/libraries/plugins/custom_operations/custom_operations_plugin.cpp index 1696b98f50..e9fb5b971c 100644 --- a/libraries/plugins/custom_operations/custom_operations_plugin.cpp +++ b/libraries/plugins/custom_operations/custom_operations_plugin.cpp @@ -35,10 +35,9 @@ namespace detail class custom_operations_plugin_impl { public: - custom_operations_plugin_impl(custom_operations_plugin& _plugin) + explicit custom_operations_plugin_impl(custom_operations_plugin& _plugin) : _self( _plugin ) { } - virtual ~custom_operations_plugin_impl(); void onBlock(); @@ -47,12 +46,12 @@ class custom_operations_plugin_impl return _self.database(); } - custom_operations_plugin& _self; - - uint32_t _start_block = 45000000; + friend class graphene::custom_operations::custom_operations_plugin; private: + custom_operations_plugin& _self; + uint32_t _start_block = 45000000; }; struct custom_op_visitor @@ -98,22 +97,16 @@ void custom_operations_plugin_impl::onBlock() } } -custom_operations_plugin_impl::~custom_operations_plugin_impl() -{ - // nothing to do -} - } // end namespace detail custom_operations_plugin::custom_operations_plugin(graphene::app::application& app) : plugin(app), my( std::make_unique(*this) ) { + // Nothing to do } -custom_operations_plugin::~custom_operations_plugin() -{ -} +custom_operations_plugin::~custom_operations_plugin() = default; std::string custom_operations_plugin::plugin_name()const { diff --git a/libraries/plugins/custom_operations/include/graphene/custom_operations/custom_operations_plugin.hpp b/libraries/plugins/custom_operations/include/graphene/custom_operations/custom_operations_plugin.hpp index e2a5fd9633..add8ce8637 100644 --- a/libraries/plugins/custom_operations/include/graphene/custom_operations/custom_operations_plugin.hpp +++ b/libraries/plugins/custom_operations/include/graphene/custom_operations/custom_operations_plugin.hpp @@ -41,7 +41,7 @@ namespace detail class custom_operations_plugin : public graphene::app::plugin { public: - custom_operations_plugin(graphene::app::application& app); + explicit custom_operations_plugin(graphene::app::application& app); ~custom_operations_plugin() override; std::string plugin_name()const override; @@ -52,7 +52,7 @@ class custom_operations_plugin : public graphene::app::plugin void plugin_initialize(const boost::program_options::variables_map& options) override; void plugin_startup() override; - friend class detail::custom_operations_plugin_impl; + private: std::unique_ptr my; }; diff --git a/libraries/plugins/delayed_node/delayed_node_plugin.cpp b/libraries/plugins/delayed_node/delayed_node_plugin.cpp index 18ef6b26b1..b16aadd233 100644 --- a/libraries/plugins/delayed_node/delayed_node_plugin.cpp +++ b/libraries/plugins/delayed_node/delayed_node_plugin.cpp @@ -47,17 +47,18 @@ struct delayed_node_plugin_impl { } delayed_node_plugin::delayed_node_plugin(graphene::app::application& app) : - plugin(app), - my(nullptr) -{} + plugin(app) +{ + // Nothing else to do +} -delayed_node_plugin::~delayed_node_plugin() -{} +delayed_node_plugin::~delayed_node_plugin() = default; void delayed_node_plugin::plugin_set_program_options(bpo::options_description& cli, bpo::options_description& cfg) { cli.add_options() - ("trusted-node", boost::program_options::value(), "RPC endpoint of a trusted validating node (required for delayed_node)") + ("trusted-node", boost::program_options::value(), + "RPC endpoint of a trusted validating node (required for delayed_node)") ; cfg.add(cli); } diff --git a/libraries/plugins/delayed_node/include/graphene/delayed_node/delayed_node_plugin.hpp b/libraries/plugins/delayed_node/include/graphene/delayed_node/delayed_node_plugin.hpp index 4e06c7fcfc..448d979782 100644 --- a/libraries/plugins/delayed_node/include/graphene/delayed_node/delayed_node_plugin.hpp +++ b/libraries/plugins/delayed_node/include/graphene/delayed_node/delayed_node_plugin.hpp @@ -32,12 +32,12 @@ class delayed_node_plugin : public graphene::app::plugin { std::unique_ptr my; public: - delayed_node_plugin(graphene::app::application& app); + explicit delayed_node_plugin(graphene::app::application& app); ~delayed_node_plugin() override; std::string plugin_name()const override { return "delayed_node"; } void plugin_set_program_options(boost::program_options::options_description&, - boost::program_options::options_description& cfg) override; + boost::program_options::options_description& cfg) override; void plugin_initialize(const boost::program_options::variables_map& options) override; void plugin_startup() override; void mainloop(); diff --git a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp index 4eaa6643e9..d583afccc0 100644 --- a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp +++ b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp @@ -36,7 +36,7 @@ namespace detail class elasticsearch_plugin_impl { public: - elasticsearch_plugin_impl(elasticsearch_plugin& _plugin) + explicit elasticsearch_plugin_impl(elasticsearch_plugin& _plugin) : _self( _plugin ) { curl = curl_easy_init(); @@ -102,7 +102,6 @@ elasticsearch_plugin_impl::~elasticsearch_plugin_impl() curl_easy_cleanup(curl); curl = nullptr; } - return; } bool elasticsearch_plugin_impl::update_account_histories( const signed_block& b ) @@ -437,11 +436,10 @@ elasticsearch_plugin::elasticsearch_plugin(graphene::app::application& app) : plugin(app), my( std::make_unique(*this) ) { + // Nothing else to do } -elasticsearch_plugin::~elasticsearch_plugin() -{ -} +elasticsearch_plugin::~elasticsearch_plugin() = default; std::string elasticsearch_plugin::plugin_name()const { diff --git a/libraries/plugins/elasticsearch/include/graphene/elasticsearch/elasticsearch_plugin.hpp b/libraries/plugins/elasticsearch/include/graphene/elasticsearch/elasticsearch_plugin.hpp index 61f385efa0..fbd8366b3f 100644 --- a/libraries/plugins/elasticsearch/include/graphene/elasticsearch/elasticsearch_plugin.hpp +++ b/libraries/plugins/elasticsearch/include/graphene/elasticsearch/elasticsearch_plugin.hpp @@ -55,7 +55,7 @@ enum mode { only_save = 0 , only_query = 1, all = 2 }; class elasticsearch_plugin : public graphene::app::plugin { public: - elasticsearch_plugin(graphene::app::application& app); + explicit elasticsearch_plugin(graphene::app::application& app); ~elasticsearch_plugin() override; std::string plugin_name()const override; diff --git a/libraries/plugins/es_objects/es_objects.cpp b/libraries/plugins/es_objects/es_objects.cpp index e538edd370..2e0fd4613e 100644 --- a/libraries/plugins/es_objects/es_objects.cpp +++ b/libraries/plugins/es_objects/es_objects.cpp @@ -41,7 +41,7 @@ namespace detail class es_objects_plugin_impl { public: - es_objects_plugin_impl(es_objects_plugin& _plugin) + explicit es_objects_plugin_impl(es_objects_plugin& _plugin) : _self( _plugin ) { curl = curl_easy_init(); @@ -269,7 +269,6 @@ es_objects_plugin_impl::~es_objects_plugin_impl() curl_easy_cleanup(curl); curl = nullptr; } - return; } } // end namespace detail @@ -278,11 +277,10 @@ es_objects_plugin::es_objects_plugin(graphene::app::application& app) : plugin(app), my( std::make_unique(*this) ) { + // Nothing else to do } -es_objects_plugin::~es_objects_plugin() -{ -} +es_objects_plugin::~es_objects_plugin() = default; std::string es_objects_plugin::plugin_name()const { diff --git a/libraries/plugins/es_objects/include/graphene/es_objects/es_objects.hpp b/libraries/plugins/es_objects/include/graphene/es_objects/es_objects.hpp index b9bc339681..dff4812498 100644 --- a/libraries/plugins/es_objects/include/graphene/es_objects/es_objects.hpp +++ b/libraries/plugins/es_objects/include/graphene/es_objects/es_objects.hpp @@ -38,8 +38,8 @@ namespace detail class es_objects_plugin : public graphene::app::plugin { public: - es_objects_plugin(graphene::app::application& app); - ~es_objects_plugin(); + explicit es_objects_plugin(graphene::app::application& app); + ~es_objects_plugin() override; std::string plugin_name()const override; std::string plugin_description()const override; @@ -49,7 +49,7 @@ class es_objects_plugin : public graphene::app::plugin void plugin_initialize(const boost::program_options::variables_map& options) override; void plugin_startup() override; - friend class detail::es_objects_plugin_impl; + private: std::unique_ptr my; }; diff --git a/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp b/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp index da655026fd..b745ea494c 100644 --- a/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp +++ b/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp @@ -34,9 +34,8 @@ namespace detail class grouped_orders_plugin_impl { public: - grouped_orders_plugin_impl(grouped_orders_plugin& _plugin) + explicit grouped_orders_plugin_impl(grouped_orders_plugin& _plugin) :_self( _plugin ) {} - virtual ~grouped_orders_plugin_impl(); graphene::chain::database& database() { @@ -235,9 +234,6 @@ void limit_order_group_index::remove_order( const limit_order_object& o, bool re } } -grouped_orders_plugin_impl::~grouped_orders_plugin_impl() -{} - } // end namespace detail @@ -245,11 +241,10 @@ grouped_orders_plugin::grouped_orders_plugin(graphene::app::application& app) : plugin(app), my( std::make_unique(*this) ) { + // Nothing else to do } -grouped_orders_plugin::~grouped_orders_plugin() -{ -} +grouped_orders_plugin::~grouped_orders_plugin() = default; std::string grouped_orders_plugin::plugin_name()const { diff --git a/libraries/plugins/grouped_orders/include/graphene/grouped_orders/grouped_orders_plugin.hpp b/libraries/plugins/grouped_orders/include/graphene/grouped_orders/grouped_orders_plugin.hpp index 637e6e7925..4a0e4452ea 100644 --- a/libraries/plugins/grouped_orders/include/graphene/grouped_orders/grouped_orders_plugin.hpp +++ b/libraries/plugins/grouped_orders/include/graphene/grouped_orders/grouped_orders_plugin.hpp @@ -69,7 +69,7 @@ namespace detail class grouped_orders_plugin : public graphene::app::plugin { public: - grouped_orders_plugin(graphene::app::application& app); + explicit grouped_orders_plugin(graphene::app::application& app); ~grouped_orders_plugin() override; std::string plugin_name()const override; @@ -85,7 +85,6 @@ class grouped_orders_plugin : public graphene::app::plugin const map< limit_order_group_key, limit_order_group_data >& limit_order_groups(); private: - friend class detail::grouped_orders_plugin_impl; std::unique_ptr my; }; diff --git a/libraries/plugins/market_history/include/graphene/market_history/market_history_plugin.hpp b/libraries/plugins/market_history/include/graphene/market_history/market_history_plugin.hpp index 4021dad75e..bc70ae8794 100644 --- a/libraries/plugins/market_history/include/graphene/market_history/market_history_plugin.hpp +++ b/libraries/plugins/market_history/include/graphene/market_history/market_history_plugin.hpp @@ -380,7 +380,7 @@ namespace detail class market_history_plugin : public graphene::app::plugin { public: - market_history_plugin(graphene::app::application& app); + explicit market_history_plugin(graphene::app::application& app); ~market_history_plugin() override; std::string plugin_name()const override; @@ -397,7 +397,6 @@ class market_history_plugin : public graphene::app::plugin uint32_t max_order_his_seconds_per_market()const; private: - friend class detail::market_history_plugin_impl; std::unique_ptr my; }; diff --git a/libraries/plugins/market_history/market_history_plugin.cpp b/libraries/plugins/market_history/market_history_plugin.cpp index f9211d1d36..adca4f5b77 100644 --- a/libraries/plugins/market_history/market_history_plugin.cpp +++ b/libraries/plugins/market_history/market_history_plugin.cpp @@ -43,9 +43,8 @@ namespace detail class market_history_plugin_impl { public: - market_history_plugin_impl(market_history_plugin& _plugin) + explicit market_history_plugin_impl(market_history_plugin& _plugin) :_self( _plugin ) {} - virtual ~market_history_plugin_impl(); /** this method is called as a callback after a block is applied * and will process/index all operations that were applied in the block. @@ -294,9 +293,6 @@ struct operation_process_fill_order } }; -market_history_plugin_impl::~market_history_plugin_impl() -{} - void market_history_plugin_impl::update_market_histories( const signed_block& b ) { graphene::chain::database& db = database(); @@ -731,19 +727,14 @@ void market_history_plugin_impl::update_liquidity_pool_histories( } // end namespace detail - - - - market_history_plugin::market_history_plugin(graphene::app::application& app) : plugin(app), my( std::make_unique(*this) ) { + // Nothing else to do } -market_history_plugin::~market_history_plugin() -{ -} +market_history_plugin::~market_history_plugin() = default; std::string market_history_plugin::plugin_name()const { diff --git a/libraries/plugins/template_plugin/include/graphene/template_plugin/template_plugin.hpp b/libraries/plugins/template_plugin/include/graphene/template_plugin/template_plugin.hpp index 12d4ae4d1e..b9ccee9b79 100644 --- a/libraries/plugins/template_plugin/include/graphene/template_plugin/template_plugin.hpp +++ b/libraries/plugins/template_plugin/include/graphene/template_plugin/template_plugin.hpp @@ -52,7 +52,7 @@ namespace detail class template_plugin : public graphene::app::plugin { public: - template_plugin(graphene::app::application& app); + explicit template_plugin(graphene::app::application& app); ~template_plugin() override; std::string plugin_name()const override; @@ -64,7 +64,6 @@ class template_plugin : public graphene::app::plugin void plugin_startup() override; void plugin_shutdown() override; - friend class detail::template_plugin_impl; private: void cleanup(); std::unique_ptr my; diff --git a/libraries/plugins/template_plugin/template_plugin.cpp b/libraries/plugins/template_plugin/template_plugin.cpp index 3f96a79081..72020a8588 100644 --- a/libraries/plugins/template_plugin/template_plugin.cpp +++ b/libraries/plugins/template_plugin/template_plugin.cpp @@ -32,9 +32,7 @@ namespace detail class template_plugin_impl { public: - template_plugin_impl(template_plugin& _plugin) - : _self( _plugin ) - { } + explicit template_plugin_impl( template_plugin& _plugin ); virtual ~template_plugin_impl(); void on_block( const signed_block& b ); @@ -44,12 +42,13 @@ class template_plugin_impl return _self.database(); } + friend class graphene::template_plugin::template_plugin; + + private: template_plugin& _self; std::string _plugin_option = ""; - private: - }; void template_plugin_impl::on_block( const signed_block& b ) @@ -57,9 +56,15 @@ void template_plugin_impl::on_block( const signed_block& b ) wdump((b.block_num())); } +template_plugin_impl::template_plugin_impl( template_plugin& _plugin ) : + _self( _plugin ) +{ + // Put other code here +} + template_plugin_impl::~template_plugin_impl() { - // Put the real code here + // Put the real code here. If none, remove the destructor. } } // end namespace detail From e2aa835302aae22504382684b6e9c8a6955b2765 Mon Sep 17 00:00:00 2001 From: abitmore Date: Wed, 7 Apr 2021 18:52:27 +0000 Subject: [PATCH 113/147] Rename long function names --- libraries/net/node.cpp | 8 ++++---- libraries/net/node_impl.hxx | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 317a9212c9..5e5559f23c 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -3004,7 +3004,7 @@ namespace graphene { namespace net { namespace detail { "process_backlog_of_sync_blocks" ); } - void node_impl::process_block_during_sync( peer_connection* originating_peer, + void node_impl::process_block_during_syncing( peer_connection* originating_peer, const graphene::net::block_message& block_message_to_process, const message_hash_type& message_hash ) { @@ -3017,7 +3017,7 @@ namespace graphene { namespace net { namespace detail { trigger_process_backlog_of_sync_blocks(); } - void node_impl::process_block_during_normal_operation( peer_connection* originating_peer, + void node_impl::process_block_when_in_sync( peer_connection* originating_peer, const graphene::net::block_message& block_message_to_process, const message_hash_type& message_hash ) { @@ -3191,7 +3191,7 @@ namespace graphene { namespace net { namespace detail { if (item_iter != originating_peer->items_requested_from_peer.end()) { originating_peer->items_requested_from_peer.erase(item_iter); - process_block_during_normal_operation(originating_peer, block_message_to_process, message_hash); + process_block_when_in_sync(originating_peer, block_message_to_process, message_hash); if (originating_peer->idle()) trigger_fetch_items_loop(); return; @@ -3210,7 +3210,7 @@ namespace graphene { namespace net { namespace detail { { originating_peer->last_sync_item_received_time = fc::time_point::now(); _active_sync_requests.erase(block_message_to_process.block_id); - process_block_during_sync(originating_peer, block_message_to_process, message_hash); + process_block_during_syncing(originating_peer, block_message_to_process, message_hash); if (originating_peer->idle()) { // we have finished fetching a batch of items, so we either need to grab another batch of items diff --git a/libraries/net/node_impl.hxx b/libraries/net/node_impl.hxx index 8a4ad5fa67..4cc89d8e0f 100644 --- a/libraries/net/node_impl.hxx +++ b/libraries/net/node_impl.hxx @@ -561,11 +561,11 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro void send_sync_block_to_node_delegate(const graphene::net::block_message& block_message_to_send); void process_backlog_of_sync_blocks(); void trigger_process_backlog_of_sync_blocks(); - void process_block_during_sync( + void process_block_during_syncing( peer_connection* originating_peer, const graphene::net::block_message& block_message, const message_hash_type& message_hash); - void process_block_during_normal_operation( + void process_block_when_in_sync( peer_connection* originating_peer, const graphene::net::block_message& block_message, const message_hash_type& message_hash); From 6a5f57674499a617cbfc0c2405561f5b8efe346d Mon Sep 17 00:00:00 2001 From: abitmore Date: Wed, 7 Apr 2021 19:02:16 +0000 Subject: [PATCH 114/147] Fix code smells --- libraries/net/include/graphene/net/node.hpp | 2 +- libraries/net/node.cpp | 40 +++++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/libraries/net/include/graphene/net/node.hpp b/libraries/net/include/graphene/net/node.hpp index 55d2df782f..98981a7813 100644 --- a/libraries/net/include/graphene/net/node.hpp +++ b/libraries/net/include/graphene/net/node.hpp @@ -194,7 +194,7 @@ namespace graphene { namespace net { void close(); - void set_node_delegate( std::shared_ptr del ); + void set_node_delegate( std::shared_ptr del ) const; void load_configuration( const fc::path& configuration_directory ); diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 5e5559f23c..d3b1129c9e 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -186,7 +186,7 @@ namespace graphene { namespace net { const message_hash_type& message_content_hash ); message get_message( const message_hash_type& hash_of_message_to_lookup ); message_propagation_data get_message_propagation_data( - const message_hash_type& hash_of_message_contents_to_lookup ) const; + const message_hash_type& hash_of_msg_contents_to_lookup ) const; size_t size() const { return _message_cache.size(); } }; @@ -220,12 +220,12 @@ namespace graphene { namespace net { } message_propagation_data blockchain_tied_message_cache::get_message_propagation_data( - const message_hash_type& hash_of_message_contents_to_lookup ) const + const message_hash_type& hash_of_msg_contents_to_lookup ) const { - if( hash_of_message_contents_to_lookup != message_hash_type() ) + if( hash_of_msg_contents_to_lookup != message_hash_type() ) { message_cache_container::index::type::const_iterator iter = - _message_cache.get().find(hash_of_message_contents_to_lookup ); + _message_cache.get().find(hash_of_msg_contents_to_lookup ); if( iter != _message_cache.get().end() ) return iter->propagation_data; } @@ -3000,13 +3000,13 @@ namespace graphene { namespace net { namespace detail { { if (!_node_is_shutting_down && (!_process_backlog_of_sync_blocks_done.valid() || _process_backlog_of_sync_blocks_done.ready())) - _process_backlog_of_sync_blocks_done = fc::async( [=](){ process_backlog_of_sync_blocks(); }, + _process_backlog_of_sync_blocks_done = fc::async( [this](){ process_backlog_of_sync_blocks(); }, "process_backlog_of_sync_blocks" ); } void node_impl::process_block_during_syncing( peer_connection* originating_peer, const graphene::net::block_message& block_message_to_process, - const message_hash_type& message_hash ) + const message_hash_type& ) { VERIFY_CORRECT_THREAD(); dlog( "received a sync block from peer ${endpoint}", ("endpoint", originating_peer->get_remote_endpoint() ) ); @@ -4337,18 +4337,20 @@ namespace graphene { namespace net { namespace detail { !_bandwidth_monitor_loop_done.valid() && !_dump_node_status_task_done.valid()); if (_node_configuration.accept_incoming_connections) - _accept_loop_complete = fc::async( [=](){ accept_loop(); }, "accept_loop"); - - _p2p_network_connect_loop_done = fc::async( [=]() { p2p_network_connect_loop(); }, "p2p_network_connect_loop" ); - _fetch_sync_items_loop_done = fc::async( [=]() { fetch_sync_items_loop(); }, "fetch_sync_items_loop" ); - _fetch_item_loop_done = fc::async( [=]() { fetch_items_loop(); }, "fetch_items_loop" ); - _advertise_inventory_loop_done = fc::async( [=]() { advertise_inventory_loop(); }, "advertise_inventory_loop" ); - _kill_inactive_conns_loop_done = fc::async( [=]() { kill_inactive_conns_loop(self); }, - "kill_inactive_conns_loop" ); - _fetch_updated_peer_lists_loop_done = fc::async([=](){ fetch_updated_peer_lists_loop(); }, - "fetch_updated_peer_lists_loop"); - _bandwidth_monitor_loop_done = fc::async([=](){ bandwidth_monitor_loop(); }, "bandwidth_monitor_loop"); - _dump_node_status_task_done = fc::async([=](){ dump_node_status_task(); }, "dump_node_status_task"); + _accept_loop_complete = fc::async( [this](){ accept_loop(); }, "accept_loop"); + + _p2p_network_connect_loop_done = fc::async( [this]() { p2p_network_connect_loop(); }, + "p2p_network_connect_loop" ); + _fetch_sync_items_loop_done = fc::async( [this]() { fetch_sync_items_loop(); }, "fetch_sync_items_loop" ); + _fetch_item_loop_done = fc::async( [this]() { fetch_items_loop(); }, "fetch_items_loop" ); + _advertise_inventory_loop_done = fc::async( [this]() { advertise_inventory_loop(); }, + "advertise_inventory_loop" ); + _kill_inactive_conns_loop_done = fc::async( [this,self]() { kill_inactive_conns_loop(self); }, + "kill_inactive_conns_loop" ); + _fetch_updated_peer_lists_loop_done = fc::async([this](){ fetch_updated_peer_lists_loop(); }, + "fetch_updated_peer_lists_loop"); + _bandwidth_monitor_loop_done = fc::async([this](){ bandwidth_monitor_loop(); }, "bandwidth_monitor_loop"); + _dump_node_status_task_done = fc::async([this](){ dump_node_status_task(); }, "dump_node_status_task"); schedule_next_update_seed_nodes_task(); } @@ -4925,7 +4927,7 @@ namespace graphene { namespace net { namespace detail { // nothing to do } - void node::set_node_delegate( std::shared_ptr del ) + void node::set_node_delegate( std::shared_ptr del ) const { fc::thread* delegate_thread = &fc::thread::current(); INVOKE_IN_IMPL(set_node_delegate, del, delegate_thread); From 670f70d580c426649b82b1ddb14eff9519dec202 Mon Sep 17 00:00:00 2001 From: abitmore Date: Wed, 7 Apr 2021 22:14:57 +0000 Subject: [PATCH 115/147] Change functions to const, fix code smells --- libraries/app/application.cpp | 21 ++++++++++--------- libraries/app/application_impl.hxx | 8 +++---- .../app/include/graphene/app/application.hpp | 7 ++++--- libraries/app/include/graphene/app/plugin.hpp | 2 +- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 73e3174e82..f8436ec844 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -449,7 +449,7 @@ graphene::chain::genesis_state_type application_impl::initialize_genesis_state() } FC_CAPTURE_AND_RETHROW() } -void application_impl::open_chain_database() +void application_impl::open_chain_database() const { try { fc::create_directories(_data_dir / "blockchain"); @@ -1034,9 +1034,9 @@ void application_impl::enable_plugin( const string& name ) _active_plugins[name] = _available_plugins[name]; } -void application_impl::initialize_plugins() +void application_impl::initialize_plugins() const { - for( auto& entry : _active_plugins ) + for( const auto& entry : _active_plugins ) { ilog( "Initializing plugin ${name}", ( "name", entry.second->plugin_name() ) ); entry.second->plugin_initialize( *_options ); @@ -1044,9 +1044,9 @@ void application_impl::initialize_plugins() } } -void application_impl::startup_plugins() +void application_impl::startup_plugins() const { - for( auto& entry : _active_plugins ) + for( const auto& entry : _active_plugins ) { ilog( "Starting plugin ${name}", ( "name", entry.second->plugin_name() ) ); entry.second->plugin_startup(); @@ -1054,9 +1054,9 @@ void application_impl::startup_plugins() } } -void application_impl::shutdown_plugins() +void application_impl::shutdown_plugins() const { - for( auto& entry : _active_plugins ) + for( const auto& entry : _active_plugins ) { ilog( "Stopping plugin ${name}", ( "name", entry.second->plugin_name() ) ); entry.second->plugin_shutdown(); @@ -1202,7 +1202,8 @@ void application::set_program_options(boost::program_options::options_descriptio configuration_file_options.add(_cfg_options); } -void application::initialize(const fc::path& data_dir, std::shared_ptr options) +void application::initialize(const fc::path& data_dir, + std::shared_ptr options) const { ilog( "Initializing application" ); my->initialize( data_dir, options ); @@ -1276,12 +1277,12 @@ bool application::is_finished_syncing() const return my->_is_finished_syncing; } -void application::enable_plugin(const string& name) +void application::enable_plugin(const string& name) const { my->enable_plugin(name); } -void application::add_available_plugin(std::shared_ptr p) +void application::add_available_plugin(std::shared_ptr p) const { my->add_available_plugin(p); } diff --git a/libraries/app/application_impl.hxx b/libraries/app/application_impl.hxx index 9f42800494..64775cfe0d 100644 --- a/libraries/app/application_impl.hxx +++ b/libraries/app/application_impl.hxx @@ -197,14 +197,14 @@ class application_impl : public net::node_delegate, public std::enable_shared_fr private: void shutdown(); - void initialize_plugins(); - void startup_plugins(); - void shutdown_plugins(); + void initialize_plugins() const; + void startup_plugins() const; + void shutdown_plugins() const; /// Initialize genesis state. Called by @ref open_chain_database. graphene::chain::genesis_state_type initialize_genesis_state() const; /// Open the chain database. Called by @ref startup. - void open_chain_database(); + void open_chain_database() const; friend graphene::app::application; diff --git a/libraries/app/include/graphene/app/application.hpp b/libraries/app/include/graphene/app/application.hpp index 6478a97a31..3b0cbb2808 100644 --- a/libraries/app/include/graphene/app/application.hpp +++ b/libraries/app/include/graphene/app/application.hpp @@ -85,7 +85,8 @@ namespace graphene { namespace app { void set_program_options(boost::program_options::options_description& command_line_options, boost::program_options::options_description& configuration_file_options)const; - void initialize(const fc::path& data_dir, std::shared_ptr options); + void initialize(const fc::path& data_dir, + std::shared_ptr options) const; void startup(); template @@ -139,7 +140,7 @@ namespace graphene { namespace app { const application_options& get_options(); - void enable_plugin( const string& name ); + void enable_plugin( const string& name ) const; bool is_plugin_enabled(const string& name) const; @@ -147,7 +148,7 @@ namespace graphene { namespace app { private: /// Add an available plugin - void add_available_plugin( std::shared_ptr p ); + void add_available_plugin( std::shared_ptr p ) const; std::shared_ptr my; diff --git a/libraries/app/include/graphene/app/plugin.hpp b/libraries/app/include/graphene/app/plugin.hpp index 10a750e28a..cc61aafc27 100644 --- a/libraries/app/include/graphene/app/plugin.hpp +++ b/libraries/app/include/graphene/app/plugin.hpp @@ -114,7 +114,7 @@ class plugin : public abstract_plugin chain::database& database() { return *app().chain_database(); } protected: - net::node_ptr p2p_node() { return app().p2p_node(); } + net::node_ptr p2p_node() const { return app().p2p_node(); } }; /// @ingroup Some useful tools for boost::program_options arguments using vectors of JSON strings From c3b084939a0655d41f9e9f3634b60a786df518e3 Mon Sep 17 00:00:00 2001 From: abitmore Date: Thu, 8 Apr 2021 16:49:47 +0000 Subject: [PATCH 116/147] Replace usage of std::cout and std::cerr by logger --- programs/witness_node/main.cpp | 68 +++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/programs/witness_node/main.cpp b/programs/witness_node/main.cpp index 846d8cd71e..50f1562d63 100644 --- a/programs/witness_node/main.cpp +++ b/programs/witness_node/main.cpp @@ -39,6 +39,8 @@ #include #include #include +#include +#include #include #include @@ -49,7 +51,7 @@ #include #include -#include +#include #ifdef WIN32 # include @@ -59,6 +61,23 @@ namespace bpo = boost::program_options; +/// Disable default logging +void disable_default_logging() +{ + fc::configure_logging( fc::logging_config() ); +} + +/// Hack to log messages to console with default color and no format via fc::console_appender +// TODO fix console_appender and use ilog() or etc instead: 1) stream is always stderr, 2) format can not change +void my_log( const std::string& s ) +{ + static fc::console_appender::config my_console_config; + static fc::console_appender my_appender( my_console_config ); + my_appender.print(s); + my_appender.print("\n"); // This is needed, otherwise the next message will cover it +} + +/// The main program int main(int argc, char** argv) { fc::print_stacktrace_on_segfault(); auto node = std::make_unique(); @@ -114,25 +133,34 @@ int main(int argc, char** argv) { } catch (const boost::program_options::error& e) { - std::cerr << "Error parsing command line: " << e.what() << "\n"; + disable_default_logging(); + std::stringstream ss; + ss << "Error parsing command line: " << e.what(); + my_log( ss.str() ); return EXIT_FAILURE; } if( options.count("version") > 0 ) { - std::cout << "Version: " << graphene::utilities::git_revision_description << "\n"; - std::cout << "SHA: " << graphene::utilities::git_revision_sha << "\n"; - std::cout << "Timestamp: " << fc::get_approximate_relative_time_string(fc::time_point_sec( + disable_default_logging(); + std::stringstream ss; + ss << "Version: " << graphene::utilities::git_revision_description << "\n"; + ss << "SHA: " << graphene::utilities::git_revision_sha << "\n"; + ss << "Timestamp: " << fc::get_approximate_relative_time_string(fc::time_point_sec( graphene::utilities::git_revision_unix_timestamp)) << "\n"; - std::cout << "SSL: " << OPENSSL_VERSION_TEXT << "\n"; - std::cout << "Boost: " << boost::replace_all_copy(std::string(BOOST_LIB_VERSION), "_", ".") << "\n"; - std::cout << "Websocket++: " << websocketpp::major_version << "." << websocketpp::minor_version - << "." << websocketpp::patch_version << "\n"; + ss << "SSL: " << OPENSSL_VERSION_TEXT << "\n"; + ss << "Boost: " << boost::replace_all_copy(std::string(BOOST_LIB_VERSION), "_", ".") << "\n"; + ss << "Websocket++: " << websocketpp::major_version << "." << websocketpp::minor_version + << "." << websocketpp::patch_version; // No end of line in the end + my_log( ss.str() ); return EXIT_SUCCESS; } if( options.count("help") > 0 ) { - std::cout << app_options << "\n"; + disable_default_logging(); + std::stringstream ss; + ss << app_options << "\n"; + my_log( ss.str() ); return EXIT_SUCCESS; } @@ -149,16 +177,22 @@ int main(int argc, char** argv) { boost::split(plugins, options.at("plugins").as(), [](char c){return c == ' ';}); if( plugins.count("account_history") > 0 && plugins.count("elasticsearch") > 0 ) { - std::cerr << "Plugin conflict: Cannot load both account_history plugin and elasticsearch plugin\n"; + disable_default_logging(); + std::stringstream ss; + ss << "Plugin conflict: Cannot load both account_history plugin and elasticsearch plugin"; + my_log( ss.str() ); return EXIT_FAILURE; } if( plugins.count("api_helper_indexes") == 0 && options.count("ignore-api-helper-indexes-warning") == 0 && ( options.count("rpc-endpoint") > 0 || options.count("rpc-tls-endpoint") > 0 ) ) { - std::cerr << "\nIf this is an API node, please enable api_helper_indexes plugin." - "\nIf this is not an API node, please start with \"--ignore-api-helper-indexes-warning\"" - " or enable it in config.ini file.\n\n"; + disable_default_logging(); + std::stringstream ss; + ss << "\nIf this is an API node, please enable api_helper_indexes plugin." + "\nIf this is not an API node, please start with \"--ignore-api-helper-indexes-warning\"" + " or enable it in config.ini file.\n"; + my_log( ss.str() ); return EXIT_FAILURE; } @@ -177,18 +211,18 @@ int main(int argc, char** argv) { fc::promise::ptr exit_promise = fc::promise::create("UNIX Signal Handler"); fc::set_signal_handler([&exit_promise](int the_signal) { - elog( "Caught SIGINT, attempting to exit cleanly" ); + wlog( "Caught SIGINT, attempting to exit cleanly" ); exit_promise->set_value(the_signal); }, SIGINT); fc::set_signal_handler([&exit_promise](int the_signal) { - elog( "Caught SIGTERM, attempting to exit cleanly" ); + wlog( "Caught SIGTERM, attempting to exit cleanly" ); exit_promise->set_value(the_signal); }, SIGTERM); #ifdef SIGQUIT fc::set_signal_handler( [&exit_promise](int the_signal) { - elog( "Caught SIGQUIT, attempting to exit cleanly" ); + wlog( "Caught SIGQUIT, attempting to exit cleanly" ); exit_promise->set_value(the_signal); }, SIGQUIT ); #endif From 6efa4c41cd9d8c5d56422f6a27d658482e0c50bd Mon Sep 17 00:00:00 2001 From: abitmore Date: Thu, 8 Apr 2021 17:08:45 +0000 Subject: [PATCH 117/147] Add tests for program arguments in Github Actions --- .github/workflows/build-and-test.mac.yml | 27 +++++++++++++++++++ .../workflows/build-and-test.ubuntu-debug.yml | 27 +++++++++++++++++++ .../build-and-test.ubuntu-release.yml | 27 +++++++++++++++++++ .github/workflows/sonar-scan.yml | 27 +++++++++++++++++++ 4 files changed, 108 insertions(+) diff --git a/.github/workflows/build-and-test.mac.yml b/.github/workflows/build-and-test.mac.yml index 17c99cf982..ed3874107a 100644 --- a/.github/workflows/build-and-test.mac.yml +++ b/.github/workflows/build-and-test.mac.yml @@ -50,6 +50,33 @@ jobs: libraries/fc/tests/run-parallel-tests.sh _build/tests/chain_test -l test_suite _build/tests/cli_test -l test_suite df -h + - name: Quick test for program arguments + run: | + _build/programs/witness_node/witness_node --version + _build/programs/witness_node/witness_node --help + if _build/programs/witness_node/witness_node --bad-arg ; then \ + echo "Fail: did not get expected error."; false; \ + else \ + echo "Pass: got expected error."; \ + fi + if _build/programs/witness_node/witness_node --plugins "account_history elasticsearch" ; then \ + echo "Fail: did not get expected error."; false; \ + else \ + echo "Pass: got expected error."; \ + fi + if _build/programs/witness_node/witness_node --rpc-endpoint --plugins "witness"; then \ + echo "Fail: did not get expected error."; false; \ + else \ + echo "Pass: got expected error."; \ + fi + _build/programs/cli_wallet/cli_wallet --version + _build/programs/cli_wallet/cli_wallet --help + _build/programs/cli_wallet/cli_wallet --suggest-brain-key + if _build/programs/cli_wallet/cli_wallet --bad-arg ; then \ + echo "Fail: did not get expected error."; false; \ + else \ + echo "Pass: got expected error."; \ + fi - name: Node-Test run: | df -h diff --git a/.github/workflows/build-and-test.ubuntu-debug.yml b/.github/workflows/build-and-test.ubuntu-debug.yml index ddec5bdec3..3a2de40eaa 100644 --- a/.github/workflows/build-and-test.ubuntu-debug.yml +++ b/.github/workflows/build-and-test.ubuntu-debug.yml @@ -104,6 +104,33 @@ jobs: libraries/fc/tests/run-parallel-tests.sh _build/tests/chain_test -l test_suite _build/tests/cli_test -l test_suite df -h + - name: Quick test for program arguments + run: | + _build/programs/witness_node/witness_node --version + _build/programs/witness_node/witness_node --help + if _build/programs/witness_node/witness_node --bad-arg ; then \ + echo "Fail: did not get expected error."; false; \ + else \ + echo "Pass: got expected error."; \ + fi + if _build/programs/witness_node/witness_node --plugins "account_history elasticsearch" ; then \ + echo "Fail: did not get expected error."; false; \ + else \ + echo "Pass: got expected error."; \ + fi + if _build/programs/witness_node/witness_node --rpc-endpoint --plugins "witness"; then \ + echo "Fail: did not get expected error."; false; \ + else \ + echo "Pass: got expected error."; \ + fi + _build/programs/cli_wallet/cli_wallet --version + _build/programs/cli_wallet/cli_wallet --help + _build/programs/cli_wallet/cli_wallet --suggest-brain-key + if _build/programs/cli_wallet/cli_wallet --bad-arg ; then \ + echo "Fail: did not get expected error."; false; \ + else \ + echo "Pass: got expected error."; \ + fi - name: Node-Test run: | df -h diff --git a/.github/workflows/build-and-test.ubuntu-release.yml b/.github/workflows/build-and-test.ubuntu-release.yml index 5f5be7fd12..8f310d8d0a 100644 --- a/.github/workflows/build-and-test.ubuntu-release.yml +++ b/.github/workflows/build-and-test.ubuntu-release.yml @@ -80,6 +80,33 @@ jobs: libraries/fc/tests/run-parallel-tests.sh _build/tests/chain_test -l test_suite _build/tests/cli_test -l test_suite df -h + - name: Quick test for program arguments + run: | + _build/programs/witness_node/witness_node --version + _build/programs/witness_node/witness_node --help + if _build/programs/witness_node/witness_node --bad-arg ; then \ + echo "Fail: did not get expected error."; false; \ + else \ + echo "Pass: got expected error."; \ + fi + if _build/programs/witness_node/witness_node --plugins "account_history elasticsearch" ; then \ + echo "Fail: did not get expected error."; false; \ + else \ + echo "Pass: got expected error."; \ + fi + if _build/programs/witness_node/witness_node --rpc-endpoint --plugins "witness"; then \ + echo "Fail: did not get expected error."; false; \ + else \ + echo "Pass: got expected error."; \ + fi + _build/programs/cli_wallet/cli_wallet --version + _build/programs/cli_wallet/cli_wallet --help + _build/programs/cli_wallet/cli_wallet --suggest-brain-key + if _build/programs/cli_wallet/cli_wallet --bad-arg ; then \ + echo "Fail: did not get expected error."; false; \ + else \ + echo "Pass: got expected error."; \ + fi - name: Node-Test run: | df -h diff --git a/.github/workflows/sonar-scan.yml b/.github/workflows/sonar-scan.yml index e7af75ea45..cda85540b1 100644 --- a/.github/workflows/sonar-scan.yml +++ b/.github/workflows/sonar-scan.yml @@ -129,6 +129,33 @@ jobs: echo "Cleanup" rm -rf /tmp/graphene* df -h + - name: Quick test for program arguments + run: | + _build/programs/witness_node/witness_node --version + _build/programs/witness_node/witness_node --help + if _build/programs/witness_node/witness_node --bad-arg ; then \ + echo "Fail: did not get expected error."; false; \ + else \ + echo "Pass: got expected error."; \ + fi + if _build/programs/witness_node/witness_node --plugins "account_history elasticsearch" ; then \ + echo "Fail: did not get expected error."; false; \ + else \ + echo "Pass: got expected error."; \ + fi + if _build/programs/witness_node/witness_node --rpc-endpoint --plugins "witness"; then \ + echo "Fail: did not get expected error."; false; \ + else \ + echo "Pass: got expected error."; \ + fi + _build/programs/cli_wallet/cli_wallet --version + _build/programs/cli_wallet/cli_wallet --help + _build/programs/cli_wallet/cli_wallet --suggest-brain-key + if _build/programs/cli_wallet/cli_wallet --bad-arg ; then \ + echo "Fail: did not get expected error."; false; \ + else \ + echo "Pass: got expected error."; \ + fi - name: Prepare for scanning with SonarScanner run: | mkdir -p sonar_cache From 0fd484c78b90899403f597660a9106791afc79b0 Mon Sep 17 00:00:00 2001 From: abitmore Date: Mon, 12 Apr 2021 10:53:32 +0000 Subject: [PATCH 118/147] Update wording in comment --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index 91e5a755d7..a3054446ca 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -25,5 +25,5 @@ sonar.cfamily.cache.enabled=true sonar.cfamily.cache.path=sonar_cache # Decide which tree the current build belongs to in SonarCloud. -# Managed by the `set_sonar_branch*` script when building with CI. +# Managed by the `set_sonar_branch*` script(s) when building with CI. sonar.branch.target=develop From 9cdc23d48f06f5e4667554025be27a411b2a37d4 Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 13 Apr 2021 16:14:40 +0000 Subject: [PATCH 119/147] Set program options with a template func in tests --- tests/app/main.cpp | 11 +- tests/cli/main.cpp | 12 +- tests/common/database_fixture.cpp | 159 ++++++++++---------------- tests/common/database_fixture.hpp | 10 +- tests/common/program_options_util.hpp | 39 +++++++ tests/tests/operation_tests2.cpp | 2 +- 6 files changed, 114 insertions(+), 119 deletions(-) create mode 100644 tests/common/program_options_util.hpp diff --git a/tests/app/main.cpp b/tests/app/main.cpp index b07eda1736..328abcfad3 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -46,6 +46,7 @@ #include "../common/init_unit_test_suite.hpp" #include "../common/genesis_file_util.hpp" +#include "../common/program_options_util.hpp" #include "../common/utils.hpp" using namespace graphene; @@ -248,9 +249,9 @@ BOOST_AUTO_TEST_CASE( two_node_network ) app1.register_plugin< graphene::grouped_orders::grouped_orders_plugin>(); auto sharable_cfg = std::make_shared(); auto& cfg = *sharable_cfg; - cfg.emplace("p2p-endpoint", boost::program_options::variable_value(app1_p2p_endpoint_str, false)); - cfg.emplace("genesis-json", boost::program_options::variable_value(genesis_file, false)); - cfg.emplace("seed-nodes", boost::program_options::variable_value(string("[]"), false)); + fc::set_option( cfg, "p2p-endpoint", app1_p2p_endpoint_str ); + fc::set_option( cfg, "genesis-json", genesis_file ); + fc::set_option( cfg, "seed-nodes", string("[]") ); app1.initialize(app_dir.path(), sharable_cfg); BOOST_TEST_MESSAGE( "Starting app1 and waiting" ); app1.startup(); @@ -273,8 +274,8 @@ BOOST_AUTO_TEST_CASE( two_node_network ) app2.register_plugin< graphene::grouped_orders::grouped_orders_plugin>(); auto sharable_cfg2 = std::make_shared(); auto& cfg2 = *sharable_cfg2; - cfg2.emplace("genesis-json", boost::program_options::variable_value(genesis_file, false)); - cfg2.emplace("seed-nodes", boost::program_options::variable_value(app2_seed_nodes_str, false)); + fc::set_option( cfg2, "genesis-json", genesis_file ); + fc::set_option( cfg2, "seed-nodes", app2_seed_nodes_str ); app2.initialize(app2_dir.path(), sharable_cfg2); BOOST_TEST_MESSAGE( "Starting app2 and waiting for connection" ); diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index d5ed125e09..58fba86a05 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -62,6 +62,7 @@ #include "../common/init_unit_test_suite.hpp" #include "../common/genesis_file_util.hpp" +#include "../common/program_options_util.hpp" #include "../common/utils.hpp" #ifdef _WIN32 @@ -107,13 +108,10 @@ std::shared_ptr start_application(fc::temp_directory auto sharable_cfg = std::make_shared(); auto& cfg = *sharable_cfg; server_port_number = fc::network::get_available_port(); - cfg.emplace( - "rpc-endpoint", - boost::program_options::variable_value(string("127.0.0.1:" + std::to_string(server_port_number)), false) - ); - cfg.emplace("genesis-json", boost::program_options::variable_value(create_genesis_file(app_dir), false)); - cfg.emplace("seed-nodes", boost::program_options::variable_value(string("[]"), false)); - cfg.emplace("custom-operations-start-block", boost::program_options::variable_value(uint32_t(1), false)); + fc::set_option( cfg, "rpc-endpoint", string("127.0.0.1:") + std::to_string(server_port_number) ); + fc::set_option( cfg, "genesis-json", create_genesis_file(app_dir) ); + fc::set_option( cfg, "seed-nodes", string("[]") ); + fc::set_option( cfg, "custom-operations-start-block", uint32_t(1) ); app1->initialize(app_dir.path(), sharable_cfg); app1->startup(); diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 847181c5cf..1ad83d031d 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -183,146 +183,127 @@ std::shared_ptr database_fixture_base::in { auto sharable_options = std::make_shared(); auto& options = *sharable_options; - set_option( options, "seed-nodes", std::string("[]") ); // Do not connect to default seed nodes + fc::set_option( options, "seed-nodes", std::string("[]") ); // Do not connect to default seed nodes /** * Test specific settings */ if (fixture.current_test_name == "broadcast_transaction_with_callback_test") - set_option( options, "enable-p2p-network", true ); + fc::set_option( options, "enable-p2p-network", true ); else if (fixture.current_test_name == "broadcast_transaction_disabled_p2p_test") - set_option( options, "enable-p2p-network", false ); + fc::set_option( options, "enable-p2p-network", false ); else if( rand() % 100 >= 50 ) // Disable P2P network randomly for test cases - set_option( options, "enable-p2p-network", false ); + fc::set_option( options, "enable-p2p-network", false ); else if( rand() % 100 >= 50 ) // this should lead to no change - set_option( options, "enable-p2p-network", true ); + fc::set_option( options, "enable-p2p-network", true ); if (fixture.current_test_name == "get_account_history_operations") { - options.insert(std::make_pair("max-ops-per-account", boost::program_options::variable_value((uint64_t)75, false))); + fc::set_option( options, "max-ops-per-account", (uint64_t)75 ); } if (fixture.current_test_name == "api_limit_get_account_history_operations") { - options.insert(std::make_pair("max-ops-per-account", boost::program_options::variable_value((uint64_t)125, false))); - options.insert(std::make_pair("api-limit-get-account-history-operations", boost::program_options::variable_value((uint64_t)300, false))); + fc::set_option( options, "max-ops-per-account", (uint64_t)125 ); + fc::set_option( options, "api-limit-get-account-history-operations", (uint64_t)300 ); } if(fixture.current_test_name =="api_limit_get_account_history") { - options.insert(std::make_pair("max-ops-per-account", boost::program_options::variable_value((uint64_t)125, false))); - options.insert(std::make_pair("api-limit-get-account-history", boost::program_options::variable_value((uint64_t)250, false))); + fc::set_option( options, "max-ops-per-account", (uint64_t)125 ); + fc::set_option( options, "api-limit-get-account-history", (uint64_t)250 ); } if(fixture.current_test_name =="api_limit_get_grouped_limit_orders") { - options.insert(std::make_pair("api-limit-get-grouped-limit-orders", boost::program_options::variable_value((uint64_t)250, false))); + fc::set_option( options, "api-limit-get-grouped-limit-orders", (uint64_t)250 ); } if(fixture.current_test_name =="api_limit_get_relative_account_history") { - options.insert(std::make_pair("max-ops-per-account", boost::program_options::variable_value((uint64_t)125, false))); - options.insert(std::make_pair("api-limit-get-relative-account-history", boost::program_options::variable_value((uint64_t)250, false))); + fc::set_option( options, "max-ops-per-account", (uint64_t)125 ); + fc::set_option( options, "api-limit-get-relative-account-history", (uint64_t)250 ); } if(fixture.current_test_name =="api_limit_get_account_history_by_operations") { - options.insert(std::make_pair("api-limit-get-account-history-by-operations", boost::program_options::variable_value((uint64_t)250, false))); - options.insert(std::make_pair("api-limit-get-relative-account-history", boost::program_options::variable_value((uint64_t)250, false))); + fc::set_option( options, "api-limit-get-account-history-by-operations", (uint64_t)250 ); + fc::set_option( options, "api-limit-get-relative-account-history", (uint64_t)250 ); } if(fixture.current_test_name =="api_limit_get_asset_holders") { - options.insert(std::make_pair("api-limit-get-asset-holders", boost::program_options::variable_value((uint64_t)250, false))); + fc::set_option( options, "api-limit-get-asset-holders", (uint64_t)250 ); } if(fixture.current_test_name =="api_limit_get_key_references") { - options.insert(std::make_pair("api-limit-get-key-references", boost::program_options::variable_value((uint64_t)200, false))); + fc::set_option( options, "api-limit-get-key-references", (uint64_t)200 ); } if(fixture.current_test_name =="api_limit_get_limit_orders") { - options.insert(std::make_pair("api-limit-get-limit-orders", boost::program_options::variable_value( - (uint64_t)350, false))); + fc::set_option( options, "api-limit-get-limit-orders", (uint64_t)350 ); } if(fixture.current_test_name =="api_limit_get_limit_orders_by_account") { - options.insert(std::make_pair("api-limit-get-limit-orders-by-account", boost::program_options::variable_value( - (uint64_t)150, false))); + fc::set_option( options, "api-limit-get-limit-orders-by-account", (uint64_t)150 ); } if(fixture.current_test_name =="api_limit_get_call_orders") { - options.insert(std::make_pair("api-limit-get-call-orders", boost::program_options::variable_value( - (uint64_t)350, false))); + fc::set_option( options, "api-limit-get-call-orders", (uint64_t)350 ); } if(fixture.current_test_name =="api_limit_get_settle_orders") { - options.insert(std::make_pair("api-limit-get-settle-orders", boost::program_options::variable_value( - (uint64_t)350, false))); + fc::set_option( options, "api-limit-get-settle-orders", (uint64_t)350 ); } if(fixture.current_test_name =="api_limit_get_order_book") { - options.insert(std::make_pair("api-limit-get-order-book", boost::program_options::variable_value( - (uint64_t)80, false))); + fc::set_option( options, "api-limit-get-order-book", (uint64_t)80 ); } if(fixture.current_test_name =="api_limit_lookup_accounts") { - options.insert(std::make_pair("api-limit-lookup-accounts", boost::program_options::variable_value - ((uint64_t)200, false))); + fc::set_option( options, "api-limit-lookup-accounts", (uint64_t)200 ); } if(fixture.current_test_name =="api_limit_lookup_witness_accounts") { - options.insert(std::make_pair("api-limit-lookup-witness-accounts", boost::program_options::variable_value - ((uint64_t)200, false))); + fc::set_option( options, "api-limit-lookup-witness-accounts", (uint64_t)200 ); } if(fixture.current_test_name =="api_limit_lookup_committee_member_accounts") { - options.insert(std::make_pair("api-limit-lookup-committee-member-accounts", boost::program_options::variable_value - ((uint64_t)200, false))); + fc::set_option( options, "api-limit-lookup-committee-member-accounts", (uint64_t)200 ); } if(fixture.current_test_name =="api_limit_lookup_committee_member_accounts") { - options.insert(std::make_pair("api-limit-lookup-committee-member-accounts", boost::program_options::variable_value - ((uint64_t)200, false))); + fc::set_option( options, "api-limit-lookup-committee-member-accounts", (uint64_t)200 ); } if(fixture.current_test_name =="api_limit_lookup_vote_ids") { - options.insert(std::make_pair("api-limit-lookup-vote-ids", boost::program_options::variable_value - ((uint64_t)2, false))); + fc::set_option( options, "api-limit-lookup-vote-ids", (uint64_t)2 ); } if(fixture.current_test_name =="api_limit_get_account_limit_orders") { - options.insert(std::make_pair("api-limit-get-account-limit-orders", boost::program_options::variable_value - ((uint64_t)250, false))); + fc::set_option( options, "api-limit-get-account-limit-orders", (uint64_t)250 ); } if(fixture.current_test_name =="api_limit_get_collateral_bids") { - options.insert(std::make_pair("api-limit-get-collateral-bids", boost::program_options::variable_value - ((uint64_t)250, false))); + fc::set_option( options, "api-limit-get-collateral-bids", (uint64_t)250 ); } if(fixture.current_test_name =="api_limit_get_top_markets") { - options.insert(std::make_pair("api-limit-get-top-markets", boost::program_options::variable_value - ((uint64_t)250, false))); + fc::set_option( options, "api-limit-get-top-markets", (uint64_t)250 ); } if(fixture.current_test_name =="api_limit_get_trade_history") { - options.insert(std::make_pair("api-limit-get-trade-history", boost::program_options::variable_value - ((uint64_t)250, false))); + fc::set_option( options, "api-limit-get-trade-history", (uint64_t)250 ); } if(fixture.current_test_name =="api_limit_get_trade_history_by_sequence") { - options.insert(std::make_pair("api-limit-get-trade-history-by-sequence", boost::program_options::variable_value - ((uint64_t)250, false))); + fc::set_option( options, "api-limit-get-trade-history-by-sequence", (uint64_t)250 ); } if(fixture.current_test_name =="api_limit_get_withdraw_permissions_by_giver") { - options.insert(std::make_pair("api-limit-get-withdraw-permissions-by-giver", boost::program_options::variable_value - ((uint64_t)250, false))); + fc::set_option( options, "api-limit-get-withdraw-permissions-by-giver", (uint64_t)250 ); } if(fixture.current_test_name =="api_limit_get_withdraw_permissions_by_recipient") { - options.insert(std::make_pair("api-limit-get-withdraw-permissions-by-recipient", boost::program_options::variable_value - ((uint64_t)250, false))); + fc::set_option( options, "api-limit-get-withdraw-permissions-by-recipient", (uint64_t)250 ); } if(fixture.current_test_name =="api_limit_get_full_accounts2") { - options.insert(std::make_pair("api-limit-get-full-accounts", boost::program_options::variable_value - ((uint64_t)200, false))); - options.insert(std::make_pair("api-limit-get-full-accounts-lists", boost::program_options::variable_value - ((uint64_t)120, false))); + fc::set_option( options, "api-limit-get-full-accounts", (uint64_t)200 ); + fc::set_option( options, "api-limit-get-full-accounts-lists", (uint64_t)120 ); } // add account tracking for ahplugin for special test case with track-account enabled @@ -330,8 +311,8 @@ std::shared_ptr database_fixture_base::in std::vector track_account; std::string track = "\"1.2.17\""; track_account.push_back(track); - options.insert(std::make_pair("track-account", boost::program_options::variable_value(track_account, false))); - options.insert(std::make_pair("partial-operations", boost::program_options::variable_value(true, false))); + fc::set_option( options, "track-account", track_account ); + fc::set_option( options, "partial-operations", true ); } // account tracking 2 accounts if( !options.count("track-account") && fixture.current_test_name == "track_account2") { @@ -340,7 +321,7 @@ std::shared_ptr database_fixture_base::in track_account.push_back(track); track = "\"1.2.16\""; track_account.push_back(track); - options.insert(std::make_pair("track-account", boost::program_options::variable_value(track_account, false))); + fc::set_option( options, "track-account", track_account ); } // standby votes tracking if( fixture.current_test_name == "track_votes_witnesses_disabled" @@ -353,27 +334,18 @@ std::shared_ptr database_fixture_base::in fixture.current_test_name == "elasticsearch_history_api") { fixture.app.register_plugin(true); - options.insert(std::make_pair("elasticsearch-node-url", - boost::program_options::variable_value(GRAPHENE_TESTING_ES_URL, false))); - options.insert(std::make_pair("elasticsearch-bulk-replay", - boost::program_options::variable_value(uint32_t(2), false))); - options.insert(std::make_pair("elasticsearch-bulk-sync", - boost::program_options::variable_value(uint32_t(2), false))); - options.insert(std::make_pair("elasticsearch-start-es-after-block", - boost::program_options::variable_value(uint32_t(0), false))); - options.insert(std::make_pair("elasticsearch-visitor", - boost::program_options::variable_value(false, false))); - options.insert(std::make_pair("elasticsearch-operation-object", - boost::program_options::variable_value(true, false))); - options.insert(std::make_pair("elasticsearch-operation-string", - boost::program_options::variable_value(true, false))); - options.insert(std::make_pair("elasticsearch-mode", - boost::program_options::variable_value(uint16_t(2), false))); + fc::set_option( options, "elasticsearch-node-url", GRAPHENE_TESTING_ES_URL ); + fc::set_option( options, "elasticsearch-bulk-replay", uint32_t(2) ); + fc::set_option( options, "elasticsearch-bulk-sync", uint32_t(2) ); + fc::set_option( options, "elasticsearch-start-es-after-block", uint32_t(0) ); + fc::set_option( options, "elasticsearch-visitor", false ); + fc::set_option( options, "elasticsearch-operation-object", true ); + fc::set_option( options, "elasticsearch-operation-string", true ); + fc::set_option( options, "elasticsearch-mode", uint16_t(2) ); fixture.es_index_prefix = string("bitshares-") + fc::to_string(uint64_t(rand())) + "-"; BOOST_TEST_MESSAGE( string("ES index prefix is ") + fixture.es_index_prefix ); - options.insert(std::make_pair("elasticsearch-index-prefix", - boost::program_options::variable_value(fixture.es_index_prefix, false))); + fc::set_option( options, "elasticsearch-index-prefix", fixture.es_index_prefix ); } else if( fixture.current_suite_name != "performance_tests" ) { @@ -383,29 +355,19 @@ std::shared_ptr database_fixture_base::in if(fixture.current_test_name == "elasticsearch_objects" || fixture.current_test_name == "elasticsearch_suite") { fixture.app.register_plugin(true); - options.insert(std::make_pair("es-objects-elasticsearch-url", - boost::program_options::variable_value(GRAPHENE_TESTING_ES_URL, false))); - options.insert(std::make_pair("es-objects-bulk-replay", - boost::program_options::variable_value(uint32_t(2), false))); - options.insert(std::make_pair("es-objects-bulk-sync", - boost::program_options::variable_value(uint32_t(2), false))); - options.insert(std::make_pair("es-objects-proposals", - boost::program_options::variable_value(true, false))); - options.insert(std::make_pair("es-objects-accounts", - boost::program_options::variable_value(true, false))); - options.insert(std::make_pair("es-objects-assets", - boost::program_options::variable_value(true, false))); - options.insert(std::make_pair("es-objects-balances", - boost::program_options::variable_value(true, false))); - options.insert(std::make_pair("es-objects-limit-orders", - boost::program_options::variable_value(true, false))); - options.insert(std::make_pair("es-objects-asset-bitasset", - boost::program_options::variable_value(true, false))); + fc::set_option( options, "es-objects-elasticsearch-url", GRAPHENE_TESTING_ES_URL ); + fc::set_option( options, "es-objects-bulk-replay", uint32_t(2) ); + fc::set_option( options, "es-objects-bulk-sync", uint32_t(2) ); + fc::set_option( options, "es-objects-proposals", true ); + fc::set_option( options, "es-objects-accounts", true ); + fc::set_option( options, "es-objects-assets", true ); + fc::set_option( options, "es-objects-balances", true ); + fc::set_option( options, "es-objects-limit-orders", true ); + fc::set_option( options, "es-objects-asset-bitasset", true ); fixture.es_obj_index_prefix = string("objects-") + fc::to_string(uint64_t(rand())) + "-"; BOOST_TEST_MESSAGE( string("ES_OBJ index prefix is ") + fixture.es_obj_index_prefix ); - options.insert(std::make_pair("es-objects-index-prefix", - boost::program_options::variable_value(fixture.es_obj_index_prefix, false))); + fc::set_option( options, "es-objects-index-prefix", fixture.es_obj_index_prefix ); } if( fixture.current_test_name == "asset_in_collateral" @@ -420,11 +382,10 @@ std::shared_ptr database_fixture_base::in if(fixture.current_test_name == "custom_operations_account_storage_map_test" || fixture.current_test_name == "custom_operations_account_storage_list_test") { fixture.app.register_plugin(true); - options.insert(std::make_pair("custom-operations-start-block", - boost::program_options::variable_value(uint32_t(1), false))); + fc::set_option( options, "custom-operations-start-block", uint32_t(1) ); } - options.insert(std::make_pair("bucket-size", boost::program_options::variable_value(string("[15]"),false))); + fc::set_option( options, "bucket-size", string("[15]") ); fixture.app.register_plugin(true); fixture.app.register_plugin(true); diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index 5c9f746af4..9658fb4019 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -45,6 +45,8 @@ #include +#include "program_options_util.hpp" + using namespace graphene::db; extern uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP; @@ -226,12 +228,6 @@ struct database_fixture_base { database_fixture_base(); virtual ~database_fixture_base(); - template - static void set_option( boost::program_options::variables_map& options, const std::string& name, const T& value ) - { - options.insert( std::make_pair( name, boost::program_options::variable_value( value, false ) ) ); - } - static void init_genesis( database_fixture_base& fixture ); static std::shared_ptr init_options( database_fixture_base& fixture ); @@ -517,7 +513,7 @@ struct database_fixture_init : database_fixture_base { F::init_genesis( fixture ); fc::json::save_to_file( fixture.genesis_state, fixture.data_dir.path() / "genesis.json" ); auto options = F::init_options( fixture ); - set_option( *options, "genesis-json", boost::filesystem::path(fixture.data_dir.path() / "genesis.json") ); + fc::set_option( *options, "genesis-json", boost::filesystem::path(fixture.data_dir.path() / "genesis.json") ); fixture.app.initialize( fixture.data_dir.path(), options ); fixture.app.startup(); diff --git a/tests/common/program_options_util.hpp b/tests/common/program_options_util.hpp new file mode 100644 index 0000000000..88d3e517c3 --- /dev/null +++ b/tests/common/program_options_util.hpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include + +namespace fc { + + /** + * Set value of a named variable in the program options map if the variable has not been set. + */ + template + static void set_option( boost::program_options::variables_map& options, const std::string& name, const T& value ) + { + options.emplace( name, boost::program_options::variable_value( value, false ) ); + } + +} // namespace fc diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index 26d2215b2d..e972dafac8 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -843,7 +843,7 @@ BOOST_AUTO_TEST_CASE( witness_create ) if( !db.find(wid) ) break; } - options.insert( std::make_pair( "witness-id", boost::program_options::variable_value( witness_ids, false ) ) ); + fc::set_option( options, "witness-id", witness_ids ); wtplugin->plugin_initialize(options); wtplugin->plugin_startup(); From 7b2ea23b9b7c292fa3b10c7307e7ae4880592d92 Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 13 Apr 2021 23:30:28 +0000 Subject: [PATCH 120/147] Fix doxygen docs in node_impl.hxx --- libraries/net/node_impl.hxx | 159 ++++++++++++++++++++++-------------- 1 file changed, 98 insertions(+), 61 deletions(-) diff --git a/libraries/net/node_impl.hxx b/libraries/net/node_impl.hxx index 4cc89d8e0f..3a9701604b 100644 --- a/libraries/net/node_impl.hxx +++ b/libraries/net/node_impl.hxx @@ -22,10 +22,11 @@ private: mutable fc::mutex mux; public: - // iterations require a lock. This exposes the mutex. Use with care (i.e. lock_guard) + /// Iterations require a lock. This exposes the mutex. Use with care (i.e. lock_guard) fc::mutex& get_mutex()const { return mux; } - // insertion + /// Insertion + /// @{ std::pair< typename std::unordered_set::iterator, bool> emplace( Key key) { fc::scoped_lock lock(mux); @@ -36,7 +37,9 @@ public: fc::scoped_lock lock(mux); return std::unordered_set::insert( val ); } - // size + /// @} + /// Size + /// @{ size_t size() const { fc::scoped_lock lock(mux); @@ -47,7 +50,9 @@ public: fc::scoped_lock lock(mux); return std::unordered_set::empty(); } - // removal + /// @} + /// Removal + /// @{ void clear() noexcept { fc::scoped_lock lock(mux); @@ -64,13 +69,17 @@ public: fc::scoped_lock lock(mux); return std::unordered_set::erase( key ); } - // swap + /// @} + /// Swap + /// @{ void swap( typename std::unordered_set& other ) noexcept { fc::scoped_lock lock(mux); std::unordered_set::swap( other ); } - // iteration + /// @} + /// Iteration + /// @{ typename std::unordered_set::iterator begin() noexcept { fc::scoped_lock lock(mux); @@ -111,7 +120,8 @@ public: fc::scoped_lock lock(mux); return std::unordered_set::end(n); } - // search + /// @} + /// Search typename std::unordered_set::const_iterator find(Key key) { fc::scoped_lock lock(mux); @@ -119,13 +129,13 @@ public: } }; -// when requesting items from peers, we want to prioritize any blocks before -// transactions, but otherwise request items in the order we heard about them +/// When requesting items from peers, we want to prioritize any blocks before +/// transactions, but otherwise request items in the order we heard about them struct prioritized_item_id { item_id item; unsigned sequence_number; - fc::time_point timestamp; // the time we last heard about this item in an inventory message + fc::time_point timestamp; ///< the time we last heard about this item in an inventory message prioritized_item_id(const item_id& item, unsigned sequence_number) : item(item), @@ -288,80 +298,94 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro fc::path _node_configuration_directory; node_configuration _node_configuration; - /// stores the endpoint we're listening on. This will be the same as - // _node_configuration.listen_endpoint, unless that endpoint was already - // in use. + /// Stores the endpoint we're listening on. This will be the same as + /// _node_configuration.listen_endpoint, unless that endpoint was already + /// in use. fc::ip::endpoint _actual_listening_endpoint; - /// we determine whether we're firewalled by asking other nodes. Store the result here: + /// We determine whether we're firewalled by asking other nodes. Store the result here. firewalled_state _is_firewalled; - /// if we're behind NAT, our listening endpoint address will appear different to the rest of the world. store it here. + /// If we're behind NAT, our listening endpoint address will appear different to the rest of the world. + /// Store it here. fc::optional _publicly_visible_listening_endpoint; fc::time_point _last_firewall_check_message_sent; - /// used by the task that manages connecting to peers - // @{ - std::list _add_once_node_list; /// list of peers we want to connect to as soon as possible + /// Used by the task that manages connecting to peers + /// @{ + /// List of peers we want to connect to as soon as possible + std::list _add_once_node_list; peer_database _potential_peer_db; fc::promise::ptr _retrigger_connect_loop_promise; bool _potential_peer_database_updated; fc::future _p2p_network_connect_loop_done; - // @} + /// @} - /// used by the task that fetches sync items during synchronization - // @{ + /// Used by the task that fetches sync items during synchronization + /// @{ fc::promise::ptr _retrigger_fetch_sync_items_loop_promise; bool _sync_items_to_fetch_updated; fc::future _fetch_sync_items_loop_done; typedef std::unordered_map active_sync_requests_map; - active_sync_requests_map _active_sync_requests; /// list of sync blocks we've asked for from peers but have not yet received - std::list _new_received_sync_items; /// list of sync blocks we've just received but haven't yet tried to process - std::list _received_sync_items; /// list of sync blocks we've received, but can't yet process because we are still missing blocks that come earlier in the chain - // @} + /// List of sync blocks we've asked for from peers but have not yet received + active_sync_requests_map _active_sync_requests; + /// List of sync blocks we've just received but haven't yet tried to process + std::list _new_received_sync_items; + /// List of sync blocks we've received, but can't yet process because we are still missing blocks + /// that come earlier in the chain + std::list _received_sync_items; + /// @} fc::future _process_backlog_of_sync_blocks_done; bool _suspend_fetching_sync_blocks; - /// used by the task that fetches items during normal operation - // @{ + /// Used by the task that fetches items during normal operation + /// @{ fc::promise::ptr _retrigger_fetch_item_loop_promise; bool _items_to_fetch_updated; fc::future _fetch_item_loop_done; struct item_id_index{}; - typedef boost::multi_index_container >, - boost::multi_index::hashed_unique, - boost::multi_index::member, - std::hash > > - > items_to_fetch_set_type; + using items_to_fetch_set_type = boost::multi_index_container< prioritized_item_id, + boost::multi_index::indexed_by< + boost::multi_index::ordered_unique< boost::multi_index::identity >, + boost::multi_index::hashed_unique< + boost::multi_index::tag, + boost::multi_index::member, + std::hash + > + > + >; unsigned _items_to_fetch_sequence_counter; - items_to_fetch_set_type _items_to_fetch; /// list of items we know another peer has and we want - peer_connection::timestamped_items_set_type _recently_failed_items; /// list of transactions we've recently pushed and had rejected by the delegate - // @} + /// List of items we know another peer has and we want + items_to_fetch_set_type _items_to_fetch; + /// List of transactions we've recently pushed and had rejected by the delegate + peer_connection::timestamped_items_set_type _recently_failed_items; + /// @} - /// used by the task that advertises inventory during normal operation + /// Used by the task that advertises inventory during normal operation /// @{ fc::promise::ptr _retrigger_advertise_inventory_loop_promise; fc::future _advertise_inventory_loop_done; - /// list of items we have received but not yet advertised to our peers + /// List of items we have received but not yet advertised to our peers concurrent_unordered_set _new_inventory; /// @} fc::future _kill_inactive_conns_loop_done; - uint8_t _recent_block_interval_in_seconds; // a cached copy of the block interval, to avoid a thread hop to the blockchain to get the current value + /// A cached copy of the block interval, to avoid a thread hop to the blockchain to get the current value + uint8_t _recent_block_interval_in_seconds; std::string _user_agent_string; - /** _node_public_key is a key automatically generated when the client is first run, stored in + /** + * A key automatically generated when the client is first run, stored in * node_config.json. It doesn't really have much of a purpose yet, there was just some thought * that we might someday have a use for nodes having a private key (sent in hello messages) */ node_id_t _node_public_key; /** - * _node_id is a random number generated each time the client is launched, used to prevent us + * A random number generated each time the client is launched, used to prevent us * from connecting to the same client multiple times (sent in hello messages). * Since this was introduced after the hello_message was finalized, this is sent in the * user_data field. @@ -370,39 +394,46 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro */ node_id_t _node_id; - /** if we have less than `_desired_number_of_connections`, we will try to connect with more nodes */ + /** If we have less than `_desired_number_of_connections`, we will try to connect with more nodes */ uint32_t _desired_number_of_connections; - /** if we have _maximum_number_of_connections or more, we will refuse any inbound connections */ + /** If we have _maximum_number_of_connections or more, we will refuse any inbound connections */ uint32_t _maximum_number_of_connections; - /** retry connections to peers that have failed or rejected us this often, in seconds */ + /** Retry connections to peers that have failed or rejected us this often, in seconds */ uint32_t _peer_connection_retry_timeout; - /** how many seconds of inactivity are permitted before disconnecting a peer */ + /** How many seconds of inactivity are permitted before disconnecting a peer */ uint32_t _peer_inactivity_timeout; fc::tcp_server _tcp_server; fc::future _accept_loop_complete; - /** Stores all connections which have not yet finished key exchange or are still sending initial handshaking messages - * back and forth (not yet ready to initiate syncing) */ + /// Stores all connections which have not yet finished key exchange or are still sending + /// initial handshaking messages back and forth (not yet ready to initiate syncing) concurrent_unordered_set _handshaking_connections; - /** stores fully established connections we're either syncing with or in normal operation with */ + /** Stores fully established connections we're either syncing with or in normal operation with */ concurrent_unordered_set _active_connections; - /** stores connections we've closed (sent closing message, not actually closed), but are still waiting for the remote end to close before we delete them */ + /// Stores connections we've closed (sent closing message, not actually closed), + /// but are still waiting for the remote end to close before we delete them concurrent_unordered_set _closing_connections; - /** stores connections we've closed, but are still waiting for the OS to notify us that the socket is really closed */ + /// Stores connections we've closed, but are still waiting for the OS to notify us that the socket + /// is really closed concurrent_unordered_set _terminating_connections; - boost::circular_buffer _most_recent_blocks_accepted; // the /n/ most recent blocks we've accepted (currently tuned to the max number of connections) + /// The /n/ most recent blocks we've accepted (currently tuned to the max number of connections) + boost::circular_buffer _most_recent_blocks_accepted; uint32_t _sync_item_type; - uint32_t _total_number_of_unfetched_items; /// the number of items we still need to fetch while syncing - std::vector _hard_fork_block_numbers; /// list of all block numbers where there are hard forks + /// The number of items we still need to fetch while syncing + uint32_t _total_number_of_unfetched_items; + /// List of all block numbers where there are hard forks + std::vector _hard_fork_block_numbers; - blockchain_tied_message_cache _message_cache; /// cache message we have received and might be required to provide to other peers via inventory requests + /// Cache message we have received and might be required to provide to other peers via inventory requests + blockchain_tied_message_cache _message_cache; fc::rate_limiting_group _rate_limiter; - uint32_t _last_reported_number_of_connections; // number of connections last reported to the client (to avoid sending duplicate messages) + /// Number of connections last reported to the client (to avoid sending duplicate messages) + uint32_t _last_reported_number_of_connections; bool _peer_advertising_disabled; @@ -422,7 +453,8 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro fc::future _dump_node_status_task_done; - /* We have two alternate paths through the schedule_peer_for_deletion code -- one that + /** + * We have two alternate paths through the schedule_peer_for_deletion code -- one that * uses a mutex to prevent one fiber from adding items to the queue while another is deleting * items from it, and one that doesn't. The one that doesn't is simpler and more efficient * code, but we're keeping around the version that uses the mutex because it crashes, and @@ -430,18 +462,22 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro * fixing. To produce the bug, define USE_PEERS_TO_DELETE_MUTEX and then connect up * to the network and set your desired/max connection counts high */ + /// @{ //#define USE_PEERS_TO_DELETE_MUTEX 1 #ifdef USE_PEERS_TO_DELETE_MUTEX fc::mutex _peers_to_delete_mutex; #endif std::list _peers_to_delete; fc::future _delayed_peer_deletion_task_done; + /// @} #ifdef ENABLE_P2P_DEBUGGING_API std::set _allowed_peers; #endif // ENABLE_P2P_DEBUGGING_API - bool _node_is_shutting_down; // set to true when we begin our destructor, used to prevent us from starting new tasks while we're shutting down + /// Set to true when we begin our destructor, + /// used to prevent us from starting new tasks while we're shutting down + bool _node_is_shutting_down; unsigned _maximum_number_of_blocks_to_handle_at_one_time; unsigned _maximum_number_of_sync_blocks_to_prefetch; @@ -449,13 +485,13 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro std::list > _handle_message_calls_in_progress; - /// used by the task that checks whether addresses of seed nodes have been updated - // @{ + /// Used by the task that checks whether addresses of seed nodes have been updated + /// @{ boost::container::flat_set _seed_nodes; fc::future _update_seed_nodes_loop_done; void update_seed_nodes_task(); void schedule_next_update_seed_nodes_task(); - // @} + /// @} node_impl(const std::string& user_agent); virtual ~node_impl(); @@ -582,7 +618,8 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro void start_synchronizing(); void start_synchronizing_with_peer(const peer_connection_ptr& peer); - void new_peer_just_added(const peer_connection_ptr& peer); /// called after a peer finishes handshaking, kicks off syncing + /// Called after a peer finishes handshaking, kicks off syncing + void new_peer_just_added(const peer_connection_ptr& peer); void close(); From eff5e417c81e93537bf7195b698f66e01527c2b8 Mon Sep 17 00:00:00 2001 From: abitmore Date: Wed, 14 Apr 2021 13:58:21 +0000 Subject: [PATCH 121/147] Rename long variable names --- libraries/net/node.cpp | 35 ++++++++++++++++++----------------- libraries/net/node_impl.hxx | 6 +++--- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index d3b1129c9e..6326324ad4 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -303,16 +303,16 @@ namespace graphene { namespace net { namespace detail { _suspend_fetching_sync_blocks(false), _items_to_fetch_updated(false), _items_to_fetch_sequence_counter(0), - _recent_block_interval_in_seconds(GRAPHENE_MAX_BLOCK_INTERVAL), + _recent_block_interval_seconds(GRAPHENE_MAX_BLOCK_INTERVAL), _user_agent_string(user_agent), _desired_number_of_connections(GRAPHENE_NET_DEFAULT_DESIRED_CONNECTIONS), _maximum_number_of_connections(GRAPHENE_NET_DEFAULT_MAX_CONNECTIONS), _peer_connection_retry_timeout(GRAPHENE_NET_DEFAULT_PEER_CONNECTION_RETRY_TIME), _peer_inactivity_timeout(GRAPHENE_NET_PEER_HANDSHAKE_INACTIVITY_TIMEOUT), _most_recent_blocks_accepted(_maximum_number_of_connections), - _total_number_of_unfetched_items(0), + _total_num_of_unfetched_items(0), _rate_limiter(0, 0), - _last_reported_number_of_connections(0), + _last_reported_number_of_conns(0), _peer_advertising_disabled(false), _average_network_read_speed_seconds(60), _average_network_write_speed_seconds(60), @@ -656,7 +656,8 @@ namespace graphene { namespace net { namespace detail { dlog("beginning an iteration of fetch items (${count} items to fetch)", ("count", _items_to_fetch.size())); - fc::time_point oldest_timestamp_to_fetch = fc::time_point::now() - fc::seconds(_recent_block_interval_in_seconds * GRAPHENE_NET_MESSAGE_CACHE_DURATION_IN_BLOCKS); + fc::time_point oldest_timestamp_to_fetch = fc::time_point::now() + - fc::seconds(_recent_block_interval_seconds * GRAPHENE_NET_MESSAGE_CACHE_DURATION_IN_BLOCKS); fc::time_point next_peer_unblocked_time = fc::time_point::maximum(); // we need to construct a list of items to request from each peer first, @@ -870,7 +871,7 @@ namespace graphene { namespace net { namespace detail { try { // Note: if the node is shutting down, it's possible that _delegate is already unusable, // in this case, we'll get an exception - _recent_block_interval_in_seconds = _delegate->get_current_block_interval_in_seconds(); + _recent_block_interval_seconds = _delegate->get_current_block_interval_in_seconds(); // Disconnect peers that haven't sent us any data recently // These numbers are just guesses and we need to think through how this works better. @@ -912,7 +913,7 @@ namespace graphene { namespace net { namespace detail { } // for } // scoped_lock // timeout for any active peers is two block intervals - uint32_t active_disconnect_timeout = 10 * _recent_block_interval_in_seconds; + uint32_t active_disconnect_timeout = 10 * _recent_block_interval_seconds; uint32_t active_send_keepalive_timeout = active_disconnect_timeout / 2; // set the ignored request time out to 6 second. When we request a block @@ -2171,7 +2172,7 @@ namespace graphene { namespace net { namespace detail { originating_peer->we_need_sync_items_from_peer = false; uint32_t new_number_of_unfetched_items = calculate_unsynced_block_count_from_all_peers(); - _total_number_of_unfetched_items = new_number_of_unfetched_items; + _total_num_of_unfetched_items = new_number_of_unfetched_items; if( new_number_of_unfetched_items == 0 ) _delegate->sync_status( blockchain_item_ids_inventory_message_received.item_type, 0 ); @@ -2291,10 +2292,10 @@ namespace graphene { namespace net { namespace detail { boost::push_back(originating_peer->ids_of_items_to_get, item_hashes_received); uint32_t new_number_of_unfetched_items = calculate_unsynced_block_count_from_all_peers(); - if (new_number_of_unfetched_items != _total_number_of_unfetched_items) + if (new_number_of_unfetched_items != _total_num_of_unfetched_items) _delegate->sync_status(blockchain_item_ids_inventory_message_received.item_type, new_number_of_unfetched_items); - _total_number_of_unfetched_items = new_number_of_unfetched_items; + _total_num_of_unfetched_items = new_number_of_unfetched_items; if (blockchain_item_ids_inventory_message_received.total_remaining_item_count != 0) { @@ -2621,10 +2622,10 @@ namespace graphene { namespace net { namespace detail { trigger_p2p_network_connect_loop(); // notify the node delegate so it can update the display - if( _active_connections.size() != _last_reported_number_of_connections ) + if( _active_connections.size() != _last_reported_number_of_conns ) { - _last_reported_number_of_connections = (uint32_t)_active_connections.size(); - _delegate->connection_count_changed( _last_reported_number_of_connections ); + _last_reported_number_of_conns = (uint32_t)_active_connections.size(); + _delegate->connection_count_changed( _last_reported_number_of_conns ); } // if we had delegated a firewall check to this peer, send it to another peer @@ -2726,9 +2727,9 @@ namespace graphene { namespace net { namespace detail { if( client_accepted_block ) { - --_total_number_of_unfetched_items; + --_total_num_of_unfetched_items; dlog("sync: client accpted the block, we now have only ${count} items left to fetch before we're in sync", - ("count", _total_number_of_unfetched_items)); + ("count", _total_num_of_unfetched_items)); bool is_fork_block = is_hard_fork_block(block_message_to_send.block.block_num()); { fc::scoped_lock lock(_active_connections.get_mutex()); @@ -3629,10 +3630,10 @@ namespace graphene { namespace net { namespace detail { peer->send_message(current_time_request_message(), offsetof(current_time_request_message, request_sent_time)); start_synchronizing_with_peer( peer ); - if( _active_connections.size() != _last_reported_number_of_connections ) + if( _active_connections.size() != _last_reported_number_of_conns ) { - _last_reported_number_of_connections = (uint32_t)_active_connections.size(); - _delegate->connection_count_changed( _last_reported_number_of_connections ); + _last_reported_number_of_conns = (uint32_t)_active_connections.size(); + _delegate->connection_count_changed( _last_reported_number_of_conns ); } } diff --git a/libraries/net/node_impl.hxx b/libraries/net/node_impl.hxx index 3a9701604b..7d6ef71b53 100644 --- a/libraries/net/node_impl.hxx +++ b/libraries/net/node_impl.hxx @@ -375,7 +375,7 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro fc::future _kill_inactive_conns_loop_done; /// A cached copy of the block interval, to avoid a thread hop to the blockchain to get the current value - uint8_t _recent_block_interval_in_seconds; + uint8_t _recent_block_interval_seconds; std::string _user_agent_string; /** @@ -423,7 +423,7 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro uint32_t _sync_item_type; /// The number of items we still need to fetch while syncing - uint32_t _total_number_of_unfetched_items; + uint32_t _total_num_of_unfetched_items; /// List of all block numbers where there are hard forks std::vector _hard_fork_block_numbers; @@ -433,7 +433,7 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro fc::rate_limiting_group _rate_limiter; /// Number of connections last reported to the client (to avoid sending duplicate messages) - uint32_t _last_reported_number_of_connections; + uint32_t _last_reported_number_of_conns; bool _peer_advertising_disabled; From 5f7c987c2c9769fbad85c174a784864a77bd80f8 Mon Sep 17 00:00:00 2001 From: abitmore Date: Thu, 15 Apr 2021 20:56:36 +0000 Subject: [PATCH 122/147] Rename long names, wrap long lines, init in-class --- libraries/net/include/graphene/net/config.hpp | 3 + libraries/net/node.cpp | 156 ++++++++---------- libraries/net/node_impl.hxx | 71 ++++---- 3 files changed, 110 insertions(+), 120 deletions(-) diff --git a/libraries/net/include/graphene/net/config.hpp b/libraries/net/include/graphene/net/config.hpp index a9ca55c9fc..1e1f87a682 100644 --- a/libraries/net/include/graphene/net/config.hpp +++ b/libraries/net/include/graphene/net/config.hpp @@ -110,3 +110,6 @@ #define GRAPHENE_NET_MAX_NESTED_OBJECTS (250) #define MAXIMUM_PEERDB_SIZE 1000 + +#define MAXIMUM_NUMBER_OF_BLOCKS_TO_HANDLE_AT_ONE_TIME 200 +#define MAXIMUM_NUMBER_OF_BLOCKS_TO_PREFETCH (10 * MAXIMUM_NUMBER_OF_BLOCKS_TO_HANDLE_AT_ONE_TIME) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 6326324ad4..25d1e4d5c9 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -289,43 +289,8 @@ namespace graphene { namespace net { namespace detail { # define VERIFY_CORRECT_THREAD() do {} while (0) #endif -#define MAXIMUM_NUMBER_OF_BLOCKS_TO_HANDLE_AT_ONE_TIME 200 -#define MAXIMUM_NUMBER_OF_BLOCKS_TO_PREFETCH (10 * MAXIMUM_NUMBER_OF_BLOCKS_TO_HANDLE_AT_ONE_TIME) - node_impl::node_impl(const std::string& user_agent) : -#ifdef P2P_IN_DEDICATED_THREAD - _thread(std::make_shared("p2p")), -#endif // P2P_IN_DEDICATED_THREAD - _delegate(nullptr), - _is_firewalled(firewalled_state::unknown), - _potential_peer_database_updated(false), - _sync_items_to_fetch_updated(false), - _suspend_fetching_sync_blocks(false), - _items_to_fetch_updated(false), - _items_to_fetch_sequence_counter(0), - _recent_block_interval_seconds(GRAPHENE_MAX_BLOCK_INTERVAL), - _user_agent_string(user_agent), - _desired_number_of_connections(GRAPHENE_NET_DEFAULT_DESIRED_CONNECTIONS), - _maximum_number_of_connections(GRAPHENE_NET_DEFAULT_MAX_CONNECTIONS), - _peer_connection_retry_timeout(GRAPHENE_NET_DEFAULT_PEER_CONNECTION_RETRY_TIME), - _peer_inactivity_timeout(GRAPHENE_NET_PEER_HANDSHAKE_INACTIVITY_TIMEOUT), - _most_recent_blocks_accepted(_maximum_number_of_connections), - _total_num_of_unfetched_items(0), - _rate_limiter(0, 0), - _last_reported_number_of_conns(0), - _peer_advertising_disabled(false), - _average_network_read_speed_seconds(60), - _average_network_write_speed_seconds(60), - _average_network_read_speed_minutes(60), - _average_network_write_speed_minutes(60), - _average_network_read_speed_hours(72), - _average_network_write_speed_hours(72), - _average_network_usage_second_counter(0), - _average_network_usage_minute_counter(0), - _node_is_shutting_down(false), - _maximum_number_of_blocks_to_handle_at_one_time(MAXIMUM_NUMBER_OF_BLOCKS_TO_HANDLE_AT_ONE_TIME), - _maximum_number_of_sync_blocks_to_prefetch(MAXIMUM_NUMBER_OF_BLOCKS_TO_PREFETCH), - _maximum_blocks_per_peer_during_syncing(GRAPHENE_NET_MAX_BLOCKS_PER_PEER_DURING_SYNCING) + _user_agent_string(user_agent) { _rate_limiter.set_actual_rate_time_constant(fc::seconds(2)); fc::rand_bytes((char*) _node_id.data(), (int)_node_id.size()); @@ -600,7 +565,7 @@ namespace graphene { namespace net { namespace detail { // then schedule a request from this peer sync_item_requests_to_send[peer].push_back(item_to_potentially_request); sync_items_to_request.insert( item_to_potentially_request ); - if (sync_item_requests_to_send[peer].size() >= _maximum_blocks_per_peer_during_syncing) + if (sync_item_requests_to_send[peer].size() >= _max_sync_blocks_per_peer) break; } } @@ -1138,24 +1103,28 @@ namespace graphene { namespace net { namespace detail { void node_impl::update_bandwidth_data(uint32_t bytes_read_this_second, uint32_t bytes_written_this_second) { VERIFY_CORRECT_THREAD(); - _average_network_read_speed_seconds.push_back(bytes_read_this_second); - _average_network_write_speed_seconds.push_back(bytes_written_this_second); - ++_average_network_usage_second_counter; - if (_average_network_usage_second_counter >= 60) - { - _average_network_usage_second_counter = 0; - ++_average_network_usage_minute_counter; - uint32_t average_read_this_minute = (uint32_t)boost::accumulate(_average_network_read_speed_seconds, uint64_t(0)) / (uint32_t)_average_network_read_speed_seconds.size(); - _average_network_read_speed_minutes.push_back(average_read_this_minute); - uint32_t average_written_this_minute = (uint32_t)boost::accumulate(_average_network_write_speed_seconds, uint64_t(0)) / (uint32_t)_average_network_write_speed_seconds.size(); - _average_network_write_speed_minutes.push_back(average_written_this_minute); - if (_average_network_usage_minute_counter >= 60) + _avg_net_read_speed_seconds.push_back(bytes_read_this_second); + _avg_net_write_speed_seconds.push_back(bytes_written_this_second); + ++_avg_net_usage_second_counter; + if (_avg_net_usage_second_counter >= 60) + { + _avg_net_usage_second_counter = 0; + ++_avg_net_usage_minute_counter; + uint32_t average_read_this_minute = (uint32_t)boost::accumulate(_avg_net_read_speed_seconds, uint64_t(0)) + / (uint32_t)_avg_net_read_speed_seconds.size(); + _avg_net_read_speed_minutes.push_back(average_read_this_minute); + uint32_t average_written_this_minute = (uint32_t)boost::accumulate(_avg_net_write_speed_seconds, uint64_t(0)) + / (uint32_t)_avg_net_write_speed_seconds.size(); + _avg_net_write_speed_minutes.push_back(average_written_this_minute); + if (_avg_net_usage_minute_counter >= 60) { - _average_network_usage_minute_counter = 0; - uint32_t average_read_this_hour = (uint32_t)boost::accumulate(_average_network_read_speed_minutes, uint64_t(0)) / (uint32_t)_average_network_read_speed_minutes.size(); - _average_network_read_speed_hours.push_back(average_read_this_hour); - uint32_t average_written_this_hour = (uint32_t)boost::accumulate(_average_network_write_speed_minutes, uint64_t(0)) / (uint32_t)_average_network_write_speed_minutes.size(); - _average_network_write_speed_hours.push_back(average_written_this_hour); + _avg_net_usage_minute_counter = 0; + uint32_t average_read_this_hour = (uint32_t)boost::accumulate(_avg_net_read_speed_minutes, uint64_t(0)) + / (uint32_t)_avg_net_read_speed_minutes.size(); + _avg_net_read_speed_hours.push_back(average_read_this_hour); + uint32_t average_written_this_hour = (uint32_t)boost::accumulate(_avg_net_write_speed_minutes, uint64_t(0)) + / (uint32_t)_avg_net_write_speed_minutes.size(); + _avg_net_write_speed_hours.push_back(average_written_this_hour); } } } @@ -2845,7 +2814,8 @@ namespace graphene { namespace net { namespace detail { dlog("Leaving send_sync_block_to_node_delegate"); - if (// _suspend_fetching_sync_blocks && <-- you can use this if "maximum_number_of_blocks_to_handle_at_one_time" == "maximum_number_of_sync_blocks_to_prefetch" + if (// _suspend_fetching_sync_blocks && <-- you can use this if + // "max_blocks_to_handle_at_once" == "max_sync_blocks_to_prefetch" !_node_is_shutting_down && (!_process_backlog_of_sync_blocks_done.valid() || _process_backlog_of_sync_blocks_done.ready())) _process_backlog_of_sync_blocks_done = fc::async([=](){ process_backlog_of_sync_blocks(); }, @@ -2866,7 +2836,7 @@ namespace graphene { namespace net { namespace detail { } dlog("in process_backlog_of_sync_blocks"); - if (_handle_message_calls_in_progress.size() >= _maximum_number_of_blocks_to_handle_at_one_time) + if (_handle_message_calls_in_progress.size() >= _max_blocks_to_handle_at_once) { dlog("leaving process_backlog_of_sync_blocks because we're already processing too many blocks"); return; // we will be rescheduled when the next block finishes its processing @@ -2979,13 +2949,13 @@ namespace graphene { namespace net { namespace detail { } // end if potential_first_block } // end for each block in _received_sync_items - if (_handle_message_calls_in_progress.size() >= _maximum_number_of_blocks_to_handle_at_one_time) + if (_handle_message_calls_in_progress.size() >= _max_blocks_to_handle_at_once) { dlog("stopping processing sync block backlog because we have ${count} blocks in progress", ("count", _handle_message_calls_in_progress.size())); //ulog("stopping processing sync block backlog because we have ${count} blocks in progress, total on hand: ${received}", // ("count", _handle_message_calls_in_progress.size())("received", _received_sync_items.size())); - if (_received_sync_items.size() >= _maximum_number_of_sync_blocks_to_prefetch) + if (_received_sync_items.size() >= _max_sync_blocks_to_prefetch) _suspend_fetching_sync_blocks = true; break; } @@ -3456,22 +3426,27 @@ namespace graphene { namespace net { namespace detail { VERIFY_CORRECT_THREAD(); get_current_connections_reply_message reply; - if (!_average_network_read_speed_minutes.empty()) + if (!_avg_net_read_speed_minutes.empty()) { - reply.upload_rate_one_minute = _average_network_write_speed_minutes.back(); - reply.download_rate_one_minute = _average_network_read_speed_minutes.back(); + reply.upload_rate_one_minute = _avg_net_write_speed_minutes.back(); + reply.download_rate_one_minute = _avg_net_read_speed_minutes.back(); - size_t minutes_to_average = std::min(_average_network_write_speed_minutes.size(), (size_t)15); - boost::circular_buffer::iterator start_iter = _average_network_write_speed_minutes.end() - minutes_to_average; - reply.upload_rate_fifteen_minutes = std::accumulate(start_iter, _average_network_write_speed_minutes.end(), 0) / (uint32_t)minutes_to_average; - start_iter = _average_network_read_speed_minutes.end() - minutes_to_average; - reply.download_rate_fifteen_minutes = std::accumulate(start_iter, _average_network_read_speed_minutes.end(), 0) / (uint32_t)minutes_to_average; + size_t minutes_to_average = std::min(_avg_net_write_speed_minutes.size(), (size_t)15); + boost::circular_buffer::iterator start_iter = _avg_net_write_speed_minutes.end() + - minutes_to_average; + reply.upload_rate_fifteen_minutes = std::accumulate(start_iter, _avg_net_write_speed_minutes.end(), 0) + / (uint32_t)minutes_to_average; + start_iter = _avg_net_read_speed_minutes.end() - minutes_to_average; + reply.download_rate_fifteen_minutes = std::accumulate(start_iter, _avg_net_read_speed_minutes.end(), 0) + / (uint32_t)minutes_to_average; - minutes_to_average = std::min(_average_network_write_speed_minutes.size(), (size_t)60); - start_iter = _average_network_write_speed_minutes.end() - minutes_to_average; - reply.upload_rate_one_hour = std::accumulate(start_iter, _average_network_write_speed_minutes.end(), 0) / (uint32_t)minutes_to_average; - start_iter = _average_network_read_speed_minutes.end() - minutes_to_average; - reply.download_rate_one_hour = std::accumulate(start_iter, _average_network_read_speed_minutes.end(), 0) / (uint32_t)minutes_to_average; + minutes_to_average = std::min(_avg_net_write_speed_minutes.size(), (size_t)60); + start_iter = _avg_net_write_speed_minutes.end() - minutes_to_average; + reply.upload_rate_one_hour = std::accumulate(start_iter, _avg_net_write_speed_minutes.end(), 0) + / (uint32_t)minutes_to_average; + start_iter = _avg_net_read_speed_minutes.end() - minutes_to_average; + reply.download_rate_one_hour = std::accumulate(start_iter, _avg_net_read_speed_minutes.end(), 0) + / (uint32_t)minutes_to_average; } fc::time_point now = fc::time_point::now(); @@ -3479,7 +3454,8 @@ namespace graphene { namespace net { namespace detail { for (const peer_connection_ptr& peer : _active_connections) { current_connection_data data_for_this_peer; - data_for_this_peer.connection_duration = now.sec_since_epoch() - peer->connection_initiation_time.sec_since_epoch(); + data_for_this_peer.connection_duration = now.sec_since_epoch() + - peer->connection_initiation_time.sec_since_epoch(); if (peer->get_remote_endpoint()) // should always be set for anyone we're actively connected to data_for_this_peer.remote_endpoint = *peer->get_remote_endpoint(); data_for_this_peer.clock_offset = peer->clock_offset; @@ -4762,12 +4738,12 @@ namespace graphene { namespace net { namespace detail { _desired_number_of_connections = params["desired_number_of_connections"].as(1); if (params.contains("maximum_number_of_connections")) _maximum_number_of_connections = params["maximum_number_of_connections"].as(1); - if (params.contains("maximum_number_of_blocks_to_handle_at_one_time")) - _maximum_number_of_blocks_to_handle_at_one_time = params["maximum_number_of_blocks_to_handle_at_one_time"].as(1); - if (params.contains("maximum_number_of_sync_blocks_to_prefetch")) - _maximum_number_of_sync_blocks_to_prefetch = params["maximum_number_of_sync_blocks_to_prefetch"].as(1); - if (params.contains("maximum_blocks_per_peer_during_syncing")) - _maximum_blocks_per_peer_during_syncing = params["maximum_blocks_per_peer_during_syncing"].as(1); + if (params.contains("max_blocks_to_handle_at_once")) + _max_blocks_to_handle_at_once = params["max_blocks_to_handle_at_once"].as(1); + if (params.contains("max_sync_blocks_to_prefetch")) + _max_sync_blocks_to_prefetch = params["max_sync_blocks_to_prefetch"].as(1); + if (params.contains("max_sync_blocks_per_peer")) + _max_sync_blocks_per_peer = params["max_sync_blocks_per_peer"].as(1); _desired_number_of_connections = std::min(_desired_number_of_connections, _maximum_number_of_connections); @@ -4784,9 +4760,9 @@ namespace graphene { namespace net { namespace detail { result["peer_connection_retry_timeout"] = _peer_connection_retry_timeout; result["desired_number_of_connections"] = _desired_number_of_connections; result["maximum_number_of_connections"] = _maximum_number_of_connections; - result["maximum_number_of_blocks_to_handle_at_one_time"] = _maximum_number_of_blocks_to_handle_at_one_time; - result["maximum_number_of_sync_blocks_to_prefetch"] = _maximum_number_of_sync_blocks_to_prefetch; - result["maximum_blocks_per_peer_during_syncing"] = _maximum_blocks_per_peer_during_syncing; + result["max_blocks_to_handle_at_once"] = _max_blocks_to_handle_at_once; + result["max_sync_blocks_to_prefetch"] = _max_sync_blocks_to_prefetch; + result["max_sync_blocks_per_peer"] = _max_sync_blocks_per_peer; return result; } @@ -4864,23 +4840,23 @@ namespace graphene { namespace net { namespace detail { { VERIFY_CORRECT_THREAD(); std::vector network_usage_by_second; - network_usage_by_second.reserve(_average_network_read_speed_seconds.size()); - std::transform(_average_network_read_speed_seconds.begin(), _average_network_read_speed_seconds.end(), - _average_network_write_speed_seconds.begin(), + network_usage_by_second.reserve(_avg_net_read_speed_seconds.size()); + std::transform(_avg_net_read_speed_seconds.begin(), _avg_net_read_speed_seconds.end(), + _avg_net_write_speed_seconds.begin(), std::back_inserter(network_usage_by_second), std::plus()); std::vector network_usage_by_minute; - network_usage_by_minute.reserve(_average_network_read_speed_minutes.size()); - std::transform(_average_network_read_speed_minutes.begin(), _average_network_read_speed_minutes.end(), - _average_network_write_speed_minutes.begin(), + network_usage_by_minute.reserve(_avg_net_read_speed_minutes.size()); + std::transform(_avg_net_read_speed_minutes.begin(), _avg_net_read_speed_minutes.end(), + _avg_net_write_speed_minutes.begin(), std::back_inserter(network_usage_by_minute), std::plus()); std::vector network_usage_by_hour; - network_usage_by_hour.reserve(_average_network_read_speed_hours.size()); - std::transform(_average_network_read_speed_hours.begin(), _average_network_read_speed_hours.end(), - _average_network_write_speed_hours.begin(), + network_usage_by_hour.reserve(_avg_net_read_speed_hours.size()); + std::transform(_avg_net_read_speed_hours.begin(), _avg_net_read_speed_hours.end(), + _avg_net_write_speed_hours.begin(), std::back_inserter(network_usage_by_hour), std::plus()); diff --git a/libraries/net/node_impl.hxx b/libraries/net/node_impl.hxx index 7d6ef71b53..bce85f45e8 100644 --- a/libraries/net/node_impl.hxx +++ b/libraries/net/node_impl.hxx @@ -288,7 +288,7 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro { public: #ifdef P2P_IN_DEDICATED_THREAD - std::shared_ptr _thread; + std::shared_ptr _thread = std::make_shared("p2p"); #endif // P2P_IN_DEDICATED_THREAD std::unique_ptr _delegate; fc::sha256 _chain_id; @@ -304,7 +304,7 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro fc::ip::endpoint _actual_listening_endpoint; /// We determine whether we're firewalled by asking other nodes. Store the result here. - firewalled_state _is_firewalled; + firewalled_state _is_firewalled = firewalled_state::unknown; /// If we're behind NAT, our listening endpoint address will appear different to the rest of the world. /// Store it here. fc::optional _publicly_visible_listening_endpoint; @@ -317,14 +317,14 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro peer_database _potential_peer_db; fc::promise::ptr _retrigger_connect_loop_promise; - bool _potential_peer_database_updated; + bool _potential_peer_database_updated = false; fc::future _p2p_network_connect_loop_done; /// @} /// Used by the task that fetches sync items during synchronization /// @{ fc::promise::ptr _retrigger_fetch_sync_items_loop_promise; - bool _sync_items_to_fetch_updated; + bool _sync_items_to_fetch_updated = false; fc::future _fetch_sync_items_loop_done; typedef std::unordered_map active_sync_requests_map; @@ -339,12 +339,12 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro /// @} fc::future _process_backlog_of_sync_blocks_done; - bool _suspend_fetching_sync_blocks; + bool _suspend_fetching_sync_blocks = false; /// Used by the task that fetches items during normal operation /// @{ fc::promise::ptr _retrigger_fetch_item_loop_promise; - bool _items_to_fetch_updated; + bool _items_to_fetch_updated = false; fc::future _fetch_item_loop_done; struct item_id_index{}; @@ -358,7 +358,7 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro > > >; - unsigned _items_to_fetch_sequence_counter; + size_t _items_to_fetch_sequence_counter = 0; /// List of items we know another peer has and we want items_to_fetch_set_type _items_to_fetch; /// List of transactions we've recently pushed and had rejected by the delegate @@ -375,7 +375,7 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro fc::future _kill_inactive_conns_loop_done; /// A cached copy of the block interval, to avoid a thread hop to the blockchain to get the current value - uint8_t _recent_block_interval_seconds; + uint8_t _recent_block_interval_seconds = GRAPHENE_MAX_BLOCK_INTERVAL; std::string _user_agent_string; /** @@ -395,13 +395,13 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro node_id_t _node_id; /** If we have less than `_desired_number_of_connections`, we will try to connect with more nodes */ - uint32_t _desired_number_of_connections; + uint32_t _desired_number_of_connections = GRAPHENE_NET_DEFAULT_DESIRED_CONNECTIONS; /** If we have _maximum_number_of_connections or more, we will refuse any inbound connections */ - uint32_t _maximum_number_of_connections; + uint32_t _maximum_number_of_connections = GRAPHENE_NET_DEFAULT_MAX_CONNECTIONS; /** Retry connections to peers that have failed or rejected us this often, in seconds */ - uint32_t _peer_connection_retry_timeout; + uint32_t _peer_connection_retry_timeout = GRAPHENE_NET_DEFAULT_PEER_CONNECTION_RETRY_TIME; /** How many seconds of inactivity are permitted before disconnecting a peer */ - uint32_t _peer_inactivity_timeout; + uint32_t _peer_inactivity_timeout = GRAPHENE_NET_PEER_HANDSHAKE_INACTIVITY_TIMEOUT; fc::tcp_server _tcp_server; fc::future _accept_loop_complete; @@ -419,34 +419,42 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro concurrent_unordered_set _terminating_connections; /// The /n/ most recent blocks we've accepted (currently tuned to the max number of connections) - boost::circular_buffer _most_recent_blocks_accepted; + boost::circular_buffer _most_recent_blocks_accepted { _maximum_number_of_connections }; uint32_t _sync_item_type; /// The number of items we still need to fetch while syncing - uint32_t _total_num_of_unfetched_items; + uint32_t _total_num_of_unfetched_items = 0; /// List of all block numbers where there are hard forks std::vector _hard_fork_block_numbers; /// Cache message we have received and might be required to provide to other peers via inventory requests blockchain_tied_message_cache _message_cache; - fc::rate_limiting_group _rate_limiter; + fc::rate_limiting_group _rate_limiter { 0, 0 }; /// Number of connections last reported to the client (to avoid sending duplicate messages) - uint32_t _last_reported_number_of_conns; + uint32_t _last_reported_number_of_conns = 0; - bool _peer_advertising_disabled; + bool _peer_advertising_disabled = false; fc::future _fetch_updated_peer_lists_loop_done; - boost::circular_buffer _average_network_read_speed_seconds; - boost::circular_buffer _average_network_write_speed_seconds; - boost::circular_buffer _average_network_read_speed_minutes; - boost::circular_buffer _average_network_write_speed_minutes; - boost::circular_buffer _average_network_read_speed_hours; - boost::circular_buffer _average_network_write_speed_hours; - unsigned _average_network_usage_second_counter; - unsigned _average_network_usage_minute_counter; + /// Average network read speed in the past seconds + boost::circular_buffer _avg_net_read_speed_seconds { 60 }; + /// Average network write speed in the past seconds + boost::circular_buffer _avg_net_write_speed_seconds { 60 }; + /// Average network read speed in the past minutes + boost::circular_buffer _avg_net_read_speed_minutes { 60 }; + /// Average network write speed in the past minutes + boost::circular_buffer _avg_net_write_speed_minutes { 60 }; + /// Average network read speed in the past hours + boost::circular_buffer _avg_net_read_speed_hours { 72 }; + /// Average network write speed in the past hours + boost::circular_buffer _avg_net_write_speed_hours { 72 }; + /// Average network usage second counter + size_t _avg_net_usage_second_counter = 0; + /// Average network usage minute counter + size_t _avg_net_usage_minute_counter = 0; fc::time_point_sec _bandwidth_monitor_last_update_time; fc::future _bandwidth_monitor_loop_done; @@ -477,11 +485,14 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro /// Set to true when we begin our destructor, /// used to prevent us from starting new tasks while we're shutting down - bool _node_is_shutting_down; - - unsigned _maximum_number_of_blocks_to_handle_at_one_time; - unsigned _maximum_number_of_sync_blocks_to_prefetch; - unsigned _maximum_blocks_per_peer_during_syncing; + bool _node_is_shutting_down = false; + + /// Maximum number of blocks to handle at one time + size_t _max_blocks_to_handle_at_once = MAXIMUM_NUMBER_OF_BLOCKS_TO_HANDLE_AT_ONE_TIME; + /// Maximum number of sync blocks to prefetch + size_t _max_sync_blocks_to_prefetch = MAXIMUM_NUMBER_OF_BLOCKS_TO_PREFETCH; + /// Maximum number of blocks per peer during syncing + size_t _max_sync_blocks_per_peer = GRAPHENE_NET_MAX_BLOCKS_PER_PEER_DURING_SYNCING; std::list > _handle_message_calls_in_progress; From 519343ea3d504a31afc6f63d77ff2bd7a02fa070 Mon Sep 17 00:00:00 2001 From: abitmore Date: Thu, 15 Apr 2021 23:33:58 +0000 Subject: [PATCH 123/147] Fix code smells --- libraries/net/include/graphene/net/config.hpp | 6 ++- libraries/net/node.cpp | 52 +++++++++++-------- libraries/net/node_impl.hxx | 15 +++--- 3 files changed, 41 insertions(+), 32 deletions(-) diff --git a/libraries/net/include/graphene/net/config.hpp b/libraries/net/include/graphene/net/config.hpp index 1e1f87a682..5e333b805c 100644 --- a/libraries/net/include/graphene/net/config.hpp +++ b/libraries/net/include/graphene/net/config.hpp @@ -23,6 +23,8 @@ */ #pragma once +#include + #define GRAPHENE_NET_PROTOCOL_VERSION 106 /** @@ -111,5 +113,5 @@ #define MAXIMUM_PEERDB_SIZE 1000 -#define MAXIMUM_NUMBER_OF_BLOCKS_TO_HANDLE_AT_ONE_TIME 200 -#define MAXIMUM_NUMBER_OF_BLOCKS_TO_PREFETCH (10 * MAXIMUM_NUMBER_OF_BLOCKS_TO_HANDLE_AT_ONE_TIME) +constexpr size_t MAX_BLOCKS_TO_HANDLE_AT_ONCE = 200; +constexpr size_t MAX_SYNC_BLOCKS_TO_PREFETCH = 10 * MAX_BLOCKS_TO_HANDLE_AT_ONCE; diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 25d1e4d5c9..9c232a3f41 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -99,12 +99,12 @@ #define P2P_IN_DEDICATED_THREAD 1 #define INVOCATION_COUNTER(name) \ - static unsigned total_ ## name ## _counter = 0; \ - static unsigned active_ ## name ## _counter = 0; \ + static size_t total_ ## name ## _counter = 0; \ + static size_t active_ ## name ## _counter = 0; \ struct name ## _invocation_logger { \ - unsigned *total; \ - unsigned *active; \ - name ## _invocation_logger(unsigned *total, unsigned *active) : \ + size_t *total; \ + size_t *active; \ + name ## _invocation_logger(size_t *total, size_t *active) : \ total(total), active(active) \ { \ ++*total; \ @@ -388,7 +388,7 @@ namespace graphene { namespace net { namespace detail { while (is_wanting_new_connections()) { bool initiated_connection_this_pass = false; - _potential_peer_database_updated = false; + _potential_peer_db_updated = false; for (peer_database::iterator iter = _potential_peer_db.begin(); iter != _potential_peer_db.end() && is_wanting_new_connections(); @@ -407,7 +407,7 @@ namespace graphene { namespace net { namespace detail { } } - if (!initiated_connection_this_pass && !_potential_peer_database_updated) + if (!initiated_connection_this_pass && !_potential_peer_db_updated) break; } @@ -452,7 +452,7 @@ namespace graphene { namespace net { namespace detail { { VERIFY_CORRECT_THREAD(); dlog( "Triggering connect loop now" ); - _potential_peer_database_updated = true; + _potential_peer_db_updated = true; //if( _retrigger_connect_loop_promise ) // _retrigger_connect_loop_promise->set_value(); } @@ -554,7 +554,7 @@ namespace graphene { namespace net { namespace detail { if (!peer->inhibit_fetching_sync_blocks) { // loop through the items it has that we don't yet have on our blockchain - for( unsigned i = 0; i < peer->ids_of_items_to_get.size(); ++i ) + for( size_t i = 0; i < peer->ids_of_items_to_get.size(); ++i ) { item_hash_t item_to_potentially_request = peer->ids_of_items_to_get[i]; // if we don't already have this item in our temporary storage and we haven't requested from another syncing peer @@ -769,7 +769,7 @@ namespace graphene { namespace net { namespace detail { // don't send the peer anything we've already advertised to it // or anything it has advertised to us // group the items we need to send by type, because we'll need to send one inventory message per type - unsigned total_items_to_send_to_this_peer = 0; + size_t total_items_to_send_to_this_peer = 0; idump((inventory_to_advertise)); for (const item_id& item_to_advertise : inventory_to_advertise) { @@ -1106,7 +1106,9 @@ namespace graphene { namespace net { namespace detail { _avg_net_read_speed_seconds.push_back(bytes_read_this_second); _avg_net_write_speed_seconds.push_back(bytes_written_this_second); ++_avg_net_usage_second_counter; - if (_avg_net_usage_second_counter >= 60) + constexpr uint8_t seconds_per_minute = 60; + constexpr uint8_t minutes_per_hour = 60; + if (_avg_net_usage_second_counter >= seconds_per_minute) { _avg_net_usage_second_counter = 0; ++_avg_net_usage_minute_counter; @@ -1116,7 +1118,7 @@ namespace graphene { namespace net { namespace detail { uint32_t average_written_this_minute = (uint32_t)boost::accumulate(_avg_net_write_speed_seconds, uint64_t(0)) / (uint32_t)_avg_net_write_speed_seconds.size(); _avg_net_write_speed_minutes.push_back(average_written_this_minute); - if (_avg_net_usage_minute_counter >= 60) + if (_avg_net_usage_minute_counter >= minutes_per_hour) { _avg_net_usage_minute_counter = 0; uint32_t average_read_this_hour = (uint32_t)boost::accumulate(_avg_net_read_speed_minutes, uint64_t(0)) @@ -1192,7 +1194,7 @@ namespace graphene { namespace net { namespace detail { #ifdef USE_PEERS_TO_DELETE_MUTEX dlog("scheduling peer for deletion: ${peer} (may block on a mutex here)", ("peer", peer_to_delete->get_remote_endpoint())); - unsigned number_of_peers_to_delete; + size_t number_of_peers_to_delete; { fc::scoped_lock lock(_peers_to_delete_mutex); _peers_to_delete.emplace_back(peer_to_delete); @@ -2044,10 +2046,12 @@ namespace graphene { namespace net { namespace detail { if (!blockchain_item_ids_inventory_message_received.item_hashes_available.empty()) { // what's more, it should be a sequential list of blocks, verify that first - uint32_t first_block_number_in_reponse = _delegate->get_block_number(blockchain_item_ids_inventory_message_received.item_hashes_available.front()); - for (unsigned i = 1; i < blockchain_item_ids_inventory_message_received.item_hashes_available.size(); ++i) + uint32_t first_block_number_in_reponse = _delegate->get_block_number( + blockchain_item_ids_inventory_message_received.item_hashes_available.front()); + for (size_t i = 1; i < blockchain_item_ids_inventory_message_received.item_hashes_available.size(); ++i) { - uint32_t actual_num = _delegate->get_block_number(blockchain_item_ids_inventory_message_received.item_hashes_available[i]); + uint32_t actual_num = _delegate->get_block_number( + blockchain_item_ids_inventory_message_received.item_hashes_available[i]); uint32_t expected_num = first_block_number_in_reponse + i; if (actual_num != expected_num) { @@ -2419,7 +2423,7 @@ namespace graphene { namespace net { namespace detail { originating_peer->items_requested_from_peer.erase( regular_item_iter ); originating_peer->inventory_peer_advertised_to_us.erase( requested_item ); if (is_item_in_any_peers_inventory(requested_item)) - _items_to_fetch.insert(prioritized_item_id(requested_item, _items_to_fetch_sequence_counter++)); + _items_to_fetch.insert(prioritized_item_id(requested_item, _items_to_fetch_seq_counter++)); wlog("Peer doesn't have the requested item."); trigger_fetch_items_loop(); return; @@ -2496,7 +2500,7 @@ namespace graphene { namespace net { namespace detail { if (items_to_fetch_iter == _items_to_fetch.get().end()) { // it's new to us - _items_to_fetch.insert(prioritized_item_id(advertised_item_id, _items_to_fetch_sequence_counter++)); + _items_to_fetch.insert(prioritized_item_id(advertised_item_id, _items_to_fetch_seq_counter++)); dlog("adding item ${item_hash} from inventory message to our list of items to fetch", ("item_hash", item_hash)); trigger_fetch_items_loop(); @@ -2629,7 +2633,7 @@ namespace graphene { namespace net { namespace detail { for (auto item_and_time : originating_peer->items_requested_from_peer) { if (is_item_in_any_peers_inventory(item_and_time.first)) - _items_to_fetch.insert(prioritized_item_id(item_and_time.first, _items_to_fetch_sequence_counter++)); + _items_to_fetch.insert(prioritized_item_id(item_and_time.first, _items_to_fetch_seq_counter++)); } trigger_fetch_items_loop(); } @@ -2859,7 +2863,7 @@ namespace graphene { namespace net { namespace detail { //fc::time_point when_we_should_yield = start_time + fc::seconds(1); bool block_processed_this_iteration; - unsigned blocks_processed = 0; + size_t blocks_processed = 0; std::set peers_with_newly_empty_item_lists; std::set peers_we_need_to_sync_to; @@ -3431,7 +3435,9 @@ namespace graphene { namespace net { namespace detail { reply.upload_rate_one_minute = _avg_net_write_speed_minutes.back(); reply.download_rate_one_minute = _avg_net_read_speed_minutes.back(); - size_t minutes_to_average = std::min(_avg_net_write_speed_minutes.size(), (size_t)15); + constexpr size_t fifteen_minutes = 15; + constexpr size_t minutes_per_hour = 60; + size_t minutes_to_average = std::min(_avg_net_write_speed_minutes.size(), fifteen_minutes); boost::circular_buffer::iterator start_iter = _avg_net_write_speed_minutes.end() - minutes_to_average; reply.upload_rate_fifteen_minutes = std::accumulate(start_iter, _avg_net_write_speed_minutes.end(), 0) @@ -3440,7 +3446,7 @@ namespace graphene { namespace net { namespace detail { reply.download_rate_fifteen_minutes = std::accumulate(start_iter, _avg_net_read_speed_minutes.end(), 0) / (uint32_t)minutes_to_average; - minutes_to_average = std::min(_avg_net_write_speed_minutes.size(), (size_t)60); + minutes_to_average = std::min(_avg_net_write_speed_minutes.size(), minutes_per_hour); start_iter = _avg_net_write_speed_minutes.end() - minutes_to_average; reply.upload_rate_one_hour = std::accumulate(start_iter, _avg_net_write_speed_minutes.end(), 0) / (uint32_t)minutes_to_average; @@ -3699,7 +3705,7 @@ namespace graphene { namespace net { namespace detail { wlog( "Exception thrown while terminating Process backlog of sync items task, ignoring" ); } - unsigned handle_message_call_count = 0; + size_t handle_message_call_count = 0; while( true ) { auto it = _handle_message_calls_in_progress.begin(); diff --git a/libraries/net/node_impl.hxx b/libraries/net/node_impl.hxx index bce85f45e8..1342af8405 100644 --- a/libraries/net/node_impl.hxx +++ b/libraries/net/node_impl.hxx @@ -134,10 +134,10 @@ public: struct prioritized_item_id { item_id item; - unsigned sequence_number; + size_t sequence_number; fc::time_point timestamp; ///< the time we last heard about this item in an inventory message - prioritized_item_id(const item_id& item, unsigned sequence_number) : + prioritized_item_id(const item_id& item, size_t sequence_number) : item(item), sequence_number(sequence_number), timestamp(fc::time_point::now()) @@ -148,7 +148,7 @@ struct prioritized_item_id "block_message_type must be greater than trx_message_type for prioritized_item_ids to sort correctly"); if (item.item_type != rhs.item.item_type) return item.item_type > rhs.item.item_type; - return (signed)(rhs.sequence_number - sequence_number) > 0; + return rhs.sequence_number > sequence_number; } }; @@ -317,7 +317,7 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro peer_database _potential_peer_db; fc::promise::ptr _retrigger_connect_loop_promise; - bool _potential_peer_database_updated = false; + bool _potential_peer_db_updated = false; fc::future _p2p_network_connect_loop_done; /// @} @@ -358,7 +358,8 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro > > >; - size_t _items_to_fetch_sequence_counter = 0; + /// Items to fetch sequence counter + size_t _items_to_fetch_seq_counter = 0; /// List of items we know another peer has and we want items_to_fetch_set_type _items_to_fetch; /// List of transactions we've recently pushed and had rejected by the delegate @@ -488,9 +489,9 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro bool _node_is_shutting_down = false; /// Maximum number of blocks to handle at one time - size_t _max_blocks_to_handle_at_once = MAXIMUM_NUMBER_OF_BLOCKS_TO_HANDLE_AT_ONE_TIME; + size_t _max_blocks_to_handle_at_once = MAX_BLOCKS_TO_HANDLE_AT_ONCE; /// Maximum number of sync blocks to prefetch - size_t _max_sync_blocks_to_prefetch = MAXIMUM_NUMBER_OF_BLOCKS_TO_PREFETCH; + size_t _max_sync_blocks_to_prefetch = MAX_SYNC_BLOCKS_TO_PREFETCH; /// Maximum number of blocks per peer during syncing size_t _max_sync_blocks_per_peer = GRAPHENE_NET_MAX_BLOCKS_PER_PEER_DURING_SYNCING; From b4f06d7fbc627f18403819abf17cab98b1896222 Mon Sep 17 00:00:00 2001 From: abitmore Date: Fri, 16 Apr 2021 12:10:53 +0000 Subject: [PATCH 124/147] Fix code smells --- libraries/net/node.cpp | 58 +++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 9c232a3f41..0c8e60f4d4 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -548,19 +548,23 @@ namespace graphene { namespace net { namespace detail { for( const peer_connection_ptr& peer : _active_connections ) { if( peer->we_need_sync_items_from_peer && - sync_item_requests_to_send.find(peer) == sync_item_requests_to_send.end() && // if we've already scheduled a request for this peer, don't consider scheduling another + // if we've already scheduled a request for this peer, don't consider scheduling another + sync_item_requests_to_send.find(peer) == sync_item_requests_to_send.end() && peer->idle() ) { if (!peer->inhibit_fetching_sync_blocks) { // loop through the items it has that we don't yet have on our blockchain - for( size_t i = 0; i < peer->ids_of_items_to_get.size(); ++i ) + for( const auto& item_to_potentially_request : peer->ids_of_items_to_get ) { - item_hash_t item_to_potentially_request = peer->ids_of_items_to_get[i]; - // if we don't already have this item in our temporary storage and we haven't requested from another syncing peer - if( !have_already_received_sync_item(item_to_potentially_request) && // already got it, but for some reson it's still in our list of items to fetch - sync_items_to_request.find(item_to_potentially_request) == sync_items_to_request.end() && // we have already decided to request it from another peer during this iteration - _active_sync_requests.find(item_to_potentially_request) == _active_sync_requests.end() ) // we've requested it in a previous iteration and we're still waiting for it to arrive + // if we don't already have this item in our temporary storage + // and we haven't requested from another syncing peer + if( // already got it, but for some reson it's still in our list of items to fetch + !have_already_received_sync_item(item_to_potentially_request) && + // we have already decided to request it from another peer during this iteration + sync_items_to_request.find(item_to_potentially_request) == sync_items_to_request.end() && + // we've requested it in a previous iteration and we're still waiting for it to arrive + _active_sync_requests.find(item_to_potentially_request) == _active_sync_requests.end() ) { // then schedule a request from this peer sync_item_requests_to_send[peer].push_back(item_to_potentially_request); @@ -769,7 +773,7 @@ namespace graphene { namespace net { namespace detail { // don't send the peer anything we've already advertised to it // or anything it has advertised to us // group the items we need to send by type, because we'll need to send one inventory message per type - size_t total_items_to_send_to_this_peer = 0; + size_t total_items_to_send = 0; idump((inventory_to_advertise)); for (const item_id& item_to_advertise : inventory_to_advertise) { @@ -780,11 +784,14 @@ namespace graphene { namespace net { namespace detail { adv_to_us == peer->inventory_peer_advertised_to_us.end()) { items_to_advertise_by_type[item_to_advertise.item_type].push_back(item_to_advertise.item_hash); - peer->inventory_advertised_to_peer.insert(peer_connection::timestamped_item_id(item_to_advertise, fc::time_point::now())); - ++total_items_to_send_to_this_peer; + peer->inventory_advertised_to_peer.insert( + peer_connection::timestamped_item_id(item_to_advertise, fc::time_point::now())); + ++total_items_to_send; if (item_to_advertise.item_type == trx_message_type) - testnetlog("advertising transaction ${id} to peer ${endpoint}", ("id", item_to_advertise.item_hash)("endpoint", peer->get_remote_endpoint())); - dlog("advertising item ${id} to peer ${endpoint}", ("id", item_to_advertise.item_hash)("endpoint", peer->get_remote_endpoint())); + testnetlog("advertising transaction ${id} to peer ${endpoint}", + ("id", item_to_advertise.item_hash)("endpoint", peer->get_remote_endpoint())); + dlog("advertising item ${id} to peer ${endpoint}", + ("id", item_to_advertise.item_hash)("endpoint", peer->get_remote_endpoint())); } else { @@ -795,7 +802,7 @@ namespace graphene { namespace net { namespace detail { } } dlog("advertising ${count} new item(s) of ${types} type(s) to peer ${endpoint}", - ("count", total_items_to_send_to_this_peer) + ("count", total_items_to_send) ("types", items_to_advertise_by_type.size()) ("endpoint", peer->get_remote_endpoint())); for (auto items_group : items_to_advertise_by_type) @@ -2048,31 +2055,33 @@ namespace graphene { namespace net { namespace detail { // what's more, it should be a sequential list of blocks, verify that first uint32_t first_block_number_in_reponse = _delegate->get_block_number( blockchain_item_ids_inventory_message_received.item_hashes_available.front()); - for (size_t i = 1; i < blockchain_item_ids_inventory_message_received.item_hashes_available.size(); ++i) + // explicitly convert the size into 32 bit, should be OK + uint32_t items_received = blockchain_item_ids_inventory_message_received.item_hashes_available.size(); + for (uint32_t i = 1; i < items_received; ++i) { uint32_t actual_num = _delegate->get_block_number( blockchain_item_ids_inventory_message_received.item_hashes_available[i]); uint32_t expected_num = first_block_number_in_reponse + i; if (actual_num != expected_num) { - wlog("Invalid response from peer ${peer_endpoint}. The list of blocks they provided is not sequential, " + wlog("Invalid response from peer ${peer_endpoint}. The list of blocks they provided is not sequential, " "the ${position}th block in their reply was block number ${actual_num}, " "but it should have been number ${expected_num}", ("peer_endpoint", originating_peer->get_remote_endpoint()) ("position", i) ("actual_num", actual_num) ("expected_num", expected_num)); - fc::exception error_for_peer(FC_LOG_MESSAGE(error, + fc::exception error_for_peer(FC_LOG_MESSAGE(error, "You gave an invalid response to my request for sync blocks. The list of blocks you provided is not sequential, " "the ${position}th block in their reply was block number ${actual_num}, " "but it should have been number ${expected_num}", ("position", i) ("actual_num", actual_num) ("expected_num", expected_num))); - disconnect_from_peer(originating_peer, + disconnect_from_peer(originating_peer, "You gave an invalid response to my request for sync blocks", true, error_for_peer); - return; + return; } } @@ -2423,7 +2432,10 @@ namespace graphene { namespace net { namespace detail { originating_peer->items_requested_from_peer.erase( regular_item_iter ); originating_peer->inventory_peer_advertised_to_us.erase( requested_item ); if (is_item_in_any_peers_inventory(requested_item)) - _items_to_fetch.insert(prioritized_item_id(requested_item, _items_to_fetch_seq_counter++)); + { + _items_to_fetch.insert(prioritized_item_id(requested_item, _items_to_fetch_seq_counter)); + ++_items_to_fetch_seq_counter; + } wlog("Peer doesn't have the requested item."); trigger_fetch_items_loop(); return; @@ -2500,7 +2512,8 @@ namespace graphene { namespace net { namespace detail { if (items_to_fetch_iter == _items_to_fetch.get().end()) { // it's new to us - _items_to_fetch.insert(prioritized_item_id(advertised_item_id, _items_to_fetch_seq_counter++)); + _items_to_fetch.insert(prioritized_item_id(advertised_item_id, _items_to_fetch_seq_counter)); + ++_items_to_fetch_seq_counter; dlog("adding item ${item_hash} from inventory message to our list of items to fetch", ("item_hash", item_hash)); trigger_fetch_items_loop(); @@ -2633,7 +2646,10 @@ namespace graphene { namespace net { namespace detail { for (auto item_and_time : originating_peer->items_requested_from_peer) { if (is_item_in_any_peers_inventory(item_and_time.first)) - _items_to_fetch.insert(prioritized_item_id(item_and_time.first, _items_to_fetch_seq_counter++)); + { + _items_to_fetch.insert(prioritized_item_id(item_and_time.first, _items_to_fetch_seq_counter)); + ++_items_to_fetch_seq_counter; + } } trigger_fetch_items_loop(); } From d85a6f8c2c946b09ee54c976003e109eccb6a29c Mon Sep 17 00:00:00 2001 From: abitmore Date: Fri, 16 Apr 2021 20:42:19 +0000 Subject: [PATCH 125/147] Fix code smells --- libraries/net/node.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 0c8e60f4d4..f015f58685 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -2056,8 +2056,8 @@ namespace graphene { namespace net { namespace detail { uint32_t first_block_number_in_reponse = _delegate->get_block_number( blockchain_item_ids_inventory_message_received.item_hashes_available.front()); // explicitly convert the size into 32 bit, should be OK - uint32_t items_received = blockchain_item_ids_inventory_message_received.item_hashes_available.size(); - for (uint32_t i = 1; i < items_received; ++i) + auto total_items = uint32_t( blockchain_item_ids_inventory_message_received.item_hashes_available.size() ); + for (uint32_t i = 1; i < total_items; ++i) { uint32_t actual_num = _delegate->get_block_number( blockchain_item_ids_inventory_message_received.item_hashes_available[i]); From aee612845d08200f8eb17529b754fa93d0c16236 Mon Sep 17 00:00:00 2001 From: abitmore Date: Fri, 16 Apr 2021 21:40:30 +0000 Subject: [PATCH 126/147] Remove unused code --- libraries/net/node.cpp | 66 +----------------------------------------- 1 file changed, 1 insertion(+), 65 deletions(-) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index f015f58685..fe2059cf26 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -3443,71 +3443,7 @@ namespace graphene { namespace net { namespace detail { void node_impl::on_get_current_connections_request_message(peer_connection* originating_peer, const get_current_connections_request_message& get_current_connections_request_message_received) { - VERIFY_CORRECT_THREAD(); - get_current_connections_reply_message reply; - - if (!_avg_net_read_speed_minutes.empty()) - { - reply.upload_rate_one_minute = _avg_net_write_speed_minutes.back(); - reply.download_rate_one_minute = _avg_net_read_speed_minutes.back(); - - constexpr size_t fifteen_minutes = 15; - constexpr size_t minutes_per_hour = 60; - size_t minutes_to_average = std::min(_avg_net_write_speed_minutes.size(), fifteen_minutes); - boost::circular_buffer::iterator start_iter = _avg_net_write_speed_minutes.end() - - minutes_to_average; - reply.upload_rate_fifteen_minutes = std::accumulate(start_iter, _avg_net_write_speed_minutes.end(), 0) - / (uint32_t)minutes_to_average; - start_iter = _avg_net_read_speed_minutes.end() - minutes_to_average; - reply.download_rate_fifteen_minutes = std::accumulate(start_iter, _avg_net_read_speed_minutes.end(), 0) - / (uint32_t)minutes_to_average; - - minutes_to_average = std::min(_avg_net_write_speed_minutes.size(), minutes_per_hour); - start_iter = _avg_net_write_speed_minutes.end() - minutes_to_average; - reply.upload_rate_one_hour = std::accumulate(start_iter, _avg_net_write_speed_minutes.end(), 0) - / (uint32_t)minutes_to_average; - start_iter = _avg_net_read_speed_minutes.end() - minutes_to_average; - reply.download_rate_one_hour = std::accumulate(start_iter, _avg_net_read_speed_minutes.end(), 0) - / (uint32_t)minutes_to_average; - } - - fc::time_point now = fc::time_point::now(); - fc::scoped_lock lock(_active_connections.get_mutex()); - for (const peer_connection_ptr& peer : _active_connections) - { - current_connection_data data_for_this_peer; - data_for_this_peer.connection_duration = now.sec_since_epoch() - - peer->connection_initiation_time.sec_since_epoch(); - if (peer->get_remote_endpoint()) // should always be set for anyone we're actively connected to - data_for_this_peer.remote_endpoint = *peer->get_remote_endpoint(); - data_for_this_peer.clock_offset = peer->clock_offset; - data_for_this_peer.round_trip_delay = peer->round_trip_delay; - data_for_this_peer.node_id = peer->node_id; - data_for_this_peer.connection_direction = peer->direction; - data_for_this_peer.firewalled = peer->is_firewalled; - fc::mutable_variant_object user_data; - if (peer->graphene_git_revision_sha) - user_data["graphene_git_revision_sha"] = *peer->graphene_git_revision_sha; - if (peer->graphene_git_revision_unix_timestamp) - user_data["graphene_git_revision_unix_timestamp"] = *peer->graphene_git_revision_unix_timestamp; - if (peer->fc_git_revision_sha) - user_data["fc_git_revision_sha"] = *peer->fc_git_revision_sha; - if (peer->fc_git_revision_unix_timestamp) - user_data["fc_git_revision_unix_timestamp"] = *peer->fc_git_revision_unix_timestamp; - if (peer->platform) - user_data["platform"] = *peer->platform; - if (peer->bitness) - user_data["bitness"] = *peer->bitness; - user_data["user_agent"] = peer->user_agent; - - user_data["last_known_block_hash"] = fc::variant( peer->last_block_delegate_has_seen, 1 ); - user_data["last_known_block_number"] = _delegate->get_block_number(peer->last_block_delegate_has_seen); - user_data["last_known_block_time"] = peer->last_block_time_delegate_has_seen; - - data_for_this_peer.user_data = user_data; - reply.current_connections.emplace_back(data_for_this_peer); - } - originating_peer->send_message(reply); + /* This is unused. TODO: When we are sure no one will call this, remove it and its associated structures */ } void node_impl::on_get_current_connections_reply_message(peer_connection* originating_peer, From 1b2291dd169458b1bba0c7a093cb3a431b2bc414 Mon Sep 17 00:00:00 2001 From: abitmore Date: Fri, 16 Apr 2021 22:15:27 +0000 Subject: [PATCH 127/147] Move some code from node.cpp to node_impl.hxx --- libraries/net/node.cpp | 137 ++++++------------------------------ libraries/net/node_impl.hxx | 83 ++++++++++++++++++++++ 2 files changed, 106 insertions(+), 114 deletions(-) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index fe2059cf26..20da0d6771 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -89,6 +89,8 @@ #include +#include "node_impl.hxx" + //#define ENABLE_DEBUG_ULOGS #ifdef DEFAULT_LOGGER @@ -96,8 +98,6 @@ #endif #define DEFAULT_LOGGER "p2p" -#define P2P_IN_DEDICATED_THREAD 1 - #define INVOCATION_COUNTER(name) \ static size_t total_ ## name ## _counter = 0; \ static size_t active_ ## name ## _counter = 0; \ @@ -125,99 +125,36 @@ #define testnetlog(...) do {} while (0) #endif -namespace graphene { namespace net { +namespace graphene { namespace net { namespace detail { - namespace detail - { - namespace bmi = boost::multi_index; - class blockchain_tied_message_cache - { - private: - static const uint32_t cache_duration_in_blocks = GRAPHENE_NET_MESSAGE_CACHE_DURATION_IN_BLOCKS; - - struct message_hash_index{}; - struct message_contents_hash_index{}; - struct block_clock_index{}; - struct message_info - { - message_hash_type message_hash; - message message_body; - uint32_t block_clock_when_received; - - // for network performance stats - message_propagation_data propagation_data; - /// hash of whatever the message contains - /// (if it's a transaction, this is the transaction id, if it's a block, it's the block_id) - message_hash_type message_contents_hash; - - message_info( const message_hash_type& message_hash, - const message& message_body, - uint32_t block_clock_when_received, - const message_propagation_data& propagation_data, - message_hash_type message_contents_hash ) : - message_hash( message_hash ), - message_body( message_body ), - block_clock_when_received( block_clock_when_received ), - propagation_data( propagation_data ), - message_contents_hash( message_contents_hash ) - {} - }; - using message_cache_container = boost::multi_index_container < message_info, - bmi::indexed_by< - bmi::ordered_unique< bmi::tag, - bmi::member >, - bmi::ordered_non_unique< bmi::tag, - bmi::member >, - bmi::ordered_non_unique< bmi::tag, - bmi::member > > >; - - message_cache_container _message_cache; - - uint32_t block_clock; - - public: - blockchain_tied_message_cache() : - block_clock( 0 ) - {} - void block_accepted(); - void cache_message( const message& message_to_cache, - const message_hash_type& hash_of_message_to_cache, - const message_propagation_data& propagation_data, - const message_hash_type& message_content_hash ); - message get_message( const message_hash_type& hash_of_message_to_lookup ); - message_propagation_data get_message_propagation_data( - const message_hash_type& hash_of_msg_contents_to_lookup ) const; - size_t size() const { return _message_cache.size(); } - }; - - void blockchain_tied_message_cache::block_accepted() - { + void blockchain_tied_message_cache::block_accepted() + { ++block_clock; if( block_clock > cache_duration_in_blocks ) _message_cache.get().erase(_message_cache.get().begin(), _message_cache.get().lower_bound(block_clock - cache_duration_in_blocks ) ); - } + } - void blockchain_tied_message_cache::cache_message( const message& message_to_cache, - const message_hash_type& hash_of_message_to_cache, - const message_propagation_data& propagation_data, - const message_hash_type& message_content_hash ) - { + void blockchain_tied_message_cache::cache_message( const message& message_to_cache, + const message_hash_type& hash_of_message_to_cache, + const message_propagation_data& propagation_data, + const message_hash_type& message_content_hash ) + { _message_cache.insert( message_info(hash_of_message_to_cache, message_to_cache, block_clock, propagation_data, message_content_hash ) ); - } + } - message blockchain_tied_message_cache::get_message( const message_hash_type& hash_of_message_to_lookup ) - { + message blockchain_tied_message_cache::get_message( const message_hash_type& hash_of_message_to_lookup ) const + { message_cache_container::index::type::const_iterator iter = _message_cache.get().find(hash_of_message_to_lookup ); if( iter != _message_cache.get().end() ) - return iter->message_body; + return iter->message_body; FC_THROW_EXCEPTION( fc::key_not_found_exception, "Requested message not in cache" ); - } + } message_propagation_data blockchain_tied_message_cache::get_message_propagation_data( const message_hash_type& hash_of_msg_contents_to_lookup ) const @@ -232,37 +169,6 @@ namespace graphene { namespace net { FC_THROW_EXCEPTION( fc::key_not_found_exception, "Requested message not in cache" ); } -///////////////////////////////////////////////////////////////////////////////////////////////////////// - - // This specifies configuration info for the local node. It's stored as JSON - // in the configuration directory (application data directory) - struct node_configuration - { - node_configuration() : accept_incoming_connections(true), wait_if_endpoint_is_busy(true) {} - - fc::ip::endpoint listen_endpoint; - bool accept_incoming_connections; - bool wait_if_endpoint_is_busy; - /** - * Originally, our p2p code just had a 'node-id' that was a random number identifying this node - * on the network. This is now a private key/public key pair, where the public key is used - * in place of the old random node-id. The private part is unused, but might be used in - * the future to support some notion of trusted peers. - */ - fc::ecc::private_key private_key; - }; - - -} } } // end namespace graphene::net::detail -FC_REFLECT(graphene::net::detail::node_configuration, (listen_endpoint) - (accept_incoming_connections) - (wait_if_endpoint_is_busy) - (private_key)); - -#include "node_impl.hxx" - -namespace graphene { namespace net { namespace detail { - void node_impl_deleter::operator()(node_impl* impl_to_delete) { #ifdef P2P_IN_DEDICATED_THREAD @@ -364,12 +270,14 @@ namespace graphene { namespace net { namespace detail { dlog("Starting an iteration of p2p_network_connect_loop()."); display_current_connections(); - // add-once peers bypass our checks on the maximum/desired number of connections (but they will still be counted against the totals once they're connected) + // add-once peers bypass our checks on the maximum/desired number of connections + // (but they will still be counted against the totals once they're connected) if (!_add_once_node_list.empty()) { std::list add_once_node_list; add_once_node_list.swap(_add_once_node_list); - dlog("Processing \"add once\" node list containing ${count} peers:", ("count", add_once_node_list.size())); + dlog("Processing \"add once\" node list containing ${count} peers:", + ("count", add_once_node_list.size())); for (const potential_peer_record& add_once_peer : add_once_node_list) { dlog(" ${peer}", ("peer", add_once_peer.endpoint)); @@ -4297,8 +4205,9 @@ namespace graphene { namespace net { namespace detail { // if we've recently connected to this peer, reset the last_connection_attempt_time to allow // us to immediately retry this peer - updated_peer_record.last_connection_attempt_time = std::min(updated_peer_record.last_connection_attempt_time, - fc::time_point::now() - fc::seconds(_peer_connection_retry_timeout)); + updated_peer_record.last_connection_attempt_time + = std::min( updated_peer_record.last_connection_attempt_time, + fc::time_point::now() - fc::seconds(_peer_connection_retry_timeout) ); _add_once_node_list.push_back(updated_peer_record); _potential_peer_db.update_entry(updated_peer_record); trigger_p2p_network_connect_loop(); diff --git a/libraries/net/node_impl.hxx b/libraries/net/node_impl.hxx index 1342af8405..a80b802824 100644 --- a/libraries/net/node_impl.hxx +++ b/libraries/net/node_impl.hxx @@ -12,6 +12,10 @@ namespace graphene { namespace net { namespace detail { +namespace bmi = boost::multi_index; + +#define P2P_IN_DEDICATED_THREAD 1 + /******* * A class to wrap std::unordered_set for multithreading */ @@ -129,6 +133,64 @@ public: } }; +class blockchain_tied_message_cache +{ +private: + static const uint32_t cache_duration_in_blocks = GRAPHENE_NET_MESSAGE_CACHE_DURATION_IN_BLOCKS; + + struct message_hash_index{}; + struct message_contents_hash_index{}; + struct block_clock_index{}; + struct message_info + { + message_hash_type message_hash; + message message_body; + uint32_t block_clock_when_received; + + /// for network performance stats + message_propagation_data propagation_data; + /// hash of whatever the message contains + /// (if it's a transaction, this is the transaction id, if it's a block, it's the block_id) + message_hash_type message_contents_hash; + + message_info( const message_hash_type& message_hash, + const message& message_body, + uint32_t block_clock_when_received, + const message_propagation_data& propagation_data, + message_hash_type message_contents_hash ) : + message_hash( message_hash ), + message_body( message_body ), + block_clock_when_received( block_clock_when_received ), + propagation_data( propagation_data ), + message_contents_hash( message_contents_hash ) + {} + }; + + using message_cache_container = boost::multi_index_container < message_info, + bmi::indexed_by< + bmi::ordered_unique< bmi::tag, + bmi::member >, + bmi::ordered_non_unique< bmi::tag, + bmi::member >, + bmi::ordered_non_unique< bmi::tag, + bmi::member > > >; + + message_cache_container _message_cache; + + uint32_t block_clock = 0; + +public: + void block_accepted(); + void cache_message( const message& message_to_cache, + const message_hash_type& hash_of_message_to_cache, + const message_propagation_data& propagation_data, + const message_hash_type& message_content_hash ); + message get_message( const message_hash_type& hash_of_message_to_lookup ) const; + message_propagation_data get_message_propagation_data( + const message_hash_type& hash_of_msg_contents_to_lookup ) const; + size_t size() const { return _message_cache.size(); } +}; + /// When requesting items from peers, we want to prioritize any blocks before /// transactions, but otherwise request items in the order we heard about them struct prioritized_item_id @@ -284,6 +346,22 @@ class statistics_gathering_node_delegate_wrapper : public node_delegate uint8_t get_current_block_interval_in_seconds() const override; }; +/// This specifies configuration info for the local node. It's stored as JSON +/// in the configuration directory (application data directory) +struct node_configuration +{ + fc::ip::endpoint listen_endpoint; + bool accept_incoming_connections = true; + bool wait_if_endpoint_is_busy = true; + /** + * Originally, our p2p code just had a 'node-id' that was a random number identifying this node + * on the network. This is now a private key/public key pair, where the public key is used + * in place of the old random node-id. The private part is unused, but might be used in + * the future to support some notion of trusted peers. + */ + fc::ecc::private_key private_key; +}; + class node_impl : public peer_connection_delegate, public std::enable_shared_from_this { public: @@ -707,3 +785,8 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro }; }}} // end of namespace graphene::net::detail + +FC_REFLECT(graphene::net::detail::node_configuration, (listen_endpoint) + (accept_incoming_connections) + (wait_if_endpoint_is_busy) + (private_key)) From 0e73064b8785af122fd3f026b7d82c81a0ee7919 Mon Sep 17 00:00:00 2001 From: abitmore Date: Fri, 16 Apr 2021 22:58:15 +0000 Subject: [PATCH 128/147] Fix code smells --- libraries/net/node.cpp | 32 ++++++++++++++++++++------------ libraries/net/node_impl.hxx | 8 ++++---- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 20da0d6771..70fd627a0f 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -302,7 +302,8 @@ namespace graphene { namespace net { namespace detail { iter != _potential_peer_db.end() && is_wanting_new_connections(); ++iter) { - fc::microseconds delay_until_retry = fc::seconds((iter->number_of_failed_connection_attempts + 1) * _peer_connection_retry_timeout); + fc::microseconds delay_until_retry = fc::seconds( (iter->number_of_failed_connection_attempts + 1) + * _peer_connection_retry_timeout ); if (!is_connection_to_endpoint_in_progress(iter->endpoint) && ((iter->last_connection_disposition != last_connection_failed && @@ -350,10 +351,11 @@ namespace graphene { namespace net { namespace detail { } catch (const fc::canceled_exception&) { + ilog( "p2p_network_connect_loop canceled" ); throw; } FC_CAPTURE_AND_LOG( (0) ) - }// while(!canceled) + }// while !canceled } void node_impl::trigger_p2p_network_connect_loop() @@ -380,7 +382,8 @@ namespace graphene { namespace net { namespace detail { } catch (const fc::canceled_exception&) { - throw; + ilog( "update_seed_nodes_task canceled" ); + throw; } FC_CAPTURE_AND_LOG( (_seed_nodes) ) @@ -549,10 +552,12 @@ namespace graphene { namespace net { namespace detail { bool operator<(const peer_and_items_to_fetch& rhs) const { return peer < rhs.peer; } size_t number_of_items() const { return item_ids.size(); } }; - typedef boost::multi_index_container >, - boost::multi_index::ordered_non_unique, - boost::multi_index::const_mem_fun > > > fetch_messages_to_send_set; + using fetch_messages_to_send_set = boost::multi_index_container< peer_and_items_to_fetch, bmi::indexed_by< + bmi::ordered_unique< + bmi::member >, + bmi::ordered_non_unique< bmi::tag, + bmi::const_mem_fun > + > >; fetch_messages_to_send_set items_by_peer; // initialize the fetch_messages_to_send with an empty set of items for all idle peers @@ -571,7 +576,9 @@ namespace graphene { namespace net { namespace detail { // this item has probably already fallen out of our peers' caches, we'll just ignore it. // this can happen during flooding, and the _items_to_fetch could otherwise get clogged // with a bunch of items that we'll never be able to request from any peer - wlog("Unable to fetch item ${item} before its likely expiration time, removing it from our list of items to fetch", ("item", item_iter->item)); + wlog("Unable to fetch item ${item} before its likely expiration time, " + "removing it from our list of items to fetch", + ("item", item_iter->item)); item_iter = _items_to_fetch.erase(item_iter); } else @@ -644,7 +651,7 @@ namespace graphene { namespace net { namespace detail { } _retrigger_fetch_item_loop_promise.reset(); } - } // while (!canceled) + } // while !canceled } void node_impl::trigger_fetch_items_loop() @@ -2263,7 +2270,8 @@ namespace graphene { namespace net { namespace detail { return item_not_available_message(item); } - void node_impl::on_fetch_items_message(peer_connection* originating_peer, const fetch_items_message& fetch_items_message_received) + void node_impl::on_fetch_items_message(peer_connection* originating_peer, + const fetch_items_message& fetch_items_message_received) const { VERIFY_CORRECT_THREAD(); dlog("received items request for ids ${ids} of type ${type} from peer ${endpoint}", @@ -3348,8 +3356,8 @@ namespace graphene { namespace net { namespace detail { } - void node_impl::on_get_current_connections_request_message(peer_connection* originating_peer, - const get_current_connections_request_message& get_current_connections_request_message_received) + void node_impl::on_get_current_connections_request_message(const peer_connection*, + const get_current_connections_request_message&) const { /* This is unused. TODO: When we are sure no one will call this, remove it and its associated structures */ } diff --git a/libraries/net/node_impl.hxx b/libraries/net/node_impl.hxx index a80b802824..9c62d85407 100644 --- a/libraries/net/node_impl.hxx +++ b/libraries/net/node_impl.hxx @@ -14,7 +14,7 @@ namespace graphene { namespace net { namespace detail { namespace bmi = boost::multi_index; -#define P2P_IN_DEDICATED_THREAD 1 +#define P2P_IN_DEDICATED_THREAD /******* * A class to wrap std::unordered_set for multithreading @@ -651,7 +651,7 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro const blockchain_item_ids_inventory_message& blockchain_item_ids_inventory_message_received ); void on_fetch_items_message( peer_connection* originating_peer, - const fetch_items_message& fetch_items_message_received ); + const fetch_items_message& fetch_items_message_received ) const; void on_item_not_available_message( peer_connection* originating_peer, const item_not_available_message& item_not_available_message_received ); @@ -676,8 +676,8 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro void on_check_firewall_reply_message(peer_connection* originating_peer, const check_firewall_reply_message& check_firewall_reply_message_received); - void on_get_current_connections_request_message(peer_connection* originating_peer, - const get_current_connections_request_message& get_current_connections_request_message_received); + void on_get_current_connections_request_message(const peer_connection*, + const get_current_connections_request_message&) const; void on_get_current_connections_reply_message(peer_connection* originating_peer, const get_current_connections_reply_message& get_current_connections_reply_message_received); From d35801bf03fe59ce7318b4671d6b49cf0df57627 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 17 Apr 2021 00:17:20 +0000 Subject: [PATCH 129/147] Remove unused code --- libraries/net/node.cpp | 15 --------------- libraries/net/node_impl.hxx | 6 ------ 2 files changed, 21 deletions(-) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 70fd627a0f..811ce9c9ca 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -1322,10 +1322,8 @@ namespace graphene { namespace net { namespace detail { on_check_firewall_reply_message(originating_peer, received_message.as()); break; case core_message_type_enum::get_current_connections_request_message_type: - on_get_current_connections_request_message(originating_peer, received_message.as()); break; case core_message_type_enum::get_current_connections_reply_message_type: - on_get_current_connections_reply_message(originating_peer, received_message.as()); break; default: @@ -3356,19 +3354,6 @@ namespace graphene { namespace net { namespace detail { } - void node_impl::on_get_current_connections_request_message(const peer_connection*, - const get_current_connections_request_message&) const - { - /* This is unused. TODO: When we are sure no one will call this, remove it and its associated structures */ - } - - void node_impl::on_get_current_connections_reply_message(peer_connection* originating_peer, - const get_current_connections_reply_message& get_current_connections_reply_message_received) - { - VERIFY_CORRECT_THREAD(); - } - - // this handles any message we get that doesn't require any special processing. // currently, this is any message other than block messages and p2p-specific // messages. (transaction messages would be handled here, for example) diff --git a/libraries/net/node_impl.hxx b/libraries/net/node_impl.hxx index 9c62d85407..25ac9e3a0a 100644 --- a/libraries/net/node_impl.hxx +++ b/libraries/net/node_impl.hxx @@ -676,12 +676,6 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro void on_check_firewall_reply_message(peer_connection* originating_peer, const check_firewall_reply_message& check_firewall_reply_message_received); - void on_get_current_connections_request_message(const peer_connection*, - const get_current_connections_request_message&) const; - - void on_get_current_connections_reply_message(peer_connection* originating_peer, - const get_current_connections_reply_message& get_current_connections_reply_message_received); - void on_connection_closed(peer_connection* originating_peer) override; void send_sync_block_to_node_delegate(const graphene::net::block_message& block_message_to_send); From c1f99ab03eced9f224e4ed653000d281707f93b5 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 17 Apr 2021 00:38:22 +0000 Subject: [PATCH 130/147] Wrap long lines --- libraries/net/node.cpp | 106 ++++++++++++++++++++++++------------ libraries/net/node_impl.hxx | 3 +- 2 files changed, 71 insertions(+), 38 deletions(-) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 811ce9c9ca..7ebe091ae8 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -500,7 +500,8 @@ namespace graphene { namespace net { namespace detail { if( !_sync_items_to_fetch_updated ) { dlog( "no sync items to fetch right now, going to sleep" ); - _retrigger_fetch_sync_items_loop_promise = fc::promise::create("graphene::net::retrigger_fetch_sync_items_loop"); + _retrigger_fetch_sync_items_loop_promise + = fc::promise::create("graphene::net::retrigger_fetch_sync_items_loop"); _retrigger_fetch_sync_items_loop_promise->wait(); _retrigger_fetch_sync_items_loop_promise.reset(); } @@ -599,11 +600,13 @@ namespace graphene { namespace net { namespace detail { //dlog("requesting item ${hash} from peer ${endpoint}", // ("hash", iter->item.item_hash)("endpoint", peer->get_remote_endpoint())); item_id item_id_to_fetch = item_iter->item; - peer->items_requested_from_peer.insert(peer_connection::item_to_time_map_type::value_type(item_id_to_fetch, fc::time_point::now())); + peer->items_requested_from_peer.insert(peer_connection::item_to_time_map_type::value_type( + item_id_to_fetch, fc::time_point::now())); item_iter = _items_to_fetch.erase(item_iter); item_fetched = true; - items_by_peer.get().modify(peer_iter, [&item_id_to_fetch](peer_and_items_to_fetch& peer_and_items) { - peer_and_items.item_ids.push_back(item_id_to_fetch); + items_by_peer.get().modify(peer_iter, + [&item_id_to_fetch](peer_and_items_to_fetch& peer_and_items) { + peer_and_items.item_ids.push_back(item_id_to_fetch); }); break; } @@ -721,7 +724,10 @@ namespace graphene { namespace net { namespace detail { ("types", items_to_advertise_by_type.size()) ("endpoint", peer->get_remote_endpoint())); for (auto items_group : items_to_advertise_by_type) - inventory_messages_to_send.push_back(std::make_pair(peer, item_ids_inventory_message(items_group.first, items_group.second))); + { + inventory_messages_to_send.push_back(std::make_pair( + peer, item_ids_inventory_message(items_group.first, items_group.second))); + } } peer->clear_old_inventory(); } @@ -733,7 +739,8 @@ namespace graphene { namespace net { namespace detail { if (_new_inventory.empty()) { - _retrigger_advertise_inventory_loop_promise = fc::promise::create("graphene::net::retrigger_advertise_inventory_loop"); + _retrigger_advertise_inventory_loop_promise + = fc::promise::create("graphene::net::retrigger_advertise_inventory_loop"); _retrigger_advertise_inventory_loop_promise->wait(); _retrigger_advertise_inventory_loop_promise.reset(); } @@ -1013,9 +1020,11 @@ namespace graphene { namespace net { namespace detail { // this has nothing to do with updating the peer list, but we need to prune this list // at regular intervals, this is a fine place to do it. fc::time_point_sec oldest_failed_ids_to_keep(fc::time_point::now() - fc::minutes(15)); - auto oldest_failed_ids_to_keep_iter = _recently_failed_items.get().lower_bound(oldest_failed_ids_to_keep); + auto oldest_failed_ids_to_keep_iter = _recently_failed_items.get() + .lower_bound(oldest_failed_ids_to_keep); auto begin_iter = _recently_failed_items.get().begin(); - _recently_failed_items.get().erase(begin_iter, oldest_failed_ids_to_keep_iter); + _recently_failed_items.get() + .erase(begin_iter, oldest_failed_ids_to_keep_iter); if (!_node_is_shutting_down && !_fetch_updated_peer_lists_loop_done.canceled() ) _fetch_updated_peer_lists_loop_done = fc::schedule( [this](){ fetch_updated_peer_lists_loop(); }, @@ -1060,7 +1069,8 @@ namespace graphene { namespace net { namespace detail { if (_bandwidth_monitor_last_update_time == fc::time_point_sec::min()) _bandwidth_monitor_last_update_time = current_time; - uint32_t seconds_since_last_update = current_time.sec_since_epoch() - _bandwidth_monitor_last_update_time.sec_since_epoch(); + uint32_t seconds_since_last_update = current_time.sec_since_epoch() + - _bandwidth_monitor_last_update_time.sec_since_epoch(); seconds_since_last_update = std::max(UINT32_C(1), seconds_since_last_update); uint32_t bytes_read_this_second = _rate_limiter.get_actual_download_rate(); uint32_t bytes_written_this_second = _rate_limiter.get_actual_upload_rate(); @@ -1097,7 +1107,8 @@ namespace graphene { namespace net { namespace detail { while (!_peers_to_delete.empty()) { std::list peers_to_delete_copy; - dlog("beginning an iteration of delayed_peer_deletion_task with ${count} in queue", ("count", _peers_to_delete.size())); + dlog("beginning an iteration of delayed_peer_deletion_task with ${count} in queue", + ("count", _peers_to_delete.size())); peers_to_delete_copy.swap(_peers_to_delete); } dlog("leaving delayed_peer_deletion_task"); @@ -1114,7 +1125,8 @@ namespace graphene { namespace net { namespace detail { assert(_terminating_connections.find(peer_to_delete) == _terminating_connections.end()); #ifdef USE_PEERS_TO_DELETE_MUTEX - dlog("scheduling peer for deletion: ${peer} (may block on a mutex here)", ("peer", peer_to_delete->get_remote_endpoint())); + dlog("scheduling peer for deletion: ${peer} (may block on a mutex here)", + ("peer", peer_to_delete->get_remote_endpoint())); size_t number_of_peers_to_delete; { @@ -1127,22 +1139,28 @@ namespace graphene { namespace net { namespace detail { if (!_node_is_shutting_down && (!_delayed_peer_deletion_task_done.valid() || _delayed_peer_deletion_task_done.ready())) { - dlog("asyncing delayed_peer_deletion_task to delete ${size} peers", ("size", number_of_peers_to_delete)); - _delayed_peer_deletion_task_done = fc::async([this](){ delayed_peer_deletion_task(); }, "delayed_peer_deletion_task" ); + dlog("asyncing delayed_peer_deletion_task to delete ${size} peers", + ("size", number_of_peers_to_delete)); + _delayed_peer_deletion_task_done = fc::async([this](){ delayed_peer_deletion_task(); }, + "delayed_peer_deletion_task" ); } else - dlog("delayed_peer_deletion_task is already scheduled (current size of _peers_to_delete is ${size})", ("size", number_of_peers_to_delete)); + dlog("delayed_peer_deletion_task is already scheduled (current size of _peers_to_delete is ${size})", + ("size", number_of_peers_to_delete)); #else - dlog("scheduling peer for deletion: ${peer} (this will not block)", ("peer", peer_to_delete->get_remote_endpoint())); + dlog("scheduling peer for deletion: ${peer} (this will not block)", + ("peer", peer_to_delete->get_remote_endpoint())); _peers_to_delete.push_back(peer_to_delete); if (!_node_is_shutting_down && (!_delayed_peer_deletion_task_done.valid() || _delayed_peer_deletion_task_done.ready())) { dlog("asyncing delayed_peer_deletion_task to delete ${size} peers", ("size", _peers_to_delete.size())); - _delayed_peer_deletion_task_done = fc::async([this](){ delayed_peer_deletion_task(); }, "delayed_peer_deletion_task" ); + _delayed_peer_deletion_task_done = fc::async([this](){ delayed_peer_deletion_task(); }, + "delayed_peer_deletion_task" ); } else - dlog("delayed_peer_deletion_task is already scheduled (current size of _peers_to_delete is ${size})", ("size", _peers_to_delete.size())); + dlog("delayed_peer_deletion_task is already scheduled (current size of _peers_to_delete is ${size})", + ("size", _peers_to_delete.size())); #endif } @@ -1150,13 +1168,15 @@ namespace graphene { namespace net { namespace detail { bool node_impl::is_accepting_new_connections() { VERIFY_CORRECT_THREAD(); - return !_p2p_network_connect_loop_done.canceled() && get_number_of_connections() <= _maximum_number_of_connections; + return !_p2p_network_connect_loop_done.canceled() + && get_number_of_connections() <= _maximum_number_of_connections; } bool node_impl::is_wanting_new_connections() { VERIFY_CORRECT_THREAD(); - return !_p2p_network_connect_loop_done.canceled() && get_number_of_connections() < _desired_number_of_connections; + return !_p2p_network_connect_loop_done.canceled() + && get_number_of_connections() < _desired_number_of_connections; } uint32_t node_impl::get_number_of_connections() @@ -1289,10 +1309,12 @@ namespace graphene { namespace net { namespace detail { on_address_message(originating_peer, received_message.as()); break; case core_message_type_enum::fetch_blockchain_item_ids_message_type: - on_fetch_blockchain_item_ids_message(originating_peer, received_message.as()); + on_fetch_blockchain_item_ids_message( + originating_peer, received_message.as()); break; case core_message_type_enum::blockchain_item_ids_inventory_message_type: - on_blockchain_item_ids_inventory_message(originating_peer, received_message.as()); + on_blockchain_item_ids_inventory_message( + originating_peer, received_message.as()); break; case core_message_type_enum::fetch_items_message_type: on_fetch_items_message(originating_peer, received_message.as()); @@ -1379,11 +1401,13 @@ namespace graphene { namespace net { namespace detail { if (user_data.contains("graphene_git_revision_sha")) originating_peer->graphene_git_revision_sha = user_data["graphene_git_revision_sha"].as_string(); if (user_data.contains("graphene_git_revision_unix_timestamp")) - originating_peer->graphene_git_revision_unix_timestamp = fc::time_point_sec(user_data["graphene_git_revision_unix_timestamp"].as(1)); + originating_peer->graphene_git_revision_unix_timestamp = fc::time_point_sec( + user_data["graphene_git_revision_unix_timestamp"].as(1)); if (user_data.contains("fc_git_revision_sha")) originating_peer->fc_git_revision_sha = user_data["fc_git_revision_sha"].as_string(); if (user_data.contains("fc_git_revision_unix_timestamp")) - originating_peer->fc_git_revision_unix_timestamp = fc::time_point_sec(user_data["fc_git_revision_unix_timestamp"].as(1)); + originating_peer->fc_git_revision_unix_timestamp = fc::time_point_sec( + user_data["fc_git_revision_unix_timestamp"].as(1)); if (user_data.contains("platform")) originating_peer->platform = user_data["platform"].as_string(); if (user_data.contains("bitness")) @@ -1413,12 +1437,14 @@ namespace graphene { namespace net { namespace detail { fc::sha256::encoder shared_secret_encoder; fc::sha512 shared_secret = originating_peer->get_shared_secret(); shared_secret_encoder.write(shared_secret.data(), sizeof(shared_secret)); - fc::ecc::public_key expected_node_public_key(hello_message_received.signed_shared_secret, shared_secret_encoder.result(), false); + fc::ecc::public_key expected_node_public_key(hello_message_received.signed_shared_secret, + shared_secret_encoder.result(), false); // store off the data provided in the hello message originating_peer->user_agent = hello_message_received.user_agent; originating_peer->node_public_key = hello_message_received.node_public_key; - originating_peer->node_id = hello_message_received.node_public_key; // will probably be overwritten in parse_hello_user_data_for_peer() + // will probably be overwritten in parse_hello_user_data_for_peer() + originating_peer->node_id = hello_message_received.node_public_key; originating_peer->core_protocol_version = hello_message_received.core_protocol_version; originating_peer->inbound_address = hello_message_received.inbound_address; originating_peer->inbound_port = hello_message_received.inbound_port; @@ -1611,7 +1637,8 @@ namespace graphene { namespace net { namespace detail { void node_impl::on_connection_accepted_message(peer_connection* originating_peer, const connection_accepted_message& connection_accepted_message_received) { VERIFY_CORRECT_THREAD(); - dlog("Received a connection_accepted in response to my \"hello\" from ${peer}", ("peer", originating_peer->get_remote_endpoint())); + dlog("Received a connection_accepted in response to my \"hello\" from ${peer}", + ("peer", originating_peer->get_remote_endpoint())); originating_peer->negotiation_status = peer_connection::connection_negotiation_status::peer_connection_accepted; originating_peer->our_state = peer_connection::our_connection_state::connection_accepted; originating_peer->send_message(address_request_message()); @@ -1665,7 +1692,7 @@ namespace graphene { namespace net { namespace detail { FC_THROW( "unexpected connection_rejected_message from peer" ); } - void node_impl::on_address_request_message(peer_connection* originating_peer, const address_request_message& address_request_message_received) + void node_impl::on_address_request_message(peer_connection* originating_peer, const address_request_message&) { VERIFY_CORRECT_THREAD(); dlog("Received an address request message"); @@ -1695,10 +1722,12 @@ namespace graphene { namespace net { namespace detail { originating_peer->send_message(reply); } - void node_impl::on_address_message(peer_connection* originating_peer, const address_message& address_message_received) + void node_impl::on_address_message(peer_connection* originating_peer, + const address_message& address_message_received) { VERIFY_CORRECT_THREAD(); - dlog("Received an address message containing ${size} addresses", ("size", address_message_received.addresses.size())); + dlog("Received an address message containing ${size} addresses", + ("size", address_message_received.addresses.size())); for (const address_info& address : address_message_received.addresses) { dlog(" ${endpoint} last seen ${time}", ("endpoint", address.remote_endpoint)("time", address.last_seen_time)); @@ -1724,7 +1753,8 @@ namespace graphene { namespace net { namespace detail { if (inbound_endpoint) { // mark the connection as successful in the database - fc::optional updated_peer_record = _potential_peer_db.lookup_entry_for_endpoint(*inbound_endpoint); + fc::optional updated_peer_record + = _potential_peer_db.lookup_entry_for_endpoint(*inbound_endpoint); if (updated_peer_record) { updated_peer_record->last_connection_disposition = last_connection_succeeded; @@ -1767,8 +1797,9 @@ namespace graphene { namespace net { namespace detail { reply_message.total_remaining_item_count = 0; try { - reply_message.item_hashes_available = _delegate->get_block_ids(fetch_blockchain_item_ids_message_received.blockchain_synopsis, - reply_message.total_remaining_item_count); + reply_message.item_hashes_available + = _delegate->get_block_ids(fetch_blockchain_item_ids_message_received.blockchain_synopsis, + reply_message.total_remaining_item_count); } catch (const peer_is_on_an_unreachable_fork&) { @@ -1863,9 +1894,10 @@ namespace graphene { namespace net { namespace detail { fc::scoped_lock lock(_active_connections.get_mutex()); for( const peer_connection_ptr& peer : _active_connections ) { - uint32_t this_peer_number_of_unfetched_items = (uint32_t)peer->ids_of_items_to_get.size() + peer->number_of_unfetched_item_ids; + uint32_t this_peer_unfetched_items_count = (uint32_t)peer->ids_of_items_to_get.size() + + peer->number_of_unfetched_item_ids; max_number_of_unfetched_items = std::max(max_number_of_unfetched_items, - this_peer_number_of_unfetched_items); + this_peer_unfetched_items_count); } return max_number_of_unfetched_items; } @@ -1883,10 +1915,12 @@ namespace graphene { namespace net { namespace detail { // chance this peer's state will change before we get control back. Save off // the stuff necessary for generating the synopsis. // This is pretty expensive, we should find a better way to do this - std::vector original_ids_of_items_to_get(peer->ids_of_items_to_get.begin(), peer->ids_of_items_to_get.end()); + std::vector original_ids_of_items_to_get(peer->ids_of_items_to_get.begin(), + peer->ids_of_items_to_get.end()); uint32_t number_of_blocks_after_reference_point = original_ids_of_items_to_get.size(); - std::vector synopsis = _delegate->get_blockchain_synopsis(reference_point, number_of_blocks_after_reference_point); + std::vector synopsis = _delegate->get_blockchain_synopsis(reference_point, + number_of_blocks_after_reference_point); #if 0 // just for debugging, enable this and set a breakpoint to step through diff --git a/libraries/net/node_impl.hxx b/libraries/net/node_impl.hxx index 25ac9e3a0a..c0d59603a6 100644 --- a/libraries/net/node_impl.hxx +++ b/libraries/net/node_impl.hxx @@ -638,8 +638,7 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro void on_connection_rejected_message( peer_connection* originating_peer, const connection_rejected_message& connection_rejected_message_received ); - void on_address_request_message( peer_connection* originating_peer, - const address_request_message& address_request_message_received ); + void on_address_request_message( peer_connection* originating_peer, const address_request_message&); void on_address_message( peer_connection* originating_peer, const address_message& address_message_received ); From cf1b1d8664967f00dc7cd044ec382f233187a7de Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 17 Apr 2021 20:30:43 +0000 Subject: [PATCH 131/147] fix code smells, wrap long lines --- libraries/net/node.cpp | 56 ++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 7ebe091ae8..4af64653c3 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -725,7 +725,7 @@ namespace graphene { namespace net { namespace detail { ("endpoint", peer->get_remote_endpoint())); for (auto items_group : items_to_advertise_by_type) { - inventory_messages_to_send.push_back(std::make_pair( + inventory_messages_to_send.emplace_back(std::make_pair( peer, item_ids_inventory_message(items_group.first, items_group.second))); } } @@ -1778,7 +1778,8 @@ namespace graphene { namespace net { namespace detail { item_id peers_last_item_seen = item_id(fetch_blockchain_item_ids_message_received.item_type, item_hash_t()); if (fetch_blockchain_item_ids_message_received.blockchain_synopsis.empty()) { - dlog("sync: received a request for item ids starting at the beginning of the chain from peer ${peer_endpoint} (full request: ${synopsis})", + dlog("sync: received a request for item ids starting at the beginning of the chain " + "from peer ${peer_endpoint} (full request: ${synopsis})", ("peer_endpoint", originating_peer->get_remote_endpoint()) ("synopsis", fetch_blockchain_item_ids_message_received.blockchain_synopsis)); } @@ -2542,7 +2543,8 @@ namespace graphene { namespace net { namespace detail { if (inbound_endpoint && originating_peer_ptr->get_remote_endpoint()) { - fc::optional updated_peer_record = _potential_peer_db.lookup_entry_for_endpoint(*inbound_endpoint); + fc::optional updated_peer_record + = _potential_peer_db.lookup_entry_for_endpoint(*inbound_endpoint); if (updated_peer_record) { updated_peer_record->last_seen_time = fc::time_point::now(); @@ -2551,7 +2553,8 @@ namespace graphene { namespace net { namespace detail { } } - ilog("Remote peer ${endpoint} closed their connection to us", ("endpoint", originating_peer->get_remote_endpoint())); + ilog("Remote peer ${endpoint} closed their connection to us", + ("endpoint", originating_peer->get_remote_endpoint())); display_current_connections(); trigger_p2p_network_connect_loop(); @@ -2991,7 +2994,8 @@ namespace graphene { namespace net { namespace detail { bool new_transaction_discovered = false; for (const item_hash_t& transaction_message_hash : contained_transaction_msg_ids) { - /*size_t items_erased =*/ _items_to_fetch.get().erase(item_id(trx_message_type, transaction_message_hash)); + /*size_t items_erased =*/ + _items_to_fetch.get().erase(item_id(trx_message_type, transaction_message_hash)); // there are two ways we could behave here: we could either act as if we received // the transaction outside the block and offer it to our peers, or we could just // forget about it (we would still advertise this block to our peers so they should @@ -3031,7 +3035,8 @@ namespace graphene { namespace net { namespace detail { peer->clear_old_inventory(); } } - message_propagation_data propagation_data{message_receive_time, message_validated_time, originating_peer->node_id}; + message_propagation_data propagation_data { message_receive_time, message_validated_time, + originating_peer->node_id }; broadcast( block_message_to_process, propagation_data ); _message_cache.block_accepted(); @@ -3126,7 +3131,8 @@ namespace graphene { namespace net { namespace detail { // mode before we receive and process the item. In that case, we should process the item as a normal // item to avoid confusing the sync code) graphene::net::block_message block_message_to_process(message_to_process.as()); - auto item_iter = originating_peer->items_requested_from_peer.find(item_id(graphene::net::block_message_type, message_hash)); + auto item_iter = originating_peer->items_requested_from_peer.find( + item_id(graphene::net::block_message_type, message_hash)); if (item_iter != originating_peer->items_requested_from_peer.end()) { originating_peer->items_requested_from_peer.erase(item_iter); @@ -3211,10 +3217,14 @@ namespace graphene { namespace net { namespace detail { { VERIFY_CORRECT_THREAD(); fc::time_point reply_received_time = fc::time_point::now(); - originating_peer->clock_offset = fc::microseconds(((current_time_reply_message_received.request_received_time - current_time_reply_message_received.request_sent_time) + - (current_time_reply_message_received.reply_transmitted_time - reply_received_time)).count() / 2); - originating_peer->round_trip_delay = (reply_received_time - current_time_reply_message_received.request_sent_time) - - (current_time_reply_message_received.reply_transmitted_time - current_time_reply_message_received.request_received_time); + originating_peer->clock_offset = fc::microseconds( ( (current_time_reply_message_received.request_received_time + - current_time_reply_message_received.request_sent_time) + + (current_time_reply_message_received.reply_transmitted_time + - reply_received_time) ).count() / 2 ); + originating_peer->round_trip_delay = ( reply_received_time + - current_time_reply_message_received.request_sent_time ) + - ( current_time_reply_message_received.reply_transmitted_time + - current_time_reply_message_received.request_received_time ); } void node_impl::forward_firewall_check_to_next_available_peer(firewall_check_state_data* firewall_check_state) @@ -3268,7 +3278,8 @@ namespace graphene { namespace net { namespace detail { // we're not going to try to connect back to the originating peer directly, // instead, we're going to coordinate requests by asking some of our peers // to try to connect to the originating peer, and relay the results back - wlog("Peer ${peer} wants us to check whether it is firewalled", ("peer", originating_peer->get_remote_endpoint())); + wlog("Peer ${peer} wants us to check whether it is firewalled", + ("peer", originating_peer->get_remote_endpoint())); firewall_check_state_data* firewall_check_state = new firewall_check_state_data; // if they are using the same inbound and outbound port, try connecting to their outbound endpoint. // if they are using a different inbound port, use their outbound address but the inbound port they reported @@ -3840,7 +3851,8 @@ namespace graphene { namespace net { namespace detail { try { _tcp_server.accept( new_peer->get_socket() ); - ilog( "accepted inbound connection from ${remote_endpoint}", ("remote_endpoint", new_peer->get_socket().remote_endpoint() ) ); + ilog( "accepted inbound connection from ${remote_endpoint}", + ("remote_endpoint", new_peer->get_socket().remote_endpoint() ) ); if (_node_is_shutting_down) return; new_peer->connection_initiation_time = fc::time_point::now(); @@ -3869,7 +3881,8 @@ namespace graphene { namespace net { namespace detail { fc::sha256::encoder shared_secret_encoder; fc::sha512 shared_secret = peer->get_shared_secret(); shared_secret_encoder.write(shared_secret.data(), sizeof(shared_secret)); - fc::ecc::compact_signature signature = _node_configuration.private_key.sign_compact(shared_secret_encoder.result()); + fc::ecc::compact_signature signature + = _node_configuration.private_key.sign_compact(shared_secret_encoder.result()); // in the hello messsage, we send three things: // ip address @@ -3882,7 +3895,8 @@ namespace graphene { namespace net { namespace detail { // detection figured it out, send those values instead. fc::ip::endpoint local_endpoint(peer->get_socket().local_endpoint()); - uint16_t listening_port = _node_configuration.accept_incoming_connections ? _actual_listening_endpoint.port() : 0; + uint16_t listening_port = _node_configuration.accept_incoming_connections ? + _actual_listening_endpoint.port() : 0; if (_is_firewalled == firewalled_state::not_firewalled && _publicly_visible_listening_endpoint) @@ -3913,7 +3927,8 @@ namespace graphene { namespace net { namespace detail { { // create or find the database entry for the new peer // if we're connecting to them, we believe they're not firewalled - potential_peer_record updated_peer_record = _potential_peer_db.lookup_or_create_entry_for_endpoint(remote_endpoint); + potential_peer_record updated_peer_record + = _potential_peer_db.lookup_or_create_entry_for_endpoint(remote_endpoint); updated_peer_record.last_connection_disposition = last_connection_failed; updated_peer_record.last_connection_attempt_time = fc::time_point::now();; _potential_peer_db.update_entry(updated_peer_record); @@ -3927,13 +3942,15 @@ namespace graphene { namespace net { namespace detail { try { - new_peer->connect_to(remote_endpoint, _actual_listening_endpoint); // blocks until the connection is established and secure connection is negotiated + // blocks until the connection is established and secure connection is negotiated + new_peer->connect_to(remote_endpoint, _actual_listening_endpoint); // we connected to the peer. guess they're not firewalled.... new_peer->is_firewalled = firewalled_state::not_firewalled; // connection succeeded, we've started handshaking. record that in our database - potential_peer_record updated_peer_record = _potential_peer_db.lookup_or_create_entry_for_endpoint(remote_endpoint); + potential_peer_record updated_peer_record + = _potential_peer_db.lookup_or_create_entry_for_endpoint(remote_endpoint); updated_peer_record.last_connection_disposition = last_connection_handshaking_failed; updated_peer_record.number_of_successful_connection_attempts++; updated_peer_record.last_seen_time = fc::time_point::now(); @@ -3947,7 +3964,8 @@ namespace graphene { namespace net { namespace detail { if (connect_failed_exception && !new_peer->performing_firewall_check()) { // connection failed. record that in our database - potential_peer_record updated_peer_record = _potential_peer_db.lookup_or_create_entry_for_endpoint(remote_endpoint); + potential_peer_record updated_peer_record + = _potential_peer_db.lookup_or_create_entry_for_endpoint(remote_endpoint); updated_peer_record.last_connection_disposition = last_connection_failed; updated_peer_record.number_of_failed_connection_attempts++; if (new_peer->connection_closed_error) From ab59dd5b83e883df4fc3a148fa20097155570057 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 18 Apr 2021 01:25:41 +0000 Subject: [PATCH 132/147] Fix code smells --- libraries/net/node.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 4af64653c3..51bffa0880 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -3217,10 +3217,11 @@ namespace graphene { namespace net { namespace detail { { VERIFY_CORRECT_THREAD(); fc::time_point reply_received_time = fc::time_point::now(); + constexpr uint8_t two = 2; originating_peer->clock_offset = fc::microseconds( ( (current_time_reply_message_received.request_received_time - current_time_reply_message_received.request_sent_time) + (current_time_reply_message_received.reply_transmitted_time - - reply_received_time) ).count() / 2 ); + - reply_received_time) ).count() / two ); originating_peer->round_trip_delay = ( reply_received_time - current_time_reply_message_received.request_sent_time ) - ( current_time_reply_message_received.reply_transmitted_time From 1f5c7911786b59435b940052c3c31bc39bf96392 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 18 Apr 2021 14:07:24 +0000 Subject: [PATCH 133/147] Document fees returned by liq_pool_exchange_op --- .../protocol/include/graphene/protocol/liquidity_pool.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libraries/protocol/include/graphene/protocol/liquidity_pool.hpp b/libraries/protocol/include/graphene/protocol/liquidity_pool.hpp index d86a498b5e..712090de3c 100644 --- a/libraries/protocol/include/graphene/protocol/liquidity_pool.hpp +++ b/libraries/protocol/include/graphene/protocol/liquidity_pool.hpp @@ -109,6 +109,11 @@ namespace graphene { namespace protocol { /** * @brief Exchange with a liquidity pool * @ingroup operations + * @note The result of this operation is a @ref generic_exchange_operation_result. + * There are 3 fees in the result, stored in this order: + * * maker market fee + * * taker market fee + * * liquidity pool taker fee */ struct liquidity_pool_exchange_operation : public base_operation { From 059fb1420068871afbe63c92c216dbe971f2a3ad Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 18 Apr 2021 15:33:17 +0000 Subject: [PATCH 134/147] Replace virtual with override for member function --- libraries/net/node_impl.hxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/net/node_impl.hxx b/libraries/net/node_impl.hxx index c0d59603a6..303c3b65a1 100644 --- a/libraries/net/node_impl.hxx +++ b/libraries/net/node_impl.hxx @@ -584,7 +584,7 @@ class node_impl : public peer_connection_delegate, public std::enable_shared_fro /// @} node_impl(const std::string& user_agent); - virtual ~node_impl(); + ~node_impl() override; void save_node_configuration(); From 5b8a083b717295ac2269de9addfa9e78df1c15e4 Mon Sep 17 00:00:00 2001 From: Abit Date: Mon, 19 Apr 2021 00:01:15 +0200 Subject: [PATCH 135/147] Update supported boost version in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 48a9c3961c..e5272f57b5 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ We recommend building on Ubuntu 20.04 LTS (64-bit) * Windows (various versions, Visual Studio and MinGW) * OpenBSD (various versions) -* BitShares requires [Boost](https://www.boost.org/) libraries to build, supports version `1.58` to `1.71`. +* BitShares requires [Boost](https://www.boost.org/) libraries to build, supports version `1.58` to `1.74`. Newer versions may work, but have not been tested. If your system came pre-installed with a version of Boost libraries that you do not wish to use, you may manually build your preferred version and use it with BitShares by specifying it on the CMake command line. From 1bbf05ab76e9152067b84726948dfe7e24f3c209 Mon Sep 17 00:00:00 2001 From: abitmore Date: Wed, 21 Apr 2021 13:27:55 +0000 Subject: [PATCH 136/147] Find 2 different ports in cli_test for rpc and p2p --- tests/cli/main.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index 58fba86a05..df4347dc9c 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -108,7 +108,14 @@ std::shared_ptr start_application(fc::temp_directory auto sharable_cfg = std::make_shared(); auto& cfg = *sharable_cfg; server_port_number = fc::network::get_available_port(); + auto p2p_port = server_port_number; + for( size_t i = 0; i < 10 && p2p_port == server_port_number; ++i ) + { + p2p_port = fc::network::get_available_port(); + } + BOOST_REQUIRE( p2p_port != server_port_number ); fc::set_option( cfg, "rpc-endpoint", string("127.0.0.1:") + std::to_string(server_port_number) ); + fc::set_option( cfg, "p2p-endpoint", string("0.0.0.0:") + std::to_string(p2p_port) ); fc::set_option( cfg, "genesis-json", create_genesis_file(app_dir) ); fc::set_option( cfg, "seed-nodes", string("[]") ); fc::set_option( cfg, "custom-operations-start-block", uint32_t(1) ); From 84166cc4d376602adc4983648d7217afec5256f9 Mon Sep 17 00:00:00 2001 From: abitmore Date: Thu, 22 Apr 2021 21:58:47 +0000 Subject: [PATCH 137/147] Remove an unnecessary header include --- tests/performance/genesis_allocation.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/performance/genesis_allocation.cpp b/tests/performance/genesis_allocation.cpp index f3c06fe4a8..7ec3029b77 100644 --- a/tests/performance/genesis_allocation.cpp +++ b/tests/performance/genesis_allocation.cpp @@ -28,8 +28,6 @@ #include -#include - #include extern uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP; From d65c18e2de836a462fa2d4c60dfbc5708c976ab1 Mon Sep 17 00:00:00 2001 From: Abit Date: Fri, 23 Apr 2021 00:39:53 +0200 Subject: [PATCH 138/147] Fix broken link --- tests/performance/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/performance/README.md b/tests/performance/README.md index 67b9b4afaf..b7b2d406e5 100644 --- a/tests/performance/README.md +++ b/tests/performance/README.md @@ -6,7 +6,8 @@ of our current implementation. The subject was talked about in detail at BitFest Amsterdam, Sep 22, 2018. The original description of the 100,000 transactions per second test can be -found at https://bitshares.org/blog/2015/06/08/measuring-performance/ . +found at +https://web.archive.org/web/20181111215859/https://bitshares.org/blog/2015/06/08/measuring-performance/ . Prepare ------- From 9dd8d643d8d55ce5c0dce170dc2c80b0d64e9ff7 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sat, 24 Apr 2021 10:01:10 +0000 Subject: [PATCH 139/147] Restore default logger of network module to "p2p" --- libraries/net/node.cpp | 14 -------------- libraries/net/node_impl.hxx | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 51bffa0880..03fa07b940 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -91,13 +91,6 @@ #include "node_impl.hxx" -//#define ENABLE_DEBUG_ULOGS - -#ifdef DEFAULT_LOGGER -# undef DEFAULT_LOGGER -#endif -#define DEFAULT_LOGGER "p2p" - #define INVOCATION_COUNTER(name) \ static size_t total_ ## name ## _counter = 0; \ static size_t active_ ## name ## _counter = 0; \ @@ -118,13 +111,6 @@ } \ } invocation_logger(&total_ ## name ## _counter, &active_ ## name ## _counter) -//log these messages even at warn level when operating on the test network -#ifdef GRAPHENE_TEST_NETWORK -#define testnetlog wlog -#else -#define testnetlog(...) do {} while (0) -#endif - namespace graphene { namespace net { namespace detail { void blockchain_tied_message_cache::block_accepted() diff --git a/libraries/net/node_impl.hxx b/libraries/net/node_impl.hxx index 303c3b65a1..2b395223c8 100644 --- a/libraries/net/node_impl.hxx +++ b/libraries/net/node_impl.hxx @@ -16,6 +16,20 @@ namespace bmi = boost::multi_index; #define P2P_IN_DEDICATED_THREAD +//#define ENABLE_DEBUG_ULOGS + +#ifdef DEFAULT_LOGGER +# undef DEFAULT_LOGGER +#endif +#define DEFAULT_LOGGER "p2p" + +//log these messages even at warn level when operating on the test network +#ifdef GRAPHENE_TEST_NETWORK +#define testnetlog wlog +#else +#define testnetlog(...) do {} while (0) +#endif + /******* * A class to wrap std::unordered_set for multithreading */ From bd2f34d4e137747b7a362d63bc95a082189a6674 Mon Sep 17 00:00:00 2001 From: hammadsherwani <83015346+hammadsherwani@users.noreply.github.com> Date: Sat, 24 Apr 2021 16:37:59 +0500 Subject: [PATCH 140/147] Update seed-nodes.txt Placing node at 9th place, "seed.bitshares.rocks:1776", // bitshares (USA) --- libraries/egenesis/seed-nodes.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/egenesis/seed-nodes.txt b/libraries/egenesis/seed-nodes.txt index 4816708ad3..9ce6e0549c 100644 --- a/libraries/egenesis/seed-nodes.txt +++ b/libraries/egenesis/seed-nodes.txt @@ -6,4 +6,5 @@ "seed2.xbts.io:1776", // xbts.io (Germany) "seed1.bitshares.im:1776", // clone (USA) "seed.bitshares.org:666", // bitshares.org (France) +"seed.bitshares.rocks:1776", // bitshares (USA) "seeds.btsnodes.com:1776", // Community From aef44330a5fc3162740d8a5eabaf83c464b3447e Mon Sep 17 00:00:00 2001 From: Abit Date: Sat, 24 Apr 2021 13:43:17 +0200 Subject: [PATCH 141/147] Update comment --- libraries/egenesis/seed-nodes.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/egenesis/seed-nodes.txt b/libraries/egenesis/seed-nodes.txt index 9ce6e0549c..192b93475d 100644 --- a/libraries/egenesis/seed-nodes.txt +++ b/libraries/egenesis/seed-nodes.txt @@ -6,5 +6,5 @@ "seed2.xbts.io:1776", // xbts.io (Germany) "seed1.bitshares.im:1776", // clone (USA) "seed.bitshares.org:666", // bitshares.org (France) -"seed.bitshares.rocks:1776", // bitshares (USA) +"seed.bitshares.rocks:1776", // bitshares.rocks (USA) "seeds.btsnodes.com:1776", // Community From 11da12d767fe43db8f2a96e489075b109d2a1f01 Mon Sep 17 00:00:00 2001 From: Abit Date: Sun, 25 Apr 2021 02:38:11 +0200 Subject: [PATCH 142/147] Remove unused code --- libraries/net/node.cpp | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 03fa07b940..034779a8c4 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -91,26 +91,6 @@ #include "node_impl.hxx" -#define INVOCATION_COUNTER(name) \ - static size_t total_ ## name ## _counter = 0; \ - static size_t active_ ## name ## _counter = 0; \ - struct name ## _invocation_logger { \ - size_t *total; \ - size_t *active; \ - name ## _invocation_logger(size_t *total, size_t *active) : \ - total(total), active(active) \ - { \ - ++*total; \ - ++*active; \ - dlog("NEWDEBUG: Entering " #name ", now ${total} total calls, ${active} active calls", ("total", *total)("active", *active)); \ - } \ - ~name ## _invocation_logger() \ - { \ - --*active; \ - dlog("NEWDEBUG: Leaving " #name ", now ${total} total calls, ${active} active calls", ("total", *total)("active", *active)); \ - } \ - } invocation_logger(&total_ ## name ## _counter, &active_ ## name ## _counter) - namespace graphene { namespace net { namespace detail { void blockchain_tied_message_cache::block_accepted() From c9a96a8d01075184730f54098e5f65075a1bced2 Mon Sep 17 00:00:00 2001 From: abitmore Date: Mon, 26 Apr 2021 19:19:59 +0000 Subject: [PATCH 143/147] Bump FC to include the contributors update --- libraries/fc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/fc b/libraries/fc index 0954033fa5..02b7593a96 160000 --- a/libraries/fc +++ b/libraries/fc @@ -1 +1 @@ -Subproject commit 0954033fa5f2991352a922114fdf4a0667ec5a18 +Subproject commit 02b7593a96b02d9966358c59d22f344d86fa9a19 From b1ceebc84285f323345f170a680730c972b90d83 Mon Sep 17 00:00:00 2001 From: abitmore Date: Mon, 26 Apr 2021 20:32:25 +0000 Subject: [PATCH 144/147] Update boost source code download link --- .github/workflows/build-and-test.win.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-test.win.yml b/.github/workflows/build-and-test.win.yml index 68bca8940d..e1fad2984e 100644 --- a/.github/workflows/build-and-test.win.yml +++ b/.github/workflows/build-and-test.win.yml @@ -30,7 +30,7 @@ jobs: - name: Download library sources if: steps.cache-libs.outputs.cache-hit != 'true' run: | - curl -LO https://dl.bintray.com/boostorg/release/${{ env.BOOST_DOTTED_VERSION }}/source/boost_${{ env.BOOST_VERSION }}.tar.bz2 + curl -LO https://boostorg.jfrog.io/artifactory/main/release/${{ env.BOOST_DOTTED_VERSION }}/source/boost_${{ env.BOOST_VERSION }}.tar.bz2 curl -LO https://curl.haxx.se/download/curl-${{ env.CURL_VERSION }}.tar.bz2 curl -LO https://www.openssl.org/source/openssl-${{ env.OPENSSL_VERSION }}.tar.gz curl -LO https://zlib.net/zlib-${{ env.ZLIB_VERSION }}.tar.gz From 22af85cd4320f0fa307b15ff2fa02704f92935ea Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 27 Apr 2021 11:07:19 +0000 Subject: [PATCH 145/147] Bump docs version --- docs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs b/docs index 0a09ebbfd7..aa766179d5 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 0a09ebbfd71c6e80bb8cf87dbd1794f425a1d300 +Subproject commit aa766179d5a206581e7507c365646ec24d23b638 From a2c2dfde78deb499ad78c9f502d04dfe79e9d700 Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 27 Apr 2021 11:09:39 +0000 Subject: [PATCH 146/147] Update version in Doxyfile --- Doxyfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doxyfile b/Doxyfile index 3d8c8770a5..7467d92fa0 100644 --- a/Doxyfile +++ b/Doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = "BitShares-Core" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = "5.1.0" +PROJECT_NUMBER = "5.2.0" # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a From 55a528f6f48810306d5c2eebb00edab6a7d0353b Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 27 Apr 2021 11:12:20 +0000 Subject: [PATCH 147/147] Update contributors --- CONTRIBUTORS.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 6a0a654748..356e2d8af0 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -75,6 +75,7 @@ Troglodactyl VoR0220 alt bitcube +hammadsherwani <83015346+hammadsherwani@users.noreply.github.com> lafona liondani lososeg