Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions binaries/cuprated/src/rpc/handlers/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub async fn map_request(
Ok(match request {
Req::GetBlocks(r) => Resp::GetBlocks(not_available()?),
Req::GetBlocksByHeight(r) => Resp::GetBlocksByHeight(not_available()?),
Req::GetHashes(r) => Resp::GetHashes(not_available()?),
Req::GetHashes(r) => Resp::GetHashes(get_hashes(state, r).await?),
Req::GetOutputIndexes(r) => Resp::GetOutputIndexes(not_available()?),
Req::GetOuts(r) => Resp::GetOuts(not_available()?),
Req::GetTransactionPoolHashes(r) => Resp::GetTransactionPoolHashes(not_available()?),
Expand Down Expand Up @@ -134,8 +134,7 @@ async fn get_blocks(
}

let (block_hashes, start_height, _) =
blockchain::next_chain_entry(&mut state.blockchain_read, block_hashes, start_height)
.await?;
blockchain::next_chain_entry(&mut state.blockchain_read, block_hashes).await?;

if start_height.is_none() {
return Err(anyhow!("Block IDs were not sorted properly"));
Expand Down Expand Up @@ -180,31 +179,28 @@ async fn get_hashes(
request: GetHashesRequest,
) -> Result<GetHashesResponse, Error> {
let GetHashesRequest {
start_height,
start_height: _,
block_ids,
} = request;

// FIXME: impl `last()`
let last = {
let len = block_ids.len();
// monerod ignores `req.start_height` it's overwritten by the split point derived from `block_ids`.
// https://github.com/monero-project/monero/blob/495c7f18dd92c53753339a9aff65e5ae097958b4/src/rpc/core_rpc_server.cpp#L894
// https://github.com/monero-project/monero/blob/495c7f18dd92c53753339a9aff65e5ae097958b4/src/cryptonote_core/blockchain.cpp#L2736
// https://github.com/monero-project/monero/blob/495c7f18dd92c53753339a9aff65e5ae097958b4/src/cryptonote_core/blockchain.cpp#L2487
let hashes: Vec<[u8; 32]> = (&block_ids).into();

if len == 0 {
return Err(anyhow!("block_ids empty"));
}
let (m_block_ids, start, current_height) =
blockchain::next_chain_entry(&mut state.blockchain_read, hashes).await?;

block_ids[len - 1]
let Some(start) = start else {
return Err(anyhow!("Could not find split point."));
};

let hashes: Vec<[u8; 32]> = (&block_ids).into();

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),
m_block_ids: m_block_ids.into(),
current_height: usize_to_u64(current_height),
start_height,
start_height: usize_to_u64(start),
})
}

Expand Down
6 changes: 1 addition & 5 deletions binaries/cuprated/src/rpc/service/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ pub async fn find_block(
pub async fn next_chain_entry(
blockchain_read: &mut BlockchainReadHandle,
block_hashes: Vec<[u8; 32]>,
start_height: u64,
) -> Result<(Vec<[u8; 32]>, Option<usize>, usize), Error> {
let BlockchainResponse::NextChainEntry {
block_ids,
Expand All @@ -136,10 +135,7 @@ pub async fn next_chain_entry(
} = blockchain_read
.ready()
.await?
.call(BlockchainReadRequest::NextChainEntry(
block_hashes,
u64_to_usize(start_height),
))
.call(BlockchainReadRequest::NextChainEntry(block_hashes, 10_000))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the 10_000 could be put in cuprate-constants to mirror monerod: https://github.com/monero-project/monero/blob/master/src/cryptonote_config.h#L96

p2p/request_handler.rs could too make use of it then for consistency

.await?
else {
unreachable!();
Expand Down
21 changes: 12 additions & 9 deletions storage/blockchain/src/service/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,15 +640,18 @@ fn next_chain_entry(
let chain_height = crate::ops::blockchain::chain_height(db, &tapes)?;
let last_height_in_chain_entry = min(first_known_height + next_entry_size, chain_height);

let (block_ids, block_weights) = (first_known_height..last_height_in_chain_entry)
.map(|height| {
let block_info = tapes
.read_entry(&db.block_infos, usize_to_u64(height))?
.ok_or(BlockchainError::NotFound)?;

Ok((block_info.block_hash, block_info.weight))
})
.collect::<DbResult<(Vec<_>, Vec<_>)>>()?;
let entry_count = last_height_in_chain_entry - first_known_height;
let mut block_infos = vec![crate::types::BlockInfo::default(); entry_count];
tapes.read_entries(
&db.block_infos,
usize_to_u64(first_known_height),
&mut block_infos,
)?;

let (block_ids, block_weights) = block_infos
.iter()
.map(|info| (info.block_hash, info.weight))
.unzip::<_, _, Vec<_>, Vec<_>>();

let top_block_info = tapes
.read_entry(&db.block_infos, usize_to_u64(chain_height) - 1)?
Expand Down
Loading