From 520b27a6c7ead2c98b5ae1407a5ea218f395dc78 Mon Sep 17 00:00:00 2001 From: Peter Zhang Date: Wed, 11 Sep 2024 16:43:32 +0800 Subject: [PATCH] add get chunk rpc --- node/rpc/src/zgs/api.rs | 8 ++++++++ node/rpc/src/zgs/impl.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/node/rpc/src/zgs/api.rs b/node/rpc/src/zgs/api.rs index 2ed6fa3..d301294 100644 --- a/node/rpc/src/zgs/api.rs +++ b/node/rpc/src/zgs/api.rs @@ -30,6 +30,14 @@ pub trait Rpc { index: usize, ) -> RpcResult>; + #[method(name = "getChunksWithProofByTxAndIndexRange")] + async fn get_chunks_with_proof_by_tx_and_index_range( + &self, + tx_seq: u64, + start_index: usize, + end_index: usize, + ) -> RpcResult>; + #[method(name = "getFileInfo")] async fn get_file_info(&self, data_root: DataRoot) -> RpcResult>; diff --git a/node/rpc/src/zgs/impl.rs b/node/rpc/src/zgs/impl.rs index a961cf4..23ae6d5 100644 --- a/node/rpc/src/zgs/impl.rs +++ b/node/rpc/src/zgs/impl.rs @@ -137,6 +137,33 @@ impl RpcServer for RpcServerImpl { })) } + async fn get_chunks_with_proof_by_tx_and_index_range( + &self, + tx_seq: u64, + start_index: usize, + end_index: usize, + ) -> RpcResult> { + info!(%tx_seq, %start_index, %end_index, "zgs_getChunksWithProofByTxAndIndexRange"); + + let segment = try_option!( + self.ctx + .log_store + .get_chunks_with_proof_by_tx_and_index_range(tx_seq, start_index, end_index, None) + .await? + ); + + let tx = try_option!(self.ctx.log_store.get_tx_by_seq_number(tx_seq).await?); + let proof = tx.compute_segment_proof(&segment, self.ctx.config.chunks_per_segment)?; + + Ok(Some(SegmentWithProof { + root: tx.data_merkle_root, + data: segment.chunks.data, + index: start_index / self.ctx.config.chunks_per_segment, + proof, + file_size: tx.size as usize, + })) + } + async fn get_file_info(&self, data_root: DataRoot) -> RpcResult> { debug!(%data_root, "zgs_getFileInfo");