From 2c32e0238efd756dd551d31526fdfcc3ee7c3fda Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Fri, 17 Jan 2025 15:22:01 -0500 Subject: [PATCH] fixes --- binaries/cuprated/src/rpc/handlers/bin.rs | 21 +++++++++---------- .../cuprated/src/rpc/handlers/other_json.rs | 4 ++-- .../cuprated/src/rpc/service/blockchain.rs | 7 +++++-- binaries/cuprated/src/rpc/service/txpool.rs | 4 ++-- storage/txpool/src/service/read.rs | 13 ++++++++++++ 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/binaries/cuprated/src/rpc/handlers/bin.rs b/binaries/cuprated/src/rpc/handlers/bin.rs index bb0d015..8d2759d 100644 --- a/binaries/cuprated/src/rpc/handlers/bin.rs +++ b/binaries/cuprated/src/rpc/handlers/bin.rs @@ -166,33 +166,32 @@ async fn get_hashes( mut state: CupratedRpcHandler, request: GetHashesRequest, ) -> Result { + let GetHashesRequest { + start_height, + block_ids, + } = request; + // FIXME: impl `last()` let last = { - let len = request.block_ids.len(); + let len = block_ids.len(); if len == 0 { return Err(anyhow!("block_ids empty")); } - request.block_ids[len - 1] + block_ids[len - 1] }; - let GetHashesRequest { - start_height, - block_ids, - .. - } = request; - let hashes: Vec<[u8; 32]> = (&block_ids).into(); - let (m_block_ids, current_height) = + let (m_blocks_ids, current_height) = blockchain::next_chain_entry(&mut state.blockchain_read, hashes, start_height).await?; Ok(GetHashesResponse { base: helper::access_response_base(false), - m_blocks_ids, + m_blocks_ids: m_blocks_ids.into(), + current_height: usize_to_u64(current_height), start_height, - current_height, }) } diff --git a/binaries/cuprated/src/rpc/handlers/other_json.rs b/binaries/cuprated/src/rpc/handlers/other_json.rs index c4c6c7b..646ea52 100644 --- a/binaries/cuprated/src/rpc/handlers/other_json.rs +++ b/binaries/cuprated/src/rpc/handlers/other_json.rs @@ -328,7 +328,7 @@ async fn is_key_image_spent( KeyImageSpentStatus::SpentInBlockchain => None, KeyImageSpentStatus::SpentInPool => unreachable!(), }) - .collect(); + .collect::>(); // Check if the remaining unspent key images exist in the transaction pool. if !key_images.is_empty() { @@ -346,7 +346,7 @@ async fn is_key_image_spent( let spent_status = spent_status .into_iter() - .map(|status| status.to_u8()) + .map(KeyImageSpentStatus::to_u8) .collect(); Ok(IsKeyImageSpentResponse { diff --git a/binaries/cuprated/src/rpc/service/blockchain.rs b/binaries/cuprated/src/rpc/service/blockchain.rs index c339187..f15ae9c 100644 --- a/binaries/cuprated/src/rpc/service/blockchain.rs +++ b/binaries/cuprated/src/rpc/service/blockchain.rs @@ -123,7 +123,7 @@ pub async fn find_block( pub async fn next_chain_entry( blockchain_read: &mut BlockchainReadHandle, block_hashes: Vec<[u8; 32]>, - len: usize, + start_height: u64, ) -> Result<(Vec<[u8; 32]>, usize), Error> { let BlockchainResponse::NextChainEntry { block_ids, @@ -132,7 +132,10 @@ pub async fn next_chain_entry( } = blockchain_read .ready() .await? - .call(BlockchainReadRequest::NextChainEntry(block_hashes, len)) + .call(BlockchainReadRequest::NextChainEntry( + block_hashes, + u64_to_usize(start_height), + )) .await? else { unreachable!(); diff --git a/binaries/cuprated/src/rpc/service/txpool.rs b/binaries/cuprated/src/rpc/service/txpool.rs index b13a3fe..01194d5 100644 --- a/binaries/cuprated/src/rpc/service/txpool.rs +++ b/binaries/cuprated/src/rpc/service/txpool.rs @@ -136,11 +136,11 @@ pub async fn key_images_spent_vec( key_images: Vec<[u8; 32]>, include_sensitive_txs: bool, ) -> Result, Error> { - let TxpoolReadResponse::KeyImagesSpent(status) = txpool_read + let TxpoolReadResponse::KeyImagesSpentVec(status) = txpool_read .ready() .await .map_err(|e| anyhow!(e))? - .call(TxpoolReadRequest::KeyImagesSpent { + .call(TxpoolReadRequest::KeyImagesSpentVec { key_images, include_sensitive_txs, }) diff --git a/storage/txpool/src/service/read.rs b/storage/txpool/src/service/read.rs index 4cd681a..1af0bf1 100644 --- a/storage/txpool/src/service/read.rs +++ b/storage/txpool/src/service/read.rs @@ -89,6 +89,10 @@ fn map_request( key_images, include_sensitive_txs, } => key_images_spent(env, key_images, include_sensitive_txs), + TxpoolReadRequest::KeyImagesSpentVec { + key_images, + include_sensitive_txs, + } => key_images_spent_vec(env, key_images, include_sensitive_txs), TxpoolReadRequest::Pool { include_sensitive_txs, } => pool(env, include_sensitive_txs), @@ -252,6 +256,15 @@ fn txs_by_hash( /// [`TxpoolReadRequest::KeyImagesSpent`]. fn key_images_spent( + env: &ConcreteEnv, + key_images: HashSet<[u8; 32]>, + include_sensitive_txs: bool, +) -> ReadResponseResult { + Ok(TxpoolReadResponse::KeyImagesSpent(todo!())) +} + +/// [`TxpoolReadRequest::KeyImagesSpentVec`]. +fn key_images_spent_vec( env: &ConcreteEnv, key_images: Vec<[u8; 32]>, include_sensitive_txs: bool,