From 38cbb8e182a7c4e4e06af05552f615819b55ad5d Mon Sep 17 00:00:00 2001 From: Peilun Li Date: Mon, 17 Jun 2024 23:53:10 +0800 Subject: [PATCH] Remove mut. --- node/log_entry_sync/src/sync_manager/mod.rs | 2 +- node/storage/src/log_store/log_manager.rs | 20 ++++++++++---------- node/storage/src/log_store/mod.rs | 14 +++++++------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/node/log_entry_sync/src/sync_manager/mod.rs b/node/log_entry_sync/src/sync_manager/mod.rs index fef288f..ebcbc85 100644 --- a/node/log_entry_sync/src/sync_manager/mod.rs +++ b/node/log_entry_sync/src/sync_manager/mod.rs @@ -401,7 +401,7 @@ impl LogSyncManager { false } else { if let Some(data) = self.data_cache.pop_data(&tx.data_merkle_root) { - let mut store = self.store.write().await; + let store = self.store.write().await; // We are holding a mutable reference of LogSyncManager, so no chain reorg is // possible after put_tx. if let Err(e) = store diff --git a/node/storage/src/log_store/log_manager.rs b/node/storage/src/log_store/log_manager.rs index b86d7a2..6993c7a 100644 --- a/node/storage/src/log_store/log_manager.rs +++ b/node/storage/src/log_store/log_manager.rs @@ -150,7 +150,7 @@ impl LogStoreInner for LogManager { } impl LogStoreChunkWrite for LogManager { - fn put_chunks(&mut self, tx_seq: u64, chunks: ChunkArray) -> Result<()> { + fn put_chunks(&self, tx_seq: u64, chunks: ChunkArray) -> Result<()> { let mut merkle = self.merkle.write(); let tx = self .tx_store @@ -175,7 +175,7 @@ impl LogStoreChunkWrite for LogManager { } fn put_chunks_with_tx_hash( - &mut self, + &self, tx_seq: u64, tx_hash: H256, chunks: ChunkArray, @@ -242,7 +242,7 @@ impl LogStoreWrite for LogManager { /// Only the last tx may have this case, so we rerun /// `put_tx` for the last tx when we restart the node to ensure that it succeeds. /// - fn put_tx(&mut self, tx: Transaction) -> Result<()> { + fn put_tx(&self, tx: Transaction) -> Result<()> { let mut merkle = self.merkle.write(); debug!("put_tx: tx={:?}", tx); let expected_seq = self.next_tx_seq(); @@ -276,7 +276,7 @@ impl LogStoreWrite for LogManager { Ok(()) } - fn finalize_tx(&mut self, tx_seq: u64) -> Result<()> { + fn finalize_tx(&self, tx_seq: u64) -> Result<()> { let tx = self .tx_store .get_tx_by_seq_number(tx_seq)? @@ -302,7 +302,7 @@ impl LogStoreWrite for LogManager { } } - fn finalize_tx_with_hash(&mut self, tx_seq: u64, tx_hash: H256) -> crate::error::Result { + fn finalize_tx_with_hash(&self, tx_seq: u64, tx_hash: H256) -> crate::error::Result { trace!( "finalize_tx_with_hash: tx_seq={} tx_hash={:?}", tx_seq, @@ -343,7 +343,7 @@ impl LogStoreWrite for LogManager { /// Return the reverted Transactions in order. /// `tx_seq == u64::MAX` is a special case for reverting all transactions. - fn revert_to(&mut self, tx_seq: u64) -> Result> { + fn revert_to(&self, tx_seq: u64) -> Result> { // FIXME(zz): If this revert is triggered by chain reorg after restarts, this will fail. let mut merkle = self.merkle.write(); merkle.revert_merkle_tree(tx_seq, &self.tx_store)?; @@ -362,7 +362,7 @@ impl LogStoreWrite for LogManager { } fn validate_and_insert_range_proof( - &mut self, + &self, tx_seq: u64, data: &ChunkArrayWithProof, ) -> Result { @@ -681,7 +681,7 @@ impl LogManager { pora_chunks_merkle, last_chunk_merkle, }); - let mut log_manager = Self { + let log_manager = Self { db, tx_store, flow_store, @@ -960,7 +960,7 @@ impl LogManager { &self.flow_store } - fn padding_rear_data(&mut self, tx: &Transaction) -> Result<()> { + fn padding_rear_data(&self, tx: &Transaction) -> Result<()> { let (chunks, _) = compute_padded_chunk_size(tx.size as usize); let (segments_for_proof, last_segment_size_for_proof) = compute_segment_size(chunks, PORA_CHUNK_SIZE); @@ -1007,7 +1007,7 @@ impl LogManager { Ok(()) } - fn copy_tx_data(&mut self, from_tx_seq: u64, to_tx_seq_list: Vec) -> Result<()> { + fn copy_tx_data(&self, from_tx_seq: u64, to_tx_seq_list: Vec) -> Result<()> { let mut merkle = self.merkle.write(); // We have all the data need for this tx, so just copy them. let old_tx = self diff --git a/node/storage/src/log_store/mod.rs b/node/storage/src/log_store/mod.rs index d47f411..4e0f391 100644 --- a/node/storage/src/log_store/mod.rs +++ b/node/storage/src/log_store/mod.rs @@ -103,7 +103,7 @@ pub trait LogStoreChunkRead { pub trait LogStoreWrite: LogStoreChunkWrite { /// Store a data entry metadata. - fn put_tx(&mut self, tx: Transaction) -> Result<()>; + fn put_tx(&self, tx: Transaction) -> Result<()>; /// Finalize a transaction storage. /// This will compute and the merkle tree, check the data root, and persist a part of the merkle @@ -111,8 +111,8 @@ pub trait LogStoreWrite: LogStoreChunkWrite { /// /// This will return error if not all chunks are stored. But since this check can be expensive, /// the caller is supposed to track chunk statuses and call this after storing all the chunks. - fn finalize_tx(&mut self, tx_seq: u64) -> Result<()>; - fn finalize_tx_with_hash(&mut self, tx_seq: u64, tx_hash: H256) -> Result; + fn finalize_tx(&self, tx_seq: u64) -> Result<()>; + fn finalize_tx_with_hash(&self, tx_seq: u64, tx_hash: H256) -> Result; /// Store the progress of synced block number and its hash. fn put_sync_progress(&self, progress: (u64, H256, Option>)) -> Result<()>; @@ -121,11 +121,11 @@ pub trait LogStoreWrite: LogStoreChunkWrite { /// This is needed when transactions are reverted because of chain reorg. /// /// Reverted transactions are returned in order. - fn revert_to(&mut self, tx_seq: u64) -> Result>; + fn revert_to(&self, tx_seq: u64) -> Result>; /// If the proof is valid, fill the tree nodes with the new data. fn validate_and_insert_range_proof( - &mut self, + &self, tx_seq: u64, data: &ChunkArrayWithProof, ) -> Result; @@ -135,10 +135,10 @@ pub trait LogStoreWrite: LogStoreChunkWrite { pub trait LogStoreChunkWrite { /// Store data chunks of a data entry. - fn put_chunks(&mut self, tx_seq: u64, chunks: ChunkArray) -> Result<()>; + fn put_chunks(&self, tx_seq: u64, chunks: ChunkArray) -> Result<()>; fn put_chunks_with_tx_hash( - &mut self, + &self, tx_seq: u64, tx_hash: H256, chunks: ChunkArray,