2019-03-05 21:05:34 +00:00
|
|
|
// Copyright (c) 2014-2019, The Monero Project
|
2015-12-14 04:54:39 +00:00
|
|
|
//
|
2015-01-29 22:10:53 +00:00
|
|
|
// All rights reserved.
|
2015-12-14 04:54:39 +00:00
|
|
|
//
|
2015-01-29 22:10:53 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
// permitted provided that the following conditions are met:
|
2015-12-14 04:54:39 +00:00
|
|
|
//
|
2015-01-29 22:10:53 +00:00
|
|
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
// conditions and the following disclaimer.
|
2015-12-14 04:54:39 +00:00
|
|
|
//
|
2015-01-29 22:10:53 +00:00
|
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
|
|
// of conditions and the following disclaimer in the documentation and/or other
|
|
|
|
// materials provided with the distribution.
|
2015-12-14 04:54:39 +00:00
|
|
|
//
|
2015-01-29 22:10:53 +00:00
|
|
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
|
|
|
// used to endorse or promote products derived from this software without specific
|
|
|
|
// prior written permission.
|
2015-12-14 04:54:39 +00:00
|
|
|
//
|
2015-01-29 22:10:53 +00:00
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
|
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
|
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
|
|
|
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
|
|
|
|
|
|
|
#include "common/command_line.h"
|
|
|
|
#include "common/scoped_message_writer.h"
|
2017-02-05 22:48:03 +00:00
|
|
|
#include "common/password.h"
|
2015-01-29 22:10:53 +00:00
|
|
|
#include "common/util.h"
|
|
|
|
#include "cryptonote_core/cryptonote_core.h"
|
2017-01-26 15:07:23 +00:00
|
|
|
#include "cryptonote_basic/miner.h"
|
2015-01-29 22:10:53 +00:00
|
|
|
#include "daemon/command_server.h"
|
|
|
|
#include "daemon/daemon.h"
|
|
|
|
#include "daemon/executor.h"
|
|
|
|
#include "daemonizer/daemonizer.h"
|
|
|
|
#include "misc_log_ex.h"
|
|
|
|
#include "p2p/net_node.h"
|
|
|
|
#include "rpc/core_rpc_server.h"
|
2017-02-05 22:48:03 +00:00
|
|
|
#include "rpc/rpc_args.h"
|
2015-01-29 22:10:53 +00:00
|
|
|
#include "daemon/command_line_args.h"
|
2015-03-25 15:41:30 +00:00
|
|
|
#include "blockchain_db/db_types.h"
|
2017-11-29 22:53:58 +00:00
|
|
|
#include "version.h"
|
2015-01-29 22:10:53 +00:00
|
|
|
|
2016-07-27 05:02:55 +00:00
|
|
|
#ifdef STACK_TRACE
|
|
|
|
#include "common/stack_trace.h"
|
|
|
|
#endif // STACK_TRACE
|
|
|
|
|
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 16:34:23 +00:00
|
|
|
#undef MONERO_DEFAULT_LOG_CATEGORY
|
|
|
|
#define MONERO_DEFAULT_LOG_CATEGORY "daemon"
|
|
|
|
|
2015-01-29 22:10:53 +00:00
|
|
|
namespace po = boost::program_options;
|
|
|
|
namespace bf = boost::filesystem;
|
|
|
|
|
|
|
|
int main(int argc, char const * argv[])
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
|
2015-12-14 04:54:39 +00:00
|
|
|
// TODO parse the debug options like set log level right here at start
|
2015-04-02 14:27:19 +00:00
|
|
|
|
2017-10-03 09:12:57 +00:00
|
|
|
tools::on_startup();
|
2015-11-21 10:13:10 +00:00
|
|
|
|
2015-01-29 22:10:53 +00:00
|
|
|
epee::string_tools::set_module_name_and_folder(argv[0]);
|
|
|
|
|
|
|
|
// Build argument description
|
|
|
|
po::options_description all_options("All");
|
|
|
|
po::options_description hidden_options("Hidden");
|
|
|
|
po::options_description visible_options("Options");
|
|
|
|
po::options_description core_settings("Settings");
|
|
|
|
po::positional_options_description positional_options;
|
|
|
|
{
|
|
|
|
// Misc Options
|
|
|
|
|
|
|
|
command_line::add_arg(visible_options, command_line::arg_help);
|
|
|
|
command_line::add_arg(visible_options, command_line::arg_version);
|
|
|
|
command_line::add_arg(visible_options, daemon_args::arg_os_version);
|
2018-01-22 01:49:51 +00:00
|
|
|
command_line::add_arg(visible_options, daemon_args::arg_config_file);
|
2015-12-14 04:54:39 +00:00
|
|
|
|
2015-01-29 22:10:53 +00:00
|
|
|
// Settings
|
2018-01-22 01:49:51 +00:00
|
|
|
command_line::add_arg(core_settings, daemon_args::arg_log_file);
|
2015-01-29 22:10:53 +00:00
|
|
|
command_line::add_arg(core_settings, daemon_args::arg_log_level);
|
2017-09-17 02:42:45 +00:00
|
|
|
command_line::add_arg(core_settings, daemon_args::arg_max_log_file_size);
|
2018-06-01 03:29:26 +00:00
|
|
|
command_line::add_arg(core_settings, daemon_args::arg_max_log_files);
|
2016-04-28 19:25:33 +00:00
|
|
|
command_line::add_arg(core_settings, daemon_args::arg_max_concurrency);
|
2017-09-05 16:20:27 +00:00
|
|
|
command_line::add_arg(core_settings, daemon_args::arg_zmq_rpc_bind_ip);
|
|
|
|
command_line::add_arg(core_settings, daemon_args::arg_zmq_rpc_bind_port);
|
** CHANGES ARE EXPERIMENTAL (FOR TESTING ONLY)
Bockchain:
1. Optim: Multi-thread long-hash computation when encountering groups of blocks.
2. Optim: Cache verified txs and return result from cache instead of re-checking whenever possible.
3. Optim: Preload output-keys when encoutering groups of blocks. Sort by amount and global-index before bulk querying database and multi-thread when possible.
4. Optim: Disable double spend check on block verification, double spend is already detected when trying to add blocks.
5. Optim: Multi-thread signature computation whenever possible.
6. Patch: Disable locking (recursive mutex) on called functions from check_tx_inputs which causes slowdowns (only seems to happen on ubuntu/VMs??? Reason: TBD)
7. Optim: Removed looped full-tx hash computation when retrieving transactions from pool (???).
8. Optim: Cache difficulty/timestamps (735 blocks) for next-difficulty calculations so that only 2 db reads per new block is needed when a new block arrives (instead of 1470 reads).
Berkeley-DB:
1. Fix: 32-bit data errors causing wrong output global indices and failure to send blocks to peers (etc).
2. Fix: Unable to pop blocks on reorganize due to transaction errors.
3. Patch: Large number of transaction aborts when running multi-threaded bulk queries.
4. Patch: Insufficient locks error when running full sync.
5. Patch: Incorrect db stats when returning from an immediate exit from "pop block" operation.
6. Optim: Add bulk queries to get output global indices.
7. Optim: Modified output_keys table to store public_key+unlock_time+height for single transaction lookup (vs 3)
8. Optim: Used output_keys table retrieve public_keys instead of going through output_amounts->output_txs+output_indices->txs->output:public_key
9. Optim: Added thread-safe buffers used when multi-threading bulk queries.
10. Optim: Added support for nosync/write_nosync options for improved performance (*see --db-sync-mode option for details)
11. Mod: Added checkpoint thread and auto-remove-logs option.
12. *Now usable on 32-bit systems like RPI2.
LMDB:
1. Optim: Added custom comparison for 256-bit key tables (minor speed-up, TBD: get actual effect)
2. Optim: Modified output_keys table to store public_key+unlock_time+height for single transaction lookup (vs 3)
3. Optim: Used output_keys table retrieve public_keys instead of going through output_amounts->output_txs+output_indices->txs->output:public_key
4. Optim: Added support for sync/writemap options for improved performance (*see --db-sync-mode option for details)
5. Mod: Auto resize to +1GB instead of multiplier x1.5
ETC:
1. Minor optimizations for slow-hash for ARM (RPI2). Incomplete.
2. Fix: 32-bit saturation bug when computing next difficulty on large blocks.
[PENDING ISSUES]
1. Berkely db has a very slow "pop-block" operation. This is very noticeable on the RPI2 as it sometimes takes > 10 MINUTES to pop a block during reorganization.
This does not happen very often however, most reorgs seem to take a few seconds but it possibly depends on the number of outputs present. TBD.
2. Berkeley db, possible bug "unable to allocate memory". TBD.
[NEW OPTIONS] (*Currently all enabled for testing purposes)
1. --fast-block-sync arg=[0:1] (default: 1)
a. 0 = Compute long hash per block (may take a while depending on CPU)
b. 1 = Skip long-hash and verify blocks based on embedded known good block hashes (faster, minimal CPU dependence)
2. --db-sync-mode arg=[[safe|fast|fastest]:[sync|async]:[nblocks_per_sync]] (default: fastest:async:1000)
a. safe = fdatasync/fsync (or equivalent) per stored block. Very slow, but safest option to protect against power-out/crash conditions.
b. fast/fastest = Enables asynchronous fdatasync/fsync (or equivalent). Useful for battery operated devices or STABLE systems with UPS and/or systems with battery backed write cache/solid state cache.
Fast - Write meta-data but defer data flush.
Fastest - Defer meta-data and data flush.
Sync - Flush data after nblocks_per_sync and wait.
Async - Flush data after nblocks_per_sync but do not wait for the operation to finish.
3. --prep-blocks-threads arg=[n] (default: 4 or system max threads, whichever is lower)
Max number of threads to use when computing long-hash in groups.
4. --show-time-stats arg=[0:1] (default: 1)
Show benchmark related time stats.
5. --db-auto-remove-logs arg=[0:1] (default: 1)
For berkeley-db only. Auto remove logs if enabled.
**Note: lmdb and berkeley-db have changes to the tables and are not compatible with official git head version.
At the moment, you need a full resync to use this optimized version.
[PERFORMANCE COMPARISON]
**Some figures are approximations only.
Using a baseline machine of an i7-2600K+SSD+(with full pow computation):
1. The optimized lmdb/blockhain core can process blocks up to 585K for ~1.25 hours + download time, so it usually takes 2.5 hours to sync the full chain.
2. The current head with memory can process blocks up to 585K for ~4.2 hours + download time, so it usually takes 5.5 hours to sync the full chain.
3. The current head with lmdb can process blocks up to 585K for ~32 hours + download time and usually takes 36 hours to sync the full chain.
Averate procesing times (with full pow computation):
lmdb-optimized:
1. tx_ave = 2.5 ms / tx
2. block_ave = 5.87 ms / block
memory-official-repo:
1. tx_ave = 8.85 ms / tx
2. block_ave = 19.68 ms / block
lmdb-official-repo (0f4a036437fd41a5498ee5e74e2422ea6177aa3e)
1. tx_ave = 47.8 ms / tx
2. block_ave = 64.2 ms / block
**Note: The following data denotes processing times only (does not include p2p download time)
lmdb-optimized processing times (with full pow computation):
1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 1.25 hours processing time (--db-sync-mode=fastest:async:1000).
2. Laptop, Dual-core / 4-threads U4200 (3Mb) - 4.90 hours processing time (--db-sync-mode=fastest:async:1000).
3. Embedded, Quad-core / 4-threads Z3735F (2x1Mb) - 12.0 hours processing time (--db-sync-mode=fastest:async:1000).
lmdb-optimized processing times (with per-block-checkpoint)
1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 10 minutes processing time (--db-sync-mode=fastest:async:1000).
berkeley-db optimized processing times (with full pow computation)
1. Desktop, Quad-core / 8-threads 2600k (8Mb) - 1.8 hours processing time (--db-sync-mode=fastest:async:1000).
2. RPI2. Improved from estimated 3 months(???) into 2.5 days (*Need 2AMP supply + Clock:1Ghz + [usb+ssd] to achieve this speed) (--db-sync-mode=fastest:async:1000).
berkeley-db optimized processing times (with per-block-checkpoint)
1. RPI2. 12-15 hours (*Need 2AMP supply + Clock:1Ghz + [usb+ssd] to achieve this speed) (--db-sync-mode=fastest:async:1000).
2015-07-10 20:09:32 +00:00
|
|
|
|
2015-01-29 22:10:53 +00:00
|
|
|
daemonizer::init_options(hidden_options, visible_options);
|
|
|
|
daemonize::t_executor::init_options(core_settings);
|
|
|
|
|
|
|
|
// Hidden options
|
|
|
|
command_line::add_arg(hidden_options, daemon_args::arg_command);
|
|
|
|
|
|
|
|
visible_options.add(core_settings);
|
|
|
|
all_options.add(visible_options);
|
|
|
|
all_options.add(hidden_options);
|
|
|
|
|
|
|
|
// Positional
|
|
|
|
positional_options.add(daemon_args::arg_command.name, -1); // -1 for unlimited arguments
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do command line parsing
|
|
|
|
po::variables_map vm;
|
|
|
|
bool ok = command_line::handle_error_helper(visible_options, [&]()
|
|
|
|
{
|
|
|
|
boost::program_options::store(
|
|
|
|
boost::program_options::command_line_parser(argc, argv)
|
|
|
|
.options(all_options).positional(positional_options).run()
|
|
|
|
, vm
|
|
|
|
);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
if (!ok) return 1;
|
|
|
|
|
|
|
|
if (command_line::get_arg(vm, command_line::arg_help))
|
|
|
|
{
|
2015-12-31 21:12:13 +00:00
|
|
|
std::cout << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")" << ENDL << ENDL;
|
2015-01-29 22:10:53 +00:00
|
|
|
std::cout << "Usage: " + std::string{argv[0]} + " [options|settings] [daemon_command...]" << std::endl << std::endl;
|
|
|
|
std::cout << visible_options << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Monero Version
|
|
|
|
if (command_line::get_arg(vm, command_line::arg_version))
|
|
|
|
{
|
2015-12-31 21:12:13 +00:00
|
|
|
std::cout << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")" << ENDL;
|
2015-01-29 22:10:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OS
|
|
|
|
if (command_line::get_arg(vm, daemon_args::arg_os_version))
|
|
|
|
{
|
|
|
|
std::cout << "OS: " << tools::get_os_version_string() << ENDL;
|
|
|
|
return 0;
|
|
|
|
}
|
2015-12-14 04:54:39 +00:00
|
|
|
|
2018-04-14 13:05:24 +00:00
|
|
|
std::string config = command_line::get_arg(vm, daemon_args::arg_config_file);
|
|
|
|
boost::filesystem::path config_path(config);
|
|
|
|
boost::system::error_code ec;
|
|
|
|
if (bf::exists(config_path, ec))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
po::store(po::parse_config_file<char>(config_path.string<std::string>().c_str(), core_settings), vm);
|
|
|
|
}
|
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
|
|
|
// log system isn't initialized yet
|
|
|
|
std::cerr << "Error parsing config file: " << e.what() << std::endl;
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!command_line::is_arg_defaulted(vm, daemon_args::arg_config_file))
|
|
|
|
{
|
|
|
|
std::cerr << "Can't find config file " << config << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-02-16 11:04:04 +00:00
|
|
|
const bool testnet = command_line::get_arg(vm, cryptonote::arg_testnet_on);
|
|
|
|
const bool stagenet = command_line::get_arg(vm, cryptonote::arg_stagenet_on);
|
2018-06-14 19:11:49 +00:00
|
|
|
const bool regtest = command_line::get_arg(vm, cryptonote::arg_regtest_on);
|
|
|
|
if (testnet + stagenet + regtest > 1)
|
2018-02-16 11:04:04 +00:00
|
|
|
{
|
2018-06-14 19:11:49 +00:00
|
|
|
std::cerr << "Can't specify more than one of --tesnet and --stagenet and --regtest" << ENDL;
|
2018-02-16 11:04:04 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-08-29 10:14:42 +00:00
|
|
|
std::string db_type = command_line::get_arg(vm, cryptonote::arg_db_type);
|
2015-03-25 15:41:30 +00:00
|
|
|
|
|
|
|
// verify that blockchaindb type is valid
|
2017-08-20 12:37:19 +00:00
|
|
|
if(!cryptonote::blockchain_valid_db_type(db_type))
|
2015-03-25 15:41:30 +00:00
|
|
|
{
|
2017-08-20 12:37:19 +00:00
|
|
|
std::cout << "Invalid database type (" << db_type << "), available types are: " <<
|
|
|
|
cryptonote::blockchain_db_types(", ") << std::endl;
|
2015-03-25 15:41:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-27 11:19:34 +00:00
|
|
|
// data_dir
|
|
|
|
// default: e.g. ~/.bitmonero/ or ~/.bitmonero/testnet
|
|
|
|
// if data-dir argument given:
|
|
|
|
// absolute path
|
|
|
|
// relative path: relative to cwd
|
|
|
|
|
2015-01-29 22:10:53 +00:00
|
|
|
// Create data dir if it doesn't exist
|
|
|
|
boost::filesystem::path data_dir = boost::filesystem::absolute(
|
2018-01-21 15:29:55 +00:00
|
|
|
command_line::get_arg(vm, cryptonote::arg_data_dir));
|
2015-01-29 22:10:53 +00:00
|
|
|
|
|
|
|
// FIXME: not sure on windows implementation default, needs further review
|
|
|
|
//bf::path relative_path_base = daemonizer::get_relative_path_base(vm);
|
|
|
|
bf::path relative_path_base = data_dir;
|
|
|
|
|
|
|
|
po::notify(vm);
|
|
|
|
|
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 16:34:23 +00:00
|
|
|
// log_file_path
|
|
|
|
// default: <data_dir>/<CRYPTONOTE_NAME>.log
|
|
|
|
// if log-file argument given:
|
|
|
|
// absolute path
|
|
|
|
// relative path: relative to data_dir
|
|
|
|
bf::path log_file_path {data_dir / std::string(CRYPTONOTE_NAME ".log")};
|
2017-10-06 09:55:36 +00:00
|
|
|
if (!command_line::is_arg_defaulted(vm, daemon_args::arg_log_file))
|
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 16:34:23 +00:00
|
|
|
log_file_path = command_line::get_arg(vm, daemon_args::arg_log_file);
|
|
|
|
log_file_path = bf::absolute(log_file_path, relative_path_base);
|
2018-06-01 03:29:26 +00:00
|
|
|
mlog_configure(log_file_path.string(), true, command_line::get_arg(vm, daemon_args::arg_max_log_file_size), command_line::get_arg(vm, daemon_args::arg_max_log_files));
|
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 16:34:23 +00:00
|
|
|
|
|
|
|
// Set log level
|
2017-10-06 09:55:36 +00:00
|
|
|
if (!command_line::is_arg_defaulted(vm, daemon_args::arg_log_level))
|
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 16:34:23 +00:00
|
|
|
{
|
|
|
|
mlog_set_log(command_line::get_arg(vm, daemon_args::arg_log_level).c_str());
|
|
|
|
}
|
|
|
|
|
2017-02-24 19:08:20 +00:00
|
|
|
// after logs initialized
|
|
|
|
tools::create_directories_if_necessary(data_dir.string());
|
|
|
|
|
2018-11-30 17:55:16 +00:00
|
|
|
#ifdef STACK_TRACE
|
|
|
|
tools::set_stack_trace_log(log_file_path.filename().string());
|
|
|
|
#endif // STACK_TRACE
|
|
|
|
|
|
|
|
if (!command_line::is_arg_defaulted(vm, daemon_args::arg_max_concurrency))
|
|
|
|
tools::set_max_concurrency(command_line::get_arg(vm, daemon_args::arg_max_concurrency));
|
|
|
|
|
|
|
|
// logging is now set up
|
|
|
|
MGINFO("Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")");
|
|
|
|
|
2015-01-29 22:10:53 +00:00
|
|
|
// If there are positional options, we're running a daemon command
|
|
|
|
{
|
|
|
|
auto command = command_line::get_arg(vm, daemon_args::arg_command);
|
|
|
|
|
2015-02-05 09:11:20 +00:00
|
|
|
if (command.size())
|
2015-01-29 22:10:53 +00:00
|
|
|
{
|
2017-02-05 22:48:03 +00:00
|
|
|
const cryptonote::rpc_args::descriptors arg{};
|
|
|
|
auto rpc_ip_str = command_line::get_arg(vm, arg.rpc_bind_ip);
|
2015-02-05 09:11:20 +00:00
|
|
|
auto rpc_port_str = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_rpc_bind_port);
|
|
|
|
|
|
|
|
uint32_t rpc_ip;
|
|
|
|
uint16_t rpc_port;
|
|
|
|
if (!epee::string_tools::get_ip_int32_from_string(rpc_ip, rpc_ip_str))
|
|
|
|
{
|
|
|
|
std::cerr << "Invalid IP: " << rpc_ip_str << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (!epee::string_tools::get_xtype_from_string(rpc_port, rpc_port_str))
|
|
|
|
{
|
|
|
|
std::cerr << "Invalid port: " << rpc_port_str << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-08-30 11:35:05 +00:00
|
|
|
const char *env_rpc_login = nullptr;
|
|
|
|
const bool has_rpc_arg = command_line::has_arg(vm, arg.rpc_login);
|
|
|
|
const bool use_rpc_env = !has_rpc_arg && (env_rpc_login = getenv("RPC_LOGIN")) != nullptr && strlen(env_rpc_login) > 0;
|
2017-02-05 22:48:03 +00:00
|
|
|
boost::optional<tools::login> login{};
|
2018-08-30 11:35:05 +00:00
|
|
|
if (has_rpc_arg || use_rpc_env)
|
2017-02-05 22:48:03 +00:00
|
|
|
{
|
|
|
|
login = tools::login::parse(
|
2018-08-30 11:35:05 +00:00
|
|
|
has_rpc_arg ? command_line::get_arg(vm, arg.rpc_login) : std::string(env_rpc_login), false, [](bool verify) {
|
2017-10-28 18:13:42 +00:00
|
|
|
#ifdef HAVE_READLINE
|
|
|
|
rdln::suspend_readline pause_readline;
|
|
|
|
#endif
|
|
|
|
return tools::password_container::prompt(verify, "Daemon client password");
|
|
|
|
}
|
2017-02-05 22:48:03 +00:00
|
|
|
);
|
|
|
|
if (!login)
|
|
|
|
{
|
|
|
|
std::cerr << "Failed to obtain password" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
daemonize::t_command_server rpc_commands{rpc_ip, rpc_port, std::move(login)};
|
2015-02-05 09:11:20 +00:00
|
|
|
if (rpc_commands.process_command_vec(command))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-31 11:13:03 +00:00
|
|
|
#ifdef HAVE_READLINE
|
|
|
|
rdln::suspend_readline pause_readline;
|
|
|
|
#endif
|
2017-12-27 02:47:39 +00:00
|
|
|
std::cerr << "Unknown command: " << command.front() << std::endl;
|
2015-02-05 09:11:20 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2015-01-29 22:10:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 16:34:23 +00:00
|
|
|
MINFO("Moving from main() into the daemonize now.");
|
2015-01-29 22:10:53 +00:00
|
|
|
|
2018-01-20 10:41:50 +00:00
|
|
|
return daemonizer::daemonize(argc, argv, daemonize::t_executor{}, vm) ? 0 : 1;
|
2015-01-29 22:10:53 +00:00
|
|
|
}
|
|
|
|
catch (std::exception const & ex)
|
|
|
|
{
|
|
|
|
LOG_ERROR("Exception in main! " << ex.what());
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
LOG_ERROR("Exception in main!");
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|