Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport dfuse support #38

Merged
merged 13 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ else()
endif()
endif()

option(EOSIO_ENABLE_DEVELOPER_OPTIONS "enable developer options for EOSIO" OFF)

# based on http://www.delorie.com/gnu/docs/gdb/gdb_70.html
# uncomment this line to tell GDB about macros (slows compile times)
# set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -gdwarf-2 -g3" )
Expand Down
2 changes: 1 addition & 1 deletion libraries/appbase
Submodule appbase updated 1 files
+25 −0 application.cpp
2 changes: 2 additions & 0 deletions libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,13 @@ add_library( eosio_chain
abi_serializer.cpp
asset.cpp
snapshot.cpp
deep_mind.cpp

${CHAIN_EOSVMOC_SOURCES}
${CHAIN_EOSVM_SOURCES}
${CHAIN_WEBASSEMBLY_SOURCES}

authority.cpp
trace.cpp
transaction_metadata.cpp
protocol_state_object.cpp
Expand Down
123 changes: 123 additions & 0 deletions libraries/chain/apply_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <eosio/chain/account_object.hpp>
#include <eosio/chain/code_object.hpp>
#include <eosio/chain/global_property_object.hpp>
#include <eosio/chain/deep_mind.hpp>
#include <boost/container/flat_set.hpp>

using boost::container::flat_set;
Expand Down Expand Up @@ -179,6 +180,11 @@ void apply_context::exec_one()
if ( control.contracts_console() ) {
print_debug(receiver, trace);
}

if (auto dm_logger = control.get_deep_mind_logger())
{
dm_logger->on_end_action();
}
}

void apply_context::finalize_trace( action_trace& trace, const fc::time_point& start )
Expand Down Expand Up @@ -281,6 +287,10 @@ void apply_context::require_recipient( account_name recipient ) {
recipient,
schedule_action( action_ordinal, recipient, false )
);

if (auto dm_logger = control.get_deep_mind_logger()) {
dm_logger->on_require_recipient();
}
}
}

Expand Down Expand Up @@ -381,6 +391,10 @@ void apply_context::execute_inline( action&& a ) {
_inline_actions.emplace_back(
schedule_action( std::move(a), inline_receiver, false )
);

if (auto dm_logger = control.get_deep_mind_logger()) {
dm_logger->on_send_inline();
}
}

void apply_context::execute_context_free_inline( action&& a ) {
Expand All @@ -402,6 +416,10 @@ void apply_context::execute_context_free_inline( action&& a ) {
_cfa_inline_actions.emplace_back(
schedule_action( std::move(a), inline_receiver, true )
);

if (auto dm_logger = control.get_deep_mind_logger()) {
dm_logger->on_send_context_free_inline();
}
}


Expand Down Expand Up @@ -537,6 +555,10 @@ void apply_context::schedule_deferred_transaction( const uint128_t& sender_id, a
subjective_block_production_exception,
"Replacing a deferred transaction is temporarily disabled." );

if (auto dm_logger = control.get_deep_mind_logger()) {
dm_logger->on_ram_trace(RAM_EVENT_ID("${id}", ("id", ptr->id)), "deferred_trx", "cancel", "deferred_trx_cancel");
}

uint64_t orig_trx_ram_bytes = config::billable_size_v<generated_transaction_object> + ptr->packed_trx.size();
if( replace_deferred_activated ) {
add_ram_usage( ptr->payer, -static_cast<int64_t>( orig_trx_ram_bytes ) );
Expand All @@ -551,6 +573,10 @@ void apply_context::schedule_deferred_transaction( const uint128_t& sender_id, a
trx_id_for_new_obj = ptr->trx_id;
}

if (auto dm_logger = control.get_deep_mind_logger()) {
dm_logger->on_cancel_deferred(deep_mind_handler::operation_qualifier::modify, *ptr);
}

// Use remove and create rather than modify because mutating the trx_id field in a modifier is unsafe.
db.remove( *ptr );
db.create<generated_transaction_object>( [&]( auto& gtx ) {
Expand All @@ -563,6 +589,11 @@ void apply_context::schedule_deferred_transaction( const uint128_t& sender_id, a
gtx.expiration = gtx.delay_until + fc::seconds(control.get_global_properties().configuration.deferred_trx_expiration_window);

trx_size = gtx.set( trx );

if (auto dm_logger = control.get_deep_mind_logger()) {
dm_logger->on_send_deferred(deep_mind_handler::operation_qualifier::modify, gtx);
dm_logger->on_ram_trace(RAM_EVENT_ID("${id}", ("id", gtx.id)), "deferred_trx", "update", "deferred_trx_add");
}
} );
} else {
db.create<generated_transaction_object>( [&]( auto& gtx ) {
Expand All @@ -575,6 +606,11 @@ void apply_context::schedule_deferred_transaction( const uint128_t& sender_id, a
gtx.expiration = gtx.delay_until + fc::seconds(control.get_global_properties().configuration.deferred_trx_expiration_window);

trx_size = gtx.set( trx );

if (auto dm_logger = control.get_deep_mind_logger()) {
dm_logger->on_send_deferred(deep_mind_handler::operation_qualifier::none, gtx);
dm_logger->on_ram_trace(RAM_EVENT_ID("${id}", ("id", gtx.id)), "deferred_trx", "add", "deferred_trx_add");
}
} );
}

Expand All @@ -591,6 +627,11 @@ bool apply_context::cancel_deferred_transaction( const uint128_t& sender_id, acc
auto& generated_transaction_idx = db.get_mutable_index<generated_transaction_multi_index>();
const auto* gto = db.find<generated_transaction_object,by_sender_id>(boost::make_tuple(sender, sender_id));
if ( gto ) {
if (auto dm_logger = control.get_deep_mind_logger()) {
dm_logger->on_cancel_deferred(deep_mind_handler::operation_qualifier::none, *gto);
dm_logger->on_ram_trace(RAM_EVENT_ID("${id}", ("id", gto->id)), "deferred_trx", "cancel", "deferred_trx_cancel");
}

add_ram_usage( gto->payer, -(config::billable_size_v<generated_transaction_object> + gto->packed_trx.size()) );
generated_transaction_idx.remove(*gto);
}
Expand Down Expand Up @@ -627,18 +668,45 @@ const table_id_object& apply_context::find_or_create_table( name code, name scop
return *existing_tid;
}

if (auto dm_logger = control.get_deep_mind_logger()) {
std::string event_id = RAM_EVENT_ID("${code}:${scope}:${table}",
("code", code)
("scope", scope)
("table", table)
);
dm_logger->on_ram_trace(std::move(event_id), "table", "add", "create_table");
}

update_db_usage(payer, config::billable_size_v<table_id_object>);

return db.create<table_id_object>([&](table_id_object &t_id){
t_id.code = code;
t_id.scope = scope;
t_id.table = table;
t_id.payer = payer;

if (auto dm_logger = control.get_deep_mind_logger()) {
dm_logger->on_create_table(t_id);
}
});
}

void apply_context::remove_table( const table_id_object& tid ) {
if (auto dm_logger = control.get_deep_mind_logger()) {
std::string event_id = RAM_EVENT_ID("${code}:${scope}:${table}",
("code", tid.code)
("scope", tid.scope)
("table", tid.table)
);
dm_logger->on_ram_trace(std::move(event_id), "table", "remove", "remove_table");
}

update_db_usage(tid.payer, - config::billable_size_v<table_id_object>);

if (auto dm_logger = control.get_deep_mind_logger()) {
dm_logger->on_remove_table(tid);
}

db.remove(tid);
}

Expand Down Expand Up @@ -735,8 +803,23 @@ int apply_context::db_store_i64( name code, name scope, name table, const accoun
});

int64_t billable_size = (int64_t)(buffer_size + config::billable_size_v<key_value_object>);

if (auto dm_logger = control.get_deep_mind_logger()) {
std::string event_id = RAM_EVENT_ID("${table_code}:${scope}:${table_name}:${primkey}",
("table_code", tab.code)
("scope", tab.scope)
("table_name", tab.table)
("primkey", name(obj.primary_key))
);
dm_logger->on_ram_trace(std::move(event_id), "table_row", "add", "primary_index_add");
}

update_db_usage( payer, billable_size);

if (auto dm_logger = control.get_deep_mind_logger()) {
dm_logger->on_db_store_i64(tab, obj);
}

keyval_cache.cache_table( tab );
return keyval_cache.add( obj );
}
Expand All @@ -755,16 +838,42 @@ void apply_context::db_update_i64( int iterator, account_name payer, const char*

if( payer == account_name() ) payer = obj.payer;

std::string event_id;
if (control.get_deep_mind_logger() != nullptr) {
event_id = RAM_EVENT_ID("${table_code}:${scope}:${table_name}:${primkey}",
("table_code", table_obj.code)
("scope", table_obj.scope)
("table_name", table_obj.table)
("primkey", name(obj.primary_key))
);
}

if( account_name(obj.payer) != payer ) {
// refund the existing payer
if (auto dm_logger = control.get_deep_mind_logger())
{
dm_logger->on_ram_trace(std::string(event_id), "table_row", "remove", "primary_index_update_remove_old_payer");
}
update_db_usage( obj.payer, -(old_size) );
// charge the new payer
if (auto dm_logger = control.get_deep_mind_logger())
{
dm_logger->on_ram_trace(std::move(event_id), "table_row", "add", "primary_index_update_add_new_payer");
}
update_db_usage( payer, (new_size));
} else if(old_size != new_size) {
// charge/refund the existing payer the difference
if (auto dm_logger = control.get_deep_mind_logger())
{
dm_logger->on_ram_trace(std::move(event_id) , "table_row", "update", "primary_index_update");
}
update_db_usage( obj.payer, new_size - old_size);
}

if (auto dm_logger = control.get_deep_mind_logger()) {
dm_logger->on_db_update_i64(table_obj, obj, payer, buffer, buffer_size);
}

db.modify( obj, [&]( auto& o ) {
o.value.assign( buffer, buffer_size );
o.payer = payer;
Expand All @@ -779,8 +888,22 @@ void apply_context::db_remove_i64( int iterator ) {

// require_write_lock( table_obj.scope );

if (auto dm_logger = control.get_deep_mind_logger()) {
std::string event_id = RAM_EVENT_ID("${table_code}:${scope}:${table_name}:${primkey}",
("table_code", table_obj.code)
("scope", table_obj.scope)
("table_name", table_obj.table)
("primkey", name(obj.primary_key))
);
dm_logger->on_ram_trace(std::move(event_id), "table_row", "remove", "primary_index_remove");
}

update_db_usage( obj.payer, -(obj.value.size() + config::billable_size_v<key_value_object>) );

if (auto dm_logger = control.get_deep_mind_logger()) {
dm_logger->on_db_remove_i64(table_obj, obj);
}

db.modify( table_obj, [&]( auto& t ) {
--t.count;
});
Expand Down
7 changes: 7 additions & 0 deletions libraries/chain/authority.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <eosio/chain/authority.hpp>

namespace fc {
void to_variant(const eosio::chain::shared_public_key& var, fc::variant& vo) {
vo = var.to_string();
}
} // namespace fc
25 changes: 25 additions & 0 deletions libraries/chain/authorization_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <boost/tuple/tuple_io.hpp>
#include <eosio/chain/database_utils.hpp>
#include <eosio/chain/protocol_state_object.hpp>
#include <eosio/chain/deep_mind.hpp>


namespace eosio { namespace chain {
Expand Down Expand Up @@ -156,6 +157,10 @@ namespace eosio { namespace chain {
p.name = name;
p.last_updated = creation_time;
p.auth = auth;

if (auto dm_logger = _control.get_deep_mind_logger()) {
dm_logger->on_create_permission(p);
}
});
return perm;
}
Expand Down Expand Up @@ -187,6 +192,10 @@ namespace eosio { namespace chain {
p.name = name;
p.last_updated = creation_time;
p.auth = std::move(auth);

if (auto dm_logger = _control.get_deep_mind_logger()) {
dm_logger->on_create_permission(p);
}
});
return perm;
}
Expand All @@ -197,8 +206,19 @@ namespace eosio { namespace chain {
"Unactivated key type used when modifying permission");

_db.modify( permission, [&](permission_object& po) {
auto dm_logger = _control.get_deep_mind_logger();

std::optional<permission_object> old_permission;
if (dm_logger) {
old_permission = po;
}

po.auth = auth;
po.last_updated = _control.pending_block_time();

if (auto dm_logger = _control.get_deep_mind_logger()) {
dm_logger->on_modify_permission(*old_permission, po);
}
});
}

Expand All @@ -209,6 +229,11 @@ namespace eosio { namespace chain {
"Cannot remove a permission which has children. Remove the children first.");

_db.get_mutable_index<permission_usage_index>().remove_object( permission.usage_id._id );

if (auto dm_logger = _control.get_deep_mind_logger()) {
dm_logger->on_remove_permission(permission);
}

_db.remove( permission );
}

Expand Down
Loading