aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.cpp3
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.h2
-rw-r--r--src/blockchain_db/blockchain_db.cpp8
-rw-r--r--src/blockchain_db/blockchain_db.h9
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp90
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.h3
-rw-r--r--src/blockchain_utilities/CMakeLists.txt3
-rw-r--r--src/blockchain_utilities/blockchain_export.cpp9
-rw-r--r--src/blockchain_utilities/blockchain_import.cpp113
-rw-r--r--src/blockchain_utilities/blocksdat_file.cpp20
-rw-r--r--src/blockchain_utilities/bootstrap_file.cpp68
-rw-r--r--src/blockchain_utilities/cn_deserialize.cpp8
-rw-r--r--src/blockchain_utilities/fake_core.h4
-rw-r--r--src/common/dns_utils.cpp3
-rw-r--r--src/common/i18n.cpp3
-rw-r--r--src/common/perf_timer.cpp14
-rw-r--r--src/common/perf_timer.h17
-rw-r--r--src/common/scoped_message_writer.h27
-rw-r--r--src/common/stack_trace.cpp21
-rw-r--r--src/common/util.h2
-rw-r--r--src/cryptonote_core/CMakeLists.txt1
-rw-r--r--src/cryptonote_core/account.cpp12
-rw-r--r--src/cryptonote_core/blockchain.cpp309
-rw-r--r--src/cryptonote_core/checkpoints.cpp7
-rw-r--r--src/cryptonote_core/cryptonote_basic_impl.cpp5
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp127
-rw-r--r--src/cryptonote_core/cryptonote_core.h9
-rw-r--r--src/cryptonote_core/cryptonote_format_utils.cpp11
-rw-r--r--src/cryptonote_core/difficulty.cpp3
-rw-r--r--src/cryptonote_core/hardfork.cpp16
-rw-r--r--src/cryptonote_core/hardfork.h15
-rw-r--r--src/cryptonote_core/miner.cpp25
-rw-r--r--src/cryptonote_core/tx_pool.cpp51
-rw-r--r--src/cryptonote_core/tx_pool.h29
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp23
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.h5
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.inl59
-rw-r--r--src/daemon/CMakeLists.txt1
-rw-r--r--src/daemon/command_line_args.h4
-rw-r--r--src/daemon/command_parser_executor.cpp41
-rw-r--r--src/daemon/command_parser_executor.h4
-rw-r--r--src/daemon/command_server.cpp10
-rw-r--r--src/daemon/core.h11
-rw-r--r--src/daemon/daemon.cpp9
-rw-r--r--src/daemon/daemon.h5
-rw-r--r--src/daemon/executor.cpp8
-rw-r--r--src/daemon/executor.h3
-rw-r--r--src/daemon/main.cpp66
-rw-r--r--src/daemon/p2p.h15
-rw-r--r--src/daemon/protocol.h11
-rw-r--r--src/daemon/rpc.h17
-rw-r--r--src/daemon/rpc_command_executor.cpp136
-rw-r--r--src/daemon/rpc_command_executor.h7
-rw-r--r--src/mnemonics/electrum-words.cpp27
-rw-r--r--src/p2p/connection_basic.cpp32
-rw-r--r--src/p2p/data_logger.cpp202
-rw-r--r--src/p2p/data_logger.hpp105
-rw-r--r--src/p2p/net_node.inl163
-rw-r--r--src/p2p/network_throttle-detail.cpp16
-rw-r--r--src/p2p/network_throttle-detail.hpp3
-rw-r--r--src/ringct/rctOps.cpp3
-rw-r--r--src/ringct/rctSigs.cpp176
-rw-r--r--src/ringct/rctSigs.h6
-rw-r--r--src/ringct/rctTypes.cpp3
-rw-r--r--src/ringct/rctTypes.h128
-rw-r--r--src/rpc/core_rpc_server.cpp54
-rw-r--r--src/rpc/core_rpc_server.h4
-rw-r--r--src/rpc/core_rpc_server_commands_defs.h51
-rw-r--r--src/simplewallet/simplewallet.cpp237
-rw-r--r--src/simplewallet/simplewallet.h3
-rw-r--r--src/wallet/CMakeLists.txt2
-rw-r--r--src/wallet/api/address_book.cpp54
-rw-r--r--src/wallet/api/address_book.h3
-rw-r--r--src/wallet/api/transaction_history.h1
-rw-r--r--src/wallet/api/wallet.cpp79
-rw-r--r--src/wallet/api/wallet.h7
-rw-r--r--src/wallet/api/wallet_manager.cpp4
-rw-r--r--src/wallet/node_rpc_proxy.cpp134
-rw-r--r--src/wallet/node_rpc_proxy.h65
-rw-r--r--src/wallet/wallet2.cpp436
-rw-r--r--src/wallet/wallet2.h27
-rw-r--r--src/wallet/wallet2_api.h20
-rw-r--r--src/wallet/wallet_args.cpp73
-rw-r--r--src/wallet/wallet_errors.h12
-rw-r--r--src/wallet/wallet_rpc_server.cpp19
-rw-r--r--src/wallet/wallet_rpc_server.h4
-rw-r--r--src/wallet/wallet_rpc_server_commands_defs.h4
87 files changed, 2160 insertions, 1479 deletions
diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp
index 137ed9dc6..57d8371bd 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.cpp
+++ b/src/blockchain_db/berkeleydb/db_bdb.cpp
@@ -1813,9 +1813,10 @@ bool BlockchainBDB::has_key_image(const crypto::key_image& img) const
// Ostensibly BerkeleyDB has batch transaction support built-in,
// so the following few functions will be NOP.
-void BlockchainBDB::batch_start(uint64_t batch_num_blocks)
+bool BlockchainBDB::batch_start(uint64_t batch_num_blocks)
{
LOG_PRINT_L3("BlockchainBDB::" << __func__);
+ return false;
}
void BlockchainBDB::batch_commit()
diff --git a/src/blockchain_db/berkeleydb/db_bdb.h b/src/blockchain_db/berkeleydb/db_bdb.h
index f320ab0e3..266e780c6 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.h
+++ b/src/blockchain_db/berkeleydb/db_bdb.h
@@ -324,7 +324,7 @@ public:
);
virtual void set_batch_transactions(bool batch_transactions);
- virtual void batch_start(uint64_t batch_num_blocks=0);
+ virtual bool batch_start(uint64_t batch_num_blocks=0);
virtual void batch_commit();
virtual void batch_stop();
virtual void batch_abort();
diff --git a/src/blockchain_db/blockchain_db.cpp b/src/blockchain_db/blockchain_db.cpp
index 7eb81d933..bd1a38ec3 100644
--- a/src/blockchain_db/blockchain_db.cpp
+++ b/src/blockchain_db/blockchain_db.cpp
@@ -32,6 +32,9 @@
#include "cryptonote_core/cryptonote_format_utils.h"
#include "profile_tools.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "blockchain.db"
+
using epee::string_tools::pod_to_hex;
namespace cryptonote
@@ -125,6 +128,8 @@ uint64_t BlockchainDB::add_block( const block& blk
TIME_MEASURE_FINISH(time1);
time_blk_hash += time1;
+ uint64_t prev_height = height();
+
// call out to subclass implementation to add the block & metadata
time1 = epee::misc_utils::get_tick_count();
add_block(blk, block_size, cumulative_difficulty, coins_generated, blk_hash);
@@ -146,9 +151,6 @@ uint64_t BlockchainDB::add_block( const block& blk
TIME_MEASURE_FINISH(time1);
time_add_transaction += time1;
- // DB's new height based on this added block is only incremented after this
- // function returns, so height() here returns the new previous height.
- uint64_t prev_height = height();
m_hardfork->add(blk, prev_height);
block_txn_stop();
diff --git a/src/blockchain_db/blockchain_db.h b/src/blockchain_db/blockchain_db.h
index b39cb1801..455e0c811 100644
--- a/src/blockchain_db/blockchain_db.h
+++ b/src/blockchain_db/blockchain_db.h
@@ -655,16 +655,17 @@ public:
* been called. In either case, it should end the batch and write to its
* backing store.
*
- * If a batch is already in-progress, this function should throw a DB_ERROR.
- * This exception may change in the future if it is deemed necessary to
- * have a more granular exception type for this scenario.
+ * If a batch is already in-progress, this function must return false.
+ * If a batch was started by this call, it must return true.
*
* If any of this cannot be done, the subclass should throw the corresponding
* subclass of DB_EXCEPTION
*
* @param batch_num_blocks number of blocks to batch together
+ *
+ * @return true if we started the batch, false if already started
*/
- virtual void batch_start(uint64_t batch_num_blocks=0) = 0;
+ virtual bool batch_start(uint64_t batch_num_blocks=0) = 0;
/**
* @brief ends a batch transaction
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index ba2cb60bd..343fd1fa4 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -38,6 +38,10 @@
#include "crypto/crypto.h"
#include "profile_tools.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "blockchain.db.lmdb"
+
+
#if defined(__i386) || defined(__x86_64)
#define MISALIGNED_OK 1
#endif
@@ -388,14 +392,14 @@ void BlockchainLMDB::do_resize(uint64_t increase_size)
boost::filesystem::space_info si = boost::filesystem::space(path);
if(si.available < add_size)
{
- LOG_PRINT_RED_L0("!! WARNING: Insufficient free space to extend database !!: " << si.available / 1LL << 20L);
+ MERROR("!! WARNING: Insufficient free space to extend database !!: " << si.available / 1LL << 20L);
return;
}
}
catch(...)
{
// print something but proceed.
- LOG_PRINT_YELLOW("Unable to query free disk space.", LOG_LEVEL_0);
+ MWARNING("Unable to query free disk space.");
}
MDB_envinfo mei;
@@ -437,7 +441,7 @@ void BlockchainLMDB::do_resize(uint64_t increase_size)
if (result)
throw0(DB_ERROR(lmdb_error("Failed to set new mapsize: ", result).c_str()));
- LOG_PRINT_GREEN("LMDB Mapsize increased." << " Old: " << mei.me_mapsize / (1024 * 1024) << "MiB" << ", New: " << new_mapsize / (1024 * 1024) << "MiB", LOG_LEVEL_0);
+ MINFO("LMDB Mapsize increased." << " Old: " << mei.me_mapsize / (1024 * 1024) << "MiB" << ", New: " << new_mapsize / (1024 * 1024) << "MiB");
mdb_txn_safe::allow_new_txns();
}
@@ -543,6 +547,7 @@ uint64_t BlockchainLMDB::get_estimated_batch_size(uint64_t batch_num_blocks) con
uint64_t min_block_size = 4 * 1024;
uint64_t block_stop = 0;
+ uint64_t m_height = height();
if (m_height > 1)
block_stop = m_height - 1;
uint64_t block_start = 0;
@@ -593,6 +598,7 @@ void BlockchainLMDB::add_block(const block& blk, const size_t& block_size, const
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
mdb_txn_cursors *m_cursors = &m_wcursors;
+ uint64_t m_height = height();
CURSOR(block_heights)
blk_height bh = {blk_hash, m_height};
@@ -654,6 +660,7 @@ void BlockchainLMDB::remove_block()
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
+ uint64_t m_height = height();
if (m_height == 0)
throw0(BLOCK_DNE ("Attempting to remove block from an empty blockchain"));
@@ -691,6 +698,7 @@ uint64_t BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, cons
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
mdb_txn_cursors *m_cursors = &m_wcursors;
+ uint64_t m_height = height();
int result;
uint64_t tx_id = m_num_txs;
@@ -787,6 +795,7 @@ uint64_t BlockchainLMDB::add_output(const crypto::hash& tx_hash,
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
mdb_txn_cursors *m_cursors = &m_wcursors;
+ uint64_t m_height = height();
int result = 0;
@@ -1018,7 +1027,6 @@ BlockchainLMDB::BlockchainLMDB(bool batch_transactions)
m_write_txn = nullptr;
m_write_batch_txn = nullptr;
m_batch_active = false;
- m_height = 0;
m_cum_size = 0;
m_cum_count = 0;
@@ -1143,7 +1151,7 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags)
if ((result = mdb_stat(txn, m_blocks, &db_stats)))
throw0(DB_ERROR(lmdb_error("Failed to query m_blocks: ", result).c_str()));
LOG_PRINT_L2("Setting m_height to: " << db_stats.ms_entries);
- m_height = db_stats.ms_entries;
+ uint64_t m_height = db_stats.ms_entries;
// get and keep current number of txs
if ((result = mdb_stat(txn, m_txs, &db_stats)))
@@ -1164,7 +1172,7 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags)
{
if (*(const uint32_t*)v.mv_data > VERSION)
{
- LOG_PRINT_RED_L0("Existing lmdb database was made by a later version. We don't know how it will change yet.");
+ MINFO("Existing lmdb database was made by a later version. We don't know how it will change yet.");
compatible = false;
}
#if VERSION > 0
@@ -1194,8 +1202,8 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags)
txn.abort();
mdb_env_close(m_env);
m_open = false;
- LOG_PRINT_RED_L0("Existing lmdb database is incompatible with this version.");
- LOG_PRINT_RED_L0("Please delete the existing database and resync.");
+ MFATAL("Existing lmdb database is incompatible with this version.");
+ MFATAL("Please delete the existing database and resync.");
return;
}
@@ -1212,7 +1220,7 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags)
txn.abort();
mdb_env_close(m_env);
m_open = false;
- LOG_PRINT_RED_L0("Failed to write version to database.");
+ MERROR("Failed to write version to database.");
return;
}
}
@@ -1294,7 +1302,6 @@ void BlockchainLMDB::reset()
throw0(DB_ERROR(lmdb_error("Failed to write version to database: ", result).c_str()));
txn.commit();
- m_height = 0;
m_num_outputs = 0;
m_cum_size = 0;
m_cum_count = 0;
@@ -1515,6 +1522,7 @@ uint64_t BlockchainLMDB::get_top_block_timestamp() const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
+ uint64_t m_height = height();
// if no blocks, return 0
if (m_height == 0)
@@ -1666,6 +1674,7 @@ crypto::hash BlockchainLMDB::top_block_hash() const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
+ uint64_t m_height = height();
if (m_height != 0)
{
return get_block_hash_from_height(m_height - 1);
@@ -1678,6 +1687,7 @@ block BlockchainLMDB::get_top_block() const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
+ uint64_t m_height = height();
if (m_height != 0)
{
@@ -1692,8 +1702,14 @@ uint64_t BlockchainLMDB::height() const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
+ TXN_PREFIX_RDONLY();
+ int result;
- return m_height;
+ // get current height
+ MDB_stat db_stats;
+ if ((result = mdb_stat(m_txn, m_blocks, &db_stats)))
+ throw0(DB_ERROR(lmdb_error("Failed to query m_blocks: ", result).c_str()));
+ return db_stats.ms_entries;
}
bool BlockchainLMDB::tx_exists(const crypto::hash& h) const
@@ -2242,15 +2258,15 @@ bool BlockchainLMDB::for_all_outputs(std::function<bool(uint64_t amount, const c
}
// batch_num_blocks: (optional) Used to check if resize needed before batch transaction starts.
-void BlockchainLMDB::batch_start(uint64_t batch_num_blocks)
+bool BlockchainLMDB::batch_start(uint64_t batch_num_blocks)
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
if (! m_batch_transactions)
throw0(DB_ERROR("batch transactions not enabled"));
if (m_batch_active)
- throw0(DB_ERROR("batch transaction already in progress"));
+ return false;
if (m_write_batch_txn != nullptr)
- throw0(DB_ERROR("batch transaction already in progress"));
+ return false;
if (m_write_txn)
throw0(DB_ERROR("batch transaction attempted, but m_write_txn already in use"));
check_open();
@@ -2276,6 +2292,7 @@ void BlockchainLMDB::batch_start(uint64_t batch_num_blocks)
memset(&m_wcursors, 0, sizeof(m_wcursors));
LOG_PRINT_L3("batch transaction: begin");
+ return true;
}
void BlockchainLMDB::batch_commit()
@@ -2287,6 +2304,9 @@ void BlockchainLMDB::batch_commit()
throw0(DB_ERROR("batch transaction not in progress"));
if (m_write_batch_txn == nullptr)
throw0(DB_ERROR("batch transaction not in progress"));
+ if (m_writer != boost::this_thread::get_id())
+ return; // batch txn owned by other thread
+
check_open();
LOG_PRINT_L3("batch transaction: committing...");
@@ -2311,6 +2331,8 @@ void BlockchainLMDB::batch_stop()
throw0(DB_ERROR("batch transaction not in progress"));
if (m_write_batch_txn == nullptr)
throw0(DB_ERROR("batch transaction not in progress"));
+ if (m_writer != boost::this_thread::get_id())
+ return; // batch txn owned by other thread
check_open();
LOG_PRINT_L3("batch transaction: committing...");
TIME_MEASURE_START(time1);
@@ -2333,6 +2355,8 @@ void BlockchainLMDB::batch_abort()
throw0(DB_ERROR("batch transactions not enabled"));
if (! m_batch_active)
throw0(DB_ERROR("batch transaction not in progress"));
+ if (m_writer != boost::this_thread::get_id())
+ return; // batch txn owned by other thread
check_open();
// for destruction of batch transaction
m_write_txn = nullptr;
@@ -2505,6 +2529,7 @@ uint64_t BlockchainLMDB::add_block(const block& blk, const size_t& block_size, c
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
+ uint64_t m_height = height();
if (m_height % 1000 == 0)
{
@@ -2558,8 +2583,6 @@ void BlockchainLMDB::pop_block(block& blk, std::vector<transaction>& txs)
block_txn_abort();
throw;
}
-
- --m_height;
}
void BlockchainLMDB::get_output_tx_and_index_from_global(const std::vector<uint64_t> &global_indices,
@@ -2845,31 +2868,36 @@ void BlockchainLMDB::fixup()
ptr = (char *)k.mv_data; \
ptr[sizeof(name)-2] = 's'
-#define LOGIF(y) if (y <= epee::log_space::log_singletone::get_log_detalisation_level())
+#define LOGIF(y) if (ELPP->vRegistry()->allowed(y, MONERO_DEFAULT_LOG_CATEGORY))
void BlockchainLMDB::migrate_0_1()
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
- uint64_t i, z;
+ uint64_t i, z, m_height;
int result;
mdb_txn_safe txn(false);
MDB_val k, v;
char *ptr;
- LOG_PRINT_YELLOW("Migrating blockchain from DB version 0 to 1 - this may take a while:", LOG_LEVEL_0);
- LOG_PRINT_L0("updating blocks, hf_versions, outputs, txs, and spent_keys tables...");
-
- LOG_PRINT_L0("Total number of blocks: " << m_height);
- LOG_PRINT_L1("block migration will update block_heights, block_info, and hf_versions...");
+ MLOG_YELLOW(el::Level::Info, "Migrating blockchain from DB version 0 to 1 - this may take a while:");
+ MINFO("updating blocks, hf_versions, outputs, txs, and spent_keys tables...");
do {
- LOG_PRINT_L1("migrating block_heights:");
- MDB_dbi o_heights;
-
- unsigned int flags;
result = mdb_txn_begin(m_env, NULL, 0, txn);
if (result)
throw0(DB_ERROR(lmdb_error("Failed to create a transaction for the db: ", result).c_str()));
+
+ MDB_stat db_stats;
+ if ((result = mdb_stat(txn, m_blocks, &db_stats)))
+ throw0(DB_ERROR(lmdb_error("Failed to query m_blocks: ", result).c_str()));
+ m_height = db_stats.ms_entries;
+ MINFO("Total number of blocks: " << m_height);
+ MINFO("block migration will update block_heights, block_info, and hf_versions...");
+
+ MINFO("migrating block_heights:");
+ MDB_dbi o_heights;
+
+ unsigned int flags;
result = mdb_dbi_flags(txn, m_block_heights, &flags);
if (result)
throw0(DB_ERROR(lmdb_error("Failed to retrieve block_heights flags: ", result).c_str()));
@@ -2901,7 +2929,7 @@ void BlockchainLMDB::migrate_0_1()
while(1) {
if (!(i % 2000)) {
if (i) {
- LOGIF(1) {
+ LOGIF(el::Level::Info) {
std::cout << i << " / " << z << " \r" << std::flush;
}
txn.commit();
@@ -2992,7 +3020,7 @@ void BlockchainLMDB::migrate_0_1()
MDB_val k, v;
if (!(i % 2000)) {
if (i) {
- LOGIF(1) {
+ LOGIF(el::Level::Info) {
std::cout << i << " / " << z << " \r" << std::flush;
}
txn.commit();
@@ -3124,7 +3152,7 @@ void BlockchainLMDB::migrate_0_1()
while(1) {
if (!(i % 2000)) {
if (i) {
- LOGIF(1) {
+ LOGIF(el::Level::Info) {
std::cout << i << " / " << z << " \r" << std::flush;
}
txn.commit();
@@ -3270,7 +3298,7 @@ void BlockchainLMDB::migrate_0_1()
while(1) {
if (!(i % 1000)) {
if (i) {
- LOGIF(1) {
+ LOGIF(el::Level::Info) {
std::cout << i << " / " << z << " \r" << std::flush;
}
MDB_val_set(pk, "txblk");
diff --git a/src/blockchain_db/lmdb/db_lmdb.h b/src/blockchain_db/lmdb/db_lmdb.h
index b0d8d9d0a..e7faf8cdc 100644
--- a/src/blockchain_db/lmdb/db_lmdb.h
+++ b/src/blockchain_db/lmdb/db_lmdb.h
@@ -247,7 +247,7 @@ public:
);
virtual void set_batch_transactions(bool batch_transactions);
- virtual void batch_start(uint64_t batch_num_blocks=0);
+ virtual bool batch_start(uint64_t batch_num_blocks=0);
virtual void batch_commit();
virtual void batch_stop();
virtual void batch_abort();
@@ -369,7 +369,6 @@ private:
MDB_dbi m_properties;
- uint64_t m_height;
uint64_t m_num_txs;
uint64_t m_num_outputs;
mutable uint64_t m_cum_size; // used in batch size estimation
diff --git a/src/blockchain_utilities/CMakeLists.txt b/src/blockchain_utilities/CMakeLists.txt
index a9ece98fc..b26fe04cc 100644
--- a/src/blockchain_utilities/CMakeLists.txt
+++ b/src/blockchain_utilities/CMakeLists.txt
@@ -72,6 +72,7 @@ target_link_libraries(blockchain_import
cryptonote_core
blockchain_db
p2p
+ epee
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY}
${Boost_THREAD_LIBRARY}
@@ -98,6 +99,7 @@ target_link_libraries(blockchain_export
cryptonote_core
blockchain_db
p2p
+ epee
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY}
${Boost_THREAD_LIBRARY}
@@ -118,6 +120,7 @@ target_link_libraries(cn_deserialize
LINK_PRIVATE
cryptonote_core
p2p
+ epee
${CMAKE_THREAD_LIBS_INIT})
add_dependencies(cn_deserialize
diff --git a/src/blockchain_utilities/blockchain_export.cpp b/src/blockchain_utilities/blockchain_export.cpp
index 231bea337..b4411fbba 100644
--- a/src/blockchain_utilities/blockchain_export.cpp
+++ b/src/blockchain_utilities/blockchain_export.cpp
@@ -38,8 +38,11 @@
#include "blockchain_db/db_types.h"
#include "version.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "bcutil"
+
namespace po = boost::program_options;
-using namespace epee; // log_space
+using namespace epee;
std::string join_set_strings(const std::unordered_set<std::string>& db_types_all, const char* delim)
{
@@ -122,10 +125,8 @@ int main(int argc, char* argv[])
log_level = command_line::get_arg(vm, arg_log_level);
block_stop = command_line::get_arg(vm, arg_block_stop);
- log_space::get_set_log_detalisation_level(true, log_level);
- log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL);
+ mlog_configure("monero-blockchain-export", true);
LOG_PRINT_L0("Starting...");
- LOG_PRINT_L0("Setting log level = " << log_level);
bool opt_testnet = command_line::get_arg(vm, arg_testnet_on);
bool opt_blocks_dat = command_line::get_arg(vm, arg_blocks_dat);
diff --git a/src/blockchain_utilities/blockchain_import.cpp b/src/blockchain_utilities/blockchain_import.cpp
index 27c9050f8..f21673b89 100644
--- a/src/blockchain_utilities/blockchain_import.cpp
+++ b/src/blockchain_utilities/blockchain_import.cpp
@@ -44,6 +44,9 @@
#include "fake_core.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "bcutil"
+
namespace
{
// CONFIG
@@ -132,7 +135,7 @@ int parse_db_arguments(const std::string& db_arg_str, std::string& db_type, int&
#if !defined(BERKELEY_DB)
if (db_type == "berkeley")
{
- LOG_ERROR("BerkeleyDB support disabled.");
+ MFATAL("BerkeleyDB support disabled.");
return false;
}
#endif
@@ -163,7 +166,7 @@ int parse_db_arguments(const std::string& db_arg_str, std::string& db_type, int&
continue;
if (db_type == "lmdb")
{
- LOG_PRINT_L1("LMDB flag: " << it);
+ MINFO("LMDB flag: " << it);
if (it == "nosync")
db_flags |= MDB_NOSYNC;
else if (it == "nometasync")
@@ -211,7 +214,7 @@ int pop_blocks(FakeCore& simple_core, int num_blocks)
if (simple_core.support_batch)
use_batch = true;
else
- LOG_PRINT_L0("WARNING: batch transactions enabled but unsupported or unnecessary for this database type - ignoring");
+ MWARNING("WARNING: batch transactions enabled but unsupported or unnecessary for this database type - ignoring");
}
if (use_batch)
@@ -260,14 +263,14 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
boost::system::error_code ec;
if (!boost::filesystem::exists(fs_import_file_path, ec))
{
- LOG_PRINT_L0("bootstrap file not found: " << fs_import_file_path);
+ MFATAL("bootstrap file not found: " << fs_import_file_path);
return false;
}
BootstrapFile bootstrap;
// BootstrapFile bootstrap(import_file_path);
uint64_t total_source_blocks = bootstrap.count_blocks(import_file_path);
- LOG_PRINT_L0("bootstrap file last block number: " << total_source_blocks-1 << " (zero-based height) total blocks: " << total_source_blocks);
+ MINFO("bootstrap file last block number: " << total_source_blocks-1 << " (zero-based height) total blocks: " << total_source_blocks);
std::cout << ENDL;
std::cout << "Preparing to read blocks..." << ENDL;
@@ -280,7 +283,7 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
uint64_t num_imported = 0;
if (import_file.fail())
{
- LOG_PRINT_L0("import_file.open() fail");
+ MFATAL("import_file.open() fail");
return false;
}
@@ -309,7 +312,7 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
// These are what we'll try to use, and they don't have to be a determination
// from source and destination blockchains, but those are the defaults.
- LOG_PRINT_L0("start block: " << start_height << " stop block: " <<
+ MINFO("start block: " << start_height << " stop block: " <<
block_stop);
bool use_batch = false;
@@ -318,13 +321,13 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
if (simple_core.support_batch)
use_batch = true;
else
- LOG_PRINT_L0("WARNING: batch transactions enabled but unsupported or unnecessary for this database type - ignoring");
+ MWARNING("WARNING: batch transactions enabled but unsupported or unnecessary for this database type - ignoring");
}
if (use_batch)
simple_core.batch_start(db_batch_size);
- LOG_PRINT_L0("Reading blockchain from bootstrap file...");
+ MINFO("Reading blockchain from bootstrap file...");
std::cout << ENDL;
// Within the loop, we skip to start_height before we start adding.
@@ -338,7 +341,7 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
// TODO: bootstrap.read_chunk();
if (! import_file) {
std::cout << refresh_string;
- LOG_PRINT_L0("End of file reached");
+ MINFO("End of file reached");
quit = 1;
break;
}
@@ -349,29 +352,29 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
{
throw std::runtime_error("Error in deserialization of chunk size");
}
- LOG_PRINT_L3("chunk_size: " << chunk_size);
+ MDEBUG("chunk_size: " << chunk_size);
if (chunk_size > BUFFER_SIZE)
{
- LOG_PRINT_L0("WARNING: chunk_size " << chunk_size << " > BUFFER_SIZE " << BUFFER_SIZE);
+ MWARNING("WARNING: chunk_size " << chunk_size << " > BUFFER_SIZE " << BUFFER_SIZE);
throw std::runtime_error("Aborting: chunk size exceeds buffer size");
}
if (chunk_size > 100000)
{
- LOG_PRINT_L0("NOTE: chunk_size " << chunk_size << " > 100000");
+ MINFO("NOTE: chunk_size " << chunk_size << " > 100000");
}
else if (chunk_size == 0) {
- LOG_PRINT_L0("ERROR: chunk_size == 0");
+ MFATAL("ERROR: chunk_size == 0");
return 2;
}
import_file.read(buffer_block, chunk_size);
if (! import_file) {
- LOG_PRINT_L0("ERROR: unexpected end of file: bytes read before error: "
+ MFATAL("ERROR: unexpected end of file: bytes read before error: "
<< import_file.gcount() << " of chunk_size " << chunk_size);
return 2;
}
bytes_read += chunk_size;
- LOG_PRINT_L3("Total bytes read: " << bytes_read);
+ MINFO("Total bytes read: " << bytes_read);
if (h + NUM_BLOCKS_PER_CHUNK < start_height + 1)
{
@@ -384,7 +387,7 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
<< " / " << block_stop
<< std::flush;
std::cout << ENDL << ENDL;
- LOG_PRINT_L0("Specified block number reached - stopping. block: " << h-1 << " total blocks: " << h);
+ MINFO("Specified block number reached - stopping. block: " << h-1 << " total blocks: " << h);
quit = 1;
break;
}
@@ -405,14 +408,14 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
if ((h-1) % display_interval == 0)
{
std::cout << refresh_string;
- LOG_PRINT_L0("loading block number " << h-1);
+ MDEBUG("loading block number " << h-1);
}
else
{
- LOG_PRINT_L3("loading block number " << h-1);
+ MDEBUG("loading block number " << h-1);
}
b = bp.block;
- LOG_PRINT_L2("block prev_id: " << b.prev_id << ENDL);
+ MDEBUG("block prev_id: " << b.prev_id << ENDL);
if ((h-1) % progress_interval == 0)
{
@@ -427,12 +430,12 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
archived_txs = bp.txs;
// std::cout << refresh_string;
- // LOG_PRINT_L1("txs: " << archived_txs.size());
+ // MDEBUG("txs: " << archived_txs.size());
// if archived_txs is invalid
// {
// std::cout << refresh_string;
- // LOG_PRINT_RED_L0("exception while de-archiving txs, height=" << h);
+ // MFATAL("exception while de-archiving txs, height=" << h);
// quit = 1;
// break;
// }
@@ -445,20 +448,20 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
++tx_num;
// if tx is invalid
// {
- // LOG_PRINT_RED_L0("exception while indexing tx from txs, height=" << h <<", tx_num=" << tx_num);
+ // MFATAL("exception while indexing tx from txs, height=" << h <<", tx_num=" << tx_num);
// quit = 1;
// break;
// }
// std::cout << refresh_string;
- // LOG_PRINT_L1("tx hash: " << get_transaction_hash(tx));
+ // MDEBUG("tx hash: " << get_transaction_hash(tx));
// crypto::hash hsh = null_hash;
// size_t blob_size = 0;
// NOTE: all tx hashes except for coinbase tx are available in the block data
// get_transaction_hash(tx, hsh, blob_size);
- // LOG_PRINT_L0("tx " << tx_num << " " << hsh << " : " << ENDL);
- // LOG_PRINT_L0(obj_to_json_str(tx) << ENDL);
+ // MDEBUG("tx " << tx_num << " " << hsh << " : " << ENDL);
+ // MDEBUG(obj_to_json_str(tx) << ENDL);
// add blocks with verification.
// for Blockchain and blockchain_storage add_new_block().
@@ -472,10 +475,10 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
uint8_t version = simple_core.m_storage.get_current_hard_fork_version();
tx_verification_context tvc = AUTO_VAL_INIT(tvc);
bool r = true;
- r = simple_core.m_pool.add_tx(tx, tvc, true, true, version);
+ r = simple_core.m_pool.add_tx(tx, tvc, true, true, false, version);
if (!r)
{
- LOG_PRINT_RED_L0("failed to add transaction to transaction pool, height=" << h <<", tx_num=" << tx_num);
+ MFATAL("failed to add transaction to transaction pool, height=" << h <<", tx_num=" << tx_num);
quit = 1;
break;
}
@@ -499,8 +502,8 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
if (bvc.m_verifivation_failed)
{
- LOG_PRINT_L0("Failed to add block to blockchain, verification failed, height = " << h);
- LOG_PRINT_L0("skipping rest of file");
+ MFATAL("Failed to add block to blockchain, verification failed, height = " << h);
+ MFATAL("skipping rest of file");
// ok to commit previously batched data because it failed only in
// verification of potential new block with nothing added to batch
// yet
@@ -509,8 +512,8 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
}
if (! bvc.m_added_to_main_chain)
{
- LOG_PRINT_L0("Failed to add block to blockchain, height = " << h);
- LOG_PRINT_L0("skipping rest of file");
+ MFATAL("Failed to add block to blockchain, height = " << h);
+ MFATAL("skipping rest of file");
// make sure we don't commit partial block data
quit = 2;
break;
@@ -527,9 +530,9 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
coins_generated = bp.coins_generated;
// std::cout << refresh_string;
- // LOG_PRINT_L2("block_size: " << block_size);
- // LOG_PRINT_L2("cumulative_difficulty: " << cumulative_difficulty);
- // LOG_PRINT_L2("coins_generated: " << coins_generated);
+ // MDEBUG("block_size: " << block_size);
+ // MDEBUG("cumulative_difficulty: " << cumulative_difficulty);
+ // MDEBUG("coins_generated: " << coins_generated);
try
{
@@ -538,7 +541,7 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
catch (const std::exception& e)
{
std::cout << refresh_string;
- LOG_PRINT_RED_L0("Error adding block to blockchain: " << e.what());
+ MFATAL("Error adding block to blockchain: " << e.what());
quit = 2; // make sure we don't commit partial block data
break;
}
@@ -563,7 +566,7 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
catch (const std::exception& e)
{
std::cout << refresh_string;
- LOG_PRINT_RED_L0("exception while reading from file, height=" << h << ": " << e.what());
+ MFATAL("exception while reading from file, height=" << h << ": " << e.what());
return 2;
}
} // while
@@ -582,10 +585,10 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path,
simple_core.batch_stop();
}
simple_core.m_storage.get_db().show_stats();
- LOG_PRINT_L0("Number of blocks imported: " << num_imported);
+ MINFO("Number of blocks imported: " << num_imported);
if (h > 0)
// TODO: if there was an error, the last added block is probably at zero-based height h-2
- LOG_PRINT_L0("Finished at block: " << h-1 << " total blocks: " << h);
+ MINFO("Finished at block: " << h-1 << " total blocks: " << h);
}
std::cout << ENDL;
return 0;
@@ -602,7 +605,7 @@ int main(int argc, char* argv[])
std::string available_dbs = join_set_strings(db_types_all, ", ");
available_dbs = "available: " + available_dbs;
- uint32_t log_level = LOG_LEVEL_0;
+ uint32_t log_level = 0;
uint64_t num_blocks = 0;
uint64_t block_stop = 0;
std::string m_config_folder;
@@ -719,10 +722,8 @@ int main(int argc, char* argv[])
m_config_folder = command_line::get_arg(vm, data_dir_arg);
db_arg_str = command_line::get_arg(vm, arg_database);
- log_space::get_set_log_detalisation_level(true, log_level);
- log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL);
- LOG_PRINT_L0("Starting...");
- LOG_PRINT_L0("Setting log level = " << log_level);
+ mlog_configure("monero-blockchain-import", true);
+ MINFO("Starting...");
boost::filesystem::path fs_import_file_path;
@@ -767,23 +768,23 @@ int main(int argc, char* argv[])
db_engine_compiled = "memory";
}
- LOG_PRINT_L0("database: " << db_type);
- LOG_PRINT_L0("database flags: " << db_flags);
- LOG_PRINT_L0("verify: " << std::boolalpha << opt_verify << std::noboolalpha);
+ MINFO("database: " << db_type);
+ MINFO("database flags: " << db_flags);
+ MINFO("verify: " << std::boolalpha << opt_verify << std::noboolalpha);
if (opt_batch)
{
- LOG_PRINT_L0("batch: " << std::boolalpha << opt_batch << std::noboolalpha
+ MINFO("batch: " << std::boolalpha << opt_batch << std::noboolalpha
<< " batch size: " << db_batch_size);
}
else
{
- LOG_PRINT_L0("batch: " << std::boolalpha << opt_batch << std::noboolalpha);
+ MINFO("batch: " << std::boolalpha << opt_batch << std::noboolalpha);
}
- LOG_PRINT_L0("resume: " << std::boolalpha << opt_resume << std::noboolalpha);
- LOG_PRINT_L0("testnet: " << std::boolalpha << opt_testnet << std::noboolalpha);
+ MINFO("resume: " << std::boolalpha << opt_resume << std::noboolalpha);
+ MINFO("testnet: " << std::boolalpha << opt_testnet << std::noboolalpha);
- LOG_PRINT_L0("bootstrap file path: " << import_file_path);
- LOG_PRINT_L0("database path: " << m_config_folder);
+ MINFO("bootstrap file path: " << import_file_path);
+ MINFO("database path: " << m_config_folder);
try
{
@@ -813,15 +814,15 @@ int main(int argc, char* argv[])
if (! vm["pop-blocks"].defaulted())
{
num_blocks = command_line::get_arg(vm, arg_pop_blocks);
- LOG_PRINT_L0("height: " << simple_core.m_storage.get_current_blockchain_height());
+ MINFO("height: " << simple_core.m_storage.get_current_blockchain_height());
pop_blocks(simple_core, num_blocks);
- LOG_PRINT_L0("height: " << simple_core.m_storage.get_current_blockchain_height());
+ MINFO("height: " << simple_core.m_storage.get_current_blockchain_height());
return 0;
}
if (! vm["drop-hard-fork"].defaulted())
{
- LOG_PRINT_L0("Dropping hard fork tables...");
+ MINFO("Dropping hard fork tables...");
simple_core.m_storage.get_db().drop_hard_fork_info();
return 0;
}
diff --git a/src/blockchain_utilities/blocksdat_file.cpp b/src/blockchain_utilities/blocksdat_file.cpp
index 926562ba2..7ccb9a145 100644
--- a/src/blockchain_utilities/blocksdat_file.cpp
+++ b/src/blockchain_utilities/blocksdat_file.cpp
@@ -28,6 +28,8 @@
#include "blocksdat_file.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "bcutil"
namespace po = boost::program_options;
@@ -50,7 +52,7 @@ bool BlocksdatFile::open_writer(const boost::filesystem::path& file_path, uint64
{
if (!boost::filesystem::is_directory(dir_path))
{
- LOG_PRINT_RED_L0("export directory path is a file: " << dir_path);
+ MFATAL("export directory path is a file: " << dir_path);
return false;
}
}
@@ -58,7 +60,7 @@ bool BlocksdatFile::open_writer(const boost::filesystem::path& file_path, uint64
{
if (!boost::filesystem::create_directory(dir_path))
{
- LOG_PRINT_RED_L0("Failed to create directory " << dir_path);
+ MFATAL("Failed to create directory " << dir_path);
return false;
}
}
@@ -66,7 +68,7 @@ bool BlocksdatFile::open_writer(const boost::filesystem::path& file_path, uint64
m_raw_data_file = new std::ofstream();
- LOG_PRINT_L0("creating file");
+ MINFO("creating file");
m_raw_data_file->open(file_path.string(), std::ios_base::binary | std::ios_base::out | std::ios::trunc);
if (m_raw_data_file->fail())
@@ -123,21 +125,21 @@ bool BlocksdatFile::store_blockchain_raw(Blockchain* _blockchain_storage, tx_mem
uint64_t block_start = 0;
uint64_t block_stop = 0;
- LOG_PRINT_L0("source blockchain height: " << m_blockchain_storage->get_current_blockchain_height()-1);
+ MINFO("source blockchain height: " << m_blockchain_storage->get_current_blockchain_height()-1);
if ((requested_block_stop > 0) && (requested_block_stop < m_blockchain_storage->get_current_blockchain_height()))
{
- LOG_PRINT_L0("Using requested block height: " << requested_block_stop);
+ MINFO("Using requested block height: " << requested_block_stop);
block_stop = requested_block_stop;
}
else
{
block_stop = m_blockchain_storage->get_current_blockchain_height() - 1;
- LOG_PRINT_L0("Using block height of source blockchain: " << block_stop);
+ MINFO("Using block height of source blockchain: " << block_stop);
}
- LOG_PRINT_L0("Storing blocks raw data...");
+ MINFO("Storing blocks raw data...");
if (!BlocksdatFile::open_writer(output_file, block_stop))
{
- LOG_PRINT_RED_L0("failed to open raw file for write");
+ MFATAL("failed to open raw file for write");
return false;
}
for (m_cur_height = block_start; m_cur_height <= block_stop; ++m_cur_height)
@@ -157,7 +159,7 @@ bool BlocksdatFile::store_blockchain_raw(Blockchain* _blockchain_storage, tx_mem
std::cout << refresh_string;
std::cout << "block " << m_cur_height-1 << "/" << block_stop << ENDL;
- LOG_PRINT_L0("Number of blocks exported: " << num_blocks_written);
+ MINFO("Number of blocks exported: " << num_blocks_written);
return BlocksdatFile::close();
}
diff --git a/src/blockchain_utilities/bootstrap_file.cpp b/src/blockchain_utilities/bootstrap_file.cpp
index 61bd35a6f..add2c65e6 100644
--- a/src/blockchain_utilities/bootstrap_file.cpp
+++ b/src/blockchain_utilities/bootstrap_file.cpp
@@ -32,6 +32,8 @@
#include "bootstrap_file.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "bcutil"
namespace po = boost::program_options;
@@ -59,7 +61,7 @@ bool BootstrapFile::open_writer(const boost::filesystem::path& file_path)
{
if (!boost::filesystem::is_directory(dir_path))
{
- LOG_PRINT_RED_L0("export directory path is a file: " << dir_path);
+ MFATAL("export directory path is a file: " << dir_path);
return false;
}
}
@@ -67,7 +69,7 @@ bool BootstrapFile::open_writer(const boost::filesystem::path& file_path)
{
if (!boost::filesystem::create_directory(dir_path))
{
- LOG_PRINT_RED_L0("Failed to create directory " << dir_path);
+ MFATAL("Failed to create directory " << dir_path);
return false;
}
}
@@ -80,14 +82,14 @@ bool BootstrapFile::open_writer(const boost::filesystem::path& file_path)
if (! boost::filesystem::exists(file_path))
{
- LOG_PRINT_L0("creating file");
+ MDEBUG("creating file");
do_initialize_file = true;
num_blocks = 0;
}
else
{
num_blocks = count_blocks(file_path.string());
- LOG_PRINT_L0("appending to existing file with height: " << num_blocks-1 << " total blocks: " << num_blocks);
+ MDEBUG("appending to existing file with height: " << num_blocks-1 << " total blocks: " << num_blocks);
}
m_height = num_blocks;
@@ -138,7 +140,7 @@ bool BootstrapFile::initialize_file()
uint32_t bd_size = 0;
blobdata bd = t_serializable_object_to_blob(bfi);
- LOG_PRINT_L1("bootstrap::file_info size: " << bd.size());
+ MDEBUG("bootstrap::file_info size: " << bd.size());
bd_size = bd.size();
if (! ::serialization::dump_binary(bd_size, blob))
@@ -149,7 +151,7 @@ bool BootstrapFile::initialize_file()
*output_stream_header << bd;
bd = t_serializable_object_to_blob(bbi);
- LOG_PRINT_L1("bootstrap::blocks_info size: " << bd.size());
+ MDEBUG("bootstrap::blocks_info size: " << bd.size());
bd_size = bd.size();
if (! ::serialization::dump_binary(bd_size, blob))
@@ -172,10 +174,10 @@ void BootstrapFile::flush_chunk()
m_output_stream->flush();
uint32_t chunk_size = m_buffer.size();
- // LOG_PRINT_L0("chunk_size " << chunk_size);
+ // MTRACE("chunk_size " << chunk_size);
if (chunk_size > BUFFER_SIZE)
{
- LOG_PRINT_L0("WARNING: chunk_size " << chunk_size << " > BUFFER_SIZE " << BUFFER_SIZE);
+ MWARNING("WARNING: chunk_size " << chunk_size << " > BUFFER_SIZE " << BUFFER_SIZE);
}
std::string blob;
@@ -196,14 +198,14 @@ void BootstrapFile::flush_chunk()
long num_chars_written = pos_after - pos_before;
if (static_cast<unsigned long>(num_chars_written) != chunk_size)
{
- LOG_PRINT_RED_L0("Error writing chunk: height: " << m_cur_height << " chunk_size: " << chunk_size << " num chars written: " << num_chars_written);
+ MFATAL("Error writing chunk: height: " << m_cur_height << " chunk_size: " << chunk_size << " num chars written: " << num_chars_written);
throw std::runtime_error("Error writing chunk");
}
m_buffer.clear();
delete m_output_stream;
m_output_stream = new boost::iostreams::stream<boost::iostreams::back_insert_device<buffer_type>>(m_buffer);
- LOG_PRINT_L1("flushed chunk: chunk_size: " << chunk_size);
+ MDEBUG("flushed chunk: chunk_size: " << chunk_size);
}
void BootstrapFile::write_block(block& block)
@@ -267,10 +269,10 @@ bool BootstrapFile::store_blockchain_raw(Blockchain* _blockchain_storage, tx_mem
m_blockchain_storage = _blockchain_storage;
m_tx_pool = _tx_pool;
uint64_t progress_interval = 100;
- LOG_PRINT_L0("Storing blocks raw data...");
+ MINFO("Storing blocks raw data...");
if (!BootstrapFile::open_writer(output_file))
{
- LOG_PRINT_RED_L0("failed to open raw file for write");
+ MFATAL("failed to open raw file for write");
return false;
}
block b;
@@ -280,16 +282,16 @@ bool BootstrapFile::store_blockchain_raw(Blockchain* _blockchain_storage, tx_mem
// height.
uint64_t block_start = m_height;
uint64_t block_stop = 0;
- LOG_PRINT_L0("source blockchain height: " << m_blockchain_storage->get_current_blockchain_height()-1);
+ MINFO("source blockchain height: " << m_blockchain_storage->get_current_blockchain_height()-1);
if ((requested_block_stop > 0) && (requested_block_stop < m_blockchain_storage->get_current_blockchain_height()))
{
- LOG_PRINT_L0("Using requested block height: " << requested_block_stop);
+ MINFO("Using requested block height: " << requested_block_stop);
block_stop = requested_block_stop;
}
else
{
block_stop = m_blockchain_storage->get_current_blockchain_height() - 1;
- LOG_PRINT_L0("Using block height of source blockchain: " << block_stop);
+ MINFO("Using block height of source blockchain: " << block_stop);
}
for (m_cur_height = block_start; m_cur_height <= block_stop; ++m_cur_height)
{
@@ -315,9 +317,9 @@ bool BootstrapFile::store_blockchain_raw(Blockchain* _blockchain_storage, tx_mem
std::cout << refresh_string;
std::cout << "block " << m_cur_height-1 << "/" << block_stop << ENDL;
- LOG_PRINT_L0("Number of blocks exported: " << num_blocks_written);
+ MINFO("Number of blocks exported: " << num_blocks_written);
if (num_blocks_written > 0)
- LOG_PRINT_L0("Largest chunk: " << m_max_chunk << " bytes");
+ MINFO("Largest chunk: " << m_max_chunk << " bytes");
return BootstrapFile::close();
}
@@ -338,11 +340,11 @@ uint64_t BootstrapFile::seek_to_first_chunk(std::ifstream& import_file)
if (file_magic != blockchain_raw_magic)
{
- LOG_PRINT_RED_L0("bootstrap file not recognized");
+ MFATAL("bootstrap file not recognized");
throw std::runtime_error("Aborting");
}
else
- LOG_PRINT_L0("bootstrap file recognized");
+ MINFO("bootstrap file recognized");
uint32_t buflen_file_info;
@@ -352,7 +354,7 @@ uint64_t BootstrapFile::seek_to_first_chunk(std::ifstream& import_file)
throw std::runtime_error("Error reading expected number of bytes");
if (! ::serialization::parse_binary(str1, buflen_file_info))
throw std::runtime_error("Error in deserialization of buflen_file_info");
- LOG_PRINT_L1("bootstrap::file_info size: " << buflen_file_info);
+ MINFO("bootstrap::file_info size: " << buflen_file_info);
if (buflen_file_info > sizeof(buf1))
throw std::runtime_error("Error: bootstrap::file_info size exceeds buffer size");
@@ -363,9 +365,9 @@ uint64_t BootstrapFile::seek_to_first_chunk(std::ifstream& import_file)
bootstrap::file_info bfi;
if (! ::serialization::parse_binary(str1, bfi))
throw std::runtime_error("Error in deserialization of bootstrap::file_info");
- LOG_PRINT_L0("bootstrap file v" << unsigned(bfi.major_version) << "." << unsigned(bfi.minor_version));
- LOG_PRINT_L0("bootstrap magic size: " << sizeof(file_magic));
- LOG_PRINT_L0("bootstrap header size: " << bfi.header_size);
+ MINFO("bootstrap file v" << unsigned(bfi.major_version) << "." << unsigned(bfi.minor_version));
+ MINFO("bootstrap magic size: " << sizeof(file_magic));
+ MINFO("bootstrap header size: " << bfi.header_size);
uint64_t full_header_size = sizeof(file_magic) + bfi.header_size;
import_file.seekg(full_header_size);
@@ -379,7 +381,7 @@ uint64_t BootstrapFile::count_blocks(const std::string& import_file_path)
boost::system::error_code ec;
if (!boost::filesystem::exists(raw_file_path, ec))
{
- LOG_PRINT_L0("bootstrap file not found: " << raw_file_path);
+ MFATAL("bootstrap file not found: " << raw_file_path);
throw std::runtime_error("Aborting");
}
std::ifstream import_file;
@@ -388,14 +390,14 @@ uint64_t BootstrapFile::count_blocks(const std::string& import_file_path)
uint64_t h = 0;
if (import_file.fail())
{
- LOG_PRINT_L0("import_file.open() fail");
+ MFATAL("import_file.open() fail");
throw std::runtime_error("Aborting");
}
uint64_t full_header_size; // 4 byte magic + length of header structures
full_header_size = seek_to_first_chunk(import_file);
- LOG_PRINT_L0("Scanning blockchain from bootstrap file...");
+ MINFO("Scanning blockchain from bootstrap file...");
block b;
bool quit = false;
uint64_t bytes_read = 0;
@@ -409,7 +411,7 @@ uint64_t BootstrapFile::count_blocks(const std::string& import_file_path)
import_file.read(buf1, sizeof(chunk_size));
if (!import_file) {
std::cout << refresh_string;
- LOG_PRINT_L1("End of file reached");
+ MDEBUG("End of file reached");
quit = true;
break;
}
@@ -425,38 +427,38 @@ uint64_t BootstrapFile::count_blocks(const std::string& import_file_path)
str1.assign(buf1, sizeof(chunk_size));
if (! ::serialization::parse_binary(str1, chunk_size))
throw std::runtime_error("Error in deserialization of chunk_size");
- LOG_PRINT_L3("chunk_size: " << chunk_size);
+ MDEBUG("chunk_size: " << chunk_size);
if (chunk_size > BUFFER_SIZE)
{
std::cout << refresh_string;
- LOG_PRINT_L0("WARNING: chunk_size " << chunk_size << " > BUFFER_SIZE " << BUFFER_SIZE
+ MWARNING("WARNING: chunk_size " << chunk_size << " > BUFFER_SIZE " << BUFFER_SIZE
<< " height: " << h-1);
throw std::runtime_error("Aborting: chunk size exceeds buffer size");
}
if (chunk_size > 100000)
{
std::cout << refresh_string;
- LOG_PRINT_L0("NOTE: chunk_size " << chunk_size << " > 100000" << " height: "
+ MDEBUG("NOTE: chunk_size " << chunk_size << " > 100000" << " height: "
<< h-1);
}
else if (chunk_size <= 0) {
std::cout << refresh_string;
- LOG_PRINT_L0("ERROR: chunk_size " << chunk_size << " <= 0" << " height: " << h-1);
+ MDEBUG("ERROR: chunk_size " << chunk_size << " <= 0" << " height: " << h-1);
throw std::runtime_error("Aborting");
}
// skip to next expected block size value
import_file.seekg(chunk_size, std::ios_base::cur);
if (! import_file) {
std::cout << refresh_string;
- LOG_PRINT_L0("ERROR: unexpected end of file: bytes read before error: "
+ MFATAL("ERROR: unexpected end of file: bytes read before error: "
<< import_file.gcount() << " of chunk_size " << chunk_size);
throw std::runtime_error("Aborting");
}
bytes_read += chunk_size;
// std::cout << refresh_string;
- LOG_PRINT_L3("Number bytes scanned: " << bytes_read);
+ MINFO("Number bytes scanned: " << bytes_read);
}
import_file.close();
diff --git a/src/blockchain_utilities/cn_deserialize.cpp b/src/blockchain_utilities/cn_deserialize.cpp
index a8448dcee..ae8e38435 100644
--- a/src/blockchain_utilities/cn_deserialize.cpp
+++ b/src/blockchain_utilities/cn_deserialize.cpp
@@ -33,8 +33,11 @@
#include "common/command_line.h"
#include "version.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "bcutil"
+
namespace po = boost::program_options;
-using namespace epee; // log_space
+using namespace epee;
using namespace cryptonote;
@@ -87,8 +90,7 @@ int main(int argc, char* argv[])
return 1;
}
- log_space::get_set_log_detalisation_level(true, log_level);
- log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL);
+ mlog_configure("", true);
std::string m_config_folder;
diff --git a/src/blockchain_utilities/fake_core.h b/src/blockchain_utilities/fake_core.h
index ba1c2ed72..814139602 100644
--- a/src/blockchain_utilities/fake_core.h
+++ b/src/blockchain_utilities/fake_core.h
@@ -119,9 +119,9 @@ struct fake_core_db
return m_storage.get_db().add_block(blk, block_size, cumulative_difficulty, coins_generated, txs);
}
- void batch_start(uint64_t batch_num_blocks = 0)
+ bool batch_start(uint64_t batch_num_blocks = 0)
{
- m_storage.get_db().batch_start(batch_num_blocks);
+ return m_storage.get_db().batch_start(batch_num_blocks);
}
void batch_stop()
diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp
index 35fb9fe6c..2efdcffcd 100644
--- a/src/common/dns_utils.cpp
+++ b/src/common/dns_utils.cpp
@@ -41,6 +41,9 @@
using namespace epee;
namespace bf = boost::filesystem;
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net.dns"
+
static boost::mutex instance_lock;
namespace
diff --git a/src/common/i18n.cpp b/src/common/i18n.cpp
index c04790ce6..05eea3b66 100644
--- a/src/common/i18n.cpp
+++ b/src/common/i18n.cpp
@@ -36,6 +36,9 @@
#include "common/util.h"
#include "common/i18n.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "i18n"
+
static const unsigned char qm_magic[16] = {0x3c, 0xb8, 0x64, 0x18, 0xca, 0xef, 0x9c, 0x95, 0xcd, 0x21, 0x1c, 0xbf, 0x60, 0xa1, 0xbd, 0xdd};
static std::map<std::string,std::string> i18n_entries;
diff --git a/src/common/perf_timer.cpp b/src/common/perf_timer.cpp
index d23c9f11d..3b68485d9 100644
--- a/src/common/perf_timer.cpp
+++ b/src/common/perf_timer.cpp
@@ -28,18 +28,22 @@
#include "perf_timer.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "perf"
+
namespace tools
{
-int performance_timer_log_level = 2;
+el::Level performance_timer_log_level = el::Level::Debug;
__thread std::vector<PerformanceTimer*> *performance_timers = NULL;
-void set_performance_timer_log_level(int level)
+void set_performance_timer_log_level(el::Level level)
{
- if (level < LOG_LEVEL_MIN || level > LOG_LEVEL_MAX)
+ if (level != el::Level::Debug && level != el::Level::Trace && level != el::Level::Info
+ && level != el::Level::Warning && level != el::Level::Error && level != el::Level::Fatal)
{
- LOG_PRINT_L0("Wrong log level: " << level << ", using 2");
- level = 2;
+ MERROR("Wrong log level: " << el::LevelHelper::convertToString(level) << ", using Debug");
+ level = el::Level::Debug;
}
performance_timer_log_level = level;
}
diff --git a/src/common/perf_timer.h b/src/common/perf_timer.h
index 5eb5aaaec..56662ff24 100644
--- a/src/common/perf_timer.h
+++ b/src/common/perf_timer.h
@@ -32,23 +32,26 @@
#include <stdio.h>
#include "misc_log_ex.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "perf"
+
namespace tools
{
class PerformanceTimer;
-extern int performance_timer_log_level;
+extern el::Level performance_timer_log_level;
extern __thread std::vector<PerformanceTimer*> *performance_timers;
class PerformanceTimer
{
public:
- PerformanceTimer(const std::string &s, int l = LOG_LEVEL_2): name(s), level(l), started(false)
+ PerformanceTimer(const std::string &s, el::Level l = el::Level::Debug): name(s), level(l), started(false)
{
ticks = epee::misc_utils::get_tick_count();
if (!performance_timers)
{
- LOG_PRINT("PERF ----------", level);
+ MLOG(level, "PERF ----------");
performance_timers = new std::vector<PerformanceTimer*>();
}
else
@@ -56,7 +59,7 @@ public:
PerformanceTimer *pt = performance_timers->back();
if (!pt->started)
{
- LOG_PRINT("PERF " << std::string((performance_timers->size()-1) * 2, ' ') << " " << pt->name, pt->level);
+ MLOG(pt->level, "PERF " << std::string((performance_timers->size()-1) * 2, ' ') << " " << pt->name);
pt->started = true;
}
}
@@ -69,7 +72,7 @@ public:
ticks = epee::misc_utils::get_tick_count() - ticks;
char s[12];
snprintf(s, sizeof(s), "%8llu ", (unsigned long long)ticks);
- LOG_PRINT("PERF " << s << std::string(performance_timers->size() * 2, ' ') << " " << name, level);
+ MLOG(level, "PERF " << s << std::string(performance_timers->size() * 2, ' ') << " " << name);
if (performance_timers->empty())
{
delete performance_timers;
@@ -79,12 +82,12 @@ public:
private:
std::string name;
- int level;
+ el::Level level;
uint64_t ticks;
bool started;
};
-void set_performance_timer_log_level(int level);
+void set_performance_timer_log_level(el::Level level);
#define PERF_TIMER(name) tools::PerformanceTimer pt_##name(#name, tools::performance_timer_log_level)
#define PERF_TIMER_L(name, l) tools::PerformanceTimer pt_##name(#name, l)
diff --git a/src/common/scoped_message_writer.h b/src/common/scoped_message_writer.h
index 77dda7181..f82181926 100644
--- a/src/common/scoped_message_writer.h
+++ b/src/common/scoped_message_writer.h
@@ -34,20 +34,23 @@
namespace tools
{
+/************************************************************************/
+/* */
+/************************************************************************/
class scoped_message_writer
{
private:
bool m_flush;
std::stringstream m_oss;
- epee::log_space::console_colors m_color;
+ epee::console_colors m_color;
bool m_bright;
- int m_log_level;
+ el::Level m_log_level;
public:
scoped_message_writer(
- epee::log_space::console_colors color = epee::log_space::console_color_default
+ epee::console_colors color = epee::console_color_default
, bool bright = false
, std::string&& prefix = std::string()
- , int log_level = LOG_LEVEL_2
+ , el::Level log_level = el::Level::Info
)
: m_flush(true)
, m_color(color)
@@ -88,17 +91,17 @@ public:
{
m_flush = false;
- LOG_PRINT(m_oss.str(), m_log_level);
+ MCLOG(m_log_level, "msgwriter", m_oss.str());
- if (epee::log_space::console_color_default == m_color)
+ if (epee::console_color_default == m_color)
{
std::cout << m_oss.str();
}
else
{
- epee::log_space::set_console_color(m_color, m_bright);
+ set_console_color(m_color, m_bright);
std::cout << m_oss.str();
- epee::log_space::reset_console_color();
+ epee::reset_console_color();
}
std::cout << std::endl;
}
@@ -107,17 +110,17 @@ public:
inline scoped_message_writer success_msg_writer()
{
- return scoped_message_writer(epee::log_space::console_color_green, false, std::string(), LOG_LEVEL_2);
+ return scoped_message_writer(epee::console_color_green, false, std::string(), el::Level::Info);
}
-inline scoped_message_writer msg_writer(epee::log_space::console_colors color = epee::log_space::console_color_default)
+inline scoped_message_writer msg_writer(epee::console_colors color = epee::console_color_default)
{
- return scoped_message_writer(color, false, std::string(), LOG_LEVEL_2);
+ return scoped_message_writer(color, false, std::string(), el::Level::Info);
}
inline scoped_message_writer fail_msg_writer()
{
- return scoped_message_writer(epee::log_space::console_color_red, true, "Error: ", LOG_LEVEL_0);
+ return scoped_message_writer(epee::console_color_red, true, "Error: ", el::Level::Error);
}
} // namespace tools
diff --git a/src/common/stack_trace.cpp b/src/common/stack_trace.cpp
index 5bbd3e252..ce05b7e04 100644
--- a/src/common/stack_trace.cpp
+++ b/src/common/stack_trace.cpp
@@ -35,6 +35,11 @@
#include <dlfcn.h>
#endif
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "stacktrace"
+
+#define ST_LOG(x) CERROR(el::base::Writer,el::base::DispatchAction::FileOnlyLog,MONERO_DEFAULT_LOG_CATEGORY) << x
+
// from http://stackoverflow.com/questions/11665829/how-can-i-print-stack-trace-for-caught-exceptions-in-c-code-injection-in-c
// The decl of __cxa_throw in /usr/include/.../cxxabi.h uses
@@ -103,34 +108,34 @@ void log_stack_trace(const char *msg)
const char *log = stack_trace_log.empty() ? NULL : stack_trace_log.c_str();
if (msg)
- LOG_PRINT2(log, msg, LOG_LEVEL_0);
- LOG_PRINT2(log, "Unwound call stack:", LOG_LEVEL_0);
+ ST_LOG(msg);
+ ST_LOG("Unwound call stack:");
if (unw_getcontext(&ctx) < 0) {
- LOG_PRINT2(log, "Failed to create unwind context", LOG_LEVEL_0);
+ ST_LOG("Failed to create unwind context");
return;
}
if (unw_init_local(&cur, &ctx) < 0) {
- LOG_PRINT2(log, "Failed to find the first unwind frame", LOG_LEVEL_0);
+ ST_LOG("Failed to find the first unwind frame");
return;
}
for (level = 1; level < 999; ++level) { // 999 for safety
int ret = unw_step(&cur);
if (ret < 0) {
- LOG_PRINT2(log, "Failed to find the next frame", LOG_LEVEL_0);
+ ST_LOG("Failed to find the next frame");
return;
}
if (ret == 0)
break;
if (unw_get_reg(&cur, UNW_REG_IP, &ip) < 0) {
- LOG_PRINT2(log, " " << std::setw(4) << level, LOG_LEVEL_0);
+ ST_LOG(" " << std::setw(4) << level);
continue;
}
if (unw_get_proc_name(&cur, sym, sizeof(sym), &off) < 0) {
- LOG_PRINT2(log, " " << std::setw(4) << level << std::setbase(16) << std::setw(20) << "0x" << ip, LOG_LEVEL_0);
+ ST_LOG(" " << std::setw(4) << level << std::setbase(16) << std::setw(20) << "0x" << ip);
continue;
}
dsym = abi::__cxa_demangle(sym, NULL, NULL, &status);
- LOG_PRINT2(log, " " << std::setw(4) << level << std::setbase(16) << std::setw(20) << "0x" << ip << " " << (!status && dsym ? dsym : sym) << " + " << "0x" << off, LOG_LEVEL_0);
+ ST_LOG(" " << std::setw(4) << level << std::setbase(16) << std::setw(20) << "0x" << ip << " " << (!status && dsym ? dsym : sym) << " + " << "0x" << off);
free(dsym);
}
}
diff --git a/src/common/util.h b/src/common/util.h
index 501a6d487..4437d821f 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -152,7 +152,7 @@ namespace tools
}
else
{
- LOG_PRINT_RED_L0("Got control signal " << type << ". Exiting without saving...");
+ MGINFO_RED("Got control signal " << type << ". Exiting without saving...");
return FALSE;
}
return TRUE;
diff --git a/src/cryptonote_core/CMakeLists.txt b/src/cryptonote_core/CMakeLists.txt
index 3b676e8ce..ad1745b7f 100644
--- a/src/cryptonote_core/CMakeLists.txt
+++ b/src/cryptonote_core/CMakeLists.txt
@@ -76,7 +76,6 @@ target_link_libraries(cryptonote_core
PUBLIC
common
crypto
- otshell_utils
blockchain_db
ringct
${Boost_DATE_TIME_LIBRARY}
diff --git a/src/cryptonote_core/account.cpp b/src/cryptonote_core/account.cpp
index 602561489..8f2db6863 100644
--- a/src/cryptonote_core/account.cpp
+++ b/src/cryptonote_core/account.cpp
@@ -40,6 +40,10 @@ extern "C"
}
#include "cryptonote_core/cryptonote_basic_impl.h"
#include "cryptonote_core/cryptonote_format_utils.h"
+
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "account"
+
using namespace std;
DISABLE_VS_WARNINGS(4244 4345)
@@ -82,7 +86,9 @@ DISABLE_VS_WARNINGS(4244 4345)
if (recover)
{
- m_creation_timestamp = std::max(mktime(&timestamp), (long)0);
+ m_creation_timestamp = mktime(&timestamp);
+ if (m_creation_timestamp == (uint64_t)-1) // failure
+ m_creation_timestamp = 0; // lowest value
}
else
{
@@ -105,7 +111,9 @@ DISABLE_VS_WARNINGS(4244 4345)
timestamp.tm_min = 0;
timestamp.tm_sec = 0;
- m_creation_timestamp = std::max(mktime(&timestamp), (long)0);
+ m_creation_timestamp = mktime(&timestamp);
+ if (m_creation_timestamp == (uint64_t)-1) // failure
+ m_creation_timestamp = 0; // lowest value
}
//-----------------------------------------------------------------
void account_base::create_from_viewkey(const cryptonote::account_public_address& address, const crypto::secret_key& viewkey)
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index de3af8e02..8f1f0b260 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -56,6 +56,9 @@
#include "blocks/blocks.h"
#endif
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "blockchain"
+
//#include "serialization/json_archive.h"
/* TODO:
@@ -71,6 +74,8 @@ extern "C" void slow_hash_free_state();
DISABLE_VS_WARNINGS(4267)
+#define MERROR_VER(x) MCERROR("verify", x)
+
// used to overestimate the block reward when estimating a per kB to use
#define BLOCK_REWARD_OVERESTIMATE (10 * 1000000000000)
@@ -180,7 +185,7 @@ bool Blockchain::scan_outputkeys_for_indexes(size_t tx_version, const txin_to_ke
}
catch (...)
{
- LOG_PRINT_L0("Output does not exist! amount = " << tx_in_to_key.amount);
+ MERROR_VER("Output does not exist! amount = " << tx_in_to_key.amount);
return false;
}
}
@@ -189,7 +194,7 @@ bool Blockchain::scan_outputkeys_for_indexes(size_t tx_version, const txin_to_ke
// check for partial results and add the rest if needed;
if (outputs.size() < absolute_offsets.size() && outputs.size() > 0)
{
- LOG_PRINT_L1("Additional outputs needed: " << absolute_offsets.size() - outputs.size());
+ MDEBUG("Additional outputs needed: " << absolute_offsets.size() - outputs.size());
std::vector < uint64_t > add_offsets;
std::vector<output_data_t> add_outputs;
for (size_t i = outputs.size(); i < absolute_offsets.size(); i++)
@@ -200,7 +205,7 @@ bool Blockchain::scan_outputkeys_for_indexes(size_t tx_version, const txin_to_ke
}
catch (...)
{
- LOG_PRINT_L0("Output does not exist! amount = " << tx_in_to_key.amount);
+ MERROR_VER("Output does not exist! amount = " << tx_in_to_key.amount);
return false;
}
outputs.insert(outputs.end(), add_outputs.begin(), add_outputs.end());
@@ -224,13 +229,13 @@ bool Blockchain::scan_outputkeys_for_indexes(size_t tx_version, const txin_to_ke
// call to the passed boost visitor to grab the public key for the output
if (!vis.handle_output(output_index.unlock_time, output_index.pubkey, output_index.commitment))
{
- LOG_PRINT_L0("Failed to handle_output for output no = " << count << ", with absolute offset " << i);
+ MERROR_VER("Failed to handle_output for output no = " << count << ", with absolute offset " << i);
return false;
}
}
catch (...)
{
- LOG_PRINT_L0("Output does not exist! amount = " << tx_in_to_key.amount << ", absolute_offset = " << i);
+ MERROR_VER("Output does not exist! amount = " << tx_in_to_key.amount << ", absolute_offset = " << i);
return false;
}
@@ -248,12 +253,12 @@ bool Blockchain::scan_outputkeys_for_indexes(size_t tx_version, const txin_to_ke
}
catch (const OUTPUT_DNE& e)
{
- LOG_PRINT_L0("Output does not exist: " << e.what());
+ MERROR_VER("Output does not exist: " << e.what());
return false;
}
catch (const TX_DNE& e)
{
- LOG_PRINT_L0("Transaction does not exist: " << e.what());
+ MERROR_VER("Transaction does not exist: " << e.what());
return false;
}
@@ -326,7 +331,7 @@ bool Blockchain::init(BlockchainDB* db, const bool testnet, const cryptonote::te
// taking testnet into account
if(!m_db->height())
{
- LOG_PRINT_L0("Blockchain not loaded, generating genesis block.");
+ MINFO("Blockchain not loaded, generating genesis block.");
block bl = boost::value_initialized<block>();
block_verification_context bvc = boost::value_initialized<block_verification_context>();
if (m_testnet)
@@ -372,9 +377,10 @@ bool Blockchain::init(BlockchainDB* db, const bool testnet, const cryptonote::te
load_compiled_in_block_hashes();
#endif
- LOG_PRINT_GREEN("Blockchain initialized. last block: " << m_db->height() - 1 << ", " << epee::misc_utils::get_time_interval_string(timestamp_diff) << " time ago, current difficulty: " << get_difficulty_for_next_block(), LOG_LEVEL_0);
+ MINFO("Blockchain initialized. last block: " << m_db->height() - 1 << ", " << epee::misc_utils::get_time_interval_string(timestamp_diff) << " time ago, current difficulty: " << get_difficulty_for_next_block());
m_db->block_txn_stop();
+ update_next_cumulative_size_limit();
return true;
}
//------------------------------------------------------------------
@@ -403,18 +409,18 @@ bool Blockchain::store_blockchain()
}
catch (const std::exception& e)
{
- LOG_PRINT_L0(std::string("Error syncing blockchain db: ") + e.what() + "-- shutting down now to prevent issues!");
+ MERROR(std::string("Error syncing blockchain db: ") + e.what() + "-- shutting down now to prevent issues!");
throw;
}
catch (...)
{
- LOG_PRINT_L0("There was an issue storing the blockchain, shutting down now to prevent issues!");
+ MERROR("There was an issue storing the blockchain, shutting down now to prevent issues!");
throw;
}
TIME_MEASURE_FINISH(save);
if(m_show_time_stats)
- LOG_PRINT_L0("Blockchain stored OK, took: " << save << " ms");
+ MINFO("Blockchain stored OK, took: " << save << " ms");
return true;
}
//------------------------------------------------------------------
@@ -422,7 +428,7 @@ bool Blockchain::deinit()
{
LOG_PRINT_L3("Blockchain::" << __func__);
- LOG_PRINT_L1("Stopping blockchain read/write activity");
+ MTRACE("Stopping blockchain read/write activity");
// stop async service
m_async_work_idle.reset();
@@ -440,7 +446,7 @@ bool Blockchain::deinit()
try
{
m_db->close();
- LOG_PRINT_L1("Local blockchain read/write activity stopped successfully");
+ MTRACE("Local blockchain read/write activity stopped successfully");
}
catch (const std::exception& e)
{
@@ -508,7 +514,7 @@ block Blockchain::pop_block_from_blockchain()
// that might not be always true. Unlikely though, and always relaying
// these again might cause a spike of traffic as many nodes re-relay
// all the transactions in a popped block when a reorg happens.
- bool r = m_tx_pool.add_tx(tx, tvc, true, true, version);
+ bool r = m_tx_pool.add_tx(tx, tvc, true, true, false, version);
if (!r)
{
LOG_ERROR("Error returning transaction to tx_pool");
@@ -532,6 +538,7 @@ bool Blockchain::reset_and_set_genesis_block(const block& b)
block_verification_context bvc = boost::value_initialized<block_verification_context>();
add_new_block(b, bvc);
+ update_next_cumulative_size_limit();
return bvc.m_added_to_main_chain && !bvc.m_verifivation_failed;
}
//------------------------------------------------------------------
@@ -618,12 +625,12 @@ crypto::hash Blockchain::get_block_id_by_height(uint64_t height) const
}
catch (const std::exception& e)
{
- LOG_PRINT_L0(std::string("Something went wrong fetching block hash by height: ") + e.what());
+ MERROR(std::string("Something went wrong fetching block hash by height: ") + e.what());
throw;
}
catch (...)
{
- LOG_PRINT_L0(std::string("Something went wrong fetching block hash by height"));
+ MERROR(std::string("Something went wrong fetching block hash by height"));
throw;
}
return null_hash;
@@ -652,12 +659,12 @@ bool Blockchain::get_block_by_hash(const crypto::hash &h, block &blk) const
}
catch (const std::exception& e)
{
- LOG_PRINT_L0(std::string("Something went wrong fetching block by hash: ") + e.what());
+ MERROR(std::string("Something went wrong fetching block by hash: ") + e.what());
throw;
}
catch (...)
{
- LOG_PRINT_L0(std::string("Something went wrong fetching block hash by hash"));
+ MERROR(std::string("Something went wrong fetching block hash by hash"));
throw;
}
@@ -771,10 +778,10 @@ bool Blockchain::rollback_blockchain_switching(std::list<block>& original_chain,
m_hardfork->reorganize_from_chain_height(rollback_height);
- LOG_PRINT_L1("Rollback to height " << rollback_height << " was successful.");
+ MINFO("Rollback to height " << rollback_height << " was successful.");
if (original_chain.size())
{
- LOG_PRINT_L1("Restoration to previous blockchain successful as well.");
+ MINFO("Restoration to previous blockchain successful as well.");
}
return true;
}
@@ -822,7 +829,7 @@ bool Blockchain::switch_to_alternative_blockchain(std::list<blocks_ext_by_hash::
// return false
if(!r || !bvc.m_added_to_main_chain)
{
- LOG_PRINT_L1("Failed to switch to alternative blockchain");
+ MERROR("Failed to switch to alternative blockchain");
// rollback_blockchain_switching should be moved to two different
// functions: rollback and apply_chain, but for now we pretend it is
@@ -833,7 +840,7 @@ bool Blockchain::switch_to_alternative_blockchain(std::list<blocks_ext_by_hash::
// about them again so we can immediately dismiss them, but needs some
// looking into.
add_block_as_invalid(ch_ent->second, get_block_hash(ch_ent->second.bl));
- LOG_PRINT_L1("The block was inserted as invalid while connecting new alternative chain, block_id: " << get_block_hash(ch_ent->second.bl));
+ MERROR("The block was inserted as invalid while connecting new alternative chain, block_id: " << get_block_hash(ch_ent->second.bl));
m_alternative_chains.erase(*alt_ch_iter++);
for(auto alt_ch_to_orph_iter = alt_ch_iter; alt_ch_to_orph_iter != alt_chain.end(); )
@@ -855,7 +862,7 @@ bool Blockchain::switch_to_alternative_blockchain(std::list<blocks_ext_by_hash::
bool r = handle_alternative_block(old_ch_ent, get_block_hash(old_ch_ent), bvc);
if(!r)
{
- LOG_PRINT_L1("Failed to push ex-main chain blocks to alternative chain ");
+ MERROR("Failed to push ex-main chain blocks to alternative chain ");
// previously this would fail the blockchain switching, but I don't
// think this is bad enough to warrant that.
}
@@ -870,7 +877,7 @@ bool Blockchain::switch_to_alternative_blockchain(std::list<blocks_ext_by_hash::
m_hardfork->reorganize_from_chain_height(split_height);
- LOG_PRINT_GREEN("REORGANIZE SUCCESS! on height: " << split_height << ", new blockchain size: " << m_db->height(), LOG_LEVEL_0);
+ MGINFO_GREEN("REORGANIZE SUCCESS! on height: " << split_height << ", new blockchain size: " << m_db->height());
return true;
}
//------------------------------------------------------------------
@@ -951,10 +958,10 @@ bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height)
CHECK_AND_ASSERT_MES(b.miner_tx.vin[0].type() == typeid(txin_gen), false, "coinbase transaction in the block has the wrong type");
if(boost::get<txin_gen>(b.miner_tx.vin[0]).height != height)
{
- LOG_PRINT_RED_L1("The miner transaction in block has invalid height: " << boost::get<txin_gen>(b.miner_tx.vin[0]).height << ", expected: " << height);
+ MWARNING("The miner transaction in block has invalid height: " << boost::get<txin_gen>(b.miner_tx.vin[0]).height << ", expected: " << height);
return false;
}
- LOG_PRINT_L1("Miner tx hash: " << get_transaction_hash(b.miner_tx));
+ MDEBUG("Miner tx hash: " << get_transaction_hash(b.miner_tx));
CHECK_AND_ASSERT_MES(b.miner_tx.unlock_time == height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW, false, "coinbase transaction transaction has the wrong unlock time=" << b.miner_tx.unlock_time << ", expected " << height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW);
//check outs overflow
@@ -963,7 +970,7 @@ bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height)
// does not overflow a uint64_t, and this transaction *is* a uint64_t...
if(!check_outs_overflow(b.miner_tx))
{
- LOG_PRINT_RED_L1("miner transaction has money overflow in block " << get_block_hash(b));
+ MERROR("miner transaction has money overflow in block " << get_block_hash(b));
return false;
}
@@ -983,7 +990,7 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl
if (version == 3) {
for (auto &o: b.miner_tx.vout) {
if (!is_valid_decomposed_amount(o.amount)) {
- LOG_PRINT_L1("miner tx output " << print_money(o.amount) << " is not a valid decomposed amount");
+ MERROR_VER("miner tx output " << print_money(o.amount) << " is not a valid decomposed amount");
return false;
}
}
@@ -993,12 +1000,12 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl
get_last_n_blocks_sizes(last_blocks_sizes, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
if (!get_block_reward(epee::misc_utils::median(last_blocks_sizes), cumulative_block_size, already_generated_coins, base_reward, version))
{
- LOG_PRINT_L1("block size " << cumulative_block_size << " is bigger than allowed for this blockchain");
+ MERROR_VER("block size " << cumulative_block_size << " is bigger than allowed for this blockchain");
return false;
}
if(base_reward + fee < money_in_use)
{
- LOG_PRINT_L1("coinbase transaction spend too much money (" << print_money(money_in_use) << "). Block reward is " << print_money(base_reward + fee) << "(" << print_money(base_reward) << "+" << print_money(fee) << ")");
+ MERROR_VER("coinbase transaction spend too much money (" << print_money(money_in_use) << "). Block reward is " << print_money(base_reward + fee) << "(" << print_money(base_reward) << "+" << print_money(fee) << ")");
return false;
}
// From hard fork 2, we allow a miner to claim less block reward than is allowed, in case a miner wants less dust
@@ -1006,7 +1013,7 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl
{
if(base_reward + fee != money_in_use)
{
- LOG_PRINT_L1("coinbase transaction doesn't use full amount of block reward: spent: " << money_in_use << ", block reward " << base_reward + fee << "(" << base_reward << "+" << fee << ")");
+ MDEBUG("coinbase transaction doesn't use full amount of block reward: spent: " << money_in_use << ", block reward " << base_reward + fee << "(" << base_reward << "+" << fee << ")");
return false;
}
}
@@ -1137,7 +1144,7 @@ bool Blockchain::create_block_template(block& b, const account_public_address& m
LOG_ERROR("Creating block template: error: wrongly calculated fee");
}
CRITICAL_REGION_END();
- LOG_PRINT_L1("Creating block template: height " << height <<
+ MDEBUG("Creating block template: height " << height <<
", median size " << median_size <<
", already generated coins " << already_generated_coins <<
", transaction size " << txs_size <<
@@ -1155,7 +1162,7 @@ bool Blockchain::create_block_template(block& b, const account_public_address& m
CHECK_AND_ASSERT_MES(r, false, "Failed to construct miner tx, first chance");
size_t cumulative_size = txs_size + get_object_blobsize(b.miner_tx);
#if defined(DEBUG_CREATE_BLOCK_TEMPLATE)
- LOG_PRINT_L1("Creating block template: miner tx size " << get_object_blobsize(b.miner_tx) <<
+ MDEBUG("Creating block template: miner tx size " << get_object_blobsize(b.miner_tx) <<
", cumulative size " << cumulative_size);
#endif
for (size_t try_count = 0; try_count != 10; ++try_count)
@@ -1168,7 +1175,7 @@ bool Blockchain::create_block_template(block& b, const account_public_address& m
{
cumulative_size = txs_size + coinbase_blob_size;
#if defined(DEBUG_CREATE_BLOCK_TEMPLATE)
- LOG_PRINT_L1("Creating block template: miner tx size " << coinbase_blob_size <<
+ MDEBUG("Creating block template: miner tx size " << coinbase_blob_size <<
", cumulative size " << cumulative_size << " is greater then before");
#endif
continue;
@@ -1178,7 +1185,7 @@ bool Blockchain::create_block_template(block& b, const account_public_address& m
{
size_t delta = cumulative_size - txs_size - coinbase_blob_size;
#if defined(DEBUG_CREATE_BLOCK_TEMPLATE)
- LOG_PRINT_L1("Creating block template: miner tx size " << coinbase_blob_size <<
+ MDEBUG("Creating block template: miner tx size " << coinbase_blob_size <<
", cumulative size " << txs_size + coinbase_blob_size <<
" is less then before, adding " << delta << " zero bytes");
#endif
@@ -1191,16 +1198,16 @@ bool Blockchain::create_block_template(block& b, const account_public_address& m
if (cumulative_size != txs_size + get_object_blobsize(b.miner_tx))
{
//fuck, not lucky, -1 makes varint-counter size smaller, in that case we continue to grow with cumulative_size
- LOG_PRINT_RED("Miner tx creation has no luck with delta_extra size = " << delta << " and " << delta - 1 , LOG_LEVEL_2);
+ MDEBUG("Miner tx creation has no luck with delta_extra size = " << delta << " and " << delta - 1);
cumulative_size += delta - 1;
continue;
}
- LOG_PRINT_GREEN("Setting extra for block: " << b.miner_tx.extra.size() << ", try_count=" << try_count, LOG_LEVEL_1);
+ MDEBUG("Setting extra for block: " << b.miner_tx.extra.size() << ", try_count=" << try_count);
}
}
CHECK_AND_ASSERT_MES(cumulative_size == txs_size + get_object_blobsize(b.miner_tx), false, "unexpected case: cumulative_size=" << cumulative_size << " is not equal txs_cumulative_size=" << txs_size << " + get_object_blobsize(b.miner_tx)=" << get_object_blobsize(b.miner_tx));
#if defined(DEBUG_CREATE_BLOCK_TEMPLATE)
- LOG_PRINT_L1("Creating block template: miner tx size " << coinbase_blob_size <<
+ MDEBUG("Creating block template: miner tx size " << coinbase_blob_size <<
", cumulative size " << cumulative_size << " is now good");
#endif
return true;
@@ -1244,7 +1251,7 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
uint64_t block_height = get_block_height(b);
if(0 == block_height)
{
- LOG_PRINT_L1("Block with id: " << epee::string_tools::pod_to_hex(id) << " (as alternative), but miner tx says height is 0.");
+ MERROR_VER("Block with id: " << epee::string_tools::pod_to_hex(id) << " (as alternative), but miner tx says height is 0.");
bvc.m_verifivation_failed = true;
return false;
}
@@ -1254,7 +1261,15 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
// the block to be added, then this is fine.
if (!m_checkpoints.is_alternative_block_allowed(get_current_blockchain_height(), block_height))
{
- LOG_PRINT_RED_L1("Block with id: " << id << std::endl << " can't be accepted for alternative chain, block height: " << block_height << std::endl << " blockchain height: " << get_current_blockchain_height());
+ MERROR_VER("Block with id: " << id << std::endl << " can't be accepted for alternative chain, block height: " << block_height << std::endl << " blockchain height: " << get_current_blockchain_height());
+ bvc.m_verifivation_failed = true;
+ return false;
+ }
+
+ // this is a cheap test
+ if (!m_hardfork->check_for_height(b, block_height))
+ {
+ LOG_PRINT_L1("Block with id: " << id << std::endl << "has old version for height " << block_height);
bvc.m_verifivation_failed = true;
return false;
}
@@ -1289,7 +1304,7 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
// this alternate chain with it.
if (!m_db->block_exists(alt_chain.front()->second.bl.prev_id))
{
- LOG_PRINT_L1("alternate chain does not appear to connect to main chain...");
+ MERROR("alternate chain does not appear to connect to main chain...");
return false;
}
@@ -1312,7 +1327,7 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
// (not earlier than the median of the last X blocks)
if(!check_block_timestamp(timestamps, b))
{
- LOG_PRINT_RED_L1("Block with id: " << id << std::endl << " for alternative chain, has invalid timestamp: " << b.timestamp);
+ MERROR_VER("Block with id: " << id << std::endl << " for alternative chain, has invalid timestamp: " << b.timestamp);
bvc.m_verifivation_failed = true;
return false;
}
@@ -1338,14 +1353,14 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
get_block_longhash(bei.bl, proof_of_work, bei.height);
if(!check_hash(proof_of_work, current_diff))
{
- LOG_PRINT_RED_L1("Block with id: " << id << std::endl << " for alternative chain, does not have enough proof of work: " << proof_of_work << std::endl << " expected difficulty: " << current_diff);
+ MERROR_VER("Block with id: " << id << std::endl << " for alternative chain, does not have enough proof of work: " << proof_of_work << std::endl << " expected difficulty: " << current_diff);
bvc.m_verifivation_failed = true;
return false;
}
if(!prevalidate_miner_transaction(b, bei.height))
{
- LOG_PRINT_RED_L1("Block with id: " << epee::string_tools::pod_to_hex(id) << " (as alternative) has incorrect miner transaction.");
+ MERROR_VER("Block with id: " << epee::string_tools::pod_to_hex(id) << " (as alternative) has incorrect miner transaction.");
bvc.m_verifivation_failed = true;
return false;
}
@@ -1375,7 +1390,7 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
if(is_a_checkpoint)
{
//do reorganize!
- LOG_PRINT_GREEN("###### REORGANIZE on height: " << alt_chain.front()->second.height << " of " << m_db->height() - 1 << ", checkpoint is found in alternative chain on height " << bei.height, LOG_LEVEL_0);
+ MGINFO_GREEN("###### REORGANIZE on height: " << alt_chain.front()->second.height << " of " << m_db->height() - 1 << ", checkpoint is found in alternative chain on height " << bei.height);
bool r = switch_to_alternative_blockchain(alt_chain, true);
@@ -1387,7 +1402,7 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
else if(main_chain_cumulative_difficulty < bei.cumulative_difficulty) //check if difficulty bigger then in main chain
{
//do reorganize!
- LOG_PRINT_GREEN("###### REORGANIZE on height: " << alt_chain.front()->second.height << " of " << m_db->height() - 1 << " with cum_difficulty " << m_db->get_block_cumulative_difficulty(m_db->height() - 1) << std::endl << " alternative blockchain size: " << alt_chain.size() << " with cum_difficulty " << bei.cumulative_difficulty, LOG_LEVEL_0);
+ MGINFO_GREEN("###### REORGANIZE on height: " << alt_chain.front()->second.height << " of " << m_db->height() - 1 << " with cum_difficulty " << m_db->get_block_cumulative_difficulty(m_db->height() - 1) << std::endl << " alternative blockchain size: " << alt_chain.size() << " with cum_difficulty " << bei.cumulative_difficulty);
bool r = switch_to_alternative_blockchain(alt_chain, false);
if (r)
@@ -1398,7 +1413,7 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
}
else
{
- LOG_PRINT_BLUE("----- BLOCK ADDED AS ALTERNATIVE ON HEIGHT " << bei.height << std::endl << "id:\t" << id << std::endl << "PoW:\t" << proof_of_work << std::endl << "difficulty:\t" << current_diff, LOG_LEVEL_0);
+ MGINFO_BLUE("----- BLOCK ADDED AS ALTERNATIVE ON HEIGHT " << bei.height << std::endl << "id:\t" << id << std::endl << "PoW:\t" << proof_of_work << std::endl << "difficulty:\t" << current_diff);
return true;
}
}
@@ -1406,7 +1421,7 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
{
//block orphaned
bvc.m_marked_as_orphaned = true;
- LOG_PRINT_RED_L1("Block recognized as orphaned and rejected, id = " << id);
+ MERROR_VER("Block recognized as orphaned and rejected, id = " << id);
}
return true;
@@ -1795,7 +1810,7 @@ bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qbloc
// how can we expect to sync from the client that the block list came from?
if(!qblock_ids.size() /*|| !req.m_total_height*/)
{
- LOG_PRINT_L1("Client sent wrong NOTIFY_REQUEST_CHAIN: m_block_ids.size()=" << qblock_ids.size() << /*", m_height=" << req.m_total_height <<*/ ", dropping connection");
+ MCERROR("net.p2p", "Client sent wrong NOTIFY_REQUEST_CHAIN: m_block_ids.size()=" << qblock_ids.size() << /*", m_height=" << req.m_total_height <<*/ ", dropping connection");
return false;
}
@@ -1805,7 +1820,7 @@ bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qbloc
auto gen_hash = m_db->get_block_hash_from_height(0);
if(qblock_ids.back() != gen_hash)
{
- LOG_PRINT_L1("Client sent wrong NOTIFY_REQUEST_CHAIN: genesis block mismatch: " << std::endl << "id: " << qblock_ids.back() << ", " << std::endl << "expected: " << gen_hash << "," << std::endl << " dropping connection");
+ MCERROR("net.p2p", "Client sent wrong NOTIFY_REQUEST_CHAIN: genesis block mismatch: " << std::endl << "id: " << qblock_ids.back() << ", " << std::endl << "expected: " << gen_hash << "," << std::endl << " dropping connection");
m_db->block_txn_abort();
return false;
}
@@ -1823,7 +1838,7 @@ bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qbloc
}
catch (const std::exception& e)
{
- LOG_PRINT_L1("Non-critical error trying to find block by hash in BlockchainDB, hash: " << *bl_it);
+ MWARNING("Non-critical error trying to find block by hash in BlockchainDB, hash: " << *bl_it);
m_db->block_txn_abort();
return false;
}
@@ -1834,7 +1849,7 @@ bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qbloc
// but just in case...
if(bl_it == qblock_ids.end())
{
- LOG_PRINT_L1("Internal error handling connection, can't find split point");
+ MERROR("Internal error handling connection, can't find split point");
return false;
}
@@ -1853,7 +1868,7 @@ uint64_t Blockchain::block_difficulty(uint64_t i) const
}
catch (const BLOCK_DNE& e)
{
- LOG_PRINT_L0("Attempted to get block difficulty for height above blockchain height");
+ MERROR("Attempted to get block difficulty for height above blockchain height");
}
return 0;
}
@@ -1918,7 +1933,7 @@ void Blockchain::print_blockchain(uint64_t start_index, uint64_t end_index) cons
auto h = m_db->height();
if(start_index > h)
{
- LOG_PRINT_L1("Wrong starter index set: " << start_index << ", expected max index " << h);
+ MERROR("Wrong starter index set: " << start_index << ", expected max index " << h);
return;
}
@@ -1926,8 +1941,7 @@ void Blockchain::print_blockchain(uint64_t start_index, uint64_t end_index) cons
{
ss << "height " << i << ", timestamp " << m_db->get_block_timestamp(i) << ", cumul_dif " << m_db->get_block_cumulative_difficulty(i) << ", size " << m_db->get_block_size(i) << "\nid\t\t" << m_db->get_block_hash_from_height(i) << "\ndifficulty\t\t" << m_db->get_block_difficulty(i) << ", nonce " << m_db->get_block_from_height(i).nonce << ", tx_count " << m_db->get_block_from_height(i).tx_hashes.size() << std::endl;
}
- LOG_PRINT_L1("Current blockchain:" << std::endl << ss.str());
- LOG_PRINT_L0("Blockchain printed with log level 1");
+ MCINFO("globlal", "Current blockchain:" << std::endl << ss.str());
}
//------------------------------------------------------------------
void Blockchain::print_blockchain_index() const
@@ -1944,7 +1958,7 @@ void Blockchain::print_blockchain_index() const
}
}
- LOG_PRINT_L0("Current blockchain index:" << std::endl << ss.str());
+ MINFO("Current blockchain index:" << std::endl << ss.str());
}
//------------------------------------------------------------------
//TODO: remove this function and references to it
@@ -2031,7 +2045,7 @@ bool Blockchain::add_block_as_invalid(const block_extended_info& bei, const cryp
CRITICAL_REGION_LOCAL(m_blockchain_lock);
auto i_res = m_invalid_blocks.insert(std::map<crypto::hash, block_extended_info>::value_type(h, bei));
CHECK_AND_ASSERT_MES(i_res.second, false, "at insertion invalid by tx returned status existed");
- LOG_PRINT_L1("BLOCK ADDED AS INVALID: " << h << std::endl << ", prev_id=" << bei.bl.prev_id << ", m_invalid_blocks count=" << m_invalid_blocks.size());
+ MINFO("BLOCK ADDED AS INVALID: " << h << std::endl << ", prev_id=" << bei.bl.prev_id << ", m_invalid_blocks count=" << m_invalid_blocks.size());
return true;
}
//------------------------------------------------------------------
@@ -2148,7 +2162,7 @@ bool Blockchain::get_tx_outputs_gindexs(const crypto::hash& tx_id, std::vector<u
uint64_t tx_index;
if (!m_db->tx_exists(tx_id, tx_index))
{
- LOG_PRINT_RED_L1("warning: get_tx_outputs_gindexs failed to find transaction with id = " << tx_id);
+ MERROR_VER("get_tx_outputs_gindexs failed to find transaction with id = " << tx_id);
return false;
}
@@ -2190,7 +2204,7 @@ bool Blockchain::check_tx_inputs(transaction& tx, uint64_t& max_used_block_heigh
if(m_show_time_stats)
{
size_t mixin = tx.vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(tx.vin[0]).key_offsets.size() - 1 : 0;
- LOG_PRINT_L0("HASH: " << "-" << " I/M/O: " << tx.vin.size() << "/" << mixin << "/" << tx.vout.size() << " H: " << 0 << " chcktx: " << a);
+ MINFO("HASH: " << "-" << " I/M/O: " << tx.vin.size() << "/" << mixin << "/" << tx.vout.size() << " H: " << 0 << " chcktx: " << a);
}
return true;
}
@@ -2202,7 +2216,7 @@ bool Blockchain::check_tx_inputs(transaction& tx, uint64_t& max_used_block_heigh
if(m_show_time_stats)
{
size_t mixin = tx.vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(tx.vin[0]).key_offsets.size() - 1 : 0;
- LOG_PRINT_L0("HASH: " << get_transaction_hash(tx) << " I/M/O: " << tx.vin.size() << "/" << mixin << "/" << tx.vout.size() << " H: " << max_used_block_height << " ms: " << a + m_fake_scan_time << " B: " << get_object_blobsize(tx));
+ MINFO("HASH: " << get_transaction_hash(tx) << " I/M/O: " << tx.vin.size() << "/" << mixin << "/" << tx.vout.size() << " H: " << max_used_block_height << " ms: " << a + m_fake_scan_time << " B: " << get_object_blobsize(tx));
}
if (!res)
return false;
@@ -2333,10 +2347,7 @@ bool Blockchain::expand_transaction_2(transaction &tx, const crypto::hash &tx_pr
CHECK_AND_ASSERT_MES(false, false, "Unsupported rct tx type: " + boost::lexical_cast<std::string>(rv.type));
}
- // outPk
- CHECK_AND_ASSERT_MES(rv.outPk.size() == tx.vout.size(), false, "Bad outPk size");
- for (size_t n = 0; n < tx.rct_signatures.outPk.size(); ++n)
- rv.outPk[n].dest = rct::pk2rct(boost::get<txout_to_key>(tx.vout[n].target).key);
+ // outPk was already done by handle_incoming_tx
return true;
}
@@ -2381,7 +2392,7 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
else
{
uint64_t n_outputs = m_db->get_num_outputs(in_to_key.amount);
- LOG_PRINT_L2("output size " << print_money(in_to_key.amount) << ": " << n_outputs << " available");
+ MDEBUG("output size " << print_money(in_to_key.amount) << ": " << n_outputs << " available");
// n_outputs includes the output we're considering
if (n_outputs <= min_mixin)
++n_unmixable;
@@ -2397,13 +2408,13 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
{
if (n_unmixable == 0)
{
- LOG_PRINT_L1("Tx " << get_transaction_hash(tx) << " has too low mixin (" << mixin << "), and no unmixable inputs");
+ MERROR_VER("Tx " << get_transaction_hash(tx) << " has too low mixin (" << mixin << "), and no unmixable inputs");
tvc.m_low_mixin = true;
return false;
}
if (n_mixable > 1)
{
- LOG_PRINT_L1("Tx " << get_transaction_hash(tx) << " has too low mixin (" << mixin << "), and more than one mixable input with unmixable inputs");
+ MERROR_VER("Tx " << get_transaction_hash(tx) << " has too low mixin (" << mixin << "), and more than one mixable input with unmixable inputs");
tvc.m_low_mixin = true;
return false;
}
@@ -2413,14 +2424,14 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
const size_t max_tx_version = (hf_version <= 3) ? 1 : 2;
if (tx.version > max_tx_version)
{
- LOG_PRINT_L1("transaction version " << (unsigned)tx.version << " is higher than max accepted version " << max_tx_version);
+ MERROR_VER("transaction version " << (unsigned)tx.version << " is higher than max accepted version " << max_tx_version);
tvc.m_verifivation_failed = true;
return false;
}
const size_t min_tx_version = (n_unmixable > 0 ? 1 : (hf_version >= 5) ? 2 : 1);
if (tx.version < min_tx_version)
{
- LOG_PRINT_L1("transaction version " << (unsigned)tx.version << " is lower than min accepted version " << min_tx_version);
+ MERROR_VER("transaction version " << (unsigned)tx.version << " is lower than min accepted version " << min_tx_version);
tvc.m_verifivation_failed = true;
return false;
}
@@ -2479,7 +2490,7 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
if(have_tx_keyimg_as_spent(in_to_key.k_image))
{
- LOG_PRINT_L1("Key image already spent in blockchain: " << epee::string_tools::pod_to_hex(in_to_key.k_image));
+ MERROR_VER("Key image already spent in blockchain: " << epee::string_tools::pod_to_hex(in_to_key.k_image));
tvc.m_double_spend = true;
return false;
}
@@ -2495,7 +2506,7 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
{
if(!itk->second)
{
- LOG_PRINT_L1("Failed ring signature for tx " << get_transaction_hash(tx) << " vin key with k_image: " << in_to_key.k_image << " sig_index: " << sig_index);
+ MERROR_VER("Failed ring signature for tx " << get_transaction_hash(tx) << " vin key with k_image: " << in_to_key.k_image << " sig_index: " << sig_index);
return false;
}
@@ -2511,10 +2522,10 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
if (!check_tx_input(tx.version, in_to_key, tx_prefix_hash, tx.version == 1 ? tx.signatures[sig_index] : std::vector<crypto::signature>(), tx.rct_signatures, pubkeys[sig_index], pmax_used_block_height))
{
it->second[in_to_key.k_image] = false;
- LOG_PRINT_L1("Failed to check ring signature for tx " << get_transaction_hash(tx) << " vin key with k_image: " << in_to_key.k_image << " sig_index: " << sig_index);
+ MERROR_VER("Failed to check ring signature for tx " << get_transaction_hash(tx) << " vin key with k_image: " << in_to_key.k_image << " sig_index: " << sig_index);
if (pmax_used_block_height) // a default value of NULL is used when called from Blockchain::handle_block_to_main_chain()
{
- LOG_PRINT_L1(" *pmax_used_block_height: " << *pmax_used_block_height);
+ MERROR_VER(" *pmax_used_block_height: " << *pmax_used_block_height);
}
return false;
@@ -2534,11 +2545,11 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
if (!results[sig_index])
{
it->second[in_to_key.k_image] = false;
- LOG_PRINT_L1("Failed to check ring signature for tx " << get_transaction_hash(tx) << " vin key with k_image: " << in_to_key.k_image << " sig_index: " << sig_index);
+ MERROR_VER("Failed to check ring signature for tx " << get_transaction_hash(tx) << " vin key with k_image: " << in_to_key.k_image << " sig_index: " << sig_index);
if (pmax_used_block_height) // a default value of NULL is used when called from Blockchain::handle_block_to_main_chain()
{
- LOG_PRINT_L1("*pmax_used_block_height: " << *pmax_used_block_height);
+ MERROR_VER("*pmax_used_block_height: " << *pmax_used_block_height);
}
return false;
@@ -2568,7 +2579,7 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
if (failed)
{
- LOG_PRINT_L1("Failed to check ring signatures!, t_loop: " << t_t1);
+ MERROR_VER("Failed to check ring signatures!, t_loop: " << t_t1);
return false;
}
}
@@ -2577,7 +2588,7 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
{
if (!expand_transaction_2(tx, tx_prefix_hash, pubkeys))
{
- LOG_PRINT_L1("Failed to expand rct signatures!");
+ MERROR_VER("Failed to expand rct signatures!");
return false;
}
@@ -2589,7 +2600,7 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
{
case rct::RCTTypeNull: {
// we only accept no signatures for coinbase txes
- LOG_PRINT_L1("Null rct signature on non-coinbase tx");
+ MERROR_VER("Null rct signature on non-coinbase tx");
return false;
}
case rct::RCTTypeSimple: {
@@ -2597,14 +2608,14 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
{
if (pubkeys.size() != rv.mixRing.size())
{
- LOG_PRINT_L1("Failed to check ringct signatures: mismatched pubkeys/mixRing size");
+ MERROR_VER("Failed to check ringct signatures: mismatched pubkeys/mixRing size");
return false;
}
for (size_t i = 0; i < pubkeys.size(); ++i)
{
if (pubkeys[i].size() != rv.mixRing[i].size())
{
- LOG_PRINT_L1("Failed to check ringct signatures: mismatched pubkeys/mixRing size");
+ MERROR_VER("Failed to check ringct signatures: mismatched pubkeys/mixRing size");
return false;
}
}
@@ -2615,12 +2626,12 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
{
if (pubkeys[n][m].dest != rct::rct2pk(rv.mixRing[n][m].dest))
{
- LOG_PRINT_L1("Failed to check ringct signatures: mismatched pubkey at vin " << n << ", index " << m);
+ MERROR_VER("Failed to check ringct signatures: mismatched pubkey at vin " << n << ", index " << m);
return false;
}
if (pubkeys[n][m].mask != rct::rct2pk(rv.mixRing[n][m].mask))
{
- LOG_PRINT_L1("Failed to check ringct signatures: mismatched commitment at vin " << n << ", index " << m);
+ MERROR_VER("Failed to check ringct signatures: mismatched commitment at vin " << n << ", index " << m);
return false;
}
}
@@ -2629,21 +2640,21 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
if (rv.p.MGs.size() != tx.vin.size())
{
- LOG_PRINT_L1("Failed to check ringct signatures: mismatched MGs/vin sizes");
+ MERROR_VER("Failed to check ringct signatures: mismatched MGs/vin sizes");
return false;
}
for (size_t n = 0; n < tx.vin.size(); ++n)
{
if (memcmp(&boost::get<txin_to_key>(tx.vin[n]).k_image, &rv.p.MGs[n].II[0], 32))
{
- LOG_PRINT_L1("Failed to check ringct signatures: mismatched key image");
+ MERROR_VER("Failed to check ringct signatures: mismatched key image");
return false;
}
}
- if (!rct::verRctSimple(rv))
+ if (!rct::verRctSimple(rv, false))
{
- LOG_PRINT_L1("Failed to check ringct signatures!");
+ MERROR_VER("Failed to check ringct signatures!");
return false;
}
break;
@@ -2658,7 +2669,7 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
size_matches &= pubkeys.size() == rv.mixRing[i].size();
if (!size_matches)
{
- LOG_PRINT_L1("Failed to check ringct signatures: mismatched pubkeys/mixRing size");
+ MERROR_VER("Failed to check ringct signatures: mismatched pubkeys/mixRing size");
return false;
}
@@ -2668,12 +2679,12 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
{
if (pubkeys[n][m].dest != rct::rct2pk(rv.mixRing[m][n].dest))
{
- LOG_PRINT_L1("Failed to check ringct signatures: mismatched pubkey at vin " << n << ", index " << m);
+ MERROR_VER("Failed to check ringct signatures: mismatched pubkey at vin " << n << ", index " << m);
return false;
}
if (pubkeys[n][m].mask != rct::rct2pk(rv.mixRing[m][n].mask))
{
- LOG_PRINT_L1("Failed to check ringct signatures: mismatched commitment at vin " << n << ", index " << m);
+ MERROR_VER("Failed to check ringct signatures: mismatched commitment at vin " << n << ", index " << m);
return false;
}
}
@@ -2682,32 +2693,32 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
if (rv.p.MGs.size() != 1)
{
- LOG_PRINT_L1("Failed to check ringct signatures: Bad MGs size");
+ MERROR_VER("Failed to check ringct signatures: Bad MGs size");
return false;
}
if (rv.p.MGs[0].II.size() != tx.vin.size())
{
- LOG_PRINT_L1("Failed to check ringct signatures: mismatched II/vin sizes");
+ MERROR_VER("Failed to check ringct signatures: mismatched II/vin sizes");
return false;
}
for (size_t n = 0; n < tx.vin.size(); ++n)
{
if (memcmp(&boost::get<txin_to_key>(tx.vin[n]).k_image, &rv.p.MGs[0].II[n], 32))
{
- LOG_PRINT_L1("Failed to check ringct signatures: mismatched II/vin sizes");
+ MERROR_VER("Failed to check ringct signatures: mismatched II/vin sizes");
return false;
}
}
- if (!rct::verRct(rv))
+ if (!rct::verRct(rv, false))
{
- LOG_PRINT_L1("Failed to check ringct signatures!");
+ MERROR_VER("Failed to check ringct signatures!");
return false;
}
break;
}
default:
- LOG_PRINT_L1("Unsupported rct type: " << rv.type);
+ MERROR_VER("Unsupported rct type: " << rv.type);
return false;
}
}
@@ -2770,7 +2781,7 @@ bool Blockchain::check_fee(size_t blob_size, uint64_t fee) const
return false;
fee_per_kb = get_dynamic_per_kb_fee(base_reward, median);
}
- LOG_PRINT_L2("Using " << print_money(fee) << "/kB fee");
+ MDEBUG("Using " << print_money(fee) << "/kB fee");
uint64_t needed_fee = blob_size / 1024;
needed_fee += (blob_size % 1024) ? 1 : 0;
@@ -2778,7 +2789,7 @@ bool Blockchain::check_fee(size_t blob_size, uint64_t fee) const
if (fee < needed_fee)
{
- LOG_PRINT_L1("transaction fee is not enough: " << print_money(fee) << ", minimum fee: " << print_money(needed_fee));
+ MERROR_VER("transaction fee is not enough: " << print_money(fee) << ", minimum fee: " << print_money(needed_fee));
return false;
}
return true;
@@ -2808,12 +2819,12 @@ uint64_t Blockchain::get_dynamic_per_kb_fee_estimate(uint64_t grace_blocks) cons
uint64_t base_reward;
if (!get_block_reward(median, 1, already_generated_coins, base_reward, version))
{
- LOG_PRINT_L1("Failed to determine block reward, using placeholder " << print_money(BLOCK_REWARD_OVERESTIMATE) << " as a high bound");
+ MERROR("Failed to determine block reward, using placeholder " << print_money(BLOCK_REWARD_OVERESTIMATE) << " as a high bound");
base_reward = BLOCK_REWARD_OVERESTIMATE;
}
uint64_t fee = get_dynamic_per_kb_fee(base_reward, median);
- LOG_PRINT_L2("Estimating " << grace_blocks << "-block fee at " << print_money(fee) << "/kB");
+ MDEBUG("Estimating " << grace_blocks << "-block fee at " << print_money(fee) << "/kB");
return fee;
}
@@ -2868,7 +2879,7 @@ bool Blockchain::check_tx_input(size_t tx_version, const txin_to_key& txin, cons
//check tx unlock time
if (!m_bch.is_tx_spendtime_unlocked(unlock_time))
{
- LOG_PRINT_L1("One of outputs for one of inputs has wrong tx.unlock_time = " << unlock_time);
+ MERROR_VER("One of outputs for one of inputs has wrong tx.unlock_time = " << unlock_time);
return false;
}
@@ -2888,13 +2899,13 @@ bool Blockchain::check_tx_input(size_t tx_version, const txin_to_key& txin, cons
outputs_visitor vi(output_keys, *this);
if (!scan_outputkeys_for_indexes(tx_version, txin, vi, tx_prefix_hash, pmax_related_block_height))
{
- LOG_PRINT_L1("Failed to get output keys for tx with amount = " << print_money(txin.amount) << " and count indexes " << txin.key_offsets.size());
+ MERROR_VER("Failed to get output keys for tx with amount = " << print_money(txin.amount) << " and count indexes " << txin.key_offsets.size());
return false;
}
if(txin.key_offsets.size() != output_keys.size())
{
- LOG_PRINT_L1("Output keys for tx with amount = " << txin.amount << " and count indexes " << txin.key_offsets.size() << " returned wrong keys count " << output_keys.size());
+ MERROR_VER("Output keys for tx with amount = " << txin.amount << " and count indexes " << txin.key_offsets.size() << " returned wrong keys count " << output_keys.size());
return false;
}
if (tx_version == 1) {
@@ -2920,7 +2931,7 @@ bool Blockchain::check_block_timestamp(std::vector<uint64_t>& timestamps, const
if(b.timestamp < median_ts)
{
- LOG_PRINT_L1("Timestamp of block with id: " << get_block_hash(b) << ", " << b.timestamp << ", less than median of last " << BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW << " blocks, " << median_ts);
+ MERROR_VER("Timestamp of block with id: " << get_block_hash(b) << ", " << b.timestamp << ", less than median of last " << BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW << " blocks, " << median_ts);
return false;
}
@@ -2939,7 +2950,7 @@ bool Blockchain::check_block_timestamp(const block& b) const
LOG_PRINT_L3("Blockchain::" << __func__);
if(b.timestamp > get_adjusted_time() + CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT)
{
- LOG_PRINT_L1("Timestamp of block with id: " << get_block_hash(b) << ", " << b.timestamp << ", bigger than adjusted time + 2 hours");
+ MERROR_VER("Timestamp of block with id: " << get_block_hash(b) << ", " << b.timestamp << ", bigger than adjusted time + 2 hours");
return false;
}
@@ -2973,9 +2984,9 @@ void Blockchain::return_tx_to_pool(const std::vector<transaction> &txs)
// that might not be always true. Unlikely though, and always relaying
// these again might cause a spike of traffic as many nodes re-relay
// all the transactions in a popped block when a reorg happens.
- if (!m_tx_pool.add_tx(tx, tvc, true, true, version))
+ if (!m_tx_pool.add_tx(tx, tvc, true, true, false, version))
{
- LOG_PRINT_L0("Failed to return taken transaction with hash: " << get_transaction_hash(tx) << " to tx_pool");
+ MERROR("Failed to return taken transaction with hash: " << get_transaction_hash(tx) << " to tx_pool");
}
}
}
@@ -2990,11 +3001,11 @@ bool Blockchain::flush_txes_from_pool(const std::list<crypto::hash> &txids)
cryptonote::transaction tx;
size_t blob_size;
uint64_t fee;
- bool relayed;
- LOG_PRINT_L1("Removing txid " << txid << " from the pool");
- if(m_tx_pool.have_tx(txid) && !m_tx_pool.take_tx(txid, tx, blob_size, fee, relayed))
+ bool relayed, do_not_relay;
+ MINFO("Removing txid " << txid << " from the pool");
+ if(m_tx_pool.have_tx(txid) && !m_tx_pool.take_tx(txid, tx, blob_size, fee, relayed, do_not_relay))
{
- LOG_PRINT_L0("Failed to remove txid " << txid << " from the pool");
+ MERROR("Failed to remove txid " << txid << " from the pool");
res = false;
}
}
@@ -3015,7 +3026,7 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash&
m_db->block_txn_start(true);
if(bl.prev_id != get_tail_id())
{
- LOG_PRINT_L1("Block with id: " << id << std::endl << "has wrong prev_id: " << bl.prev_id << std::endl << "expected: " << get_tail_id());
+ MERROR_VER("Block with id: " << id << std::endl << "has wrong prev_id: " << bl.prev_id << std::endl << "expected: " << get_tail_id());
leave:
m_db->block_txn_stop();
return false;
@@ -3024,7 +3035,7 @@ leave:
// this is a cheap test
if (!m_hardfork->check(bl))
{
- LOG_PRINT_L1("Block with id: " << id << std::endl << "has old version: " << (unsigned)bl.major_version << std::endl << "current: " << (unsigned)m_hardfork->get_current_version());
+ MERROR_VER("Block with id: " << id << std::endl << "has old version: " << (unsigned)bl.major_version << std::endl << "current: " << (unsigned)m_hardfork->get_current_version());
bvc.m_verifivation_failed = true;
goto leave;
}
@@ -3036,7 +3047,7 @@ leave:
// of a set number of the most recent blocks.
if(!check_block_timestamp(bl))
{
- LOG_PRINT_L1("Block with id: " << id << std::endl << "has invalid timestamp: " << bl.timestamp);
+ MERROR_VER("Block with id: " << id << std::endl << "has invalid timestamp: " << bl.timestamp);
bvc.m_verifivation_failed = true;
goto leave;
}
@@ -3076,7 +3087,7 @@ leave:
auto hash = get_block_hash(bl);
if (memcmp(&hash, &m_blocks_hash_check[m_db->height()], sizeof(hash)) != 0)
{
- LOG_PRINT_L1("Block with id is INVALID: " << id);
+ MERROR_VER("Block with id is INVALID: " << id);
bvc.m_verifivation_failed = true;
goto leave;
}
@@ -3097,7 +3108,7 @@ leave:
// validate proof_of_work versus difficulty target
if(!check_hash(proof_of_work, current_diffic))
{
- LOG_PRINT_L1("Block with id: " << id << std::endl << "does not have enough proof of work: " << proof_of_work << std::endl << "unexpected difficulty: " << current_diffic);
+ MERROR_VER("Block with id: " << id << std::endl << "does not have enough proof of work: " << proof_of_work << std::endl << "unexpected difficulty: " << current_diffic);
bvc.m_verifivation_failed = true;
goto leave;
}
@@ -3124,7 +3135,7 @@ leave:
// sanity check basic miner tx properties;
if(!prevalidate_miner_transaction(bl, m_db->height()))
{
- LOG_PRINT_L1("Block with id: " << id << " failed to pass prevalidation");
+ MERROR_VER("Block with id: " << id << " failed to pass prevalidation");
bvc.m_verifivation_failed = true;
goto leave;
}
@@ -3153,13 +3164,13 @@ leave:
transaction tx;
size_t blob_size = 0;
uint64_t fee = 0;
- bool relayed = false;
+ bool relayed = false, do_not_relay = false;
TIME_MEASURE_START(aa);
// XXX old code does not check whether tx exists
if (m_db->tx_exists(tx_id))
{
- LOG_PRINT_L1("Block with id: " << id << " attempting to add transaction already in blockchain with id: " << tx_id);
+ MERROR("Block with id: " << id << " attempting to add transaction already in blockchain with id: " << tx_id);
bvc.m_verifivation_failed = true;
return_tx_to_pool(txs);
goto leave;
@@ -3170,9 +3181,9 @@ leave:
TIME_MEASURE_START(bb);
// get transaction with hash <tx_id> from tx_pool
- if(!m_tx_pool.take_tx(tx_id, tx, blob_size, fee, relayed))
+ if(!m_tx_pool.take_tx(tx_id, tx, blob_size, fee, relayed, do_not_relay))
{
- LOG_PRINT_L1("Block with id: " << id << " has at least one unknown transaction with id: " << tx_id);
+ MERROR_VER("Block with id: " << id << " has at least one unknown transaction with id: " << tx_id);
bvc.m_verifivation_failed = true;
return_tx_to_pool(txs);
goto leave;
@@ -3211,11 +3222,11 @@ leave:
tx_verification_context tvc;
if(!check_tx_inputs(tx, tvc))
{
- LOG_PRINT_L1("Block with id: " << id << " has at least one transaction (id: " << tx_id << ") with wrong inputs.");
+ MERROR_VER("Block with id: " << id << " has at least one transaction (id: " << tx_id << ") with wrong inputs.");
//TODO: why is this done? make sure that keeping invalid blocks makes sense.
add_block_as_invalid(bl, id);
- LOG_PRINT_L1("Block with id " << id << " added as invalid because of wrong inputs in transactions");
+ MERROR_VER("Block with id " << id << " added as invalid because of wrong inputs in transactions");
bvc.m_verifivation_failed = true;
return_tx_to_pool(txs);
goto leave;
@@ -3228,10 +3239,10 @@ leave:
// the transaction inputs, but do some sanity checks anyway.
if (memcmp(&m_blocks_txs_check[tx_index++], &tx_id, sizeof(tx_id)) != 0)
{
- LOG_PRINT_L1("Block with id: " << id << " has at least one transaction (id: " << tx_id << ") with wrong inputs.");
+ MERROR_VER("Block with id: " << id << " has at least one transaction (id: " << tx_id << ") with wrong inputs.");
//TODO: why is this done? make sure that keeping invalid blocks makes sense.
add_block_as_invalid(bl, id);
- LOG_PRINT_L1("Block with id " << id << " added as invalid because of wrong inputs in transactions");
+ MERROR_VER("Block with id " << id << " added as invalid because of wrong inputs in transactions");
bvc.m_verifivation_failed = true;
return_tx_to_pool(txs);
goto leave;
@@ -3251,7 +3262,7 @@ leave:
uint64_t already_generated_coins = m_db->height() ? m_db->get_block_already_generated_coins(m_db->height() - 1) : 0;
if(!validate_miner_transaction(bl, cumulative_block_size, fee_summary, base_reward, already_generated_coins, bvc.m_partial_block_reward, m_hardfork->get_current_version()))
{
- LOG_PRINT_L1("Block with id: " << id << " has incorrect miner transaction");
+ MERROR_VER("Block with id: " << id << " has incorrect miner transaction");
bvc.m_verifivation_failed = true;
return_tx_to_pool(txs);
goto leave;
@@ -3310,10 +3321,10 @@ leave:
// do this after updating the hard fork state since the size limit may change due to fork
update_next_cumulative_size_limit();
- LOG_PRINT_L1("+++++ BLOCK SUCCESSFULLY ADDED" << std::endl << "id:\t" << id << std::endl << "PoW:\t" << proof_of_work << std::endl << "HEIGHT " << new_height-1 << ", difficulty:\t" << current_diffic << std::endl << "block reward: " << print_money(fee_summary + base_reward) << "(" << print_money(base_reward) << " + " << print_money(fee_summary) << "), coinbase_blob_size: " << coinbase_blob_size << ", cumulative size: " << cumulative_block_size << ", " << block_processing_time << "(" << target_calculating_time << "/" << longhash_calculating_time << ")ms");
+ MINFO("+++++ BLOCK SUCCESSFULLY ADDED" << std::endl << "id:\t" << id << std::endl << "PoW:\t" << proof_of_work << std::endl << "HEIGHT " << new_height-1 << ", difficulty:\t" << current_diffic << std::endl << "block reward: " << print_money(fee_summary + base_reward) << "(" << print_money(base_reward) << " + " << print_money(fee_summary) << "), coinbase_blob_size: " << coinbase_blob_size << ", cumulative size: " << cumulative_block_size << ", " << block_processing_time << "(" << target_calculating_time << "/" << longhash_calculating_time << ")ms");
if(m_show_time_stats)
{
- LOG_PRINT_L0("Height: " << new_height << " blob: " << coinbase_blob_size << " cumm: "
+ MINFO("Height: " << new_height << " blob: " << coinbase_blob_size << " cumm: "
<< cumulative_block_size << " p/t: " << block_processing_time << " ("
<< target_calculating_time << "/" << longhash_calculating_time << "/"
<< t1 << "/" << t2 << "/" << t3 << "/" << t_exists << "/" << t_pool
@@ -3381,9 +3392,10 @@ bool Blockchain::add_new_block(const block& bl_, block_verification_context& bvc
void Blockchain::check_against_checkpoints(const checkpoints& points, bool enforce)
{
const auto& pts = points.get_points();
+ bool stop_batch;
CRITICAL_REGION_LOCAL(m_blockchain_lock);
- m_db->batch_start();
+ stop_batch = m_db->batch_start();
for (const auto& pt : pts)
{
// if the checkpoint is for a block we don't have yet, move on
@@ -3407,7 +3419,8 @@ void Blockchain::check_against_checkpoints(const checkpoints& points, bool enfor
}
}
}
- m_db->batch_stop();
+ if (stop_batch)
+ m_db->batch_stop();
}
//------------------------------------------------------------------
// returns false if any of the checkpoints loading returns false.
@@ -3439,7 +3452,7 @@ bool Blockchain::update_checkpoints(const std::string& file_path, bool check_dns
}
else
{
- LOG_PRINT_L0("One or more checkpoints fetched from DNS conflicted with existing checkpoints!");
+ MERROR("One or more checkpoints fetched from DNS conflicted with existing checkpoints!");
}
}
@@ -3477,10 +3490,11 @@ void Blockchain::block_longhash_worker(const uint64_t height, const std::vector<
//------------------------------------------------------------------
bool Blockchain::cleanup_handle_incoming_blocks(bool force_sync)
{
- LOG_PRINT_YELLOW("Blockchain::" << __func__, LOG_LEVEL_3);
+ MTRACE("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock);
TIME_MEASURE_START(t1);
+ m_db->batch_stop();
if (m_sync_counter > 0)
{
if (force_sync)
@@ -3526,7 +3540,7 @@ void Blockchain::output_scan_worker(const uint64_t amount, const std::vector<uin
}
catch (const std::exception& e)
{
- LOG_PRINT_L1("EXCEPTION: " << e.what());
+ MERROR_VER("EXCEPTION: " << e.what());
}
catch (...)
{
@@ -3543,13 +3557,20 @@ void Blockchain::output_scan_worker(const uint64_t amount, const std::vector<uin
// keys.
bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_entry> &blocks_entry)
{
- LOG_PRINT_YELLOW("Blockchain::" << __func__, LOG_LEVEL_3);
+ MTRACE("Blockchain::" << __func__);
TIME_MEASURE_START(prepare);
+ bool stop_batch;
CRITICAL_REGION_LOCAL(m_blockchain_lock);
if(blocks_entry.size() == 0)
return false;
+ while (!(stop_batch = m_db->batch_start(blocks_entry.size()))) {
+ m_blockchain_lock.unlock();
+ epee::misc_utils::sleep_no_w(1000);
+ m_blockchain_lock.lock();
+ }
+
if ((m_db->height() + blocks_entry.size()) < m_blocks_hash_check.size())
return true;
@@ -3566,7 +3587,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
std::vector<boost::thread *> thread_list;
int batches = blocks_entry.size() / threads;
int extra = blocks_entry.size() % threads;
- LOG_PRINT_L1("block_batches: " << batches);
+ MDEBUG("block_batches: " << batches);
std::vector<std::unordered_map<crypto::hash, crypto::hash>> maps(threads);
std::vector < std::vector < block >> blocks(threads);
auto it = blocks_entry.begin();
@@ -3589,7 +3610,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
crypto::hash tophash = m_db->top_block_hash();
if (block.prev_id != tophash)
{
- LOG_PRINT_L1("Skipping prepare blocks. New blocks don't belong to chain.");
+ MDEBUG("Skipping prepare blocks. New blocks don't belong to chain.");
return true;
}
}
@@ -3655,7 +3676,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
if (blocks_exist)
{
- LOG_PRINT_L0("Skipping prepare blocks. Blocks exist.");
+ MDEBUG("Skipping prepare blocks. Blocks exist.");
return true;
}
@@ -3669,7 +3690,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
m_fake_pow_calc_time = prepare / blocks_entry.size();
if (blocks_entry.size() > 1 && threads > 1 && m_show_time_stats)
- LOG_PRINT_L0("Prepare blocks took: " << prepare << " ms");
+ MDEBUG("Prepare blocks took: " << prepare << " ms");
TIME_MEASURE_START(scantable);
@@ -3682,7 +3703,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
#define SCAN_TABLE_QUIT(m) \
do { \
- LOG_PRINT_L0(m) ;\
+ MERROR_VER(m) ;\
m_scan_table.clear(); \
return false; \
} while(0); \
@@ -3856,7 +3877,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
{
m_fake_scan_time = scantable / total_txs;
if(m_show_time_stats)
- LOG_PRINT_L0("Prepare scantable took: " << scantable << " ms");
+ MDEBUG("Prepare scantable took: " << scantable << " ms");
}
return true;
@@ -3934,7 +3955,7 @@ void Blockchain::load_compiled_in_block_hashes()
const size_t size_needed = 4 + nblocks * sizeof(crypto::hash);
if(nblocks > 0 && nblocks > m_db->height() && get_blocks_dat_size(m_testnet) >= size_needed)
{
- LOG_PRINT_L0("Loading precomputed blocks: " << nblocks);
+ MINFO("Loading precomputed blocks: " << nblocks);
p += sizeof(uint32_t);
for (uint32_t i = 0; i < nblocks; i++)
{
@@ -3954,12 +3975,12 @@ void Blockchain::load_compiled_in_block_hashes()
size_t blob_size;
uint64_t fee;
- bool relayed;
+ bool relayed, do_not_relay;
transaction pool_tx;
for(const transaction &tx : txs)
{
crypto::hash tx_hash = get_transaction_hash(tx);
- m_tx_pool.take_tx(tx_hash, pool_tx, blob_size, fee, relayed);
+ m_tx_pool.take_tx(tx_hash, pool_tx, blob_size, fee, relayed, do_not_relay);
}
}
}
diff --git a/src/cryptonote_core/checkpoints.cpp b/src/cryptonote_core/checkpoints.cpp
index dc1912856..3cf804ede 100644
--- a/src/cryptonote_core/checkpoints.cpp
+++ b/src/cryptonote_core/checkpoints.cpp
@@ -39,6 +39,9 @@ using namespace epee;
#include <sstream>
#include <random>
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "checkpoints"
+
namespace
{
bool dns_records_match(const std::vector<std::string>& a, const std::vector<std::string>& b)
@@ -99,11 +102,11 @@ namespace cryptonote
if(it->second == h)
{
- LOG_PRINT_GREEN("CHECKPOINT PASSED FOR HEIGHT " << height << " " << h, LOG_LEVEL_1);
+ MINFO("CHECKPOINT PASSED FOR HEIGHT " << height << " " << h);
return true;
}else
{
- LOG_ERROR("CHECKPOINT FAILED FOR HEIGHT " << height << ". EXPECTED HASH: " << it->second << ", FETCHED HASH: " << h);
+ MWARNING("CHECKPOINT FAILED FOR HEIGHT " << height << ". EXPECTED HASH: " << it->second << ", FETCHED HASH: " << h);
return false;
}
}
diff --git a/src/cryptonote_core/cryptonote_basic_impl.cpp b/src/cryptonote_core/cryptonote_basic_impl.cpp
index 4f35b8298..5a8c61dd9 100644
--- a/src/cryptonote_core/cryptonote_basic_impl.cpp
+++ b/src/cryptonote_core/cryptonote_basic_impl.cpp
@@ -42,6 +42,9 @@ using namespace epee;
#include "crypto/hash.h"
#include "common/int-util.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "cn"
+
namespace cryptonote {
struct integrated_address {
@@ -98,7 +101,7 @@ namespace cryptonote {
}
if(current_block_size > 2 * median_size) {
- LOG_PRINT_L4("Block cumulative size is too big: " << current_block_size << ", expected less than " << 2 * median_size);
+ MERROR("Block cumulative size is too big: " << current_block_size << ", expected less than " << 2 * median_size);
return false;
}
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index c63a08ee4..5294431d6 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -49,9 +49,15 @@ using namespace epee;
#if defined(BERKELEY_DB)
#include "blockchain_db/berkeleydb/db_bdb.h"
#endif
+#include "ringct/rctSigs.h"
+
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "cn"
DISABLE_VS_WARNINGS(4355)
+#define MERROR_VER(x) MCERROR("verify", x)
+
namespace cryptonote
{
@@ -281,10 +287,10 @@ namespace cryptonote
const boost::filesystem::path old_files = folder;
if (boost::filesystem::exists(old_files / "blockchain.bin"))
{
- LOG_PRINT_RED_L0("Found old-style blockchain.bin in " << old_files.string());
- LOG_PRINT_RED_L0("Monero now uses a new format. You can either remove blockchain.bin to start syncing");
- LOG_PRINT_RED_L0("the blockchain anew, or use monero-blockchain-export and monero-blockchain-import to");
- LOG_PRINT_RED_L0("convert your existing blockchain.bin to the new format. See README.md for instructions.");
+ MWARNING("Found old-style blockchain.bin in " << old_files.string());
+ MWARNING("Monero now uses a new format. You can either remove blockchain.bin to start syncing");
+ MWARNING("the blockchain anew, or use monero-blockchain-export and monero-blockchain-import to");
+ MWARNING("convert your existing blockchain.bin to the new format. See README.md for instructions.");
return false;
}
}
@@ -309,12 +315,12 @@ namespace cryptonote
}
folder /= db->get_db_name();
- LOG_PRINT_L0("Loading blockchain from folder " << folder.string() << " ...");
+ MGINFO("Loading blockchain from folder " << folder.string() << " ...");
const std::string filename = folder.string();
- // temporarily default to fastest:async:1000
+ // default to fast:async:1
blockchain_db_sync_mode sync_mode = db_async;
- uint64_t blocks_per_sync = 1000;
+ uint64_t blocks_per_sync = 1;
try
{
@@ -325,14 +331,14 @@ namespace cryptonote
boost::split(options, db_sync_mode, boost::is_any_of(" :"));
for(const auto &option : options)
- LOG_PRINT_L0("option: " << option);
+ MDEBUG("option: " << option);
- // default to fast:async:1000
+ // default to fast:async:1
uint64_t DEFAULT_FLAGS = DBS_FAST_MODE;
if(options.size() == 0)
{
- // temporarily default to fastest:async:1000
+ // default to fast:async:1
db_flags = DEFAULT_FLAGS;
}
@@ -348,7 +354,10 @@ namespace cryptonote
else if(options[0] == "fast")
db_flags = DBS_FAST_MODE;
else if(options[0] == "fastest")
+ {
db_flags = DBS_FASTEST_MODE;
+ blocks_per_sync = 1000; // default to fastest:async:1000
+ }
else
db_flags = DEFAULT_FLAGS;
}
@@ -452,7 +461,7 @@ namespace cryptonote
return false;
}
//-----------------------------------------------------------------------------------------------
- bool core::handle_incoming_tx(const blobdata& tx_blob, tx_verification_context& tvc, bool keeped_by_block, bool relayed)
+ bool core::handle_incoming_tx(const blobdata& tx_blob, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
{
tvc = boost::value_initialized<tx_verification_context>();
//want to process all transactions sequentially
@@ -494,6 +503,22 @@ namespace cryptonote
return false;
}
+ // resolve outPk references in rct txes
+ // outPk aren't the only thing that need resolving for a fully resolved tx,
+ // but outPk (1) are needed now to check range proof semantics, and
+ // (2) do not need access to the blockchain to find data
+ if (tx.version >= 2)
+ {
+ rct::rctSig &rv = tx.rct_signatures;
+ if (rv.outPk.size() != tx.vout.size())
+ {
+ LOG_PRINT_L1("WRONG TRANSACTION BLOB, Bad outPk size in tx " << tx_hash << ", rejected");
+ return false;
+ }
+ for (size_t n = 0; n < tx.rct_signatures.outPk.size(); ++n)
+ rv.outPk[n].dest = rct::pk2rct(boost::get<txout_to_key>(tx.vout[n].target).key);
+ }
+
if(!check_tx_semantic(tx, keeped_by_block))
{
LOG_PRINT_L1("WRONG TRANSACTION BLOB, Failed to check tx " << tx_hash << " semantic, rejected");
@@ -501,14 +526,14 @@ namespace cryptonote
return false;
}
- bool r = add_new_tx(tx, tx_hash, tx_prefixt_hash, tx_blob.size(), tvc, keeped_by_block, relayed);
+ bool r = add_new_tx(tx, tx_hash, tx_prefixt_hash, tx_blob.size(), tvc, keeped_by_block, relayed, do_not_relay);
if(tvc.m_verifivation_failed)
- {LOG_PRINT_RED_L1("Transaction verification failed: " << tx_hash);}
+ {MERROR_VER("Transaction verification failed: " << tx_hash);}
else if(tvc.m_verifivation_impossible)
- {LOG_PRINT_RED_L1("Transaction verification impossible: " << tx_hash);}
+ {MERROR_VER("Transaction verification impossible: " << tx_hash);}
if(tvc.m_added_to_pool)
- LOG_PRINT_L1("tx added: " << tx_hash);
+ MDEBUG("tx added: " << tx_hash);
return r;
}
//-----------------------------------------------------------------------------------------------
@@ -527,33 +552,33 @@ namespace cryptonote
{
if(!tx.vin.size())
{
- LOG_PRINT_RED_L1("tx with empty inputs, rejected for tx id= " << get_transaction_hash(tx));
+ MERROR_VER("tx with empty inputs, rejected for tx id= " << get_transaction_hash(tx));
return false;
}
if(!check_inputs_types_supported(tx))
{
- LOG_PRINT_RED_L1("unsupported input types for tx id= " << get_transaction_hash(tx));
+ MERROR_VER("unsupported input types for tx id= " << get_transaction_hash(tx));
return false;
}
if(!check_outs_valid(tx))
{
- LOG_PRINT_RED_L1("tx with invalid outputs, rejected for tx id= " << get_transaction_hash(tx));
+ MERROR_VER("tx with invalid outputs, rejected for tx id= " << get_transaction_hash(tx));
return false;
}
if (tx.version > 1)
{
if (tx.rct_signatures.outPk.size() != tx.vout.size())
{
- LOG_PRINT_RED_L1("tx with mismatched vout/outPk count, rejected for tx id= " << get_transaction_hash(tx));
+ MERROR_VER("tx with mismatched vout/outPk count, rejected for tx id= " << get_transaction_hash(tx));
return false;
}
}
if(!check_money_overflow(tx))
{
- LOG_PRINT_RED_L1("tx has money overflow, rejected for tx id= " << get_transaction_hash(tx));
+ MERROR_VER("tx has money overflow, rejected for tx id= " << get_transaction_hash(tx));
return false;
}
@@ -565,7 +590,7 @@ namespace cryptonote
if(amount_in <= amount_out)
{
- LOG_PRINT_RED_L1("tx with wrong amounts: ins " << amount_in << ", outs " << amount_out << ", rejected for tx id= " << get_transaction_hash(tx));
+ MERROR_VER("tx with wrong amounts: ins " << amount_in << ", outs " << amount_out << ", rejected for tx id= " << get_transaction_hash(tx));
return false;
}
}
@@ -573,17 +598,44 @@ namespace cryptonote
if(!keeped_by_block && get_object_blobsize(tx) >= m_blockchain_storage.get_current_cumulative_blocksize_limit() - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE)
{
- LOG_PRINT_RED_L1("tx is too large " << get_object_blobsize(tx) << ", expected not bigger than " << m_blockchain_storage.get_current_cumulative_blocksize_limit() - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE);
+ MERROR_VER("tx is too large " << get_object_blobsize(tx) << ", expected not bigger than " << m_blockchain_storage.get_current_cumulative_blocksize_limit() - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE);
return false;
}
//check if tx use different key images
if(!check_tx_inputs_keyimages_diff(tx))
{
- LOG_PRINT_RED_L1("tx uses a single key image more than once");
+ MERROR_VER("tx uses a single key image more than once");
return false;
}
+ if (tx.version >= 2)
+ {
+ const rct::rctSig &rv = tx.rct_signatures;
+ switch (rv.type) {
+ case rct::RCTTypeNull:
+ // coinbase should not come here, so we reject for all other types
+ MERROR_VER("Unexpected Null rctSig type");
+ return false;
+ case rct::RCTTypeSimple:
+ if (!rct::verRctSimple(rv, true))
+ {
+ MERROR_VER("rct signature semantics check failed");
+ return false;
+ }
+ break;
+ case rct::RCTTypeFull:
+ if (!rct::verRct(rv, true))
+ {
+ MERROR_VER("rct signature semantics check failed");
+ return false;
+ }
+ break;
+ default:
+ MERROR_VER("Unknown rct type: " << rv.type);
+ return false;
+ }
+ }
return true;
}
@@ -640,13 +692,13 @@ namespace cryptonote
return true;
}
//-----------------------------------------------------------------------------------------------
- bool core::add_new_tx(const transaction& tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed)
+ bool core::add_new_tx(const transaction& tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
{
crypto::hash tx_hash = get_transaction_hash(tx);
crypto::hash tx_prefix_hash = get_transaction_prefix_hash(tx);
blobdata bl;
t_serializable_object_to_blob(tx, bl);
- return add_new_tx(tx, tx_hash, tx_prefix_hash, bl.size(), tvc, keeped_by_block, relayed);
+ return add_new_tx(tx, tx_hash, tx_prefix_hash, bl.size(), tvc, keeped_by_block, relayed, do_not_relay);
}
//-----------------------------------------------------------------------------------------------
size_t core::get_blockchain_total_transactions() const
@@ -654,7 +706,7 @@ namespace cryptonote
return m_blockchain_storage.get_total_transactions();
}
//-----------------------------------------------------------------------------------------------
- bool core::add_new_tx(const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block, bool relayed)
+ bool core::add_new_tx(const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
{
if(m_mempool.have_tx(tx_hash))
{
@@ -669,7 +721,7 @@ namespace cryptonote
}
uint8_t version = m_blockchain_storage.get_current_hard_fork_version();
- return m_mempool.add_tx(tx, tx_hash, blob_size, tvc, keeped_by_block, relayed, version);
+ return m_mempool.add_tx(tx, tx_hash, blob_size, tvc, keeped_by_block, relayed, do_not_relay, version);
}
//-----------------------------------------------------------------------------------------------
bool core::relay_txpool_transactions()
@@ -945,10 +997,10 @@ namespace cryptonote
{
if(!m_starter_message_showed)
{
- LOG_PRINT_L0(ENDL << "**********************************************************************" << ENDL
+ MGINFO_YELLOW(ENDL << "**********************************************************************" << ENDL
<< "The daemon will start synchronizing with the network. It may take up to several hours." << ENDL
<< ENDL
- << "You can set the level of process detailization* through \"set_log <level>\" command*, where <level> is between 0 (no details) and 4 (very verbose)." << ENDL
+ << "You can set the level of process detailization* through \"set_log <level|categories>\" command*, where <level> is between 0 (no details) and 4 (very verbose), or custom category based levels (eg, *:WARNING)" << ENDL
<< ENDL
<< "Use \"help\" command to see the list of available commands." << ENDL
<< ENDL
@@ -967,19 +1019,18 @@ namespace cryptonote
bool core::check_fork_time()
{
HardFork::State state = m_blockchain_storage.get_hard_fork_state();
+ const el::Level level = el::Level::Warning;
switch (state) {
case HardFork::LikelyForked:
- LOG_PRINT_RED_L0(ENDL
- << "**********************************************************************" << ENDL
- << "Last scheduled hard fork is too far in the past." << ENDL
- << "We are most likely forked from the network. Daemon update needed now." << ENDL
- << "**********************************************************************" << ENDL);
+ MCLOG_RED(level, "global", "**********************************************************************");
+ MCLOG_RED(level, "global", "Last scheduled hard fork is too far in the past.");
+ MCLOG_RED(level, "global", "We are most likely forked from the network. Daemon update needed now.");
+ MCLOG_RED(level, "global", "**********************************************************************");
break;
case HardFork::UpdateNeeded:
- LOG_PRINT_RED_L0(ENDL
- << "**********************************************************************" << ENDL
- << "Last scheduled hard fork time shows a daemon update is needed now." << ENDL
- << "**********************************************************************" << ENDL);
+ MCLOG_RED(level, "global", "**********************************************************************");
+ MCLOG_RED(level, "global", "Last scheduled hard fork time shows a daemon update is needed now.");
+ MCLOG_RED(level, "global", "**********************************************************************");
break;
default:
break;
diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h
index a9e80aeee..fa67ff265 100644
--- a/src/cryptonote_core/cryptonote_core.h
+++ b/src/cryptonote_core/cryptonote_core.h
@@ -107,10 +107,11 @@ namespace cryptonote
* @param tvc metadata about the transaction's validity
* @param keeped_by_block if the transaction has been in a block
* @param relayed whether or not the transaction was relayed to us
+ * @param do_not_relay whether to prevent the transaction from being relayed
*
* @return true if the transaction made it to the transaction pool, otherwise false
*/
- bool handle_incoming_tx(const blobdata& tx_blob, tx_verification_context& tvc, bool keeped_by_block, bool relayed);
+ bool handle_incoming_tx(const blobdata& tx_blob, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay);
/**
* @brief handles an incoming block
@@ -641,9 +642,10 @@ namespace cryptonote
* @param tx_prefix_hash the transaction prefix' hash
* @param blob_size the size of the transaction
* @param relayed whether or not the transaction was relayed to us
+ * @param do_not_relay whether to prevent the transaction from being relayed
*
*/
- bool add_new_tx(const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block, bool relayed);
+ bool add_new_tx(const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay);
/**
* @brief add a new transaction to the transaction pool
@@ -654,12 +656,13 @@ namespace cryptonote
* @param tvc return-by-reference metadata about the transaction's verification process
* @param keeped_by_block whether or not the transaction has been in a block
* @param relayed whether or not the transaction was relayed to us
+ * @param do_not_relay whether to prevent the transaction from being relayed
*
* @return true if the transaction is already in the transaction pool,
* is already in a block on the Blockchain, or is successfully added
* to the transaction pool
*/
- bool add_new_tx(const transaction& tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed);
+ bool add_new_tx(const transaction& tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay);
/**
* @copydoc Blockchain::add_new_block
diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp
index d6dbc400a..e04409d87 100644
--- a/src/cryptonote_core/cryptonote_format_utils.cpp
+++ b/src/cryptonote_core/cryptonote_format_utils.cpp
@@ -39,6 +39,9 @@ using namespace epee;
#include "crypto/hash.h"
#include "ringct/rctSigs.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "cn"
+
#define ENCRYPTED_PAYMENT_ID_TAIL 0x8d
static const uint64_t valid_decomposed_outputs[] = {
@@ -368,6 +371,8 @@ namespace cryptonote
//---------------------------------------------------------------
bool remove_field_from_tx_extra(std::vector<uint8_t>& tx_extra, const std::type_info &type)
{
+ if (tx_extra.empty())
+ return true;
std::string extra_str(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size());
std::istringstream iss(extra_str);
binary_archive<false> ar(iss);
@@ -623,7 +628,7 @@ namespace cryptonote
zero_secret_key &= (sender_account_keys.m_spend_secret_key.data[i] == 0);
if (zero_secret_key)
{
- LOG_PRINT_L1("Null secret key, skipping signatures");
+ MDEBUG("Null secret key, skipping signatures");
}
if (tx.version == 1)
@@ -659,7 +664,7 @@ namespace cryptonote
i++;
}
- LOG_PRINT2("construct_tx.log", "transaction_created: " << get_transaction_hash(tx) << ENDL << obj_to_json_str(tx) << ENDL << ss_ring_s.str() , LOG_LEVEL_3);
+ MCINFO("construct_tx", "transaction_created: " << get_transaction_hash(tx) << ENDL << obj_to_json_str(tx) << ENDL << ss_ring_s.str());
}
else
{
@@ -764,7 +769,7 @@ namespace cryptonote
CHECK_AND_ASSERT_MES(tx.vout.size() == outSk.size(), false, "outSk size does not match vout");
- LOG_PRINT2("construct_tx.log", "transaction_created: " << get_transaction_hash(tx) << ENDL << obj_to_json_str(tx) << ENDL, LOG_LEVEL_3);
+ MCINFO("construct_tx", "transaction_created: " << get_transaction_hash(tx) << ENDL << obj_to_json_str(tx) << ENDL);
}
return true;
diff --git a/src/cryptonote_core/difficulty.cpp b/src/cryptonote_core/difficulty.cpp
index 54da77392..1c5b9cfbd 100644
--- a/src/cryptonote_core/difficulty.cpp
+++ b/src/cryptonote_core/difficulty.cpp
@@ -39,6 +39,9 @@
#include "cryptonote_config.h"
#include "difficulty.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "difficulty"
+
namespace cryptonote {
using std::size_t;
diff --git a/src/cryptonote_core/hardfork.cpp b/src/cryptonote_core/hardfork.cpp
index c63ca36ef..13d7d717d 100644
--- a/src/cryptonote_core/hardfork.cpp
+++ b/src/cryptonote_core/hardfork.cpp
@@ -33,6 +33,9 @@
#include "blockchain_db/blockchain_db.h"
#include "hardfork.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "hardfork"
+
using namespace cryptonote;
static uint8_t get_block_vote(const cryptonote::block &b)
@@ -114,6 +117,19 @@ bool HardFork::check(const cryptonote::block &block) const
return do_check(::get_block_version(block), ::get_block_vote(block));
}
+bool HardFork::do_check_for_height(uint8_t block_version, uint8_t voting_version, uint64_t height) const
+{
+ int fork_index = get_voted_fork_index(height);
+ return block_version == heights[fork_index].version
+ && voting_version >= heights[fork_index].version;
+}
+
+bool HardFork::check_for_height(const cryptonote::block &block, uint64_t height) const
+{
+ CRITICAL_REGION_LOCAL(lock);
+ return do_check_for_height(::get_block_version(block), ::get_block_vote(block), height);
+}
+
bool HardFork::add(uint8_t block_version, uint8_t voting_version, uint64_t height)
{
CRITICAL_REGION_LOCAL(lock);
diff --git a/src/cryptonote_core/hardfork.h b/src/cryptonote_core/hardfork.h
index 33b958f9c..8d2edfa2a 100644
--- a/src/cryptonote_core/hardfork.h
+++ b/src/cryptonote_core/hardfork.h
@@ -114,6 +114,20 @@ namespace cryptonote
bool check(const cryptonote::block &block) const;
/**
+ * @brief same as check, but for a particular height, rather than the top
+ *
+ * NOTE: this does not play well with voting, and relies on voting to be
+ * disabled (that is, forks happen on the scheduled date, whether or not
+ * enough blocks have voted for the fork).
+ *
+ * returns true if no error, false otherwise
+ *
+ * @param block the new block
+ * @param height which height to check for
+ */
+ bool check_for_height(const cryptonote::block &block, uint64_t height) const;
+
+ /**
* @brief add a new block
*
* returns true if no error, false otherwise
@@ -211,6 +225,7 @@ namespace cryptonote
uint8_t get_block_version(uint64_t height) const;
bool do_check(uint8_t block_version, uint8_t voting_version) const;
+ bool do_check_for_height(uint8_t block_version, uint8_t voting_version, uint64_t height) const;
int get_voted_fork_index(uint64_t height) const;
uint8_t get_effective_version(uint8_t voting_version) const;
bool add(uint8_t block_version, uint8_t voting_version, uint64_t height);
diff --git a/src/cryptonote_core/miner.cpp b/src/cryptonote_core/miner.cpp
index 6f4e706ed..51f508858 100644
--- a/src/cryptonote_core/miner.cpp
+++ b/src/cryptonote_core/miner.cpp
@@ -43,6 +43,9 @@
#include "string_coding.h"
#include "storages/portable_storage_template_helper.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "miner"
+
using namespace epee;
#include "miner.h"
@@ -193,7 +196,7 @@ namespace cryptonote
m_config_folder_path = boost::filesystem::path(command_line::get_arg(vm, arg_extra_messages)).parent_path().string();
m_config = AUTO_VAL_INIT(m_config);
epee::serialization::load_t_from_json_file(m_config, m_config_folder_path + "/" + MINER_CONFIG_FILE_NAME);
- LOG_PRINT_L0("Loaded " << m_extra_messages.size() << " extra messages, current index " << m_config.current_extra_message_index);
+ MINFO("Loaded " << m_extra_messages.size() << " extra messages, current index " << m_config.current_extra_message_index);
}
if(command_line::has_arg(vm, arg_start_mining))
@@ -278,11 +281,11 @@ namespace cryptonote
//-----------------------------------------------------------------------------------------------------
bool miner::stop()
{
- LOG_PRINT_L1("Miner has received stop signal");
+ MTRACE("Miner has received stop signal");
if (!is_mining())
{
- LOG_PRINT_L1("Not mining - nothing to stop" );
+ MDEBUG("Not mining - nothing to stop" );
return true;
}
@@ -292,7 +295,7 @@ namespace cryptonote
BOOST_FOREACH(boost::thread& th, m_threads)
th.join();
- LOG_PRINT_L0("Mining has been stopped, " << m_threads.size() << " finished" );
+ MINFO("Mining has been stopped, " << m_threads.size() << " finished" );
m_threads.clear();
return true;
}
@@ -328,7 +331,7 @@ namespace cryptonote
CRITICAL_REGION_LOCAL(m_miners_count_lock);
++m_pausers_count;
if(m_pausers_count == 1 && is_mining())
- LOG_PRINT_L2("MINING PAUSED");
+ MDEBUG("MINING PAUSED");
}
//-----------------------------------------------------------------------------------------------------
void miner::resume()
@@ -338,17 +341,17 @@ namespace cryptonote
if(m_pausers_count < 0)
{
m_pausers_count = 0;
- LOG_PRINT_RED_L0("Unexpected miner::resume() called");
+ MERROR("Unexpected miner::resume() called");
}
if(!m_pausers_count && is_mining())
- LOG_PRINT_L2("MINING RESUMED");
+ MDEBUG("MINING RESUMED");
}
//-----------------------------------------------------------------------------------------------------
bool miner::worker_thread()
{
uint32_t th_local_index = boost::interprocess::ipcdetail::atomic_inc32(&m_thread_index);
- LOG_PRINT_L0("Miner thread was started ["<< th_local_index << "]");
- log_space::log_singletone::set_thread_log_prefix(std::string("[miner ") + std::to_string(th_local_index) + "]");
+ MGINFO("Miner thread was started ["<< th_local_index << "]");
+ MLOG_SET_THREAD_NAME(std::string("[miner ") + std::to_string(th_local_index) + "]");
uint32_t nonce = m_starter_nonce + th_local_index;
uint64_t height = 0;
difficulty_type local_diff = 0;
@@ -389,7 +392,7 @@ namespace cryptonote
{
//we lucky!
++m_config.current_extra_message_index;
- LOG_PRINT_GREEN("Found block for difficulty: " << local_diff, LOG_LEVEL_0);
+ MGINFO_GREEN("Found block for difficulty: " << local_diff);
if(!m_phandler->handle_block_found(b))
{
--m_config.current_extra_message_index;
@@ -404,7 +407,7 @@ namespace cryptonote
++m_hashes;
}
slow_hash_free_state();
- LOG_PRINT_L0("Miner thread stopped ["<< th_local_index << "]");
+ MGINFO("Miner thread stopped ["<< th_local_index << "]");
return true;
}
//-----------------------------------------------------------------------------------------------------
diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp
index 59ac534fe..6ad139023 100644
--- a/src/cryptonote_core/tx_pool.cpp
+++ b/src/cryptonote_core/tx_pool.cpp
@@ -45,6 +45,9 @@
#include "common/perf_timer.h"
#include "crypto/hash.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "txpool"
+
DISABLE_VS_WARNINGS(4244 4345 4503) //'boost::foreach_detail_::or_' : decorated name length exceeded, name was truncated
namespace cryptonote
@@ -83,7 +86,7 @@ namespace cryptonote
}
//---------------------------------------------------------------------------------
- bool tx_memory_pool::add_tx(const transaction &tx, /*const crypto::hash& tx_prefix_hash,*/ const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool kept_by_block, bool relayed, uint8_t version)
+ bool tx_memory_pool::add_tx(const transaction &tx, /*const crypto::hash& tx_prefix_hash,*/ const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool kept_by_block, bool relayed, bool do_not_relay, uint8_t version)
{
PERF_TIMER(add_tx);
if (tx.version == 0)
@@ -177,6 +180,8 @@ namespace cryptonote
return false;
}
+ time_t receive_time = time(nullptr);
+
crypto::hash max_used_block_id = null_hash;
uint64_t max_used_block_height = 0;
tx_details txd;
@@ -198,9 +203,10 @@ namespace cryptonote
txd_p.first->second.last_failed_height = 0;
txd_p.first->second.last_failed_id = null_hash;
txd_p.first->second.kept_by_block = kept_by_block;
- txd_p.first->second.receive_time = time(nullptr);
+ txd_p.first->second.receive_time = receive_time;
txd_p.first->second.last_relayed_time = time(NULL);
txd_p.first->second.relayed = relayed;
+ txd_p.first->second.do_not_relay = do_not_relay;
tvc.m_verifivation_impossible = true;
tvc.m_added_to_pool = true;
}else
@@ -221,12 +227,13 @@ namespace cryptonote
txd_p.first->second.max_used_block_height = max_used_block_height;
txd_p.first->second.last_failed_height = 0;
txd_p.first->second.last_failed_id = null_hash;
- txd_p.first->second.receive_time = time(nullptr);
+ txd_p.first->second.receive_time = receive_time;
txd_p.first->second.last_relayed_time = time(NULL);
txd_p.first->second.relayed = relayed;
+ txd_p.first->second.do_not_relay = do_not_relay;
tvc.m_added_to_pool = true;
- if(txd_p.first->second.fee > 0)
+ if(txd_p.first->second.fee > 0 && !do_not_relay)
tvc.m_should_be_relayed = true;
}
@@ -246,17 +253,17 @@ namespace cryptonote
tvc.m_verifivation_failed = false;
- m_txs_by_fee.emplace((double)blob_size / fee, id);
+ m_txs_by_fee_and_receive_time.emplace(std::pair<double, std::time_t>((double)blob_size / fee, receive_time), id);
return true;
}
//---------------------------------------------------------------------------------
- bool tx_memory_pool::add_tx(const transaction &tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed, uint8_t version)
+ bool tx_memory_pool::add_tx(const transaction &tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay, uint8_t version)
{
crypto::hash h = null_hash;
size_t blob_size = 0;
get_transaction_hash(tx, h, blob_size);
- return add_tx(tx, h, blob_size, tvc, keeped_by_block, relayed, version);
+ return add_tx(tx, h, blob_size, tvc, keeped_by_block, relayed, do_not_relay, version);
}
//---------------------------------------------------------------------------------
//FIXME: Can return early before removal of all of the key images.
@@ -292,7 +299,7 @@ namespace cryptonote
return true;
}
//---------------------------------------------------------------------------------
- bool tx_memory_pool::take_tx(const crypto::hash &id, transaction &tx, size_t& blob_size, uint64_t& fee, bool &relayed)
+ bool tx_memory_pool::take_tx(const crypto::hash &id, transaction &tx, size_t& blob_size, uint64_t& fee, bool &relayed, bool &do_not_relay)
{
CRITICAL_REGION_LOCAL(m_transactions_lock);
auto it = m_transactions.find(id);
@@ -301,16 +308,17 @@ namespace cryptonote
auto sorted_it = find_tx_in_sorted_container(id);
- if (sorted_it == m_txs_by_fee.end())
+ if (sorted_it == m_txs_by_fee_and_receive_time.end())
return false;
tx = it->second.tx;
blob_size = it->second.blob_size;
fee = it->second.fee;
relayed = it->second.relayed;
+ do_not_relay = it->second.do_not_relay;
remove_transaction_keyimages(it->second.tx);
m_transactions.erase(it);
- m_txs_by_fee.erase(sorted_it);
+ m_txs_by_fee_and_receive_time.erase(sorted_it);
return true;
}
//---------------------------------------------------------------------------------
@@ -321,7 +329,7 @@ namespace cryptonote
//---------------------------------------------------------------------------------
sorted_tx_container::iterator tx_memory_pool::find_tx_in_sorted_container(const crypto::hash& id) const
{
- return std::find_if( m_txs_by_fee.begin(), m_txs_by_fee.end()
+ return std::find_if( m_txs_by_fee_and_receive_time.begin(), m_txs_by_fee_and_receive_time.end()
, [&](const sorted_tx_container::value_type& a){
return a.second == id;
}
@@ -342,13 +350,13 @@ namespace cryptonote
LOG_PRINT_L1("Tx " << it->first << " removed from tx pool due to outdated, age: " << tx_age );
remove_transaction_keyimages(it->second.tx);
auto sorted_it = find_tx_in_sorted_container(it->first);
- if (sorted_it == m_txs_by_fee.end())
+ if (sorted_it == m_txs_by_fee_and_receive_time.end())
{
LOG_PRINT_L1("Removing tx " << it->first << " from tx pool, but it was not found in the sorted txs container!");
}
else
{
- m_txs_by_fee.erase(sorted_it);
+ m_txs_by_fee_and_receive_time.erase(sorted_it);
}
m_timed_out_transactions.insert(it->first);
auto pit = it++;
@@ -367,7 +375,7 @@ namespace cryptonote
for(auto it = m_transactions.begin(); it!= m_transactions.end();)
{
// 0 fee transactions are never relayed
- if(it->second.fee > 0 && now - it->second.last_relayed_time > get_relay_delay(now, it->second.receive_time))
+ if(it->second.fee > 0 && !it->second.do_not_relay && now - it->second.last_relayed_time > get_relay_delay(now, it->second.receive_time))
{
// if the tx is older than half the max lifetime, we don't re-relay it, to avoid a problem
// mentioned by smooth where nodes would flush txes at slightly different times, causing
@@ -431,6 +439,7 @@ namespace cryptonote
txi.receive_time = txd.receive_time;
txi.relayed = txd.relayed;
txi.last_relayed_time = txd.last_relayed_time;
+ txi.do_not_relay = txd.do_not_relay;
tx_infos.push_back(txi);
}
@@ -608,9 +617,9 @@ namespace cryptonote
size_t max_total_size = 2 * median_size - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE;
std::unordered_set<crypto::key_image> k_images;
- LOG_PRINT_L2("Filling block template, median size " << median_size << ", " << m_txs_by_fee.size() << " txes in the pool");
- auto sorted_it = m_txs_by_fee.begin();
- while (sorted_it != m_txs_by_fee.end())
+ LOG_PRINT_L2("Filling block template, median size " << median_size << ", " << m_txs_by_fee_and_receive_time.size() << " txes in the pool");
+ auto sorted_it = m_txs_by_fee_and_receive_time.begin();
+ while (sorted_it != m_txs_by_fee_and_receive_time.end())
{
auto tx_it = m_transactions.find(sorted_it->second);
LOG_PRINT_L2("Considering " << tx_it->first << ", size " << tx_it->second.blob_size << ", current block size " << total_size << "/" << max_total_size << ", current coinbase " << print_money(best_coinbase));
@@ -675,13 +684,13 @@ namespace cryptonote
LOG_PRINT_L1("Transaction " << get_transaction_hash(it->second.tx) << " is too big (" << it->second.blob_size << " bytes), removing it from pool");
remove_transaction_keyimages(it->second.tx);
auto sorted_it = find_tx_in_sorted_container(it->first);
- if (sorted_it == m_txs_by_fee.end())
+ if (sorted_it == m_txs_by_fee_and_receive_time.end())
{
LOG_PRINT_L1("Removing tx " << it->first << " from tx pool, but it was not found in the sorted txs container!");
}
else
{
- m_txs_by_fee.erase(sorted_it);
+ m_txs_by_fee_and_receive_time.erase(sorted_it);
}
auto pit = it++;
m_transactions.erase(pit);
@@ -712,14 +721,14 @@ namespace cryptonote
LOG_ERROR("Failed to load memory pool from file " << state_file_path);
m_transactions.clear();
- m_txs_by_fee.clear();
+ m_txs_by_fee_and_receive_time.clear();
m_spent_key_images.clear();
}
// no need to store queue of sorted transactions, as it's easy to generate.
for (const auto& tx : m_transactions)
{
- m_txs_by_fee.emplace((double)tx.second.blob_size / tx.second.fee, tx.first);
+ m_txs_by_fee_and_receive_time.emplace(std::pair<double, time_t>((double)tx.second.blob_size / tx.second.fee, tx.second.receive_time), tx.first);
}
// Ignore deserialization error
diff --git a/src/cryptonote_core/tx_pool.h b/src/cryptonote_core/tx_pool.h
index 32a05b0f4..2712f75bb 100644
--- a/src/cryptonote_core/tx_pool.h
+++ b/src/cryptonote_core/tx_pool.h
@@ -54,23 +54,25 @@ namespace cryptonote
/************************************************************************/
//! pair of <transaction fee, transaction hash> for organization
- typedef std::pair<double, crypto::hash> tx_by_fee_entry;
+ typedef std::pair<std::pair<double, std::time_t>, crypto::hash> tx_by_fee_and_receive_time_entry;
class txCompare
{
public:
- bool operator()(const tx_by_fee_entry& a, const tx_by_fee_entry& b)
+ bool operator()(const tx_by_fee_and_receive_time_entry& a, const tx_by_fee_and_receive_time_entry& b)
{
// sort by greatest first, not least
- if (a.first > b.first) return true;
- else if (a.first < b.first) return false;
+ if (a.first.first > b.first.first) return true;
+ else if (a.first.first < b.first.first) return false;
+ else if (a.first.second < b.first.second) return true;
+ else if (a.first.second > b.first.second) return false;
else if (a.second != b.second) return true;
else return false;
}
};
//! container for sorting transactions by fee per unit size
- typedef std::set<tx_by_fee_entry, txCompare> sorted_tx_container;
+ typedef std::set<tx_by_fee_and_receive_time_entry, txCompare> sorted_tx_container;
/**
* @brief Transaction pool, handles transactions which are not part of a block
@@ -103,7 +105,7 @@ namespace cryptonote
* @param id the transaction's hash
* @param blob_size the transaction's size
*/
- bool add_tx(const transaction &tx, const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool kept_by_block, bool relayed, uint8_t version);
+ bool add_tx(const transaction &tx, const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool kept_by_block, bool relayed, bool do_not_relay, uint8_t version);
/**
* @brief add a transaction to the transaction pool
@@ -117,11 +119,12 @@ namespace cryptonote
* @param tvc return-by-reference status about the transaction verification
* @param kept_by_block has this transaction been in a block?
* @param relayed was this transaction from the network or a local client?
+ * @param do_not_relay to avoid relaying the transaction to the network
* @param version the version used to create the transaction
*
* @return true if the transaction passes validations, otherwise false
*/
- bool add_tx(const transaction &tx, tx_verification_context& tvc, bool kept_by_block, bool relayed, uint8_t version);
+ bool add_tx(const transaction &tx, tx_verification_context& tvc, bool kept_by_block, bool relayed, bool do_not_relay, uint8_t version);
/**
* @brief takes a transaction with the given hash from the pool
@@ -131,10 +134,11 @@ namespace cryptonote
* @param blob_size return-by-reference the transaction's size
* @param fee the transaction fee
* @param relayed return-by-reference was transaction relayed to us by the network?
+ * @param do_not_relay return-by-reference is transaction not to be relayed to the network?
*
* @return true unless the transaction cannot be found in the pool
*/
- bool take_tx(const crypto::hash &id, transaction &tx, size_t& blob_size, uint64_t& fee, bool &relayed);
+ bool take_tx(const crypto::hash &id, transaction &tx, size_t& blob_size, uint64_t& fee, bool &relayed, bool &do_not_relay);
/**
* @brief checks if the pool has a transaction with the given hash
@@ -303,7 +307,7 @@ namespace cryptonote
#define CURRENT_MEMPOOL_ARCHIVE_VER 11
-#define CURRENT_MEMPOOL_TX_DETAILS_ARCHIVE_VER 11
+#define CURRENT_MEMPOOL_TX_DETAILS_ARCHIVE_VER 12
/**
* @brief serialize the transaction pool to/from disk
@@ -362,6 +366,7 @@ namespace cryptonote
time_t last_relayed_time; //!< the last time the transaction was relayed to the network
bool relayed; //!< whether or not the transaction has been relayed to the network
+ bool do_not_relay; //!< to avoid relay this transaction to the network
};
private:
@@ -473,7 +478,8 @@ private:
epee::math_helper::once_a_time_seconds<30> m_remove_stuck_tx_interval;
//TODO: look into doing this better
- sorted_tx_container m_txs_by_fee; //!< container for transactions organized by fee per size
+ //!< container for transactions organized by fee per size and receive time
+ sorted_tx_container m_txs_by_fee_and_receive_time;
/**
* @brief get an iterator to a transaction in the sorted container
@@ -515,6 +521,9 @@ namespace boost
if (version < 11)
return;
ar & td.kept_by_block;
+ if (version < 12)
+ return;
+ ar & td.do_not_relay;
}
}
}
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp b/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp
index 9d9ab3321..56b82ed15 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp
@@ -73,11 +73,11 @@
#include "../../src/cryptonote_protocol/cryptonote_protocol_handler.h"
#include "../../src/p2p/network_throttle.hpp"
-#include "../../contrib/otshell_utils/utils.hpp"
-using namespace nOT::nUtils;
-
#include "../../../src/cryptonote_core/cryptonote_core.h" // e.g. for the send_stop_signal()
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net.cn"
+
// ################################################################################################
// ################################################################################################
// the "header part". Not separated out for .hpp because point of this modification is
@@ -122,25 +122,24 @@ cryptonote_protocol_handler_base::~cryptonote_protocol_handler_base() {
void cryptonote_protocol_handler_base::handler_request_blocks_history(std::list<crypto::hash>& ids) {
using namespace epee::net_utils;
- LOG_PRINT_L1("### ~~~RRRR~~~~ ### sending request (type 2), limit = " << ids.size());
- LOG_PRINT_RED("RATE LIMIT NOT IMPLEMENTED HERE YET (download at unlimited speed?)" , LOG_LEVEL_1);
- _note_c("net/req2", "### ~~~RRRR~~~~ ### sending request (type 2), limit = " << ids.size());
+ MDEBUG("### ~~~RRRR~~~~ ### sending request (type 2), limit = " << ids.size());
+ MWARNING("RATE LIMIT NOT IMPLEMENTED HERE YET (download at unlimited speed?)");
// TODO
}
-void cryptonote_protocol_handler_base::handler_response_blocks_now(size_t packet_size) { _scope_dbg1("");
+void cryptonote_protocol_handler_base::handler_response_blocks_now(size_t packet_size) {
using namespace epee::net_utils;
double delay=0; // will be calculated
- _dbg1("Packet size: " << packet_size);
+ MDEBUG("Packet size: " << packet_size);
do
{ // rate limiting
//XXX
/*if (::cryptonote::core::get_is_stopping()) {
- _dbg1("We are stopping - so abort sleep");
+ MDEBUG("We are stopping - so abort sleep");
return;
}*/
/*if (m_was_shutdown) {
- _dbg2_c("net/netuse/sleep","m_was_shutdown - so abort sleep");
+ MDEBUG("m_was_shutdown - so abort sleep");
return;
}*/
@@ -155,9 +154,7 @@ void cryptonote_protocol_handler_base::handler_response_blocks_now(size_t packet
if (delay > 0) {
//delay += rand2*0.1;
long int ms = (long int)(delay * 1000);
- _info_c("net/sleep", "Sleeping in " << __FUNCTION__ << " for " << ms << " ms before packet_size="<<packet_size); // XXX debug sleep
- _dbg1_c("net/sleep/", "sleep in sleep_before_packet");
- _dbg2("Sleep for " << ms);
+ MDEBUG("Sleeping for " << ms << " ms before packet_size="<<packet_size); // XXX debug sleep
boost::this_thread::sleep(boost::posix_time::milliseconds( ms ) ); // TODO randomize sleeps
}
} while(delay > 0);
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.h b/src/cryptonote_protocol/cryptonote_protocol_handler.h
index 08dde4904..4b2de39b9 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.h
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.h
@@ -69,8 +69,6 @@ namespace cryptonote
virtual double get_avg_block_size() = 0;
virtual double estimate_one_block_size() noexcept; // for estimating size of blocks to download
-
- virtual std::ofstream& get_logreq() const =0;
};
template<class t_core>
@@ -138,7 +136,6 @@ namespace cryptonote
bool m_one_request = true;
std::atomic<bool> m_stopping;
- // static std::ofstream m_logreq;
boost::mutex m_buffer_mutex;
double get_avg_block_size();
boost::circular_buffer<size_t> m_avg_buffer = boost::circular_buffer<size_t>(10);
@@ -161,8 +158,6 @@ namespace cryptonote
epee::serialization::store_t_to_binary(arg, arg_buff);
return m_p2p->relay_notify_to_all(t_parameter::ID, arg_buff, exclude_context);
}
-
- virtual std::ofstream& get_logreq() const ;
};
} // namespace
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
index b13c1f437..58388f8f7 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
@@ -41,19 +41,15 @@
#include "cryptonote_core/cryptonote_format_utils.h"
#include "profile_tools.h"
-#include "../../contrib/otshell_utils/utils.hpp"
#include "../../src/p2p/network_throttle-detail.hpp"
-#include "../../src/p2p/data_logger.hpp"
-using namespace nOT::nUtils;
+
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net.cn"
namespace cryptonote
{
-// static
-// template<class t_core> std::ofstream t_cryptonote_protocol_handler<t_core>::m_logreq("logreq.txt"); // static
-
-
//-----------------------------------------------------------------------------------------------------------------------
template<class t_core>
@@ -284,10 +280,10 @@ namespace cryptonote
int64_t max_block_height = max(static_cast<int64_t>(hshd.current_height),static_cast<int64_t>(m_core.get_current_blockchain_height()));
int64_t last_block_v1 = 1009826;
int64_t diff_v2 = max_block_height > last_block_v1 ? min(abs(diff), max_block_height - last_block_v1) : 0;
- LOG_PRINT_CCONTEXT_YELLOW("Sync data returned a new top block candidate: " << m_core.get_current_blockchain_height() << " -> " << hshd.current_height
+ MCLOG(is_inital ? el::Level::Info : el::Level::Debug, "global", context << "Sync data returned a new top block candidate: " << m_core.get_current_blockchain_height() << " -> " << hshd.current_height
<< " [Your node is " << std::abs(diff) << " blocks (" << ((abs(diff) - diff_v2) / (24 * 60 * 60 / DIFFICULTY_TARGET_V1)) + (diff_v2 / (24 * 60 * 60 / DIFFICULTY_TARGET_V2)) << " days) "
<< (0 <= diff ? std::string("behind") : std::string("ahead"))
- << "] " << ENDL << "SYNCHRONIZATION started", (is_inital ? LOG_LEVEL_0:LOG_LEVEL_1));
+ << "] " << ENDL << "SYNCHRONIZATION started");
LOG_PRINT_L1("Remote blockchain height: " << hshd.current_height << ", id: " << hshd.top_id);
context.m_state = cryptonote_connection_context::state_synchronizing;
context.m_remote_blockchain_height = hshd.current_height;
@@ -328,7 +324,7 @@ namespace cryptonote
for(auto tx_blob_it = arg.b.txs.begin(); tx_blob_it!=arg.b.txs.end();tx_blob_it++)
{
cryptonote::tx_verification_context tvc = AUTO_VAL_INIT(tvc);
- m_core.handle_incoming_tx(*tx_blob_it, tvc, true, true);
+ m_core.handle_incoming_tx(*tx_blob_it, tvc, true, true, false);
if(tvc.m_verifivation_failed)
{
LOG_PRINT_CCONTEXT_L1("Block verification failed: transaction verification failed, dropping connection");
@@ -478,7 +474,7 @@ namespace cryptonote
if(!m_core.get_pool_transaction(tx_hash, tx))
{
cryptonote::tx_verification_context tvc = AUTO_VAL_INIT(tvc);
- if(!m_core.handle_incoming_tx(tx_blob, tvc, true, true) || tvc.m_verifivation_failed)
+ if(!m_core.handle_incoming_tx(tx_blob, tvc, true, true, false) || tvc.m_verifivation_failed)
{
LOG_PRINT_CCONTEXT_L1("Block verification failed: transaction verification failed, dropping connection");
m_p2p->drop_connection(context);
@@ -515,12 +511,12 @@ namespace cryptonote
// ones we received.
if(context.m_requested_objects.size())
{
- LOG_PRINT_CCONTEXT_RED
+ MERROR
(
"NOTIFY_NEW_FLUFFY_BLOCK: peer sent the number of transaction requested"
<< ", but not the actual transactions requested"
<< ", context.m_requested_objects.size() = " << context.m_requested_objects.size()
- << ", dropping connection", LOG_LEVEL_0
+ << ", dropping connection"
);
m_p2p->drop_connection(context);
@@ -682,7 +678,7 @@ namespace cryptonote
for(auto tx_blob_it = arg.txs.begin(); tx_blob_it!=arg.txs.end();)
{
cryptonote::tx_verification_context tvc = AUTO_VAL_INIT(tvc);
- m_core.handle_incoming_tx(*tx_blob_it, tvc, false, true);
+ m_core.handle_incoming_tx(*tx_blob_it, tvc, false, true, false);
if(tvc.m_verifivation_failed)
{
LOG_PRINT_CCONTEXT_L1("Tx verification failed, dropping connection");
@@ -842,8 +838,8 @@ namespace cryptonote
if(context.m_requested_objects.size())
{
- LOG_PRINT_CCONTEXT_RED("returned not all requested objects (context.m_requested_objects.size()="
- << context.m_requested_objects.size() << "), dropping connection", LOG_LEVEL_0);
+ MERROR("returned not all requested objects (context.m_requested_objects.size()="
+ << context.m_requested_objects.size() << "), dropping connection");
m_p2p->drop_connection(context);
return 1;
}
@@ -854,7 +850,7 @@ namespace cryptonote
epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler(
boost::bind(&t_core::resume_mine, &m_core));
- LOG_PRINT_CCONTEXT_YELLOW( "Got NEW BLOCKS inside of " << __FUNCTION__ << ": size: " << arg.blocks.size() , LOG_LEVEL_1);
+ MLOG_YELLOW(el::Level::Debug, "Got NEW BLOCKS inside of " << __FUNCTION__ << ": size: " << arg.blocks.size());
if (m_core.get_test_drop_download() && m_core.get_test_drop_download_height()) { // DISCARD BLOCKS for testing
@@ -874,7 +870,7 @@ namespace cryptonote
BOOST_FOREACH(auto& tx_blob, block_entry.txs)
{
tx_verification_context tvc = AUTO_VAL_INIT(tvc);
- m_core.handle_incoming_tx(tx_blob, tvc, true, true);
+ m_core.handle_incoming_tx(tx_blob, tvc, true, true, false);
if(tvc.m_verifivation_failed)
{
LOG_ERROR_CCONTEXT("transaction verification failed on NOTIFY_RESPONSE_GET_OBJECTS, \r\ntx_id = "
@@ -913,15 +909,12 @@ namespace cryptonote
TIME_MEASURE_FINISH(block_process_time);
LOG_PRINT_CCONTEXT_L2("Block process time: " << block_process_time + transactions_process_time << "(" << transactions_process_time << "/" << block_process_time << ")ms");
- epee::net_utils::data_logger::get_instance().add_data("calc_time", block_process_time + transactions_process_time);
- epee::net_utils::data_logger::get_instance().add_data("block_processing", 1);
-
} // each download block
m_core.cleanup_handle_incoming_blocks();
if (m_core.get_current_blockchain_height() > previous_height)
{
- LOG_PRINT_CCONTEXT_YELLOW( "Synced " << m_core.get_current_blockchain_height() << "/" << m_core.get_target_blockchain_height() , LOG_LEVEL_0);
+ MGINFO_YELLOW(context << " Synced " << m_core.get_current_blockchain_height() << "/" << m_core.get_target_blockchain_height());
}
} // if not DISCARD BLOCK
@@ -973,7 +966,7 @@ namespace cryptonote
auto it = context.m_needed_objects.begin();
const size_t count_limit = m_core.get_block_sync_size();
- _note_c("net/req-calc" , "Setting count_limit: " << count_limit);
+ MDEBUG("Setting count_limit: " << count_limit);
while(it != context.m_needed_objects.end() && count < count_limit)
{
if( !(check_having_blocks && m_core.have_block(*it)))
@@ -1015,7 +1008,7 @@ namespace cryptonote
<< "\r\non connection [" << epee::net_utils::print_connection_context_short(context)<< "]");
context.m_state = cryptonote_connection_context::state_normal;
- LOG_PRINT_CCONTEXT_GREEN(" SYNCHRONIZED OK", LOG_LEVEL_0);
+ MGINFO_GREEN("SYNCHRONIZED OK");
on_connection_synchronized();
}
return true;
@@ -1027,7 +1020,7 @@ namespace cryptonote
bool val_expected = false;
if(m_synchronized.compare_exchange_strong(val_expected, true))
{
- LOG_PRINT_L0(ENDL << "**********************************************************************" << ENDL
+ MGINFO_GREEN(ENDL << "**********************************************************************" << ENDL
<< "You are now synchronized with the network. You may now start monero-wallet-cli." << ENDL
<< ENDL
<< "Please note, that the blockchain will be saved only after you quit the daemon with \"exit\" command or if you use \"save\" command." << ENDL
@@ -1118,12 +1111,12 @@ namespace cryptonote
{
if(m_core.get_testnet() && (support_flags & P2P_SUPPORT_FLAG_FLUFFY_BLOCKS))
{
- LOG_PRINT_CCONTEXT_YELLOW("PEER SUPPORTS FLUFFY BLOCKS - RELAYING THIN/COMPACT WHATEVER BLOCK", LOG_LEVEL_1);
+ MDEBUG("PEER SUPPORTS FLUFFY BLOCKS - RELAYING THIN/COMPACT WHATEVER BLOCK");
fluffyConnections.push_back(context.m_connection_id);
}
else
{
- LOG_PRINT_CCONTEXT_YELLOW("PEER DOESN'T SUPPORT FLUFFY BLOCKS - RELAYING FULL BLOCK", LOG_LEVEL_1);
+ MDEBUG("PEER DOESN'T SUPPORT FLUFFY BLOCKS - RELAYING FULL BLOCK");
fullConnections.push_back(context.m_connection_id);
}
}
@@ -1146,18 +1139,6 @@ namespace cryptonote
return relay_post_notify<NOTIFY_NEW_TRANSACTIONS>(arg, exclude_context);
}
- /// @deprecated
- template<class t_core> std::ofstream& t_cryptonote_protocol_handler<t_core>::get_logreq() const {
- static std::ofstream * logreq=NULL;
- if (!logreq) {
- LOG_PRINT_RED("LOG OPENED",LOG_LEVEL_0);
- logreq = new std::ofstream("logreq.txt"); // leak mem (singleton)
- *logreq << "Opened log" << std::endl;
- }
- LOG_PRINT_YELLOW("LOG USED",LOG_LEVEL_0);
- (*logreq) << "log used" << std::endl;
- return *logreq;
- }
//------------------------------------------------------------------------------------------------------------------------
template<class t_core>
void t_cryptonote_protocol_handler<t_core>::stop()
diff --git a/src/daemon/CMakeLists.txt b/src/daemon/CMakeLists.txt
index 0f4baf932..1b6363f7b 100644
--- a/src/daemon/CMakeLists.txt
+++ b/src/daemon/CMakeLists.txt
@@ -89,7 +89,6 @@ target_link_libraries(daemon
cryptonote_core
crypto
common
- otshell_utils
p2p
cryptonote_protocol
daemonizer
diff --git a/src/daemon/command_line_args.h b/src/daemon/command_line_args.h
index 1fe2ddcf6..cb9fb6014 100644
--- a/src/daemon/command_line_args.h
+++ b/src/daemon/command_line_args.h
@@ -46,10 +46,10 @@ namespace daemon_args
, "Specify log file"
, ""
};
- const command_line::arg_descriptor<int> arg_log_level = {
+ const command_line::arg_descriptor<std::string> arg_log_level = {
"log-level"
, ""
- , LOG_LEVEL_0
+ , ""
};
const command_line::arg_descriptor<std::vector<std::string>> arg_command = {
"daemon_command"
diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp
index 7381dd06f..27f9d0fd7 100644
--- a/src/daemon/command_parser_executor.cpp
+++ b/src/daemon/command_parser_executor.cpp
@@ -29,6 +29,9 @@
#include "common/dns_utils.h"
#include "daemon/command_parser_executor.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "daemon"
+
namespace daemonize {
t_command_parser_executor::t_command_parser_executor(
@@ -117,24 +120,24 @@ bool t_command_parser_executor::set_log_level(const std::vector<std::string>& ar
{
if(args.size() != 1)
{
- std::cout << "use: set_log <log_level_number_0-4>" << std::endl;
+ std::cout << "use: set_log [<log_level_number_0-4> | <categories>]" << std::endl;
return true;
}
uint16_t l = 0;
- if(!epee::string_tools::get_xtype_from_string(l, args[0]))
+ if(epee::string_tools::get_xtype_from_string(l, args[0]))
{
- std::cout << "wrong number format, use: set_log <log_level_number_0-4>" << std::endl;
- return true;
+ if(4 < l)
+ {
+ std::cout << "wrong number range, use: set_log <log_level_number_0-4>" << std::endl;
+ return true;
+ }
+ return m_executor.set_log_level(l);
}
-
- if(LOG_LEVEL_4 < l)
+ else
{
- std::cout << "wrong number range, use: set_log <log_level_number_0-4>" << std::endl;
- return true;
+ return m_executor.set_log_categories(args.front());
}
-
- return m_executor.set_log_level(l);
}
bool t_command_parser_executor::print_height(const std::vector<std::string>& args)
@@ -511,4 +514,22 @@ bool t_command_parser_executor::alt_chain_info(const std::vector<std::string>& a
return m_executor.alt_chain_info();
}
+bool t_command_parser_executor::print_blockchain_dynamic_stats(const std::vector<std::string>& args)
+{
+ if(args.size() != 1)
+ {
+ std::cout << "Exactly one parameter is needed" << std::endl;
+ return false;
+ }
+
+ uint64_t nblocks = 0;
+ if(!epee::string_tools::get_xtype_from_string(nblocks, args[0]) || nblocks == 0)
+ {
+ std::cout << "wrong number of blocks" << std::endl;
+ return false;
+ }
+
+ return m_executor.print_blockchain_dynamic_stats(nblocks);
+}
+
} // namespace daemonize
diff --git a/src/daemon/command_parser_executor.h b/src/daemon/command_parser_executor.h
index cc929db00..15293ade9 100644
--- a/src/daemon/command_parser_executor.h
+++ b/src/daemon/command_parser_executor.h
@@ -72,6 +72,8 @@ public:
bool set_log_level(const std::vector<std::string>& args);
+ bool set_log_categories(const std::vector<std::string>& args);
+
bool print_height(const std::vector<std::string>& args);
bool print_block(const std::vector<std::string>& args);
@@ -121,6 +123,8 @@ public:
bool print_coinbase_tx_sum(const std::vector<std::string>& args);
bool alt_chain_info(const std::vector<std::string>& args);
+
+ bool print_blockchain_dynamic_stats(const std::vector<std::string>& args);
};
} // namespace daemonize
diff --git a/src/daemon/command_server.cpp b/src/daemon/command_server.cpp
index 88c49d111..95fd3178c 100644
--- a/src/daemon/command_server.cpp
+++ b/src/daemon/command_server.cpp
@@ -30,6 +30,9 @@
#include "version.h"
#include "daemon/command_server.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "daemon"
+
namespace daemonize {
namespace p = std::placeholders;
@@ -133,7 +136,7 @@ t_command_server::t_command_server(
m_command_lookup.set_handler(
"set_log"
, std::bind(&t_command_parser_executor::set_log_level, &m_parser, p::_1)
- , "set_log <level> - Change current log detalization level, <level> is a number 0-4"
+ , "set_log <level>|<categories> - Change current loglevel, <level> is a number 0-4"
);
m_command_lookup.set_handler(
"diff"
@@ -230,6 +233,11 @@ t_command_server::t_command_server(
, std::bind(&t_command_parser_executor::alt_chain_info, &m_parser, p::_1)
, "Print information about alternative chains"
);
+ m_command_lookup.set_handler(
+ "bc_dyn_stats"
+ , std::bind(&t_command_parser_executor::print_blockchain_dynamic_stats, &m_parser, p::_1)
+ , "Print information about current blockchain dynamic state"
+ );
}
bool t_command_server::process_command_str(const std::string& cmd)
diff --git a/src/daemon/core.h b/src/daemon/core.h
index 2b7f0d177..23f7a9f63 100644
--- a/src/daemon/core.h
+++ b/src/daemon/core.h
@@ -33,6 +33,9 @@
#include "misc_log_ex.h"
#include "daemon/command_line_args.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "daemon"
+
namespace daemonize
{
@@ -68,12 +71,12 @@ public:
bool run()
{
//initialize core here
- LOG_PRINT_L0("Initializing core...");
+ MGINFO("Initializing core...");
if (!m_core.init(m_vm_HACK))
{
return false;
}
- LOG_PRINT_L0("Core initialized OK");
+ MGINFO("Core initialized OK");
return true;
}
@@ -84,12 +87,12 @@ public:
~t_core()
{
- LOG_PRINT_L0("Deinitializing core...");
+ MGINFO("Deinitializing core...");
try {
m_core.deinit();
m_core.set_cryptonote_protocol(nullptr);
} catch (...) {
- LOG_PRINT_L0("Failed to deinitialize core...");
+ MERROR("Failed to deinitialize core...");
}
}
};
diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp
index 74875bfb0..287c30cb4 100644
--- a/src/daemon/daemon.cpp
+++ b/src/daemon/daemon.cpp
@@ -46,6 +46,9 @@ using namespace epee;
#include <functional>
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "daemon"
+
namespace daemonize {
struct t_internals {
@@ -136,17 +139,17 @@ bool t_daemon::run(bool interactive)
}
mp_internals->rpc.stop();
- LOG_PRINT("Node stopped.", LOG_LEVEL_0);
+ MGINFO("Node stopped.");
return true;
}
catch (std::exception const & ex)
{
- LOG_ERROR("Uncaught exception! " << ex.what());
+ MFATAL("Uncaught exception! " << ex.what());
return false;
}
catch (...)
{
- LOG_ERROR("Uncaught exception!");
+ MFATAL("Uncaught exception!");
return false;
}
}
diff --git a/src/daemon/daemon.h b/src/daemon/daemon.h
index 561cb4d9d..c8fae5c28 100644
--- a/src/daemon/daemon.h
+++ b/src/daemon/daemon.h
@@ -29,9 +29,12 @@
#pragma once
#include <boost/program_options.hpp>
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "daemon"
+
namespace daemonize {
-class t_internals;
+struct t_internals;
class t_daemon final {
public:
diff --git a/src/daemon/executor.cpp b/src/daemon/executor.cpp
index 9583fd056..ac5803cfb 100644
--- a/src/daemon/executor.cpp
+++ b/src/daemon/executor.cpp
@@ -26,16 +26,19 @@
// 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.
-#include "daemon/executor.h"
-
#include "misc_log_ex.h"
+#include "daemon/executor.h"
+
#include "common/command_line.h"
#include "cryptonote_config.h"
#include "version.h"
#include <string>
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "daemon"
+
namespace daemonize
{
std::string const t_executor::NAME = "Monero Daemon";
@@ -64,7 +67,6 @@ namespace daemonize
boost::program_options::variables_map const & vm
)
{
- epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL);
return t_daemon{vm}.run(true);
}
}
diff --git a/src/daemon/executor.h b/src/daemon/executor.h
index 37b4970f4..a6b47b93d 100644
--- a/src/daemon/executor.h
+++ b/src/daemon/executor.h
@@ -34,6 +34,9 @@
#include <string>
#include <vector>
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "daemon"
+
namespace daemonize
{
class t_executor final
diff --git a/src/daemon/main.cpp b/src/daemon/main.cpp
index 0895e1bf1..e08065ccd 100644
--- a/src/daemon/main.cpp
+++ b/src/daemon/main.cpp
@@ -47,6 +47,9 @@
#include "common/stack_trace.h"
#endif // STACK_TRACE
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "daemon"
+
namespace po = boost::program_options;
namespace bf = boost::filesystem;
@@ -54,7 +57,6 @@ int main(int argc, char const * argv[])
{
try {
- _note_c("dbg/main", "Begin of main()");
// TODO parse the debug options like set log level right here at start
tools::sanitize_locale();
@@ -79,7 +81,6 @@ int main(int argc, char const * argv[])
bf::path default_conf = default_data_dir / std::string(CRYPTONOTE_NAME ".conf");
command_line::add_arg(visible_options, daemon_args::arg_config_file, default_conf.string());
command_line::add_arg(visible_options, command_line::arg_test_dbg_lock_sleep);
- cryptonote::core::init_options(core_settings);
// Settings
bf::path default_log = default_data_dir / std::string(CRYPTONOTE_NAME ".log");
@@ -196,6 +197,23 @@ int main(int argc, char const * argv[])
}
po::notify(vm);
+ // 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")};
+ if (! vm["log-file"].defaulted())
+ log_file_path = command_line::get_arg(vm, daemon_args::arg_log_file);
+ log_file_path = bf::absolute(log_file_path, relative_path_base);
+ mlog_configure(log_file_path.string(), true);
+
+ // Set log level
+ if (!vm["log-level"].defaulted())
+ {
+ mlog_set_log(command_line::get_arg(vm, daemon_args::arg_log_level).c_str());
+ }
+
// If there are positional options, we're running a daemon command
{
auto command = command_line::get_arg(vm, daemon_args::arg_command);
@@ -236,55 +254,17 @@ int main(int argc, char const * argv[])
}
}
- // Start with log level 0
- epee::log_space::get_set_log_detalisation_level(true, LOG_LEVEL_0);
-
- // Set log level
- {
- int new_log_level = command_line::get_arg(vm, daemon_args::arg_log_level);
- if(new_log_level < LOG_LEVEL_MIN || new_log_level > LOG_LEVEL_MAX)
- {
- LOG_PRINT_L0("Wrong log level value: " << new_log_level);
- }
- else if (epee::log_space::get_set_log_detalisation_level(false) != new_log_level)
- {
- epee::log_space::get_set_log_detalisation_level(true, new_log_level);
- int otshell_utils_log_level = 100 - (new_log_level * 20);
- gCurrentLogger.setDebugLevel(otshell_utils_log_level);
- LOG_PRINT_L0("LOG_LEVEL set to " << new_log_level);
- }
- }
-
- // log_file_path
- // default: <data_dir>/<CRYPTONOTE_NAME>.log
- // if log-file argument given:
- // absolute path
- // relative path: relative to data_dir
-
- // Set log file
- {
- bf::path log_file_path {data_dir / std::string(CRYPTONOTE_NAME ".log")};
- if (! vm["log-file"].defaulted())
- log_file_path = command_line::get_arg(vm, daemon_args::arg_log_file);
- log_file_path = bf::absolute(log_file_path, relative_path_base);
-
- epee::log_space::log_singletone::add_logger(
- LOGGER_FILE
- , log_file_path.filename().string().c_str()
- , log_file_path.parent_path().string().c_str()
- );
#ifdef STACK_TRACE
- tools::set_stack_trace_log(log_file_path.filename().string());
+ tools::set_stack_trace_log(log_file_path.filename().string());
#endif // STACK_TRACE
- }
if (command_line::has_arg(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
- LOG_PRINT_L0("Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")");
+ MGINFO("Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")");
- _note_c("dbg/main", "Moving from main() into the daemonize now.");
+ MINFO("Moving from main() into the daemonize now.");
return daemonizer::daemonize(argc, argv, daemonize::t_executor{}, vm);
}
diff --git a/src/daemon/p2p.h b/src/daemon/p2p.h
index 3858989ce..f29c2d822 100644
--- a/src/daemon/p2p.h
+++ b/src/daemon/p2p.h
@@ -34,6 +34,9 @@
#include "p2p/net_node.h"
#include "daemon/protocol.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "daemon"
+
namespace daemonize
{
@@ -57,12 +60,12 @@ public:
: m_server{protocol.get()}
{
//initialize objects
- LOG_PRINT_L0("Initializing p2p server...");
+ MGINFO("Initializing p2p server...");
if (!m_server.init(vm))
{
throw std::runtime_error("Failed to initialize p2p server.");
}
- LOG_PRINT_L0("P2p server initialized OK");
+ MGINFO("P2p server initialized OK");
}
t_node_server & get()
@@ -72,9 +75,9 @@ public:
void run()
{
- LOG_PRINT_L0("Starting p2p net loop...");
+ MGINFO("Starting p2p net loop...");
m_server.run();
- LOG_PRINT_L0("p2p net loop stopped");
+ MGINFO("p2p net loop stopped");
}
void stop()
@@ -84,11 +87,11 @@ public:
~t_p2p()
{
- LOG_PRINT_L0("Deinitializing p2p...");
+ MGINFO("Deinitializing p2p...");
try {
m_server.deinit();
} catch (...) {
- LOG_PRINT_L0("Failed to deinitialize p2p...");
+ MERROR("Failed to deinitialize p2p...");
}
}
};
diff --git a/src/daemon/protocol.h b/src/daemon/protocol.h
index eb894fb81..bc2333659 100644
--- a/src/daemon/protocol.h
+++ b/src/daemon/protocol.h
@@ -30,6 +30,9 @@
#pragma once
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "daemon"
+
namespace daemonize
{
@@ -47,12 +50,12 @@ public:
)
: m_protocol{core.get(), nullptr}
{
- LOG_PRINT_L0("Initializing cryptonote protocol...");
+ MGINFO("Initializing cryptonote protocol...");
if (!m_protocol.init(vm))
{
throw std::runtime_error("Failed to initialize cryptonote protocol.");
}
- LOG_PRINT_L0("Cryptonote protocol initialized OK");
+ MGINFO("Cryptonote protocol initialized OK");
}
t_protocol_raw & get()
@@ -69,11 +72,11 @@ public:
~t_protocol()
{
- LOG_PRINT_L0("Stopping cryptonote protocol...");
+ MGINFO("Stopping cryptonote protocol...");
try {
m_protocol.deinit();
m_protocol.set_p2p_endpoint(nullptr);
- LOG_PRINT_L0("Cryptonote protocol stopped successfully");
+ MGINFO("Cryptonote protocol stopped successfully");
} catch (...) {
LOG_ERROR("Failed to stop cryptonote protocol!");
}
diff --git a/src/daemon/rpc.h b/src/daemon/rpc.h
index bfd2afd84..8b0d5808d 100644
--- a/src/daemon/rpc.h
+++ b/src/daemon/rpc.h
@@ -32,6 +32,9 @@
#include "rpc/core_rpc_server.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "daemon"
+
namespace daemonize
{
@@ -52,27 +55,27 @@ public:
)
: m_server{core.get(), p2p.get()}
{
- LOG_PRINT_L0("Initializing core rpc server...");
+ MGINFO("Initializing core rpc server...");
if (!m_server.init(vm))
{
throw std::runtime_error("Failed to initialize core rpc server.");
}
- LOG_PRINT_GREEN("Core rpc server initialized OK on port: " << m_server.get_binded_port(), LOG_LEVEL_0);
+ MGINFO("Core rpc server initialized OK on port: " << m_server.get_binded_port());
}
void run()
{
- LOG_PRINT_L0("Starting core rpc server...");
+ MGINFO("Starting core rpc server...");
if (!m_server.run(2, false))
{
throw std::runtime_error("Failed to start core rpc server.");
}
- LOG_PRINT_L0("Core rpc server started ok");
+ MGINFO("Core rpc server started ok");
}
void stop()
{
- LOG_PRINT_L0("Stopping core rpc server...");
+ MGINFO("Stopping core rpc server...");
m_server.send_stop_signal();
m_server.timed_wait_server_stop(5000);
}
@@ -84,11 +87,11 @@ public:
~t_rpc()
{
- LOG_PRINT_L0("Deinitializing rpc server...");
+ MGINFO("Deinitializing rpc server...");
try {
m_server.deinit();
} catch (...) {
- LOG_PRINT_L0("Failed to deinitialize rpc server...");
+ MERROR("Failed to deinitialize rpc server...");
}
}
};
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp
index 447783d76..8558ebc17 100644
--- a/src/daemon/rpc_command_executor.cpp
+++ b/src/daemon/rpc_command_executor.cpp
@@ -38,6 +38,9 @@
#include <ctime>
#include <string>
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "daemon"
+
namespace daemonize {
namespace {
@@ -517,6 +520,34 @@ bool t_rpc_command_executor::set_log_level(int8_t level) {
return true;
}
+bool t_rpc_command_executor::set_log_categories(const std::string &categories) {
+ cryptonote::COMMAND_RPC_SET_LOG_CATEGORIES::request req;
+ cryptonote::COMMAND_RPC_SET_LOG_CATEGORIES::response res;
+ req.categories = categories;
+
+ std::string fail_message = "Unsuccessful";
+
+ if (m_is_rpc)
+ {
+ if (!m_rpc_client->rpc_request(req, res, "/set_log_categories", fail_message.c_str()))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (!m_rpc_server->on_set_log_categories(req, res) || res.status != CORE_RPC_STATUS_OK)
+ {
+ tools::fail_msg_writer() << fail_message.c_str();
+ return true;
+ }
+ }
+
+ tools::success_msg_writer() << "Log categories are now " << categories;
+
+ return true;
+}
+
bool t_rpc_command_executor::print_height() {
cryptonote::COMMAND_RPC_GET_HEIGHT::request req;
cryptonote::COMMAND_RPC_GET_HEIGHT::response res;
@@ -743,6 +774,7 @@ bool t_rpc_command_executor::print_transaction_pool_long() {
<< "fee: " << cryptonote::print_money(tx_info.fee) << std::endl
<< "receive_time: " << tx_info.receive_time << " (" << get_human_time_ago(tx_info.receive_time, now) << ")" << std::endl
<< "relayed: " << [&](const cryptonote::tx_info &tx_info)->std::string { if (!tx_info.relayed) return "no"; return boost::lexical_cast<std::string>(tx_info.last_relayed_time) + " (" + get_human_time_ago(tx_info.last_relayed_time, now) + ")"; } (tx_info) << std::endl
+ << "do_not_relay: " << (tx_info.do_not_relay ? 'T' : 'F') << std::endl
<< "kept_by_block: " << (tx_info.kept_by_block ? 'T' : 'F') << std::endl
<< "max_used_block_height: " << tx_info.max_used_block_height << std::endl
<< "max_used_block_id: " << tx_info.max_used_block_id_hash << std::endl
@@ -823,6 +855,7 @@ bool t_rpc_command_executor::print_transaction_pool_short() {
<< "fee: " << cryptonote::print_money(tx_info.fee) << std::endl
<< "receive_time: " << tx_info.receive_time << " (" << get_human_time_ago(tx_info.receive_time, now) << ")" << std::endl
<< "relayed: " << [&](const cryptonote::tx_info &tx_info)->std::string { if (!tx_info.relayed) return "no"; return boost::lexical_cast<std::string>(tx_info.last_relayed_time) + " (" + get_human_time_ago(tx_info.last_relayed_time, now) + ")"; } (tx_info) << std::endl
+ << "do_not_relay: " << (tx_info.do_not_relay ? 'T' : 'F') << std::endl
<< "kept_by_block: " << (tx_info.kept_by_block ? 'T' : 'F') << std::endl
<< "max_used_block_height: " << tx_info.max_used_block_height << std::endl
<< "max_used_block_id: " << tx_info.max_used_block_id_hash << std::endl
@@ -1406,5 +1439,108 @@ bool t_rpc_command_executor::alt_chain_info()
return true;
}
+bool t_rpc_command_executor::print_blockchain_dynamic_stats(uint64_t nblocks)
+{
+ cryptonote::COMMAND_RPC_GET_INFO::request ireq;
+ cryptonote::COMMAND_RPC_GET_INFO::response ires;
+ cryptonote::COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::request bhreq;
+ cryptonote::COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::response bhres;
+ cryptonote::COMMAND_RPC_GET_PER_KB_FEE_ESTIMATE::request fereq;
+ cryptonote::COMMAND_RPC_GET_PER_KB_FEE_ESTIMATE::response feres;
+ epee::json_rpc::error error_resp;
+
+ std::string fail_message = "Problem fetching info";
+
+ if (m_is_rpc)
+ {
+ if (!m_rpc_client->rpc_request(ireq, ires, "/getinfo", fail_message.c_str()))
+ {
+ return true;
+ }
+ if (!m_rpc_client->rpc_request(fereq, feres, "/get_fee_estimate", fail_message.c_str()))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (!m_rpc_server->on_get_info(ireq, ires) || ires.status != CORE_RPC_STATUS_OK)
+ {
+ tools::fail_msg_writer() << fail_message.c_str();
+ return true;
+ }
+ if (!m_rpc_server->on_get_per_kb_fee_estimate(fereq, feres, error_resp) || feres.status != CORE_RPC_STATUS_OK)
+ {
+ tools::fail_msg_writer() << fail_message.c_str();
+ return true;
+ }
+ }
+
+ tools::msg_writer() << "Height: " << ires.height << ", diff " << ires.difficulty << ", cum. diff " << ires.cumulative_difficulty
+ << ", target " << ires.target << " sec" << ", dyn fee " << cryptonote::print_money(feres.fee) << "/kB";
+
+ if (nblocks > 0)
+ {
+ if (nblocks > ires.height)
+ nblocks = ires.height;
+
+ bhreq.start_height = ires.height - nblocks;
+ bhreq.end_height = ires.height - 1;
+ if (m_is_rpc)
+ {
+ if (!m_rpc_client->rpc_request(bhreq, bhres, "/getblockheadersrange", fail_message.c_str()))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (!m_rpc_server->on_get_block_headers_range(bhreq, bhres, error_resp) || bhres.status != CORE_RPC_STATUS_OK)
+ {
+ tools::fail_msg_writer() << fail_message.c_str();
+ return true;
+ }
+ }
+
+ double avgdiff = 0;
+ double avgnumtxes = 0;
+ double avgreward = 0;
+ std::vector<uint64_t> sizes;
+ sizes.reserve(nblocks);
+ std::vector<unsigned> major_versions(256, 0), minor_versions(256, 0);
+ for (const auto &bhr: bhres.headers)
+ {
+ avgdiff += bhr.difficulty;
+ avgnumtxes += bhr.num_txes;
+ avgreward += bhr.reward;
+ sizes.push_back(bhr.block_size);
+ static_assert(sizeof(bhr.major_version) == 1, "major_version expected to be uint8_t");
+ static_assert(sizeof(bhr.minor_version) == 1, "major_version expected to be uint8_t");
+ major_versions[(unsigned)bhr.major_version]++;
+ minor_versions[(unsigned)bhr.minor_version]++;
+ }
+ avgdiff /= nblocks;
+ avgnumtxes /= nblocks;
+ avgreward /= nblocks;
+ uint64_t median_block_size = epee::misc_utils::median(sizes);
+ tools::msg_writer() << "Last " << nblocks << ": avg. diff " << (uint64_t)avgdiff << ", avg num txes " << avgnumtxes
+ << ", avg. reward " << cryptonote::print_money(avgreward) << ", median block size " << median_block_size;
+
+ unsigned int max_major = 256, max_minor = 256;
+ while (max_major > 0 && !major_versions[--max_major]);
+ while (max_minor > 0 && !minor_versions[--max_minor]);
+ std::string s = "";
+ for (unsigned n = 0; n <= max_major; ++n)
+ if (major_versions[n])
+ s += (s.empty() ? "" : ", ") + boost::lexical_cast<std::string>(major_versions[n]) + std::string(" v") + boost::lexical_cast<std::string>(n);
+ tools::msg_writer() << "Block versions: " << s;
+ s = "";
+ for (unsigned n = 0; n <= max_minor; ++n)
+ if (minor_versions[n])
+ s += (s.empty() ? "" : ", ") + boost::lexical_cast<std::string>(minor_versions[n]) + std::string(" v") + boost::lexical_cast<std::string>(n);
+ tools::msg_writer() << "Voting for: " << s;
+ }
+ return true;
+}
}// namespace daemonize
diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h
index a6c712c04..afcd99d32 100644
--- a/src/daemon/rpc_command_executor.h
+++ b/src/daemon/rpc_command_executor.h
@@ -45,6 +45,9 @@
#include "p2p/net_node.h"
#include "rpc/core_rpc_server.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "daemon"
+
namespace daemonize {
class t_rpc_command_executor final {
@@ -82,6 +85,8 @@ public:
bool set_log_level(int8_t level);
+ bool set_log_categories(const std::string &categories);
+
bool print_height();
bool print_block_by_hash(crypto::hash block_hash);
@@ -139,6 +144,8 @@ public:
bool print_coinbase_tx_sum(uint64_t height, uint64_t count);
bool alt_chain_info();
+
+ bool print_blockchain_dynamic_stats(uint64_t nblocks);
};
} // namespace daemonize
diff --git a/src/mnemonics/electrum-words.cpp b/src/mnemonics/electrum-words.cpp
index 33d36d2d0..f0e254ba4 100644
--- a/src/mnemonics/electrum-words.cpp
+++ b/src/mnemonics/electrum-words.cpp
@@ -64,12 +64,15 @@
namespace
{
+ uint32_t create_checksum_index(const std::vector<std::string> &word_list,
+ uint32_t unique_prefix_length);
+ bool checksum_test(std::vector<std::string> seed, uint32_t unique_prefix_length);
/*!
* \brief Finds the word list that contains the seed words and puts the indices
* where matches occured in matched_indices.
* \param seed List of words to match.
- * \param has_checksum If word list passed checksum test, we need to only do a prefix check.
+ * \param has_checksum The seed has a checksum word (maybe not checked).
* \param matched_indices The indices where the seed words were found are added to this.
* \param language Language instance pointer to write to after it is found.
* \return true if all the words were present in some language false if not.
@@ -88,6 +91,7 @@ namespace
Language::Singleton<Language::Russian>::instance(),
Language::Singleton<Language::OldEnglish>::instance()
});
+ Language::Base *fallback = NULL;
// Iterate through all the languages and find a match
for (std::vector<Language::Base*>::iterator it1 = language_instances.begin();
@@ -126,12 +130,33 @@ namespace
}
if (full_match)
{
+ // if we were using prefix only, and we have a checksum, check it now
+ // to avoid false positives due to prefix set being too common
+ if (has_checksum)
+ if (!checksum_test(seed, (*it1)->get_unique_prefix_length()))
+ {
+ fallback = *it1;
+ full_match = false;
+ }
+ }
+ if (full_match)
+ {
*language = *it1;
return true;
}
// Some didn't match. Clear the index array.
matched_indices.clear();
}
+
+ // if we get there, we've not found a good match, but we might have a fallback,
+ // if we detected a match which did not fit the checksum, which might be a badly
+ // typed/transcribed seed in the right language
+ if (fallback)
+ {
+ *language = fallback;
+ return true;
+ }
+
return false;
}
diff --git a/src/p2p/connection_basic.cpp b/src/p2p/connection_basic.cpp
index 981a02882..80915e9a3 100644
--- a/src/p2p/connection_basic.cpp
+++ b/src/p2p/connection_basic.cpp
@@ -77,14 +77,13 @@
#include <boost/asio/ip/unicast.hpp>
#include "../../contrib/epee/include/net/abstract_tcp_server2.h"
-#include "../../contrib/otshell_utils/utils.hpp"
-#include "data_logger.hpp"
-using namespace nOT::nUtils;
-
// TODO:
#include "../../src/p2p/network_throttle-detail.hpp"
#include "../../src/cryptonote_core/cryptonote_core.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net.p2p"
+
// ################################################################################################
// local (TU local) headers
// ################################################################################################
@@ -219,19 +218,6 @@ uint64_t connection_basic::get_rate_down_limit() {
}
void connection_basic::save_limit_to_file(int limit) {
- // saving limit to file
- if (!epee::net_utils::data_logger::m_save_graph)
- return;
-
- {
- CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_out );
- epee::net_utils::data_logger::get_instance().add_data("upload_limit", network_throttle_manager::get_global_throttle_out().get_target_speed() / 1024);
- }
-
- {
- CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_in );
- epee::net_utils::data_logger::get_instance().add_data("download_limit", network_throttle_manager::get_global_throttle_in().get_target_speed() / 1024);
- }
}
void connection_basic::set_tos_flag(int tos) {
@@ -259,9 +245,8 @@ void connection_basic::sleep_before_packet(size_t packet_size, int phase, int q
delay *= 0.50;
if (delay > 0) {
long int ms = (long int)(delay * 1000);
- _info_c("net/sleep", "Sleeping in " << __FUNCTION__ << " for " << ms << " ms before packet_size="<<packet_size); // debug sleep
+ MDEBUG("Sleeping in " << __FUNCTION__ << " for " << ms << " ms before packet_size="<<packet_size); // debug sleep
_dbg1("sleep in sleep_before_packet");
- epee::net_utils::data_logger::get_instance().add_data("sleep_up", ms);
boost::this_thread::sleep(boost::posix_time::milliseconds( ms ) );
}
} while(delay > 0);
@@ -280,25 +265,21 @@ void connection_basic::set_start_time() {
void connection_basic::do_send_handler_write(const void* ptr , size_t cb ) {
sleep_before_packet(cb,1,-1);
- _info_c("net/out/size", "handler_write (direct) - before ASIO write, for packet="<<cb<<" B (after sleep)");
+ MDEBUG("handler_write (direct) - before ASIO write, for packet="<<cb<<" B (after sleep)");
set_start_time();
}
void connection_basic::do_send_handler_write_from_queue( const boost::system::error_code& e, size_t cb, int q_len ) {
sleep_before_packet(cb,2,q_len);
- _info_c("net/out/size", "handler_write (after write, from queue="<<q_len<<") - before ASIO write, for packet="<<cb<<" B (after sleep)");
+ MDEBUG("handler_write (after write, from queue="<<q_len<<") - before ASIO write, for packet="<<cb<<" B (after sleep)");
set_start_time();
}
void connection_basic::logger_handle_net_read(size_t size) { // network data read
- size /= 1024;
- epee::net_utils::data_logger::get_instance().add_data("download", size);
}
void connection_basic::logger_handle_net_write(size_t size) {
- size /= 1024;
- epee::net_utils::data_logger::get_instance().add_data("upload", size);
}
double connection_basic::get_sleep_time(size_t cb) {
@@ -308,7 +289,6 @@ double connection_basic::get_sleep_time(size_t cb) {
}
void connection_basic::set_save_graph(bool save_graph) {
- epee::net_utils::data_logger::m_save_graph = save_graph;
}
diff --git a/src/p2p/data_logger.cpp b/src/p2p/data_logger.cpp
deleted file mode 100644
index fe54aef63..000000000
--- a/src/p2p/data_logger.cpp
+++ /dev/null
@@ -1,202 +0,0 @@
-// Copyright (c) 2014-2016, The Monero Project
-//
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without modification, are
-// permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this list of
-// conditions and the following disclaimer.
-//
-// 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.
-//
-// 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.
-//
-// 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.
-
-#include "data_logger.hpp"
-#include <stdexcept>
-
-#include <boost/chrono.hpp>
-#include <boost/filesystem.hpp>
-#include <boost/thread.hpp>
-#include <chrono>
-#include "../../contrib/otshell_utils/utils.hpp"
-
-namespace epee
-{
-namespace net_utils
-{
- data_logger &data_logger::get_instance() {
- boost::call_once(m_singleton,
- [] {
- _info_c("dbg/data","Creating singleton of data_logger");
- if (m_state != data_logger_state::state_before_init) { _erro_c("dbg/data","Internal error in singleton"); throw std::runtime_error("data_logger singleton"); }
- m_state = data_logger_state::state_during_init;
- m_obj.reset(new data_logger());
- m_state = data_logger_state::state_ready_to_use;
- }
- );
-
- if (m_state != data_logger_state::state_ready_to_use) {
- _erro ("trying to use not working data_logger");
- throw std::runtime_error("data_logger ctor state");
- }
-
- return * m_obj;
- }
-
- data_logger::data_logger() {
- _note_c("dbg/data","Starting data logger (for graphs data)");
- if (m_state != data_logger_state::state_during_init) { _erro_c("dbg/data","Singleton ctor state"); throw std::runtime_error("data_logger ctor state"); }
- boost::lock_guard<boost::mutex> lock(mMutex); // lock
-
- // prepare all the files for given data channels:
- mFilesMap["peers"] = data_logger::fileData("log/dr-monero/peers.data");
- mFilesMap["download"] = data_logger::fileData("log/dr-monero/net/in-all.data");
- mFilesMap["upload"] = data_logger::fileData("log/dr-monero/net/out-all.data");
- mFilesMap["request"] = data_logger::fileData("log/dr-monero/net/req-all.data");
- mFilesMap["sleep_down"] = data_logger::fileData("log/dr-monero/down_sleep_log.data");
- mFilesMap["sleep_up"] = data_logger::fileData("log/dr-monero/up_sleep_log.data");
- mFilesMap["calc_time"] = data_logger::fileData("log/dr-monero/get_objects_calc_time.data");
- mFilesMap["blockchain_processing_time"] = data_logger::fileData("log/dr-monero/blockchain_log.data");
- mFilesMap["block_processing"] = data_logger::fileData("log/dr-monero/block_proc.data");
-
- mFilesMap["peers_limit"] = data_logger::fileData("log/dr-monero/peers_limit.info");
- mFilesMap["download_limit"] = data_logger::fileData("log/dr-monero/limit_down.info");
- mFilesMap["upload_limit"] = data_logger::fileData("log/dr-monero/limit_up.info");
-
- mFilesMap["peers_limit"].mLimitFile = true;
- mFilesMap["download_limit"].mLimitFile = true;
- mFilesMap["upload_limit"].mLimitFile = true;
-
- // do NOT modify mFilesMap below this point, since there is no locking for this used (yet)
-
- _info_c("dbg/data","Creating thread for data logger"); // create timer thread
- m_thread_maybe_running=true;
- std::shared_ptr<boost::thread> logger_thread(new boost::thread([&]() {
- _info_c("dbg/data","Inside thread for data logger");
- while (m_state == data_logger_state::state_during_init) { // wait for creation to be done (in other thread, in singleton) before actually running
- boost::this_thread::sleep_for(boost::chrono::seconds(1));
- }
- _info_c("dbg/data","Inside thread for data logger - going into main loop");
- while (m_state == data_logger_state::state_ready_to_use) { // run as long as we are not closing the single object
- boost::this_thread::sleep_for(boost::chrono::seconds(1));
- saveToFile(); // save all the pending data
- }
- _info_c("dbg/data","Inside thread for data logger - done the main loop");
- m_thread_maybe_running=false;
- }));
- logger_thread->detach();
- _info_c("dbg/data","Data logger constructed");
- }
-
- data_logger::~data_logger() noexcept(false) {
- _note_c("dbg/data","Destructor of the data logger");
- {
- boost::lock_guard<boost::mutex> lock(mMutex);
- m_state = data_logger_state::state_dying;
- }
- _info_c("dbg/data","State was set to dying");
- while(m_thread_maybe_running) { // wait for the thread to exit
- boost::this_thread::sleep_for(boost::chrono::seconds(1));
- _info_c("dbg/data","Waiting for background thread to exit");
- }
- _info_c("dbg/data","Thread exited");
- }
-
- void data_logger::kill_instance() {
- m_state = data_logger_state::state_dying;
- m_obj.reset();
- }
-
- void data_logger::add_data(std::string filename, unsigned int data) {
- boost::lock_guard<boost::mutex> lock(mMutex);
- if (m_state != data_logger_state::state_ready_to_use) { _info_c("dbg/data","Data logger is not ready, returning."); return; }
-
- if (mFilesMap.find(filename) == mFilesMap.end()) { // no such file/counter
- _erro_c("dbg/data","Trying to use not opened data file filename="<<filename);
- _erro_c("dbg/data","Disabling saving of graphs due to error");
- m_save_graph=false; // <--- disabling saving graphs
- return;
- }
-
- if (mFilesMap[filename].mLimitFile) { // this holds a number (that is not additive) - e.g. the limit setting
- mFilesMap[filename].mDataToSave = data;
- } else {
- mFilesMap[filename].mDataToSave += data; // this holds a number that should be sum of all accumulated samples
- }
- }
-
- bool data_logger::is_dying() {
- if (m_state == data_logger_state::state_dying) {
- return true;
- }
- else {
- return false;
- }
- }
-
- void data_logger::saveToFile() {
- _dbg2_c("dbg/data","saving to files");
- boost::lock_guard<boost::mutex> lock(mMutex);
- if (m_state != data_logger_state::state_ready_to_use) { _info_c("dbg/data","Data logger is not ready, returning."); return; }
- nOT::nUtils::cFilesystemUtils::CreateDirTree("log/dr-monero/net/");
- for (auto &element : mFilesMap)
- {
- element.second.save();
- if (!element.second.mLimitFile) element.second.mDataToSave = 0;
- }
- }
-
- // the inner class:
-
- double data_logger::fileData::get_current_time() {
- #if defined(__APPLE__)
- auto point = std::chrono::system_clock::now();
- #else
- auto point = std::chrono::steady_clock::now();
- #endif
- auto time_from_epoh = point.time_since_epoch();
- auto ms = std::chrono::duration_cast< std::chrono::milliseconds >( time_from_epoh ).count();
- double ms_f = ms;
- return ms_f / 1000.;
- }
-
- data_logger::fileData::fileData(std::string pFile) {
- _dbg3_c("dbg/data","opening data file named pFile="<<pFile<<" for this="<<this);
- mFile = std::make_shared<std::ofstream> (pFile);
- _dbg1_c("dbg/data","opened data file named pFile="<<pFile<<" in mFile="<<mFile<<" for this="<<this);
- mPath = pFile;
- }
-
- void data_logger::fileData::save() {
- if (!data_logger::m_save_graph) return; // <--- disabled
- _dbg2_c("dbg/data","saving to the file now, mFile="<<mFile);
- mFile->open(mPath, std::ios::app);
- *mFile << static_cast<int>(get_current_time()) << " " << mDataToSave << std::endl;
- mFile->close();
- }
-
-
-data_logger_state data_logger::m_state(data_logger_state::state_before_init); ///< (static) state of the singleton object
-std::atomic<bool> data_logger::m_save_graph(false); // (static)
-std::atomic<bool> data_logger::m_thread_maybe_running(false); // (static)
-boost::once_flag data_logger::m_singleton; // (static)
-std::unique_ptr<data_logger> data_logger::m_obj; // (static)
-
-} // namespace
-} // namespace
-
diff --git a/src/p2p/data_logger.hpp b/src/p2p/data_logger.hpp
deleted file mode 100644
index 278d08bfc..000000000
--- a/src/p2p/data_logger.hpp
+++ /dev/null
@@ -1,105 +0,0 @@
-// Copyright (c) 2014-2016, The Monero Project
-//
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without modification, are
-// permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this list of
-// conditions and the following disclaimer.
-//
-// 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.
-//
-// 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.
-//
-// 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.
-
-#ifndef INCLUDED_p2p_data_logger_hpp
-#define INCLUDED_p2p_data_logger_hpp
-
-#include <string>
-#include <map>
-#include <fstream>
-#include <memory>
-#include <boost/thread/thread.hpp>
-#include <boost/thread/mutex.hpp>
-#include <boost/thread/once.hpp>
-#include <atomic>
-
-namespace epee
-{
-namespace net_utils
-{
-
-enum class data_logger_state { state_before_init, state_during_init, state_ready_to_use, state_dying };
-
-/***
-@note: use it ONLY via singleton! It will be spawned then, and will auto destruct on program exit.
-@note: do call ::kill_instance() before exiting main, at end of main. But before make sure no one else (e.g. no other threads) will try to use this/singleton
-@note: it is not allowed to use this class from code "runnig before or after main", e.g. from ctors of static objects, because of static-creation-order races
-@note: on creation (e.g. from singleton), it spawns a thread that saves all data in background
-*/
- class data_logger {
- public:
- static data_logger &get_instance(); ///< singleton
- static void kill_instance(); ///< call this before ending main to allow more gracefull shutdown of the main singleton and it's background thread
- ~data_logger() noexcept(false); ///< destr, will be called when singleton is killed when global m_obj dies. will kill theads etc
-
- private:
- data_logger(); ///< constructor is private, use only via singleton get_instance
-
- public:
- data_logger(const data_logger &ob) = delete; // use only one per program
- data_logger(data_logger &&ob) = delete;
- data_logger & operator=(const data_logger&) = delete;
- data_logger & operator=(data_logger&&) = delete;
-
- void add_data(std::string filename, unsigned int data); ///< use this to append data here. Use it only the singleton. It locks itself.
-
- static std::atomic<bool> m_save_graph; ///< global setting flag, should we save all the data or not (can disable logging graphs data)
- static bool is_dying();
-
- private:
- static boost::once_flag m_singleton; ///< to guarantee singleton creates the object exactly once
- static data_logger_state m_state; ///< state of the singleton object
- static std::atomic<bool> m_thread_maybe_running; ///< is the background thread (more or less) running, or is it fully finished
- static std::unique_ptr<data_logger> m_obj; ///< the singleton object. Only use it via get_instance(). Can be killed by kill_instance()
-
- /***
- * one graph/file with data
- */
- class fileData {
- public:
- fileData() = default;
- fileData(const fileData &ob) = delete;
- fileData(std::string pFile);
-
- std::shared_ptr<std::ofstream> mFile;
- long int mDataToSave = 0; ///< sum of the data (in current interval, will be counted from 0 on next interval)
- static double get_current_time();
- void save();
- std::string mPath;
- bool mLimitFile = false; ///< this holds a number (that is not additive) - e.g. the limit setting
- };
-
- std::map<std::string, fileData> mFilesMap;
- boost::mutex mMutex;
- void saveToFile(); ///< write data to the target files. do not use this directly
- };
-
-} // namespace
-} // namespace
-
-#endif
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index 452f6d1a6..60e51c222 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -48,7 +48,6 @@
#include "net/local_ip.h"
#include "crypto/crypto.h"
#include "storages/levin_abstract_invoke2.h"
-#include "data_logger.hpp"
// We have to look for miniupnpc headers in different places, dependent on if its compiled or external
#ifdef UPNP_STATIC
@@ -61,6 +60,9 @@
#include "upnperrors.h"
#endif
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net.p2p"
+
#define NET_MAKE_IP(b1,b2,b3,b4) ((LPARAM)(((DWORD)(b1)<<24)+((DWORD)(b2)<<16)+((DWORD)(b3)<<8)+((DWORD)(b4))))
@@ -203,7 +205,7 @@ namespace nodetool
if(time(nullptr) >= it->second)
{
m_blocked_ips.erase(it);
- LOG_PRINT_CYAN("IP " << epee::string_tools::get_ip_string_from_int32(addr) << " unblocked.", LOG_LEVEL_0);
+ MLOG_CYAN(el::Level::Info, "IP " << epee::string_tools::get_ip_string_from_int32(addr) << " unblocked.");
return true;
}
return false;
@@ -235,7 +237,7 @@ namespace nodetool
for (const auto &c: conns)
m_net_server.get_config_object().close(c);
- LOG_PRINT_CYAN("IP " << epee::string_tools::get_ip_string_from_int32(addr) << " blocked.", LOG_LEVEL_0);
+ MLOG_CYAN(el::Level::Info, "IP " << epee::string_tools::get_ip_string_from_int32(addr) << " blocked.");
return true;
}
//-----------------------------------------------------------------------------------
@@ -247,7 +249,7 @@ namespace nodetool
if (i == m_blocked_ips.end())
return false;
m_blocked_ips.erase(i);
- LOG_PRINT_CYAN("IP " << epee::string_tools::get_ip_string_from_int32(addr) << " unblocked.", LOG_LEVEL_0);
+ MLOG_CYAN(el::Level::Info, "IP " << epee::string_tools::get_ip_string_from_int32(addr) << " unblocked.");
return true;
}
//-----------------------------------------------------------------------------------
@@ -256,7 +258,7 @@ namespace nodetool
{
CRITICAL_REGION_LOCAL(m_ip_fails_score_lock);
uint64_t fails = ++m_ip_fails_score[address];
- LOG_PRINT_CYAN("IP " << epee::string_tools::get_ip_string_from_int32(address) << " fail score=" << fails, LOG_LEVEL_1);
+ MDEBUG("IP " << epee::string_tools::get_ip_string_from_int32(address) << " fail score=" << fails);
if(fails > P2P_IP_FAILS_BEFORE_BLOCK)
{
auto it = m_ip_fails_score.find(address);
@@ -376,11 +378,11 @@ namespace nodetool
na.ip = boost::asio::detail::socket_ops::host_to_network_long(endpoint.address().to_v4().to_ulong());
na.port = endpoint.port();
seed_nodes.push_back(na);
- LOG_PRINT_L4("Added seed node: " << endpoint.address().to_v4().to_string(ec) << ':' << na.port);
+ MINFO("Added seed node: " << endpoint.address().to_v4().to_string(ec) << ':' << na.port);
}
else
{
- LOG_PRINT_L2("IPv6 doesn't supported, skip '" << host << "' -> " << endpoint.address().to_v6().to_string(ec));
+ MDEBUG("IPv6 doesn't supported, skip '" << host << "' -> " << endpoint.address().to_v6().to_string(ec));
}
}
}
@@ -416,7 +418,7 @@ namespace nodetool
{
boost::thread* th = new boost::thread([=, &dns_results, &addr_str]
{
- LOG_PRINT_L4("dns_threads[" << result_index << "] created for: " << addr_str);
+ MDEBUG("dns_threads[" << result_index << "] created for: " << addr_str);
// TODO: care about dnssec avail/valid
bool avail, valid;
std::vector<std::string> addr_list;
@@ -424,7 +426,7 @@ namespace nodetool
try
{
addr_list = tools::DNSResolver::instance().get_ipv4(addr_str, avail, valid);
- LOG_PRINT_L4("dns_threads[" << result_index << "] DNS resolve done");
+ MDEBUG("dns_threads[" << result_index << "] DNS resolve done");
boost::this_thread::interruption_point();
}
catch(const boost::thread_interrupted&)
@@ -432,11 +434,11 @@ namespace nodetool
// thread interruption request
// even if we now have results, finish thread without setting
// result variables, which are now out of scope in main thread
- LOG_PRINT_L4("dns_threads[" << result_index << "] interrupted");
+ MWARNING("dns_threads[" << result_index << "] interrupted");
return;
}
- LOG_PRINT_L4("dns_threads[" << result_index << "] addr_str: " << addr_str << " number of results: " << addr_list.size());
+ MINFO("dns_threads[" << result_index << "] addr_str: " << addr_str << " number of results: " << addr_list.size());
dns_results[result_index] = addr_list;
});
@@ -444,14 +446,14 @@ namespace nodetool
++result_index;
}
- LOG_PRINT_L4("dns_threads created, now waiting for completion or timeout of " << CRYPTONOTE_DNS_TIMEOUT_MS << "ms");
+ MDEBUG("dns_threads created, now waiting for completion or timeout of " << CRYPTONOTE_DNS_TIMEOUT_MS << "ms");
boost::chrono::system_clock::time_point deadline = boost::chrono::system_clock::now() + boost::chrono::milliseconds(CRYPTONOTE_DNS_TIMEOUT_MS);
uint64_t i = 0;
for (boost::thread* th : dns_threads)
{
if (! th->try_join_until(deadline))
{
- LOG_PRINT_L4("dns_threads[" << i << "] timed out, sending interrupt");
+ MWARNING("dns_threads[" << i << "] timed out, sending interrupt");
th->interrupt();
}
++i;
@@ -460,7 +462,7 @@ namespace nodetool
i = 0;
for (const auto& result : dns_results)
{
- LOG_PRINT_L4("DNS lookup for " << m_seed_nodes_list[i] << ": " << result.size() << " results");
+ MDEBUG("DNS lookup for " << m_seed_nodes_list[i] << ": " << result.size() << " results");
// if no results for node, thread's lookup likely timed out
if (result.size())
{
@@ -472,7 +474,7 @@ namespace nodetool
if (!full_addrs.size())
{
- LOG_PRINT_L0("DNS seed node lookup either timed out or failed, falling back to defaults");
+ MINFO("DNS seed node lookup either timed out or failed, falling back to defaults");
full_addrs.insert("198.74.231.92:18080");
full_addrs.insert("161.67.132.39:18080");
full_addrs.insert("163.172.182.165:18080");
@@ -483,10 +485,10 @@ namespace nodetool
for (const auto& full_addr : full_addrs)
{
- LOG_PRINT_L2("Seed node: " << full_addr);
+ MDEBUG("Seed node: " << full_addr);
append_net_address(m_seed_nodes, full_addr);
}
- LOG_PRINT_L1("Number of seed nodes: " << m_seed_nodes.size());
+ MDEBUG("Number of seed nodes: " << m_seed_nodes.size());
bool res = handle_command_line(vm, testnet);
CHECK_AND_ASSERT_MES(res, false, "Failed to handle command line");
@@ -520,18 +522,18 @@ namespace nodetool
return res;
//try to bind
- LOG_PRINT_L0("Binding on " << m_bind_ip << ":" << m_port);
+ MINFO("Binding on " << m_bind_ip << ":" << m_port);
res = m_net_server.init_server(m_port, m_bind_ip);
CHECK_AND_ASSERT_MES(res, false, "Failed to bind server");
m_listenning_port = m_net_server.get_binded_port();
- LOG_PRINT_GREEN("Net service bound to " << m_bind_ip << ":" << m_listenning_port, LOG_LEVEL_0);
+ MLOG_GREEN(el::Level::Info, "Net service bound to " << m_bind_ip << ":" << m_listenning_port);
if(m_external_port)
- LOG_PRINT_L0("External port defined as " << m_external_port);
+ MDEBUG("External port defined as " << m_external_port);
// Add UPnP port mapping
if(m_no_igd == false) {
- LOG_PRINT_L0("Attempting to add IGD port mapping.");
+ MDEBUG("Attempting to add IGD port mapping.");
int result;
#if MINIUPNPC_API_VERSION > 13
// default according to miniupnpc.h
@@ -558,19 +560,19 @@ namespace nodetool
if (portMappingResult != 0) {
LOG_ERROR("UPNP_AddPortMapping failed, error: " << strupnperror(portMappingResult));
} else {
- LOG_PRINT_GREEN("Added IGD port mapping.", LOG_LEVEL_0);
+ MLOG_GREEN(el::Level::Info, "Added IGD port mapping.");
}
} else if (result == 2) {
- LOG_PRINT_L0("IGD was found but reported as not connected.");
+ MWARNING("IGD was found but reported as not connected.");
} else if (result == 3) {
- LOG_PRINT_L0("UPnP device was found but not recognized as IGD.");
+ MWARNING("UPnP device was found but not recognized as IGD.");
} else {
- LOG_ERROR("UPNP_GetValidIGD returned an unknown result code.");
+ MWARNING("UPNP_GetValidIGD returned an unknown result code.");
}
FreeUPNPUrls(&urls);
} else {
- LOG_PRINT_L0("No IGD was found.");
+ MINFO("No IGD was found.");
}
}
return res;
@@ -600,9 +602,6 @@ namespace nodetool
}); // lambda
m_current_number_of_out_peers = number_of_peers;
- if (epee::net_utils::data_logger::is_dying())
- break;
- epee::net_utils::data_logger::get_instance().add_data("peers", number_of_peers);
boost::this_thread::sleep_for(boost::chrono::seconds(1));
} // main loop of thread
@@ -619,13 +618,13 @@ namespace nodetool
attrs.set_stack_size(THREAD_STACK_SIZE);
//go to loop
- LOG_PRINT("Run net_service loop( " << thrds_count << " threads)...", LOG_LEVEL_0);
+ MINFO("Run net_service loop( " << thrds_count << " threads)...");
if(!m_net_server.run_server(thrds_count, true, attrs))
{
LOG_ERROR("Failed to run net tcp server!");
}
- LOG_PRINT("net_service loop stopped.", LOG_LEVEL_0);
+ MINFO("net_service loop stopped.");
return true;
}
@@ -652,7 +651,7 @@ namespace nodetool
TRY_ENTRY();
if (!tools::create_directories_if_necessary(m_config_folder))
{
- LOG_PRINT_L0("Failed to create data directory: " << m_config_folder);
+ MWARNING("Failed to create data directory: " << m_config_folder);
return false;
}
@@ -661,7 +660,7 @@ namespace nodetool
p2p_data.open( state_file_path , std::ios_base::binary | std::ios_base::out| std::ios::trunc);
if(p2p_data.fail())
{
- LOG_PRINT_L0("Failed to save config to file " << state_file_path);
+ MWARNING("Failed to save config to file " << state_file_path);
return false;
};
@@ -678,7 +677,7 @@ namespace nodetool
{
m_payload_handler.stop();
m_net_server.send_stop_signal();
- LOG_PRINT_L0("[node] Stop signal sent");
+ MDEBUG("[node] Stop signal sent");
return true;
}
//-----------------------------------------------------------------------------------
@@ -702,19 +701,19 @@ namespace nodetool
if(code < 0)
{
- LOG_PRINT_CC_RED(context, "COMMAND_HANDSHAKE invoke failed. (" << code << ", " << epee::levin::get_err_descr(code) << ")", LOG_LEVEL_1);
+ LOG_ERROR_CC(context, "COMMAND_HANDSHAKE invoke failed. (" << code << ", " << epee::levin::get_err_descr(code) << ")");
return;
}
if(rsp.node_data.network_id != m_network_id)
{
- LOG_ERROR_CCONTEXT("COMMAND_HANDSHAKE Failed, wrong network! (" << epee::string_tools::get_str_from_guid_a(rsp.node_data.network_id) << "), closing connection.");
+ LOG_ERROR_CC(context, "COMMAND_HANDSHAKE Failed, wrong network! (" << epee::string_tools::get_str_from_guid_a(rsp.node_data.network_id) << "), closing connection.");
return;
}
if(!handle_remote_peerlist(rsp.local_peerlist, rsp.node_data.local_time, context))
{
- LOG_ERROR_CCONTEXT("COMMAND_HANDSHAKE: failed to handle_remote_peerlist(...), closing connection.");
+ LOG_ERROR_CC(context, "COMMAND_HANDSHAKE: failed to handle_remote_peerlist(...), closing connection.");
add_ip_fail(context.m_remote_ip);
return;
}
@@ -723,7 +722,7 @@ namespace nodetool
{
if(!m_payload_handler.process_payload_sync_data(rsp.payload_data, context, true))
{
- LOG_ERROR_CCONTEXT("COMMAND_HANDSHAKE invoked, but process_payload_sync_data returned false, dropping connection.");
+ LOG_ERROR_CC(context, "COMMAND_HANDSHAKE invoked, but process_payload_sync_data returned false, dropping connection.");
hsh_result = false;
return;
}
@@ -733,14 +732,14 @@ namespace nodetool
if(rsp.node_data.peer_id == m_config.m_peer_id)
{
- LOG_PRINT_CCONTEXT_L2("Connection to self detected, dropping connection");
+ LOG_DEBUG_CC(context, "Connection to self detected, dropping connection");
hsh_result = false;
return;
}
- LOG_PRINT_CCONTEXT_L1(" COMMAND_HANDSHAKE INVOKED OK");
+ LOG_DEBUG_CC(context, " COMMAND_HANDSHAKE INVOKED OK");
}else
{
- LOG_PRINT_CCONTEXT_L1(" COMMAND_HANDSHAKE(AND CLOSE) INVOKED OK");
+ LOG_DEBUG_CC(context, " COMMAND_HANDSHAKE(AND CLOSE) INVOKED OK");
}
}, P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT);
@@ -751,7 +750,7 @@ namespace nodetool
if(!hsh_result)
{
- LOG_PRINT_CC_L1(context_, "COMMAND_HANDSHAKE Failed");
+ LOG_ERROR_CC(context_, "COMMAND_HANDSHAKE Failed");
m_net_server.get_config_object().close(context_.m_connection_id);
}
else
@@ -776,13 +775,13 @@ namespace nodetool
{
if(code < 0)
{
- LOG_PRINT_CC_RED(context, "COMMAND_TIMED_SYNC invoke failed. (" << code << ", " << epee::levin::get_err_descr(code) << ")", LOG_LEVEL_1);
+ LOG_ERROR_CC(context, "COMMAND_TIMED_SYNC invoke failed. (" << code << ", " << epee::levin::get_err_descr(code) << ")");
return;
}
if(!handle_remote_peerlist(rsp.local_peerlist, rsp.local_time, context))
{
- LOG_ERROR_CCONTEXT("COMMAND_TIMED_SYNC: failed to handle_remote_peerlist(...), closing connection.");
+ LOG_WARNING_CC(context, "COMMAND_TIMED_SYNC: failed to handle_remote_peerlist(...), closing connection.");
m_net_server.get_config_object().close(context.m_connection_id );
add_ip_fail(context.m_remote_ip);
}
@@ -793,7 +792,7 @@ namespace nodetool
if(!r)
{
- LOG_PRINT_CC_L2(context_, "COMMAND_TIMED_SYNC Failed");
+ LOG_ERROR_CC(context_, "COMMAND_TIMED_SYNC Failed");
return false;
}
return true;
@@ -808,7 +807,7 @@ namespace nodetool
size_t x = crypto::rand<size_t>()%(max_index+1);
size_t res = (x*x*x)/(max_index*max_index); //parabola \/
- LOG_PRINT_L3("Random connection index=" << res << "(x="<< x << ", max_index=" << max_index << ")");
+ MDEBUG("Random connection index=" << res << "(x="<< x << ", max_index=" << max_index << ")");
return res;
}
//-----------------------------------------------------------------------------------
@@ -853,9 +852,9 @@ namespace nodetool
#define LOG_PRINT_CC_PRIORITY_NODE(priority, con, msg) \
do { \
if (priority) {\
- LOG_PRINT_CC_L1(con, msg); \
+ LOG_INFO_CC(con, "[priority]" << msg); \
} else {\
- LOG_PRINT_CC_L1(con, msg); \
+ LOG_INFO_CC(con, msg); \
} \
} while(0)
@@ -872,7 +871,7 @@ namespace nodetool
m_current_number_of_out_peers --; // atomic variable, update time = 1s
return false;
}
- LOG_PRINT_L1("Connecting to " << epee::string_tools::get_ip_string_from_int32(na.ip) << ":"
+ MDEBUG("Connecting to " << epee::string_tools::get_ip_string_from_int32(na.ip) << ":"
<< epee::string_tools::num_to_string_fast(na.port) << "(white=" << white << ", last_seen: "
<< (last_seen_stamp ? epee::misc_utils::get_time_interval_string(time(NULL) - last_seen_stamp):"never")
<< ")...");
@@ -910,7 +909,7 @@ namespace nodetool
if(just_take_peerlist)
{
m_net_server.get_config_object().close(con.m_connection_id);
- LOG_PRINT_CC_GREEN(con, "CONNECTION HANDSHAKED OK AND CLOSED.", LOG_LEVEL_2);
+ LOG_DEBUG_CC(con, "CONNECTION HANDSHAKED OK AND CLOSED.");
return true;
}
@@ -923,7 +922,7 @@ namespace nodetool
m_peerlist.append_with_peer_white(pe_local);
//update last seen and push it to peerlist manager
- LOG_PRINT_CC_GREEN(con, "CONNECTION HANDSHAKED OK.", LOG_LEVEL_2);
+ LOG_DEBUG_CC(con, "CONNECTION HANDSHAKED OK.");
return true;
}
@@ -986,7 +985,7 @@ namespace nodetool
if(is_addr_recently_failed(pe.adr))
continue;
- LOG_PRINT_L2("Selected peer: " << pe.id << " " << epee::string_tools::get_ip_string_from_int32(pe.adr.ip)
+ MDEBUG("Selected peer: " << pe.id << " " << epee::string_tools::get_ip_string_from_int32(pe.adr.ip)
<< ":" << boost::lexical_cast<std::string>(pe.adr.port)
<< "[white=" << use_white_list
<< "] last_seen: " << (pe.last_seen ? epee::misc_utils::get_time_interval_string(time(NULL) - pe.last_seen) : "never"));
@@ -1021,7 +1020,7 @@ namespace nodetool
break;
if(++try_count > m_seed_nodes.size())
{
- LOG_PRINT_RED_L0("Failed to connect to any of seed peers, continuing without seeds");
+ MWARNING("Failed to connect to any of seed peers, continuing without seeds");
break;
}
if(++current_index >= m_seed_nodes.size())
@@ -1105,7 +1104,7 @@ namespace nodetool
template<class t_payload_net_handler>
bool node_server<t_payload_net_handler>::peer_sync_idle_maker()
{
- LOG_PRINT_L2("STARTED PEERLIST IDLE HANDSHAKE");
+ MDEBUG("STARTED PEERLIST IDLE HANDSHAKE");
typedef std::list<std::pair<epee::net_utils::connection_context_base, peerid_type> > local_connects_type;
local_connects_type cncts;
m_net_server.get_config_object().foreach_connection([&](const p2p_connection_context& cntxt)
@@ -1117,7 +1116,7 @@ namespace nodetool
std::for_each(cncts.begin(), cncts.end(), [&](const typename local_connects_type::value_type& vl){do_peer_timed_sync(vl.first, vl.second);});
- LOG_PRINT_L2("FINISHED PEERLIST IDLE HANDSHAKE");
+ MDEBUG("FINISHED PEERLIST IDLE HANDSHAKE");
return true;
}
//-----------------------------------------------------------------------------------
@@ -1133,7 +1132,7 @@ namespace nodetool
{
if(be.last_seen > local_time)
{
- LOG_PRINT_RED_L1("FOUND FUTURE peerlist for entry " << epee::string_tools::get_ip_string_from_int32(be.adr.ip) << ":" << be.adr.port << " last_seen: " << be.last_seen << ", local_time(on remote node):" << local_time);
+ MWARNING("FOUND FUTURE peerlist for entry " << epee::string_tools::get_ip_string_from_int32(be.adr.ip) << ":" << be.adr.port << " last_seen: " << be.last_seen << ", local_time(on remote node):" << local_time);
return false;
}
be.last_seen += delta;
@@ -1148,8 +1147,8 @@ namespace nodetool
std::list<peerlist_entry> peerlist_ = peerlist;
if(!fix_time_delta(peerlist_, local_time, delta))
return false;
- LOG_PRINT_CCONTEXT_L2("REMOTE PEERLIST: TIME_DELTA: " << delta << ", remote peerlist size=" << peerlist_.size());
- LOG_PRINT_CCONTEXT_L3("REMOTE PEERLIST: " << print_peerlist_to_string(peerlist_));
+ LOG_DEBUG_CC(context, "REMOTE PEERLIST: TIME_DELTA: " << delta << ", remote peerlist size=" << peerlist_.size());
+ LOG_DEBUG_CC(context, "REMOTE PEERLIST: " << print_peerlist_to_string(peerlist_));
return m_peerlist.merge_peerlist(peerlist_);
}
//-----------------------------------------------------------------------------------
@@ -1332,7 +1331,7 @@ namespace nodetool
{
if(ec)
{
- LOG_PRINT_CC_L2(ping_context, "back ping connect failed to " << ip << ":" << port);
+ LOG_WARNING_CC(ping_context, "back ping connect failed to " << ip << ":" << port);
return false;
}
COMMAND_PING::request req;
@@ -1351,13 +1350,13 @@ namespace nodetool
{
if(code <= 0)
{
- LOG_PRINT_CC_L2(ping_context, "Failed to invoke COMMAND_PING to " << ip << ":" << port << "(" << code << ", " << epee::levin::get_err_descr(code) << ")");
+ LOG_ERROR_CC(ping_context, "Failed to invoke COMMAND_PING to " << ip << ":" << port << "(" << code << ", " << epee::levin::get_err_descr(code) << ")");
return;
}
if(rsp.status != PING_OK_RESPONSE_STATUS_TEXT || pr != rsp.peer_id)
{
- LOG_PRINT_CC_L2(ping_context, "back ping invoke wrong response \"" << rsp.status << "\" from" << ip << ":" << port << ", hsh_peer_id=" << pr_ << ", rsp.peer_id=" << rsp.peer_id);
+ LOG_ERROR_CC(ping_context, "back ping invoke wrong response \"" << rsp.status << "\" from" << ip << ":" << port << ", hsh_peer_id=" << pr_ << ", rsp.peer_id=" << rsp.peer_id);
m_net_server.get_config_object().close(ping_context.m_connection_id);
return;
}
@@ -1367,7 +1366,7 @@ namespace nodetool
if(!inv_call_res)
{
- LOG_PRINT_CC_L2(ping_context, "back ping invoke failed to " << ip << ":" << port);
+ LOG_ERROR_CC(ping_context, "back ping invoke failed to " << ip << ":" << port);
m_net_server.get_config_object().close(ping_context.m_connection_id);
return false;
}
@@ -1375,7 +1374,7 @@ namespace nodetool
});
if(!r)
{
- LOG_ERROR("Failed to call connect_async, network error.");
+ LOG_ERROR_CC(context, "Failed to call connect_async, network error.");
}
return r;
}
@@ -1394,7 +1393,7 @@ namespace nodetool
{
if(code < 0)
{
- LOG_PRINT_CC_RED(context_, "COMMAND_REQUEST_SUPPORT_FLAGS invoke failed. (" << code << ", " << epee::levin::get_err_descr(code) << ")", LOG_LEVEL_1);
+ LOG_ERROR_CC(context_, "COMMAND_REQUEST_SUPPORT_FLAGS invoke failed. (" << code << ", " << epee::levin::get_err_descr(code) << ")");
return;
}
@@ -1411,7 +1410,7 @@ namespace nodetool
{
if(!m_payload_handler.process_payload_sync_data(arg.payload_data, context, false))
{
- LOG_ERROR_CCONTEXT("Failed to process_payload_sync_data(), dropping connection");
+ LOG_ERROR_CC(context, "Failed to process_payload_sync_data(), dropping connection");
drop_connection(context);
return 1;
}
@@ -1420,7 +1419,7 @@ namespace nodetool
rsp.local_time = time(NULL);
m_peerlist.get_peerlist_head(rsp.local_peerlist);
m_payload_handler.get_payload_sync_data(rsp.payload_data);
- LOG_PRINT_CCONTEXT_L2("COMMAND_TIMED_SYNC");
+ LOG_DEBUG_CC(context, "COMMAND_TIMED_SYNC");
return 1;
}
//-----------------------------------------------------------------------------------
@@ -1430,7 +1429,7 @@ namespace nodetool
if(arg.node_data.network_id != m_network_id)
{
- LOG_PRINT_CCONTEXT_L1("WRONG NETWORK AGENT CONNECTED! id=" << epee::string_tools::get_str_from_guid_a(arg.node_data.network_id));
+ LOG_INFO_CC(context, "WRONG NETWORK AGENT CONNECTED! id=" << epee::string_tools::get_str_from_guid_a(arg.node_data.network_id));
drop_connection(context);
add_ip_fail(context.m_remote_ip);
return 1;
@@ -1438,7 +1437,7 @@ namespace nodetool
if(!context.m_is_income)
{
- LOG_ERROR_CCONTEXT("COMMAND_HANDSHAKE came not from incoming connection");
+ LOG_ERROR_CC(context, "COMMAND_HANDSHAKE came not from incoming connection");
drop_connection(context);
add_ip_fail(context.m_remote_ip);
return 1;
@@ -1446,14 +1445,14 @@ namespace nodetool
if(context.peer_id)
{
- LOG_ERROR_CCONTEXT("COMMAND_HANDSHAKE came, but seems that connection already have associated peer_id (double COMMAND_HANDSHAKE?)");
+ LOG_ERROR_CC(context, "COMMAND_HANDSHAKE came, but seems that connection already have associated peer_id (double COMMAND_HANDSHAKE?)");
drop_connection(context);
return 1;
}
if(!m_payload_handler.process_payload_sync_data(arg.payload_data, context, true))
{
- LOG_ERROR_CCONTEXT("COMMAND_HANDSHAKE came, but process_payload_sync_data returned false, dropping connection.");
+ LOG_ERROR_CC(context, "COMMAND_HANDSHAKE came, but process_payload_sync_data returned false, dropping connection.");
drop_connection(context);
return 1;
}
@@ -1484,7 +1483,7 @@ namespace nodetool
pe.last_seen = static_cast<int64_t>(last_seen);
pe.id = peer_id_l;
this->m_peerlist.append_with_peer_white(pe);
- LOG_PRINT_CCONTEXT_L2("PING SUCCESS " << epee::string_tools::get_ip_string_from_int32(context.m_remote_ip) << ":" << port_l);
+ LOG_DEBUG_CC(context, "PING SUCCESS " << epee::string_tools::get_ip_string_from_int32(context.m_remote_ip) << ":" << port_l);
});
}
@@ -1497,14 +1496,14 @@ namespace nodetool
m_peerlist.get_peerlist_head(rsp.local_peerlist);
get_local_node_data(rsp.node_data);
m_payload_handler.get_payload_sync_data(rsp.payload_data);
- LOG_PRINT_CCONTEXT_GREEN("COMMAND_HANDSHAKE", LOG_LEVEL_1);
+ LOG_DEBUG_CC(context, "COMMAND_HANDSHAKE");
return 1;
}
//-----------------------------------------------------------------------------------
template<class t_payload_net_handler>
int node_server<t_payload_net_handler>::handle_ping(int command, COMMAND_PING::request& arg, COMMAND_PING::response& rsp, p2p_connection_context& context)
{
- LOG_PRINT_CCONTEXT_L2("COMMAND_PING");
+ LOG_DEBUG_CC(context, "COMMAND_PING");
rsp.status = PING_OK_RESPONSE_STATUS_TEXT;
rsp.peer_id = m_config.m_peer_id;
return 1;
@@ -1516,14 +1515,14 @@ namespace nodetool
std::list<peerlist_entry> pl_white;
std::list<peerlist_entry> pl_gray;
m_peerlist.get_peerlist_full(pl_gray, pl_white);
- LOG_PRINT_L0(ENDL << "Peerlist white:" << ENDL << print_peerlist_to_string(pl_white) << ENDL << "Peerlist gray:" << ENDL << print_peerlist_to_string(pl_gray) );
+ MINFO(ENDL << "Peerlist white:" << ENDL << print_peerlist_to_string(pl_white) << ENDL << "Peerlist gray:" << ENDL << print_peerlist_to_string(pl_gray) );
return true;
}
//-----------------------------------------------------------------------------------
template<class t_payload_net_handler>
bool node_server<t_payload_net_handler>::log_connections()
{
- LOG_PRINT_L0("Connections: \r\n" << print_connections_container() );
+ MINFO("Connections: \r\n" << print_connections_container() );
return true;
}
//-----------------------------------------------------------------------------------
@@ -1547,13 +1546,13 @@ namespace nodetool
template<class t_payload_net_handler>
void node_server<t_payload_net_handler>::on_connection_new(p2p_connection_context& context)
{
- LOG_PRINT_L2("["<< epee::net_utils::print_connection_context(context) << "] NEW CONNECTION");
+ MINFO("["<< epee::net_utils::print_connection_context(context) << "] NEW CONNECTION");
}
//-----------------------------------------------------------------------------------
template<class t_payload_net_handler>
void node_server<t_payload_net_handler>::on_connection_close(p2p_connection_context& context)
{
- LOG_PRINT_L2("["<< epee::net_utils::print_connection_context(context) << "] CLOSE CONNECTION");
+ MINFO("["<< epee::net_utils::print_connection_context(context) << "] CLOSE CONNECTION");
}
template<class t_payload_net_handler>
@@ -1603,10 +1602,8 @@ namespace nodetool
{
if(max == -1) {
m_config.m_net_config.connections_count = P2P_DEFAULT_CONNECTIONS_COUNT;
- epee::net_utils::data_logger::get_instance().add_data("peers_limit", m_config.m_net_config.connections_count);
return true;
}
- epee::net_utils::data_logger::get_instance().add_data("peers_limit", max);
m_config.m_net_config.connections_count = max;
return true;
}
@@ -1640,7 +1637,7 @@ namespace nodetool
limit *= 1024;
epee::net_utils::connection<epee::levin::async_protocol_handler<p2p_connection_context> >::set_rate_up_limit( limit );
- LOG_PRINT_L0("Set limit-up to " << limit/1024 << " kB/s");
+ MINFO("Set limit-up to " << limit/1024 << " kB/s");
return true;
}
@@ -1654,7 +1651,7 @@ namespace nodetool
}
limit *= 1024;
epee::net_utils::connection<epee::levin::async_protocol_handler<p2p_connection_context> >::set_rate_down_limit( limit );
- LOG_PRINT_L0("Set limit-down to " << limit/1024 << " kB/s");
+ MINFO("Set limit-down to " << limit/1024 << " kB/s");
return true;
}
@@ -1676,11 +1673,11 @@ namespace nodetool
}
if(!this->islimitup) {
epee::net_utils::connection<epee::levin::async_protocol_handler<p2p_connection_context> >::set_rate_up_limit(limit_up);
- LOG_PRINT_L0("Set limit-up to " << limit_up/1024 << " kB/s");
+ MINFO("Set limit-up to " << limit_up/1024 << " kB/s");
}
if(!this->islimitdown) {
epee::net_utils::connection<epee::levin::async_protocol_handler<p2p_connection_context> >::set_rate_down_limit(limit_down);
- LOG_PRINT_L0("Set limit-down to " << limit_down/1024 << " kB/s");
+ MINFO("Set limit-down to " << limit_down/1024 << " kB/s");
}
return true;
diff --git a/src/p2p/network_throttle-detail.cpp b/src/p2p/network_throttle-detail.cpp
index ed3c8e7b4..9efaaf95a 100644
--- a/src/p2p/network_throttle-detail.cpp
+++ b/src/p2p/network_throttle-detail.cpp
@@ -77,9 +77,8 @@
// TODO:
#include "../../src/p2p/network_throttle-detail.hpp"
-#include "../../contrib/otshell_utils/utils.hpp"
-#include "data_logger.hpp"
-using namespace nOT::nUtils;
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net.throttle"
// ################################################################################################
// ################################################################################################
@@ -89,8 +88,6 @@ using namespace nOT::nUtils;
// ################################################################################################
// ################################################################################################
-using namespace nOT::nUtils;
-
namespace epee
{
namespace net_utils
@@ -163,7 +160,7 @@ void network_throttle::set_name(const std::string &name)
void network_throttle::set_target_speed( network_speed_kbps target )
{
m_target_speed = target * 1024;
- _note_c("net/"+m_nameshort, "Setting LIMIT: " << target << " kbps");
+ MINFO("Setting LIMIT: " << target << " kbps");
set_real_target_speed(target);
}
@@ -220,7 +217,7 @@ void network_throttle::_handle_trafic_exact(size_t packet_size, size_t orginal_s
std::ostringstream oss; oss << "["; for (auto sample: m_history) oss << sample.m_size << " "; oss << "]" << std::ends;
std::string history_str = oss.str();
- _dbg2_c( "net/" + m_nameshort , "Throttle " << m_name << ": packet of ~"<<packet_size<<"b " << " (from "<<orginal_size<<" b)"
+ MDEBUG("Throttle " << m_name << ": packet of ~"<<packet_size<<"b " << " (from "<<orginal_size<<" b)"
<< " Speed AVG=" << std::setw(4) << ((long int)(cts .average/1024)) <<"[w="<<cts .window<<"]"
<< " " << std::setw(4) << ((long int)(cts2.average/1024)) <<"[w="<<cts2.window<<"]"
<<" / " << " Limit="<< ((long int)(m_target_speed/1024)) <<" KiB/sec "
@@ -241,8 +238,6 @@ network_time_seconds network_throttle::get_sleep_time_after_tick(size_t packet_s
}
void network_throttle::logger_handle_net(const std::string &filename, double time, size_t size) {
- if (! epee::net_utils::data_logger::m_save_graph)
- return;
boost::mutex mutex;
mutex.lock(); {
std::fstream file;
@@ -312,8 +307,7 @@ void network_throttle::calculate_times(size_t packet_size, calculate_times_struc
if (dbg) {
std::ostringstream oss; oss << "["; for (auto sample: m_history) oss << sample.m_size << " "; oss << "]" << std::ends;
std::string history_str = oss.str();
- _dbg1_c( "net/"+m_nameshort+"_c" ,
- (cts.delay > 0 ? "SLEEP" : "")
+ MDEBUG((cts.delay > 0 ? "SLEEP" : "")
<< "dbg " << m_name << ": "
<< "speed is A=" << std::setw(8) <<cts.average<<" vs "
<< "Max=" << std::setw(8) <<M<<" "
diff --git a/src/p2p/network_throttle-detail.hpp b/src/p2p/network_throttle-detail.hpp
index 5960fa91d..ef7227eb9 100644
--- a/src/p2p/network_throttle-detail.hpp
+++ b/src/p2p/network_throttle-detail.hpp
@@ -67,9 +67,6 @@ class network_throttle : public i_network_throttle {
network_time_seconds m_start_time; // when we were created
bool m_any_packet_yet; // did we yet got any packet to count
- double m_overheat; // last overheat
- double m_overheat_time; // time in seconds after epoch
-
std::string m_name; // my name for debug and logs
std::string m_nameshort; // my name for debug and logs (used in log file name)
diff --git a/src/ringct/rctOps.cpp b/src/ringct/rctOps.cpp
index 21f29ccf5..0e1715072 100644
--- a/src/ringct/rctOps.cpp
+++ b/src/ringct/rctOps.cpp
@@ -33,6 +33,9 @@
using namespace crypto;
using namespace std;
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "ringct"
+
namespace rct {
//Various key initialization functions
diff --git a/src/ringct/rctSigs.cpp b/src/ringct/rctSigs.cpp
index 4f8782cdf..74fed0ede 100644
--- a/src/ringct/rctSigs.cpp
+++ b/src/ringct/rctSigs.cpp
@@ -39,6 +39,9 @@
using namespace crypto;
using namespace std;
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "ringct"
+
namespace rct {
//Borromean (c.f. gmax/andytoshi's paper)
boroSig genBorromean(const key64 x, const key64 P1, const key64 P2, const bits indices) {
@@ -710,45 +713,56 @@ namespace rct {
//decodeRct: (c.f. http://eprint.iacr.org/2015/1098 section 5.1.1)
// uses the attached ecdh info to find the amounts represented by each output commitment
// must know the destination private key to find the correct amount, else will return a random number
- bool verRct(const rctSig & rv) {
+ bool verRct(const rctSig & rv, bool semantics) {
PERF_TIMER(verRct);
CHECK_AND_ASSERT_MES(rv.type == RCTTypeFull, false, "verRct called on non-full rctSig");
- CHECK_AND_ASSERT_MES(rv.outPk.size() == rv.p.rangeSigs.size(), false, "Mismatched sizes of outPk and rv.p.rangeSigs");
- CHECK_AND_ASSERT_MES(rv.outPk.size() == rv.ecdhInfo.size(), false, "Mismatched sizes of outPk and rv.ecdhInfo");
- CHECK_AND_ASSERT_MES(rv.p.MGs.size() == 1, false, "full rctSig has not one MG");
+ if (semantics)
+ {
+ CHECK_AND_ASSERT_MES(rv.outPk.size() == rv.p.rangeSigs.size(), false, "Mismatched sizes of outPk and rv.p.rangeSigs");
+ CHECK_AND_ASSERT_MES(rv.outPk.size() == rv.ecdhInfo.size(), false, "Mismatched sizes of outPk and rv.ecdhInfo");
+ CHECK_AND_ASSERT_MES(rv.p.MGs.size() == 1, false, "full rctSig has not one MG");
+ }
+ else
+ {
+ // semantics check is early, we don't have the MGs resolved yet
+ }
// some rct ops can throw
try
{
- std::deque<bool> results(rv.outPk.size(), false);
- tools::thread_group threadpool(tools::thread_group::optimal_with_max(rv.outPk.size()));
+ if (semantics) {
+ std::deque<bool> results(rv.outPk.size(), false);
+ tools::thread_group threadpool(tools::thread_group::optimal_with_max(rv.outPk.size()));
+
+ tools::task_region(threadpool, [&] (tools::task_region_handle& region) {
+ DP("range proofs verified?");
+ for (size_t i = 0; i < rv.outPk.size(); i++) {
+ region.run([&, i] {
+ results[i] = verRange(rv.outPk[i].mask, rv.p.rangeSigs[i]);
+ });
+ }
+ });
- tools::task_region(threadpool, [&] (tools::task_region_handle& region) {
- DP("range proofs verified?");
- for (size_t i = 0; i < rv.outPk.size(); i++) {
- region.run([&, i] {
- results[i] = verRange(rv.outPk[i].mask, rv.p.rangeSigs[i]);
- });
+ for (size_t i = 0; i < rv.outPk.size(); ++i) {
+ if (!results[i]) {
+ LOG_PRINT_L1("Range proof verified failed for output " << i);
+ return false;
+ }
}
- });
+ }
- for (size_t i = 0; i < rv.outPk.size(); ++i) {
- if (!results[i]) {
- LOG_PRINT_L1("Range proof verified failed for output " << i);
+ if (!semantics) {
+ //compute txn fee
+ key txnFeeKey = scalarmultH(d2h(rv.txnFee));
+ bool mgVerd = verRctMG(rv.p.MGs[0], rv.mixRing, rv.outPk, txnFeeKey, get_pre_mlsag_hash(rv));
+ DP("mg sig verified?");
+ DP(mgVerd);
+ if (!mgVerd) {
+ LOG_PRINT_L1("MG signature verification failed");
return false;
}
}
- //compute txn fee
- key txnFeeKey = scalarmultH(d2h(rv.txnFee));
- bool mgVerd = verRctMG(rv.p.MGs[0], rv.mixRing, rv.outPk, txnFeeKey, get_pre_mlsag_hash(rv));
- DP("mg sig verified?");
- DP(mgVerd);
- if (!mgVerd) {
- LOG_PRINT_L1("MG signature verification failed");
- return false;
- }
-
return true;
}
catch(...)
@@ -759,76 +773,86 @@ namespace rct {
//ver RingCT simple
//assumes only post-rct style inputs (at least for max anonymity)
- bool verRctSimple(const rctSig & rv) {
+ bool verRctSimple(const rctSig & rv, bool semantics) {
try
{
PERF_TIMER(verRctSimple);
CHECK_AND_ASSERT_MES(rv.type == RCTTypeSimple, false, "verRctSimple called on non simple rctSig");
- CHECK_AND_ASSERT_MES(rv.outPk.size() == rv.p.rangeSigs.size(), false, "Mismatched sizes of outPk and rv.p.rangeSigs");
- CHECK_AND_ASSERT_MES(rv.outPk.size() == rv.ecdhInfo.size(), false, "Mismatched sizes of outPk and rv.ecdhInfo");
- CHECK_AND_ASSERT_MES(rv.pseudoOuts.size() == rv.p.MGs.size(), false, "Mismatched sizes of rv.pseudoOuts and rv.p.MGs");
- CHECK_AND_ASSERT_MES(rv.pseudoOuts.size() == rv.mixRing.size(), false, "Mismatched sizes of rv.pseudoOuts and mixRing");
+ if (semantics)
+ {
+ CHECK_AND_ASSERT_MES(rv.outPk.size() == rv.p.rangeSigs.size(), false, "Mismatched sizes of outPk and rv.p.rangeSigs");
+ CHECK_AND_ASSERT_MES(rv.outPk.size() == rv.ecdhInfo.size(), false, "Mismatched sizes of outPk and rv.ecdhInfo");
+ CHECK_AND_ASSERT_MES(rv.pseudoOuts.size() == rv.p.MGs.size(), false, "Mismatched sizes of rv.pseudoOuts and rv.p.MGs");
+ }
+ else
+ {
+ // semantics check is early, and mixRing/MGs aren't resolved yet
+ CHECK_AND_ASSERT_MES(rv.pseudoOuts.size() == rv.mixRing.size(), false, "Mismatched sizes of rv.pseudoOuts and mixRing");
+ }
const size_t threads = std::max(rv.outPk.size(), rv.mixRing.size());
std::deque<bool> results(threads);
tools::thread_group threadpool(tools::thread_group::optimal_with_max(threads));
- results.clear();
- results.resize(rv.outPk.size());
- tools::task_region(threadpool, [&] (tools::task_region_handle& region) {
- for (size_t i = 0; i < rv.outPk.size(); i++) {
- region.run([&, i] {
- results[i] = verRange(rv.outPk[i].mask, rv.p.rangeSigs[i]);
- });
- }
- });
+ if (semantics) {
+ results.clear();
+ results.resize(rv.outPk.size());
+ tools::task_region(threadpool, [&] (tools::task_region_handle& region) {
+ for (size_t i = 0; i < rv.outPk.size(); i++) {
+ region.run([&, i] {
+ results[i] = verRange(rv.outPk[i].mask, rv.p.rangeSigs[i]);
+ });
+ }
+ });
- for (size_t i = 0; i < results.size(); ++i) {
- if (!results[i]) {
- LOG_PRINT_L1("Range proof verified failed for output " << i);
- return false;
+ for (size_t i = 0; i < results.size(); ++i) {
+ if (!results[i]) {
+ LOG_PRINT_L1("Range proof verified failed for output " << i);
+ return false;
+ }
}
- }
-
- key sumOutpks = identity();
- for (size_t i = 0; i < rv.outPk.size(); i++) {
- addKeys(sumOutpks, sumOutpks, rv.outPk[i].mask);
- }
- DP(sumOutpks);
- key txnFeeKey = scalarmultH(d2h(rv.txnFee));
- addKeys(sumOutpks, txnFeeKey, sumOutpks);
- key message = get_pre_mlsag_hash(rv);
+ key sumOutpks = identity();
+ for (size_t i = 0; i < rv.outPk.size(); i++) {
+ addKeys(sumOutpks, sumOutpks, rv.outPk[i].mask);
+ }
+ DP(sumOutpks);
+ key txnFeeKey = scalarmultH(d2h(rv.txnFee));
+ addKeys(sumOutpks, txnFeeKey, sumOutpks);
- results.clear();
- results.resize(rv.mixRing.size());
- tools::task_region(threadpool, [&] (tools::task_region_handle& region) {
- for (size_t i = 0 ; i < rv.mixRing.size() ; i++) {
- region.run([&, i] {
- results[i] = verRctMGSimple(message, rv.p.MGs[i], rv.mixRing[i], rv.pseudoOuts[i]);
- });
+ key sumPseudoOuts = identity();
+ for (size_t i = 0 ; i < rv.pseudoOuts.size() ; i++) {
+ addKeys(sumPseudoOuts, sumPseudoOuts, rv.pseudoOuts[i]);
}
- });
+ DP(sumPseudoOuts);
- for (size_t i = 0; i < results.size(); ++i) {
- if (!results[i]) {
- LOG_PRINT_L1("verRctMGSimple failed for input " << i);
- return false;
+ //check pseudoOuts vs Outs..
+ if (!equalKeys(sumPseudoOuts, sumOutpks)) {
+ LOG_PRINT_L1("Sum check failed");
+ return false;
}
}
+ else {
+ const key message = get_pre_mlsag_hash(rv);
- key sumPseudoOuts = identity();
- for (size_t i = 0 ; i < rv.mixRing.size() ; i++) {
- addKeys(sumPseudoOuts, sumPseudoOuts, rv.pseudoOuts[i]);
- }
- DP(sumPseudoOuts);
-
- //check pseudoOuts vs Outs..
- if (!equalKeys(sumPseudoOuts, sumOutpks)) {
- LOG_PRINT_L1("Sum check failed");
- return false;
+ results.clear();
+ results.resize(rv.mixRing.size());
+ tools::task_region(threadpool, [&] (tools::task_region_handle& region) {
+ for (size_t i = 0 ; i < rv.mixRing.size() ; i++) {
+ region.run([&, i] {
+ results[i] = verRctMGSimple(message, rv.p.MGs[i], rv.mixRing[i], rv.pseudoOuts[i]);
+ });
+ }
+ });
+
+ for (size_t i = 0; i < results.size(); ++i) {
+ if (!results[i]) {
+ LOG_PRINT_L1("verRctMGSimple failed for input " << i);
+ return false;
+ }
+ }
}
return true;
diff --git a/src/ringct/rctSigs.h b/src/ringct/rctSigs.h
index 1fe4aa074..ca40ddd85 100644
--- a/src/ringct/rctSigs.h
+++ b/src/ringct/rctSigs.h
@@ -126,8 +126,10 @@ namespace rct {
rctSig genRct(const key &message, const ctkeyV & inSk, const ctkeyV & inPk, const keyV & destinations, const vector<xmr_amount> & amounts, const keyV &amount_keys, const int mixin);
rctSig genRctSimple(const key & message, const ctkeyV & inSk, const ctkeyV & inPk, const keyV & destinations, const vector<xmr_amount> & inamounts, const vector<xmr_amount> & outamounts, const keyV &amount_keys, xmr_amount txnFee, unsigned int mixin);
rctSig genRctSimple(const key & message, const ctkeyV & inSk, const keyV & destinations, const vector<xmr_amount> & inamounts, const vector<xmr_amount> & outamounts, xmr_amount txnFee, const ctkeyM & mixRing, const keyV &amount_keys, const std::vector<unsigned int> & index, ctkeyV &outSk);
- bool verRct(const rctSig & rv);
- bool verRctSimple(const rctSig & rv);
+ bool verRct(const rctSig & rv, bool semantics);
+ static inline bool verRct(const rctSig & rv) { return verRct(rv, true) && verRct(rv, false); }
+ bool verRctSimple(const rctSig & rv, bool semantics);
+ static inline bool verRctSimple(const rctSig & rv) { return verRctSimple(rv, true) && verRctSimple(rv, false); }
xmr_amount decodeRct(const rctSig & rv, const key & sk, unsigned int i, key & mask);
xmr_amount decodeRct(const rctSig & rv, const key & sk, unsigned int i);
xmr_amount decodeRctSimple(const rctSig & rv, const key & sk, unsigned int i, key & mask);
diff --git a/src/ringct/rctTypes.cpp b/src/ringct/rctTypes.cpp
index e773c6043..1526dcf7c 100644
--- a/src/ringct/rctTypes.cpp
+++ b/src/ringct/rctTypes.cpp
@@ -32,6 +32,9 @@
using namespace crypto;
using namespace std;
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "ringct"
+
namespace rct {
//dp
diff --git a/src/ringct/rctTypes.h b/src/ringct/rctTypes.h
index 6b24fc470..b1aa243b9 100644
--- a/src/ringct/rctTypes.h
+++ b/src/ringct/rctTypes.h
@@ -328,70 +328,70 @@ namespace rct {
//H2 contains 2^i H in each index, i.e. H, 2H, 4H, 8H, ...
//This is used for the range proofG
//You can regenerate this by running python2 Test.py HPow2 in the MiniNero repo
- static const key64 H2 = {{0x8b, 0x65, 0x59, 0x70, 0x15, 0x37, 0x99, 0xaf, 0x2a, 0xea, 0xdc, 0x9f, 0xf1, 0xad, 0xd0, 0xea, 0x6c, 0x72, 0x51, 0xd5, 0x41, 0x54, 0xcf, 0xa9, 0x2c, 0x17, 0x3a, 0x0d, 0xd3, 0x9c, 0x1f, 0x94},
- {0x8f, 0xaa, 0x44, 0x8a, 0xe4, 0xb3, 0xe2, 0xbb, 0x3d, 0x4d, 0x13, 0x09, 0x09, 0xf5, 0x5f, 0xcd, 0x79, 0x71, 0x1c, 0x1c, 0x83, 0xcd, 0xbc, 0xca, 0xdd, 0x42, 0xcb, 0xe1, 0x51, 0x5e, 0x87, 0x12},
- {0x12, 0xa7, 0xd6, 0x2c, 0x77, 0x91, 0x65, 0x4a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0x4a, 0x6b, 0xb9, 0x7d, 0x22, 0xfe, 0xad, 0xbc, 0x6c, 0x0d, 0x89, 0x30, 0xc5, 0xf8, 0xfc, 0x50, 0x8b, 0x2f, 0xc5, 0xb3, 0x53, 0x28, 0xd2, 0x6b, 0x88, 0xdb, 0x19, 0xae},
- {0x60, 0xb6, 0x26, 0xa0, 0x33, 0xb5, 0x5f, 0x27, 0xd7, 0x67, 0x6c, 0x40, 0x95, 0xea, 0xba, 0xbc, 0x7a, 0x2c, 0x7e, 0xde, 0x26, 0x24, 0xb4, 0x72, 0xe9, 0x7f, 0x64, 0xf9, 0x6b, 0x8c, 0xfc, 0x0e},
- {0xe5, 0xb5, 0x2b, 0xc9, 0x27, 0x46, 0x8d, 0xf7, 0x18, 0x93, 0xeb, 0x81, 0x97, 0xef, 0x82, 0x0c, 0xf7, 0x6c, 0xb0, 0xaa, 0xf6, 0xe8, 0xe4, 0xfe, 0x93, 0xad, 0x62, 0xd8, 0x03, 0x98, 0x31, 0x04},
- {0x05, 0x65, 0x41, 0xae, 0x5d, 0xa9, 0x96, 0x1b, 0xe2, 0xb0, 0xa5, 0xe8, 0x95, 0xe5, 0xc5, 0xba, 0x15, 0x3c, 0xbb, 0x62, 0xdd, 0x56, 0x1a, 0x42, 0x7b, 0xad, 0x0f, 0xfd, 0x41, 0x92, 0x31, 0x99},
- {0xf8, 0xfe, 0xf0, 0x5a, 0x3f, 0xa5, 0xc9, 0xf3, 0xeb, 0xa4, 0x16, 0x38, 0xb2, 0x47, 0xb7, 0x11, 0xa9, 0x9f, 0x96, 0x0f, 0xe7, 0x3a, 0xa2, 0xf9, 0x01, 0x36, 0xae, 0xb2, 0x03, 0x29, 0xb8, 0x88}};
+ static const key64 H2 = {{{0x8b, 0x65, 0x59, 0x70, 0x15, 0x37, 0x99, 0xaf, 0x2a, 0xea, 0xdc, 0x9f, 0xf1, 0xad, 0xd0, 0xea, 0x6c, 0x72, 0x51, 0xd5, 0x41, 0x54, 0xcf, 0xa9, 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, 0xb0, 0xa5, 0xe8, 0x95, 0xe5, 0xc5, 0xba, 0x15, 0x3c, 0xbb, 0x62, 0xdd, 0x56, 0x1a, 0x42, 0x7b, 0xad, 0x0f, 0xfd, 0x41, 0x92, 0x31, 0x99}},
+ {{0xf8, 0xfe, 0xf0, 0x5a, 0x3f, 0xa5, 0xc9, 0xf3, 0xeb, 0xa4, 0x16, 0x38, 0xb2, 0x47, 0xb7, 0x11, 0xa9, 0x9f, 0x96, 0x0f, 0xe7, 0x3a, 0xa2, 0xf9, 0x01, 0x36, 0xae, 0xb2, 0x03, 0x29, 0xb8, 0x88}}};
//Debug printing for the above types
//Actually use DP(value) and #define DBG
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index ddf892cae..1c5c321da 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -190,6 +190,36 @@ namespace cryptonote
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
+ bool core_rpc_server::on_get_blocks_by_height(const COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::request& req, COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::response& res)
+ {
+ CHECK_CORE_BUSY();
+ res.status = "Failed";
+ res.blocks.clear();
+ res.blocks.reserve(req.heights.size());
+ for (uint64_t height : req.heights)
+ {
+ block blk;
+ try
+ {
+ blk = m_core.get_blockchain_storage().get_db().get_block_from_height(height);
+ }
+ catch (...)
+ {
+ res.status = "Error retrieving block at height " + height;
+ return true;
+ }
+ std::list<transaction> txs;
+ std::list<crypto::hash> missed_txs;
+ m_core.get_transactions(blk.tx_hashes, txs, missed_txs);
+ res.blocks.resize(res.blocks.size() + 1);
+ res.blocks.back().block = block_to_blob(blk);
+ for (auto& tx : txs)
+ res.blocks.back().txs.push_back(tx_to_blob(tx));
+ }
+ res.status = CORE_RPC_STATUS_OK;
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_hashes(const COMMAND_RPC_GET_HASHES_FAST::request& req, COMMAND_RPC_GET_HASHES_FAST::response& res)
{
CHECK_CORE_BUSY();
@@ -528,7 +558,7 @@ namespace cryptonote
cryptonote_connection_context fake_context = AUTO_VAL_INIT(fake_context);
tx_verification_context tvc = AUTO_VAL_INIT(tvc);
- if(!m_core.handle_incoming_tx(tx_blob, tvc, false, false) || tvc.m_verifivation_failed)
+ if(!m_core.handle_incoming_tx(tx_blob, tvc, false, false, req.do_not_relay) || tvc.m_verifivation_failed)
{
if (tvc.m_verifivation_failed)
{
@@ -558,7 +588,7 @@ namespace cryptonote
return true;
}
- if(!tvc.m_should_be_relayed || req.do_not_relay)
+ if(!tvc.m_should_be_relayed)
{
LOG_PRINT_L0("[on_send_raw_tx]: tx accepted, but not relayed");
res.reason = "Not relayed";
@@ -678,17 +708,20 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_set_log_level(const COMMAND_RPC_SET_LOG_LEVEL::request& req, COMMAND_RPC_SET_LOG_LEVEL::response& res)
{
- if (req.level < LOG_LEVEL_MIN || req.level > LOG_LEVEL_MAX)
+ if (req.level < 0 || req.level > 4)
{
res.status = "Error: log level not valid";
+ return true;
}
- else
- {
- epee::log_space::log_singletone::get_set_log_detalisation_level(true, req.level);
- int otshell_utils_log_level = 100 - (req.level * 20);
- gCurrentLogger.setDebugLevel(otshell_utils_log_level);
- res.status = CORE_RPC_STATUS_OK;
- }
+ mlog_set_log_level(req.level);
+ res.status = CORE_RPC_STATUS_OK;
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
+ bool core_rpc_server::on_set_log_categories(const COMMAND_RPC_SET_LOG_CATEGORIES::request& req, COMMAND_RPC_SET_LOG_CATEGORIES::response& res)
+ {
+ mlog_set_categories(req.categories.c_str());
+ res.status = CORE_RPC_STATUS_OK;
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
@@ -896,6 +929,7 @@ namespace cryptonote
response.difficulty = m_core.get_blockchain_storage().block_difficulty(height);
response.reward = get_block_reward(blk);
response.block_size = m_core.get_blockchain_storage().get_db().get_block_size(height);
+ response.num_txes = blk.tx_hashes.size();
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h
index 0c0668f3b..84871e8bb 100644
--- a/src/rpc/core_rpc_server.h
+++ b/src/rpc/core_rpc_server.h
@@ -76,6 +76,7 @@ namespace cryptonote
BEGIN_URI_MAP2()
MAP_URI_AUTO_JON2("/getheight", on_get_height, COMMAND_RPC_GET_HEIGHT)
MAP_URI_AUTO_BIN2("/getblocks.bin", on_get_blocks, COMMAND_RPC_GET_BLOCKS_FAST)
+ MAP_URI_AUTO_BIN2("/getblocks_by_height.bin", on_get_blocks_by_height, COMMAND_RPC_GET_BLOCKS_BY_HEIGHT)
MAP_URI_AUTO_BIN2("/gethashes.bin", on_get_hashes, COMMAND_RPC_GET_HASHES_FAST)
MAP_URI_AUTO_BIN2("/get_o_indexes.bin", on_get_indexes, COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES)
MAP_URI_AUTO_BIN2("/getrandom_outs.bin", on_get_random_outs, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS)
@@ -91,6 +92,7 @@ namespace cryptonote
MAP_URI_AUTO_JON2_IF("/get_peer_list", on_get_peer_list, COMMAND_RPC_GET_PEER_LIST, !m_restricted)
MAP_URI_AUTO_JON2_IF("/set_log_hash_rate", on_set_log_hash_rate, COMMAND_RPC_SET_LOG_HASH_RATE, !m_restricted)
MAP_URI_AUTO_JON2_IF("/set_log_level", on_set_log_level, COMMAND_RPC_SET_LOG_LEVEL, !m_restricted)
+ MAP_URI_AUTO_JON2_IF("/set_log_categories", on_set_log_categories, COMMAND_RPC_SET_LOG_CATEGORIES, !m_restricted)
MAP_URI_AUTO_JON2("/get_transaction_pool", on_get_transaction_pool, COMMAND_RPC_GET_TRANSACTION_POOL)
MAP_URI_AUTO_JON2_IF("/stop_daemon", on_stop_daemon, COMMAND_RPC_STOP_DAEMON, !m_restricted)
MAP_URI_AUTO_JON2("/getinfo", on_get_info, COMMAND_RPC_GET_INFO)
@@ -124,6 +126,7 @@ namespace cryptonote
bool on_get_height(const COMMAND_RPC_GET_HEIGHT::request& req, COMMAND_RPC_GET_HEIGHT::response& res);
bool on_get_blocks(const COMMAND_RPC_GET_BLOCKS_FAST::request& req, COMMAND_RPC_GET_BLOCKS_FAST::response& res);
+ bool on_get_blocks_by_height(const COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::request& req, COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::response& res);
bool on_get_hashes(const COMMAND_RPC_GET_HASHES_FAST::request& req, COMMAND_RPC_GET_HASHES_FAST::response& res);
bool on_get_transactions(const COMMAND_RPC_GET_TRANSACTIONS::request& req, COMMAND_RPC_GET_TRANSACTIONS::response& res);
bool on_is_key_image_spent(const COMMAND_RPC_IS_KEY_IMAGE_SPENT::request& req, COMMAND_RPC_IS_KEY_IMAGE_SPENT::response& res);
@@ -141,6 +144,7 @@ namespace cryptonote
bool on_get_peer_list(const COMMAND_RPC_GET_PEER_LIST::request& req, COMMAND_RPC_GET_PEER_LIST::response& res);
bool on_set_log_hash_rate(const COMMAND_RPC_SET_LOG_HASH_RATE::request& req, COMMAND_RPC_SET_LOG_HASH_RATE::response& res);
bool on_set_log_level(const COMMAND_RPC_SET_LOG_LEVEL::request& req, COMMAND_RPC_SET_LOG_LEVEL::response& res);
+ bool on_set_log_categories(const COMMAND_RPC_SET_LOG_CATEGORIES::request& req, COMMAND_RPC_SET_LOG_CATEGORIES::response& res);
bool on_get_transaction_pool(const COMMAND_RPC_GET_TRANSACTION_POOL::request& req, COMMAND_RPC_GET_TRANSACTION_POOL::response& res);
bool on_stop_daemon(const COMMAND_RPC_STOP_DAEMON::request& req, COMMAND_RPC_STOP_DAEMON::response& res);
bool on_out_peers(const COMMAND_RPC_OUT_PEERS::request& req, COMMAND_RPC_OUT_PEERS::response& res);
diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h
index fa86c08e4..0fc230d11 100644
--- a/src/rpc/core_rpc_server_commands_defs.h
+++ b/src/rpc/core_rpc_server_commands_defs.h
@@ -49,8 +49,9 @@ namespace cryptonote
// advance which version they will stop working with
// Don't go over 32767 for any of these
#define CORE_RPC_VERSION_MAJOR 1
-#define CORE_RPC_VERSION_MINOR 4
-#define CORE_RPC_VERSION (((CORE_RPC_VERSION_MAJOR)<<16)|(CORE_RPC_VERSION_MINOR))
+#define CORE_RPC_VERSION_MINOR 6
+#define MAKE_CORE_RPC_VERSION(major,minor) (((major)<<16)|(minor))
+#define CORE_RPC_VERSION MAKE_CORE_RPC_VERSION(CORE_RPC_VERSION_MAJOR, CORE_RPC_VERSION_MINOR)
struct COMMAND_RPC_GET_HEIGHT
{
@@ -121,6 +122,28 @@ namespace cryptonote
};
};
+ struct COMMAND_RPC_GET_BLOCKS_BY_HEIGHT
+ {
+ struct request
+ {
+ std::vector<uint64_t> heights;
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(heights)
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct response
+ {
+ std::vector<block_complete_entry> blocks;
+ std::string status;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(blocks)
+ KV_SERIALIZE(status)
+ END_KV_SERIALIZE_MAP()
+ };
+ };
+
struct COMMAND_RPC_GET_HASHES_FAST
{
@@ -706,6 +729,7 @@ namespace cryptonote
difficulty_type difficulty;
uint64_t reward;
uint64_t block_size;
+ uint64_t num_txes;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(major_version)
@@ -720,6 +744,7 @@ namespace cryptonote
KV_SERIALIZE(difficulty)
KV_SERIALIZE(reward)
KV_SERIALIZE(block_size)
+ KV_SERIALIZE(num_txes)
END_KV_SERIALIZE_MAP()
};
@@ -906,6 +931,26 @@ namespace cryptonote
};
};
+ struct COMMAND_RPC_SET_LOG_CATEGORIES
+ {
+ struct request
+ {
+ std::string categories;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(categories)
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct response
+ {
+ std::string status;
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(status)
+ END_KV_SERIALIZE_MAP()
+ };
+ };
+
struct tx_info
{
std::string id_hash;
@@ -920,6 +965,7 @@ namespace cryptonote
uint64_t receive_time;
bool relayed;
uint64_t last_relayed_time;
+ bool do_not_relay;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(id_hash)
@@ -934,6 +980,7 @@ namespace cryptonote
KV_SERIALIZE(receive_time)
KV_SERIALIZE(relayed)
KV_SERIALIZE(last_relayed_time)
+ KV_SERIALIZE(do_not_relay)
END_KV_SERIALIZE_MAP()
};
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index f0c1e914a..68781dd73 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -68,11 +68,13 @@ using boost::lexical_cast;
namespace po = boost::program_options;
typedef cryptonote::simple_wallet sw;
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "wallet.simplewallet"
+
#define EXTENDED_LOGS_FILE "wallet_details.log"
#define DEFAULT_MIX 4
-#define KEY_IMAGE_EXPORT_FILE_MAGIC "Monero key image export\002"
#define OUTPUT_EXPORT_FILE_MAGIC "Monero output export\003"
#define LOCK_IDLE_SCOPE() \
@@ -137,8 +139,8 @@ namespace
class message_writer
{
public:
- message_writer(epee::log_space::console_colors color = epee::log_space::console_color_default, bool bright = false,
- std::string&& prefix = std::string(), int log_level = LOG_LEVEL_2)
+ message_writer(console_colors color = console_color_default, bool bright = false,
+ std::string&& prefix = std::string(), el::Level log_level = el::Level::Info)
: m_flush(true)
, m_color(color)
, m_bright(bright)
@@ -174,17 +176,17 @@ namespace
{
m_flush = false;
- LOG_PRINT(m_oss.str(), m_log_level);
+ MCLOG(m_log_level, "global", m_oss.str());
- if (epee::log_space::console_color_default == m_color)
+ if (console_color_default == m_color)
{
std::cout << m_oss.str();
}
else
{
- epee::log_space::set_console_color(m_color, m_bright);
+ set_console_color(m_color, m_bright);
std::cout << m_oss.str();
- epee::log_space::reset_console_color();
+ reset_console_color();
}
std::cout << std::endl;
}
@@ -198,19 +200,19 @@ namespace
private:
bool m_flush;
std::stringstream m_oss;
- epee::log_space::console_colors m_color;
+ console_colors m_color;
bool m_bright;
- int m_log_level;
+ el::Level m_log_level;
};
message_writer success_msg_writer(bool color = false)
{
- return message_writer(color ? epee::log_space::console_color_green : epee::log_space::console_color_default, false, std::string(), LOG_LEVEL_2);
+ return message_writer(color ? console_color_green : console_color_default, false, std::string(), el::Level::Info);
}
message_writer fail_msg_writer()
{
- return message_writer(epee::log_space::console_color_red, true, sw::tr("Error: "), LOG_LEVEL_0);
+ return message_writer(console_color_red, true, sw::tr("Error: "), el::Level::Error);
}
bool is_it_true(const std::string& s)
@@ -572,7 +574,7 @@ simple_wallet::simple_wallet()
m_cmd_binder.set_handler("donate", boost::bind(&simple_wallet::donate, this, _1), tr("donate [<mixin_count>] <amount> [payment_id] - Donate <amount> to the development team (donate.getmonero.org)"));
m_cmd_binder.set_handler("sign_transfer", boost::bind(&simple_wallet::sign_transfer, this, _1), tr("Sign a transaction from a file"));
m_cmd_binder.set_handler("submit_transfer", boost::bind(&simple_wallet::submit_transfer, this, _1), tr("Submit a signed transaction from a file"));
- m_cmd_binder.set_handler("set_log", boost::bind(&simple_wallet::set_log, this, _1), tr("set_log <level> - Change current log detail level, <0-4>"));
+ m_cmd_binder.set_handler("set_log", boost::bind(&simple_wallet::set_log, this, _1), tr("set_log <level>|<categories> - Change current log detail (level must be <0-4>)"));
m_cmd_binder.set_handler("address", boost::bind(&simple_wallet::print_address, this, _1), tr("Show current wallet public address"));
m_cmd_binder.set_handler("integrated_address", boost::bind(&simple_wallet::print_integrated_address, this, _1), tr("integrated_address [PID] - Encode a payment ID into an integrated address for the current wallet public address (no argument uses a random payment ID), or decode an integrated address to standard address and payment ID"));
m_cmd_binder.set_handler("address_book", boost::bind(&simple_wallet::address_book, this, _1), tr("address_book [(add (<address> [pid <long or short payment id>])|<integrated address> [<description possibly with whitespaces>])|(delete <index>)] - Print all entries in the address book, optionally adding/deleting an entry to/from it"));
@@ -746,22 +748,24 @@ bool simple_wallet::set_log(const std::vector<std::string> &args)
{
if(args.size() != 1)
{
- fail_msg_writer() << tr("usage: set_log <log_level_number_0-4>");
+ fail_msg_writer() << tr("usage: set_log <log_level_number_0-4> | <categories>");
return true;
}
uint16_t l = 0;
- if(!epee::string_tools::get_xtype_from_string(l, args[0]))
+ if(epee::string_tools::get_xtype_from_string(l, args[0]))
{
- fail_msg_writer() << tr("wrong number format, use: set_log <log_level_number_0-4>");
- return true;
+ if(4 < l)
+ {
+ fail_msg_writer() << tr("wrong number range, use: set_log <log_level_number_0-4>");
+ return true;
+ }
+
+ mlog_set_log_level(l);
}
- if(LOG_LEVEL_4 < l)
+ else
{
- fail_msg_writer() << tr("wrong number range, use: set_log <log_level_number_0-4>");
- return true;
+ mlog_set_categories(args.front().c_str());
}
-
- log_space::log_singletone::get_set_log_detalisation_level(true, l);
return true;
}
//----------------------------------------------------------------------------------------------------
@@ -935,22 +939,6 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
return false;
}
}
- if (!m_restore_height && m_restoring)
- {
- std::string heightstr = command_line::input_line("Restore from specific blockchain height (optional, default 0): ");
- if (std::cin.eof())
- return false;
- if (heightstr.size())
- {
- try {
- m_restore_height = boost::lexical_cast<uint64_t>(heightstr);
- }
- catch (boost::bad_lexical_cast &) {
- fail_msg_writer() << tr("bad m_restore_height parameter:") << " " << heightstr;
- return false;
- }
- }
- }
if (!m_generate_from_view_key.empty())
{
m_wallet_file = m_generate_from_view_key;
@@ -1091,6 +1079,70 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
bool r = new_wallet(vm, m_recovery_key, m_restore_deterministic_wallet, m_non_deterministic, old_language);
CHECK_AND_ASSERT_MES(r, false, tr("account creation failed"));
}
+ if (!m_restore_height && m_restoring)
+ {
+ uint32_t version;
+ bool connected = try_connect_to_daemon(false, &version);
+ while (true)
+ {
+ std::string heightstr;
+ if (!connected || version < MAKE_CORE_RPC_VERSION(1, 6))
+ heightstr = command_line::input_line("Restore from specific blockchain height (optional, default 0): ");
+ else
+ heightstr = command_line::input_line("Restore from specific blockchain height (optional, default 0),\nor alternatively from specific date (YYYY-MM-DD): ");
+ if (std::cin.eof())
+ return false;
+ if (heightstr.empty())
+ {
+ m_restore_height = 0;
+ break;
+ }
+ try
+ {
+ m_restore_height = boost::lexical_cast<uint64_t>(heightstr);
+ break;
+ }
+ catch (const boost::bad_lexical_cast &)
+ {
+ if (!connected || version < MAKE_CORE_RPC_VERSION(1, 6))
+ {
+ fail_msg_writer() << tr("bad m_restore_height parameter: ") << heightstr;
+ continue;
+ }
+ if (heightstr.size() != 10 || heightstr[4] != '-' || heightstr[7] != '-')
+ {
+ fail_msg_writer() << tr("date format must be YYYY-MM-DD");
+ continue;
+ }
+ uint16_t year;
+ uint8_t month; // 1, 2, ..., 12
+ uint8_t day; // 1, 2, ..., 31
+ try
+ {
+ year = boost::lexical_cast<uint16_t>(heightstr.substr(0,4));
+ // lexical_cast<uint8_t> won't work becasue uint8_t is treated as character type
+ month = boost::lexical_cast<uint16_t>(heightstr.substr(5,2));
+ day = boost::lexical_cast<uint16_t>(heightstr.substr(8,2));
+ m_restore_height = m_wallet->get_blockchain_height_by_date(year, month, day);
+ success_msg_writer() << tr("Restore height is: ") << m_restore_height;
+ std::string confirm = command_line::input_line(tr("Is this okay? (Y/Yes/N/No): "));
+ if (std::cin.eof())
+ return false;
+ if(command_line::is_yes(confirm))
+ break;
+ }
+ catch (const boost::bad_lexical_cast &)
+ {
+ fail_msg_writer() << tr("bad m_restore_height parameter: ") << heightstr;
+ }
+ catch (const std::runtime_error& e)
+ {
+ fail_msg_writer() << e.what();
+ }
+ }
+ }
+ m_wallet->set_refresh_from_block_height(m_restore_height);
+ }
}
else
{
@@ -1245,7 +1297,7 @@ bool simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
if (was_deprecated_wallet)
{
// The user had used an older version of the wallet with old style mnemonics.
- message_writer(epee::log_space::console_color_green, false) << "\n" << tr("You had been using "
+ message_writer(console_color_green, false) << "\n" << tr("You had been using "
"a deprecated version of the wallet. Please use the new seed that we provide.\n");
}
mnemonic_language = get_mnemonic_language();
@@ -1269,7 +1321,7 @@ bool simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
try
{
recovery_val = m_wallet->generate(m_wallet_file, std::move(rc.second).password(), recovery_key, recover, two_random);
- message_writer(epee::log_space::console_color_white, true) << tr("Generated new wallet: ")
+ message_writer(console_color_white, true) << tr("Generated new wallet: ")
<< m_wallet->get_account().get_public_address_str(m_wallet->testnet());
std::cout << tr("View key: ") << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key) << ENDL;
}
@@ -1326,7 +1378,7 @@ bool simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
{
m_wallet->generate(m_wallet_file, std::move(rc.second).password(), address, viewkey);
}
- message_writer(epee::log_space::console_color_white, true) << tr("Generated new wallet: ")
+ message_writer(console_color_white, true) << tr("Generated new wallet: ")
<< m_wallet->get_account().get_public_address_str(m_wallet->testnet());
}
catch (const std::exception& e)
@@ -1357,7 +1409,7 @@ bool simple_wallet::open_wallet(const boost::program_options::variables_map& vm)
return false;
}
- message_writer(epee::log_space::console_color_white, true) <<
+ message_writer(console_color_white, true) <<
(m_wallet->watch_only() ? tr("Opened watch-only wallet") : tr("Opened wallet")) << ": "
<< m_wallet->get_account().get_public_address_str(m_wallet->testnet());
// If the wallet file is deprecated, we should ask for mnemonic language again and store
@@ -1367,7 +1419,7 @@ bool simple_wallet::open_wallet(const boost::program_options::variables_map& vm)
{
if (m_wallet->is_deterministic())
{
- message_writer(epee::log_space::console_color_green, false) << "\n" << tr("You had been using "
+ message_writer(console_color_green, false) << "\n" << tr("You had been using "
"a deprecated version of the wallet. Please proceed to upgrade your wallet.\n");
std::string mnemonic_language = get_mnemonic_language();
if (mnemonic_language.empty())
@@ -1382,7 +1434,7 @@ bool simple_wallet::open_wallet(const boost::program_options::variables_map& vm)
}
else
{
- message_writer(epee::log_space::console_color_green, false) << "\n" << tr("You had been using "
+ message_writer(console_color_green, false) << "\n" << tr("You had been using "
"a deprecated version of the wallet. Your wallet file format is being upgraded now.\n");
m_wallet->rewrite(m_wallet_file, password);
}
@@ -1559,7 +1611,7 @@ void simple_wallet::on_new_block(uint64_t height, const cryptonote::block& block
//----------------------------------------------------------------------------------------------------
void simple_wallet::on_money_received(uint64_t height, const cryptonote::transaction& tx, uint64_t amount)
{
- message_writer(epee::log_space::console_color_green, false) << "\r" <<
+ message_writer(console_color_green, false) << "\r" <<
tr("Height ") << height << ", " <<
tr("transaction ") << get_transaction_hash(tx) << ", " <<
tr("received ") << print_money(amount);
@@ -1576,7 +1628,7 @@ void simple_wallet::on_unconfirmed_money_received(uint64_t height, const crypton
//----------------------------------------------------------------------------------------------------
void simple_wallet::on_money_spent(uint64_t height, const cryptonote::transaction& in_tx, uint64_t amount, const cryptonote::transaction& spend_tx)
{
- message_writer(epee::log_space::console_color_magenta, false) << "\r" <<
+ message_writer(console_color_magenta, false) << "\r" <<
tr("Height ") << height << ", " <<
tr("transaction ") << get_transaction_hash(spend_tx) << ", " <<
tr("spent ") << print_money(amount);
@@ -1588,7 +1640,7 @@ void simple_wallet::on_money_spent(uint64_t height, const cryptonote::transactio
//----------------------------------------------------------------------------------------------------
void simple_wallet::on_skip_transaction(uint64_t height, const cryptonote::transaction& tx)
{
- message_writer(epee::log_space::console_color_red, true) << "\r" <<
+ message_writer(console_color_red, true) << "\r" <<
tr("Height ") << height << ", " <<
tr("transaction ") << get_transaction_hash(tx) << ", " <<
tr("unsupported transaction format");
@@ -1740,7 +1792,7 @@ bool simple_wallet::show_incoming_transfers(const std::vector<std::string>& args
std::string verbose_string;
if (verbose)
verbose_string = (boost::format("%68s%68s") % td.get_public_key() % (td.m_key_image_known ? epee::string_tools::pod_to_hex(td.m_key_image) : std::string('?', 64))).str();
- message_writer(td.m_spent ? epee::log_space::console_color_magenta : epee::log_space::console_color_green, false) <<
+ message_writer(td.m_spent ? console_color_magenta : console_color_green, false) <<
boost::format("%21s%8s%12s%8s%16u%68s%s") %
print_money(td.amount()) %
(td.m_spent ? tr("T") : tr("F")) %
@@ -3395,7 +3447,7 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
// print in and out sorted by height
for (std::map<uint64_t, std::pair<bool, std::string>>::const_iterator i = output.begin(); i != output.end(); ++i) {
- message_writer(i->second.first ? epee::log_space::console_color_green : epee::log_space::console_color_magenta, false) <<
+ message_writer(i->second.first ? console_color_green : console_color_magenta, false) <<
boost::format("%8.8llu %6.6s %s") %
((unsigned long long)i->first) % (i->second.first ? tr("in") : tr("out")) % i->second.second;
}
@@ -3605,7 +3657,7 @@ bool simple_wallet::run()
m_idle_thread = boost::thread([&]{wallet_idle_thread();});
std::string addr_start = m_wallet->get_account().get_public_address_str(m_wallet->testnet()).substr(0, 6);
- message_writer(epee::log_space::console_color_green, false) << "Background refresh thread started";
+ message_writer(console_color_green, false) << "Background refresh thread started";
return m_cmd_binder.run_handling(std::string("[") + tr("wallet") + " " + addr_start + "]: ", "");
}
//----------------------------------------------------------------------------------------------------
@@ -3907,23 +3959,7 @@ bool simple_wallet::export_key_images(const std::vector<std::string> &args)
try
{
- std::vector<std::pair<crypto::key_image, crypto::signature>> ski = m_wallet->export_key_images();
- std::string magic(KEY_IMAGE_EXPORT_FILE_MAGIC, strlen(KEY_IMAGE_EXPORT_FILE_MAGIC));
- const cryptonote::account_public_address &keys = m_wallet->get_account().get_keys().m_account_address;
-
- std::string data;
- data += std::string((const char *)&keys.m_spend_public_key, sizeof(crypto::public_key));
- data += std::string((const char *)&keys.m_view_public_key, sizeof(crypto::public_key));
- for (const auto &i: ski)
- {
- data += std::string((const char *)&i.first, sizeof(crypto::key_image));
- data += std::string((const char *)&i.second, sizeof(crypto::signature));
- }
-
- // encrypt data, keep magic plaintext
- std::string ciphertext = m_wallet->encrypt_with_view_secret_key(data);
- bool r = epee::file_io_utils::save_string_to_file(filename, magic + ciphertext);
- if (!r)
+ if (!m_wallet->export_key_images(filename))
{
fail_msg_writer() << tr("failed to save file ") << filename;
return true;
@@ -3949,69 +3985,17 @@ bool simple_wallet::import_key_images(const std::vector<std::string> &args)
}
std::string filename = args[0];
- std::string data;
- bool r = epee::file_io_utils::load_file_to_string(filename, data);
- if (!r)
- {
- fail_msg_writer() << tr("failed to read file ") << filename;
- return true;
- }
- const size_t magiclen = strlen(KEY_IMAGE_EXPORT_FILE_MAGIC);
- if (data.size() < magiclen || memcmp(data.data(), KEY_IMAGE_EXPORT_FILE_MAGIC, magiclen))
- {
- fail_msg_writer() << "Bad key image export file magic in " << filename;
- return true;
- }
-
- try
- {
- data = m_wallet->decrypt_with_view_secret_key(std::string(data, magiclen));
- }
- catch (const std::exception &e)
- {
- fail_msg_writer() << "Failed to decrypt " << filename << ": " << e.what();
- return true;
- }
-
- const size_t headerlen = 2 * sizeof(crypto::public_key);
- if (data.size() < headerlen)
- {
- fail_msg_writer() << "Bad data size from file " << filename;
- return true;
- }
- const crypto::public_key &public_spend_key = *(const crypto::public_key*)&data[0];
- const crypto::public_key &public_view_key = *(const crypto::public_key*)&data[sizeof(crypto::public_key)];
- const cryptonote::account_public_address &keys = m_wallet->get_account().get_keys().m_account_address;
- if (public_spend_key != keys.m_spend_public_key || public_view_key != keys.m_view_public_key)
- {
- fail_msg_writer() << "Key images from " << filename << " are for a different account";
- return true;
- }
-
- const size_t record_size = sizeof(crypto::key_image) + sizeof(crypto::signature);
- if ((data.size() - headerlen) % record_size)
- {
- fail_msg_writer() << "Bad data size from file " << filename;
- return true;
- }
- size_t nki = (data.size() - headerlen) / record_size;
-
- std::vector<std::pair<crypto::key_image, crypto::signature>> ski;
- ski.reserve(nki);
- for (size_t n = 0; n < nki; ++n)
- {
- crypto::key_image key_image = *reinterpret_cast<const crypto::key_image*>(&data[headerlen + n * record_size]);
- crypto::signature signature = *reinterpret_cast<const crypto::signature*>(&data[headerlen + n * record_size + sizeof(crypto::key_image)]);
-
- ski.push_back(std::make_pair(key_image, signature));
- }
-
try
{
uint64_t spent = 0, unspent = 0;
- uint64_t height = m_wallet->import_key_images(ski, spent, unspent);
- success_msg_writer() << "Signed key images imported to height " << height << ", "
- << print_money(spent) << " spent, " << print_money(unspent) << " unspent";
+ uint64_t height = m_wallet->import_key_images(filename, spent, unspent);
+ if (height > 0)
+ {
+ success_msg_writer() << "Signed key images imported to height " << height << ", "
+ << print_money(spent) << " spent, " << print_money(unspent) << " unspent";
+ } else {
+ fail_msg_writer() << "Failed to import key images";
+ }
}
catch (const std::exception &e)
{
@@ -4317,6 +4301,7 @@ int main(int argc, char* argv[])
const bool r = w.init(*vm);
CHECK_AND_ASSERT_MES(r, 1, sw::tr("Failed to initialize wallet"));
+try{ throw 1; } catch(...){}
std::vector<std::string> command = command_line::get_arg(*vm, arg_command);
if (!command.empty())
{
diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h
index bf4ace948..237c1e3e1 100644
--- a/src/simplewallet/simplewallet.h
+++ b/src/simplewallet/simplewallet.h
@@ -47,6 +47,9 @@
#include "wallet/password_container.h"
#include "crypto/crypto.h" // for definition of crypto::secret_key
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "wallet.simplewallet"
+
/*!
* \namespace cryptonote
* \brief Holds cryptonote related classes and helpers.
diff --git a/src/wallet/CMakeLists.txt b/src/wallet/CMakeLists.txt
index 53b0a794f..922464a3c 100644
--- a/src/wallet/CMakeLists.txt
+++ b/src/wallet/CMakeLists.txt
@@ -34,6 +34,7 @@ set(wallet_sources
password_container.cpp
wallet2.cpp
wallet_args.cpp
+ node_rpc_proxy.cpp
api/wallet.cpp
api/wallet_manager.cpp
api/transaction_info.cpp
@@ -55,6 +56,7 @@ set(wallet_private_headers
wallet_rpc_server.h
wallet_rpc_server_commands_defs.h
wallet_rpc_server_error_codes.h
+ node_rpc_proxy.h
api/wallet.h
api/wallet_manager.h
api/transaction_info.h
diff --git a/src/wallet/api/address_book.cpp b/src/wallet/api/address_book.cpp
index b878491ce..e397dac04 100644
--- a/src/wallet/api/address_book.cpp
+++ b/src/wallet/api/address_book.cpp
@@ -33,6 +33,7 @@
#include "wallet.h"
#include "crypto/hash.h"
#include "wallet/wallet2.h"
+#include "common_defines.h"
#include <vector>
@@ -43,30 +44,50 @@ AddressBook::~AddressBook() {}
AddressBookImpl::AddressBookImpl(WalletImpl *wallet)
: m_wallet(wallet) {}
-bool AddressBookImpl::addRow(const std::string &dst_addr , const std::string &payment_id, const std::string &description)
+bool AddressBookImpl::addRow(const std::string &dst_addr , const std::string &payment_id_str, const std::string &description)
{
- LOG_PRINT_L2("Adding row");
-
clearStatus();
cryptonote::account_public_address addr;
- bool has_payment_id;
+ bool has_short_pid;
crypto::hash8 payment_id_short;
- if(!cryptonote::get_account_integrated_address_from_str(addr, has_payment_id, payment_id_short, m_wallet->m_wallet->testnet(), dst_addr)) {
- m_errorString = "Invalid destination address";
+ if(!cryptonote::get_account_integrated_address_from_str(addr, has_short_pid, payment_id_short, m_wallet->m_wallet->testnet(), dst_addr)) {
+ m_errorString = tr("Invalid destination address");
m_errorCode = Invalid_Address;
return false;
}
- crypto::hash pid32 = cryptonote::null_hash;
- bool long_pid = (payment_id.empty())? false : tools::wallet2::parse_long_payment_id(payment_id, pid32);
- if(!payment_id.empty() && !long_pid) {
- m_errorString = "Invalid payment ID";
+ crypto::hash payment_id = cryptonote::null_hash;
+ bool has_long_pid = (payment_id_str.empty())? false : tools::wallet2::parse_long_payment_id(payment_id_str, payment_id);
+
+ // Short payment id provided
+ if(payment_id_str.length() == 16) {
+ m_errorString = tr("Invalid payment ID. Short payment ID should only be used in an integrated address");
+ m_errorCode = Invalid_Payment_Id;
+ return false;
+ }
+
+ // long payment id provided but not valid
+ if(!payment_id_str.empty() && !has_long_pid) {
+ m_errorString = tr("Invalid payment ID");
+ m_errorCode = Invalid_Payment_Id;
+ return false;
+ }
+
+ // integrated + long payment id provided
+ if(has_long_pid && has_short_pid) {
+ m_errorString = tr("Integrated address and long payment id can't be used at the same time");
m_errorCode = Invalid_Payment_Id;
return false;
}
- bool r = m_wallet->m_wallet->add_address_book_row(addr,pid32,description);
+ // Pad short pid with zeros
+ if (has_short_pid)
+ {
+ memcpy(payment_id.data, payment_id_short.data, 8);
+ }
+
+ bool r = m_wallet->m_wallet->add_address_book_row(addr,payment_id,description);
if (r)
refresh();
else
@@ -87,7 +108,16 @@ void AddressBookImpl::refresh()
std::string payment_id = (row->m_payment_id == cryptonote::null_hash)? "" : epee::string_tools::pod_to_hex(row->m_payment_id);
std::string address = cryptonote::get_account_address_as_str(m_wallet->m_wallet->testnet(),row->m_address);
-
+ // convert the zero padded short payment id to integrated address
+ if (payment_id.length() > 16 && payment_id.substr(16).find_first_not_of('0') == std::string::npos) {
+ payment_id = payment_id.substr(0,16);
+ crypto::hash8 payment_id_short;
+ if(tools::wallet2::parse_short_payment_id(payment_id, payment_id_short)) {
+ address = cryptonote::get_account_integrated_address_as_str(m_wallet->m_wallet->testnet(), row->m_address, payment_id_short);
+ // Don't show payment id when integrated address is used
+ payment_id = "";
+ }
+ }
AddressBookRow * abr = new AddressBookRow(i, address, payment_id, row->m_description);
m_rows.push_back(abr);
}
diff --git a/src/wallet/api/address_book.h b/src/wallet/api/address_book.h
index 33d06a078..5f72c5860 100644
--- a/src/wallet/api/address_book.h
+++ b/src/wallet/api/address_book.h
@@ -32,8 +32,7 @@
#include "wallet/wallet2.h"
namespace Monero {
-
-class AddressBookRow;
+
class WalletImpl;
class AddressBookImpl : public AddressBook
diff --git a/src/wallet/api/transaction_history.h b/src/wallet/api/transaction_history.h
index bd18e9440..37c9ea0e4 100644
--- a/src/wallet/api/transaction_history.h
+++ b/src/wallet/api/transaction_history.h
@@ -33,7 +33,6 @@
namespace Monero {
-class TransactionInfo;
class WalletImpl;
class TransactionHistoryImpl : public TransactionHistory
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index e8ae7c642..5f7d8e522 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -54,6 +54,8 @@ namespace {
static const int MAX_REFRESH_INTERVAL_MILLIS = 1000 * 60 * 1;
// Default refresh interval when connected to remote node
static const int DEFAULT_REMOTE_NODE_REFRESH_INTERVAL_MILLIS = 1000 * 10;
+ // Connection timeout 30 sec
+ static const int DEFAULT_CONNECTION_TIMEOUT_MILLIS = 1000 * 30;
}
struct Wallet2CallbackImpl : public tools::i_wallet2_callback
@@ -83,7 +85,7 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback
virtual void on_new_block(uint64_t height, const cryptonote::block& block)
{
- LOG_PRINT_L3(__FUNCTION__ << ": new block. height: " << height);
+ //LOG_PRINT_L3(__FUNCTION__ << ": new block. height: " << height);
if (m_listener) {
m_listener->newBlock(height);
@@ -662,25 +664,68 @@ UnsignedTransaction *WalletImpl::loadUnsignedTx(const std::string &unsigned_file
bool WalletImpl::submitTransaction(const string &fileName) {
clearStatus();
- PendingTransactionImpl * transaction = new PendingTransactionImpl(*this);
+ std::unique_ptr<PendingTransactionImpl> transaction(new PendingTransactionImpl(*this));
-// bool r = m_wallet->load_tx(fileName, transaction->m_pending_tx, [&](const tools::wallet2::signed_tx_set &tx){ return accept_loaded_tx(tx); });
bool r = m_wallet->load_tx(fileName, transaction->m_pending_tx);
if (!r) {
m_errorString = tr("Failed to load transaction from file");
m_status = Status_Ok;
- delete transaction;
return false;
}
if(!transaction->commit()) {
m_errorString = transaction->m_errorString;
m_status = Status_Error;
- delete transaction;
return false;
}
- delete transaction;
+ return true;
+}
+
+bool WalletImpl::exportKeyImages(const string &filename)
+{
+ if (m_wallet->watch_only())
+ {
+ m_errorString = tr("Wallet is view only");
+ m_status = Status_Error;
+ return false;
+ }
+
+ try
+ {
+ if (!m_wallet->export_key_images(filename))
+ {
+ m_errorString = tr("failed to save file ") + filename;
+ m_status = Status_Error;
+ return false;
+ }
+ }
+ catch (std::exception &e)
+ {
+ LOG_ERROR("Error exporting key images: " << e.what());
+ m_errorString = e.what();
+ m_status = Status_Error;
+ return false;
+ }
+ return true;
+}
+
+bool WalletImpl::importKeyImages(const string &filename)
+{
+ try
+ {
+ uint64_t spent = 0, unspent = 0;
+ uint64_t height = m_wallet->import_key_images(filename, spent, unspent);
+ LOG_PRINT_L2("Signed key images imported to height " << height << ", "
+ << print_money(spent) << " spent, " << print_money(unspent) << " unspent");
+ }
+ catch (const std::exception &e)
+ {
+ LOG_ERROR("Error exporting key images: " << e.what());
+ m_errorString = string(tr("Failed to import key images: ")) + e.what();
+ m_status = Status_Error;
+ return false;
+ }
return true;
}
@@ -1043,7 +1088,7 @@ bool WalletImpl::verifySignedMessage(const std::string &message, const std::stri
bool WalletImpl::connectToDaemon()
{
- bool result = m_wallet->check_connection();
+ bool result = m_wallet->check_connection(NULL, DEFAULT_CONNECTION_TIMEOUT_MILLIS);
m_status = result ? Status_Ok : Status_Error;
if (!result) {
m_errorString = "Error connecting to daemon at " + m_wallet->get_daemon_address();
@@ -1056,7 +1101,7 @@ bool WalletImpl::connectToDaemon()
Wallet::ConnectionStatus WalletImpl::connected() const
{
uint32_t version = 0;
- m_is_connected = m_wallet->check_connection(&version);
+ m_is_connected = m_wallet->check_connection(&version, DEFAULT_CONNECTION_TIMEOUT_MILLIS);
if (!m_is_connected)
return Wallet::ConnectionStatus_Disconnected;
if ((version >> 16) != CORE_RPC_VERSION_MAJOR)
@@ -1217,6 +1262,24 @@ bool WalletImpl::parse_uri(const std::string &uri, std::string &address, std::st
return m_wallet->parse_uri(uri, address, payment_id, amount, tx_description, recipient_name, unknown_parameters, error);
}
+bool WalletImpl::rescanSpent()
+{
+ clearStatus();
+ if (!trustedDaemon()) {
+ m_status = Status_Error;
+ m_errorString = tr("Rescan spent can only be used with a trusted daemon");
+ return false;
+ }
+ try {
+ m_wallet->rescan_spent();
+ } catch (const std::exception &e) {
+ LOG_ERROR(__FUNCTION__ << " error: " << e.what());
+ m_status = Status_Error;
+ m_errorString = e.what();
+ return false;
+ }
+ return true;
+}
} // namespace
namespace Bitmonero = Monero;
diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h
index 5b4064e8e..e3df7fd01 100644
--- a/src/wallet/api/wallet.h
+++ b/src/wallet/api/wallet.h
@@ -93,7 +93,7 @@ public:
void setRefreshFromBlockHeight(uint64_t refresh_from_block_height);
void setRecoveringFromSeed(bool recoveringFromSeed);
bool watchOnly() const;
-
+ bool rescanSpent();
PendingTransaction * createTransaction(const std::string &dst_addr, const std::string &payment_id,
@@ -102,6 +102,8 @@ public:
virtual PendingTransaction * createSweepUnmixableTransaction();
bool submitTransaction(const std::string &fileName);
virtual UnsignedTransaction * loadUnsignedTx(const std::string &unsigned_filename);
+ bool exportKeyImages(const std::string &filename);
+ bool importKeyImages(const std::string &filename);
virtual void disposeTransaction(PendingTransaction * t);
virtual TransactionHistory * history() const;
@@ -127,11 +129,12 @@ private:
bool isNewWallet() const;
void doInit(const std::string &daemon_address, uint64_t upper_transaction_size_limit);
+
private:
friend class PendingTransactionImpl;
friend class UnsignedTransactionImpl;
friend class TransactionHistoryImpl;
- friend class Wallet2CallbackImpl;
+ friend struct Wallet2CallbackImpl;
friend class AddressBookImpl;
tools::wallet2 * m_wallet;
diff --git a/src/wallet/api/wallet_manager.cpp b/src/wallet/api/wallet_manager.cpp
index 48faa3183..12bce0285 100644
--- a/src/wallet/api/wallet_manager.cpp
+++ b/src/wallet/api/wallet_manager.cpp
@@ -436,7 +436,7 @@ WalletManager *WalletManagerFactory::getWalletManager()
static WalletManagerImpl * g_walletManager = nullptr;
if (!g_walletManager) {
- epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_MAX);
+ mlog_configure("monero-wallet-gui.log", false);
g_walletManager = new WalletManagerImpl();
}
@@ -445,7 +445,7 @@ WalletManager *WalletManagerFactory::getWalletManager()
void WalletManagerFactory::setLogLevel(int level)
{
- epee::log_space::log_singletone::get_set_log_detalisation_level(true, level);
+ mlog_set_log_level(level);
}
diff --git a/src/wallet/node_rpc_proxy.cpp b/src/wallet/node_rpc_proxy.cpp
new file mode 100644
index 000000000..d7f755e36
--- /dev/null
+++ b/src/wallet/node_rpc_proxy.cpp
@@ -0,0 +1,134 @@
+// Copyright (c) 2017, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 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.
+//
+// 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.
+//
+// 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.
+
+#include "node_rpc_proxy.h"
+#include "rpc/core_rpc_server_commands_defs.h"
+#include "common/json_util.h"
+#include "storages/http_abstract_invoke.h"
+
+using namespace epee;
+
+namespace tools
+{
+
+void NodeRPCProxy::init(const std::string &daemon_address)
+{
+ m_daemon_address = daemon_address;
+
+ m_height = 0;
+ m_height_time = 0;
+ for (auto &slot: m_earliest_height)
+ slot = 0;
+ m_dynamic_per_kb_fee_estimate = 0;
+ m_dynamic_per_kb_fee_estimate_cached_height = 0;
+ m_dynamic_per_kb_fee_estimate_grace_blocks = 0;
+}
+
+boost::optional<std::string> NodeRPCProxy::get_height(uint64_t &height)
+{
+ const time_t now = time(NULL);
+ if (m_height == 0 || now >= m_height_time + 30) // re-cache every 30 seconds
+ {
+ cryptonote::COMMAND_RPC_GET_HEIGHT::request req = AUTO_VAL_INIT(req);
+ cryptonote::COMMAND_RPC_GET_HEIGHT::response res = AUTO_VAL_INIT(res);
+
+ m_daemon_rpc_mutex.lock();
+ bool r = net_utils::invoke_http_json_remote_command2(m_daemon_address + "/getheight", req, res, m_http_client);
+ m_daemon_rpc_mutex.unlock();
+ CHECK_AND_ASSERT_MES(r, std::string(), "Failed to connect to daemon");
+ CHECK_AND_ASSERT_MES(res.status != CORE_RPC_STATUS_BUSY, res.status, "Failed to connect to daemon");
+ CHECK_AND_ASSERT_MES(res.status == CORE_RPC_STATUS_OK, res.status, "Failed to get current blockchain height");
+ m_height = res.height;
+ m_height_time = now;
+ }
+ height = m_height;
+ return boost::optional<std::string>();
+}
+
+void NodeRPCProxy::set_height(uint64_t h)
+{
+ m_height = h;
+}
+
+boost::optional<std::string> NodeRPCProxy::get_earliest_height(uint8_t version, uint64_t &earliest_height)
+{
+ if (m_earliest_height[version] == 0)
+ {
+ epee::json_rpc::request<cryptonote::COMMAND_RPC_HARD_FORK_INFO::request> req_t = AUTO_VAL_INIT(req_t);
+ epee::json_rpc::response<cryptonote::COMMAND_RPC_HARD_FORK_INFO::response, std::string> resp_t = AUTO_VAL_INIT(resp_t);
+
+ m_daemon_rpc_mutex.lock();
+ req_t.jsonrpc = "2.0";
+ req_t.id = epee::serialization::storage_entry(0);
+ req_t.method = "hard_fork_info";
+ req_t.params.version = version;
+ bool r = net_utils::invoke_http_json_remote_command2(m_daemon_address + "/json_rpc", req_t, resp_t, m_http_client);
+ m_daemon_rpc_mutex.unlock();
+ CHECK_AND_ASSERT_MES(r, std::string(), "Failed to connect to daemon");
+ CHECK_AND_ASSERT_MES(resp_t.result.status != CORE_RPC_STATUS_BUSY, resp_t.result.status, "Failed to connect to daemon");
+ CHECK_AND_ASSERT_MES(resp_t.result.status == CORE_RPC_STATUS_OK, resp_t.result.status, "Failed to get hard fork status");
+ m_earliest_height[version] = resp_t.result.earliest_height;
+ }
+
+ earliest_height = m_earliest_height[version];
+ return boost::optional<std::string>();
+}
+
+boost::optional<std::string> NodeRPCProxy::get_dynamic_per_kb_fee_estimate(uint64_t grace_blocks, uint64_t &fee)
+{
+ uint64_t height;
+
+ boost::optional<std::string> result = get_height(height);
+ if (result)
+ return result;
+
+ if (m_dynamic_per_kb_fee_estimate_cached_height != height || m_dynamic_per_kb_fee_estimate_grace_blocks != grace_blocks)
+ {
+ epee::json_rpc::request<cryptonote::COMMAND_RPC_GET_PER_KB_FEE_ESTIMATE::request> req_t = AUTO_VAL_INIT(req_t);
+ epee::json_rpc::response<cryptonote::COMMAND_RPC_GET_PER_KB_FEE_ESTIMATE::response, std::string> resp_t = AUTO_VAL_INIT(resp_t);
+
+ m_daemon_rpc_mutex.lock();
+ req_t.jsonrpc = "2.0";
+ req_t.id = epee::serialization::storage_entry(0);
+ req_t.method = "get_fee_estimate";
+ req_t.params.grace_blocks = grace_blocks;
+ bool r = net_utils::invoke_http_json_remote_command2(m_daemon_address + "/json_rpc", req_t, resp_t, m_http_client);
+ m_daemon_rpc_mutex.unlock();
+ CHECK_AND_ASSERT_MES(r, std::string(), "Failed to connect to daemon");
+ CHECK_AND_ASSERT_MES(resp_t.result.status != CORE_RPC_STATUS_BUSY, resp_t.result.status, "Failed to connect to daemon");
+ CHECK_AND_ASSERT_MES(resp_t.result.status == CORE_RPC_STATUS_OK, resp_t.result.status, "Failed to get fee estimate");
+ m_dynamic_per_kb_fee_estimate = resp_t.result.fee;
+ m_dynamic_per_kb_fee_estimate_cached_height = height;
+ m_dynamic_per_kb_fee_estimate_grace_blocks = grace_blocks;
+ }
+
+ fee = m_dynamic_per_kb_fee_estimate;
+ return boost::optional<std::string>();
+}
+
+}
diff --git a/src/wallet/node_rpc_proxy.h b/src/wallet/node_rpc_proxy.h
new file mode 100644
index 000000000..1ae716dab
--- /dev/null
+++ b/src/wallet/node_rpc_proxy.h
@@ -0,0 +1,65 @@
+// Copyright (c) 2017, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 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.
+//
+// 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.
+//
+// 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.
+
+#pragma once
+
+#include <string>
+#include <boost/thread/mutex.hpp>
+#include "include_base_utils.h"
+#include "net/http_client.h"
+
+namespace tools
+{
+
+class NodeRPCProxy
+{
+public:
+ NodeRPCProxy(epee::net_utils::http::http_simple_client &http_client, boost::mutex &mutex):
+ m_http_client(http_client), m_daemon_rpc_mutex(mutex) { init(""); }
+
+ void init(const std::string &daemon_address);
+
+ boost::optional<std::string> get_height(uint64_t &height);
+ void set_height(uint64_t h);
+ boost::optional<std::string> get_earliest_height(uint8_t version, uint64_t &earliest_height);
+ boost::optional<std::string> get_dynamic_per_kb_fee_estimate(uint64_t grace_blocks, uint64_t &fee);
+
+private:
+ std::string m_daemon_address;
+ epee::net_utils::http::http_simple_client &m_http_client;
+ boost::mutex &m_daemon_rpc_mutex;
+
+ uint64_t m_height;
+ time_t m_height_time;
+ uint64_t m_earliest_height[256];
+ uint64_t m_dynamic_per_kb_fee_estimate;
+ uint64_t m_dynamic_per_kb_fee_estimate_cached_height;
+ uint64_t m_dynamic_per_kb_fee_estimate_grace_blocks;
+};
+
+}
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 29cf47ddd..c08b16a5f 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -67,6 +67,9 @@ extern "C"
}
using namespace cryptonote;
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "wallet.wallet2"
+
// used to choose when to stop adding outputs to a tx
#define APPROXIMATE_INPUT_BYTES 80
@@ -92,6 +95,8 @@ using namespace cryptonote;
ioservice.stop(); \
} while(0)
+#define KEY_IMAGE_EXPORT_FILE_MAGIC "Monero key image export\002"
+
namespace
{
// Create on-demand to prevent static initialization order fiasco issues.
@@ -391,6 +396,19 @@ std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file,
return nullptr;
}
+static void throw_on_rpc_response_error(const boost::optional<std::string> &status, const char *method)
+{
+ // no error
+ if (!status)
+ return;
+
+ // empty string -> not connection
+ THROW_WALLET_EXCEPTION_IF(status->empty(), tools::error::no_connection_to_daemon, method);
+
+ THROW_WALLET_EXCEPTION_IF(*status == CORE_RPC_STATUS_BUSY, tools::error::daemon_busy, method);
+ THROW_WALLET_EXCEPTION_IF(*status != CORE_RPC_STATUS_OK, tools::error::wallet_generic_rpc_error, method, *status);
+}
+
} //namespace
namespace tools
@@ -468,6 +486,7 @@ void wallet2::init(const std::string& daemon_address, uint64_t upper_transaction
{
m_upper_transaction_size_limit = upper_transaction_size_limit;
m_daemon_address = daemon_address;
+ m_node_rpc_proxy.init(m_daemon_address);
}
//----------------------------------------------------------------------------------------------------
bool wallet2::is_deterministic() const
@@ -1638,7 +1657,10 @@ void wallet2::refresh(uint64_t start_height, uint64_t & blocks_fetched, bool& re
blocks_fetched += added_blocks;
pull_thread.join();
if(blocks_start_height == next_blocks_start_height)
+ {
+ m_node_rpc_proxy.set_height(m_blockchain.size());
break;
+ }
// switch to the new blocks from the daemon
blocks_start_height = next_blocks_start_height;
@@ -2063,7 +2085,7 @@ crypto::secret_key wallet2::generate(const std::string& wallet_, const std::stri
THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_testnet));
- if(!r) LOG_PRINT_RED_L0("String with address text not saved");
+ if(!r) MERROR("String with address text not saved");
cryptonote::block b;
generate_genesis(b);
@@ -2098,7 +2120,7 @@ void wallet2::generate(const std::string& wallet_, const std::string& password,
THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_testnet));
- if(!r) LOG_PRINT_RED_L0("String with address text not saved");
+ if(!r) MERROR("String with address text not saved");
cryptonote::block b;
generate_genesis(b);
@@ -2133,7 +2155,7 @@ void wallet2::generate(const std::string& wallet_, const std::string& password,
THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_testnet));
- if(!r) LOG_PRINT_RED_L0("String with address text not saved");
+ if(!r) MERROR("String with address text not saved");
cryptonote::block b;
generate_genesis(b);
@@ -2232,7 +2254,7 @@ bool wallet2::prepare_file_names(const std::string& file_path)
return true;
}
//----------------------------------------------------------------------------------------------------
-bool wallet2::check_connection(uint32_t *version)
+bool wallet2::check_connection(uint32_t *version, uint32_t timeout)
{
boost::lock_guard<boost::mutex> lock(m_daemon_rpc_mutex);
@@ -2246,7 +2268,7 @@ bool wallet2::check_connection(uint32_t *version)
u.port = m_testnet ? config::testnet::RPC_DEFAULT_PORT : config::RPC_DEFAULT_PORT;
}
- if (!m_http_client.connect(u.host, std::to_string(u.port), 10000))
+ if (!m_http_client.connect(u.host, std::to_string(u.port), timeout))
return false;
}
@@ -2731,7 +2753,7 @@ float wallet2::get_output_relatedness(const transfer_details &td0, const transfe
return 0.0f;
}
//----------------------------------------------------------------------------------------------------
-size_t wallet2::pop_best_value_from(const transfer_container &transfers, std::vector<size_t> &unused_indices, const std::list<size_t>& selected_transfers) const
+size_t wallet2::pop_best_value_from(const transfer_container &transfers, std::vector<size_t> &unused_indices, const std::list<size_t>& selected_transfers, bool smallest) const
{
std::vector<size_t> candidates;
float best_relatedness = 1.0f;
@@ -2759,13 +2781,30 @@ size_t wallet2::pop_best_value_from(const transfer_container &transfers, std::ve
if (relatedness == best_relatedness)
candidates.push_back(n);
}
- size_t idx = crypto::rand<size_t>() % candidates.size();
+
+ // we have all the least related outputs in candidates, so we can pick either
+ // the smallest, or a random one, depending on request
+ size_t idx;
+ if (smallest)
+ {
+ idx = 0;
+ for (size_t n = 0; n < candidates.size(); ++n)
+ {
+ const transfer_details &td = transfers[unused_indices[candidates[n]]];
+ if (td.amount() < transfers[unused_indices[candidates[idx]]].amount())
+ idx = n;
+ }
+ }
+ else
+ {
+ idx = crypto::rand<size_t>() % candidates.size();
+ }
return pop_index (unused_indices, candidates[idx]);
}
//----------------------------------------------------------------------------------------------------
-size_t wallet2::pop_best_value(std::vector<size_t> &unused_indices, const std::list<size_t>& selected_transfers) const
+size_t wallet2::pop_best_value(std::vector<size_t> &unused_indices, const std::list<size_t>& selected_transfers, bool smallest) const
{
- return pop_best_value_from(m_transfers, unused_indices, selected_transfers);
+ return pop_best_value_from(m_transfers, unused_indices, selected_transfers, smallest);
}
//----------------------------------------------------------------------------------------------------
// Select random input sources for transaction.
@@ -3146,7 +3185,7 @@ bool wallet2::sign_tx(unsigned_tx_set &exported_txs, const std::string &signed_f
{
return false;
}
- LOG_PRINT_L2("Saving signed tx data: " << oss.str());
+ LOG_PRINT_L3("Saving signed tx data: " << oss.str());
return epee::file_io_utils::save_string_to_file(signed_filename, std::string(SIGNED_TX_PREFIX) + oss.str());
}
//----------------------------------------------------------------------------------------------------
@@ -3237,20 +3276,12 @@ uint64_t wallet2::get_fee_multiplier(uint32_t priority, bool use_new_fee) const
//----------------------------------------------------------------------------------------------------
uint64_t wallet2::get_dynamic_per_kb_fee_estimate()
{
- epee::json_rpc::request<cryptonote::COMMAND_RPC_GET_PER_KB_FEE_ESTIMATE::request> req_t = AUTO_VAL_INIT(req_t);
- epee::json_rpc::response<cryptonote::COMMAND_RPC_GET_PER_KB_FEE_ESTIMATE::response, std::string> resp_t = AUTO_VAL_INIT(resp_t);
-
- m_daemon_rpc_mutex.lock();
- req_t.jsonrpc = "2.0";
- req_t.id = epee::serialization::storage_entry(0);
- req_t.method = "get_fee_estimate";
- req_t.params.grace_blocks = FEE_ESTIMATE_GRACE_BLOCKS;
- bool r = net_utils::invoke_http_json_remote_command2(m_daemon_address + "/json_rpc", req_t, resp_t, m_http_client);
- m_daemon_rpc_mutex.unlock();
- CHECK_AND_ASSERT_THROW_MES(r, "Failed to connect to daemon");
- CHECK_AND_ASSERT_THROW_MES(resp_t.result.status != CORE_RPC_STATUS_BUSY, "Failed to connect to daemon");
- CHECK_AND_ASSERT_THROW_MES(resp_t.result.status == CORE_RPC_STATUS_OK, "Failed to get fee estimate");
- return resp_t.result.fee;
+ uint64_t fee;
+ boost::optional<std::string> result = m_node_rpc_proxy.get_dynamic_per_kb_fee_estimate(FEE_ESTIMATE_GRACE_BLOCKS, fee);
+ if (!result)
+ return fee;
+ LOG_PRINT_L1("Failed to query per kB fee, using " << print_money(FEE_PER_KB));
+ return FEE_PER_KB;
}
//----------------------------------------------------------------------------------------------------
uint64_t wallet2::get_per_kb_fee()
@@ -3258,15 +3289,8 @@ uint64_t wallet2::get_per_kb_fee()
bool use_dyn_fee = use_fork_rules(HF_VERSION_DYNAMIC_FEE, -720 * 1);
if (!use_dyn_fee)
return FEE_PER_KB;
- try
- {
- return get_dynamic_per_kb_fee_estimate();
- }
- catch (...)
- {
- LOG_PRINT_L1("Failed to query per kB fee, using " << print_money(FEE_PER_KB));
- return FEE_PER_KB;
- }
+
+ return get_dynamic_per_kb_fee_estimate();
}
//----------------------------------------------------------------------------------------------------
// separated the call(s) to wallet2::transfer into their own function
@@ -3378,8 +3402,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions(std::vector<crypto
}
}
-template<typename entry>
-void wallet2::get_outs(std::vector<std::vector<entry>> &outs, const std::list<size_t> &selected_transfers, size_t fake_outputs_count)
+void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs, const std::list<size_t> &selected_transfers, size_t fake_outputs_count)
{
LOG_PRINT_L2("fake_outputs_count: " << fake_outputs_count);
outs.clear();
@@ -3470,6 +3493,7 @@ void wallet2::get_outs(std::vector<std::vector<entry>> &outs, const std::list<si
uint64_t num_found = 1;
seen_indices.emplace(td.m_global_output_index);
req.outputs.push_back({amount, td.m_global_output_index});
+ LOG_PRINT_L1("Selecting real output: " << td.m_global_output_index << " for " << print_money(amount));
// while we still need more mixins
while (num_found < requested_outputs_count)
@@ -3541,7 +3565,7 @@ void wallet2::get_outs(std::vector<std::vector<entry>> &outs, const std::list<si
{
const transfer_details &td = m_transfers[idx];
size_t requested_outputs_count = base_requested_outputs_count + (td.is_rct() ? CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW - CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE : 0);
- outs.push_back(std::vector<entry>());
+ outs.push_back(std::vector<get_outs_entry>());
outs.back().reserve(fake_outputs_count + 1);
const rct::key mask = td.is_rct() ? rct::commit(td.amount(), td.m_mask) : rct::zeroCommit(td.amount());
@@ -3594,7 +3618,7 @@ void wallet2::get_outs(std::vector<std::vector<entry>> &outs, const std::list<si
else
{
// sort the subsection, so any spares are reset in order
- std::sort(outs.back().begin(), outs.back().end(), [](const entry &a, const entry &b) { return std::get<0>(a) < std::get<0>(b); });
+ std::sort(outs.back().begin(), outs.back().end(), [](const get_outs_entry &a, const get_outs_entry &b) { return std::get<0>(a) < std::get<0>(b); });
}
base += requested_outputs_count;
}
@@ -3605,7 +3629,7 @@ void wallet2::get_outs(std::vector<std::vector<entry>> &outs, const std::list<si
for (size_t idx: selected_transfers)
{
const transfer_details &td = m_transfers[idx];
- std::vector<entry> v;
+ std::vector<get_outs_entry> v;
const rct::key mask = td.is_rct() ? rct::commit(td.amount(), td.m_mask) : rct::zeroCommit(td.amount());
v.push_back(std::make_tuple(td.m_global_output_index, boost::get<txout_to_key>(td.m_tx.vout[td.m_internal_output_index].target).key, mask));
outs.push_back(v);
@@ -3614,7 +3638,8 @@ void wallet2::get_outs(std::vector<std::vector<entry>> &outs, const std::list<si
}
template<typename T>
-void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_entry>& dsts, const std::list<size_t> selected_transfers, size_t fake_outputs_count,
+void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_entry>& dsts, const std::list<size_t> selected_transfers, size_t fake_outputs_count,
+ std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs,
uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, T destination_split_strategy, const tx_dust_policy& dust_policy, cryptonote::transaction& tx, pending_tx &ptx)
{
using namespace cryptonote;
@@ -3644,11 +3669,11 @@ void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_ent
LOG_PRINT_L2("wanted " << print_money(needed_money) << ", found " << print_money(found_money) << ", fee " << print_money(fee));
THROW_WALLET_EXCEPTION_IF(found_money < needed_money, error::not_enough_money, found_money, needed_money - fee, fee);
- typedef std::tuple<uint64_t, crypto::public_key, rct::key> entry;
- std::vector<std::vector<entry>> outs;
- get_outs(outs, selected_transfers, fake_outputs_count); // may throw
+ if (outs.empty())
+ get_outs(outs, selected_transfers, fake_outputs_count); // may throw
//prepare inputs
+ LOG_PRINT_L2("preparing outputs");
typedef cryptonote::tx_source_entry::output_entry tx_output_entry;
size_t i = 0, out_index = 0;
std::vector<cryptonote::tx_source_entry> sources;
@@ -3691,6 +3716,7 @@ void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_ent
detail::print_source_entry(src);
++out_index;
}
+ LOG_PRINT_L2("outputs prepared");
cryptonote::tx_destination_entry change_dts = AUTO_VAL_INIT(change_dts);
if (needed_money < found_money)
@@ -3713,7 +3739,9 @@ void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_ent
}
crypto::secret_key tx_key;
+ LOG_PRINT_L2("constructing tx");
bool r = cryptonote::construct_tx_and_get_tx_key(m_account.get_keys(), sources, splitted_dsts, extra, tx, unlock_time, tx_key);
+ LOG_PRINT_L2("constructed tx, r="<<r);
THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sources, splitted_dsts, unlock_time, m_testnet);
THROW_WALLET_EXCEPTION_IF(upper_transaction_size_limit <= get_object_blobsize(tx), error::tx_too_big, tx, upper_transaction_size_limit);
@@ -3749,9 +3777,11 @@ void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_ent
ptx.construction_data.unlock_time = unlock_time;
ptx.construction_data.use_rct = false;
ptx.construction_data.dests = dsts;
+ LOG_PRINT_L2("transfer_selected done");
}
void wallet2::transfer_selected_rct(std::vector<cryptonote::tx_destination_entry> dsts, const std::list<size_t> selected_transfers, size_t fake_outputs_count,
+ std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs,
uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, cryptonote::transaction& tx, pending_tx &ptx)
{
using namespace cryptonote;
@@ -3760,7 +3790,7 @@ void wallet2::transfer_selected_rct(std::vector<cryptonote::tx_destination_entry
uint64_t upper_transaction_size_limit = get_upper_tranaction_size_limit();
uint64_t needed_money = fee;
- LOG_PRINT_L2("transfer: starting with fee " << print_money (needed_money));
+ LOG_PRINT_L2("transfer_selected_rct: starting with fee " << print_money (needed_money));
LOG_PRINT_L0("selected transfers: ");
for (auto t: selected_transfers)
LOG_PRINT_L2(" " << t);
@@ -3784,11 +3814,11 @@ void wallet2::transfer_selected_rct(std::vector<cryptonote::tx_destination_entry
LOG_PRINT_L2("wanted " << print_money(needed_money) << ", found " << print_money(found_money) << ", fee " << print_money(fee));
THROW_WALLET_EXCEPTION_IF(found_money < needed_money, error::not_enough_money, found_money, needed_money - fee, fee);
- typedef std::tuple<uint64_t, crypto::public_key, rct::key> entry;
- std::vector<std::vector<entry>> outs;
- get_outs(outs, selected_transfers, fake_outputs_count); // may throw
+ if (outs.empty())
+ get_outs(outs, selected_transfers, fake_outputs_count); // may throw
//prepare inputs
+ LOG_PRINT_L2("preparing outputs");
size_t i = 0, out_index = 0;
std::vector<cryptonote::tx_source_entry> sources;
BOOST_FOREACH(size_t idx, selected_transfers)
@@ -3831,6 +3861,7 @@ void wallet2::transfer_selected_rct(std::vector<cryptonote::tx_destination_entry
detail::print_source_entry(src);
++out_index;
}
+ LOG_PRINT_L2("outputs prepared");
// we still keep a copy, since we want to keep dsts free of change for user feedback purposes
std::vector<cryptonote::tx_destination_entry> splitted_dsts = dsts;
@@ -3842,9 +3873,11 @@ void wallet2::transfer_selected_rct(std::vector<cryptonote::tx_destination_entry
// the sender with a 0 amount output. We send a 0 amount in order to avoid
// letting the destination be able to work out which of the inputs is the
// real one in our rings
+ LOG_PRINT_L2("generating dummy address for 0 change");
cryptonote::account_base dummy;
dummy.generate();
change_dts.addr = dummy.get_keys().m_account_address;
+ LOG_PRINT_L2("generated dummy address for 0 change");
}
else
{
@@ -3853,10 +3886,13 @@ void wallet2::transfer_selected_rct(std::vector<cryptonote::tx_destination_entry
splitted_dsts.push_back(change_dts);
crypto::secret_key tx_key;
+ LOG_PRINT_L2("constructing tx");
bool r = cryptonote::construct_tx_and_get_tx_key(m_account.get_keys(), sources, splitted_dsts, extra, tx, unlock_time, tx_key, true);
+ LOG_PRINT_L2("constructed tx, r="<<r);
THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sources, dsts, unlock_time, m_testnet);
THROW_WALLET_EXCEPTION_IF(upper_transaction_size_limit <= get_object_blobsize(tx), error::tx_too_big, tx, upper_transaction_size_limit);
+ LOG_PRINT_L2("gathering key images");
std::string key_images;
bool all_are_txin_to_key = std::all_of(tx.vin.begin(), tx.vin.end(), [&](const txin_v& s_e) -> bool
{
@@ -3865,6 +3901,7 @@ void wallet2::transfer_selected_rct(std::vector<cryptonote::tx_destination_entry
return true;
});
THROW_WALLET_EXCEPTION_IF(!all_are_txin_to_key, error::unexpected_txin_type, tx);
+ LOG_PRINT_L2("gathered key images");
ptx.key_images = key_images;
ptx.fee = fee;
@@ -3883,6 +3920,7 @@ void wallet2::transfer_selected_rct(std::vector<cryptonote::tx_destination_entry
ptx.construction_data.unlock_time = unlock_time;
ptx.construction_data.use_rct = true;
ptx.construction_data.dests = dsts;
+ LOG_PRINT_L2("transfer_selected_rct done");
}
static size_t estimate_rct_tx_size(int n_inputs, int mixin, int n_outputs)
@@ -4084,12 +4122,14 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
accumulated_change = 0;
adding_fee = false;
needed_fee = 0;
+ std::vector<std::vector<tools::wallet2::get_outs_entry>> outs;
// for rct, since we don't see the amounts, we will try to make all transactions
// look the same, with 1 or 2 inputs, and 2 outputs. One input is preferable, as
// this prevents linking to another by provenance analysis, but two is ok if we
// try to pick outputs not from the same block. We will get two outputs, one for
// the destination, and one for change.
+ LOG_PRINT_L2("checking preferred");
std::vector<size_t> prefered_inputs;
uint64_t rct_outs_needed = 2 * (fake_outs_count + 1);
rct_outs_needed += 100; // some fudge factor since we don't know how many are locked
@@ -4106,9 +4146,13 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
LOG_PRINT_L1("Found prefered rct inputs for rct tx: " << s);
}
}
+ LOG_PRINT_L2("done checking preferred");
- // while we have something to send
- while ((!dsts.empty() && dsts[0].amount > 0) || adding_fee) {
+ // while:
+ // - we have something to send
+ // - or we need to gather more fee
+ // - or we have just one input in that tx, which is rct (to try and make all/most rct txes 2/2)
+ while ((!dsts.empty() && dsts[0].amount > 0) || adding_fee || (use_rct && txes.back().selected_transfers.size() == 1)) {
TX &tx = txes.back();
// if we need to spend money and don't have any left, we fail
@@ -4119,7 +4163,14 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
// get a random unspent output and use it to pay part (or all) of the current destination (and maybe next one, etc)
// This could be more clever, but maybe at the cost of making probabilistic inferences easier
- size_t idx = !prefered_inputs.empty() ? pop_back(prefered_inputs) : !unused_transfers_indices.empty() ? pop_best_value(unused_transfers_indices, tx.selected_transfers) : pop_best_value(unused_dust_indices, tx.selected_transfers);
+ size_t idx;
+ if ((dsts.empty() || dsts[0].amount == 0) && !adding_fee)
+ // the "make rct txes 2/2" case - we pick a small value output to "clean up" the wallet too
+ idx = pop_best_value(unused_dust_indices.empty() ? unused_transfers_indices : unused_dust_indices, tx.selected_transfers, true);
+ else if (!prefered_inputs.empty())
+ idx = pop_back(prefered_inputs);
+ else
+ idx = pop_best_value(unused_transfers_indices.empty() ? unused_dust_indices : unused_transfers_indices, tx.selected_transfers);
const transfer_details &td = m_transfers[idx];
LOG_PRINT_L2("Picking output " << idx << ", amount " << print_money(td.amount()) << ", ki " << td.m_key_image);
@@ -4129,6 +4180,9 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
uint64_t available_amount = td.amount();
accumulated_outputs += available_amount;
+ // clear any fake outs we'd already gathered, since we'll need a new set
+ outs.clear();
+
if (adding_fee)
{
LOG_PRINT_L2("We need more fee, adding it to fee");
@@ -4185,10 +4239,10 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
LOG_PRINT_L2("Trying to create a tx now, with " << tx.dsts.size() << " destinations and " <<
tx.selected_transfers.size() << " outputs");
if (use_rct)
- transfer_selected_rct(tx.dsts, tx.selected_transfers, fake_outs_count, unlock_time, needed_fee, extra,
+ transfer_selected_rct(tx.dsts, tx.selected_transfers, fake_outs_count, outs, unlock_time, needed_fee, extra,
test_tx, test_ptx);
else
- transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, unlock_time, needed_fee, extra,
+ transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, outs, unlock_time, needed_fee, extra,
detail::digit_split_strategy, tx_dust_policy(::config::DEFAULT_DUST_THRESHOLD), test_tx, test_ptx);
auto txBlob = t_serializable_object_to_blob(test_ptx.tx);
needed_fee = calculate_fee(fee_per_kb, txBlob, fee_multiplier);
@@ -4226,13 +4280,19 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
else
{
LOG_PRINT_L2("We made a tx, adjusting fee and saving it");
- if (use_rct)
- transfer_selected_rct(tx.dsts, tx.selected_transfers, fake_outs_count, unlock_time, needed_fee, extra,
- test_tx, test_ptx);
- else
- transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, unlock_time, needed_fee, extra,
- detail::digit_split_strategy, tx_dust_policy(::config::DEFAULT_DUST_THRESHOLD), test_tx, test_ptx);
- txBlob = t_serializable_object_to_blob(test_ptx.tx);
+ do {
+ if (use_rct)
+ transfer_selected_rct(tx.dsts, tx.selected_transfers, fake_outs_count, outs, unlock_time, needed_fee, extra,
+ test_tx, test_ptx);
+ else
+ transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, outs, unlock_time, needed_fee, extra,
+ detail::digit_split_strategy, tx_dust_policy(::config::DEFAULT_DUST_THRESHOLD), test_tx, test_ptx);
+ txBlob = t_serializable_object_to_blob(test_ptx.tx);
+ needed_fee = calculate_fee(fee_per_kb, txBlob, fee_multiplier);
+ LOG_PRINT_L2("Made an attempt at a final " << ((txBlob.size() + 1023)/1024) << " kB tx, with " << print_money(test_ptx.fee) <<
+ " fee and " << print_money(test_ptx.change_dts.amount) << " change");
+ } while (needed_fee > test_ptx.fee);
+
LOG_PRINT_L2("Made a final " << ((txBlob.size() + 1023)/1024) << " kB tx, with " << print_money(test_ptx.fee) <<
" fee and " << print_money(test_ptx.change_dts.amount) << " change");
@@ -4313,6 +4373,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_from(const crypton
std::vector<TX> txes;
uint64_t needed_fee, available_for_fee = 0;
uint64_t upper_transaction_size_limit = get_upper_tranaction_size_limit();
+ std::vector<std::vector<get_outs_entry>> outs;
const bool use_rct = fake_outs_count > 0 && use_fork_rules(4, 0);
const bool use_new_fee = use_fork_rules(3, -720 * 14);
@@ -4348,6 +4409,9 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_from(const crypton
uint64_t available_amount = td.amount();
accumulated_outputs += available_amount;
+ // clear any fake outs we'd already gathered, since we'll need a new set
+ outs.clear();
+
// here, check if we need to sent tx and start a new one
LOG_PRINT_L2("Considering whether to create a tx now, " << tx.selected_transfers.size() << " inputs, tx limit "
<< upper_transaction_size_limit);
@@ -4369,10 +4433,10 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_from(const crypton
LOG_PRINT_L2("Trying to create a tx now, with " << tx.dsts.size() << " destinations and " <<
tx.selected_transfers.size() << " outputs");
if (use_rct)
- transfer_selected_rct(tx.dsts, tx.selected_transfers, fake_outs_count, unlock_time, needed_fee, extra,
+ transfer_selected_rct(tx.dsts, tx.selected_transfers, fake_outs_count, outs, unlock_time, needed_fee, extra,
test_tx, test_ptx);
else
- transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, unlock_time, needed_fee, extra,
+ transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, outs, unlock_time, needed_fee, extra,
detail::digit_split_strategy, tx_dust_policy(::config::DEFAULT_DUST_THRESHOLD), test_tx, test_ptx);
auto txBlob = t_serializable_object_to_blob(test_ptx.tx);
needed_fee = calculate_fee(fee_per_kb, txBlob, fee_multiplier);
@@ -4386,10 +4450,10 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_from(const crypton
LOG_PRINT_L2("We made a tx, adjusting fee and saving it");
tx.dsts[0].amount = available_for_fee - needed_fee;
if (use_rct)
- transfer_selected_rct(tx.dsts, tx.selected_transfers, fake_outs_count, unlock_time, needed_fee, extra,
+ transfer_selected_rct(tx.dsts, tx.selected_transfers, fake_outs_count, outs, unlock_time, needed_fee, extra,
test_tx, test_ptx);
else
- transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, unlock_time, needed_fee, extra,
+ transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, outs, unlock_time, needed_fee, extra,
detail::digit_split_strategy, tx_dust_policy(::config::DEFAULT_DUST_THRESHOLD), test_tx, test_ptx);
txBlob = t_serializable_object_to_blob(test_ptx.tx);
needed_fee = calculate_fee(fee_per_kb, txBlob, fee_multiplier);
@@ -4451,39 +4515,19 @@ uint64_t wallet2::unlocked_dust_balance(const tx_dust_policy &dust_policy) const
//----------------------------------------------------------------------------------------------------
void wallet2::get_hard_fork_info(uint8_t version, uint64_t &earliest_height)
{
- epee::json_rpc::request<cryptonote::COMMAND_RPC_HARD_FORK_INFO::request> req_t = AUTO_VAL_INIT(req_t);
- epee::json_rpc::response<cryptonote::COMMAND_RPC_HARD_FORK_INFO::response, std::string> resp_t = AUTO_VAL_INIT(resp_t);
-
- m_daemon_rpc_mutex.lock();
- req_t.jsonrpc = "2.0";
- req_t.id = epee::serialization::storage_entry(0);
- req_t.method = "hard_fork_info";
- req_t.params.version = version;
- bool r = net_utils::invoke_http_json_remote_command2(m_daemon_address + "/json_rpc", req_t, resp_t, m_http_client);
- m_daemon_rpc_mutex.unlock();
- CHECK_AND_ASSERT_THROW_MES(r, "Failed to connect to daemon");
- CHECK_AND_ASSERT_THROW_MES(resp_t.result.status != CORE_RPC_STATUS_BUSY, "Failed to connect to daemon");
- CHECK_AND_ASSERT_THROW_MES(resp_t.result.status == CORE_RPC_STATUS_OK, "Failed to get hard fork status");
-
- earliest_height = resp_t.result.earliest_height;
+ boost::optional<std::string> result = m_node_rpc_proxy.get_earliest_height(version, earliest_height);
+ throw_on_rpc_response_error(result, "get_hard_fork_info");
}
//----------------------------------------------------------------------------------------------------
bool wallet2::use_fork_rules(uint8_t version, int64_t early_blocks)
{
- cryptonote::COMMAND_RPC_GET_HEIGHT::request req = AUTO_VAL_INIT(req);
- cryptonote::COMMAND_RPC_GET_HEIGHT::response res = AUTO_VAL_INIT(res);
-
- m_daemon_rpc_mutex.lock();
- bool r = net_utils::invoke_http_json_remote_command2(m_daemon_address + "/getheight", req, res, m_http_client);
- m_daemon_rpc_mutex.unlock();
- CHECK_AND_ASSERT_MES(r, false, "Failed to connect to daemon");
- CHECK_AND_ASSERT_MES(res.status != CORE_RPC_STATUS_BUSY, false, "Failed to connect to daemon");
- CHECK_AND_ASSERT_MES(res.status == CORE_RPC_STATUS_OK, false, "Failed to get current blockchain height");
+ uint64_t height, earliest_height;
+ boost::optional<std::string> result = m_node_rpc_proxy.get_height(height);
+ throw_on_rpc_response_error(result, "get_info");
+ result = m_node_rpc_proxy.get_earliest_height(version, earliest_height);
+ throw_on_rpc_response_error(result, "get_hard_fork_info");
- uint64_t earliest_height;
- get_hard_fork_info(version, earliest_height); // can throw
-
- bool close_enough = res.height >= earliest_height - early_blocks; // start using the rules that many blocks beforehand
+ bool close_enough = height >= earliest_height - early_blocks; // start using the rules that many blocks beforehand
if (close_enough)
LOG_PRINT_L2("Using v" << (unsigned)version << " rules");
else
@@ -4672,34 +4716,17 @@ std::string wallet2::get_daemon_address() const
uint64_t wallet2::get_daemon_blockchain_height(string &err)
{
- // XXX: DRY violation. copy-pasted from simplewallet.cpp:get_daemon_blockchain_height()
- // consider to move it from simplewallet to wallet2 ?
- COMMAND_RPC_GET_HEIGHT::request req;
- COMMAND_RPC_GET_HEIGHT::response res = boost::value_initialized<COMMAND_RPC_GET_HEIGHT::response>();
- m_daemon_rpc_mutex.lock();
- bool ok = net_utils::invoke_http_json_remote_command2(m_daemon_address + "/getheight", req, res, m_http_client);
- m_daemon_rpc_mutex.unlock();
- // XXX: DRY violation. copy-pasted from simplewallet.cpp:interpret_rpc_response()
- if (ok)
- {
- if (res.status == CORE_RPC_STATUS_BUSY)
- {
- err = "daemon is busy. Please try again later.";
- }
- else if (res.status != CORE_RPC_STATUS_OK)
- {
- err = res.status;
- }
- else // success, cleaning up error message
- {
- err = "";
- }
- }
- else
+ uint64_t height;
+
+ boost::optional<std::string> result = m_node_rpc_proxy.get_height(height);
+ if (result)
{
- err = "possibly lost connection to daemon";
+ err = *result;
+ return 0;
}
- return res.height;
+
+ err = "";
+ return height;
}
uint64_t wallet2::get_daemon_blockchain_target_height(string &err)
@@ -4841,6 +4868,27 @@ crypto::public_key wallet2::get_tx_pub_key_from_received_outs(const tools::walle
"Public key yielding at least one output wasn't found in the transaction extra");
return cryptonote::null_pkey;
}
+
+bool wallet2::export_key_images(const std::string filename)
+{
+ std::vector<std::pair<crypto::key_image, crypto::signature>> ski = export_key_images();
+ std::string magic(KEY_IMAGE_EXPORT_FILE_MAGIC, strlen(KEY_IMAGE_EXPORT_FILE_MAGIC));
+ const cryptonote::account_public_address &keys = get_account().get_keys().m_account_address;
+
+ std::string data;
+ data += std::string((const char *)&keys.m_spend_public_key, sizeof(crypto::public_key));
+ data += std::string((const char *)&keys.m_view_public_key, sizeof(crypto::public_key));
+ for (const auto &i: ski)
+ {
+ data += std::string((const char *)&i.first, sizeof(crypto::key_image));
+ data += std::string((const char *)&i.second, sizeof(crypto::signature));
+ }
+
+ // encrypt data, keep magic plaintext
+ std::string ciphertext = encrypt_with_view_secret_key(data);
+ return epee::file_io_utils::save_string_to_file(filename, magic + ciphertext);
+}
+
//----------------------------------------------------------------------------------------------------
std::vector<std::pair<crypto::key_image, crypto::signature>> wallet2::export_key_images() const
{
@@ -4891,6 +4939,70 @@ std::vector<std::pair<crypto::key_image, crypto::signature>> wallet2::export_key
}
return ski;
}
+
+uint64_t wallet2::import_key_images(const std::string &filename, uint64_t &spent, uint64_t &unspent)
+{
+ std::string data;
+ bool r = epee::file_io_utils::load_file_to_string(filename, data);
+
+ if (!r)
+ {
+ fail_msg_writer() << tr("failed to read file ") << filename;
+ return 0;
+ }
+ const size_t magiclen = strlen(KEY_IMAGE_EXPORT_FILE_MAGIC);
+ if (data.size() < magiclen || memcmp(data.data(), KEY_IMAGE_EXPORT_FILE_MAGIC, magiclen))
+ {
+ fail_msg_writer() << "Bad key image export file magic in " << filename;
+ return 0;
+ }
+
+ try
+ {
+ data = decrypt_with_view_secret_key(std::string(data, magiclen));
+ }
+ catch (const std::exception &e)
+ {
+ fail_msg_writer() << "Failed to decrypt " << filename << ": " << e.what();
+ return 0;
+ }
+
+ const size_t headerlen = 2 * sizeof(crypto::public_key);
+ if (data.size() < headerlen)
+ {
+ fail_msg_writer() << "Bad data size from file " << filename;
+ return 0;
+ }
+ const crypto::public_key &public_spend_key = *(const crypto::public_key*)&data[0];
+ const crypto::public_key &public_view_key = *(const crypto::public_key*)&data[sizeof(crypto::public_key)];
+ const cryptonote::account_public_address &keys = get_account().get_keys().m_account_address;
+ if (public_spend_key != keys.m_spend_public_key || public_view_key != keys.m_view_public_key)
+ {
+ fail_msg_writer() << "Key images from " << filename << " are for a different account";
+ return 0;
+ }
+
+ const size_t record_size = sizeof(crypto::key_image) + sizeof(crypto::signature);
+ if ((data.size() - headerlen) % record_size)
+ {
+ fail_msg_writer() << "Bad data size from file " << filename;
+ return 0;
+ }
+ size_t nki = (data.size() - headerlen) / record_size;
+
+ std::vector<std::pair<crypto::key_image, crypto::signature>> ski;
+ ski.reserve(nki);
+ for (size_t n = 0; n < nki; ++n)
+ {
+ crypto::key_image key_image = *reinterpret_cast<const crypto::key_image*>(&data[headerlen + n * record_size]);
+ crypto::signature signature = *reinterpret_cast<const crypto::signature*>(&data[headerlen + n * record_size + sizeof(crypto::key_image)]);
+
+ ski.push_back(std::make_pair(key_image, signature));
+ }
+
+ return import_key_images(ski, spent, unspent);
+}
+
//----------------------------------------------------------------------------------------------------
uint64_t wallet2::import_key_images(const std::vector<std::pair<crypto::key_image, crypto::signature>> &signed_key_images, uint64_t &spent, uint64_t &unspent)
{
@@ -5030,7 +5142,7 @@ std::string wallet2::encrypt(const std::string &plaintext, const crypto::secret_
crypto::signature &signature = *(crypto::signature*)&ciphertext[ciphertext.size() - sizeof(crypto::signature)];
crypto::generate_signature(hash, pkey, skey, signature);
}
- return std::move(ciphertext);
+ return ciphertext;
}
//----------------------------------------------------------------------------------------------------
std::string wallet2::encrypt_with_view_secret_key(const std::string &plaintext, bool authenticated) const
@@ -5060,7 +5172,7 @@ std::string wallet2::decrypt(const std::string &ciphertext, const crypto::secret
error::wallet_internal_error, "Failed to authenticate criphertext");
}
crypto::chacha8(ciphertext.data() + sizeof(iv), ciphertext.size() - prefix_size, key, iv, &plaintext[0]);
- return std::move(plaintext);
+ return plaintext;
}
//----------------------------------------------------------------------------------------------------
std::string wallet2::decrypt_with_view_secret_key(const std::string &ciphertext, bool authenticated) const
@@ -5098,7 +5210,7 @@ std::string wallet2::make_uri(const std::string &address, const std::string &pay
}
std::string uri = "monero:" + address;
- bool n_fields = 0;
+ unsigned int n_fields = 0;
if (!payment_id.empty())
{
@@ -5210,6 +5322,92 @@ bool wallet2::parse_uri(const std::string &uri, std::string &address, std::strin
return true;
}
//----------------------------------------------------------------------------------------------------
+uint64_t wallet2::get_blockchain_height_by_date(uint16_t year, uint8_t month, uint8_t day)
+{
+ uint32_t version;
+ if (!check_connection(&version))
+ {
+ throw std::runtime_error("failed to connect to daemon: " + get_daemon_address());
+ }
+ if (version < MAKE_CORE_RPC_VERSION(1, 6))
+ {
+ throw std::runtime_error("this function requires RPC version 1.6 or higher");
+ }
+ std::tm date = { 0, 0, 0, 0, 0, 0, 0, 0 };
+ date.tm_year = year - 1900;
+ date.tm_mon = month - 1;
+ date.tm_mday = day;
+ if (date.tm_mon < 0 || 11 < date.tm_mon || date.tm_mday < 1 || 31 < date.tm_mday)
+ {
+ throw std::runtime_error("month or day out of range");
+ }
+ uint64_t timestamp_target = std::mktime(&date);
+ std::string err;
+ uint64_t height_min = 0;
+ uint64_t height_max = get_daemon_blockchain_height(err) - 1;
+ if (!err.empty())
+ {
+ throw std::runtime_error("failed to get blockchain height");
+ }
+ while (true)
+ {
+ COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::request req;
+ COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::response res;
+ uint64_t height_mid = (height_min + height_max) / 2;
+ req.heights =
+ {
+ height_min,
+ height_mid,
+ height_max
+ };
+ bool r = net_utils::invoke_http_bin_remote_command2(get_daemon_address() + "/getblocks_by_height.bin", req, res, m_http_client);
+ if (!r || res.status != CORE_RPC_STATUS_OK)
+ {
+ std::ostringstream oss;
+ oss << "failed to get blocks by heights: ";
+ for (auto height : req.heights)
+ oss << height << ' ';
+ oss << endl << "reason: ";
+ if (!r)
+ oss << "possibly lost connection to daemon";
+ else if (res.status == CORE_RPC_STATUS_BUSY)
+ oss << "daemon is busy";
+ else
+ oss << res.status;
+ throw std::runtime_error(oss.str());
+ }
+ cryptonote::block blk_min, blk_mid, blk_max;
+ if (!parse_and_validate_block_from_blob(res.blocks[0].block, blk_min)) throw std::runtime_error("failed to parse blob at height " + height_min);
+ if (!parse_and_validate_block_from_blob(res.blocks[1].block, blk_mid)) throw std::runtime_error("failed to parse blob at height " + height_mid);
+ if (!parse_and_validate_block_from_blob(res.blocks[2].block, blk_max)) throw std::runtime_error("failed to parse blob at height " + height_max);
+ uint64_t timestamp_min = blk_min.timestamp;
+ uint64_t timestamp_mid = blk_mid.timestamp;
+ uint64_t timestamp_max = blk_max.timestamp;
+ if (!(timestamp_min <= timestamp_mid && timestamp_mid <= timestamp_max))
+ {
+ // the timestamps are not in the chronological order.
+ // assuming they're sufficiently close to each other, simply return the smallest height
+ return std::min({height_min, height_mid, height_max});
+ }
+ if (timestamp_target > timestamp_max)
+ {
+ throw std::runtime_error("specified date is in the future");
+ }
+ if (timestamp_target <= timestamp_min + 2 * 24 * 60 * 60) // two days of "buffer" period
+ {
+ return height_min;
+ }
+ if (timestamp_target <= timestamp_mid)
+ height_max = height_mid;
+ else
+ height_min = height_mid;
+ if (height_max - height_min <= 2 * 24 * 30) // don't divide the height range finer than two days
+ {
+ return height_min;
+ }
+ }
+}
+//----------------------------------------------------------------------------------------------------
void wallet2::generate_genesis(cryptonote::block& b) {
if (m_testnet)
{
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index 5883102bc..629011800 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -54,8 +54,13 @@
#include "wallet_errors.h"
#include "password_container.h"
+#include "node_rpc_proxy.h"
#include <iostream>
+
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "wallet.wallet2"
+
#define WALLET_RCP_CONNECTION_TIMEOUT 200000
class Serialization_portability_wallet_Test;
@@ -99,7 +104,7 @@ namespace tools
};
private:
- wallet2(const wallet2&) : m_run(true), m_callback(0), m_testnet(false), m_always_confirm_transfers(true), m_print_ring_members(false), m_store_tx_info(true), m_default_mixin(0), m_default_priority(0), m_refresh_type(RefreshOptimizeCoinbase), m_auto_refresh(true), m_refresh_from_block_height(0), m_confirm_missing_payment_id(true) {}
+ wallet2(const wallet2&) : m_run(true), m_callback(0), m_testnet(false), m_always_confirm_transfers(true), m_print_ring_members(false), m_store_tx_info(true), m_default_mixin(0), m_default_priority(0), m_refresh_type(RefreshOptimizeCoinbase), m_auto_refresh(true), m_refresh_from_block_height(0), m_confirm_missing_payment_id(true), m_node_rpc_proxy(m_http_client, m_daemon_rpc_mutex) {}
public:
static const char* tr(const char* str);// { return i18n_translate(str, "cryptonote::simple_wallet"); }
@@ -120,7 +125,7 @@ namespace tools
//! Uses stdin and stdout. Returns a wallet2 and password for wallet with no file if no errors.
static std::pair<std::unique_ptr<wallet2>, password_container> make_new(const boost::program_options::variables_map& vm);
- wallet2(bool testnet = false, bool restricted = false) : m_run(true), m_callback(0), m_testnet(testnet), m_always_confirm_transfers(true), m_print_ring_members(false), m_store_tx_info(true), m_default_mixin(0), m_default_priority(0), m_refresh_type(RefreshOptimizeCoinbase), m_auto_refresh(true), m_refresh_from_block_height(0), m_confirm_missing_payment_id(true), m_restricted(restricted), is_old_file_format(false) {}
+ wallet2(bool testnet = false, bool restricted = false) : m_run(true), m_callback(0), m_testnet(testnet), m_always_confirm_transfers(true), m_print_ring_members(false), m_store_tx_info(true), m_default_mixin(0), m_default_priority(0), m_refresh_type(RefreshOptimizeCoinbase), m_auto_refresh(true), m_refresh_from_block_height(0), m_confirm_missing_payment_id(true), m_restricted(restricted), is_old_file_format(false), m_node_rpc_proxy(m_http_client, m_daemon_rpc_mutex) {}
struct transfer_details
{
uint64_t m_block_height;
@@ -271,6 +276,8 @@ namespace tools
std::string m_description;
};
+ typedef std::tuple<uint64_t, crypto::public_key, rct::key> get_outs_entry;
+
/*!
* \brief Generates a wallet or restores one.
* \param wallet_ Name of wallet file
@@ -383,8 +390,10 @@ namespace tools
void transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, const size_t fake_outputs_count, const std::vector<size_t> &unused_transfers_indices, uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, cryptonote::transaction& tx, pending_tx& ptx, bool trusted_daemon);
template<typename T>
void transfer_selected(const std::vector<cryptonote::tx_destination_entry>& dsts, const std::list<size_t> selected_transfers, size_t fake_outputs_count,
+ std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs,
uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, T destination_split_strategy, const tx_dust_policy& dust_policy, cryptonote::transaction& tx, pending_tx &ptx);
void transfer_selected_rct(std::vector<cryptonote::tx_destination_entry> dsts, const std::list<size_t> selected_transfers, size_t fake_outputs_count,
+ std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs,
uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, cryptonote::transaction& tx, pending_tx &ptx);
void commit_tx(pending_tx& ptx_vector);
@@ -402,7 +411,7 @@ namespace tools
std::vector<wallet2::pending_tx> create_transactions_all(const cryptonote::account_public_address &address, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t> extra, bool trusted_daemon);
std::vector<wallet2::pending_tx> create_transactions_from(const cryptonote::account_public_address &address, std::vector<size_t> unused_transfers_indices, std::vector<size_t> unused_dust_indices, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t> extra, bool trusted_daemon);
std::vector<pending_tx> create_unmixable_sweep_transactions(bool trusted_daemon);
- bool check_connection(uint32_t *version = NULL);
+ bool check_connection(uint32_t *version = NULL, uint32_t timeout = 200000);
void get_transfers(wallet2::transfer_container& incoming_transfers) const;
void get_payments(const crypto::hash& payment_id, std::list<wallet2::payment_details>& payments, uint64_t min_height = 0) const;
void get_payments(std::list<std::pair<crypto::hash,wallet2::payment_details>>& payments, uint64_t min_height, uint64_t max_height = (uint64_t)-1) const;
@@ -527,8 +536,8 @@ namespace tools
std::vector<size_t> select_available_unmixable_outputs(bool trusted_daemon);
std::vector<size_t> select_available_mixable_outputs(bool trusted_daemon);
- size_t pop_best_value_from(const transfer_container &transfers, std::vector<size_t> &unused_dust_indices, const std::list<size_t>& selected_transfers) const;
- size_t pop_best_value(std::vector<size_t> &unused_dust_indices, const std::list<size_t>& selected_transfers) const;
+ size_t pop_best_value_from(const transfer_container &transfers, std::vector<size_t> &unused_dust_indices, const std::list<size_t>& selected_transfers, bool smallest = false) const;
+ size_t pop_best_value(std::vector<size_t> &unused_dust_indices, const std::list<size_t>& selected_transfers, bool smallest = false) const;
void set_tx_note(const crypto::hash &txid, const std::string &note);
std::string get_tx_note(const crypto::hash &txid) const;
@@ -539,8 +548,10 @@ namespace tools
std::vector<tools::wallet2::transfer_details> export_outputs() const;
size_t import_outputs(const std::vector<tools::wallet2::transfer_details> &outputs);
+ bool export_key_images(const std::string filename);
std::vector<std::pair<crypto::key_image, crypto::signature>> export_key_images() const;
uint64_t import_key_images(const std::vector<std::pair<crypto::key_image, crypto::signature>> &signed_key_images, uint64_t &spent, uint64_t &unspent);
+ uint64_t import_key_images(const std::string &filename, uint64_t &spent, uint64_t &unspent);
void update_pool_state();
@@ -552,6 +563,8 @@ namespace tools
std::string make_uri(const std::string &address, const std::string &payment_id, uint64_t amount, const std::string &tx_description, const std::string &recipient_name, std::string &error);
bool parse_uri(const std::string &uri, std::string &address, std::string &payment_id, uint64_t &amount, std::string &tx_description, std::string &recipient_name, std::vector<std::string> &unknown_parameters, std::string &error);
+ uint64_t get_blockchain_height_by_date(uint16_t year, uint8_t month, uint8_t day); // 1<=month<=12, 1<=day<=31
+
private:
/*!
* \brief Stores wallet information to wallet file.
@@ -599,8 +612,7 @@ namespace tools
std::vector<size_t> pick_preferred_rct_inputs(uint64_t needed_money) const;
void set_spent(size_t idx, uint64_t height);
void set_unspent(size_t idx);
- template<typename entry>
- void get_outs(std::vector<std::vector<entry>> &outs, const std::list<size_t> &selected_transfers, size_t fake_outputs_count);
+ void get_outs(std::vector<std::vector<get_outs_entry>> &outs, const std::list<size_t> &selected_transfers, size_t fake_outputs_count);
bool wallet_generate_key_image_helper(const cryptonote::account_keys& ack, const crypto::public_key& tx_public_key, size_t real_output_index, cryptonote::keypair& in_ephemeral, crypto::key_image& ki);
crypto::public_key get_tx_pub_key_from_received_outs(const tools::wallet2::transfer_details &td) const;
@@ -644,6 +656,7 @@ namespace tools
bool m_auto_refresh;
uint64_t m_refresh_from_block_height;
bool m_confirm_missing_payment_id;
+ NodeRPCProxy m_node_rpc_proxy;
};
}
BOOST_CLASS_VERSION(tools::wallet2, 16)
diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h
index daffb48bf..5a13205c5 100644
--- a/src/wallet/wallet2_api.h
+++ b/src/wallet/wallet2_api.h
@@ -513,6 +513,21 @@ struct Wallet
*/
virtual void disposeTransaction(PendingTransaction * t) = 0;
+ /*!
+ * \brief exportKeyImages - exports key images to file
+ * \param filename
+ * \return - true on success
+ */
+ virtual bool exportKeyImages(const std::string &filename) = 0;
+
+ /*!
+ * \brief importKeyImages - imports key images from file
+ * \param filename
+ * \return - true on success
+ */
+ virtual bool importKeyImages(const std::string &filename) = 0;
+
+
virtual TransactionHistory * history() const = 0;
virtual AddressBook * addressBook() const = 0;
virtual void setListener(WalletListener *) = 0;
@@ -558,6 +573,11 @@ struct Wallet
virtual bool verifySignedMessage(const std::string &message, const std::string &addres, const std::string &signature) const = 0;
virtual bool parse_uri(const std::string &uri, std::string &address, std::string &payment_id, uint64_t &amount, std::string &tx_description, std::string &recipient_name, std::vector<std::string> &unknown_parameters, std::string &error) = 0;
+ /*
+ * \brief rescanSpent - Rescan spent outputs - Can only be used with trusted daemon
+ * \return true on success
+ */
+ virtual bool rescanSpent() = 0;
};
/**
diff --git a/src/wallet/wallet_args.cpp b/src/wallet/wallet_args.cpp
index f7eec8cfc..7ec4ad6e4 100644
--- a/src/wallet/wallet_args.cpp
+++ b/src/wallet/wallet_args.cpp
@@ -40,6 +40,9 @@
#include <crtdbg.h>
#endif
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "wallet.wallet2"
+
// workaround for a suspected bug in pthread/kernel on MacOS X
#ifdef __APPLE__
#define DEFAULT_MAX_CONCURRENCY 1
@@ -78,7 +81,7 @@ namespace wallet_args
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
- const command_line::arg_descriptor<uint32_t> arg_log_level = {"log-level", "", LOG_LEVEL_0};
+ const command_line::arg_descriptor<std::string> arg_log_level = {"log-level", "0-4 or categories", ""};
const command_line::arg_descriptor<uint32_t> arg_max_concurrency = {"max-concurrency", wallet_args::tr("Max number of threads to use for a parallel job"), DEFAULT_MAX_CONCURRENCY};
const command_line::arg_descriptor<std::string> arg_log_file = {"log-file", wallet_args::tr("Specify log file"), ""};
@@ -93,26 +96,7 @@ namespace wallet_args
command_line::add_arg(desc_general, command_line::arg_help);
command_line::add_arg(desc_general, command_line::arg_version);
-
- bf::path default_log {epee::log_space::log_singletone::get_default_log_folder()};
- std::string log_file_name = epee::log_space::log_singletone::get_default_log_file();
- if (log_file_name.empty())
- {
- // Sanity check: File path should also be empty if file name is. If not,
- // this would be a problem in epee's discovery of current process's file
- // path.
- if (! default_log.empty())
- {
- tools::fail_msg_writer() << wallet_args::tr("unexpected empty log file name in presence of non-empty file path");
- return boost::none;
- }
- // epee didn't find path to executable from argv[0], so use this default file name.
- log_file_name = "monero-wallet-cli.log";
- // The full path will use cwd because epee also returned an empty default log folder.
- }
- default_log /= log_file_name;
-
- command_line::add_arg(desc_params, arg_log_file, default_log.string());
+ command_line::add_arg(desc_params, arg_log_file, "");
command_line::add_arg(desc_params, arg_log_level);
command_line::add_arg(desc_params, arg_max_concurrency);
@@ -146,39 +130,28 @@ namespace wallet_args
if (!r)
return boost::none;
- // log_file_path
- // default: < argv[0] directory >/monero-wallet-cli.log
- // so if ran as "monero-wallet-cli" (no path), log file will be in cwd
- //
- // if log-file argument given:
- // absolute path
- // relative path: relative to cwd
-
- // Set log file
- bf::path log_file_path {bf::absolute(command_line::get_arg(vm, arg_log_file))};
-
- // Set up logging options
- int log_level = LOG_LEVEL_2;
- epee::log_space::get_set_log_detalisation_level(true, log_level);
- //epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_0);
- epee::log_space::log_singletone::add_logger(LOGGER_FILE,
- log_file_path.filename().string().c_str(),
- log_file_path.parent_path().string().c_str(),
- LOG_LEVEL_4
- );
-
if(command_line::has_arg(vm, arg_max_concurrency))
tools::set_max_concurrency(command_line::get_arg(vm, arg_max_concurrency));
- tools::scoped_message_writer(epee::log_space::console_color_white, true) << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")";
+ std::string log_path;
+ if (!vm["log-file"].defaulted())
+ log_path = command_line::get_arg(vm, arg_log_file);
+ else
+ log_path = mlog_get_default_log_path("monero-wallet-cli,log");
+ mlog_configure(log_path, false);
+ if (!vm["log-level"].defaulted())
+ {
+ mlog_set_log(command_line::get_arg(vm, arg_log_level).c_str());
+ }
+
+ tools::scoped_message_writer(epee::console_color_white, true) << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")";
- if(command_line::has_arg(vm, arg_log_level))
- log_level = command_line::get_arg(vm, arg_log_level);
- LOG_PRINT_L0("Setting log level = " << log_level);
- LOG_PRINT_L0(wallet_args::tr("default_log: ") << default_log.string());
- tools::scoped_message_writer(epee::log_space::console_color_white, true) << boost::format(wallet_args::tr("Logging at log level %d to %s")) %
- log_level % log_file_path.string();
- epee::log_space::get_set_log_detalisation_level(true, log_level);
+ if (!vm["log-level"].defaulted())
+ MINFO("Setting log level = " << command_line::get_arg(vm, arg_log_level));
+ else
+ MINFO("Setting log levels = " << getenv("MONERO_LOGS"));
+ MINFO(wallet_args::tr("Logging to: ") << log_path);
+ tools::scoped_message_writer(epee::console_color_white, true) << boost::format(wallet_args::tr("Logging to %s")) % log_path;
return {std::move(vm)};
}
diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h
index 93e7c2ec3..785a72e4b 100644
--- a/src/wallet/wallet_errors.h
+++ b/src/wallet/wallet_errors.h
@@ -626,6 +626,18 @@ namespace tools
std::string m_request;
};
//----------------------------------------------------------------------------------------------------
+ struct wallet_generic_rpc_error : public wallet_rpc_error
+ {
+ explicit wallet_generic_rpc_error(std::string&& loc, const std::string& request, const std::string& status)
+ : wallet_rpc_error(std::move(loc), std::string("error in ") + request + " RPC: " + status, request),
+ m_status(status)
+ {
+ }
+ const std::string& status() const { return m_status; }
+ private:
+ const std::string m_status;
+ };
+ //----------------------------------------------------------------------------------------------------
struct daemon_busy : public wallet_rpc_error
{
explicit daemon_busy(std::string&& loc, const std::string& request)
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index d61b11f8a..33e099ceb 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -46,6 +46,9 @@ using namespace epee;
#include "string_tools.h"
#include "crypto/hash.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "wallet.rpc"
+
namespace
{
const command_line::arg_descriptor<std::string, true> arg_rpc_bind_port = {"rpc-bind-port", "Sets bind port for server"};
@@ -393,6 +396,7 @@ namespace tools
std::vector<cryptonote::tx_destination_entry> dsts;
std::vector<uint8_t> extra;
+ LOG_PRINT_L3("on_transfer_split starts");
if (m_wallet.restricted())
{
er.code = WALLET_RPC_ERROR_CODE_DENIED;
@@ -482,9 +486,13 @@ namespace tools
mixin = 2;
}
std::vector<wallet2::pending_tx> ptx_vector;
+ LOG_PRINT_L2("on_transfer_split calling create_transactions_2");
ptx_vector = m_wallet.create_transactions_2(dsts, mixin, req.unlock_time, req.priority, extra, req.trusted_daemon);
+ LOG_PRINT_L2("on_transfer_split called create_transactions_2");
+ LOG_PRINT_L2("on_transfer_split calling commit_txyy");
m_wallet.commit_tx(ptx_vector);
+ LOG_PRINT_L2("on_transfer_split called commit_txyy");
// populate response with tx hashes
for (auto & ptx : ptx_vector)
@@ -1323,7 +1331,8 @@ int main(int argc, char** argv) {
return 1;
}
- epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_2);
+ mlog_configure("monero-wallet-rpc.log", true);
+ mlog_set_log_level(2);
std::unique_ptr<tools::wallet2> wal;
try
@@ -1368,12 +1377,12 @@ int main(int argc, char** argv) {
// if we ^C during potentially length load/refresh, there's no server loop yet
if (quit)
{
- LOG_PRINT_L0(tools::wallet_rpc_server::tr("Storing wallet..."));
+ MINFO(tools::wallet_rpc_server::tr("Storing wallet..."));
wal->store();
- LOG_PRINT_GREEN(tools::wallet_rpc_server::tr("Stored ok"), LOG_LEVEL_0);
+ MINFO(tools::wallet_rpc_server::tr("Stored ok"));
return 1;
}
- LOG_PRINT_GREEN(tools::wallet_rpc_server::tr("Loaded ok"), LOG_LEVEL_0);
+ MINFO(tools::wallet_rpc_server::tr("Loaded ok"));
}
catch (const std::exception& e)
{
@@ -1393,7 +1402,7 @@ int main(int argc, char** argv) {
{
LOG_PRINT_L0(tools::wallet_rpc_server::tr("Storing wallet..."));
wal->store();
- LOG_PRINT_GREEN(tools::wallet_rpc_server::tr("Stored ok"), LOG_LEVEL_0);
+ LOG_PRINT_L0(tools::wallet_rpc_server::tr("Stored ok"));
}
catch (const std::exception& e)
{
diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h
index 4ff1b267f..7d5db1bcb 100644
--- a/src/wallet/wallet_rpc_server.h
+++ b/src/wallet/wallet_rpc_server.h
@@ -36,6 +36,10 @@
#include "net/http_server_impl_base.h"
#include "wallet_rpc_server_commands_defs.h"
#include "wallet2.h"
+
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "wallet.rpc"
+
namespace tools
{
/************************************************************************/
diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h
index ea0fc685f..4d643637f 100644
--- a/src/wallet/wallet_rpc_server_commands_defs.h
+++ b/src/wallet/wallet_rpc_server_commands_defs.h
@@ -33,6 +33,10 @@
#include "cryptonote_core/cryptonote_basic.h"
#include "crypto/hash.h"
#include "wallet_rpc_server_error_codes.h"
+
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "wallet.rpc"
+
namespace tools
{
namespace wallet_rpc