diff --git a/beacon_node/store/src/hot_cold_store.rs b/beacon_node/store/src/hot_cold_store.rs index 201a78afd..17c5a81b8 100644 --- a/beacon_node/store/src/hot_cold_store.rs +++ b/beacon_node/store/src/hot_cold_store.rs @@ -123,6 +123,7 @@ pub enum HotColdDBError { request_slot: Option, state_root: Hash256, }, + Rollback, } impl HotColdDB, MemoryStore> { @@ -906,22 +907,17 @@ impl, Cold: ItemStore> HotColdDB }; // Rollback on failure if let Err(e) = tx_res { - let mut rollback_blob_ops: Vec> = Vec::with_capacity(blob_cache_ops.len()); - for blob_op in blob_cache_ops { - match blob_op { - StoreOp::PutBlobs(block_root, _) => { - rollback_blob_ops.push(StoreOp::DeleteBlobs(block_root)); - } - StoreOp::DeleteBlobs(_) => { - if let Some(blobs) = blobs_to_delete.pop() { - rollback_blob_ops - .push(StoreOp::PutBlobs(blobs.beacon_block_root, Arc::new(blobs))); - } - } - _ => (), - } + for op in blob_cache_ops.iter_mut() { + let reverse_op = match op { + StoreOp::PutBlobs(block_root, _) => StoreOp::DeleteBlobs(block_root), + StoreOp::DeleteBlobs(_) => match blobs_to_delete.pop() { + Some(blobs) => StoreOp::PutBlobs(blobs.beacon_block_root, Arc::new(blobs)), + None => return Err(HotColdDBError::Rollback.into()), + }, + _ => return Err(HotColdDBError::Rollback.into()), + }; } - blobs_db.do_atomically(self.convert_to_kv_batch(rollback_blob_ops)?)?; + blobs_db.do_atomically(self.convert_to_kv_batch(blob_cache_ops)?)?; return Err(e); }