diff options
38 files changed, 212 insertions, 95 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index d584e41c0..a9d6be986 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -338,6 +338,8 @@ if (UNIX AND NOT APPLE) find_package(Threads) endif() +add_definitions(-DAUTO_INITIALIZE_EASYLOGGINGPP) + add_subdirectory(external) # Final setup for miniupnpc diff --git a/contrib/epee/src/mlog.cpp b/contrib/epee/src/mlog.cpp index 7487fdbd2..3be992374 100644 --- a/contrib/epee/src/mlog.cpp +++ b/contrib/epee/src/mlog.cpp @@ -31,8 +31,6 @@ #include <atomic> #include "misc_log_ex.h" -INITIALIZE_EASYLOGGINGPP - #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "logging" diff --git a/external/easylogging++/easylogging++.cc b/external/easylogging++/easylogging++.cc index efa876664..721b2af15 100644 --- a/external/easylogging++/easylogging++.cc +++ b/external/easylogging++/easylogging++.cc @@ -1164,19 +1164,19 @@ unsigned long long DateTime::getTimeDifference(const struct timeval& endTime, co struct ::tm* DateTime::buildTimeInfo(struct timeval* currTime, struct ::tm* timeInfo) { #if ELPP_OS_UNIX time_t rawTime = currTime->tv_sec; - ::localtime_r(&rawTime, timeInfo); + ::gmtime_r(&rawTime, timeInfo); return timeInfo; #else # if ELPP_COMPILER_MSVC ELPP_UNUSED(currTime); time_t t; _time64(&t); - localtime_s(timeInfo, &t); + gmtime_s(timeInfo, &t); return timeInfo; # else // For any other compilers that don't have CRT warnings issue e.g, MinGW or TDM GCC- we use different method time_t rawTime = currTime->tv_sec; - struct tm* tmInf = localtime(&rawTime); + struct tm* tmInf = gmtime(&rawTime); *timeInfo = *tmInf; return timeInfo; # endif // ELPP_COMPILER_MSVC diff --git a/external/unbound/validator/val_secalgo.c b/external/unbound/validator/val_secalgo.c index 256c3ff92..b55d4a62c 100644 --- a/external/unbound/validator/val_secalgo.c +++ b/external/unbound/validator/val_secalgo.c @@ -546,15 +546,15 @@ verify_canonrrset(sldns_buffer* buf, int algo, unsigned char* sigblock, /* do the signature cryptography work */ EVP_MD_CTX_init(&ctx); - if(EVP_VerifyInit(&ctx, digest_type) == 0) { - verbose(VERB_QUERY, "verify: EVP_VerifyInit failed"); + if(EVP_DigestInit(&ctx, digest_type) == 0) { + verbose(VERB_QUERY, "verify: EVP_DigestInit failed"); EVP_PKEY_free(evp_key); if(dofree) free(sigblock); return sec_status_unchecked; } - if(EVP_VerifyUpdate(&ctx, (unsigned char*)sldns_buffer_begin(buf), + if(EVP_DigestUpdate(&ctx, (unsigned char*)sldns_buffer_begin(buf), (unsigned int)sldns_buffer_limit(buf)) == 0) { - verbose(VERB_QUERY, "verify: EVP_VerifyUpdate failed"); + verbose(VERB_QUERY, "verify: EVP_DigestUpdate failed"); EVP_PKEY_free(evp_key); if(dofree) free(sigblock); return sec_status_unchecked; diff --git a/src/blockchain_db/CMakeLists.txt b/src/blockchain_db/CMakeLists.txt index c27aa73b0..041d9568f 100644 --- a/src/blockchain_db/CMakeLists.txt +++ b/src/blockchain_db/CMakeLists.txt @@ -62,7 +62,7 @@ monero_add_library(blockchain_db target_link_libraries(blockchain_db PUBLIC common - crypto + cncrypto ringct ${LMDB_LIBRARY} ${BDB_LIBRARY} diff --git a/src/blockchain_db/blockchain_db.h b/src/blockchain_db/blockchain_db.h index 9dd343f4b..b0a3d84e1 100644 --- a/src/blockchain_db/blockchain_db.h +++ b/src/blockchain_db/blockchain_db.h @@ -1353,10 +1353,10 @@ public: virtual bool for_all_key_images(std::function<bool(const crypto::key_image&)>) const = 0; /** - * @brief runs a function over all blocks stored + * @brief runs a function over a range of blocks * - * The subclass should run the passed function for each block it has - * stored, passing (block_height, block_hash, block) as its parameters. + * The subclass should run the passed function for each block in the + * specified range, passing (block_height, block_hash, block) as its parameters. * * If any call to the function returns false, the subclass should return * false. Otherwise, the subclass returns true. @@ -1364,11 +1364,13 @@ public: * The subclass should throw DB_ERROR if any of the expected values are * not found. Current implementations simply return false. * + * @param h1 the start height + * @param h2 the end height * @param std::function fn the function to run * * @return false if the function returns false for any block, otherwise true */ - virtual bool for_all_blocks(std::function<bool(uint64_t, const crypto::hash&, const cryptonote::block&)>) const = 0; + virtual bool for_blocks_range(const uint64_t& h1, const uint64_t& h2, std::function<bool(uint64_t, const crypto::hash&, const cryptonote::block&)>) const = 0; /** * @brief runs a function over all transactions stored diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 1f0831874..d7947c8d0 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -2380,7 +2380,7 @@ bool BlockchainLMDB::for_all_key_images(std::function<bool(const crypto::key_ima return ret; } -bool BlockchainLMDB::for_all_blocks(std::function<bool(uint64_t, const crypto::hash&, const cryptonote::block&)> f) const +bool BlockchainLMDB::for_blocks_range(const uint64_t& h1, const uint64_t& h2, std::function<bool(uint64_t, const crypto::hash&, const cryptonote::block&)> f) const { LOG_PRINT_L3("BlockchainLMDB::" << __func__); check_open(); @@ -2392,7 +2392,15 @@ bool BlockchainLMDB::for_all_blocks(std::function<bool(uint64_t, const crypto::h MDB_val v; bool ret = true; - MDB_cursor_op op = MDB_FIRST; + MDB_cursor_op op; + if (h1) + { + MDB_val_set(k, h1); + op = MDB_SET; + } else + { + op = MDB_FIRST; + } while (1) { int ret = mdb_cursor_get(m_cur_blocks, &k, &v, op); @@ -2414,6 +2422,8 @@ bool BlockchainLMDB::for_all_blocks(std::function<bool(uint64_t, const crypto::h ret = false; break; } + if (height >= h2) + break; } TXN_POSTFIX_RDONLY(); diff --git a/src/blockchain_db/lmdb/db_lmdb.h b/src/blockchain_db/lmdb/db_lmdb.h index 02f57ce18..540fababb 100644 --- a/src/blockchain_db/lmdb/db_lmdb.h +++ b/src/blockchain_db/lmdb/db_lmdb.h @@ -249,7 +249,7 @@ public: virtual bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)> f, bool include_blob = false) const; virtual bool for_all_key_images(std::function<bool(const crypto::key_image&)>) const; - virtual bool for_all_blocks(std::function<bool(uint64_t, const crypto::hash&, const cryptonote::block&)>) const; + virtual bool for_blocks_range(const uint64_t& h1, const uint64_t& h2, std::function<bool(uint64_t, const crypto::hash&, const cryptonote::block&)>) const; virtual bool for_all_transactions(std::function<bool(const crypto::hash&, const cryptonote::transaction&)>) const; virtual bool for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, size_t tx_idx)> f) const; diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 0a3e8cd19..55b8ad3e6 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -79,7 +79,7 @@ monero_add_library(common target_link_libraries(common PUBLIC epee - crypto + cncrypto ${UNBOUND_LIBRARY} ${LIBUNWIND_LIBRARIES} ${Boost_DATE_TIME_LIBRARY} diff --git a/src/crypto/CMakeLists.txt b/src/crypto/CMakeLists.txt index 277ee64c2..1e06a0dfd 100644 --- a/src/crypto/CMakeLists.txt +++ b/src/crypto/CMakeLists.txt @@ -68,13 +68,13 @@ set(crypto_private_headers skein.h skein_port.h) -monero_private_headers(crypto +monero_private_headers(cncrypto ${crypto_private_headers}) -monero_add_library(crypto +monero_add_library(cncrypto ${crypto_sources} ${crypto_headers} ${crypto_private_headers}) -target_link_libraries(crypto +target_link_libraries(cncrypto PUBLIC ${Boost_SYSTEM_LIBRARY} PRIVATE diff --git a/src/cryptonote_basic/CMakeLists.txt b/src/cryptonote_basic/CMakeLists.txt index 2b8ad365a..ec7aa251f 100644 --- a/src/cryptonote_basic/CMakeLists.txt +++ b/src/cryptonote_basic/CMakeLists.txt @@ -62,7 +62,7 @@ monero_add_library(cryptonote_basic target_link_libraries(cryptonote_basic PUBLIC common - crypto + cncrypto ${Boost_DATE_TIME_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_SERIALIZATION_LIBRARY} diff --git a/src/cryptonote_core/CMakeLists.txt b/src/cryptonote_core/CMakeLists.txt index 5944ddcd1..7c43323d4 100644 --- a/src/cryptonote_core/CMakeLists.txt +++ b/src/cryptonote_core/CMakeLists.txt @@ -56,7 +56,7 @@ monero_add_library(cryptonote_core target_link_libraries(cryptonote_core PUBLIC common - crypto + cncrypto blockchain_db ringct ${Boost_DATE_TIME_LIBRARY} diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 7fb85ee76..6f2977c5b 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -4164,9 +4164,9 @@ bool Blockchain::for_all_key_images(std::function<bool(const crypto::key_image&) return m_db->for_all_key_images(f); } -bool Blockchain::for_all_blocks(std::function<bool(uint64_t, const crypto::hash&, const block&)> f) const +bool Blockchain::for_blocks_range(const uint64_t& h1, const uint64_t& h2, std::function<bool(uint64_t, const crypto::hash&, const block&)> f) const { - return m_db->for_all_blocks(f); + return m_db->for_blocks_range(h1, h2, f); } bool Blockchain::for_all_transactions(std::function<bool(const crypto::hash&, const cryptonote::transaction&)> f) const diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h index 89efe5452..52172012c 100644 --- a/src/cryptonote_core/blockchain.h +++ b/src/cryptonote_core/blockchain.h @@ -790,13 +790,15 @@ namespace cryptonote bool for_all_key_images(std::function<bool(const crypto::key_image&)>) const; /** - * @brief perform a check on all blocks in the blockchain + * @brief perform a check on all blocks in the blockchain in the given range * + * @param h1 the start height + * @param h2 the end height * @param std::function the check to perform, pass/fail * * @return false if any block fails the check, otherwise true */ - bool for_all_blocks(std::function<bool(uint64_t, const crypto::hash&, const block&)>) const; + bool for_blocks_range(const uint64_t& h1, const uint64_t& h2, std::function<bool(uint64_t, const crypto::hash&, const block&)>) const; /** * @brief perform a check on all transactions in the blockchain diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 1cd285522..c601c066c 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -713,12 +713,13 @@ namespace cryptonote //----------------------------------------------------------------------------------------------- std::pair<uint64_t, uint64_t> core::get_coinbase_tx_sum(const uint64_t start_offset, const size_t count) { - std::list<block> blocks; uint64_t emission_amount = 0; uint64_t total_fee_amount = 0; - this->get_blocks(start_offset, count, blocks); - for(auto& b: blocks) + if (count) { + const uint64_t end = start_offset + count - 1; + m_blockchain_storage.for_blocks_range(start_offset, end, + [this, &emission_amount, &total_fee_amount](uint64_t, const crypto::hash& hash, const block& b){ std::list<transaction> txs; std::list<crypto::hash> missed_txs; uint64_t coinbase_amount = get_outs_money_amount(b.miner_tx); @@ -731,6 +732,8 @@ namespace cryptonote emission_amount += coinbase_amount - tx_fee_amount; total_fee_amount += tx_fee_amount; + return true; + }); } return std::pair<uint64_t, uint64_t>(emission_amount, total_fee_amount); @@ -1046,6 +1049,12 @@ namespace cryptonote return true; } //----------------------------------------------------------------------------------------------- + bool core::get_pool_transaction_stats(struct txpool_stats& stats) const + { + m_mempool.get_transaction_stats(stats); + return true; + } + //----------------------------------------------------------------------------------------------- bool core::get_pool_transaction(const crypto::hash &id, cryptonote::blobdata& tx) const { return m_mempool.get_transaction(id, tx); @@ -1097,7 +1106,7 @@ namespace cryptonote if(!m_starter_message_showed) { MGINFO_YELLOW(ENDL << "**********************************************************************" << ENDL - << "The daemon will start synchronizing with the network. It may take up to several hours." << ENDL + << "The daemon will start synchronizing with the network. This may take a long time to complete." << ENDL << ENDL << "You can set the level of process detailization* through \"set_log <level|categories>\" command*," << ENDL << "where <level> is between 0 (no details) and 4 (very verbose), or custom category based levels (eg, *:WARNING)" << ENDL diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index 5e66af545..e5fbf7f91 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -411,6 +411,13 @@ namespace cryptonote bool get_pool_transaction_hashes(std::vector<crypto::hash>& txs) const; /** + * @copydoc tx_memory_pool::get_transactions + * + * @note see tx_memory_pool::get_transactions + */ + bool get_pool_transaction_stats(struct txpool_stats& stats) const; + + /** * @copydoc tx_memory_pool::get_transaction * * @note see tx_memory_pool::get_transaction diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 30aed50f9..515918cfa 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -107,6 +107,9 @@ namespace cryptonote //--------------------------------------------------------------------------------- bool tx_memory_pool::add_tx(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) { + // this should already be called with that lock, but let's make it explicit for clarity + CRITICAL_REGION_LOCAL(m_transactions_lock); + PERF_TIMER(add_tx); if (tx.version == 0) { @@ -224,6 +227,7 @@ namespace cryptonote meta.do_not_relay = do_not_relay; try { + CRITICAL_REGION_LOCAL1(m_blockchain); LockedTXN lock(m_blockchain); m_blockchain.add_txpool_tx(tx, meta); if (!insert_key_images(tx, kept_by_block)) @@ -260,6 +264,7 @@ namespace cryptonote try { + CRITICAL_REGION_LOCAL1(m_blockchain); LockedTXN lock(m_blockchain); m_blockchain.remove_txpool_tx(get_transaction_hash(tx)); m_blockchain.add_txpool_tx(tx, meta); @@ -546,6 +551,31 @@ namespace cryptonote }); } //------------------------------------------------------------------ + void tx_memory_pool::get_transaction_stats(struct txpool_stats& stats) const + { + CRITICAL_REGION_LOCAL(m_transactions_lock); + CRITICAL_REGION_LOCAL1(m_blockchain); + const uint64_t now = time(NULL); + stats.txs_total = m_blockchain.get_txpool_tx_count(); + m_blockchain.for_all_txpool_txes([&stats, now](const crypto::hash &txid, const txpool_tx_meta_t &meta, const cryptonote::blobdata *bd){ + stats.bytes_total += meta.blob_size; + if (!stats.bytes_min || meta.blob_size < stats.bytes_min) + stats.bytes_min = meta.blob_size; + if (meta.blob_size > stats.bytes_max) + stats.bytes_max = meta.blob_size; + if (!meta.relayed) + stats.num_not_relayed++; + stats.fee_total += meta.fee; + if (!stats.oldest || meta.receive_time < stats.oldest) + stats.oldest = meta.receive_time; + if (meta.receive_time < now - 600) + stats.num_10m++; + if (meta.last_failed_height) + stats.num_failing++; + return true; + }); + } + //------------------------------------------------------------------ //TODO: investigate whether boolean return is appropriate bool tx_memory_pool::get_transactions_and_spent_keys_info(std::vector<tx_info>& tx_infos, std::vector<spent_key_image_info>& key_image_infos) const { diff --git a/src/cryptonote_core/tx_pool.h b/src/cryptonote_core/tx_pool.h index a2ab76959..1858ccdd8 100644 --- a/src/cryptonote_core/tx_pool.h +++ b/src/cryptonote_core/tx_pool.h @@ -243,6 +243,13 @@ namespace cryptonote void get_transaction_hashes(std::vector<crypto::hash>& txs) const; /** + * @brief get a summary statistics of all transaction hashes in the pool + * + * @param stats return-by-reference the pool statistics + */ + void get_transaction_stats(struct txpool_stats& stats) const; + + /** * @brief get information about all transactions and key images in the pool * * see documentation on tx_info and spent_key_image_info for more details diff --git a/src/daemon/CMakeLists.txt b/src/daemon/CMakeLists.txt index 649823a59..795442a2d 100644 --- a/src/daemon/CMakeLists.txt +++ b/src/daemon/CMakeLists.txt @@ -87,7 +87,7 @@ target_link_libraries(daemon rpc blockchain_db cryptonote_core - crypto + cncrypto common p2p cryptonote_protocol diff --git a/src/daemon/command_server.cpp b/src/daemon/command_server.cpp index 21f550a85..f47891fdd 100644 --- a/src/daemon/command_server.cpp +++ b/src/daemon/command_server.cpp @@ -246,7 +246,7 @@ t_command_server::t_command_server( m_command_lookup.set_handler( "update" , std::bind(&t_command_parser_executor::update, &m_parser, p::_1) - , "subcommands: check (check if an update is available), download (download it is there is), update (not implemented)" + , "subcommands: check (check if an update is available), download (download it if there is), update (not implemented)" ); m_command_lookup.set_handler( "relay_tx" diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index 31f432918..d5bde7f09 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -911,57 +911,35 @@ bool t_rpc_command_executor::print_transaction_pool_short() { } bool t_rpc_command_executor::print_transaction_pool_stats() { - cryptonote::COMMAND_RPC_GET_TRANSACTION_POOL::request req; - cryptonote::COMMAND_RPC_GET_TRANSACTION_POOL::response res; + cryptonote::COMMAND_RPC_GET_TRANSACTION_POOL_STATS::request req; + cryptonote::COMMAND_RPC_GET_TRANSACTION_POOL_STATS::response res; - std::string fail_message = "Problem fetching transaction pool"; + std::string fail_message = "Problem fetching transaction pool stats"; if (m_is_rpc) { - if (!m_rpc_client->rpc_request(req, res, "/get_transaction_pool", fail_message.c_str())) + if (!m_rpc_client->rpc_request(req, res, "/get_transaction_pool_stats", fail_message.c_str())) { return true; } } else { - if (!m_rpc_server->on_get_transaction_pool(req, res) || res.status != CORE_RPC_STATUS_OK) + memset(&res.pool_stats, 0, sizeof(res.pool_stats)); + if (!m_rpc_server->on_get_transaction_pool_stats(req, res) || res.status != CORE_RPC_STATUS_OK) { tools::fail_msg_writer() << make_error(fail_message, res.status); return true; } } - size_t n_transactions = res.transactions.size(); - size_t bytes = 0, min_bytes = 0, max_bytes = 0; - size_t n_not_relayed = 0; - uint64_t fee = 0; - uint64_t oldest = 0; - size_t n_10m = 0; - size_t n_failing = 0; + size_t n_transactions = res.pool_stats.txs_total; const uint64_t now = time(NULL); - for (const auto &tx_info: res.transactions) - { - bytes += tx_info.blob_size; - if (min_bytes == 0 || tx_info.blob_size < min_bytes) - min_bytes = tx_info.blob_size; - if (tx_info.blob_size > max_bytes) - max_bytes = tx_info.blob_size; - if (!tx_info.relayed) - n_not_relayed++; - fee += tx_info.fee; - if (oldest == 0 || tx_info.receive_time < oldest) - oldest = tx_info.receive_time; - if (tx_info.receive_time < now - 600) - n_10m++; - if (tx_info.last_failed_height) - ++n_failing; - } - size_t avg_bytes = n_transactions ? bytes / n_transactions : 0; - - tools::msg_writer() << n_transactions << " tx(es), " << bytes << " bytes total (min " << min_bytes << ", max " << max_bytes << ", avg " << avg_bytes << ")" << std::endl - << "fees " << cryptonote::print_money(fee) << " (avg " << cryptonote::print_money(n_transactions ? fee / n_transactions : 0) << " per tx" << ", " << cryptonote::print_money(bytes ? fee / bytes : 0) << " per byte )" << std::endl - << n_not_relayed << " not relayed, " << n_failing << " failing, " << n_10m << " older than 10 minutes (oldest " << (oldest == 0 ? "-" : get_human_time_ago(oldest, now)) << ")" << std::endl; + size_t avg_bytes = n_transactions ? res.pool_stats.bytes_total / n_transactions : 0; + + tools::msg_writer() << n_transactions << " tx(es), " << res.pool_stats.bytes_total << " bytes total (min " << res.pool_stats.bytes_min << ", max " << res.pool_stats.bytes_max << ", avg " << avg_bytes << ")" << std::endl + << "fees " << cryptonote::print_money(res.pool_stats.fee_total) << " (avg " << cryptonote::print_money(n_transactions ? res.pool_stats.fee_total / n_transactions : 0) << " per tx" << ", " << cryptonote::print_money(res.pool_stats.bytes_total ? res.pool_stats.fee_total / res.pool_stats.bytes_total : 0) << " per byte )" << std::endl + << res.pool_stats.num_not_relayed << " not relayed, " << res.pool_stats.num_failing << " failing, " << res.pool_stats.num_10m << " older than 10 minutes (oldest " << (res.pool_stats.oldest == 0 ? "-" : get_human_time_ago(res.pool_stats.oldest, now)) << ")" << std::endl; return true; } diff --git a/src/mnemonics/CMakeLists.txt b/src/mnemonics/CMakeLists.txt index c521a0932..269cfe846 100644 --- a/src/mnemonics/CMakeLists.txt +++ b/src/mnemonics/CMakeLists.txt @@ -55,6 +55,7 @@ monero_add_library(mnemonics ${mnemonics_private_headers}) target_link_libraries(mnemonics PUBLIC + easylogging ${Boost_SYSTEM_LIBRARY} PRIVATE ${EXTRA_LIBRARIES}) diff --git a/src/ringct/CMakeLists.txt b/src/ringct/CMakeLists.txt index e15af205a..f9862ac80 100644 --- a/src/ringct/CMakeLists.txt +++ b/src/ringct/CMakeLists.txt @@ -48,7 +48,7 @@ monero_add_library(ringct target_link_libraries(ringct PUBLIC common - crypto + cncrypto cryptonote_basic PRIVATE ${EXTRA_LIBRARIES}) diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 53cfedc04..43891458c 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -797,6 +797,14 @@ namespace cryptonote return true; } //------------------------------------------------------------------------------------------------------------------------------ + bool core_rpc_server::on_get_transaction_pool_stats(const COMMAND_RPC_GET_TRANSACTION_POOL_STATS::request& req, COMMAND_RPC_GET_TRANSACTION_POOL_STATS::response& res) + { + CHECK_CORE_BUSY(); + m_core.get_pool_transaction_stats(res.pool_stats); + res.status = CORE_RPC_STATUS_OK; + return true; + } + //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::on_stop_daemon(const COMMAND_RPC_STOP_DAEMON::request& req, COMMAND_RPC_STOP_DAEMON::response& res) { // FIXME: replace back to original m_p2p.send_stop_signal() after diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h index 0aa222c87..44ac6f07a 100644 --- a/src/rpc/core_rpc_server.h +++ b/src/rpc/core_rpc_server.h @@ -93,6 +93,7 @@ namespace cryptonote 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("/get_transaction_pool_hashes.bin", on_get_transaction_pool_hashes, COMMAND_RPC_GET_TRANSACTION_POOL_HASHES) + MAP_URI_AUTO_JON2("/get_transaction_pool_stats", on_get_transaction_pool_stats, COMMAND_RPC_GET_TRANSACTION_POOL_STATS) 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) MAP_URI_AUTO_JON2_IF("/out_peers", on_out_peers, COMMAND_RPC_OUT_PEERS, !m_restricted) @@ -148,6 +149,7 @@ namespace cryptonote 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_get_transaction_pool_hashes(const COMMAND_RPC_GET_TRANSACTION_POOL_HASHES::request& req, COMMAND_RPC_GET_TRANSACTION_POOL_HASHES::response& res); + bool on_get_transaction_pool_stats(const COMMAND_RPC_GET_TRANSACTION_POOL_STATS::request& req, COMMAND_RPC_GET_TRANSACTION_POOL_STATS::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); bool on_start_save_graph(const COMMAND_RPC_START_SAVE_GRAPH::request& req, COMMAND_RPC_START_SAVE_GRAPH::response& res); diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 9bdadf0d1..8b5f189ca 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -49,7 +49,7 @@ 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 10 +#define CORE_RPC_VERSION_MINOR 11 #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) @@ -1047,6 +1047,51 @@ namespace cryptonote }; }; + struct txpool_stats + { + uint64_t bytes_total; + uint32_t bytes_min; + uint32_t bytes_max; + uint64_t fee_total; + uint64_t oldest; + uint32_t txs_total; + uint32_t num_failing; + uint32_t num_10m; + uint32_t num_not_relayed; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(bytes_total) + KV_SERIALIZE(bytes_min) + KV_SERIALIZE(bytes_max) + KV_SERIALIZE(fee_total) + KV_SERIALIZE(oldest) + KV_SERIALIZE(txs_total) + KV_SERIALIZE(num_failing) + KV_SERIALIZE(num_10m) + KV_SERIALIZE(num_not_relayed) + END_KV_SERIALIZE_MAP() + }; + + struct COMMAND_RPC_GET_TRANSACTION_POOL_STATS + { + struct request + { + BEGIN_KV_SERIALIZE_MAP() + END_KV_SERIALIZE_MAP() + }; + + struct response + { + std::string status; + txpool_stats pool_stats; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(status) + KV_SERIALIZE(pool_stats) + END_KV_SERIALIZE_MAP() + }; + }; + struct COMMAND_RPC_GET_CONNECTIONS { struct request diff --git a/src/simplewallet/CMakeLists.txt b/src/simplewallet/CMakeLists.txt index 18a8bac68..443e9b87e 100644 --- a/src/simplewallet/CMakeLists.txt +++ b/src/simplewallet/CMakeLists.txt @@ -45,7 +45,7 @@ target_link_libraries(simplewallet wallet rpc cryptonote_core - crypto + cncrypto common mnemonics p2p diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 024396b87..87dbcf513 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -903,6 +903,8 @@ static bool might_be_partial_seed(std::string words) //---------------------------------------------------------------------------------------------------- bool simple_wallet::init(const boost::program_options::variables_map& vm) { + bool need_refresh_height = false; + if (!handle_command_line(vm)) return false; @@ -1091,6 +1093,8 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) m_wallet_file = m_generate_new; 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_deterministic_wallet) + need_refresh_height = true; } if (!m_restore_height && m_restoring) { @@ -1178,6 +1182,15 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) m_http_client.set_server(m_wallet->get_daemon_address(), m_wallet->get_daemon_login()); m_wallet->callback(this); + + if (need_refresh_height) + { + // for a totally new account, we don't care about older blocks. + MDEBUG("Calling daemon to set refresh height"); + std::string err; + m_wallet->set_refresh_from_block_height(get_daemon_blockchain_height(err)); + } + return true; } //---------------------------------------------------------------------------------------------------- @@ -1321,16 +1334,6 @@ bool simple_wallet::new_wallet(const boost::program_options::variables_map& vm, m_wallet->set_seed_language(mnemonic_language); - // for a totally new account, we don't care about older blocks. - if (!m_restoring) - { - std::string err; - m_wallet->set_refresh_from_block_height(get_daemon_blockchain_height(err)); - } else if (m_restore_height) - { - m_wallet->set_refresh_from_block_height(m_restore_height); - } - crypto::secret_key recovery_val; try { diff --git a/src/wallet/CMakeLists.txt b/src/wallet/CMakeLists.txt index 2e7610b64..639080051 100644 --- a/src/wallet/CMakeLists.txt +++ b/src/wallet/CMakeLists.txt @@ -108,7 +108,7 @@ if (NOT BUILD_GUI_DEPS) epee rpc cryptonote_core - crypto + cncrypto common ${Boost_CHRONO_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} @@ -126,7 +126,7 @@ endif() # build and install libwallet_merged only if we building for GUI if (BUILD_GUI_DEPS) - set(libs_to_merge wallet cryptonote_core cryptonote_basic mnemonics common crypto ringct) + set(libs_to_merge wallet cryptonote_core cryptonote_basic mnemonics common cncrypto ringct) foreach(lib ${libs_to_merge}) list(APPEND objlibs $<TARGET_OBJECTS:obj_${lib}>) # matches naming convention in src/CMakeLists.txt diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 611c1819f..1b4300edf 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -464,7 +464,8 @@ bool WalletImpl::recoverFromKeys(const std::string &path, { if (has_spendkey) { m_wallet->generate(path, "", address, spendkey, viewkey); - LOG_PRINT_L1("Generated new wallet from keys"); + setSeedLanguage(language); + LOG_PRINT_L1("Generated new wallet from keys with seed language: " + language); } else { m_wallet->generate(path, "", address, viewkey); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index f56506772..96ba04c47 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -5277,6 +5277,10 @@ uint64_t wallet2::import_key_images(const std::vector<std::pair<crypto::key_imag std::vector<const crypto::public_key*> pkeys; pkeys.push_back(&pkey); + THROW_WALLET_EXCEPTION_IF(!(rct::scalarmultKey(rct::ki2rct(key_image), rct::curveOrder()) == rct::identity()), + error::wallet_internal_error, "Key image out of validity domain: input " + boost::lexical_cast<std::string>(n) + "/" + + boost::lexical_cast<std::string>(signed_key_images.size()) + ", key image " + epee::string_tools::pod_to_hex(key_image)); + THROW_WALLET_EXCEPTION_IF(!crypto::check_ring_signature((const crypto::hash&)key_image, key_image, pkeys, &signature), error::wallet_internal_error, "Signature check failed: input " + boost::lexical_cast<std::string>(n) + "/" + boost::lexical_cast<std::string>(signed_key_images.size()) + ", key image " + epee::string_tools::pod_to_hex(key_image) diff --git a/tests/core_tests/tx_validation.cpp b/tests/core_tests/tx_validation.cpp index 885b95c69..66460e876 100644 --- a/tests/core_tests/tx_validation.cpp +++ b/tests/core_tests/tx_validation.cpp @@ -163,6 +163,15 @@ namespace throw std::runtime_error("invalid public key wasn't found"); return crypto::public_key(); } + + crypto::key_image generate_invalid_key_image() + { + crypto::key_image key_image; + // a random key image plucked from the blockchain + if (!epee::string_tools::hex_to_pod("6b9f5d1be7c950dc6e4e258c6ef75509412ba9ecaaf90e6886140151d1365b5e", key_image)) + throw std::runtime_error("invalid key image wasn't found"); + return key_image; + } } //---------------------------------------------------------------------------------------------------------------------- @@ -541,8 +550,7 @@ bool gen_tx_key_image_is_invalid::generate(std::vector<test_event_entry>& events builder.step2_fill_inputs(miner_account.get_keys(), sources); txin_to_key& in_to_key = boost::get<txin_to_key>(builder.m_tx.vin.front()); - crypto::public_key pub = generate_invalid_pub_key(); - memcpy(&in_to_key.k_image, &pub, sizeof(crypto::ec_point)); + in_to_key.k_image = generate_invalid_key_image(); builder.step3_fill_outputs(destinations); builder.step4_calc_hash(); diff --git a/tests/crypto/CMakeLists.txt b/tests/crypto/CMakeLists.txt index e1c632a00..573c62ad4 100644 --- a/tests/crypto/CMakeLists.txt +++ b/tests/crypto/CMakeLists.txt @@ -37,17 +37,17 @@ set(crypto_sources set(crypto_headers crypto-tests.h) -add_executable(crypto-tests +add_executable(cncrypto-tests ${crypto_sources} ${crypto_headers}) -target_link_libraries(crypto-tests +target_link_libraries(cncrypto-tests PRIVATE ${Boost_SYSTEM_LIBRARY} ${EXTRA_LIBRARIES}) -set_property(TARGET crypto-tests +set_property(TARGET cncrypto-tests PROPERTY FOLDER "tests") add_test( - NAME crypto - COMMAND crypto-tests "${CMAKE_CURRENT_SOURCE_DIR}/tests.txt") + NAME cncrypto + COMMAND cncrypto-tests "${CMAKE_CURRENT_SOURCE_DIR}/tests.txt") diff --git a/tests/daemon_tests/CMakeLists.txt b/tests/daemon_tests/CMakeLists.txt index c6dc69e9d..b554bfec8 100644 --- a/tests/daemon_tests/CMakeLists.txt +++ b/tests/daemon_tests/CMakeLists.txt @@ -39,7 +39,7 @@ target_link_libraries(transfers useragent rpc cryptonote_core - crypto + cncrypto common epee ${GTEST_LIBRARIES}) diff --git a/tests/functional_tests/CMakeLists.txt b/tests/functional_tests/CMakeLists.txt index 166476904..498fe3c2c 100644 --- a/tests/functional_tests/CMakeLists.txt +++ b/tests/functional_tests/CMakeLists.txt @@ -43,7 +43,7 @@ target_link_libraries(functional_tests cryptonote_core wallet common - crypto + cncrypto epee ${Boost_REGEX_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} diff --git a/tests/hash/CMakeLists.txt b/tests/hash/CMakeLists.txt index 0f579cc6a..5cc95efbb 100644 --- a/tests/hash/CMakeLists.txt +++ b/tests/hash/CMakeLists.txt @@ -36,7 +36,7 @@ add_executable(hash-tests ${hash_headers}) target_link_libraries(hash-tests PRIVATE - crypto + cncrypto ${EXTRA_LIBRARIES}) set_property(TARGET hash-tests PROPERTY diff --git a/tests/performance_tests/CMakeLists.txt b/tests/performance_tests/CMakeLists.txt index 7845515de..2b3a0d6f8 100644 --- a/tests/performance_tests/CMakeLists.txt +++ b/tests/performance_tests/CMakeLists.txt @@ -53,7 +53,7 @@ target_link_libraries(performance_tests PRIVATE cryptonote_core common - crypto + cncrypto epee ${Boost_CHRONO_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp index e29919e8f..4bfe90733 100644 --- a/tests/unit_tests/hardfork.cpp +++ b/tests/unit_tests/hardfork.cpp @@ -106,7 +106,7 @@ public: virtual void remove_spent_key(const crypto::key_image& k_image) {} virtual bool for_all_key_images(std::function<bool(const crypto::key_image&)>) const { return true; } - virtual bool for_all_blocks(std::function<bool(uint64_t, const crypto::hash&, const cryptonote::block&)>) const { return true; } + virtual bool for_blocks_range(const uint64_t&, const uint64_t&, std::function<bool(uint64_t, const crypto::hash&, const cryptonote::block&)>) const { return true; } virtual bool for_all_transactions(std::function<bool(const crypto::hash&, const cryptonote::transaction&)>) const { return true; } virtual bool for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, size_t tx_idx)> f) const { return true; } virtual bool is_read_only() const { return false; } |