mirror of
https://github.com/0glabs/0g-storage-node.git
synced 2024-11-20 15:05:19 +00:00
Add zgs_getSectorProof. (#112)
This commit is contained in:
parent
0a69d0f56c
commit
e54b583b1c
@ -81,7 +81,7 @@ impl Submitter {
|
||||
let flow_proof = self
|
||||
.store
|
||||
.get_proof_at_root(
|
||||
mine_answer.context_flow_root,
|
||||
Some(mine_answer.context_flow_root),
|
||||
mine_answer.recall_position,
|
||||
SECTORS_PER_SEAL as u64,
|
||||
)
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::types::{FileInfo, Segment, SegmentWithProof, Status};
|
||||
use jsonrpsee::core::RpcResult;
|
||||
use jsonrpsee::proc_macros::rpc;
|
||||
use shared_types::DataRoot;
|
||||
use shared_types::{DataRoot, FlowProof};
|
||||
use storage::config::ShardConfig;
|
||||
|
||||
#[rpc(server, client, namespace = "zgs")]
|
||||
@ -38,4 +38,11 @@ pub trait Rpc {
|
||||
|
||||
#[method(name = "getShardConfig")]
|
||||
async fn get_shard_config(&self) -> RpcResult<ShardConfig>;
|
||||
|
||||
#[method(name = "getSectorProof")]
|
||||
async fn get_sector_proof(
|
||||
&self,
|
||||
sector_index: u64,
|
||||
flow_root: Option<DataRoot>,
|
||||
) -> RpcResult<FlowProof>;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ use crate::Context;
|
||||
use chunk_pool::{FileID, SegmentInfo};
|
||||
use jsonrpsee::core::async_trait;
|
||||
use jsonrpsee::core::RpcResult;
|
||||
use shared_types::{DataRoot, Transaction, CHUNK_SIZE};
|
||||
use shared_types::{DataRoot, FlowProof, Transaction, CHUNK_SIZE};
|
||||
use std::fmt::{Debug, Formatter, Result};
|
||||
use storage::config::ShardConfig;
|
||||
use storage::try_option;
|
||||
@ -157,6 +157,20 @@ impl RpcServer for RpcServerImpl {
|
||||
let shard_config = self.ctx.log_store.get_store().flow().get_shard_config();
|
||||
Ok(shard_config)
|
||||
}
|
||||
|
||||
async fn get_sector_proof(
|
||||
&self,
|
||||
sector_index: u64,
|
||||
flow_root: Option<DataRoot>,
|
||||
) -> RpcResult<FlowProof> {
|
||||
let proof = self
|
||||
.ctx
|
||||
.log_store
|
||||
.get_proof_at_root(flow_root, sector_index, 1)
|
||||
.await?;
|
||||
assert_eq!(proof.left_proof, proof.right_proof);
|
||||
Ok(proof.right_proof)
|
||||
}
|
||||
}
|
||||
|
||||
impl RpcServerImpl {
|
||||
|
@ -54,7 +54,7 @@ impl Store {
|
||||
delegate!(fn get_chunk_by_flow_index(index: u64, length: u64) -> Result<Option<ChunkArray>>);
|
||||
delegate!(fn finalize_tx(tx_seq: u64) -> Result<()>);
|
||||
delegate!(fn finalize_tx_with_hash(tx_seq: u64, tx_hash: H256) -> Result<bool>);
|
||||
delegate!(fn get_proof_at_root(root: DataRoot, index: u64, length: u64) -> Result<FlowRangeProof>);
|
||||
delegate!(fn get_proof_at_root(root: Option<DataRoot>, index: u64, length: u64) -> Result<FlowRangeProof>);
|
||||
delegate!(fn get_context() -> Result<(DataRoot, u64)>);
|
||||
|
||||
pub async fn get_tx_seq_by_data_root(&self, data_root: &DataRoot) -> Result<Option<u64>> {
|
||||
|
@ -540,12 +540,12 @@ impl LogStoreRead for LogManager {
|
||||
|
||||
fn get_proof_at_root(
|
||||
&self,
|
||||
root: DataRoot,
|
||||
root: Option<DataRoot>,
|
||||
index: u64,
|
||||
length: u64,
|
||||
) -> crate::error::Result<FlowRangeProof> {
|
||||
let left_proof = self.gen_proof(index, Some(root))?;
|
||||
let right_proof = self.gen_proof(index + length - 1, Some(root))?;
|
||||
let left_proof = self.gen_proof(index, root)?;
|
||||
let right_proof = self.gen_proof(index + length - 1, root)?;
|
||||
Ok(FlowRangeProof {
|
||||
left_proof,
|
||||
right_proof,
|
||||
|
@ -62,7 +62,12 @@ pub trait LogStoreRead: LogStoreChunkRead {
|
||||
|
||||
fn validate_range_proof(&self, tx_seq: u64, data: &ChunkArrayWithProof) -> Result<bool>;
|
||||
|
||||
fn get_proof_at_root(&self, root: DataRoot, index: u64, length: u64) -> Result<FlowRangeProof>;
|
||||
fn get_proof_at_root(
|
||||
&self,
|
||||
root: Option<DataRoot>,
|
||||
index: u64,
|
||||
length: u64,
|
||||
) -> Result<FlowRangeProof>;
|
||||
|
||||
/// Return flow root and length.
|
||||
fn get_context(&self) -> Result<(DataRoot, u64)>;
|
||||
|
Loading…
Reference in New Issue
Block a user