diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-10-20 20:49:23 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-11-14 17:15:19 +0000 |
commit | 0f2c2d4c34c100e226cf67758ee07fae36858893 (patch) | |
tree | 238d1b42a781fe957feb40f4462fbb92014927c2 /src/rpc/core_rpc_server.cpp | |
parent | Merge pull request #2756 (diff) | |
download | monero-0f2c2d4c34c100e226cf67758ee07fae36858893.tar.xz |
rpc: remove obsolete busy core checks
Diffstat (limited to 'src/rpc/core_rpc_server.cpp')
-rw-r--r-- | src/rpc/core_rpc_server.cpp | 128 |
1 files changed, 2 insertions, 126 deletions
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index f6932c659..5801e515c 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -106,23 +106,13 @@ namespace cryptonote ); } //------------------------------------------------------------------------------------------------------------------------------ - bool core_rpc_server::check_core_busy() - { - if(m_p2p.get_payload_object().get_core().get_blockchain_storage().is_storing_blockchain()) - { - return false; - } - return true; - } -#define CHECK_CORE_BUSY() do { if(!check_core_busy()){res.status = CORE_RPC_STATUS_BUSY;return true;} } while(0) - //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::check_core_ready() { if(!m_p2p.get_payload_object().is_synchronized()) { return false; } - return check_core_busy(); + return true; } #define CHECK_CORE_READY() do { if(!check_core_ready()){res.status = CORE_RPC_STATUS_BUSY;return true;} } while(0) @@ -130,7 +120,6 @@ namespace cryptonote bool core_rpc_server::on_get_height(const COMMAND_RPC_GET_HEIGHT::request& req, COMMAND_RPC_GET_HEIGHT::response& res) { PERF_TIMER(on_get_height); - CHECK_CORE_BUSY(); res.height = m_core.get_current_blockchain_height(); res.status = CORE_RPC_STATUS_OK; return true; @@ -139,7 +128,6 @@ namespace cryptonote bool core_rpc_server::on_get_info(const COMMAND_RPC_GET_INFO::request& req, COMMAND_RPC_GET_INFO::response& res) { PERF_TIMER(on_get_info); - CHECK_CORE_BUSY(); crypto::hash top_hash; m_core.get_blockchain_top(res.height, top_hash); ++res.height; // turn top block height into blockchain height @@ -184,7 +172,6 @@ namespace cryptonote bool core_rpc_server::on_get_blocks(const COMMAND_RPC_GET_BLOCKS_FAST::request& req, COMMAND_RPC_GET_BLOCKS_FAST::response& res) { PERF_TIMER(on_get_blocks); - CHECK_CORE_BUSY(); std::list<std::pair<cryptonote::blobdata, std::list<cryptonote::blobdata> > > bs; if(!m_core.find_blockchain_supplement(req.start_height, req.block_ids, bs, res.current_height, res.start_height, COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT)) @@ -244,7 +231,6 @@ namespace cryptonote bool core_rpc_server::on_get_alt_blocks_hashes(const COMMAND_RPC_GET_ALT_BLOCKS_HASHES::request& req, COMMAND_RPC_GET_ALT_BLOCKS_HASHES::response& res) { PERF_TIMER(on_get_alt_blocks_hashes); - CHECK_CORE_BUSY(); std::list<block> blks; if(!m_core.get_alternative_blocks(blks)) @@ -268,7 +254,6 @@ namespace cryptonote 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) { PERF_TIMER(on_get_blocks_by_height); - CHECK_CORE_BUSY(); res.status = "Failed"; res.blocks.clear(); res.blocks.reserve(req.heights.size()); @@ -299,7 +284,6 @@ namespace cryptonote bool core_rpc_server::on_get_hashes(const COMMAND_RPC_GET_HASHES_FAST::request& req, COMMAND_RPC_GET_HASHES_FAST::response& res) { PERF_TIMER(on_get_hashes); - CHECK_CORE_BUSY(); NOTIFY_RESPONSE_CHAIN_ENTRY::request resp; resp.start_height = req.start_height; @@ -319,7 +303,6 @@ namespace cryptonote bool core_rpc_server::on_get_random_outs(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res) { PERF_TIMER(on_get_random_outs); - CHECK_CORE_BUSY(); res.status = "Failed"; if (m_restricted) @@ -359,7 +342,6 @@ namespace cryptonote bool core_rpc_server::on_get_outs_bin(const COMMAND_RPC_GET_OUTPUTS_BIN::request& req, COMMAND_RPC_GET_OUTPUTS_BIN::response& res) { PERF_TIMER(on_get_outs_bin); - CHECK_CORE_BUSY(); res.status = "Failed"; if (m_restricted) @@ -383,7 +365,6 @@ namespace cryptonote bool core_rpc_server::on_get_outs(const COMMAND_RPC_GET_OUTPUTS::request& req, COMMAND_RPC_GET_OUTPUTS::response& res) { PERF_TIMER(on_get_outs); - CHECK_CORE_BUSY(); res.status = "Failed"; if (m_restricted) @@ -422,7 +403,6 @@ namespace cryptonote bool core_rpc_server::on_get_random_rct_outs(const COMMAND_RPC_GET_RANDOM_RCT_OUTPUTS::request& req, COMMAND_RPC_GET_RANDOM_RCT_OUTPUTS::response& res) { PERF_TIMER(on_get_random_rct_outs); - CHECK_CORE_BUSY(); res.status = "Failed"; if(!m_core.get_random_rct_outs(req, res)) { @@ -447,7 +427,6 @@ namespace cryptonote bool core_rpc_server::on_get_indexes(const COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request& req, COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response& res) { PERF_TIMER(on_get_indexes); - CHECK_CORE_BUSY(); bool r = m_core.get_tx_outputs_gindexs(req.txid, res.o_indexes); if(!r) { @@ -462,7 +441,6 @@ namespace cryptonote bool core_rpc_server::on_get_transactions(const COMMAND_RPC_GET_TRANSACTIONS::request& req, COMMAND_RPC_GET_TRANSACTIONS::response& res) { PERF_TIMER(on_get_transactions); - CHECK_CORE_BUSY(); std::vector<crypto::hash> vh; for(const auto& tx_hex_str: req.txs_hashes) { @@ -608,7 +586,6 @@ namespace cryptonote bool core_rpc_server::on_is_key_image_spent(const COMMAND_RPC_IS_KEY_IMAGE_SPENT::request& req, COMMAND_RPC_IS_KEY_IMAGE_SPENT::response& res, bool request_has_rpc_origin) { PERF_TIMER(on_is_key_image_spent); - CHECK_CORE_BUSY(); std::vector<crypto::key_image> key_images; for(const auto& ki_hex_str: req.key_images) { @@ -797,7 +774,6 @@ namespace cryptonote bool core_rpc_server::on_mining_status(const COMMAND_RPC_MINING_STATUS::request& req, COMMAND_RPC_MINING_STATUS::response& res) { PERF_TIMER(on_mining_status); - CHECK_CORE_BUSY(); const miner& lMiner = m_core.get_miner(); res.active = lMiner.is_mining(); @@ -817,7 +793,6 @@ namespace cryptonote bool core_rpc_server::on_save_bc(const COMMAND_RPC_SAVE_BC::request& req, COMMAND_RPC_SAVE_BC::response& res) { PERF_TIMER(on_save_bc); - CHECK_CORE_BUSY(); if( !m_core.get_blockchain_storage().store_blockchain() ) { res.status = "Error while storing blockhain"; @@ -897,7 +872,6 @@ namespace cryptonote bool core_rpc_server::on_get_transaction_pool(const COMMAND_RPC_GET_TRANSACTION_POOL::request& req, COMMAND_RPC_GET_TRANSACTION_POOL::response& res, bool request_has_rpc_origin) { PERF_TIMER(on_get_transaction_pool); - CHECK_CORE_BUSY(); m_core.get_pool_transactions_and_spent_keys_info(res.transactions, res.spent_key_images, !request_has_rpc_origin || !m_restricted); res.status = CORE_RPC_STATUS_OK; return true; @@ -906,7 +880,6 @@ namespace cryptonote bool core_rpc_server::on_get_transaction_pool_hashes(const COMMAND_RPC_GET_TRANSACTION_POOL_HASHES::request& req, COMMAND_RPC_GET_TRANSACTION_POOL_HASHES::response& res, bool request_has_rpc_origin) { PERF_TIMER(on_get_transaction_pool_hashes); - CHECK_CORE_BUSY(); m_core.get_pool_transaction_hashes(res.tx_hashes, !request_has_rpc_origin || !m_restricted); res.status = CORE_RPC_STATUS_OK; return true; @@ -915,7 +888,6 @@ namespace cryptonote 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, bool request_has_rpc_origin) { PERF_TIMER(on_get_transaction_pool_stats); - CHECK_CORE_BUSY(); m_core.get_pool_transaction_stats(res.pool_stats, !request_has_rpc_origin || !m_restricted); res.status = CORE_RPC_STATUS_OK; return true; @@ -934,7 +906,6 @@ namespace cryptonote bool core_rpc_server::on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res) { PERF_TIMER(on_getblockcount); - CHECK_CORE_BUSY(); res.count = m_core.get_current_blockchain_height(); res.status = CORE_RPC_STATUS_OK; return true; @@ -943,12 +914,6 @@ namespace cryptonote bool core_rpc_server::on_getblockhash(const COMMAND_RPC_GETBLOCKHASH::request& req, COMMAND_RPC_GETBLOCKHASH::response& res, epee::json_rpc::error& error_resp) { PERF_TIMER(on_getblockhash); - if(!check_core_busy()) - { - error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY; - error_resp.message = "Core is busy"; - return false; - } if(req.size() != 1) { error_resp.code = CORE_RPC_ERROR_CODE_WRONG_PARAM; @@ -1136,12 +1101,7 @@ namespace cryptonote bool core_rpc_server::on_get_last_block_header(const COMMAND_RPC_GET_LAST_BLOCK_HEADER::request& req, COMMAND_RPC_GET_LAST_BLOCK_HEADER::response& res, epee::json_rpc::error& error_resp) { PERF_TIMER(on_get_last_block_header); - if(!check_core_busy()) - { - error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY; - error_resp.message = "Core is busy."; - return false; - } + CHECK_CORE_READY(); uint64_t last_block_height; crypto::hash last_block_hash; m_core.get_blockchain_top(last_block_height, last_block_hash); @@ -1166,12 +1126,6 @@ namespace cryptonote //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::on_get_block_header_by_hash(const COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::request& req, COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::response& res, epee::json_rpc::error& error_resp){ PERF_TIMER(on_get_block_header_by_hash); - if(!check_core_busy()) - { - error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY; - error_resp.message = "Core is busy."; - return false; - } crypto::hash block_hash; bool hash_parsed = parse_hash256(req.hash, block_hash); if(!hash_parsed) @@ -1209,12 +1163,6 @@ namespace cryptonote //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::on_get_block_headers_range(const COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::request& req, COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::response& res, epee::json_rpc::error& error_resp){ PERF_TIMER(on_get_block_headers_range); - if(!check_core_busy()) - { - error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY; - error_resp.message = "Core is busy."; - return false; - } const uint64_t bc_height = m_core.get_current_blockchain_height(); if (req.start_height >= bc_height || req.end_height >= bc_height || req.start_height > req.end_height) { @@ -1261,12 +1209,6 @@ namespace cryptonote //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::on_get_block_header_by_height(const COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::request& req, COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::response& res, epee::json_rpc::error& error_resp){ PERF_TIMER(on_get_block_header_by_height); - if(!check_core_busy()) - { - error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY; - error_resp.message = "Core is busy."; - return false; - } if(m_core.get_current_blockchain_height() <= req.height) { error_resp.code = CORE_RPC_ERROR_CODE_TOO_BIG_HEIGHT; @@ -1295,12 +1237,6 @@ namespace cryptonote //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::on_get_block(const COMMAND_RPC_GET_BLOCK::request& req, COMMAND_RPC_GET_BLOCK::response& res, epee::json_rpc::error& error_resp){ PERF_TIMER(on_get_block); - if(!check_core_busy()) - { - error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY; - error_resp.message = "Core is busy."; - return false; - } crypto::hash block_hash; if (!req.hash.empty()) { @@ -1359,12 +1295,6 @@ namespace cryptonote bool core_rpc_server::on_get_connections(const COMMAND_RPC_GET_CONNECTIONS::request& req, COMMAND_RPC_GET_CONNECTIONS::response& res, epee::json_rpc::error& error_resp) { PERF_TIMER(on_get_connections); - if(!check_core_busy()) - { - error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY; - error_resp.message = "Core is busy."; - return false; - } res.connections = m_p2p.get_payload_object().get_connections(); @@ -1376,12 +1306,6 @@ namespace cryptonote bool core_rpc_server::on_get_info_json(const COMMAND_RPC_GET_INFO::request& req, COMMAND_RPC_GET_INFO::response& res, epee::json_rpc::error& error_resp) { PERF_TIMER(on_get_info_json); - if(!check_core_busy()) - { - error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY; - error_resp.message = "Core is busy."; - return false; - } crypto::hash top_hash; m_core.get_blockchain_top(res.height, top_hash); @@ -1410,12 +1334,6 @@ namespace cryptonote bool core_rpc_server::on_hard_fork_info(const COMMAND_RPC_HARD_FORK_INFO::request& req, COMMAND_RPC_HARD_FORK_INFO::response& res, epee::json_rpc::error& error_resp) { PERF_TIMER(on_hard_fork_info); - if(!check_core_busy()) - { - error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY; - error_resp.message = "Core is busy."; - return false; - } const Blockchain &blockchain = m_core.get_blockchain_storage(); uint8_t version = req.version > 0 ? req.version : blockchain.get_next_hard_fork_version(); @@ -1429,12 +1347,6 @@ namespace cryptonote bool core_rpc_server::on_get_bans(const COMMAND_RPC_GETBANS::request& req, COMMAND_RPC_GETBANS::response& res, epee::json_rpc::error& error_resp) { PERF_TIMER(on_get_bans); - if(!check_core_busy()) - { - error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY; - error_resp.message = "Core is busy."; - return false; - } auto now = time(nullptr); std::map<std::string, time_t> blocked_hosts = m_p2p.get_blocked_hosts(); @@ -1459,12 +1371,6 @@ namespace cryptonote bool core_rpc_server::on_set_bans(const COMMAND_RPC_SETBANS::request& req, COMMAND_RPC_SETBANS::response& res, epee::json_rpc::error& error_resp) { PERF_TIMER(on_set_bans); - if(!check_core_busy()) - { - error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY; - error_resp.message = "Core is busy."; - return false; - } for (auto i = req.bans.begin(); i != req.bans.end(); ++i) { @@ -1495,12 +1401,6 @@ namespace cryptonote bool core_rpc_server::on_flush_txpool(const COMMAND_RPC_FLUSH_TRANSACTION_POOL::request& req, COMMAND_RPC_FLUSH_TRANSACTION_POOL::response& res, epee::json_rpc::error& error_resp) { PERF_TIMER(on_flush_txpool); - if(!check_core_busy()) - { - error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY; - error_resp.message = "Core is busy."; - return false; - } bool failed = false; std::list<crypto::hash> txids; @@ -1550,12 +1450,6 @@ namespace cryptonote bool core_rpc_server::on_get_output_histogram(const COMMAND_RPC_GET_OUTPUT_HISTOGRAM::request& req, COMMAND_RPC_GET_OUTPUT_HISTOGRAM::response& res, epee::json_rpc::error& error_resp) { PERF_TIMER(on_get_output_histogram); - if(!check_core_busy()) - { - error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY; - error_resp.message = "Core is busy."; - return false; - } std::map<uint64_t, std::tuple<uint64_t, uint64_t, uint64_t>> histogram; try @@ -1800,12 +1694,6 @@ namespace cryptonote bool core_rpc_server::on_relay_tx(const COMMAND_RPC_RELAY_TX::request& req, COMMAND_RPC_RELAY_TX::response& res, epee::json_rpc::error& error_resp) { PERF_TIMER(on_relay_tx); - if(!check_core_busy()) - { - error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY; - error_resp.message = "Core is busy."; - return false; - } bool failed = false; for (const auto &str: req.txids) @@ -1847,12 +1735,6 @@ namespace cryptonote bool core_rpc_server::on_sync_info(const COMMAND_RPC_SYNC_INFO::request& req, COMMAND_RPC_SYNC_INFO::response& res, epee::json_rpc::error& error_resp) { PERF_TIMER(on_sync_info); - if(!check_core_busy()) - { - error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY; - error_resp.message = "Core is busy."; - return false; - } crypto::hash top_hash; m_core.get_blockchain_top(res.height, top_hash); @@ -1879,12 +1761,6 @@ namespace cryptonote bool core_rpc_server::on_get_txpool_backlog(const COMMAND_RPC_GET_TRANSACTION_POOL_BACKLOG::request& req, COMMAND_RPC_GET_TRANSACTION_POOL_BACKLOG::response& res, epee::json_rpc::error& error_resp) { PERF_TIMER(on_get_txpool_backlog); - if(!check_core_busy()) - { - error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY; - error_resp.message = "Core is busy."; - return false; - } if (!m_core.get_txpool_backlog(res.backlog)) { |