Skip to content

Commit

Permalink
GH-16 Add deep-mind ACCEPTED_BLOCK_V2
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Apr 15, 2024
1 parent 8ae27a1 commit 4bff371
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
21 changes: 11 additions & 10 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>(chain_head, [&](const auto& head) {
#warning todo: support deep_mind_logger even when in IF mode
if constexpr (std::is_same_v<block_state_legacy_ptr, typename std::decay_t<decltype(head)>>) {
// 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<void>([&](auto& forkdb) {
assert(std::holds_alternative<std::decay_t<decltype(forkdb.head())>>(cb.bsp.internal()));
Expand All @@ -3202,6 +3192,17 @@ struct controller_impl {
apply_s<void>(chain_head, [&](const auto& head) { create_and_send_vote_msg(head); });
}

apply<void>(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<block_state_legacy_ptr, typename std::decay_t<decltype(head)>>) {
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();
Expand Down
14 changes: 14 additions & 0 deletions libraries/chain/deep_mind.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <eosio/chain/deep_mind.hpp>
#include <eosio/chain/block_state_legacy.hpp>
#include <eosio/chain/block_state.hpp>
#include <eosio/chain/generated_transaction_object.hpp>
#include <eosio/chain/contract_table_objects.hpp>
#include <eosio/chain/resource_limits_private.hpp>
Expand Down Expand Up @@ -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}",
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/eosio/chain/block_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct valid_t {
std::vector<digest_type> 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};
Expand Down
3 changes: 3 additions & 0 deletions libraries/chain/include/eosio/chain/deep_mind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <fc/log/logger.hpp>

#include <eosio/chain/types.hpp>
#include <eosio/chain/block.hpp>

namespace eosio::chain {

Expand All @@ -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;
Expand Down Expand Up @@ -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<block_state_legacy>& 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);
Expand Down

0 comments on commit 4bff371

Please sign in to comment.