Skip to content

Commit

Permalink
Merge pull request #9252 from EOSIO/transaction-logging-rel-2.0.x
Browse files Browse the repository at this point in the history
Transaction logging rel 2.0.x
  • Loading branch information
huangminghuang authored Jun 29, 2020
2 parents be079b4 + 4230e18 commit f6b238b
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 19 deletions.
1 change: 1 addition & 0 deletions docs/01_nodeos/06_logging/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ The logging library built into EOSIO currently supports the following loggers:
- `http_plugin` - detailed logging for the http plugin.
- `producer_plugin` - detailed logging for the producer plugin.
- `transaction_tracing` - detailed log that emits verdicts from relay nodes on the P2P network.
- `transaction_failure_tracing` - detailed log that emits failed verdicts from relay nodes on the P2P network.
- `trace_api` - detailed logging for the trace_api plugin.

The configuration options are:
Expand Down
5 changes: 3 additions & 2 deletions plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2852,8 +2852,9 @@ namespace eosio {

uint32_t trx_in_progress_sz = this->trx_in_progress_size.load();
if( trx_in_progress_sz > def_max_trx_in_progress_size ) {
fc_wlog( logger, "Dropping trx ${id}, too many trx in progress ${s} bytes",
("id", tid)("s", trx_in_progress_sz) );
char reason[72];
snprintf(reason, 72, "Dropping trx, too many trx in progress %lu bytes", (unsigned long) trx_in_progress_sz);
my_impl->producer_plug->log_failed_transaction(tid, reason);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ class producer_plugin : public appbase::plugin<producer_plugin> {

get_account_ram_corrections_result get_account_ram_corrections( const get_account_ram_corrections_params& params ) const;

private:
void log_failed_transaction(const transaction_id_type& trx_id, const char* reason) const;

private:
std::shared_ptr<class producer_plugin_impl> my;
};

Expand Down
68 changes: 52 additions & 16 deletions plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ using boost::signals2::scoped_connection;
const fc::string logger_name("producer_plugin");
fc::logger _log;

const fc::string trx_trace_logger_name("transaction_tracing");
fc::logger _trx_trace_log;
const fc::string trx_successful_trace_logger_name("transaction_tracing");
fc::logger _trx_successful_trace_log;

const fc::string trx_failed_trace_logger_name("transaction_failure_tracing");
fc::logger _trx_failed_trace_log;

namespace eosio {

Expand Down Expand Up @@ -462,17 +465,28 @@ class producer_plugin_impl : public std::enable_shared_from_this<producer_plugin

auto future = transaction_metadata::start_recover_keys( trx, _thread_pool->get_executor(),
chain.get_chain_id(), fc::microseconds( max_trx_cpu_usage ), chain.configured_subjective_signature_length_limit() );
boost::asio::post( _thread_pool->get_executor(), [self = this, future{std::move(future)}, persist_until_expired, next{std::move(next)}]() mutable {

auto trx_id = trx->id();
boost::asio::post(_thread_pool->get_executor(), [self = this, future{std::move(future)}, persist_until_expired,
next{std::move(next)}, trx_id]() mutable {
if( future.valid() ) {
future.wait();
app().post( priority::low, [self, future{std::move(future)}, persist_until_expired, next{std::move( next )}]() mutable {
app().post( priority::low, [self, future{std::move(future)}, persist_until_expired, next{std::move( next )}, trx_id]() mutable {
auto exception_handler = [&next, trx_id](fc::exception_ptr ex) {
fc_dlog(_trx_successful_trace_log, "[TRX_TRACE] Speculative execution is REJECTING tx: ${txid} : ${why} ",
("txid", trx_id)("why",ex->what()));
fc_dlog(_trx_failed_trace_log, "[TRX_TRACE] Speculative execution is REJECTING tx: ${txid} : ${why} ",
("txid", trx_id)("why",ex->what()));
next(ex);
};
try {
if( !self->process_incoming_transaction_async( future.get(), persist_until_expired, std::move( next ) ) ) {
auto result = future.get();
if( !self->process_incoming_transaction_async( result, persist_until_expired, next ) ) {
if( self->_pending_block_mode == pending_block_mode::producing ) {
self->schedule_maybe_produce_block( true );
}
}
} CATCH_AND_CALL(next);
} CATCH_AND_CALL(exception_handler);
} );
}
});
Expand All @@ -487,25 +501,33 @@ class producer_plugin_impl : public std::enable_shared_from_this<producer_plugin
if (response.contains<fc::exception_ptr>()) {
_transaction_ack_channel.publish(priority::low, std::pair<fc::exception_ptr, transaction_metadata_ptr>(response.get<fc::exception_ptr>(), trx));
if (_pending_block_mode == pending_block_mode::producing) {
fc_dlog(_trx_trace_log, "[TRX_TRACE] Block ${block_num} for producer ${prod} is REJECTING tx: ${txid} : ${why} ",
fc_dlog(_trx_successful_trace_log, "[TRX_TRACE] Block ${block_num} for producer ${prod} is REJECTING tx: ${txid} : ${why} ",
("block_num", chain.head_block_num() + 1)
("prod", get_pending_block_producer())
("txid", trx->id())
("why",response.get<fc::exception_ptr>()->what()));
fc_dlog(_trx_failed_trace_log, "[TRX_TRACE] Block ${block_num} for producer ${prod} is REJECTING tx: ${txid} : ${why} ",
("block_num", chain.head_block_num() + 1)
("prod", get_pending_block_producer())
("txid", trx->id())
("why",response.get<fc::exception_ptr>()->what()));
} else {
fc_dlog(_trx_trace_log, "[TRX_TRACE] Speculative execution is REJECTING tx: ${txid} : ${why} ",
fc_dlog(_trx_successful_trace_log, "[TRX_TRACE] Speculative execution is REJECTING tx: ${txid} : ${why} ",
("txid", trx->id())
("why",response.get<fc::exception_ptr>()->what()));
fc_dlog(_trx_failed_trace_log, "[TRX_TRACE] Speculative execution is REJECTING tx: ${txid} : ${why} ",
("txid", trx->id())
("why",response.get<fc::exception_ptr>()->what()));
}
} else {
_transaction_ack_channel.publish(priority::low, std::pair<fc::exception_ptr, transaction_metadata_ptr>(nullptr, trx));
if (_pending_block_mode == pending_block_mode::producing) {
fc_dlog(_trx_trace_log, "[TRX_TRACE] Block ${block_num} for producer ${prod} is ACCEPTING tx: ${txid}",
fc_dlog(_trx_successful_trace_log, "[TRX_TRACE] Block ${block_num} for producer ${prod} is ACCEPTING tx: ${txid}",
("block_num", chain.head_block_num() + 1)
("prod", get_pending_block_producer())
("txid", trx->id()));
} else {
fc_dlog(_trx_trace_log, "[TRX_TRACE] Speculative execution is ACCEPTING tx: ${txid}",
fc_dlog(_trx_successful_trace_log, "[TRX_TRACE] Speculative execution is ACCEPTING tx: ${txid}",
("txid", trx->id()));
}
}
Expand Down Expand Up @@ -548,12 +570,12 @@ class producer_plugin_impl : public std::enable_shared_from_this<producer_plugin
if( exception_is_exhausted( *trace->except, deadline_is_subjective )) {
_pending_incoming_transactions.add( trx, persist_until_expired, next );
if( _pending_block_mode == pending_block_mode::producing ) {
fc_dlog( _trx_trace_log, "[TRX_TRACE] Block ${block_num} for producer ${prod} COULD NOT FIT, tx: ${txid} RETRYING ",
fc_dlog(_log, "[TRX_TRACE] Block ${block_num} for producer ${prod} COULD NOT FIT, tx: ${txid} RETRYING ",
("block_num", chain.head_block_num() + 1)
("prod", get_pending_block_producer())
("txid", trx->id()));
} else {
fc_dlog( _trx_trace_log, "[TRX_TRACE] Speculative execution COULD NOT FIT tx: ${txid} RETRYING",
fc_dlog(_log, "[TRX_TRACE] Speculative execution COULD NOT FIT tx: ${txid} RETRYING",
("txid", trx->id()));
}
if( !exhausted )
Expand Down Expand Up @@ -1018,7 +1040,8 @@ void producer_plugin::plugin_shutdown() {

void producer_plugin::handle_sighup() {
fc::logger::update( logger_name, _log );
fc::logger::update( trx_trace_logger_name, _trx_trace_log );
fc::logger::update(trx_successful_trace_logger_name, _trx_successful_trace_log);
fc::logger::update(trx_failed_trace_logger_name, _trx_failed_trace_log);
}

void producer_plugin::pause() {
Expand Down Expand Up @@ -1655,17 +1678,25 @@ bool producer_plugin_impl::remove_expired_persisted_trxs( const fc::time_point&
&chain, has_producers = !_producers.empty()]( const transaction_id_type& txid, trx_enum_type trx_type ) {
if( trx_type == trx_enum_type::persisted ) {
if( pbm == pending_block_mode::producing ) {
fc_dlog( _trx_trace_log,
fc_dlog(_trx_successful_trace_log,
"[TRX_TRACE] Block ${block_num} for producer ${prod} is EXPIRING PERSISTED tx: ${txid}",
("block_num", chain.head_block_num() + 1)("txid", txid)
("prod", chain.is_building_block() ? chain.pending_block_producer() : name()) );
fc_dlog(_trx_failed_trace_log,
"[TRX_TRACE] Block ${block_num} for producer ${prod} is EXPIRING PERSISTED tx: ${txid}",
("block_num", chain.head_block_num() + 1)("txid", txid)
("prod", chain.is_building_block() ? chain.pending_block_producer() : name()) );
} else {
fc_dlog( _trx_trace_log, "[TRX_TRACE] Speculative execution is EXPIRING PERSISTED tx: ${txid}", ("txid", txid));
fc_dlog(_trx_successful_trace_log, "[TRX_TRACE] Speculative execution is EXPIRING PERSISTED tx: ${txid}", ("txid", txid));
fc_dlog(_trx_failed_trace_log, "[TRX_TRACE] Speculative execution is EXPIRING PERSISTED tx: ${txid}", ("txid", txid));
}
++num_expired_persistent;
} else {
if (has_producers) {
fc_dlog(_trx_trace_log,
fc_dlog(_trx_successful_trace_log,
"[TRX_TRACE] Node with producers configured is dropping an EXPIRED transaction that was PREVIOUSLY ACCEPTED : ${txid}",
("txid", txid));
fc_dlog(_trx_failed_trace_log,
"[TRX_TRACE] Node with producers configured is dropping an EXPIRED transaction that was PREVIOUSLY ACCEPTED : ${txid}",
("txid", txid));
}
Expand Down Expand Up @@ -2109,4 +2140,9 @@ void producer_plugin_impl::produce_block() {

}

void producer_plugin::log_failed_transaction(const transaction_id_type& trx_id, const char* reason) const {
fc_dlog(_trx_failed_trace_log, "[TRX_TRACE] Speculative execution is REJECTING tx: ${txid} : ${why}",
("trxid", trx_id)("reason", reason));
}

} // namespace eosio
9 changes: 9 additions & 0 deletions programs/nodeos/logging.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@
"stderr",
"net"
]
}{
"name": "transaction_failure_tracing",
"level": "debug",
"enabled": true,
"additivity": false,
"appenders": [
"stderr",
"net"
]
},{
"name": "trace_api",
"level": "debug",
Expand Down

0 comments on commit f6b238b

Please sign in to comment.