int main( int argc, char** argv ) { auto lgr = fc::logger::get(); auto dconfig = fc::logging_config::default_config(); dconfig.appenders.push_back( fc::appender_config("logfile", "file", fc::value(fc::file_appender::config("test.log")) ) ); dconfig.loggers.push_back( fc::logger_config("main").add_appender("stderr").add_appender("logfile") ); fc::configure_logging( dconfig ); fc_dlog( lgr, "Hello Debug" ); fc_ilog( lgr, "Hello Info" ); fc_wlog( lgr, "Hello Warn" ); fc_elog( lgr, "Hello Error" ); fc_flog( lgr, "Hello Fatal" ); auto main_lgr = fc::logger::get( "main" ); fc_dlog( main_lgr, "Hello Debug" ); fc_ilog( main_lgr, "Hello Info" ); fc_wlog( main_lgr, "Hello Warn" ); fc_elog( main_lgr, "Hello Error" ); fc_flog( main_lgr, "Hello Fatal" ); return 0; }
/** * @brief allows the application to validate an item prior to broadcasting to peers. * * @param sync_mode true if the message was fetched through the sync process, false during normal operation * @returns true if this message caused the blockchain to switch forks, false if it did not * * @throws exception if error validating the item, otherwise the item is safe to broadcast on. */ virtual bool handle_block(const graphene::net::block_message& blk_msg, bool sync_mode, std::vector<fc::uint160_t>& contained_transaction_message_ids) override { try { if( _running ) { if (sync_mode) fc_ilog(fc::logger::get("sync"), "chain pushing sync block #${block_num} ${block_hash}, head is ${head}", ("block_num", blk_msg.block.block_num()) ("block_hash", blk_msg.block_id) ("head", _chain_db->head_block_num())); else fc_ilog(fc::logger::get("sync"), "chain pushing block #${block_num} ${block_hash}, head is ${head}", ("block_num", blk_msg.block.block_num()) ("block_hash", blk_msg.block_id) ("head", _chain_db->head_block_num())); if (sync_mode && blk_msg.block.block_num() % 10000 == 0) { ilog("Syncing Blockchain --- Got block: #${n} time: ${t}", ("t",blk_msg.block.timestamp) ("n", blk_msg.block.block_num()) ); } time_point_sec now = fc::time_point::now(); uint64_t max_accept_time = now.sec_since_epoch(); max_accept_time += allow_future_time; FC_ASSERT( blk_msg.block.timestamp.sec_since_epoch() <= max_accept_time ); try { // TODO: in the case where this block is valid but on a fork that's too old for us to switch to, // you can help the network code out by throwing a block_older_than_undo_history exception. // when the net code sees that, it will stop trying to push blocks from that chain, but // leave that peer connected so that they can get sync blocks from us bool result = _chain_db->push_block(blk_msg.block, (_is_block_producer | _force_validate) ? database::skip_nothing : database::skip_transaction_signatures); if( !sync_mode ) { fc::microseconds latency = fc::time_point::now() - blk_msg.block.timestamp; ilog( "Got ${t} transactions on block ${b} by ${w} -- latency: ${l} ms", ("t", blk_msg.block.transactions.size()) ("b", blk_msg.block.block_num()) ("w", blk_msg.block.witness) ("l", latency.count() / 1000) ); } return result; } catch ( const steemit::chain::unlinkable_block_exception& e ) { // translate to a graphene::net exception fc_elog(fc::logger::get("sync"), "Error when pushing block, current head block is ${head}:\n${e}", ("e", e.to_detail_string()) ("head", _chain_db->head_block_num())); elog("Error when pushing block:\n${e}", ("e", e.to_detail_string())); FC_THROW_EXCEPTION(graphene::net::unlinkable_block_exception, "Error when pushing block:\n${e}", ("e", e.to_detail_string())); } catch( const fc::exception& e ) { fc_elog(fc::logger::get("sync"), "Error when pushing block, current head block is ${head}:\n${e}", ("e", e.to_detail_string()) ("head", _chain_db->head_block_num())); elog("Error when pushing block:\n${e}", ("e", e.to_detail_string())); throw; } } return false; } FC_CAPTURE_AND_RETHROW( (blk_msg)(sync_mode) ) }