new update of the pr with network limits
more debug options:
discarding downloaded blocks all or after given height.
trying to trigger the locking errors.
debug levels polished/tuned to sane values.
debug/logging improved.
warning: this pr should be correct code, but it could make
an existing (in master version) locking error appear more often.
it's a race on the list (map) of peers, e.g. between closing/deleting
them versus working on them in net-limit sleep in sending chunk.
the bug is not in this code/this pr, but in the master version.
the locking problem of master will be fixed in other pr.
problem is ub, and in practice is seems to usually cause program abort
(tested on debian stable with updated gcc). see --help for option
to add sleep to trigger the error faster.
_erro("send que size is more than ABSTRACT_SERVER_SEND_QUE_MAX_COUNT(" << ABSTRACT_SERVER_SEND_QUE_MAX_COUNT << "), shutting down connection");
// _mark_c("net/sleep", "send que size is more than ABSTRACT_SERVER_SEND_QUE_MAX_COUNT(" << ABSTRACT_SERVER_SEND_QUE_MAX_COUNT << "), shutting down connection");
// _dbg1_c("net/sleep", "send que size is more than ABSTRACT_SERVER_SEND_QUE_MAX_COUNT(" << ABSTRACT_SERVER_SEND_QUE_MAX_COUNT << "), shutting down connection");
@ -65,18 +65,55 @@ extern cNullstream g_nullstream; // a stream that does nothing (eats/discards da
// TODO make _dbg_ignore thread-safe everywhere
externstd::mutexgLoggerGuard;
externstd::recursive_mutexgLoggerGuard;// the mutex guarding logging/debugging code e.g. protecting streams, files, etc
std::atomic<int>&gLoggerGuardDepth_Get();// getter for the global singleton of counter (it guarantees initializing it to 0). This counter shows the current recursion (re-entrant) level of debug macros.
// TODO more debug of the debug system:
// detect lock() error e.g. recursive limit
// detect stream e.g. operator<< error
#define _debug_level(LEVEL,VAR) do { if (_dbg_ignore< LEVEL) { \
gCurrentLogger.write_stream(std::max(level,90),"")<<nOT::nUtils::get_current_time()<<''<<OT_CODE_STAMP<<''<<"(ERROR IN DEBUG)"<<gCurrentLogger.endline(); \
--nOT::nUtils::gLoggerGuardDepth_Get();throw; \
} \
--nOT::nUtils::gLoggerGuardDepth_Get(); \
}catch(...){if(part<8)gCurrentLogger.write_stream(100,"")<<"DEBUG-ERROR: problem in debug mechanism e.g. in locking."<<gCurrentLogger.endline();throw;} \
}}while(0)
// info for code below: oss object is normal stack variable, using it does not need lock protection
#define _debug_level_c(CHANNEL,LEVEL,VAR) do { if (_dbg_ignore< LEVEL) { \
gCurrentLogger.write_stream(std::max(level,90),CHANNEL)<<nOT::nUtils::get_current_time()<<''<<OT_CODE_STAMP<<''<<"(ERROR IN DEBUG)"<<gCurrentLogger.endline(); \
--nOT::nUtils::gLoggerGuardDepth_Get();throw; \
} \
--nOT::nUtils::gLoggerGuardDepth_Get(); \
}catch(...){if(part<8)gCurrentLogger.write_stream(100,CHANNEL)<<"DEBUG-ERROR: problem in debug mechanism e.g. in locking."<<gCurrentLogger.endline();throw;} \
constcommand_line::arg_descriptor<bool>arg_dns_checkpoints={"enforce-dns-checkpointing","checkpoints from DNS server will be enforced",false};
constcommand_line::arg_descriptor<bool>arg_test_drop_download={"test-drop-download","For network testing, drop downloaded blocks instead checking/adding them to blockchain. Can fake-download blocks very fast."};
constcommand_line::arg_descriptor<bool>arg_test_drop_download={"test-drop-download","For net tests: in download, discard ALL blocks instead checking/saving them (very fast)"};
constcommand_line::arg_descriptor<uint64_t>arg_test_drop_download_height={"test-drop-download-height","Like test-drop-download but disards only after around certain height",0};
constcommand_line::arg_descriptor<bool>arg_save_graph={"save-graph","Save data for dr monero",false};
constcommand_line::arg_descriptor<int>test_dbg_lock_sleep={"test-dbg-lock-sleep","Sleep time in ms, defaults to 0 (off), used to debug before/after locking mutex. Values 100 to 1000 are good for tests.",0};