From 420f84cb330a78ce63fd19f094750106d7112ea6 Mon Sep 17 00:00:00 2001 From: Odysseas Gabrielides Date: Mon, 13 Jan 2025 18:10:41 +0200 Subject: [PATCH] suggestions --- packages/rs-drive-abci/src/abci/config.rs | 7 +++++++ .../src/abci/handler/apply_snapshot_chunk.rs | 9 --------- .../rs-drive-abci/src/abci/handler/list_snapshots.rs | 6 ++---- .../rs-drive-abci/src/platform_types/snapshot/mod.rs | 4 ++-- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/rs-drive-abci/src/abci/config.rs b/packages/rs-drive-abci/src/abci/config.rs index 3a3fe3a150..65fdb81fb2 100644 --- a/packages/rs-drive-abci/src/abci/config.rs +++ b/packages/rs-drive-abci/src/abci/config.rs @@ -70,6 +70,7 @@ pub struct StateSyncAbciConfig { pub snapshots_enabled: bool, /// Path to checkpoints + #[serde(default = "StateSyncAbciConfig::default_checkpoints_path")] pub checkpoints_path: PathBuf, /// Frequency of snapshot creation (in blocks) @@ -113,4 +114,10 @@ impl StateSyncAbciConfig { max_num_snapshots: 10, } } + + fn default_checkpoints_path() -> PathBuf { + std::env::var("CHECKPOINTS_PATH") + .map(PathBuf::from) + .unwrap_or_else(|_| PathBuf::from("/var/lib/dash-platform/data/checkpoints")) + } } diff --git a/packages/rs-drive-abci/src/abci/handler/apply_snapshot_chunk.rs b/packages/rs-drive-abci/src/abci/handler/apply_snapshot_chunk.rs index 782a1d7c7a..a87efb9551 100644 --- a/packages/rs-drive-abci/src/abci/handler/apply_snapshot_chunk.rs +++ b/packages/rs-drive-abci/src/abci/handler/apply_snapshot_chunk.rs @@ -90,15 +90,6 @@ where ) })?; if incorrect_hashes.len() > 0 { - for element in incorrect_hashes.keys() { - let subtree_path: Vec<&[u8]> = element.iter().map(|vec| vec.as_slice()).collect(); - let path: &[&[u8]] = &subtree_path; - let prefix = RocksDbStorage::build_prefix(path.into()).unwrap(); - println!( - "[state_sync] incorrect hash in prefix:{:?}", - hex::encode(prefix) - ); - } Err(AbciError::StateSyncInternalError(format!( "apply_snapshot_chunk grovedb verification failed with {} incorrect hashes", incorrect_hashes.len() diff --git a/packages/rs-drive-abci/src/abci/handler/list_snapshots.rs b/packages/rs-drive-abci/src/abci/handler/list_snapshots.rs index a69c26c293..7e838d0328 100644 --- a/packages/rs-drive-abci/src/abci/handler/list_snapshots.rs +++ b/packages/rs-drive-abci/src/abci/handler/list_snapshots.rs @@ -1,3 +1,4 @@ +use std::path::Path; use crate::abci::app::{PlatformApplication, SnapshotManagerApplication}; use crate::abci::handler::error::error_into_exception; use crate::abci::AbciError; @@ -37,10 +38,7 @@ where } }; let checkpoint_exists = |s: &Snapshot| -> bool { - match GroveDb::open(&s.path) { - Ok(_) => true, - Err(_) => false, - } + Path::new(&s.path).exists() }; response.snapshots = snapshots diff --git a/packages/rs-drive-abci/src/platform_types/snapshot/mod.rs b/packages/rs-drive-abci/src/platform_types/snapshot/mod.rs index 84405250f5..c618bdd4d7 100644 --- a/packages/rs-drive-abci/src/platform_types/snapshot/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/snapshot/mod.rs @@ -127,7 +127,7 @@ impl SnapshotManager { pub fn get_snapshots(&self, grove: &GroveDb) -> Result, Error> { let data = grove .get_aux(SNAPSHOT_KEY, None) - .unwrap() + .value .map_err(|e| Error::Drive(GroveDB(e)))?; match data { @@ -208,7 +208,7 @@ impl SnapshotManager { .map_err(|e| Error::Drive(Drive(DriveError::Snapshot(e.to_string()))))?; grove .put_aux(SNAPSHOT_KEY, data.as_slice(), None, None) - .unwrap() + .value .map_err(|e| Error::Drive(GroveDB(e)))?; Ok(()) }