From 82de096cf2bd0145d64bed9a575638a25b561d24 Mon Sep 17 00:00:00 2001 From: raulk Date: Wed, 16 Nov 2022 18:52:22 +0000 Subject: [PATCH] fix: BufferedBlockstore#flush should not reset the write buffer. (#1096) Resetting the buffer was never advertised as a behaviour of this method. This makes it possible to call flush multiple times to selectively flush roots during its lifetime. Selective flushes are used to flush the event AMTs as they are being produced. --- fvm/src/blockstore/buffered.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/fvm/src/blockstore/buffered.rs b/fvm/src/blockstore/buffered.rs index 422b8f072..f1f5e4253 100644 --- a/fvm/src/blockstore/buffered.rs +++ b/fvm/src/blockstore/buffered.rs @@ -42,14 +42,13 @@ where { /// Flushes the buffered cache based on the root node. /// This will recursively traverse the cache and write all data connected by links to this - /// root Cid. + /// root Cid. Calling flush will not reset the write buffer. fn flush(&self, root: &Cid) -> Result<()> { let mut buffer = Vec::new(); - let mut s = self.write.borrow_mut(); + let s = self.write.borrow(); copy_rec(&s, *root, &mut buffer)?; self.base.put_many_keyed(buffer)?; - *s = Default::default(); Ok(()) } @@ -290,7 +289,6 @@ mod tests { buf_store.flush(&cid).unwrap(); assert_eq!(buf_store.get_cbor::(&cid).unwrap(), Some(8)); assert_eq!(mem.get_cbor::(&cid).unwrap(), Some(8)); - assert!(buf_store.write.borrow().get(&cid).is_none()); } #[test] @@ -361,6 +359,5 @@ mod tests { assert_eq!(buf_store.get(&unsealed_comm_cid).unwrap(), None); assert_eq!(buf_store.get(&sealed_comm_cid).unwrap(), None); assert_eq!(mem.get_cbor::(&unconnected).unwrap(), None); - assert_eq!(buf_store.get_cbor::(&unconnected).unwrap(), None); } }