diff options
-rw-r--r-- | src/cryptonote_core/blockchain.cpp | 2 | ||||
-rw-r--r-- | src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp | 2 | ||||
-rw-r--r-- | src/daemon/rpc_command_executor.cpp | 1 | ||||
-rw-r--r-- | src/p2p/net_node.inl | 2 | ||||
-rw-r--r-- | src/rpc/core_rpc_server.cpp | 9 | ||||
-rw-r--r-- | src/rpc/core_rpc_server_commands_defs.h | 2 | ||||
-rw-r--r-- | src/wallet/wallet2.cpp | 19 | ||||
-rw-r--r-- | src/wallet/wallet_errors.h | 6 |
8 files changed, 36 insertions, 7 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index bf7294375..45ddc45e9 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -2059,7 +2059,7 @@ bool Blockchain::check_tx_inputs(const transaction& tx, uint64_t* pmax_used_bloc boost::asio::io_service ioservice; boost::thread_group threadpool; - std::auto_ptr < boost::asio::io_service::work > work(new boost::asio::io_service::work(ioservice)); + std::unique_ptr < boost::asio::io_service::work > work(new boost::asio::io_service::work(ioservice)); if(threads > 1) { for (int i = 0; i < threads; i++) diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp b/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp index 12ec4b14a..e5340d62f 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp +++ b/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp @@ -123,7 +123,7 @@ 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_0); + 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()); // TODO } diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index 686af69c2..9e7f3fdc3 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -241,6 +241,7 @@ bool t_rpc_command_executor::show_difficulty() { } tools::success_msg_writer() << "BH: " << res.height + << ", TH: " << res.top_block_hash << ", DIFF: " << res.difficulty << ", HR: " << (int) res.difficulty / res.target << " H/s"; diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 83bb80ac0..ef733416d 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -182,7 +182,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) << "is unblocked.", LOG_LEVEL_0); + LOG_PRINT_CYAN("IP " << epee::string_tools::get_ip_string_from_int32(addr) << " unblocked.", LOG_LEVEL_0); return true; } return false; diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index b566e7318..945557a46 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -117,7 +117,14 @@ namespace cryptonote bool core_rpc_server::on_get_info(const COMMAND_RPC_GET_INFO::request& req, COMMAND_RPC_GET_INFO::response& res) { CHECK_CORE_BUSY(); - res.height = m_core.get_current_blockchain_height(); + crypto::hash top_hash; + if (!m_core.get_blockchain_top(res.height, top_hash)) + { + res.status = "Failed"; + return false; + } + ++res.height; // turn top block height into blockchain height + res.top_block_hash = string_tools::pod_to_hex(top_hash); res.target_height = m_core.get_target_blockchain_height(); res.difficulty = m_core.get_blockchain_storage().get_difficulty_for_next_block(); res.target = m_core.get_blockchain_storage().get_current_hard_fork_version() < 2 ? DIFFICULTY_TARGET_V1 : DIFFICULTY_TARGET; diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index b70164614..73cdbbe07 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -282,6 +282,7 @@ namespace cryptonote uint64_t white_peerlist_size; uint64_t grey_peerlist_size; bool testnet; + std::string top_block_hash; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(status) @@ -296,6 +297,7 @@ namespace cryptonote KV_SERIALIZE(white_peerlist_size) KV_SERIALIZE(grey_peerlist_size) KV_SERIALIZE(testnet) + KV_SERIALIZE(top_block_hash) END_KV_SERIALIZE_MAP() }; }; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 5a9b96bb8..903e70097 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -48,6 +48,7 @@ using namespace epee; #include "cryptonote_protocol/blobdatatype.h" #include "mnemonics/electrum-words.h" #include "common/dns_utils.h" +#include "common/util.h" #include "rapidjson/document.h" #include "rapidjson/writer.h" #include "rapidjson/stringbuffer.h" @@ -228,7 +229,7 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_ // process the other outs from that tx boost::asio::io_service ioservice; boost::thread_group threadpool; - std::auto_ptr < boost::asio::io_service::work > work(new boost::asio::io_service::work(ioservice)); + std::unique_ptr < boost::asio::io_service::work > work(new boost::asio::io_service::work(ioservice)); for (int i = 0; i < threads; i++) { threadpool.create_thread(boost::bind(&boost::asio::io_service::run, &ioservice)); @@ -264,7 +265,7 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_ { boost::asio::io_service ioservice; boost::thread_group threadpool; - std::auto_ptr < boost::asio::io_service::work > work(new boost::asio::io_service::work(ioservice)); + std::unique_ptr < boost::asio::io_service::work > work(new boost::asio::io_service::work(ioservice)); for (int i = 0; i < threads; i++) { threadpool.create_thread(boost::bind(&boost::asio::io_service::run, &ioservice)); @@ -1283,8 +1284,20 @@ void wallet2::store() std::string buf; bool r = ::serialization::dump_binary(cache_file_data, buf); - r = r && epee::file_io_utils::save_string_to_file(m_wallet_file, buf); THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_wallet_file); + + // save to new file, rename main to old, rename new to main + // at all times, there should be a valid file on disk + const std::string new_file = m_wallet_file + ".new"; + const std::string old_file = m_wallet_file + ".old"; + r = epee::file_io_utils::save_string_to_file(new_file, buf); + THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, new_file); + boost::filesystem::remove(old_file); // probably does not exist + std::error_code e = tools::replace_file(m_wallet_file, old_file); + THROW_WALLET_EXCEPTION_IF(e, error::file_save_error, m_wallet_file, e); + e = tools::replace_file(new_file, m_wallet_file); + THROW_WALLET_EXCEPTION_IF(e, error::file_save_error, m_wallet_file, e); + boost::filesystem::remove(old_file); } //---------------------------------------------------------------------------------------------------- uint64_t wallet2::unlocked_balance() const diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h index 94518e691..dd13343ed 100644 --- a/src/wallet/wallet_errors.h +++ b/src/wallet/wallet_errors.h @@ -192,6 +192,12 @@ namespace tools { } + explicit file_error_base(std::string&& loc, const std::string& file, const std::error_code &e) + : wallet_logic_error(std::move(loc), std::string(file_error_messages[msg_index]) + " \"" + file + "\": " + e.message()) + , m_file(file) + { + } + const std::string& file() const { return m_file; } std::string to_string() const { return wallet_logic_error::to_string(); } |