From 4bff371d7a8fd3b132ea8a8ac379f6270bd7cc73 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Mon, 15 Apr 2024 09:21:53 -0500 Subject: [PATCH] GH-16 Add deep-mind ACCEPTED_BLOCK_V2 --- libraries/chain/controller.cpp | 21 ++++++++++--------- libraries/chain/deep_mind.cpp | 14 +++++++++++++ .../chain/include/eosio/chain/block_state.hpp | 2 +- .../chain/include/eosio/chain/deep_mind.hpp | 3 +++ 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 613a7fb16b..4b73cfb954 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -3167,16 +3167,6 @@ struct controller_impl { chain_head = block_handle{cb.bsp}; emit( accepted_block, std::tie(chain_head.block(), chain_head.id()) ); - apply(chain_head, [&](const auto& head) { -#warning todo: support deep_mind_logger even when in IF mode - if constexpr (std::is_same_v>) { - // at block level, no transaction specific logging is possible - if (auto* dm_logger = get_deep_mind_logger(false)) { - dm_logger->on_accepted_block(head); - } - } - }); - if( s == controller::block_status::incomplete ) { fork_db.apply_s([&](auto& forkdb) { assert(std::holds_alternative>(cb.bsp.internal())); @@ -3202,6 +3192,17 @@ struct controller_impl { apply_s(chain_head, [&](const auto& head) { create_and_send_vote_msg(head); }); } + apply(chain_head, [&](const auto& head) { + if (auto* dm_logger = get_deep_mind_logger(false)) { + auto fd = head_finality_data(); + if constexpr (std::is_same_v>) { + dm_logger->on_accepted_block(head); + } else { + assert(fd); + dm_logger->on_accepted_block_v2(fork_db_root_block_num(), head->block, *fd); + } + } + }); if (s == controller::block_status::incomplete) { const auto& id = chain_head.id(); diff --git a/libraries/chain/deep_mind.cpp b/libraries/chain/deep_mind.cpp index 3714adf6ce..308b047004 100644 --- a/libraries/chain/deep_mind.cpp +++ b/libraries/chain/deep_mind.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -82,6 +83,19 @@ namespace eosio::chain { ); } + void deep_mind_handler::on_accepted_block_v2(block_num_type lib, const signed_block_ptr& b, const finality_data_t& fd) + { + auto packed_blk = fc::raw::pack(*b); + auto finality_data = fc::raw::pack(fd); + + fc_dlog(_logger, "ACCEPTED_BLOCK_V2 ${num} ${lib} ${blk} ${fd}", + ("num", b->block_num()) + ("lib", lib) + ("blk", fc::to_hex(packed_blk)) + ("fd", fc::to_hex(finality_data)) + ); + } + void deep_mind_handler::on_switch_forks(const block_id_type& old_head, const block_id_type& new_head) { fc_dlog(_logger, "SWITCH_FORK ${from_id} ${to_id}", diff --git a/libraries/chain/include/eosio/chain/block_state.hpp b/libraries/chain/include/eosio/chain/block_state.hpp index a212f1655f..4b51da8443 100644 --- a/libraries/chain/include/eosio/chain/block_state.hpp +++ b/libraries/chain/include/eosio/chain/block_state.hpp @@ -55,7 +55,7 @@ struct valid_t { std::vector validation_mroots; }; -// This is mostly used by SHiP to stream finality_data +// This is mostly used by SHiP & deep-mind to stream finality_data struct finality_data_t { uint32_t major_version{light_header_protocol_version_major}; uint32_t minor_version{light_header_protocol_version_minor}; diff --git a/libraries/chain/include/eosio/chain/deep_mind.hpp b/libraries/chain/include/eosio/chain/deep_mind.hpp index ba630440a4..08bffa129e 100644 --- a/libraries/chain/include/eosio/chain/deep_mind.hpp +++ b/libraries/chain/include/eosio/chain/deep_mind.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace eosio::chain { @@ -17,6 +18,7 @@ struct signed_transaction; struct packed_transaction; struct transaction_trace; struct ram_trace; +struct finality_data_t; namespace resource_limits { class resource_limits_config_object; class resource_limits_state_object; @@ -57,6 +59,7 @@ class deep_mind_handler void on_startup(chainbase::database& db, uint32_t head_block_num); void on_start_block(uint32_t block_num); void on_accepted_block(const std::shared_ptr& bsp); + void on_accepted_block_v2(block_num_type lib, const signed_block_ptr& b, const finality_data_t& fd); void on_switch_forks(const block_id_type& old_head, const block_id_type& new_head); void on_onerror(const signed_transaction& etrx); void on_onblock(const signed_transaction& trx);