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 e58f6ca101
commit 93885bb25c
2 changed files with 9 additions and 10 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))); range_root = Some(BatchRoot::Multiple((subtree_depth, root)));
root_list.push((subtree_depth, root)); root_list.push((subtree_depth, root));
expected_index += 1 << (subtree_depth - 1); 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()?; 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 struct UpdateFlowMessage {
pub root_map: BTreeMap<usize, (H256, usize)>, pub root_map: BTreeMap<usize, (H256, usize)>,
pub pad_data: Vec<u8>, pub pad_data: usize,
pub tx_start_flow_index: u64, pub tx_start_flow_index: u64,
} }
@ -770,7 +770,7 @@ impl LogManager {
// subtrees with data known. // subtrees with data known.
flow_store flow_store
.append_entries(ChunkArray { .append_entries(ChunkArray {
data: data.pad_data, data: vec![0; data.pad_data],
start_index: data.tx_start_flow_index, start_index: data.tx_start_flow_index,
}) })
.unwrap(); .unwrap();
@ -973,7 +973,7 @@ impl LogManager {
if is_full_empty { if is_full_empty {
self.sender.send(UpdateFlowMessage { self.sender.send(UpdateFlowMessage {
root_map, root_map,
pad_data: pad_data.to_vec(), pad_data: pad_data.len(),
tx_start_flow_index, tx_start_flow_index,
})?; })?;
} else { } else {