From 8cf414442f68eeaa91965e4a5452660ecd9dc866 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 2 Jan 2022 16:49:36 +0000 Subject: [PATCH 1/3] Add a missing quotation mark --- libraries/plugins/elasticsearch/elasticsearch_plugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp index ba02c4d074..570e902674 100644 --- a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp +++ b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp @@ -661,7 +661,7 @@ operation_history_object elasticsearch_plugin::get_operation_by_id(operation_his "query": { "match": { - "account_history.operation_id": )" + operation_id_string + R"(" + "account_history.operation_id": ")" + operation_id_string + R"(" } } } From 827340abc5298dcf682685c1d8e58a3060d2bfa6 Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 2 Jan 2022 17:05:04 +0000 Subject: [PATCH 2/3] Store budget records in ES --- libraries/plugins/es_objects/es_objects.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libraries/plugins/es_objects/es_objects.cpp b/libraries/plugins/es_objects/es_objects.cpp index c7227ca5ac..8814179225 100644 --- a/libraries/plugins/es_objects/es_objects.cpp +++ b/libraries/plugins/es_objects/es_objects.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -83,6 +84,7 @@ class es_objects_plugin_impl object_options balances { true, false, true, "balance" }; object_options limit_orders { true, false, false, "limitorder" }; object_options asset_bitasset { true, false, true, "bitasset" }; + object_options budget { true, false, true, "budget" }; std::string index_prefix = "objects-"; uint32_t start_es_after_block = 0; @@ -173,6 +175,7 @@ void es_objects_plugin_impl::sync_db() loader.load( _options.balances ); loader.load( _options.proposals ); loader.load( _options.limit_orders ); + loader.load( _options.budget ); } void es_objects_plugin_impl::index_database(const vector& ids, action_type action) @@ -198,7 +201,8 @@ void es_objects_plugin_impl::index_database(const vector& ids, a { asset_id_type::space_type, _options.assets }, { asset_bitasset_data_id_type::space_type, _options.asset_bitasset }, { limit_order_id_type::space_type, _options.limit_orders }, - { proposal_id_type::space_type, _options.proposals } + { proposal_id_type::space_type, _options.proposals }, + { budget_record_id_type::space_type, _options.budget } }; for( const auto& value: ids ) @@ -231,6 +235,9 @@ void es_objects_plugin_impl::index_database(const vector& ids, a case proposal_id_type::space_type: prepareTemplate( db.get(value), opt ); break; + case budget_record_id_type::space_type: + prepareTemplate( db.get(value), opt ); + break; default: break; } @@ -381,6 +388,8 @@ void es_objects_plugin::plugin_set_program_options( ("es-objects-asset-bitasset-store-updates", boost::program_options::value(), "Store all updates to the bitasset data (false)") + ("es-objects-budget-records", boost::program_options::value(), "Store budget records (true)") + ("es-objects-index-prefix", boost::program_options::value(), "Add a prefix to the index(objects-)") ("es-objects-keep-only-current", boost::program_options::value(), @@ -419,6 +428,7 @@ void detail::es_objects_plugin_impl::plugin_options::init(const boost::program_o utilities::get_program_option( options, "es-objects-limit-orders-no-delete", limit_orders.no_delete ); utilities::get_program_option( options, "es-objects-asset-bitasset", asset_bitasset.enabled ); utilities::get_program_option( options, "es-objects-asset-bitasset-store-updates", asset_bitasset.store_updates ); + utilities::get_program_option( options, "es-objects-budget-records", budget.enabled ); utilities::get_program_option( options, "es-objects-index-prefix", index_prefix ); utilities::get_program_option( options, "es-objects-start-es-after-block", start_es_after_block ); utilities::get_program_option( options, "es-objects-sync-db-on-startup", sync_db_on_startup ); From 7a30eded9173403174f040081f73870dd0ef672e Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 2 Jan 2022 18:22:49 +0000 Subject: [PATCH 3/3] Add tests for storing budget records in ES --- tests/elasticsearch/main.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/elasticsearch/main.cpp b/tests/elasticsearch/main.cpp index 772ffe118b..6e82f27530 100644 --- a/tests/elasticsearch/main.cpp +++ b/tests/elasticsearch/main.cpp @@ -224,7 +224,10 @@ BOOST_AUTO_TEST_CASE(elasticsearch_objects) { es.elasticsearch_url = GRAPHENE_TESTING_ES_URL; es.index_prefix = es_obj_index_prefix; - // delete all first + // The head block number is 1 + BOOST_CHECK_EQUAL( db.head_block_num(), 1u ); + + // delete all first, this will delete genesis data and data inserted at block 1 auto delete_objects = graphene::utilities::deleteAll(es); BOOST_REQUIRE(delete_objects); // require successful deletion @@ -259,11 +262,30 @@ BOOST_AUTO_TEST_CASE(elasticsearch_objects) { auto bitasset_data_id = j["hits"]["hits"][size_t(0)]["_source"]["bitasset_data_id"].as_string(); es.endpoint = es.index_prefix + "bitasset/_doc/_search"; - es.query = "{ \"query\" : { \"bool\": { \"must\" : [{ \"term\": { \"object_id\": \""+bitasset_data_id+"\"}}] } } }"; + es.query = "{ \"query\" : { \"bool\": { \"must\" : [{ \"term\": { \"object_id\": \"" + + bitasset_data_id + "\"}}] } } }"; res = graphene::utilities::simpleQuery(es); j = fc::json::from_string(res); auto bitasset_object_id = j["hits"]["hits"][size_t(0)]["_source"]["object_id"].as_string(); BOOST_CHECK_EQUAL(bitasset_object_id, bitasset_data_id); + + // maintenance, for budget records + generate_blocks( db.get_dynamic_global_properties().next_maintenance_time ); + + es.endpoint = es.index_prefix + "budget/_doc/_count"; + es.query = ""; + fc::wait_for( ES_WAIT_TIME, [&]() { + res = graphene::utilities::getEndPoint(es); + j = fc::json::from_string(res); + if( !j.is_object() ) + return false; + const auto& obj = j.get_object(); + if( obj.find("count") == obj.end() ) + return false; + total = obj["count"].as_string(); + return (total == "1"); // new record inserted at the first maintenance block + }); + } } catch (fc::exception &e) {