From 93885bb25ca649707a73ec10b4fefb58afa33ed7 Mon Sep 17 00:00:00 2001 From: Peter Zhang Date: Sat, 14 Sep 2024 17:38:29 +0800 Subject: [PATCH] range root should also add back missing padded data --- node/storage/src/log_store/flow_store.rs | 13 ++++++------- node/storage/src/log_store/log_manager.rs | 6 +++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/node/storage/src/log_store/flow_store.rs b/node/storage/src/log_store/flow_store.rs index 8083af7..11f20f0 100644 --- a/node/storage/src/log_store/flow_store.rs +++ b/node/storage/src/log_store/flow_store.rs @@ -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()?; diff --git a/node/storage/src/log_store/log_manager.rs b/node/storage/src/log_store/log_manager.rs index 0aa0bba..6471667 100644 --- a/node/storage/src/log_store/log_manager.rs +++ b/node/storage/src/log_store/log_manager.rs @@ -50,7 +50,7 @@ const PAD_MAX_SIZE: usize = 1 << 20; pub struct UpdateFlowMessage { pub root_map: BTreeMap, - pub pad_data: Vec, + pub pad_data: usize, pub tx_start_flow_index: u64, } @@ -770,7 +770,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(); @@ -973,7 +973,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 {