rpc: remove obsolete busy core checks

This commit is contained in:
moneromooo-monero 2017-10-20 20:49:23 +01:00
parent f48aeab5c4
commit 0f2c2d4c34
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3
2 changed files with 2 additions and 136 deletions

View File

@ -634,16 +634,6 @@ namespace cryptonote
*/ */
uint64_t get_current_cumulative_blocksize_limit() const; uint64_t get_current_cumulative_blocksize_limit() const;
/**
* @brief checks if the blockchain is currently being stored
*
* Note: this should be meaningless in cases where Blockchain is not
* directly managing saving the blockchain to disk.
*
* @return true if Blockchain is having the chain stored currently, else false
*/
bool is_storing_blockchain()const{return false;}
/** /**
* @brief gets the difficulty of the block with a given height * @brief gets the difficulty of the block with a given height
* *

View File

@ -105,16 +105,6 @@ namespace cryptonote
std::move(port), std::move(rpc_config->bind_ip), std::move(rpc_config->access_control_origins), std::move(http_login) std::move(port), std::move(rpc_config->bind_ip), std::move(rpc_config->access_control_origins), std::move(http_login)
); );
} }
//------------------------------------------------------------------------------------------------------------------------------
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() bool core_rpc_server::check_core_ready()
{ {
@ -122,7 +112,7 @@ namespace cryptonote
{ {
return false; 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) #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) 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); PERF_TIMER(on_get_height);
CHECK_CORE_BUSY();
res.height = m_core.get_current_blockchain_height(); res.height = m_core.get_current_blockchain_height();
res.status = CORE_RPC_STATUS_OK; res.status = CORE_RPC_STATUS_OK;
return true; 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) 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); PERF_TIMER(on_get_info);
CHECK_CORE_BUSY();
crypto::hash top_hash; crypto::hash top_hash;
m_core.get_blockchain_top(res.height, top_hash); m_core.get_blockchain_top(res.height, top_hash);
++res.height; // turn top block height into blockchain height ++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) 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); PERF_TIMER(on_get_blocks);
CHECK_CORE_BUSY();
std::list<std::pair<cryptonote::blobdata, std::list<cryptonote::blobdata> > > bs; 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)) 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) 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); PERF_TIMER(on_get_alt_blocks_hashes);
CHECK_CORE_BUSY();
std::list<block> blks; std::list<block> blks;
if(!m_core.get_alternative_blocks(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) 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); PERF_TIMER(on_get_blocks_by_height);
CHECK_CORE_BUSY();
res.status = "Failed"; res.status = "Failed";
res.blocks.clear(); res.blocks.clear();
res.blocks.reserve(req.heights.size()); 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) 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); PERF_TIMER(on_get_hashes);
CHECK_CORE_BUSY();
NOTIFY_RESPONSE_CHAIN_ENTRY::request resp; NOTIFY_RESPONSE_CHAIN_ENTRY::request resp;
resp.start_height = req.start_height; 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) 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); PERF_TIMER(on_get_random_outs);
CHECK_CORE_BUSY();
res.status = "Failed"; res.status = "Failed";
if (m_restricted) 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) 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); PERF_TIMER(on_get_outs_bin);
CHECK_CORE_BUSY();
res.status = "Failed"; res.status = "Failed";
if (m_restricted) 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) 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); PERF_TIMER(on_get_outs);
CHECK_CORE_BUSY();
res.status = "Failed"; res.status = "Failed";
if (m_restricted) 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) 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); PERF_TIMER(on_get_random_rct_outs);
CHECK_CORE_BUSY();
res.status = "Failed"; res.status = "Failed";
if(!m_core.get_random_rct_outs(req, res)) 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) 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); PERF_TIMER(on_get_indexes);
CHECK_CORE_BUSY();
bool r = m_core.get_tx_outputs_gindexs(req.txid, res.o_indexes); bool r = m_core.get_tx_outputs_gindexs(req.txid, res.o_indexes);
if(!r) 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) 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); PERF_TIMER(on_get_transactions);
CHECK_CORE_BUSY();
std::vector<crypto::hash> vh; std::vector<crypto::hash> vh;
for(const auto& tx_hex_str: req.txs_hashes) 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) 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); PERF_TIMER(on_is_key_image_spent);
CHECK_CORE_BUSY();
std::vector<crypto::key_image> key_images; std::vector<crypto::key_image> key_images;
for(const auto& ki_hex_str: req.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) 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); PERF_TIMER(on_mining_status);
CHECK_CORE_BUSY();
const miner& lMiner = m_core.get_miner(); const miner& lMiner = m_core.get_miner();
res.active = lMiner.is_mining(); 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) 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); PERF_TIMER(on_save_bc);
CHECK_CORE_BUSY();
if( !m_core.get_blockchain_storage().store_blockchain() ) if( !m_core.get_blockchain_storage().store_blockchain() )
{ {
res.status = "Error while storing blockhain"; 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) 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); 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); 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; res.status = CORE_RPC_STATUS_OK;
return true; 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) 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); 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); m_core.get_pool_transaction_hashes(res.tx_hashes, !request_has_rpc_origin || !m_restricted);
res.status = CORE_RPC_STATUS_OK; res.status = CORE_RPC_STATUS_OK;
return true; 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) 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); 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); m_core.get_pool_transaction_stats(res.pool_stats, !request_has_rpc_origin || !m_restricted);
res.status = CORE_RPC_STATUS_OK; res.status = CORE_RPC_STATUS_OK;
return true; 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) bool core_rpc_server::on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res)
{ {
PERF_TIMER(on_getblockcount); PERF_TIMER(on_getblockcount);
CHECK_CORE_BUSY();
res.count = m_core.get_current_blockchain_height(); res.count = m_core.get_current_blockchain_height();
res.status = CORE_RPC_STATUS_OK; res.status = CORE_RPC_STATUS_OK;
return true; 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) 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); 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) if(req.size() != 1)
{ {
error_resp.code = CORE_RPC_ERROR_CODE_WRONG_PARAM; 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) 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); PERF_TIMER(on_get_last_block_header);
if(!check_core_busy()) CHECK_CORE_READY();
{
error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
error_resp.message = "Core is busy.";
return false;
}
uint64_t last_block_height; uint64_t last_block_height;
crypto::hash last_block_hash; crypto::hash last_block_hash;
m_core.get_blockchain_top(last_block_height, 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){ 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); 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; crypto::hash block_hash;
bool hash_parsed = parse_hash256(req.hash, block_hash); bool hash_parsed = parse_hash256(req.hash, block_hash);
if(!hash_parsed) 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){ 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); 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(); 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) 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){ 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); 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) if(m_core.get_current_blockchain_height() <= req.height)
{ {
error_resp.code = CORE_RPC_ERROR_CODE_TOO_BIG_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){ 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); 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; crypto::hash block_hash;
if (!req.hash.empty()) 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) 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); 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(); 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) 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); 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; crypto::hash top_hash;
m_core.get_blockchain_top(res.height, 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) 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); 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(); const Blockchain &blockchain = m_core.get_blockchain_storage();
uint8_t version = req.version > 0 ? req.version : blockchain.get_next_hard_fork_version(); 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) 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); 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); auto now = time(nullptr);
std::map<std::string, time_t> blocked_hosts = m_p2p.get_blocked_hosts(); 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) 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); 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) 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) 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); 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; bool failed = false;
std::list<crypto::hash> txids; 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) 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); 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; std::map<uint64_t, std::tuple<uint64_t, uint64_t, uint64_t>> histogram;
try 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) 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); 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; bool failed = false;
for (const auto &str: req.txids) 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) 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); 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; crypto::hash top_hash;
m_core.get_blockchain_top(res.height, 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) 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); 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)) if (!m_core.get_txpool_backlog(res.backlog))
{ {