Merge pull request #9383

9f83e74 Daemon RPC: /getblocks.bin return chain's top_block_hash in resp (j-berman)
This commit is contained in:
luigi1111 2024-07-16 19:00:39 -04:00
commit 330212888a
No known key found for this signature in database
GPG Key ID: F4ACA0183641E010
8 changed files with 17 additions and 9 deletions

View File

@ -2765,7 +2765,7 @@ bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qbloc
// find split point between ours and foreign blockchain (or start at // find split point between ours and foreign blockchain (or start at
// blockchain height <req_start_block>), and return up to max_count FULL // blockchain height <req_start_block>), and return up to max_count FULL
// blocks by reference. // blocks by reference.
bool Blockchain::find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::vector<std::pair<std::pair<cryptonote::blobdata, crypto::hash>, std::vector<std::pair<crypto::hash, cryptonote::blobdata> > > >& blocks, uint64_t& total_height, uint64_t& start_height, bool pruned, bool get_miner_tx_hash, size_t max_block_count, size_t max_tx_count) const bool Blockchain::find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::vector<std::pair<std::pair<cryptonote::blobdata, crypto::hash>, std::vector<std::pair<crypto::hash, cryptonote::blobdata> > > >& blocks, uint64_t& total_height, crypto::hash& top_hash, uint64_t& start_height, bool pruned, bool get_miner_tx_hash, size_t max_block_count, size_t max_tx_count) const
{ {
LOG_PRINT_L3("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
@ -2774,7 +2774,9 @@ bool Blockchain::find_blockchain_supplement(const uint64_t req_start_block, cons
if(req_start_block > 0) if(req_start_block > 0)
{ {
// if requested height is higher than our chain, return false -- we can't help // if requested height is higher than our chain, return false -- we can't help
if (req_start_block >= m_db->height()) top_hash = m_db->top_block_hash(&total_height);
++total_height;
if (req_start_block >= total_height)
{ {
return false; return false;
} }
@ -2789,7 +2791,8 @@ bool Blockchain::find_blockchain_supplement(const uint64_t req_start_block, cons
} }
db_rtxn_guard rtxn_guard(m_db); db_rtxn_guard rtxn_guard(m_db);
total_height = get_current_blockchain_height(); top_hash = m_db->top_block_hash(&total_height);
++total_height;
blocks.reserve(std::min(std::min(max_block_count, (size_t)10000), (size_t)(total_height - start_height))); blocks.reserve(std::min(std::min(max_block_count, (size_t)10000), (size_t)(total_height - start_height)));
CHECK_AND_ASSERT_MES(m_db->get_blocks_from(start_height, 3, max_block_count, max_tx_count, FIND_BLOCKCHAIN_SUPPLEMENT_MAX_SIZE, blocks, pruned, true, get_miner_tx_hash), CHECK_AND_ASSERT_MES(m_db->get_blocks_from(start_height, 3, max_block_count, max_tx_count, FIND_BLOCKCHAIN_SUPPLEMENT_MAX_SIZE, blocks, pruned, true, get_miner_tx_hash),
false, "Error getting blocks"); false, "Error getting blocks");

View File

@ -485,6 +485,7 @@ namespace cryptonote
* @param qblock_ids the foreign chain's "short history" (see get_short_chain_history) * @param qblock_ids the foreign chain's "short history" (see get_short_chain_history)
* @param blocks return-by-reference the blocks and their transactions * @param blocks return-by-reference the blocks and their transactions
* @param total_height return-by-reference our current blockchain height * @param total_height return-by-reference our current blockchain height
* @param top_hash return-by-reference top block hash
* @param start_height return-by-reference the height of the first block returned * @param start_height return-by-reference the height of the first block returned
* @param pruned whether to return full or pruned tx blobs * @param pruned whether to return full or pruned tx blobs
* @param max_block_count the max number of blocks to get * @param max_block_count the max number of blocks to get
@ -492,7 +493,7 @@ namespace cryptonote
* *
* @return true if a block found in common or req_start_block specified, else false * @return true if a block found in common or req_start_block specified, else false
*/ */
bool find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::vector<std::pair<std::pair<cryptonote::blobdata, crypto::hash>, std::vector<std::pair<crypto::hash, cryptonote::blobdata> > > >& blocks, uint64_t& total_height, uint64_t& start_height, bool pruned, bool get_miner_tx_hash, size_t max_block_count, size_t max_tx_count) const; bool find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::vector<std::pair<std::pair<cryptonote::blobdata, crypto::hash>, std::vector<std::pair<crypto::hash, cryptonote::blobdata> > > >& blocks, uint64_t& total_height, crypto::hash& top_hash, uint64_t& start_height, bool pruned, bool get_miner_tx_hash, size_t max_block_count, size_t max_tx_count) const;
/** /**
* @brief retrieves a set of blocks and their transactions, and possibly other transactions * @brief retrieves a set of blocks and their transactions, and possibly other transactions

View File

@ -1488,9 +1488,9 @@ namespace cryptonote
return m_blockchain_storage.find_blockchain_supplement(qblock_ids, clip_pruned, resp); return m_blockchain_storage.find_blockchain_supplement(qblock_ids, clip_pruned, resp);
} }
//----------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
bool core::find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::vector<std::pair<std::pair<cryptonote::blobdata, crypto::hash>, std::vector<std::pair<crypto::hash, cryptonote::blobdata> > > >& blocks, uint64_t& total_height, uint64_t& start_height, bool pruned, bool get_miner_tx_hash, size_t max_block_count, size_t max_tx_count) const bool core::find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::vector<std::pair<std::pair<cryptonote::blobdata, crypto::hash>, std::vector<std::pair<crypto::hash, cryptonote::blobdata> > > >& blocks, uint64_t& total_height, crypto::hash& top_hash, uint64_t& start_height, bool pruned, bool get_miner_tx_hash, size_t max_block_count, size_t max_tx_count) const
{ {
return m_blockchain_storage.find_blockchain_supplement(req_start_block, qblock_ids, blocks, total_height, start_height, pruned, get_miner_tx_hash, max_block_count, max_tx_count); return m_blockchain_storage.find_blockchain_supplement(req_start_block, qblock_ids, blocks, total_height, top_hash, start_height, pruned, get_miner_tx_hash, max_block_count, max_tx_count);
} }
//----------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
bool core::get_outs(const COMMAND_RPC_GET_OUTPUTS_BIN::request& req, COMMAND_RPC_GET_OUTPUTS_BIN::response& res) const bool core::get_outs(const COMMAND_RPC_GET_OUTPUTS_BIN::request& req, COMMAND_RPC_GET_OUTPUTS_BIN::response& res) const

View File

@ -597,7 +597,7 @@ namespace cryptonote
* *
* @note see Blockchain::find_blockchain_supplement(const uint64_t, const std::list<crypto::hash>&, std::vector<std::pair<cryptonote::blobdata, std::vector<transaction> > >&, uint64_t&, uint64_t&, size_t) const * @note see Blockchain::find_blockchain_supplement(const uint64_t, const std::list<crypto::hash>&, std::vector<std::pair<cryptonote::blobdata, std::vector<transaction> > >&, uint64_t&, uint64_t&, size_t) const
*/ */
bool find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::vector<std::pair<std::pair<cryptonote::blobdata, crypto::hash>, std::vector<std::pair<crypto::hash, cryptonote::blobdata> > > >& blocks, uint64_t& total_height, uint64_t& start_height, bool pruned, bool get_miner_tx_hash, size_t max_block_count, size_t max_tx_count) const; bool find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::vector<std::pair<std::pair<cryptonote::blobdata, crypto::hash>, std::vector<std::pair<crypto::hash, cryptonote::blobdata> > > >& blocks, uint64_t& total_height, crypto::hash& top_hash, uint64_t& start_height, bool pruned, bool get_miner_tx_hash, size_t max_block_count, size_t max_tx_count) const;
/** /**
* @copydoc Blockchain::get_tx_outputs_gindexs * @copydoc Blockchain::get_tx_outputs_gindexs

View File

@ -719,6 +719,7 @@ namespace cryptonote
{ {
res.start_height = 0; res.start_height = 0;
res.current_height = last_block_height + 1; res.current_height = last_block_height + 1;
res.top_block_hash = last_block_hash;
res.status = CORE_RPC_STATUS_OK; res.status = CORE_RPC_STATUS_OK;
return true; return true;
} }
@ -738,7 +739,7 @@ namespace cryptonote
} }
std::vector<std::pair<std::pair<cryptonote::blobdata, crypto::hash>, std::vector<std::pair<crypto::hash, cryptonote::blobdata> > > > bs; std::vector<std::pair<std::pair<cryptonote::blobdata, crypto::hash>, std::vector<std::pair<crypto::hash, cryptonote::blobdata> > > > bs;
if(!m_core.find_blockchain_supplement(req.start_height, req.block_ids, bs, res.current_height, res.start_height, req.prune, !req.no_miner_tx, max_blocks, COMMAND_RPC_GET_BLOCKS_FAST_MAX_TX_COUNT)) if(!m_core.find_blockchain_supplement(req.start_height, req.block_ids, bs, res.current_height, res.top_block_hash, res.start_height, req.prune, !req.no_miner_tx, max_blocks, COMMAND_RPC_GET_BLOCKS_FAST_MAX_TX_COUNT))
{ {
res.status = "Failed"; res.status = "Failed";
add_host_fail(ctx); add_host_fail(ctx);

View File

@ -247,6 +247,7 @@ inline const std::string get_rpc_status(const bool trusted_daemon, const std::st
std::vector<block_complete_entry> blocks; std::vector<block_complete_entry> blocks;
uint64_t start_height; uint64_t start_height;
uint64_t current_height; uint64_t current_height;
crypto::hash top_block_hash;
std::vector<block_output_indices> output_indices; std::vector<block_output_indices> output_indices;
uint64_t daemon_time; uint64_t daemon_time;
uint8_t pool_info_extent; uint8_t pool_info_extent;
@ -259,6 +260,7 @@ inline const std::string get_rpc_status(const bool trusted_daemon, const std::st
KV_SERIALIZE(blocks) KV_SERIALIZE(blocks)
KV_SERIALIZE(start_height) KV_SERIALIZE(start_height)
KV_SERIALIZE(current_height) KV_SERIALIZE(current_height)
KV_SERIALIZE_VAL_POD_AS_BLOB_OPT(top_block_hash, crypto::null_hash)
KV_SERIALIZE(output_indices) KV_SERIALIZE(output_indices)
KV_SERIALIZE_OPT(daemon_time, (uint64_t) 0) KV_SERIALIZE_OPT(daemon_time, (uint64_t) 0)
KV_SERIALIZE_OPT(pool_info_extent, (uint8_t) 0) KV_SERIALIZE_OPT(pool_info_extent, (uint8_t) 0)

View File

@ -128,7 +128,7 @@ namespace rpc
{ {
std::vector<std::pair<std::pair<blobdata, crypto::hash>, std::vector<std::pair<crypto::hash, blobdata> > > > blocks; std::vector<std::pair<std::pair<blobdata, crypto::hash>, std::vector<std::pair<crypto::hash, blobdata> > > > blocks;
if(!m_core.find_blockchain_supplement(req.start_height, req.block_ids, blocks, res.current_height, res.start_height, req.prune, true, COMMAND_RPC_GET_BLOCKS_FAST_MAX_BLOCK_COUNT, COMMAND_RPC_GET_BLOCKS_FAST_MAX_TX_COUNT)) if(!m_core.find_blockchain_supplement(req.start_height, req.block_ids, blocks, res.current_height, res.top_block_hash, res.start_height, req.prune, true, COMMAND_RPC_GET_BLOCKS_FAST_MAX_BLOCK_COUNT, COMMAND_RPC_GET_BLOCKS_FAST_MAX_TX_COUNT))
{ {
res.status = Message::STATUS_FAILED; res.status = Message::STATUS_FAILED;
res.error_details = "core::find_blockchain_supplement() returned false"; res.error_details = "core::find_blockchain_supplement() returned false";

View File

@ -97,6 +97,7 @@ BEGIN_RPC_MESSAGE_CLASS(GetBlocksFast);
RPC_MESSAGE_MEMBER(std::vector<cryptonote::rpc::block_with_transactions>, blocks); RPC_MESSAGE_MEMBER(std::vector<cryptonote::rpc::block_with_transactions>, blocks);
RPC_MESSAGE_MEMBER(uint64_t, start_height); RPC_MESSAGE_MEMBER(uint64_t, start_height);
RPC_MESSAGE_MEMBER(uint64_t, current_height); RPC_MESSAGE_MEMBER(uint64_t, current_height);
RPC_MESSAGE_MEMBER(crypto::hash, top_block_hash);
RPC_MESSAGE_MEMBER(std::vector<cryptonote::rpc::block_output_indices>, output_indices); RPC_MESSAGE_MEMBER(std::vector<cryptonote::rpc::block_output_indices>, output_indices);
END_RPC_MESSAGE_RESPONSE; END_RPC_MESSAGE_RESPONSE;
END_RPC_MESSAGE_CLASS; END_RPC_MESSAGE_CLASS;