From 3679a0f1cbd520abba3832763e44e8a0e43b0328 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Wed, 11 Jan 2023 13:38:43 +0100 Subject: [PATCH] Improve syntax --- beacon_node/client/src/config.rs | 7 +++--- beacon_node/store/src/hot_cold_store.rs | 29 +++++++++++-------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/beacon_node/client/src/config.rs b/beacon_node/client/src/config.rs index 598945923..10bca9471 100644 --- a/beacon_node/client/src/config.rs +++ b/beacon_node/client/src/config.rs @@ -168,10 +168,9 @@ impl Config { /// Get the blobs freezer DB path, creating it if necessary. pub fn create_blobs_freezer_db_path(&self) -> Result, String> { - if let Some(blobs_freezer_path) = self.get_blobs_freezer_db_path() { - Ok(Some(ensure_dir_exists(blobs_freezer_path)?)) - } else { - Ok(None) + match self.get_blobs_freezer_db_path() { + Some(blobs_freezer_path) => Ok(Some(ensure_dir_exists(blobs_freezer_path)?)), + None => Ok(None), } } diff --git a/beacon_node/store/src/hot_cold_store.rs b/beacon_node/store/src/hot_cold_store.rs index ef7175c9f..01971e2b3 100644 --- a/beacon_node/store/src/hot_cold_store.rs +++ b/beacon_node/store/src/hot_cold_store.rs @@ -1250,15 +1250,16 @@ impl, Cold: ItemStore> HotColdDB pub fn load_hot_blobs(&self, block_root: &Hash256) -> Result>, Error> { // FIXME(sean) I was attempting to use a blob cache here but was getting deadlocks, // may want to attempt to use one again - if let Some(bytes) = self + match self .hot_db .get_bytes(DBColumn::BeaconBlob.into(), block_root.as_bytes())? { - let ret = BlobsSidecar::from_ssz_bytes(&bytes)?; - self.blob_cache.lock().put(*block_root, ret.clone()); - Ok(Some(ret)) - } else { - Ok(None) + Some(bytes) => { + let ret = BlobsSidecar::from_ssz_bytes(&bytes)?; + self.blob_cache.lock().put(*block_root, ret.clone()); + Ok(Some(ret)) + } + None => Ok(None), } } @@ -1272,12 +1273,9 @@ impl, Cold: ItemStore> HotColdDB &self.cold_db }; - if let Some(ref blobs_bytes) = - blobs_freezer.get_bytes(DBColumn::BeaconBlob.into(), block_root.as_bytes())? - { - Ok(Some(BlobsSidecar::from_ssz_bytes(blobs_bytes)?)) - } else { - Ok(None) + match blobs_freezer.get_bytes(DBColumn::BeaconBlob.into(), block_root.as_bytes())? { + Some(ref blobs_bytes) => Ok(Some(BlobsSidecar::from_ssz_bytes(blobs_bytes)?)), + None => Ok(None), } } @@ -1989,10 +1987,9 @@ pub fn migrate_database, Cold: ItemStore>( let mut hot_db_ops: Vec> = Vec::new(); let mut cold_blobs_db_ops: Vec> = Vec::new(); - let blobs_freezer = if let Some(ref cold_blobs_db) = store.cold_blobs_db { - cold_blobs_db - } else { - &store.cold_db + let blobs_freezer = match store.cold_blobs_db { + Some(ref cold_blobs_db) => cold_blobs_db, + None => &store.cold_db, }; // 1. Copy all of the states between the head and the split slot, from the hot DB