This commit is contained in:
Peter Zhang 2025-11-20 21:21:02 +08:00
parent 023c777123
commit c2f2fbb934
7 changed files with 45 additions and 26 deletions

View File

@ -427,10 +427,6 @@ impl<E: HashElement, A: Algorithm<E>> AppendMerkleTree<E, A> {
self.root_to_tx_seq_map.contains_key(root) self.root_to_tx_seq_map.contains_key(root)
} }
pub fn get_node_hash_by_index(&self, index: usize) -> Result<Option<E>> {
Ok(Some(self.node(0, index)))
}
pub fn leaf_at(&self, position: usize) -> Result<Option<E>> { pub fn leaf_at(&self, position: usize) -> Result<Option<E>> {
if position >= self.leaves() { if position >= self.leaves() {
bail!("Out of bound: position={} end={}", position, self.leaves()); bail!("Out of bound: position={} end={}", position, self.leaves());

View File

@ -83,10 +83,7 @@ pub trait Rpc {
) -> RpcResult<FlowProof>; ) -> RpcResult<FlowProof>;
#[method(name = "getHashAtNodeIndex")] #[method(name = "getHashAtNodeIndex")]
async fn get_hash_at_node_index( async fn get_hash_at_node_index(&self, node_index: u64) -> RpcResult<Option<H256>>;
&self,
node_index: u64,
) -> RpcResult<Option<H256>>;
#[method(name = "getFlowContext")] #[method(name = "getFlowContext")]
async fn get_flow_context(&self) -> RpcResult<(H256, u64)>; async fn get_flow_context(&self) -> RpcResult<(H256, u64)>;

View File

@ -225,10 +225,7 @@ impl RpcServer for RpcServerImpl {
Ok(proof.right_proof) Ok(proof.right_proof)
} }
async fn get_hash_at_node_index( async fn get_hash_at_node_index(&self, node_index: u64) -> RpcResult<Option<H256>> {
&self,
node_index: u64,
) -> RpcResult<Option<H256>> {
debug!(%node_index, "zgs_getHashAtNodeIndex"); debug!(%node_index, "zgs_getHashAtNodeIndex");
let hash = self let hash = self
.ctx .ctx

View File

@ -2,6 +2,7 @@
extern crate tracing; extern crate tracing;
use anyhow::bail; use anyhow::bail;
use append_merkle::OptionalHash;
use shared_types::{ use shared_types::{
Chunk, ChunkArray, ChunkArrayWithProof, DataRoot, FlowProof, FlowRangeProof, Transaction, Chunk, ChunkArray, ChunkArrayWithProof, DataRoot, FlowProof, FlowRangeProof, Transaction,
}; };
@ -10,7 +11,6 @@ use std::sync::Arc;
use storage::{error, error::Result, log_store::Store as LogStore, H256}; use storage::{error, error::Result, log_store::Store as LogStore, H256};
use task_executor::TaskExecutor; use task_executor::TaskExecutor;
use tokio::sync::oneshot; use tokio::sync::oneshot;
use append_merkle::OptionalHash;
pub use storage::config::ShardConfig; pub use storage::config::ShardConfig;
use storage::log_store::config::ConfigurableExt; use storage::log_store::config::ConfigurableExt;

View File

@ -228,6 +228,17 @@ impl FlowWrite for FlowStore {
if data.data.len() % BYTES_PER_SECTOR != 0 { if data.data.len() % BYTES_PER_SECTOR != 0 {
bail!("append_entries: invalid data size, len={}", data.data.len()); bail!("append_entries: invalid data size, len={}", data.data.len());
} }
let batch_data_12288 = self
.data_db
.get_entry_batch(12288)?
.unwrap_or_else(|| EntryBatch::new(12288));
debug!(
"Entry batch data at 12288 before insert: {:?}",
batch_data_12288.as_ssz_bytes()
);
let mut batch_list = Vec::new(); let mut batch_list = Vec::new();
for (start_entry_index, end_entry_index) in batch_iter( for (start_entry_index, end_entry_index) in batch_iter(
data.start_index, data.start_index,
@ -250,6 +261,7 @@ impl FlowWrite for FlowStore {
.data_db .data_db
.get_entry_batch(chunk_index)? .get_entry_batch(chunk_index)?
.unwrap_or_else(|| EntryBatch::new(chunk_index)); .unwrap_or_else(|| EntryBatch::new(chunk_index));
let completed_seals = batch.insert_data( let completed_seals = batch.insert_data(
(chunk.start_index % self.config.batch_size as u64) as usize, (chunk.start_index % self.config.batch_size as u64) as usize,
chunk.data, chunk.data,
@ -267,7 +279,19 @@ impl FlowWrite for FlowStore {
} }
metrics::APPEND_ENTRIES.update_since(start_time); metrics::APPEND_ENTRIES.update_since(start_time);
self.data_db.put_entry_batch_list(batch_list) let res = self.data_db.put_entry_batch_list(batch_list);
let batch_data_12288 = self
.data_db
.get_entry_batch(12288)?
.unwrap_or_else(|| EntryBatch::new(12288));
debug!(
"Entry batch data at 12288 after insert: {:?}",
batch_data_12288.as_ssz_bytes()
);
res
} }
fn truncate(&self, start_index: u64) -> crate::error::Result<()> { fn truncate(&self, start_index: u64) -> crate::error::Result<()> {
@ -393,6 +417,7 @@ impl FlowDBStore {
let start_time = Instant::now(); let start_time = Instant::now();
let mut completed_batches = Vec::new(); let mut completed_batches = Vec::new();
let mut tx = self.kvdb.transaction(); let mut tx = self.kvdb.transaction();
for (batch_index, batch) in batch_list { for (batch_index, batch) in batch_list {
tx.put( tx.put(
COL_ENTRY_BATCH, COL_ENTRY_BATCH,

View File

@ -566,9 +566,7 @@ impl LogStoreRead for LogManager {
fn get_node_hash_by_index(&self, index: u64) -> crate::error::Result<OptionalHash> { fn get_node_hash_by_index(&self, index: u64) -> crate::error::Result<OptionalHash> {
let merkle = self.merkle.read(); let merkle = self.merkle.read();
let opt = merkle let opt = merkle.pora_chunks_merkle.leaf_at(index as usize)?;
.pora_chunks_merkle
.get_node_hash_by_index(index as usize)?;
opt.ok_or_else(|| anyhow!("node hash not found at index {}", index)) opt.ok_or_else(|| anyhow!("node hash not found at index {}", index))
} }
@ -1180,10 +1178,13 @@ impl LogManager {
); );
// Padding should only start after real data ends // Padding should only start after real data ends
let real_data_end_index = (segments_for_file - 1) * PORA_CHUNK_SIZE + last_segment_size_for_file; let real_data_end_index =
(segments_for_file - 1) * PORA_CHUNK_SIZE + last_segment_size_for_file;
debug!( debug!(
"Padding: real_data_end_index={}, padding_start_segment={}, padding_start_offset={}", "Padding: real_data_end_index={}, padding_start_segment={}, padding_start_offset={}",
real_data_end_index, segments_for_file - 1, last_segment_size_for_file real_data_end_index,
segments_for_file - 1,
last_segment_size_for_file
); );
while segments_for_file <= segments_for_proof { while segments_for_file <= segments_for_proof {
@ -1193,12 +1194,15 @@ impl LogManager {
(PORA_CHUNK_SIZE - last_segment_size_for_file) * ENTRY_SIZE (PORA_CHUNK_SIZE - last_segment_size_for_file) * ENTRY_SIZE
}; };
let padding_start_index = ((segments_for_file - 1) * PORA_CHUNK_SIZE let padding_start_index =
+ last_segment_size_for_file) as u64; ((segments_for_file - 1) * PORA_CHUNK_SIZE + last_segment_size_for_file) as u64;
debug!( debug!(
"Padding iteration: segment={}, offset={}, padding_size={}, start_index={}", "Padding iteration: segment={}, offset={}, padding_size={}, start_index={}",
segments_for_file - 1, last_segment_size_for_file, padding_size, padding_start_index segments_for_file - 1,
last_segment_size_for_file,
padding_size,
padding_start_index
); );
if padding_size > 0 { if padding_size > 0 {