mirror of
https://github.com/hinto-janai/cuprate.git
synced 2025-01-21 10:14:30 +00:00
fix get_hashes
This commit is contained in:
parent
0b3ff4e14c
commit
78b3ff1925
2 changed files with 34 additions and 10 deletions
|
@ -177,18 +177,16 @@ async fn get_hashes(
|
|||
request.block_ids[len - 1]
|
||||
};
|
||||
|
||||
let mut bytes = request.block_ids;
|
||||
let hashes: Vec<[u8; 32]> = (&bytes).into();
|
||||
let GetHashesRequest {
|
||||
start_height,
|
||||
block_ids,
|
||||
..
|
||||
} = request;
|
||||
|
||||
let (current_height, _) = helper::top_height(&mut state).await?;
|
||||
let hashes: Vec<[u8; 32]> = (&block_ids).into();
|
||||
|
||||
let Some((index, start_height)) =
|
||||
blockchain::find_first_unknown(&mut state.blockchain_read, hashes).await?
|
||||
else {
|
||||
return Err(anyhow!("Failed"));
|
||||
};
|
||||
|
||||
let m_blocks_ids = bytes.split_off(index);
|
||||
let (m_block_ids, current_height) =
|
||||
blockchain::next_chain_entry(&mut state.blockchain_read, hashes, start_height).await?;
|
||||
|
||||
Ok(GetHashesResponse {
|
||||
base: helper::access_response_base(false),
|
||||
|
|
|
@ -115,6 +115,32 @@ pub async fn find_block(
|
|||
Ok(option)
|
||||
}
|
||||
|
||||
/// [`BlockchainReadRequest::NextChainEntry`].
|
||||
///
|
||||
/// Returns only the:
|
||||
/// - block IDs
|
||||
/// - current chain height
|
||||
pub async fn next_chain_entry(
|
||||
blockchain_read: &mut BlockchainReadHandle,
|
||||
block_hashes: Vec<[u8; 32]>,
|
||||
len: usize,
|
||||
) -> Result<(Vec<[u8; 32]>, Option<std::num::NonZero<usize>>), Error> {
|
||||
let BlockchainResponse::NextChainEntry {
|
||||
block_ids,
|
||||
chain_height,
|
||||
..
|
||||
} = blockchain_read
|
||||
.ready()
|
||||
.await?
|
||||
.call(BlockchainReadRequest::NextChainEntry(block_hashes, len))
|
||||
.await?
|
||||
else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
Ok((block_ids, chain_height))
|
||||
}
|
||||
|
||||
/// [`BlockchainReadRequest::FilterUnknownHashes`].
|
||||
pub async fn filter_unknown_hashes(
|
||||
blockchain_read: &mut BlockchainReadHandle,
|
||||
|
|
Loading…
Reference in a new issue