From a409689c40b8d914f23a1b62271d50282fdc8adc Mon Sep 17 00:00:00 2001 From: Peilun Li Date: Sat, 12 Oct 2024 16:06:43 +0800 Subject: [PATCH] Fix proof insertion. --- common/append_merkle/src/lib.rs | 24 ++++++++++++------------ common/task_executor/Cargo.toml | 2 +- node/storage/Cargo.toml | 2 +- node/storage/src/log_store/tx_store.rs | 6 +----- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/common/append_merkle/src/lib.rs b/common/append_merkle/src/lib.rs index 55fe806..e0548fe 100644 --- a/common/append_merkle/src/lib.rs +++ b/common/append_merkle/src/lib.rs @@ -226,18 +226,18 @@ impl> AppendMerkleTree { &mut self, proof: RangeProof, ) -> Result> { - self.fill_with_proof( - proof - .left_proof - .proof_nodes_in_tree() - .split_off(self.leaf_height), - )?; - self.fill_with_proof( - proof - .right_proof - .proof_nodes_in_tree() - .split_off(self.leaf_height), - ) + let mut updated_nodes = Vec::new(); + let mut left_nodes = proof.left_proof.proof_nodes_in_tree(); + if left_nodes.len() >= self.leaf_height { + updated_nodes + .append(&mut self.fill_with_proof(left_nodes.split_off(self.leaf_height))?); + } + let mut right_nodes = proof.right_proof.proof_nodes_in_tree(); + if right_nodes.len() >= self.leaf_height { + updated_nodes + .append(&mut self.fill_with_proof(right_nodes.split_off(self.leaf_height))?); + } + Ok(updated_nodes) } pub fn fill_with_file_proof( diff --git a/common/task_executor/Cargo.toml b/common/task_executor/Cargo.toml index c4c0b44..c40f916 100644 --- a/common/task_executor/Cargo.toml +++ b/common/task_executor/Cargo.toml @@ -9,5 +9,5 @@ exit-future = "0.2.0" futures = "0.3.21" lazy_static = "1.4.0" lighthouse_metrics = { path = "../lighthouse_metrics" } -tokio = { version = "1.19.2", features = ["rt"] } +tokio = { version = "1.38.0", features = ["full"] } tracing = "0.1.35" diff --git a/node/storage/Cargo.toml b/node/storage/Cargo.toml index 9c7ebca..225b8c3 100644 --- a/node/storage/Cargo.toml +++ b/node/storage/Cargo.toml @@ -29,7 +29,7 @@ itertools = "0.13.0" serde = { version = "1.0.197", features = ["derive"] } parking_lot = "0.12.3" serde_json = "1.0.127" -tokio = { version = "1.10.0", features = ["sync"] } +tokio = { version = "1.38.0", features = ["full"] } task_executor = { path = "../../common/task_executor" } [dev-dependencies] diff --git a/node/storage/src/log_store/tx_store.rs b/node/storage/src/log_store/tx_store.rs index 48ee2ab..39fb893 100644 --- a/node/storage/src/log_store/tx_store.rs +++ b/node/storage/src/log_store/tx_store.rs @@ -335,11 +335,7 @@ impl TransactionStore { } let mut merkle = if last_chunk_start_index == 0 { // The first entry hash is initialized as zero. - AppendMerkleTree::::new_with_depth( - vec![H256::zero()], - log2_pow2(PORA_CHUNK_SIZE) + 1, - None, - ) + AppendMerkleTree::::new_with_depth(vec![H256::zero()], 1, None) } else { AppendMerkleTree::::new_with_depth( vec![],