From 29fcc415a602d93d8c95487bb6191aadfde0cc74 Mon Sep 17 00:00:00 2001 From: peilun-conflux <48905552+peilun-conflux@users.noreply.github.com> Date: Fri, 6 Sep 2024 17:56:04 +0800 Subject: [PATCH] Add log for proof generation errors. (#182) --- node/storage/src/log_store/flow_store.rs | 15 +++++++++++++++ .../src/log_store/load_chunk/chunk_data.rs | 1 + node/storage/src/log_store/load_chunk/mod.rs | 2 +- node/storage/src/log_store/load_chunk/seal.rs | 2 +- node/storage/src/log_store/log_manager.rs | 16 +++++++++++++++- 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/node/storage/src/log_store/flow_store.rs b/node/storage/src/log_store/flow_store.rs index 8c2fae9..5ff4061 100644 --- a/node/storage/src/log_store/flow_store.rs +++ b/node/storage/src/log_store/flow_store.rs @@ -90,6 +90,14 @@ impl FlowStore { } self.db.delete_batch_list(batch_list) } + + pub fn get_raw_batch(&self, batch_index: u64) -> Result> { + self.db.get_entry_batch(batch_index) + } + + pub fn get_batch_root(&self, batch_index: u64) -> Result> { + self.db.get_batch_root(batch_index) + } } #[derive(Clone, Debug)] @@ -575,6 +583,13 @@ impl FlowDBStore { } Ok(self.kvdb.write(tx)?) } + + fn get_batch_root(&self, batch_index: u64) -> Result> { + Ok(self + .kvdb + .get(COL_ENTRY_BATCH_ROOT, &batch_index.to_be_bytes())? + .map(|v| DataRoot::from_slice(&v))) + } } #[derive(DeriveEncode, DeriveDecode, Clone, Debug)] diff --git a/node/storage/src/log_store/load_chunk/chunk_data.rs b/node/storage/src/log_store/load_chunk/chunk_data.rs index 30b0ec2..75e92de 100644 --- a/node/storage/src/log_store/load_chunk/chunk_data.rs +++ b/node/storage/src/log_store/load_chunk/chunk_data.rs @@ -6,6 +6,7 @@ use std::mem; use tracing::error; use zgs_spec::{BYTES_PER_LOAD, BYTES_PER_SECTOR, SECTORS_PER_LOAD, SECTORS_PER_SEAL}; +#[derive(Debug)] pub enum EntryBatchData { Complete(Vec), /// All `PartialBatch`s are ordered based on `start_index`. diff --git a/node/storage/src/log_store/load_chunk/mod.rs b/node/storage/src/log_store/load_chunk/mod.rs index f1b35bd..15365f9 100644 --- a/node/storage/src/log_store/load_chunk/mod.rs +++ b/node/storage/src/log_store/load_chunk/mod.rs @@ -23,7 +23,7 @@ use super::SealAnswer; use chunk_data::EntryBatchData; use seal::SealInfo; -#[derive(Encode, Decode)] +#[derive(Debug, Encode, Decode)] pub struct EntryBatch { seal: SealInfo, // the inner data diff --git a/node/storage/src/log_store/load_chunk/seal.rs b/node/storage/src/log_store/load_chunk/seal.rs index 75f1ae9..9c6f5ff 100644 --- a/node/storage/src/log_store/load_chunk/seal.rs +++ b/node/storage/src/log_store/load_chunk/seal.rs @@ -19,7 +19,7 @@ pub struct SealContextInfo { type ChunkSealBitmap = WrappedBitmap; const_assert!(SEALS_PER_LOAD <= u128::BITS as usize); -#[derive(Default, DeriveEncode, DeriveDecode)] +#[derive(Debug, Default, DeriveEncode, DeriveDecode)] pub struct SealInfo { // a bitmap specify which sealing chunks have been sealed bitmap: ChunkSealBitmap, diff --git a/node/storage/src/log_store/log_manager.rs b/node/storage/src/log_store/log_manager.rs index 64ac9e0..52772cd 100644 --- a/node/storage/src/log_store/log_manager.rs +++ b/node/storage/src/log_store/log_manager.rs @@ -776,7 +776,21 @@ impl LogManager { .gen_proof(flow_index as usize % PORA_CHUNK_SIZE)?, } }; - entry_proof(&top_proof, &sub_proof) + let r = entry_proof(&top_proof, &sub_proof); + if r.is_err() { + let raw_batch = self.flow_store.get_raw_batch(seg_index as u64)?; + let db_root = self.flow_store.get_batch_root(seg_index as u64)?; + error!( + ?r, + ?raw_batch, + ?db_root, + ?seg_index, + "gen proof error: top_leaves={}, last={}", + merkle.pora_chunks_merkle.leaves(), + merkle.last_chunk_merkle.leaves() + ); + } + r } #[instrument(skip(self, merkle))]