diff options
author | Riccardo Spagni <ric@spagni.net> | 2017-11-25 19:48:33 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2017-11-25 19:48:33 +0200 |
commit | ed2fc4a1ffaf2af5d96545332db367e7033e8c1a (patch) | |
tree | 2d86cb3921ac2b15dc239b9a7c66e4c7d88ce20e /src | |
parent | Merge pull request #2793 (diff) | |
parent | core: warn when free disk space is low (diff) | |
download | monero-ed2fc4a1ffaf2af5d96545332db367e7033e8c1a.tar.xz |
Merge pull request #2794
43f27c7d core: warn when free disk space is low (moneromooo-monero)
Diffstat (limited to 'src')
-rw-r--r-- | src/cryptonote_core/cryptonote_core.cpp | 19 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_core.h | 15 | ||||
-rw-r--r-- | src/rpc/core_rpc_server.cpp | 2 | ||||
-rw-r--r-- | src/rpc/core_rpc_server_commands_defs.h | 2 |
4 files changed, 38 insertions, 0 deletions
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index acc76a8d6..5c181208f 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -1336,6 +1336,7 @@ namespace cryptonote m_fork_moaner.do_call(boost::bind(&core::check_fork_time, this)); m_txpool_auto_relayer.do_call(boost::bind(&core::relay_txpool_transactions, this)); m_check_updates_interval.do_call(boost::bind(&core::check_updates, this)); + m_check_disk_space_interval.do_call(boost::bind(&core::check_disk_space, this)); m_miner.on_idle(); m_mempool.on_idle(); return true; @@ -1467,6 +1468,17 @@ namespace cryptonote return true; } //----------------------------------------------------------------------------------------------- + bool core::check_disk_space() + { + uint64_t free_space = get_free_space(); + if (free_space < 1ull * 1024 * 1024 * 1024) // 1 GB + { + const el::Level level = el::Level::Warning; + MCLOG_RED(level, "global", "Free space is below 1 GB on " << m_config_folder); + } + return true; + } + //----------------------------------------------------------------------------------------------- void core::set_target_blockchain_height(uint64_t target_blockchain_height) { m_target_blockchain_height = target_blockchain_height; @@ -1482,6 +1494,13 @@ namespace cryptonote return get_blockchain_storage().prevalidate_block_hashes(height, hashes); } //----------------------------------------------------------------------------------------------- + uint64_t core::get_free_space() const + { + boost::filesystem::path path(m_config_folder); + boost::filesystem::space_info si = boost::filesystem::space(path); + return si.available; + } + //----------------------------------------------------------------------------------------------- std::time_t core::get_start_time() const { return start_time; diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index dc014206d..905e67f6d 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -766,6 +766,13 @@ namespace cryptonote */ uint64_t prevalidate_block_hashes(uint64_t height, const std::list<crypto::hash> &hashes); + /** + * @brief get free disk space on the blockchain partition + * + * @return free space in bytes + */ + uint64_t get_free_space() const; + private: /** @@ -925,6 +932,13 @@ namespace cryptonote */ bool check_updates(); + /** + * @brief checks free disk space + * + * @return true on success, false otherwise + */ + bool check_disk_space(); + 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 @@ -948,6 +962,7 @@ namespace cryptonote epee::math_helper::once_a_time_seconds<60*60*2, true> m_fork_moaner; //!< interval for checking HardFork status epee::math_helper::once_a_time_seconds<60*2, false> m_txpool_auto_relayer; //!< interval for checking re-relaying txpool transactions epee::math_helper::once_a_time_seconds<60*60*12, true> m_check_updates_interval; //!< interval for checking for new versions + epee::math_helper::once_a_time_seconds<60*10, true> m_check_disk_space_interval; //!< interval for checking for disk space std::atomic<bool> m_starter_message_showed; //!< has the "daemon will sync now" message been shown? diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 6e7fb7e8e..e9a6a18aa 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -149,6 +149,7 @@ namespace cryptonote res.block_size_limit = m_core.get_blockchain_storage().get_current_cumulative_blocksize_limit(); res.status = CORE_RPC_STATUS_OK; res.start_time = (uint64_t)m_core.get_start_time(); + res.free_space = m_restricted ? std::numeric_limits<uint64_t>::max() : m_core.get_free_space(); return true; } //------------------------------------------------------------------------------------------------------------------------------ @@ -1328,6 +1329,7 @@ namespace cryptonote res.block_size_limit = m_core.get_blockchain_storage().get_current_cumulative_blocksize_limit(); res.status = CORE_RPC_STATUS_OK; res.start_time = (uint64_t)m_core.get_start_time(); + res.free_space = m_restricted ? std::numeric_limits<uint64_t>::max() : m_core.get_free_space(); return true; } //------------------------------------------------------------------------------------------------------------------------------ diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 15b4b503a..d27d5611e 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -927,6 +927,7 @@ namespace cryptonote uint64_t cumulative_difficulty; uint64_t block_size_limit; uint64_t start_time; + uint64_t free_space; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(status) @@ -947,6 +948,7 @@ namespace cryptonote KV_SERIALIZE(cumulative_difficulty) KV_SERIALIZE(block_size_limit) KV_SERIALIZE(start_time) + KV_SERIALIZE(free_space) END_KV_SERIALIZE_MAP() }; }; |