diff options
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r-- | src/cryptonote_core/blockchain.cpp | 22 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_core.cpp | 29 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_core.h | 29 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_format_utils.cpp | 22 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_format_utils.h | 17 | ||||
-rw-r--r-- | src/cryptonote_core/miner.cpp | 5 | ||||
-rw-r--r-- | src/cryptonote_core/tx_pool.cpp | 19 |
7 files changed, 77 insertions, 66 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index badb1a335..74e1419c8 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -387,7 +387,7 @@ bool Blockchain::init(BlockchainDB* db, HardFork*& hf, const bool testnet) //------------------------------------------------------------------ bool Blockchain::store_blockchain() { - LOG_PRINT_YELLOW("Blockchain::" << __func__, LOG_LEVEL_3); + LOG_PRINT_L3("Blockchain::" << __func__); // lock because the rpc_thread command handler also calls this CRITICAL_REGION_LOCAL(m_db->m_synchronization_lock); @@ -419,9 +419,10 @@ bool Blockchain::deinit() { LOG_PRINT_L3("Blockchain::" << __func__); - LOG_PRINT_L0("Closing IO Service."); - // stop async service - m_async_work_idle.reset(); + LOG_PRINT_L1("Stopping blockchain read/write activity"); + + // stop async service + m_async_work_idle.reset(); m_async_pool.join_all(); m_async_service.stop(); @@ -436,14 +437,15 @@ bool Blockchain::deinit() try { m_db->close(); + LOG_PRINT_L1("Local blockchain read/write activity stopped successfully"); } catch (const std::exception& e) { - LOG_PRINT_L0(std::string("Error closing blockchain db: ") + e.what()); + LOG_ERROR(std::string("Error closing blockchain db: ") + e.what()); } catch (...) { - LOG_PRINT_L0("There was an issue closing/storing the blockchain, shutting down now to prevent issues!"); + LOG_ERROR("There was an issue closing/storing the blockchain, shutting down now to prevent issues!"); } delete m_hardfork; @@ -1828,14 +1830,6 @@ bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qbloc return false; } - // if split_height remains 0, we didn't have any but the genesis block in common - // which is only fine if the blocks just have the genesis block - if(split_height == 0 && qblock_ids.size() > 1) - { - LOG_ERROR("Ours and foreign blockchain have only genesis block in common... o.O"); - return false; - } - //we start to put block ids INCLUDING last known id, just to make other side be sure starter_offset = split_height; return true; diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 52a5d48c7..149fb09df 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -142,6 +142,7 @@ namespace cryptonote command_line::add_arg(desc, command_line::arg_db_sync_mode); command_line::add_arg(desc, command_line::arg_show_time_stats); command_line::add_arg(desc, command_line::arg_db_auto_remove_logs); + command_line::add_arg(desc, command_line::arg_block_sync_size); } //----------------------------------------------------------------------------------------------- bool core::handle_command_line(const boost::program_options::variables_map& vm) @@ -227,14 +228,14 @@ namespace cryptonote LOG_PRINT_L1("Locking " << lock_path.string()); if (!db_lock.try_lock()) { - LOG_PRINT_L0("Failed to lock " << lock_path.string()); + LOG_ERROR("Failed to lock " << lock_path.string()); return false; } return true; } catch (const std::exception &e) { - LOG_PRINT_L0("Error trying to lock " << lock_path.string() << ": " << e.what()); + LOG_ERROR("Error trying to lock " << lock_path.string() << ": " << e.what()); return false; } } @@ -243,6 +244,7 @@ namespace cryptonote { db_lock.unlock(); db_lock = boost::interprocess::file_lock(); + LOG_PRINT_L1("Blockchain directory successfully unlocked"); return true; } //----------------------------------------------------------------------------------------------- @@ -386,7 +388,7 @@ namespace cryptonote } catch (const DB_ERROR& e) { - LOG_PRINT_L0("Error opening database: " << e.what()); + LOG_ERROR("Error opening database: " << e.what()); return false; } @@ -403,6 +405,10 @@ namespace cryptonote m_blockchain_storage.set_show_time_stats(show_time_stats); CHECK_AND_ASSERT_MES(r, false, "Failed to initialize blockchain storage"); + block_sync_size = command_line::get_arg(vm, command_line::arg_block_sync_size); + if (block_sync_size == 0) + block_sync_size = BLOCKS_SYNCHRONIZING_DEFAULT_COUNT; + // load json & DNS checkpoints, and verify them // with respect to what blocks we already have CHECK_AND_ASSERT_MES(update_checkpoints(), false, "One or more checkpoints loaded from json or dns conflicted with existing checkpoints."); @@ -428,24 +434,11 @@ namespace cryptonote { m_miner.stop(); m_mempool.deinit(); - if (!m_fast_exit) - { - m_blockchain_storage.deinit(); - } + m_blockchain_storage.deinit(); unlock_db_directory(); return true; } //----------------------------------------------------------------------------------------------- - void core::set_fast_exit() - { - m_fast_exit = true; - } - //----------------------------------------------------------------------------------------------- - bool core::get_fast_exit() - { - return m_fast_exit; - } - //----------------------------------------------------------------------------------------------- void core::test_drop_download() { m_test_drop_download = false; @@ -977,6 +970,4 @@ namespace cryptonote { raise(SIGTERM); } - - std::atomic<bool> core::m_fast_exit(false); } diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index d16bd6553..6727d6b04 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -230,29 +230,11 @@ namespace cryptonote * * Uninitializes the miner instance, transaction pool, and Blockchain * - * if m_fast_exit is set, the call to Blockchain::deinit() is not made. - * * @return true */ bool deinit(); /** - * @brief sets fast exit flag - * - * @note see deinit() - */ - static void set_fast_exit(); - - /** - * @brief gets the current state of the fast exit flag - * - * @return the fast exit flag - * - * @note see deinit() - */ - static bool get_fast_exit(); - - /** * @brief sets to drop blocks downloaded (for testing) */ void test_drop_download(); @@ -611,6 +593,13 @@ namespace cryptonote */ bool are_key_images_spent(const std::vector<crypto::key_image>& key_im, std::vector<bool> &spent) const; + /** + * @brief get the number of blocks to sync in one go + * + * @return the number of blocks to sync in one go + */ + size_t get_block_sync_size() const { return block_sync_size; } + private: /** @@ -757,8 +746,6 @@ namespace cryptonote */ bool unlock_db_directory(); - static std::atomic<bool> m_fast_exit; //!< whether or not to deinit Blockchain on exit - bool m_test_drop_download = true; //!< whether or not to drop incoming blocks (for testing) uint64_t m_test_drop_download_height = 0; //!< height under which to drop incoming blocks, if doing so @@ -798,6 +785,8 @@ namespace cryptonote std::atomic_flag m_checkpoints_updating; //!< set if checkpoints are currently updating to avoid multiple threads attempting to update at once boost::interprocess::file_lock db_lock; //!< a lock object for a file lock in the db directory + + size_t block_sync_size; }; } diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp index d1ccfc7d1..64f8eb924 100644 --- a/src/cryptonote_core/cryptonote_format_utils.cpp +++ b/src/cryptonote_core/cryptonote_format_utils.cpp @@ -366,7 +366,7 @@ namespace cryptonote return true; } //--------------------------------------------------------------- - bool remove_extra_nonce_tx_extra(std::vector<uint8_t>& tx_extra) + bool remove_field_from_tx_extra(std::vector<uint8_t>& tx_extra, const std::type_info &type) { std::string extra_str(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size()); std::istringstream iss(extra_str); @@ -380,7 +380,7 @@ namespace cryptonote tx_extra_field field; bool r = ::do_serialize(ar, field); CHECK_AND_NO_ASSERT_MES_L1(r, false, "failed to deserialize extra field. extra = " << string_tools::buff_to_hex_nodelimer(std::string(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size()))); - if (field.type() != typeid(tx_extra_nonce)) + if (field.type() != type) ::do_serialize(newar, field); std::ios_base::iostate state = iss.rdstate(); @@ -472,10 +472,7 @@ namespace cryptonote bool construct_tx_and_get_tx_key(const account_keys& sender_account_keys, const std::vector<tx_source_entry>& sources, const std::vector<tx_destination_entry>& destinations, std::vector<uint8_t> extra, transaction& tx, uint64_t unlock_time, crypto::secret_key &tx_key, bool rct) { std::vector<rct::key> amount_keys; - tx.vin.clear(); - tx.vout.clear(); - tx.signatures.clear(); - tx.rct_signatures.type = rct::RCTTypeNull; + tx.set_null(); amount_keys.clear(); tx.version = rct ? 2 : 1; @@ -512,7 +509,7 @@ namespace cryptonote std::string extra_nonce; set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, payment_id); - remove_extra_nonce_tx_extra(tx.extra); + remove_field_from_tx_extra(tx.extra, typeid(tx_extra_fields)); if (!add_extra_nonce_to_tx_extra(tx.extra, extra_nonce)) { LOG_ERROR("Failed to add encrypted payment id to tx extra"); @@ -615,6 +612,14 @@ namespace cryptonote return false; } + // check for watch only wallet + bool zero_secret_key = true; + for (size_t i = 0; i < sizeof(sender_account_keys.m_spend_secret_key); ++i) + 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"); + } if (tx.version == 1) { @@ -641,7 +646,8 @@ namespace cryptonote tx.signatures.push_back(std::vector<crypto::signature>()); std::vector<crypto::signature>& sigs = tx.signatures.back(); sigs.resize(src_entr.outputs.size()); - crypto::generate_ring_signature(tx_prefix_hash, boost::get<txin_to_key>(tx.vin[i]).k_image, keys_ptrs, in_contexts[i].in_ephemeral.sec, src_entr.real_output, sigs.data()); + if (!zero_secret_key) + crypto::generate_ring_signature(tx_prefix_hash, boost::get<txin_to_key>(tx.vin[i]).k_image, keys_ptrs, in_contexts[i].in_ephemeral.sec, src_entr.real_output, sigs.data()); ss_ring_s << "signatures:" << ENDL; std::for_each(sigs.begin(), sigs.end(), [&](const crypto::signature& s){ss_ring_s << s << ENDL;}); ss_ring_s << "prefix_hash:" << tx_prefix_hash << ENDL << "in_ephemeral_key: " << in_contexts[i].in_ephemeral.sec << ENDL << "real_output: " << src_entr.real_output; diff --git a/src/cryptonote_core/cryptonote_format_utils.h b/src/cryptonote_core/cryptonote_format_utils.h index e6a3bfba4..24db8008e 100644 --- a/src/cryptonote_core/cryptonote_format_utils.h +++ b/src/cryptonote_core/cryptonote_format_utils.h @@ -62,6 +62,16 @@ namespace cryptonote rct::key mask; //ringct amount mask void push_output(uint64_t idx, const crypto::public_key &k, uint64_t amount) { outputs.push_back(std::make_pair(idx, rct::ctkey({rct::pk2rct(k), rct::zeroCommit(amount)}))); } + + BEGIN_SERIALIZE_OBJECT() + FIELD(outputs) + VARINT_FIELD(real_output) + FIELD(real_out_tx_key) + VARINT_FIELD(real_output_in_tx_index) + VARINT_FIELD(amount) + FIELD(rct) + FIELD(mask) + END_SERIALIZE() }; struct tx_destination_entry @@ -71,6 +81,11 @@ namespace cryptonote tx_destination_entry() : amount(0), addr(AUTO_VAL_INIT(addr)) { } tx_destination_entry(uint64_t a, const account_public_address &ad) : amount(a), addr(ad) { } + + BEGIN_SERIALIZE_OBJECT() + VARINT_FIELD(amount) + FIELD(addr) + END_SERIALIZE() }; //--------------------------------------------------------------- @@ -94,7 +109,7 @@ namespace cryptonote crypto::public_key get_tx_pub_key_from_extra(const transaction& tx); bool add_tx_pub_key_to_extra(transaction& tx, const crypto::public_key& tx_pub_key); bool add_extra_nonce_to_tx_extra(std::vector<uint8_t>& tx_extra, const blobdata& extra_nonce); - bool remove_extra_nonce_tx_extra(std::vector<uint8_t>& tx_extra); + bool remove_field_from_tx_extra(std::vector<uint8_t>& tx_extra, const std::type_info &type); void set_payment_id_to_tx_extra_nonce(blobdata& extra_nonce, const crypto::hash& payment_id); void set_encrypted_payment_id_to_tx_extra_nonce(blobdata& extra_nonce, const crypto::hash8& payment_id); bool get_payment_id_from_tx_extra_nonce(const blobdata& extra_nonce, crypto::hash& payment_id); diff --git a/src/cryptonote_core/miner.cpp b/src/cryptonote_core/miner.cpp index ec717a13d..6f4e706ed 100644 --- a/src/cryptonote_core/miner.cpp +++ b/src/cryptonote_core/miner.cpp @@ -278,8 +278,13 @@ namespace cryptonote //----------------------------------------------------------------------------------------------------- bool miner::stop() { + LOG_PRINT_L1("Miner has received stop signal"); + if (!is_mining()) + { + LOG_PRINT_L1("Not mining - nothing to stop" ); return true; + } send_stop_signal(); CRITICAL_REGION_LOCAL(m_threads_lock); diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 46fab4dcf..5bfa7eca6 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -689,7 +689,7 @@ namespace cryptonote bool res = tools::unserialize_obj_from_file(*this, state_file_path); if(!res) { - LOG_PRINT_L1("Failed to load memory pool from file " << state_file_path); + LOG_ERROR("Failed to load memory pool from file " << state_file_path); m_transactions.clear(); m_txs_by_fee.clear(); @@ -710,12 +710,17 @@ namespace cryptonote //TODO: investigate whether only ever returning true is correct bool tx_memory_pool::deinit() { + LOG_PRINT_L1("Received signal to deactivate memory pool store"); + if (m_config_folder.empty()) + { + LOG_PRINT_L1("Memory pool store already empty"); return true; + } if (!tools::create_directories_if_necessary(m_config_folder)) { - LOG_PRINT_L1("Failed to create data directory: " << m_config_folder); + LOG_ERROR("Failed to create memory pool data directory: " << m_config_folder); return false; } @@ -723,8 +728,14 @@ namespace cryptonote bool res = tools::serialize_obj_to_file(*this, state_file_path); if(!res) { - LOG_PRINT_L1("Failed to serialize memory pool to file " << state_file_path); + LOG_ERROR("Failed to serialize memory pool to file " << state_file_path); + return false; } - return true; + else + { + LOG_PRINT_L1("Memory pool store deactivated successfully"); + return true; + } + } } |