range root should also add back missing padded data

This commit is contained in:
Peter Zhang 2024-09-14 17:38:29 +08:00
parent 7e19cd7e94
commit 522900ec32
2 changed files with 12 additions and 11 deletions

View File

@ -491,16 +491,15 @@ impl FlowDBStore {
}
}
}
} else if expected_index == batch_index {
} else {
while batch_index > expected_index {
// Fill the gap with empty leaves.
root_list.push((1, empty_root));
expected_index += 1;
}
range_root = Some(BatchRoot::Multiple((subtree_depth, root)));
root_list.push((subtree_depth, root));
expected_index += 1 << (subtree_depth - 1);
} else {
bail!(
"unexpected range root: expected={} get={}",
expected_index,
batch_index
);
}
}
let extra_node_list = self.get_mpt_node_list()?;

View File

@ -50,7 +50,7 @@ const PAD_MAX_SIZE: usize = 1 << 20;
pub struct UpdateFlowMessage {
pub root_map: BTreeMap<usize, (H256, usize)>,
pub pad_data: Vec<u8>,
pub pad_data: usize,
pub tx_start_flow_index: u64,
}
@ -760,7 +760,7 @@ impl LogManager {
fn start_receiver(&mut self, rx: mpsc::Receiver<UpdateFlowMessage>) {
let flow_store = self.flow_store.clone();
thread::spawn(move || -> Result<(), anyhow::Error> {
let handle = thread::spawn(move || -> Result<(), anyhow::Error> {
loop {
match rx.recv() {
std::result::Result::Ok(data) => {
@ -771,7 +771,7 @@ impl LogManager {
// subtrees with data known.
flow_store
.append_entries(ChunkArray {
data: data.pad_data,
data: vec![0; data.pad_data],
start_index: data.tx_start_flow_index,
})
.unwrap();
@ -782,6 +782,8 @@ impl LogManager {
}
}
});
// Wait for the spawned thread to finish
let _ = handle.join().expect("Thread panicked");
}
fn gen_proof(&self, flow_index: u64, maybe_root: Option<DataRoot>) -> Result<FlowProof> {
@ -974,7 +976,7 @@ impl LogManager {
if is_full_empty {
self.sender.send(UpdateFlowMessage {
root_map,
pad_data: pad_data.to_vec(),
pad_data: pad_data.len(),
tx_start_flow_index,
})?;
} else {