add get chunk rpc

This commit is contained in:
Peter Zhang 2024-09-11 16:43:32 +08:00
parent e20be63026
commit 520b27a6c7
2 changed files with 35 additions and 0 deletions

View File

@ -30,6 +30,14 @@ pub trait Rpc {
index: usize,
) -> RpcResult<Option<SegmentWithProof>>;
#[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<Option<SegmentWithProof>>;
#[method(name = "getFileInfo")]
async fn get_file_info(&self, data_root: DataRoot) -> RpcResult<Option<FileInfo>>;

View File

@ -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<Option<SegmentWithProof>> {
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<Option<FileInfo>> {
debug!(%data_root, "zgs_getFileInfo");