diff --git a/src/blockchain2/blockstore.rs b/src/blockchain2/blockstore.rs index 2a6cac262..a1083a797 100644 --- a/src/blockchain2/blockstore.rs +++ b/src/blockchain2/blockstore.rs @@ -1,3 +1,5 @@ +use sled::Batch; + use crate::{ util::serial::{deserialize, serialize, SerialDecodable, SerialEncodable}, Result, @@ -32,12 +34,15 @@ impl BlockStore { /// The blocks are hashed with blake3 and this blockhash is used as // the key, where value is the serialized block itself. pub fn insert(&self, blocks: Vec) -> Result<()> { + let mut batch = Batch::default(); for i in &blocks { let serialized = serialize(i); let blockhash = blake3::hash(&serialized); - self.0.insert(blockhash.as_bytes(), serialized)?; + batch.insert(blockhash.as_bytes(), serialized); } + self.0.apply_batch(batch)?; + Ok(()) }