From 80c3b22e43bd9dc794a80c66f4a91089856b7722 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Wed, 27 Mar 2024 19:07:21 -0400 Subject: [PATCH 01/11] add get_blocks_result_v1 to SHiP --- libraries/state_history/abi.cpp | 13 +- .../eosio/state_history/serialization.hpp | 12 + .../include/eosio/state_history/types.hpp | 9 +- .../eosio/state_history_plugin/session.hpp | 95 +++--- .../tests/session_test.cpp | 274 ++++++++++++------ tests/ship_streamer.cpp | 12 +- 6 files changed, 290 insertions(+), 125 deletions(-) diff --git a/libraries/state_history/abi.cpp b/libraries/state_history/abi.cpp index f3a2a43ff3..00652169b0 100644 --- a/libraries/state_history/abi.cpp +++ b/libraries/state_history/abi.cpp @@ -53,6 +53,17 @@ extern const char* const state_history_plugin_abi = R"({ }, { "name": "get_blocks_result_v0", "fields": [ + { "name": "head", "type": "block_position" }, + { "name": "last_irreversible", "type": "block_position" }, + { "name": "this_block", "type": "block_position?" }, + { "name": "prev_block", "type": "block_position?" }, + { "name": "block", "type": "bytes?" }, + { "name": "traces", "type": "bytes?" }, + { "name": "deltas", "type": "bytes?" } + ] + }, + { + "name": "get_blocks_result_v1", "fields": [ { "name": "head", "type": "block_position" }, { "name": "last_irreversible", "type": "block_position" }, { "name": "this_block", "type": "block_position?" }, @@ -576,7 +587,7 @@ extern const char* const state_history_plugin_abi = R"({ ], "variants": [ { "name": "request", "types": ["get_status_request_v0", "get_blocks_request_v0", "get_blocks_request_v1", "get_blocks_ack_request_v0"] }, - { "name": "result", "types": ["get_status_result_v0", "get_blocks_result_v0"] }, + { "name": "result", "types": ["get_status_result_v0", "get_blocks_result_v0", "get_blocks_result_v1"] }, { "name": "action_receipt", "types": ["action_receipt_v0"] }, { "name": "action_trace", "types": ["action_trace_v0", "action_trace_v1"] }, diff --git a/libraries/state_history/include/eosio/state_history/serialization.hpp b/libraries/state_history/include/eosio/state_history/serialization.hpp index 50d90bb431..a20200c61f 100644 --- a/libraries/state_history/include/eosio/state_history/serialization.hpp +++ b/libraries/state_history/include/eosio/state_history/serialization.hpp @@ -709,6 +709,18 @@ datastream& operator<<(datastream& ds, const history_context_wrapper_sta template datastream& operator<<(datastream& ds, const eosio::state_history::get_blocks_result_v0& obj) { + fc::raw::pack(ds, obj.head); + fc::raw::pack(ds, obj.last_irreversible); + fc::raw::pack(ds, obj.this_block); + fc::raw::pack(ds, obj.prev_block); + history_pack_big_bytes(ds, obj.block); + history_pack_big_bytes(ds, obj.traces); + history_pack_big_bytes(ds, obj.deltas); + return ds; +} + +template +datastream& operator<<(datastream& ds, const eosio::state_history::get_blocks_result_v1& obj) { fc::raw::pack(ds, obj.head); fc::raw::pack(ds, obj.last_irreversible); fc::raw::pack(ds, obj.this_block); diff --git a/libraries/state_history/include/eosio/state_history/types.hpp b/libraries/state_history/include/eosio/state_history/types.hpp index 38cfb9af86..76b39957ce 100644 --- a/libraries/state_history/include/eosio/state_history/types.hpp +++ b/libraries/state_history/include/eosio/state_history/types.hpp @@ -123,12 +123,16 @@ struct get_blocks_result_base { struct get_blocks_result_v0 : get_blocks_result_base { std::optional traces; std::optional deltas; +}; + +struct get_blocks_result_v1 : get_blocks_result_v0 { std::optional finality_data; }; using state_request = std::variant; +using state_result = std::variant; using get_blocks_request = std::variant; -using state_result = std::variant; +using get_blocks_result = std::variant; } // namespace state_history } // namespace eosio @@ -142,5 +146,6 @@ FC_REFLECT(eosio::state_history::get_blocks_request_v0, (start_block_num)(end_bl FC_REFLECT_DERIVED(eosio::state_history::get_blocks_request_v1, (eosio::state_history::get_blocks_request_v0), (fetch_finality_data)); FC_REFLECT(eosio::state_history::get_blocks_ack_request_v0, (num_messages)); FC_REFLECT(eosio::state_history::get_blocks_result_base, (head)(last_irreversible)(this_block)(prev_block)(block)); -FC_REFLECT_DERIVED(eosio::state_history::get_blocks_result_v0, (eosio::state_history::get_blocks_result_base), (traces)(deltas)(finality_data)); +FC_REFLECT_DERIVED(eosio::state_history::get_blocks_result_v0, (eosio::state_history::get_blocks_result_base), (traces)(deltas)); +FC_REFLECT_DERIVED(eosio::state_history::get_blocks_result_v1, (eosio::state_history::get_blocks_result_v0), (finality_data)); // clang-format on diff --git a/plugins/state_history_plugin/include/eosio/state_history_plugin/session.hpp b/plugins/state_history_plugin/include/eosio/state_history_plugin/session.hpp index 84ee1557a7..3e0f647352 100644 --- a/plugins/state_history_plugin/include/eosio/state_history_plugin/session.hpp +++ b/plugins/state_history_plugin/include/eosio/state_history_plugin/session.hpp @@ -194,7 +194,7 @@ class blocks_request_send_queue_entry : public send_queue_entry_base { template class blocks_result_send_queue_entry : public send_queue_entry_base, public std::enable_shared_from_this> { std::shared_ptr session; - state_history::get_blocks_result_v0 r; + state_history::get_blocks_result result; std::vector data; std::optional stream; @@ -264,46 +264,68 @@ class blocks_result_send_queue_entry : public send_queue_entry_base, public std: }); } - // last to be sent + // last to be sent if result is get_blocks_result_v1 void send_finality_data() { + assert(std::holds_alternative(result)); stream.reset(); - send_log(session->get_finality_data_log_entry(r, stream), true, [me=this->shared_from_this()]() { + send_log(session->get_finality_data_log_entry(std::get(result), stream), true, [me=this->shared_from_this()]() { me->stream.reset(); me->session->session_mgr.pop_entry(); }); } - // second to be sent + // second to be sent if result is get_blocks_result_v1; + // last to be sent if result is get_blocks_result_v0 void send_deltas() { stream.reset(); - send_log(session->get_delta_log_entry(r, stream), false, [me=this->shared_from_this()]() { - me->send_finality_data(); - }); + std::visit(chain::overloaded{ + [&](state_history::get_blocks_result_v0& r) { + send_log(session->get_delta_log_entry(r, stream), true, [me=this->shared_from_this()]() { + me->stream.reset(); + me->session->session_mgr.pop_entry();}); }, + [&](state_history::get_blocks_result_v1& r) { + send_log(session->get_delta_log_entry(r, stream), false, [me=this->shared_from_this()]() { + me->send_finality_data(); }); }}, + result); } // first to be sent void send_traces() { stream.reset(); - send_log(session->get_trace_log_entry(r, stream), false, [me=this->shared_from_this()]() { + send_log(session->get_trace_log_entry(result, stream), false, [me=this->shared_from_this()]() { me->send_deltas(); }); } public: - blocks_result_send_queue_entry(std::shared_ptr s, state_history::get_blocks_result_v0&& r) + blocks_result_send_queue_entry(std::shared_ptr s, state_history::get_blocks_result&& r) : session(std::move(s)), - r(std::move(r)) {} + result(std::move(r)) {} void send_entry() override { + assert(std::holds_alternative(result) || + std::holds_alternative(result)); + // pack the state_result{get_blocks_result} excluding the fields `traces` and `deltas` fc::datastream ss; - fc::raw::pack(ss, fc::unsigned_int(1)); // pack the variant index of state_result{r} - fc::raw::pack(ss, static_cast(r)); + if(std::holds_alternative(result)) { + fc::raw::pack(ss, fc::unsigned_int(1)); // pack the variant index of state_result{r}, 1 for get_blocks_result_v0 + } else { + fc::raw::pack(ss, fc::unsigned_int(2)); // pack the variant index of state_result{r}, 2 for get_blocks_result_v1 + } + std::visit([&](auto& r) { + fc::raw::pack(ss, static_cast(r)); }, + result); data.resize(ss.tellp()); fc::datastream ds(data.data(), data.size()); - fc::raw::pack(ds, fc::unsigned_int(1)); // pack the variant index of state_result{r} - fc::raw::pack(ds, static_cast(r)); - + if(std::holds_alternative(result)) { + fc::raw::pack(ds, fc::unsigned_int(1)); // pack the variant index of state_result{r}, 1 for get_blocks_result_v0 + } else { + fc::raw::pack(ds, fc::unsigned_int(2)); // pack the variant index of state_result{r}, 2 for get_blocks_result_v1 + } + std::visit([&](auto& r) { + fc::raw::pack(ds, static_cast(r)); }, + result); async_send(false, data, [me=this->shared_from_this()]() { me->send_traces(); }); @@ -394,31 +416,31 @@ struct session : session_base, std::enable_shared_from_this& optional_log, std::optional& buf) { if (has_value) { if( optional_log ) { buf.emplace( optional_log->create_locked_decompress_stream() ); - return optional_log->get_unpacked_entry( result.this_block->block_num, *buf ); + return std::visit([&](auto& r) { return optional_log->get_unpacked_entry( r.this_block->block_num, *buf ); }, result); } } return 0; } - uint64_t get_trace_log_entry(const eosio::state_history::get_blocks_result_v0& result, + uint64_t get_trace_log_entry(const eosio::state_history::get_blocks_result& result, std::optional& buf) { - return get_log_entry_impl(result, result.traces.has_value(), plugin.get_trace_log(), buf); + return std::visit([&](auto& r) { return get_log_entry_impl(r, r.traces.has_value(), plugin.get_trace_log(), buf); }, result); } - uint64_t get_delta_log_entry(const eosio::state_history::get_blocks_result_v0& result, + uint64_t get_delta_log_entry(const eosio::state_history::get_blocks_result& result, std::optional& buf) { - return get_log_entry_impl(result, result.deltas.has_value(), plugin.get_chain_state_log(), buf); + return std::visit([&](auto& r) { return get_log_entry_impl(r, r.deltas.has_value(), plugin.get_chain_state_log(), buf); }, result); } - uint64_t get_finality_data_log_entry(const eosio::state_history::get_blocks_result_v0& result, - std::optional& buf) { + uint64_t get_finality_data_log_entry(const eosio::state_history::get_blocks_result_v1& result, + std::optional& buf) { return get_log_entry_impl(result, result.finality_data.has_value(), plugin.get_finality_data_log(), buf); } @@ -515,7 +537,8 @@ struct session : session_base, std::enable_shared_from_this // get_blocks_result_v0 or get_blocks_result_v1 + void send_update(state_history::get_blocks_request_v0& request, bool fetch_finality_data, T result, const chain::signed_block_ptr& block, const chain::block_id_type& id) { need_to_send_update = true; result.last_irreversible = plugin.get_last_irreversible(); @@ -565,8 +588,10 @@ struct session : session_base, std::enable_shared_from_this) { + if (fetch_finality_data && plugin.get_finality_data_log()) { + result.finality_data.emplace(); + } } } ++to_send_block_num; @@ -601,7 +626,7 @@ struct session : session_base, std::enable_shared_from_thisblock_num(); - state_history::get_blocks_result_v0 result; - result.head = {block_num, id}; to_send_block_num = std::min(block_num, to_send_block_num); - send_update(std::move(result), block, id); + send_update(state_history::block_position{block_num, id}, block, id); } void send_update(bool changed) override { if (changed || need_to_send_update) { - state_history::get_blocks_result_v0 result; - result.head = plugin.get_block_head(); - send_update(std::move(result), nullptr, chain::block_id_type{}); + send_update(plugin.get_block_head(), nullptr, chain::block_id_type{}); } else { session_mgr.pop_entry(false); } diff --git a/plugins/state_history_plugin/tests/session_test.cpp b/plugins/state_history_plugin/tests/session_test.cpp index 0a35bbaa55..d064ab2cb4 100644 --- a/plugins/state_history_plugin/tests/session_test.cpp +++ b/plugins/state_history_plugin/tests/session_test.cpp @@ -68,6 +68,18 @@ void unpack_big_bytes(fc::datastream& ds, std::optional template fc::datastream& operator>>(fc::datastream& ds, eosio::state_history::get_blocks_result_v0& obj) { + fc::raw::unpack(ds, obj.head); + fc::raw::unpack(ds, obj.last_irreversible); + fc::raw::unpack(ds, obj.this_block); + fc::raw::unpack(ds, obj.prev_block); + unpack_big_bytes(ds, obj.block); + unpack_big_bytes(ds, obj.traces); + unpack_big_bytes(ds, obj.deltas); + return ds; +} + +template +fc::datastream& operator>>(fc::datastream& ds, eosio::state_history::get_blocks_result_v1& obj) { fc::raw::unpack(ds, obj.head); fc::raw::unpack(ds, obj.last_irreversible); fc::raw::unpack(ds, obj.this_block); @@ -467,27 +479,40 @@ void test_session_no_prune_impl(state_history_test_fixture& fixture, bool fetch_ // we should get 3 consecutive block result for (int i = 0; i < 3; ++i) { fixture.receive_result(result); - BOOST_REQUIRE(std::holds_alternative(result)); - auto r = std::get(result); - BOOST_REQUIRE_EQUAL(r.head.block_num, fixture.server.block_head.block_num); - BOOST_REQUIRE(r.traces.has_value()); - BOOST_REQUIRE(r.deltas.has_value()); + if( fetch_finality_data ) { + BOOST_REQUIRE(std::holds_alternative(result)); + auto r = std::get(result); + BOOST_REQUIRE_EQUAL(r.head.block_num, fixture.server.block_head.block_num); + BOOST_REQUIRE(r.traces.has_value()); + BOOST_REQUIRE(r.deltas.has_value()); BOOST_REQUIRE(r.finality_data.has_value()); - } - auto traces = r.traces.value(); - auto deltas = r.deltas.value(); - auto& data = fixture.written_data[i]; - auto data_size = data.size() * sizeof(int32_t); - BOOST_REQUIRE_EQUAL(traces.size(), data_size); - BOOST_REQUIRE_EQUAL(deltas.size(), data_size); - BOOST_REQUIRE(std::equal(traces.begin(), traces.end(), (const char*)data.data())); - BOOST_REQUIRE(std::equal(deltas.begin(), deltas.end(), (const char*)data.data())); + auto traces = r.traces.value(); + auto deltas = r.deltas.value(); + auto& data = fixture.written_data[i]; + auto data_size = data.size() * sizeof(int32_t); + BOOST_REQUIRE_EQUAL(traces.size(), data_size); + BOOST_REQUIRE_EQUAL(deltas.size(), data_size); + BOOST_REQUIRE(std::equal(traces.begin(), traces.end(), (const char*)data.data())); + BOOST_REQUIRE(std::equal(deltas.begin(), deltas.end(), (const char*)data.data())); - if( fetch_finality_data ) { auto finality_data = r.finality_data.value(); BOOST_REQUIRE_EQUAL(finality_data.size(), data_size); BOOST_REQUIRE(std::equal(finality_data.begin(), finality_data.end(), (const char*)data.data())); + } else { + BOOST_REQUIRE(std::holds_alternative(result)); + auto r = std::get(result); + BOOST_REQUIRE_EQUAL(r.head.block_num, fixture.server.block_head.block_num); + BOOST_REQUIRE(r.traces.has_value()); + BOOST_REQUIRE(r.deltas.has_value()); + auto traces = r.traces.value(); + auto deltas = r.deltas.value(); + auto& data = fixture.written_data[i]; + auto data_size = data.size() * sizeof(int32_t); + BOOST_REQUIRE_EQUAL(traces.size(), data_size); + BOOST_REQUIRE_EQUAL(deltas.size(), data_size); + BOOST_REQUIRE(std::equal(traces.begin(), traces.end(), (const char*)data.data())); + BOOST_REQUIRE(std::equal(deltas.begin(), deltas.end(), (const char*)data.data())); } } } @@ -531,30 +556,50 @@ void test_split_log_impl(state_history_test_fixture& fixture, bool fetch_finalit eosio::chain::block_id_type prev_id; for (uint32_t i = 0; i < head; ++i) { fixture.receive_result(result); - BOOST_REQUIRE(std::holds_alternative(result)); - auto r = std::get(result); - BOOST_REQUIRE_EQUAL(r.head.block_num, fixture.server.block_head.block_num); - if (i > 0) { - BOOST_TEST(prev_id.str() == r.prev_block->block_id.str()); - } - prev_id = r.this_block->block_id; - BOOST_REQUIRE(r.traces.has_value()); - BOOST_REQUIRE(r.deltas.has_value()); - auto traces = r.traces.value(); - auto deltas = r.deltas.value(); - auto& data = fixture.written_data[i]; - auto data_size = data.size() * sizeof(int32_t); - BOOST_REQUIRE_EQUAL(traces.size(), data_size); - BOOST_REQUIRE_EQUAL(deltas.size(), data_size); - - BOOST_REQUIRE(std::equal(traces.begin(), traces.end(), (const char*)data.data())); - BOOST_REQUIRE(std::equal(deltas.begin(), deltas.end(), (const char*)data.data())); if( fetch_finality_data ) { + BOOST_REQUIRE(std::holds_alternative(result)); + auto r = std::get(result); + BOOST_REQUIRE_EQUAL(r.head.block_num, fixture.server.block_head.block_num); + if (i > 0) { + BOOST_TEST(prev_id.str() == r.prev_block->block_id.str()); + } + prev_id = r.this_block->block_id; + BOOST_REQUIRE(r.traces.has_value()); + BOOST_REQUIRE(r.deltas.has_value()); + auto traces = r.traces.value(); + auto deltas = r.deltas.value(); + auto& data = fixture.written_data[i]; + auto data_size = data.size() * sizeof(int32_t); + BOOST_REQUIRE_EQUAL(traces.size(), data_size); + BOOST_REQUIRE_EQUAL(deltas.size(), data_size); + + BOOST_REQUIRE(std::equal(traces.begin(), traces.end(), (const char*)data.data())); + BOOST_REQUIRE(std::equal(deltas.begin(), deltas.end(), (const char*)data.data())); + auto finality_data = r.finality_data.value(); BOOST_REQUIRE(r.finality_data.has_value()); BOOST_REQUIRE_EQUAL(finality_data.size(), data_size); BOOST_REQUIRE(std::equal(finality_data.begin(), finality_data.end(), (const char*)data.data())); + } else { + BOOST_REQUIRE(std::holds_alternative(result)); + auto r = std::get(result); + BOOST_REQUIRE_EQUAL(r.head.block_num, fixture.server.block_head.block_num); + if (i > 0) { + BOOST_TEST(prev_id.str() == r.prev_block->block_id.str()); + } + prev_id = r.this_block->block_id; + BOOST_REQUIRE(r.traces.has_value()); + BOOST_REQUIRE(r.deltas.has_value()); + auto traces = r.traces.value(); + auto deltas = r.deltas.value(); + auto& data = fixture.written_data[i]; + auto data_size = data.size() * sizeof(int32_t); + BOOST_REQUIRE_EQUAL(traces.size(), data_size); + BOOST_REQUIRE_EQUAL(deltas.size(), data_size); + + BOOST_REQUIRE(std::equal(traces.begin(), traces.end(), (const char*)data.data())); + BOOST_REQUIRE(std::equal(deltas.begin(), deltas.end(), (const char*)data.data())); } } } @@ -603,37 +648,59 @@ void test_session_with_prune_impl(state_history_test_fixture& fixture, bool fetc // we should get 3 consecutive block result fixture.receive_result(result); - BOOST_REQUIRE(std::holds_alternative(result)); - auto r = std::get(result); - BOOST_REQUIRE_EQUAL(r.head.block_num, fixture.server.block_head.block_num); - BOOST_REQUIRE(!r.traces.has_value()); - BOOST_REQUIRE(!r.deltas.has_value()); if( fetch_finality_data ) { + BOOST_REQUIRE(std::holds_alternative(result)); + auto r = std::get(result); + BOOST_REQUIRE_EQUAL(r.head.block_num, fixture.server.block_head.block_num); + BOOST_REQUIRE(!r.traces.has_value()); + BOOST_REQUIRE(!r.deltas.has_value()); BOOST_REQUIRE(!r.finality_data.has_value()); + } else { + BOOST_REQUIRE(std::holds_alternative(result)); + auto r = std::get(result); + BOOST_REQUIRE_EQUAL(r.head.block_num, fixture.server.block_head.block_num); + BOOST_REQUIRE(!r.traces.has_value()); + BOOST_REQUIRE(!r.deltas.has_value()); } for (int i = 1; i < 3; ++i) { fixture.receive_result(result); - BOOST_REQUIRE(std::holds_alternative(result)); - auto r = std::get(result); - BOOST_REQUIRE_EQUAL(r.head.block_num, fixture.server.block_head.block_num); - BOOST_REQUIRE(r.traces.has_value()); - BOOST_REQUIRE(r.deltas.has_value()); - auto traces = r.traces.value(); - auto deltas = r.deltas.value(); - auto& data = fixture.written_data[i]; - auto data_size = data.size() * sizeof(int32_t); - BOOST_REQUIRE_EQUAL(traces.size(), data_size); - BOOST_REQUIRE_EQUAL(deltas.size(), data_size); - - BOOST_REQUIRE(std::equal(traces.begin(), traces.end(), (const char*)data.data())); - BOOST_REQUIRE(std::equal(deltas.begin(), deltas.end(), (const char*)data.data())); if( fetch_finality_data ) { + BOOST_REQUIRE(std::holds_alternative(result)); + auto r = std::get(result); + BOOST_REQUIRE_EQUAL(r.head.block_num, fixture.server.block_head.block_num); + BOOST_REQUIRE(r.traces.has_value()); + BOOST_REQUIRE(r.deltas.has_value()); + auto traces = r.traces.value(); + auto deltas = r.deltas.value(); + auto& data = fixture.written_data[i]; + auto data_size = data.size() * sizeof(int32_t); + BOOST_REQUIRE_EQUAL(traces.size(), data_size); + BOOST_REQUIRE_EQUAL(deltas.size(), data_size); + + BOOST_REQUIRE(std::equal(traces.begin(), traces.end(), (const char*)data.data())); + BOOST_REQUIRE(std::equal(deltas.begin(), deltas.end(), (const char*)data.data())); + BOOST_REQUIRE(r.finality_data.has_value()); auto finality_data = r.finality_data.value(); BOOST_REQUIRE_EQUAL(finality_data.size(), data_size); BOOST_REQUIRE(std::equal(finality_data.begin(), finality_data.end(), (const char*)data.data())); + } else { + BOOST_REQUIRE(std::holds_alternative(result)); + auto r = std::get(result); + BOOST_REQUIRE_EQUAL(r.head.block_num, fixture.server.block_head.block_num); + BOOST_REQUIRE(r.traces.has_value()); + BOOST_REQUIRE(r.deltas.has_value()); + auto traces = r.traces.value(); + auto deltas = r.deltas.value(); + auto& data = fixture.written_data[i]; + auto data_size = data.size() * sizeof(int32_t); + BOOST_REQUIRE_EQUAL(traces.size(), data_size); + BOOST_REQUIRE_EQUAL(deltas.size(), data_size); + + BOOST_REQUIRE(std::equal(traces.begin(), traces.end(), (const char*)data.data())); + BOOST_REQUIRE(std::equal(deltas.begin(), deltas.end(), (const char*)data.data())); } } } @@ -681,29 +748,48 @@ void test_session_fork_impl(state_history_test_fixture& fixture, bool fetch_fina // we should get 4 consecutive block result for (uint32_t i = 0; i < 4; ++i) { fixture.receive_result(result); - BOOST_REQUIRE(std::holds_alternative(result)); - auto r = std::get(result); - BOOST_REQUIRE_EQUAL(r.head.block_num, fixture.server.block_head.block_num); - BOOST_REQUIRE(r.traces.has_value()); - BOOST_REQUIRE(r.deltas.has_value()); - auto traces = r.traces.value(); - auto deltas = r.deltas.value(); - auto& data = fixture.written_data[i]; - auto data_size = data.size() * sizeof(int32_t); - BOOST_REQUIRE_EQUAL(traces.size(), data_size); - BOOST_REQUIRE_EQUAL(deltas.size(), data_size); - BOOST_REQUIRE(r.this_block.has_value()); - BOOST_REQUIRE_EQUAL(r.this_block->block_num, i+1); - have_positions.push_back(*r.this_block); - - BOOST_REQUIRE(std::equal(traces.begin(), traces.end(), (const char*)data.data())); - BOOST_REQUIRE(std::equal(deltas.begin(), deltas.end(), (const char*)data.data())); if( fetch_finality_data ) { + BOOST_REQUIRE(std::holds_alternative(result)); + auto r = std::get(result); + BOOST_REQUIRE_EQUAL(r.head.block_num, fixture.server.block_head.block_num); + BOOST_REQUIRE(r.traces.has_value()); + BOOST_REQUIRE(r.deltas.has_value()); + auto traces = r.traces.value(); + auto deltas = r.deltas.value(); + auto& data = fixture.written_data[i]; + auto data_size = data.size() * sizeof(int32_t); + BOOST_REQUIRE_EQUAL(traces.size(), data_size); + BOOST_REQUIRE_EQUAL(deltas.size(), data_size); + BOOST_REQUIRE(r.this_block.has_value()); + BOOST_REQUIRE_EQUAL(r.this_block->block_num, i+1); + have_positions.push_back(*r.this_block); + + BOOST_REQUIRE(std::equal(traces.begin(), traces.end(), (const char*)data.data())); + BOOST_REQUIRE(std::equal(deltas.begin(), deltas.end(), (const char*)data.data())); + BOOST_REQUIRE(r.finality_data.has_value()); auto finality_data = r.finality_data.value(); BOOST_REQUIRE_EQUAL(finality_data.size(), data_size); BOOST_REQUIRE(std::equal(finality_data.begin(), finality_data.end(), (const char*)data.data())); + } else { + BOOST_REQUIRE(std::holds_alternative(result)); + auto r = std::get(result); + BOOST_REQUIRE_EQUAL(r.head.block_num, fixture.server.block_head.block_num); + BOOST_REQUIRE(r.traces.has_value()); + BOOST_REQUIRE(r.deltas.has_value()); + auto traces = r.traces.value(); + auto deltas = r.deltas.value(); + auto& data = fixture.written_data[i]; + auto data_size = data.size() * sizeof(int32_t); + BOOST_REQUIRE_EQUAL(traces.size(), data_size); + BOOST_REQUIRE_EQUAL(deltas.size(), data_size); + BOOST_REQUIRE(r.this_block.has_value()); + BOOST_REQUIRE_EQUAL(r.this_block->block_num, i+1); + have_positions.push_back(*r.this_block); + + BOOST_REQUIRE(std::equal(traces.begin(), traces.end(), (const char*)data.data())); + BOOST_REQUIRE(std::equal(deltas.begin(), deltas.end(), (const char*)data.data())); } } @@ -731,28 +817,46 @@ void test_session_fork_impl(state_history_test_fixture& fixture, bool fetch_fina // we should now get data for fork 3,4 for (uint32_t i = 2; i < 4; ++i) { fixture.receive_result(fork_result); - BOOST_REQUIRE(std::holds_alternative(fork_result)); - auto r = std::get(fork_result); - BOOST_REQUIRE_EQUAL(r.head.block_num, fixture.server.block_head.block_num); - BOOST_REQUIRE(r.this_block.has_value()); - BOOST_REQUIRE_EQUAL(r.this_block->block_num, i+1); - BOOST_REQUIRE(r.traces.has_value()); - BOOST_REQUIRE(r.deltas.has_value()); - auto traces = r.traces.value(); - auto deltas = r.deltas.value(); - auto& data = fixture.written_data[i]; - auto data_size = data.size() * sizeof(int32_t); - BOOST_REQUIRE_EQUAL(traces.size(), data_size); - BOOST_REQUIRE_EQUAL(deltas.size(), data_size); - - BOOST_REQUIRE(std::equal(traces.begin(), traces.end(), (const char*)data.data())); - BOOST_REQUIRE(std::equal(deltas.begin(), deltas.end(), (const char*)data.data())); if( fetch_finality_data ) { + BOOST_REQUIRE(std::holds_alternative(fork_result)); + auto r = std::get(fork_result); + BOOST_REQUIRE_EQUAL(r.head.block_num, fixture.server.block_head.block_num); + BOOST_REQUIRE(r.this_block.has_value()); + BOOST_REQUIRE_EQUAL(r.this_block->block_num, i+1); + BOOST_REQUIRE(r.traces.has_value()); + BOOST_REQUIRE(r.deltas.has_value()); + auto traces = r.traces.value(); + auto deltas = r.deltas.value(); + auto& data = fixture.written_data[i]; + auto data_size = data.size() * sizeof(int32_t); + BOOST_REQUIRE_EQUAL(traces.size(), data_size); + BOOST_REQUIRE_EQUAL(deltas.size(), data_size); + + BOOST_REQUIRE(std::equal(traces.begin(), traces.end(), (const char*)data.data())); + BOOST_REQUIRE(std::equal(deltas.begin(), deltas.end(), (const char*)data.data())); + BOOST_REQUIRE(r.finality_data.has_value()); auto finality_data = r.finality_data.value(); BOOST_REQUIRE_EQUAL(finality_data.size(), data_size); BOOST_REQUIRE(std::equal(finality_data.begin(), finality_data.end(), (const char*)data.data())); + } else { + BOOST_REQUIRE(std::holds_alternative(fork_result)); + auto r = std::get(fork_result); + BOOST_REQUIRE_EQUAL(r.head.block_num, fixture.server.block_head.block_num); + BOOST_REQUIRE(r.this_block.has_value()); + BOOST_REQUIRE_EQUAL(r.this_block->block_num, i+1); + BOOST_REQUIRE(r.traces.has_value()); + BOOST_REQUIRE(r.deltas.has_value()); + auto traces = r.traces.value(); + auto deltas = r.deltas.value(); + auto& data = fixture.written_data[i]; + auto data_size = data.size() * sizeof(int32_t); + BOOST_REQUIRE_EQUAL(traces.size(), data_size); + BOOST_REQUIRE_EQUAL(deltas.size(), data_size); + + BOOST_REQUIRE(std::equal(traces.begin(), traces.end(), (const char*)data.data())); + BOOST_REQUIRE(std::equal(deltas.begin(), deltas.end(), (const char*)data.data())); } } } diff --git a/tests/ship_streamer.cpp b/tests/ship_streamer.cpp index 039b0f9566..a0720b2b1d 100644 --- a/tests/ship_streamer.cpp +++ b/tests/ship_streamer.cpp @@ -142,7 +142,11 @@ int main(int argc, char* argv[]) { eosio::check(!result_document.HasParseError(), "Failed to parse result JSON from abieos"); eosio::check(result_document.IsArray(), "result should have been an array (variant) but it's not"); eosio::check(result_document.Size() == 2, "result was an array but did not contain 2 items like a variant should"); - eosio::check(std::string(result_document[0].GetString()) == "get_blocks_result_v0", "result type doesn't look like get_blocks_result_v0"); + if( fetch_finality_data ) { + eosio::check(std::string(result_document[0].GetString()) == "get_blocks_result_v1", "result type doesn't look like get_blocks_result_v1"); + } else { + eosio::check(std::string(result_document[0].GetString()) == "get_blocks_result_v0", "result type doesn't look like get_blocks_result_v0"); + } eosio::check(result_document[1].IsObject(), "second item in result array is not an object"); eosio::check(result_document[1].HasMember("head"), "cannot find 'head' in result"); eosio::check(result_document[1]["head"].IsObject(), "'head' is not an object"); @@ -158,7 +162,11 @@ int main(int argc, char* argv[]) { } else { std::cout << "," << std::endl; } - std::cout << "{ \"get_blocks_result_v0\":" << std::endl; + if( fetch_finality_data ) { + std::cout << "{ \"get_blocks_result_v1\":" << std::endl; + } else { + std::cout << "{ \"get_blocks_result_v0\":" << std::endl; + } rapidjson::StringBuffer result_sb; rapidjson::PrettyWriter result_writer(result_sb); From fe71f93b449aa4fd49efe67e6e6c21e8619cfe2e Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Wed, 27 Mar 2024 21:52:02 -0400 Subject: [PATCH 02/11] update ship_streamer_test to use get_blocks_result_v1 or get_blocks_result_v0 based on finality_data_history argument --- tests/ship_streamer_test.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/ship_streamer_test.py b/tests/ship_streamer_test.py index 4f4719efc9..eb5e53242c 100755 --- a/tests/ship_streamer_test.py +++ b/tests/ship_streamer_test.py @@ -211,11 +211,14 @@ def getLatestSnapshot(nodeId): block_num = start_block_num for i in data: # fork can cause block numbers to be repeated - this_block_num = i['get_blocks_result_v0']['this_block']['block_num'] + this_block_num = i['get_blocks_result_v1']['this_block']['block_num'] if args.finality_data_history else i['get_blocks_result_v0']['this_block']['block_num'] if this_block_num < block_num: block_num = this_block_num assert block_num == this_block_num, f"{block_num} != {this_block_num}" - assert isinstance(i['get_blocks_result_v0']['block'], str) # verify block in result + if args.finality_data_history: + assert isinstance(i['get_blocks_result_v1']['block'], str) # verify block in result + else: + assert isinstance(i['get_blocks_result_v0']['block'], str) # verify block in result block_num += 1 assert block_num-1 == end_block_num, f"{block_num-1} != {end_block_num}" @@ -268,11 +271,14 @@ def getLatestSnapshot(nodeId): block_num = start_block_num for i in data: # fork can cause block numbers to be repeated - this_block_num = i['get_blocks_result_v0']['this_block']['block_num'] + this_block_num = i['get_blocks_result_v1']['this_block']['block_num'] if args.finality_data_history else i['get_blocks_result_v0']['this_block']['block_num'] if this_block_num < block_num: block_num = this_block_num assert block_num == this_block_num, f"{block_num} != {this_block_num}" - assert isinstance(i['get_blocks_result_v0']['deltas'], str) # verify deltas in result + if args.finality_data_history: + assert isinstance(i['get_blocks_result_v1']['deltas'], str) # verify deltas in result + else: + assert isinstance(i['get_blocks_result_v0']['deltas'], str) # verify deltas in result block_num += 1 assert block_num-1 == end_block_num, f"{block_num-1} != {end_block_num}" From 81ede3c624a4c892c837597d87189d007cfae198 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Wed, 27 Mar 2024 22:00:48 -0400 Subject: [PATCH 03/11] set initial active_finalizer_policy_generation in finality_data to 1 --- libraries/chain/include/eosio/chain/block_state.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/include/eosio/chain/block_state.hpp b/libraries/chain/include/eosio/chain/block_state.hpp index f506d8ac08..05438c56fc 100644 --- a/libraries/chain/include/eosio/chain/block_state.hpp +++ b/libraries/chain/include/eosio/chain/block_state.hpp @@ -57,7 +57,7 @@ struct valid_t { struct finality_data_t { uint32_t major_version{light_header_protocol_version_major}; uint32_t minor_version{light_header_protocol_version_minor}; - uint32_t active_finalizer_policy_generation{0}; + uint32_t active_finalizer_policy_generation{1}; digest_type action_mroot{}; digest_type base_digest{}; }; From 37c3322dc20c6c2d61ff2d2b45ff2c960f104877 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Thu, 28 Mar 2024 10:46:14 -0400 Subject: [PATCH 04/11] simplify send_entryby factoring out result variant processing --- .../eosio/state_history_plugin/session.hpp | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/plugins/state_history_plugin/include/eosio/state_history_plugin/session.hpp b/plugins/state_history_plugin/include/eosio/state_history_plugin/session.hpp index 3e0f647352..7809405a5a 100644 --- a/plugins/state_history_plugin/include/eosio/state_history_plugin/session.hpp +++ b/plugins/state_history_plugin/include/eosio/state_history_plugin/session.hpp @@ -297,35 +297,38 @@ class blocks_result_send_queue_entry : public send_queue_entry_base, public std: }); } + template + void pack_result_base(const T& result, uint32_t variant_index) { + // pack the state_result{get_blocks_result} excluding the fields `traces` and `deltas`, + // and `finality_data` if get_blocks_result_v1 + fc::datastream ss; + + fc::raw::pack(ss, fc::unsigned_int(variant_index)); // pack the variant index of state_result{result} + fc::raw::pack(ss, static_cast(result)); + data.resize(ss.tellp()); + fc::datastream ds(data.data(), data.size()); + fc::raw::pack(ds, fc::unsigned_int(variant_index)); // pack the variant index of state_result{result} + fc::raw::pack(ds, static_cast(result)); + } + public: blocks_result_send_queue_entry(std::shared_ptr s, state_history::get_blocks_result&& r) : session(std::move(s)), result(std::move(r)) {} void send_entry() override { - assert(std::holds_alternative(result) || - std::holds_alternative(result)); + std::visit( + chain::overloaded{ + [&](state_history::get_blocks_result_v0& r) { + pack_result_base(r, 1); // 1 for variant index of get_blocks_result_v0 in state_result + }, + [&](state_history::get_blocks_result_v1& r) { + pack_result_base(r, 2); // 2 for variant index of get_blocks_result_v1 in state_result + } + }, + result + ); - // pack the state_result{get_blocks_result} excluding the fields `traces` and `deltas` - fc::datastream ss; - if(std::holds_alternative(result)) { - fc::raw::pack(ss, fc::unsigned_int(1)); // pack the variant index of state_result{r}, 1 for get_blocks_result_v0 - } else { - fc::raw::pack(ss, fc::unsigned_int(2)); // pack the variant index of state_result{r}, 2 for get_blocks_result_v1 - } - std::visit([&](auto& r) { - fc::raw::pack(ss, static_cast(r)); }, - result); - data.resize(ss.tellp()); - fc::datastream ds(data.data(), data.size()); - if(std::holds_alternative(result)) { - fc::raw::pack(ds, fc::unsigned_int(1)); // pack the variant index of state_result{r}, 1 for get_blocks_result_v0 - } else { - fc::raw::pack(ds, fc::unsigned_int(2)); // pack the variant index of state_result{r}, 2 for get_blocks_result_v1 - } - std::visit([&](auto& r) { - fc::raw::pack(ds, static_cast(r)); }, - result); async_send(false, data, [me=this->shared_from_this()]() { me->send_traces(); }); From 57b61b96fad47ae58af4f8d063e82242525e9794 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Thu, 28 Mar 2024 11:41:14 -0400 Subject: [PATCH 05/11] use common code to serialize get_blocks_result_v0 and get_blocks_result_v1 --- .../include/eosio/state_history/serialization.hpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/libraries/state_history/include/eosio/state_history/serialization.hpp b/libraries/state_history/include/eosio/state_history/serialization.hpp index a20200c61f..9b6bad8e3f 100644 --- a/libraries/state_history/include/eosio/state_history/serialization.hpp +++ b/libraries/state_history/include/eosio/state_history/serialization.hpp @@ -709,11 +709,7 @@ datastream& operator<<(datastream& ds, const history_context_wrapper_sta template datastream& operator<<(datastream& ds, const eosio::state_history::get_blocks_result_v0& obj) { - fc::raw::pack(ds, obj.head); - fc::raw::pack(ds, obj.last_irreversible); - fc::raw::pack(ds, obj.this_block); - fc::raw::pack(ds, obj.prev_block); - history_pack_big_bytes(ds, obj.block); + ds << static_cast(obj); history_pack_big_bytes(ds, obj.traces); history_pack_big_bytes(ds, obj.deltas); return ds; @@ -721,13 +717,7 @@ datastream& operator<<(datastream& ds, const eosio::state_history::get_b template datastream& operator<<(datastream& ds, const eosio::state_history::get_blocks_result_v1& obj) { - fc::raw::pack(ds, obj.head); - fc::raw::pack(ds, obj.last_irreversible); - fc::raw::pack(ds, obj.this_block); - fc::raw::pack(ds, obj.prev_block); - history_pack_big_bytes(ds, obj.block); - history_pack_big_bytes(ds, obj.traces); - history_pack_big_bytes(ds, obj.deltas); + ds << static_cast(obj); history_pack_big_bytes(ds, obj.finality_data); return ds; } From 93905c3f2a165bb5e29a51c22451cb2914396b19 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Thu, 28 Mar 2024 11:42:04 -0400 Subject: [PATCH 06/11] use T&& result for send_update --- .../include/eosio/state_history_plugin/session.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/state_history_plugin/include/eosio/state_history_plugin/session.hpp b/plugins/state_history_plugin/include/eosio/state_history_plugin/session.hpp index 7809405a5a..bba06d85ef 100644 --- a/plugins/state_history_plugin/include/eosio/state_history_plugin/session.hpp +++ b/plugins/state_history_plugin/include/eosio/state_history_plugin/session.hpp @@ -541,7 +541,7 @@ struct session : session_base, std::enable_shared_from_this // get_blocks_result_v0 or get_blocks_result_v1 - void send_update(state_history::get_blocks_request_v0& request, bool fetch_finality_data, T result, const chain::signed_block_ptr& block, const chain::block_id_type& id) { + void send_update(state_history::get_blocks_request_v0& request, bool fetch_finality_data, T&& result, const chain::signed_block_ptr& block, const chain::block_id_type& id) { need_to_send_update = true; result.last_irreversible = plugin.get_last_irreversible(); From f68869a3267eb33050c893a76589715d2f964c54 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Thu, 28 Mar 2024 14:19:06 -0400 Subject: [PATCH 07/11] static_assert the variant index is correct for get_blocks_result_v0 and get_blocks_result_v1 --- .../include/eosio/state_history_plugin/session.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/state_history_plugin/include/eosio/state_history_plugin/session.hpp b/plugins/state_history_plugin/include/eosio/state_history_plugin/session.hpp index bba06d85ef..1fbb2ed023 100644 --- a/plugins/state_history_plugin/include/eosio/state_history_plugin/session.hpp +++ b/plugins/state_history_plugin/include/eosio/state_history_plugin/session.hpp @@ -320,9 +320,11 @@ class blocks_result_send_queue_entry : public send_queue_entry_base, public std: std::visit( chain::overloaded{ [&](state_history::get_blocks_result_v0& r) { + static_assert(std::is_same_v>); pack_result_base(r, 1); // 1 for variant index of get_blocks_result_v0 in state_result }, [&](state_history::get_blocks_result_v1& r) { + static_assert(std::is_same_v>); pack_result_base(r, 2); // 2 for variant index of get_blocks_result_v1 in state_result } }, From 9480cf8c87483d2b3dc59072750d1df0786a0aac Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Thu, 28 Mar 2024 14:20:28 -0400 Subject: [PATCH 08/11] Only use get_blocks_request_v1 and get_blocks_result_v1 for ship_streamer tests --- tests/ship_streamer.cpp | 14 ++------------ tests/ship_streamer_test.py | 14 ++++---------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/tests/ship_streamer.cpp b/tests/ship_streamer.cpp index a0720b2b1d..44eb9f2bb0 100644 --- a/tests/ship_streamer.cpp +++ b/tests/ship_streamer.cpp @@ -93,11 +93,7 @@ int main(int argc, char* argv[]) { //}; request_writer.StartArray(); - if( fetch_finality_data ) { - request_writer.String("get_blocks_request_v1"); - } else { - request_writer.String("get_blocks_request_v0"); - } + request_writer.String("get_blocks_request_v1"); // always send out latest version of request request_writer.StartObject(); request_writer.Key("start_block_num"); request_writer.Uint(start_block_num); @@ -144,8 +140,6 @@ int main(int argc, char* argv[]) { eosio::check(result_document.Size() == 2, "result was an array but did not contain 2 items like a variant should"); if( fetch_finality_data ) { eosio::check(std::string(result_document[0].GetString()) == "get_blocks_result_v1", "result type doesn't look like get_blocks_result_v1"); - } else { - eosio::check(std::string(result_document[0].GetString()) == "get_blocks_result_v0", "result type doesn't look like get_blocks_result_v0"); } eosio::check(result_document[1].IsObject(), "second item in result array is not an object"); eosio::check(result_document[1].HasMember("head"), "cannot find 'head' in result"); @@ -162,11 +156,7 @@ int main(int argc, char* argv[]) { } else { std::cout << "," << std::endl; } - if( fetch_finality_data ) { - std::cout << "{ \"get_blocks_result_v1\":" << std::endl; - } else { - std::cout << "{ \"get_blocks_result_v0\":" << std::endl; - } + std::cout << "{ \"get_blocks_result_v1\":" << std::endl; rapidjson::StringBuffer result_sb; rapidjson::PrettyWriter result_writer(result_sb); diff --git a/tests/ship_streamer_test.py b/tests/ship_streamer_test.py index eb5e53242c..8b92397ef7 100755 --- a/tests/ship_streamer_test.py +++ b/tests/ship_streamer_test.py @@ -211,14 +211,11 @@ def getLatestSnapshot(nodeId): block_num = start_block_num for i in data: # fork can cause block numbers to be repeated - this_block_num = i['get_blocks_result_v1']['this_block']['block_num'] if args.finality_data_history else i['get_blocks_result_v0']['this_block']['block_num'] + this_block_num = i['get_blocks_result_v1']['this_block']['block_num'] if this_block_num < block_num: block_num = this_block_num assert block_num == this_block_num, f"{block_num} != {this_block_num}" - if args.finality_data_history: - assert isinstance(i['get_blocks_result_v1']['block'], str) # verify block in result - else: - assert isinstance(i['get_blocks_result_v0']['block'], str) # verify block in result + assert isinstance(i['get_blocks_result_v1']['block'], str) # verify block in result block_num += 1 assert block_num-1 == end_block_num, f"{block_num-1} != {end_block_num}" @@ -271,14 +268,11 @@ def getLatestSnapshot(nodeId): block_num = start_block_num for i in data: # fork can cause block numbers to be repeated - this_block_num = i['get_blocks_result_v1']['this_block']['block_num'] if args.finality_data_history else i['get_blocks_result_v0']['this_block']['block_num'] + this_block_num = i['get_blocks_result_v1']['this_block']['block_num'] if this_block_num < block_num: block_num = this_block_num assert block_num == this_block_num, f"{block_num} != {this_block_num}" - if args.finality_data_history: - assert isinstance(i['get_blocks_result_v1']['deltas'], str) # verify deltas in result - else: - assert isinstance(i['get_blocks_result_v0']['deltas'], str) # verify deltas in result + assert isinstance(i['get_blocks_result_v1']['deltas'], str) # verify deltas in result block_num += 1 assert block_num-1 == end_block_num, f"{block_num-1} != {end_block_num}" From 789dfee0d060c730b10b064839b2d44f7bc9ace1 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Thu, 28 Mar 2024 14:32:10 -0400 Subject: [PATCH 09/11] remove unnecessary if( fetch_finality_data ) --- tests/ship_streamer.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/ship_streamer.cpp b/tests/ship_streamer.cpp index 44eb9f2bb0..7ac51c4305 100644 --- a/tests/ship_streamer.cpp +++ b/tests/ship_streamer.cpp @@ -138,9 +138,7 @@ int main(int argc, char* argv[]) { eosio::check(!result_document.HasParseError(), "Failed to parse result JSON from abieos"); eosio::check(result_document.IsArray(), "result should have been an array (variant) but it's not"); eosio::check(result_document.Size() == 2, "result was an array but did not contain 2 items like a variant should"); - if( fetch_finality_data ) { - eosio::check(std::string(result_document[0].GetString()) == "get_blocks_result_v1", "result type doesn't look like get_blocks_result_v1"); - } + eosio::check(std::string(result_document[0].GetString()) == "get_blocks_result_v1", "result type doesn't look like get_blocks_result_v1"); eosio::check(result_document[1].IsObject(), "second item in result array is not an object"); eosio::check(result_document[1].HasMember("head"), "cannot find 'head' in result"); eosio::check(result_document[1]["head"].IsObject(), "'head' is not an object"); From 51e93797c2b303f880dd6dce221ac985a6d76b5f Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Thu, 28 Mar 2024 15:22:16 -0400 Subject: [PATCH 10/11] Update nodeos_forked_chain_test.py to use get_blocks_result_v1 instead of get_blocks_result_v0 --- tests/nodeos_forked_chain_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/nodeos_forked_chain_test.py b/tests/nodeos_forked_chain_test.py index e4efc3dd64..d2ba089e53 100755 --- a/tests/nodeos_forked_chain_test.py +++ b/tests/nodeos_forked_chain_test.py @@ -598,11 +598,11 @@ def getBlock(self, blockNum): block_num = start_block_num for i in data: # fork can cause block numbers to be repeated - this_block_num = i['get_blocks_result_v0']['this_block']['block_num'] + this_block_num = i['get_blocks_result_v1']['this_block']['block_num'] if this_block_num < block_num: block_num = this_block_num assert block_num == this_block_num, f"{block_num} != {this_block_num}" - assert isinstance(i['get_blocks_result_v0']['block'], str) # verify block in result + assert isinstance(i['get_blocks_result_v1']['block'], str) # verify block in result block_num += 1 assert block_num-1 == end_block_num, f"{block_num-1} != {end_block_num}" From 9cc6f747dfebebe5b3125af7d0be2c18944783cf Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Thu, 28 Mar 2024 16:46:57 -0400 Subject: [PATCH 11/11] always provide fetch_finality_data field for get_blocks_request_v1 --- tests/ship_streamer.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/ship_streamer.cpp b/tests/ship_streamer.cpp index 7ac51c4305..0c2be248a3 100644 --- a/tests/ship_streamer.cpp +++ b/tests/ship_streamer.cpp @@ -112,10 +112,8 @@ int main(int argc, char* argv[]) { request_writer.Bool(fetch_traces); request_writer.Key("fetch_deltas"); request_writer.Bool(fetch_deltas); - if( fetch_finality_data ) { - request_writer.Key("fetch_finality_data"); - request_writer.Bool(fetch_finality_data); - } + request_writer.Key("fetch_finality_data"); + request_writer.Bool(fetch_finality_data); request_writer.EndObject(); request_writer.EndArray();