forked from lthn/blockchain
on_get_blocks_fuzzy_direct/find_blockchain_supplement_fuzzy draft impl
This commit is contained in:
parent
7b0eaf7ae4
commit
bf222f18fe
4 changed files with 58 additions and 1 deletions
|
|
@ -2938,6 +2938,31 @@ bool blockchain_storage::find_blockchain_supplement(const std::list<crypto::hash
|
|||
|
||||
return true;
|
||||
}
|
||||
bool blockchain_storage::find_blockchain_supplement_fuzzy(const std::list<epee::pod_pair<uint64_t, crypto::hash>& qblock_ids, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp)const
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_read_lock);
|
||||
// if (!find_blockchain_supplement(qblock_ids, resp.start_height))
|
||||
// return false;
|
||||
//
|
||||
// resp.total_height = get_current_blockchain_size();
|
||||
// size_t count = 0;
|
||||
//
|
||||
// block_context_info* pprevinfo = nullptr;
|
||||
// size_t i = 0;
|
||||
// for (i = resp.start_height; i != m_db_blocks.size() && count < BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT; i++, count++)
|
||||
// {
|
||||
// resp.m_block_ids.push_back(block_context_info());
|
||||
//
|
||||
// if (pprevinfo)
|
||||
// pprevinfo->h = m_db_blocks[i]->bl.prev_id;
|
||||
// resp.m_block_ids.back().cumul_size = m_db_blocks[i]->block_cumulative_size;
|
||||
// pprevinfo = &resp.m_block_ids.back();
|
||||
// }
|
||||
// if (pprevinfo)
|
||||
// pprevinfo->h = get_block_hash(m_db_blocks[--i]->bl);
|
||||
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
bool blockchain_storage::find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count)const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -252,6 +252,7 @@ namespace currency
|
|||
size_t get_total_transactions()const;
|
||||
bool get_outs(uint64_t amount, std::list<crypto::public_key>& pkeys)const;
|
||||
bool get_short_chain_history(std::list<crypto::hash>& ids)const;
|
||||
bool find_blockchain_supplement_fuzzy(const std::list<epee::pod_pair<uint64_t, crypto::hash>& qblock_ids, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp)const;
|
||||
bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp)const;
|
||||
bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, uint64_t& starter_offset)const;
|
||||
bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count)const;
|
||||
|
|
|
|||
|
|
@ -288,7 +288,36 @@ namespace currency
|
|||
res.status = CORE_RPC_STATUS_OK;
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool core_rpc_server::on_get_blocks_fuzzy_direct(const COMMAND_RPC_GET_BLOCKS_FUZZY_DIRECT::request& req, COMMAND_RPC_GET_BLOCKS_FUZZY_DIRECT::response& res, connection_context& cntx)
|
||||
{
|
||||
CHECK_CORE_READY();
|
||||
|
||||
if (req.block_ids.back() != m_core.get_blockchain_storage().get_block_id_by_height(0))
|
||||
{
|
||||
//genesis mismatch, return specific
|
||||
res.status = CORE_RPC_STATUS_GENESIS_MISMATCH;
|
||||
return true;
|
||||
}
|
||||
|
||||
blockchain_storage::blocks_direct_container bs;
|
||||
if (!m_core.get_blockchain_storage().find_blockchain_supplement2(req.block_ids, bs, res.current_height, res.start_height, COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT))
|
||||
{
|
||||
res.status = CORE_RPC_STATUS_FAILED;
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto& b : bs)
|
||||
{
|
||||
res.blocks.resize(res.blocks.size() + 1);
|
||||
res.blocks.back().block_ptr = b.first;
|
||||
res.blocks.back().txs_ptr = std::move(b.second);
|
||||
}
|
||||
|
||||
res.status = CORE_RPC_STATUS_OK;
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool core_rpc_server::on_get_blocks(const COMMAND_RPC_GET_BLOCKS_FAST::request& req, COMMAND_RPC_GET_BLOCKS_FAST::response& res, connection_context& cntx)
|
||||
{
|
||||
CHECK_CORE_READY();
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ namespace currency
|
|||
bool init(const boost::program_options::variables_map& vm);
|
||||
|
||||
bool on_get_blocks_direct(const COMMAND_RPC_GET_BLOCKS_DIRECT::request& req, COMMAND_RPC_GET_BLOCKS_DIRECT::response& res, connection_context& cntx);
|
||||
bool on_get_blocks_fuzzy_direct(const COMMAND_RPC_GET_BLOCKS_FUZZY_DIRECT::request& req, COMMAND_RPC_GET_BLOCKS_FUZZY_DIRECT::response& res, connection_context& cntx);
|
||||
|
||||
|
||||
bool on_get_height(const COMMAND_RPC_GET_HEIGHT::request& req, COMMAND_RPC_GET_HEIGHT::response& res, connection_context& cntx);
|
||||
bool on_get_blocks(const COMMAND_RPC_GET_BLOCKS_FAST::request& req, COMMAND_RPC_GET_BLOCKS_FAST::response& res, connection_context& cntx);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue