From 778fa645e1600b87021f7f51634272692f6e590d Mon Sep 17 00:00:00 2001 From: Abit Date: Sun, 19 Mar 2023 03:09:06 +0100 Subject: [PATCH 1/4] Add `is_virtual` field in account history in ES --- libraries/plugins/elasticsearch/elasticsearch_plugin.cpp | 1 + .../include/graphene/elasticsearch/elasticsearch_plugin.hpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp index 205bbf78f3..776046f3cf 100644 --- a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp +++ b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp @@ -272,6 +272,7 @@ void elasticsearch_plugin_impl::doOperationHistory( const optional trx_in_block; os.op_in_trx = oho->op_in_trx; os.virtual_op = oho->virtual_op; + os.is_virtual = oho->is_virtual; os.fee_payer = oho->op.visit( get_fee_payer_visitor() ); if(_options.operation_string) diff --git a/libraries/plugins/elasticsearch/include/graphene/elasticsearch/elasticsearch_plugin.hpp b/libraries/plugins/elasticsearch/include/graphene/elasticsearch/elasticsearch_plugin.hpp index 797fe3b8c0..e2ad5bf483 100644 --- a/libraries/plugins/elasticsearch/include/graphene/elasticsearch/elasticsearch_plugin.hpp +++ b/libraries/plugins/elasticsearch/include/graphene/elasticsearch/elasticsearch_plugin.hpp @@ -83,6 +83,7 @@ struct operation_history_struct { uint16_t trx_in_block; uint16_t op_in_trx; uint32_t virtual_op; + bool is_virtual; account_id_type fee_payer; std::string op; std::string operation_result; @@ -147,7 +148,7 @@ struct bulk_struct { FC_REFLECT_ENUM( graphene::elasticsearch::mode, (only_save)(only_query)(all) ) FC_REFLECT( graphene::elasticsearch::operation_history_struct, - (trx_in_block)(op_in_trx)(virtual_op)(fee_payer) + (trx_in_block)(op_in_trx)(virtual_op)(is_virtual)(fee_payer) (op)(operation_result)(op_object)(operation_result_object) ) FC_REFLECT( graphene::elasticsearch::block_struct, (block_num)(block_time)(trx_id) ) FC_REFLECT( graphene::elasticsearch::fee_struct, (asset)(asset_name)(amount)(amount_units) ) From 56b8d19a8b2d0d04f4d53e27085e2c1be34f039e Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 19 Mar 2023 12:12:17 +0000 Subject: [PATCH 2/4] Fix missing data in es_plugin::get_account_history Data in these fields was missing from the return value: * is_virtual * block_time --- libraries/plugins/elasticsearch/elasticsearch_plugin.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp index 776046f3cf..14529fb3fb 100644 --- a/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp +++ b/libraries/plugins/elasticsearch/elasticsearch_plugin.cpp @@ -612,6 +612,9 @@ static operation_history_object fromEStoOperation(const variant& source) result.trx_in_block = source["operation_history"]["trx_in_block"].as_uint64(); result.op_in_trx = source["operation_history"]["op_in_trx"].as_uint64(); result.trx_in_block = source["operation_history"]["virtual_op"].as_uint64(); + result.is_virtual = source["operation_history"]["is_virtual"].as_bool(); + + result.block_time = fc::time_point_sec::from_iso_string( source["block_data"]["block_time"].as_string() ); return result; } From bfa0401bdcba8bc52e6668766ecdb4b62e3919ab Mon Sep 17 00:00:00 2001 From: abitmore Date: Sun, 19 Mar 2023 17:03:36 +0000 Subject: [PATCH 3/4] Add tests for es_plugin::get_acc_his missing data --- tests/elasticsearch/main.cpp | 49 +++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/tests/elasticsearch/main.cpp b/tests/elasticsearch/main.cpp index bba0ce1889..5794d7f433 100644 --- a/tests/elasticsearch/main.cpp +++ b/tests/elasticsearch/main.cpp @@ -129,6 +129,8 @@ BOOST_AUTO_TEST_CASE(elasticsearch_account_history) { BOOST_CHECK_EQUAL(last_transfer_amount, "300"); auto last_transfer_payer = j["_source"]["operation_history"]["fee_payer"].as_string(); BOOST_CHECK_EQUAL(last_transfer_payer, "1.2.0"); + auto is_virtual = j["_source"]["operation_history"]["is_virtual"].as_bool(); + BOOST_CHECK( !is_virtual ); // To test credit offers generate_blocks( HARDFORK_CORE_2362_TIME ); @@ -375,6 +377,9 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[3].id.instance(), 0u); + BOOST_CHECK( !histories[0].is_virtual ); + BOOST_CHECK( histories[0].block_time == db.head_block_time() ); + // 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_REQUIRE_EQUAL(histories.size(), 4u); @@ -627,7 +632,8 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { BOOST_CHECK_EQUAL(histories.size(), 0u); // create a new account C = alice { 7 } - create_account("alice"); + auto alice = create_account("alice"); + account_id_type alice_id = alice.get_id(); generate_block(); @@ -662,6 +668,47 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { }, "thread invoke for method " BOOST_PP_STRINGIZE(method_name)).wait(); BOOST_REQUIRE( his_obj7.op.is_type() ); BOOST_CHECK_EQUAL( his_obj7.op.get().name, "alice" ); + + // Test virtual operation + + // Prepare funds + transfer( account_id_type()(db), alice_id(db), asset(100) ); + // Create a limit order that expires in 300 seconds + create_sell_order( alice_id, asset(1), asset(1, asset_id_type(1)), db.head_block_time() + 300 ); + + generate_block(); + + // f(C, 0, 4, 0) = { 9, 8, 7 } + fc::wait_for( ES_WAIT_TIME, [&]() { + histories = hist_api.get_account_history( + "alice", operation_history_id_type(0), 4, operation_history_id_type(0)); + return (histories.size() == 3u); + }); + BOOST_REQUIRE_EQUAL(histories.size(), 3u); + BOOST_CHECK( histories[0].op.is_type() ); + BOOST_CHECK( !histories[0].is_virtual ); + BOOST_CHECK( histories[0].block_time == db.head_block_time() ); + BOOST_CHECK( histories[1].op.is_type() ); + BOOST_CHECK( !histories[1].is_virtual ); + + // Let the limit order expire + generate_blocks( db.head_block_time() + 300 ); + generate_block(); + + // f(C, 0, 4, 0) = { 10, 9, 8, 7 } + fc::wait_for( ES_WAIT_TIME, [&]() { + histories = hist_api.get_account_history( + "alice", operation_history_id_type(0), 4, operation_history_id_type(0)); + return (histories.size() == 4u); + }); + BOOST_REQUIRE_EQUAL(histories.size(), 4u); + BOOST_CHECK( histories[0].op.is_type() ); + BOOST_CHECK( histories[0].is_virtual ); + BOOST_CHECK( histories[1].op.is_type() ); + BOOST_CHECK( !histories[1].is_virtual ); + BOOST_CHECK( histories[2].op.is_type() ); + BOOST_CHECK( !histories[2].is_virtual ); + } } catch (fc::exception &e) { From 887203c4da09dcb82ffb0327d37f0fca157f8470 Mon Sep 17 00:00:00 2001 From: abitmore Date: Mon, 20 Mar 2023 00:12:42 +0000 Subject: [PATCH 4/4] Bump DB_VERSION --- libraries/chain/include/graphene/chain/config.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/include/graphene/chain/config.hpp b/libraries/chain/include/graphene/chain/config.hpp index e905050d7c..c7d322801c 100644 --- a/libraries/chain/include/graphene/chain/config.hpp +++ b/libraries/chain/include/graphene/chain/config.hpp @@ -32,7 +32,7 @@ #define GRAPHENE_MAX_NESTED_OBJECTS (200) -const std::string GRAPHENE_CURRENT_DB_VERSION = "20230319"; +const std::string GRAPHENE_CURRENT_DB_VERSION = "20230320"; #define GRAPHENE_RECENTLY_MISSED_COUNT_INCREMENT 4 #define GRAPHENE_RECENTLY_MISSED_COUNT_DECREMENT 3