From dace92aca14b364ee705f49b517a6c7e7a0691cb Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Tue, 27 Oct 2020 14:24:00 -0700 Subject: [PATCH] state: add SLED_FORMAT_VERSION prefix to db path Also removes a redundant test. --- zebra-state/src/config.rs | 7 ++++++- zebra-state/src/constants.rs | 2 ++ zebra-state/src/tests.rs | 31 +------------------------------ 3 files changed, 9 insertions(+), 31 deletions(-) diff --git a/zebra-state/src/config.rs b/zebra-state/src/config.rs index a0c67a35..bdc5b74e 100644 --- a/zebra-state/src/config.rs +++ b/zebra-state/src/config.rs @@ -61,7 +61,12 @@ impl Config { if self.ephemeral { config.temporary(self.ephemeral) } else { - let path = self.cache_dir.join(net_dir).join("state"); + let path = self + .cache_dir + .join("state") + .join(format!("v{}", crate::constants::SLED_FORMAT_VERSION)) + .join(net_dir); + config.path(path) } } diff --git a/zebra-state/src/constants.rs b/zebra-state/src/constants.rs index 9143abfe..7664f89c 100644 --- a/zebra-state/src/constants.rs +++ b/zebra-state/src/constants.rs @@ -13,3 +13,5 @@ pub const MIN_TRASPARENT_COINBASE_MATURITY: block::Height = block::Height(100); /// coinbase transactions. pub const MAX_BLOCK_REORG_HEIGHT: block::Height = block::Height(MIN_TRASPARENT_COINBASE_MATURITY.0 - 1); + +pub const SLED_FORMAT_VERSION: u32 = 0; diff --git a/zebra-state/src/tests.rs b/zebra-state/src/tests.rs index 83800e86..26aeb1e4 100644 --- a/zebra-state/src/tests.rs +++ b/zebra-state/src/tests.rs @@ -1,36 +1,7 @@ -use std::ffi::OsStr; - -use zebra_chain::{block, parameters::Network}; +use zebra_chain::block; use super::*; -#[test] -fn test_path_mainnet() { - test_path(Network::Mainnet); -} - -#[test] -fn test_path_testnet() { - test_path(Network::Testnet); -} - -/// Check the sled path for `network`. -fn test_path(network: Network) { - zebra_test::init(); - - let config = Config::default(); - // we can't do many useful tests on this value, because it depends on the - // local environment and OS. - let sled_config = config.sled_config(network); - let mut path = sled_config.get_path(); - assert_eq!(path.file_name(), Some(OsStr::new("state"))); - assert!(path.pop()); - match network { - Network::Mainnet => assert_eq!(path.file_name(), Some(OsStr::new("mainnet"))), - Network::Testnet => assert_eq!(path.file_name(), Some(OsStr::new("testnet"))), - } -} - /// Block heights, and the expected minimum block locator height static BLOCK_LOCATOR_CASES: &[(u32, u32)] = &[ (0, 0),