From 1439d921da12c1022756ada79033dc6ea678cb14 Mon Sep 17 00:00:00 2001 From: parazyd Date: Sun, 3 Apr 2022 15:55:06 +0200 Subject: [PATCH] blockstore: Use sled::Batch for insert(). --- src/blockchain2/blockstore.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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(()) }