From 17d2736a51fe47467bfd324e3c894d0e2fabf580 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Mon, 17 Feb 2020 13:19:21 -0300 Subject: [PATCH 01/12] replace upper_bound with equal_range in api call --- libraries/app/api.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 99564106a2..5814f27643 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -697,11 +697,9 @@ namespace graphene { namespace app { vector results; const auto& storage_index = _app.chain_database()->get_index_type(); const auto& by_account_catalog_idx = storage_index.indices().get(); - auto itr = by_account_catalog_idx.lower_bound(make_tuple(account_id, catalog)); - while(itr != by_account_catalog_idx.end() && itr->account == account_id && itr->catalog == catalog) { - results.push_back(*itr); - ++itr; - } + auto range = by_account_catalog_idx.equal_range(make_tuple(account_id, catalog)); + for( const account_storage_object& aso : boost::make_iterator_range( range.first, range.second ) ) + results.push_back(aso); return results; } From ec701b5dbeb5ee1dc25227a91b9e3c630c3cb7ee Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Mon, 17 Feb 2020 13:23:51 -0300 Subject: [PATCH 02/12] fix small typo in comment --- libraries/app/api.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 5814f27643..5eb46fc797 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -676,7 +676,7 @@ namespace graphene { namespace app { max_price = std::max( std::min( max_price, *start ), min_price ); auto itr = limit_groups.lower_bound( limit_order_group_key( group, max_price ) ); - // use an end itrator to try to avoid expensive price comparison + // use an end iterator to try to avoid expensive price comparison auto end = limit_groups.upper_bound( limit_order_group_key( group, min_price ) ); while( itr != end && result.size() < limit ) { From d1b74ebf2e85ae4643d542a06d9ff9ccdae38815 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Mon, 17 Feb 2020 13:35:18 -0300 Subject: [PATCH 03/12] change exception to reference --- .../plugins/custom_operations/custom_operations_plugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/plugins/custom_operations/custom_operations_plugin.cpp b/libraries/plugins/custom_operations/custom_operations_plugin.cpp index 562bcaf217..a7a250f1f6 100644 --- a/libraries/plugins/custom_operations/custom_operations_plugin.cpp +++ b/libraries/plugins/custom_operations/custom_operations_plugin.cpp @@ -88,7 +88,7 @@ void custom_operations_plugin_impl::onBlock( const signed_block& b ) custom_op_visitor vtor(db, custom_op.fee_payer()); unpacked.visit(vtor); } - catch (fc::exception e) { // only api node will know if the unpack, validate or apply fails + catch (fc::exception& e) { // only api node will know if the unpack, validate or apply fails dlog("Custom operations plugin serializing error: ${ex} in operation: ${op}", ("ex", e.to_detail_string())("op", fc::json::to_string(custom_op))); continue; From 5c4f5b08c4c57974a79646ff6d36284b1ef8f795 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Mon, 17 Feb 2020 14:51:36 -0300 Subject: [PATCH 04/12] remove not needed indexes from custom operations --- libraries/app/api.cpp | 2 +- .../graphene/custom_operations/custom_objects.hpp | 14 ++------------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 5eb46fc797..d16052cf62 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -696,7 +696,7 @@ namespace graphene { namespace app { const auto account_id = database_api.get_account_id_from_string(account_id_or_name); vector results; const auto& storage_index = _app.chain_database()->get_index_type(); - const auto& by_account_catalog_idx = storage_index.indices().get(); + const auto& by_account_catalog_idx = storage_index.indices().get(); auto range = by_account_catalog_idx.equal_range(make_tuple(account_id, catalog)); for( const account_storage_object& aso : boost::make_iterator_range( range.first, range.second ) ) results.push_back(aso); diff --git a/libraries/plugins/custom_operations/include/graphene/custom_operations/custom_objects.hpp b/libraries/plugins/custom_operations/include/graphene/custom_operations/custom_objects.hpp index 8586dc6e44..616448a369 100644 --- a/libraries/plugins/custom_operations/include/graphene/custom_operations/custom_objects.hpp +++ b/libraries/plugins/custom_operations/include/graphene/custom_operations/custom_objects.hpp @@ -52,23 +52,13 @@ struct account_storage_object : public abstract_object }; struct by_custom_id; -struct by_custom_account; -struct by_account_catalog; struct by_account_catalog_key; typedef multi_index_container< account_storage_object, indexed_by< - ordered_non_unique< tag, member< object, object_id_type, &object::id > >, - ordered_non_unique< tag, - member< account_storage_object, account_id_type, &account_storage_object::account > >, - ordered_non_unique< tag, - composite_key< account_storage_object, - member< account_storage_object, account_id_type, &account_storage_object::account >, - member< account_storage_object, string, &account_storage_object::catalog > - > - >, - ordered_non_unique< tag, + ordered_unique< tag, member< object, object_id_type, &object::id > >, + ordered_unique< tag, composite_key< account_storage_object, member< account_storage_object, account_id_type, &account_storage_object::account >, member< account_storage_object, string, &account_storage_object::catalog >, From 6e9b53d66e81989ce39ca0965f2ee5982e95cad2 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Mon, 17 Feb 2020 15:17:02 -0300 Subject: [PATCH 05/12] change account name to account name or id in api call --- libraries/app/include/graphene/app/api.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index 191380091c..b92c95edc2 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -534,12 +534,12 @@ namespace graphene { namespace app { /** * @brief Get all stored objects of an account in a particular catalog * - * @param account Account name to get info from + * @param account Account name or ID to get info from * @param catalog Category classification. Each account can store multiple catalogs. * * @return The vector of objects of the account or empty */ - vector get_storage_info(std::string account, std::string catalog)const; + vector get_storage_info(std::string account_id_or_name, std::string catalog)const; private: application& _app; From e57ab4ed6573ab973e2e905e5f94503f9b6b416d Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Mon, 17 Feb 2020 15:55:42 -0300 Subject: [PATCH 06/12] change custom() to custom_operations() --- libraries/app/api.cpp | 2 +- libraries/app/include/graphene/app/api.hpp | 4 ++-- libraries/wallet/wallet_api_impl.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index d16052cf62..ef03a4181c 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -302,7 +302,7 @@ namespace graphene { namespace app { return *_debug_api; } - fc::api login_api::custom() const + fc::api login_api::custom_operations() const { FC_ASSERT(_custom_operations_api); return *_custom_operations_api; diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index b92c95edc2..17e274c0cd 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -598,7 +598,7 @@ namespace graphene { namespace app { /// @brief Retrieve the debug API (if available) fc::api debug()const; /// @brief Retrieve the custom operations API - fc::api custom()const; + fc::api custom_operations()const; /// @brief Called to enable an API, not reflected. void enable_api( const string& api_name ); @@ -695,5 +695,5 @@ FC_API(graphene::app::login_api, (asset) (orders) (debug) - (custom) + (custom_operations) ) diff --git a/libraries/wallet/wallet_api_impl.cpp b/libraries/wallet/wallet_api_impl.cpp index b3316b36a5..790ee77d5a 100644 --- a/libraries/wallet/wallet_api_impl.cpp +++ b/libraries/wallet/wallet_api_impl.cpp @@ -59,7 +59,7 @@ namespace graphene { namespace wallet { namespace detail { _remote_hist(rapi->history()) { try { - _custom_operations = rapi->custom(); + _custom_operations = rapi->custom_operations(); } catch(const fc::exception& e) { From 3c6e4c8804ed276e6235b39c5ea50c5632c3aa94 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Mon, 17 Feb 2020 16:22:04 -0300 Subject: [PATCH 07/12] add after_block option to custom operations plugin --- .../custom_operations_plugin.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/libraries/plugins/custom_operations/custom_operations_plugin.cpp b/libraries/plugins/custom_operations/custom_operations_plugin.cpp index a7a250f1f6..30e2886df6 100644 --- a/libraries/plugins/custom_operations/custom_operations_plugin.cpp +++ b/libraries/plugins/custom_operations/custom_operations_plugin.cpp @@ -40,7 +40,7 @@ class custom_operations_plugin_impl { } virtual ~custom_operations_plugin_impl(); - void onBlock( const signed_block& b ); + void onBlock(); graphene::chain::database& database() { @@ -49,6 +49,8 @@ class custom_operations_plugin_impl custom_operations_plugin& _self; + uint32_t _after_block = 1; + private: }; @@ -69,7 +71,7 @@ struct custom_op_visitor } }; -void custom_operations_plugin_impl::onBlock( const signed_block& b ) +void custom_operations_plugin_impl::onBlock() { graphene::chain::database& db = database(); const vector >& hist = db.get_applied_operations(); @@ -126,14 +128,25 @@ void custom_operations_plugin::plugin_set_program_options( boost::program_options::options_description& cfg ) { + cli.add_options() + ("custom-operations-start-after-block", boost::program_options::value(), + "Start processing custom operations transactions with the plugin only after this block(1)") + ; + cfg.add(cli); + } void custom_operations_plugin::plugin_initialize(const boost::program_options::variables_map& options) { database().add_index< primary_index< account_storage_index > >(); + if (options.count("custom-operations-start-after-block")) { + my->_after_block = options["elasticsearch-bulk-replay"].as(); + } + database().applied_block.connect( [this]( const signed_block& b) { - my->onBlock(b); + if( b.block_num() >= my->_after_block ) + my->onBlock(); } ); } From 84b18cb7d00fdab200750c5047edacfc5176e160 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Mon, 17 Feb 2020 16:48:42 -0300 Subject: [PATCH 08/12] change dlog to wlog in custom operations plugin --- libraries/plugins/custom_operations/custom_evaluators.cpp | 6 +++--- .../plugins/custom_operations/custom_operations_plugin.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/plugins/custom_operations/custom_evaluators.cpp b/libraries/plugins/custom_operations/custom_evaluators.cpp index 6270f011e0..cfc501be83 100644 --- a/libraries/plugins/custom_operations/custom_evaluators.cpp +++ b/libraries/plugins/custom_operations/custom_evaluators.cpp @@ -54,7 +54,7 @@ vector custom_generic_evaluator::do_apply(const account_storage_ for(auto const& row: op.key_values) { if(row.first.length() > CUSTOM_OPERATIONS_MAX_KEY_SIZE) { - dlog("Key can't be bigger than ${max} characters", ("max", CUSTOM_OPERATIONS_MAX_KEY_SIZE)); + wlog("Key can't be bigger than ${max} characters", ("max", CUSTOM_OPERATIONS_MAX_KEY_SIZE)); continue; } auto itr = index.find(make_tuple(_account, op.catalog, row.first)); @@ -70,7 +70,7 @@ vector custom_generic_evaluator::do_apply(const account_storage_ }); results.push_back(created.id); } - catch(const fc::parse_error_exception& e) { dlog(e.to_detail_string()); } + catch(const fc::parse_error_exception& e) { wlog(e.to_detail_string()); } } else { @@ -84,7 +84,7 @@ vector custom_generic_evaluator::do_apply(const account_storage_ }); results.push_back(itr->id); } - catch(const fc::parse_error_exception& e) { dlog((e.to_detail_string())); } + catch(const fc::parse_error_exception& e) { wlog((e.to_detail_string())); } } } } diff --git a/libraries/plugins/custom_operations/custom_operations_plugin.cpp b/libraries/plugins/custom_operations/custom_operations_plugin.cpp index 30e2886df6..60fccbe767 100644 --- a/libraries/plugins/custom_operations/custom_operations_plugin.cpp +++ b/libraries/plugins/custom_operations/custom_operations_plugin.cpp @@ -91,7 +91,7 @@ void custom_operations_plugin_impl::onBlock() unpacked.visit(vtor); } catch (fc::exception& e) { // only api node will know if the unpack, validate or apply fails - dlog("Custom operations plugin serializing error: ${ex} in operation: ${op}", + wlog("Custom operations plugin serializing error: ${ex} in operation: ${op}", ("ex", e.to_detail_string())("op", fc::json::to_string(custom_op))); continue; } From 42d422a34a8a7487aeefd0905cb263b3e465adc8 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Mon, 17 Feb 2020 19:16:25 -0300 Subject: [PATCH 09/12] fix wrong key and others --- libraries/app/include/graphene/app/api.hpp | 2 +- .../plugins/custom_operations/custom_operations_plugin.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index 17e274c0cd..e861ce2a98 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -534,7 +534,7 @@ namespace graphene { namespace app { /** * @brief Get all stored objects of an account in a particular catalog * - * @param account Account name or ID to get info from + * @param account The account ID or name to get info from * @param catalog Category classification. Each account can store multiple catalogs. * * @return The vector of objects of the account or empty diff --git a/libraries/plugins/custom_operations/custom_operations_plugin.cpp b/libraries/plugins/custom_operations/custom_operations_plugin.cpp index 60fccbe767..22f1088b55 100644 --- a/libraries/plugins/custom_operations/custom_operations_plugin.cpp +++ b/libraries/plugins/custom_operations/custom_operations_plugin.cpp @@ -129,7 +129,7 @@ void custom_operations_plugin::plugin_set_program_options( ) { cli.add_options() - ("custom-operations-start-after-block", boost::program_options::value(), + ("custom-operations-start-after-block", boost::program_options::value()->default_value(1), "Start processing custom operations transactions with the plugin only after this block(1)") ; cfg.add(cli); @@ -141,7 +141,7 @@ void custom_operations_plugin::plugin_initialize(const boost::program_options::v database().add_index< primary_index< account_storage_index > >(); if (options.count("custom-operations-start-after-block")) { - my->_after_block = options["elasticsearch-bulk-replay"].as(); + my->_after_block = options["custom-operations-start-after-block"].as(); } database().applied_block.connect( [this]( const signed_block& b) { From 4f219aa587a19e38445b532882c5a3d5159ab0a0 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Mon, 17 Feb 2020 19:41:30 -0300 Subject: [PATCH 10/12] change default start after block to 45000000 --- .../plugins/custom_operations/custom_operations_plugin.cpp | 4 ++-- tests/cli/main.cpp | 1 + tests/common/database_fixture.cpp | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/plugins/custom_operations/custom_operations_plugin.cpp b/libraries/plugins/custom_operations/custom_operations_plugin.cpp index 22f1088b55..6360ec508c 100644 --- a/libraries/plugins/custom_operations/custom_operations_plugin.cpp +++ b/libraries/plugins/custom_operations/custom_operations_plugin.cpp @@ -49,7 +49,7 @@ class custom_operations_plugin_impl custom_operations_plugin& _self; - uint32_t _after_block = 1; + uint32_t _after_block = 45000000; private: @@ -129,7 +129,7 @@ void custom_operations_plugin::plugin_set_program_options( ) { cli.add_options() - ("custom-operations-start-after-block", boost::program_options::value()->default_value(1), + ("custom-operations-start-after-block", boost::program_options::value()->default_value(45000000), "Start processing custom operations transactions with the plugin only after this block(1)") ; cfg.add(cli); diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index ba42d2eb0b..b3b4565c95 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -143,6 +143,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-after-block", boost::program_options::variable_value(uint32_t(1), false)); app1->initialize(app_dir.path(), cfg); app1->initialize_plugins(cfg); diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 3cee06f19b..95a03b03e3 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -344,6 +344,7 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) current_test_name == "custom_operations_account_storage_list_test") { auto custom_operations_plugin = app.register_plugin(); custom_operations_plugin->plugin_set_app(&app); + options.insert(std::make_pair("custom-operations-start-after-block", boost::program_options::variable_value(uint32_t(1), false))); custom_operations_plugin->plugin_initialize(options); custom_operations_plugin->plugin_startup(); } From 500459a5cb794cae9ae054cdaa4d89411ae1ce69 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Thu, 27 Feb 2020 12:23:06 -0300 Subject: [PATCH 11/12] change plugin option name --- .../custom_operations/custom_operations_plugin.cpp | 12 ++++++------ tests/common/database_fixture.cpp | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/plugins/custom_operations/custom_operations_plugin.cpp b/libraries/plugins/custom_operations/custom_operations_plugin.cpp index 6360ec508c..64d5959d90 100644 --- a/libraries/plugins/custom_operations/custom_operations_plugin.cpp +++ b/libraries/plugins/custom_operations/custom_operations_plugin.cpp @@ -49,7 +49,7 @@ class custom_operations_plugin_impl custom_operations_plugin& _self; - uint32_t _after_block = 45000000; + uint32_t _start_block = 45000000; private: @@ -129,8 +129,8 @@ void custom_operations_plugin::plugin_set_program_options( ) { cli.add_options() - ("custom-operations-start-after-block", boost::program_options::value()->default_value(45000000), - "Start processing custom operations transactions with the plugin only after this block(1)") + ("custom-operations-start-block", boost::program_options::value()->default_value(45000000), + "Start processing custom operations transactions with the plugin only after this block") ; cfg.add(cli); @@ -140,12 +140,12 @@ void custom_operations_plugin::plugin_initialize(const boost::program_options::v { database().add_index< primary_index< account_storage_index > >(); - if (options.count("custom-operations-start-after-block")) { - my->_after_block = options["custom-operations-start-after-block"].as(); + if (options.count("custom-operations-start-block")) { + my->_start_block = options["custom-operations-start-block"].as(); } database().applied_block.connect( [this]( const signed_block& b) { - if( b.block_num() >= my->_after_block ) + if( b.block_num() >= my->_start_block ) my->onBlock(); } ); } diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 95a03b03e3..64e4f0ba7a 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -344,7 +344,7 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) current_test_name == "custom_operations_account_storage_list_test") { auto custom_operations_plugin = app.register_plugin(); custom_operations_plugin->plugin_set_app(&app); - options.insert(std::make_pair("custom-operations-start-after-block", boost::program_options::variable_value(uint32_t(1), false))); + 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(); } From 10ed74ede72d546447e18afaef9ee2946dabb725 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Thu, 27 Feb 2020 17:07:37 -0300 Subject: [PATCH 12/12] fix cli test --- tests/cli/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index b3b4565c95..58959f7c88 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -143,7 +143,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-after-block", boost::program_options::variable_value(uint32_t(1), 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);