From 26cdff2c73701f7a4d543f31f7693dc4cc274f51 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 15 Aug 2019 14:40:34 +0200 Subject: [PATCH 1/5] Remove unused account_referrer_index --- libraries/chain/account_object.cpp | 13 ------------- libraries/chain/db_init.cpp | 1 - .../include/graphene/chain/account_object.hpp | 16 ---------------- 3 files changed, 30 deletions(-) diff --git a/libraries/chain/account_object.cpp b/libraries/chain/account_object.cpp index d72d29536a..1840916113 100644 --- a/libraries/chain/account_object.cpp +++ b/libraries/chain/account_object.cpp @@ -256,19 +256,6 @@ void account_member_index::object_modified(const object& after) } -void account_referrer_index::object_inserted( const object& obj ) -{ -} -void account_referrer_index::object_removed( const object& obj ) -{ -} -void account_referrer_index::about_to_modify( const object& before ) -{ -} -void account_referrer_index::object_modified( const object& after ) -{ -} - const uint8_t balances_by_account_index::bits = 20; const uint64_t balances_by_account_index::mask = (1ULL << balances_by_account_index::bits) - 1; diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 124cede1eb..41f7f7018f 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -191,7 +191,6 @@ void database::initialize_indexes() auto acnt_index = add_index< primary_index >(); // ~1 million accounts per chunk acnt_index->add_secondary_index(); - acnt_index->add_secondary_index(); add_index< primary_index >(); // 256 members per chunk add_index< primary_index >(); // 1024 witnesses per chunk diff --git a/libraries/chain/include/graphene/chain/account_object.hpp b/libraries/chain/include/graphene/chain/account_object.hpp index 70aa0f78e9..1f610eb55a 100644 --- a/libraries/chain/include/graphene/chain/account_object.hpp +++ b/libraries/chain/include/graphene/chain/account_object.hpp @@ -324,22 +324,6 @@ namespace graphene { namespace chain { }; - /** - * @brief This secondary index will allow a reverse lookup of all accounts that have been referred by - * a particular account. - */ - class account_referrer_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; - - /** maps the referrer to the set of accounts that they have referred */ - map< account_id_type, set > referred_by; - }; - /** * @brief This secondary index will allow fast access to the balance objects * that belonging to an account. From e90ea0cf8afca0be06475a40f090d273b52dc169 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 15 Aug 2019 15:21:19 +0200 Subject: [PATCH 2/5] Move account_member_index to api_helper_indexs plugin --- libraries/chain/db_init.cpp | 4 +--- .../api_helper_indexes/api_helper_indexes.cpp | 4 ++++ tests/cli/main.cpp | 2 ++ tests/common/database_fixture.cpp | 12 +++++++----- tests/common/database_fixture.hpp | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 41f7f7018f..12bd2cd583 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -189,9 +189,7 @@ void database::initialize_indexes() add_index< primary_index >(); // 8192 assets per chunk add_index< primary_index >(); - auto acnt_index = add_index< primary_index >(); // ~1 million accounts per chunk - acnt_index->add_secondary_index(); - + add_index< primary_index >(); // ~1 million accounts per chunk add_index< primary_index >(); // 256 members per chunk add_index< primary_index >(); // 1024 witnesses per chunk add_index< primary_index >(); diff --git a/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp b/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp index e99e29b9c1..0470c6aab6 100644 --- a/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp +++ b/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp @@ -149,6 +149,10 @@ void api_helper_indexes::plugin_startup() amount_in_collateral = 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 ); + + auto& account_members = *database().add_secondary_index< primary_index, account_member_index >(); + for( const auto& account : database().get_index_type< account_index >().indices() ) + account_members.object_inserted( account ); } } } diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index 43dfaabfb3..24bab00b98 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -125,6 +126,7 @@ std::shared_ptr start_application(fc::temp_directory app1->register_plugin(true); app1->register_plugin< graphene::market_history::market_history_plugin >(true); app1->register_plugin< graphene::grouped_orders::grouped_orders_plugin>(true); + app1->register_plugin< graphene::api_helper_indexes::api_helper_indexes>(true); app1->startup_plugins(); boost::program_options::variables_map cfg; #ifdef _WIN32 diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index c8bf3517d9..db76bc65ab 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -125,8 +125,10 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) /** * Test specific settings */ - auto current_test_name = boost::unit_test::framework::current_test_case().p_name.value; - auto current_test_suite_id = boost::unit_test::framework::current_test_case().p_parent_id; + const auto current_test_name = boost::unit_test::framework::current_test_case().p_name.value; + const auto current_test_suite_id = boost::unit_test::framework::current_test_case().p_parent_id; + const auto current_suite_name = boost::unit_test::framework::get(current_test_suite_id) + .p_name.value; if (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))); @@ -292,7 +294,7 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) esplugin->plugin_initialize(options); esplugin->plugin_startup(); } - else if( boost::unit_test::framework::get(current_test_suite_id).p_name.value != "performance_tests" ) + else if( current_suite_name != "performance_tests" ) { auto ahplugin = app.register_plugin(); ahplugin->plugin_set_app(&app); @@ -323,7 +325,7 @@ 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" ) + else if( current_test_name == "asset_in_collateral" || current_suite_name == "database_api_tests" ) { auto ahiplugin = app.register_plugin(); ahiplugin->plugin_set_app(&app); @@ -431,7 +433,7 @@ string database_fixture::generate_anon_acct_name() // 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(string & current_test_name) const +bool database_fixture::validation_current_test_name_for_setting_api_limit( const string& current_test_name ) const { 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" diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index e626475fb0..a3cc5624df 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -371,7 +371,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 (string & current_test_name) const; + bool validation_current_test_name_for_setting_api_limit( const string& current_test_name )const; /**** * @brief return htlc fee parameters From a3160582db7bb5d6260cdace863dee34d9257c5c Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 15 Aug 2019 16:43:45 +0200 Subject: [PATCH 3/5] Move required_approval_index to api_helper_indexes plugin --- libraries/chain/db_init.cpp | 5 +---- .../plugins/api_helper_indexes/api_helper_indexes.cpp | 5 +++++ tests/common/database_fixture.cpp | 4 +++- tests/tests/database_tests.cpp | 8 ++++---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 12bd2cd583..bc7167d8bb 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -194,10 +194,7 @@ void database::initialize_indexes() add_index< primary_index >(); // 1024 witnesses per chunk add_index< primary_index >(); add_index< primary_index >(); - - auto prop_index = add_index< primary_index >(); - prop_index->add_secondary_index(); - + add_index< primary_index >(); add_index< primary_index >(); add_index< primary_index >(); add_index< primary_index >(); diff --git a/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp b/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp index 0470c6aab6..25644b3f65 100644 --- a/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp +++ b/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp @@ -24,6 +24,7 @@ #include #include +#include namespace graphene { namespace api_helper_indexes { @@ -153,6 +154,10 @@ void api_helper_indexes::plugin_startup() auto& account_members = *database().add_secondary_index< primary_index, account_member_index >(); for( const auto& account : database().get_index_type< account_index >().indices() ) account_members.object_inserted( account ); + + 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 ); } } } diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index db76bc65ab..f7c85c18c8 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -325,7 +325,9 @@ 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_suite_name == "database_api_tests" ) + else if( current_test_name == "asset_in_collateral" + || current_test_name == "htlc_database_api" + || current_suite_name == "database_api_tests" ) { auto ahiplugin = app.register_plugin(); ahiplugin->plugin_set_app(&app); diff --git a/tests/tests/database_tests.cpp b/tests/tests/database_tests.cpp index 3978bd3da7..742bf39795 100644 --- a/tests/tests/database_tests.cpp +++ b/tests/tests/database_tests.cpp @@ -229,8 +229,8 @@ BOOST_AUTO_TEST_CASE( required_approval_index_test ) // see https://github.com/b database db1; db1.initialize_indexes(); - const auto& proposals = db1.get_index_type< primary_index< proposal_index > >(); - const auto& required_approvals = proposals.get_secondary_index< required_approval_index >()._account_to_proposals; + const auto& required_approvals = db1.add_secondary_index, required_approval_index>() + ->_account_to_proposals; // Create a proposal const auto& prop = db1.create( [this,alice_id,agnetha_id]( object& o ) { @@ -279,8 +279,8 @@ BOOST_AUTO_TEST_CASE( required_approval_index_test ) // see https://github.com/b database db2; db2.initialize_indexes(); const auto& reloaded_proposals = db2.get_index_type< primary_index< proposal_index > >(); - const auto& reloaded_approvals = reloaded_proposals.get_secondary_index() - ._account_to_proposals; + const auto& reloaded_approvals = db2.add_secondary_index, required_approval_index>() + ->_account_to_proposals; const_cast< primary_index< proposal_index >& >( reloaded_proposals ).load( serialized ); const auto& prop2 = *reloaded_proposals.indices().begin(); From 8d263e189ab342ed38f127a6b382ef80edc58484 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 15 Aug 2019 16:56:59 +0200 Subject: [PATCH 4/5] Add grouped order index after replay --- libraries/plugins/grouped_orders/grouped_orders_plugin.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp b/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp index ef1ae04cae..7ffc3a1ced 100644 --- a/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp +++ b/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp @@ -279,12 +279,13 @@ void grouped_orders_plugin::plugin_initialize(const boost::program_options::vari else my->_tracked_groups = fc::json::from_string("[10,100]").as>(2); - database().add_secondary_index< primary_index, detail::limit_order_group_index >( my->_tracked_groups ); - } FC_CAPTURE_AND_RETHROW() } void grouped_orders_plugin::plugin_startup() { + auto& groups = *database().add_secondary_index< primary_index, detail::limit_order_group_index >( my->_tracked_groups ); + for( const auto& order : database().get_index_type< limit_order_index >().indices() ) + groups.object_inserted( order ); } const flat_set& grouped_orders_plugin::tracked_groups() const From 552d587a15698fcc9dc1d7f6dde551f1d87b4a49 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 13 Sep 2019 14:51:36 +0200 Subject: [PATCH 5/5] Wrapped long lines --- .../grouped_orders/grouped_orders_plugin.cpp | 3 ++- tests/common/database_fixture.cpp | 22 ++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp b/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp index 7ffc3a1ced..2e2542bef3 100644 --- a/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp +++ b/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp @@ -283,7 +283,8 @@ void grouped_orders_plugin::plugin_initialize(const boost::program_options::vari void grouped_orders_plugin::plugin_startup() { - auto& groups = *database().add_secondary_index< primary_index, detail::limit_order_group_index >( my->_tracked_groups ); + auto& groups = *database().add_secondary_index< primary_index, + detail::limit_order_group_index >( my->_tracked_groups ); for( const auto& order : database().get_index_type< limit_order_index >().indices() ) groups.object_inserted( order ); } diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index f7c85c18c8..06c1803db7 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -59,6 +59,8 @@ namespace graphene { namespace chain { using std::cout; using std::cerr; +namespace buf = boost::unit_test::framework; + void clearable_block::clear() { _calculated_merkle_root = checksum_type(); @@ -70,16 +72,20 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) : app(), db( *app.chain_database() ) { try { - int argc = boost::unit_test::framework::master_test_suite().argc; - char** argv = boost::unit_test::framework::master_test_suite().argv; + 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(); @@ -88,7 +94,7 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) genesis_state.initial_timestamp = initial_timestamp; - if(boost::unit_test::framework::current_test_case().p_name.value == "hf_935_test") { + if(current_test_name == "hf_935_test") { genesis_state.initial_active_witnesses = 20; } else { @@ -125,10 +131,6 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) /** * Test specific settings */ - const auto current_test_name = boost::unit_test::framework::current_test_case().p_name.value; - const auto current_test_suite_id = boost::unit_test::framework::current_test_case().p_parent_id; - const auto current_suite_name = boost::unit_test::framework::get(current_test_suite_id) - .p_name.value; if (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))); @@ -273,8 +275,8 @@ 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( boost::unit_test::framework::current_test_case().p_name.value == "track_votes_witnesses_disabled" || - boost::unit_test::framework::current_test_case().p_name.value == "track_votes_committee_disabled") { + if( current_test_name == "track_votes_witnesses_disabled" + || current_test_name == "track_votes_committee_disabled") { app.chain_database()->enable_standby_votes_tracking( false ); } if(current_test_name == "elasticsearch_account_history" || current_test_name == "elasticsearch_suite" ||