apply non mutating actions
MODIFY
light_node/src/configuration.rs
light_node/src/configuration.rs
@@ -59,7 +59,7 @@ impl ContextActionStoreBackend {
fn supported_values(&self) -> Vec<&'static str> {
match self {
ContextActionStoreBackend::RocksDB => vec!["rocksdb"],
- ContextActionStoreBackend::FileStorage => vec!["file"],
+ ContextActionStoreBackend::FileStorage { .. } => vec!["file"],
ContextActionStoreBackend::NoneBackend => vec!["none"],
}
}
@@ -939,6 +939,15 @@ impl Environment {
|value| {
value
.parse::<KeyValueStoreBackend>()
+ .map(|v| {
+ if let KeyValueStoreBackend::Sled { .. } = v {
+ KeyValueStoreBackend::Sled {
+ path: db_path.join("sled"),
+ }
+ } else {
+ v
+ }
+ })
.expect("Was expecting one value from KeyValueStoreBackend")
},
);

MODIFY
shell/tests/apply_and_verify_context_actions_from_file.rs
shell/tests/apply_and_verify_context_actions_from_file.rs
@@ -134,16 +134,20 @@ fn feed_tezedge_context_with_actions() -> Result<(), Error> {
let header_stub = BlockHeaderWithHash::new(block_header_stub).unwrap();
let cache = Cache::new_lru_cache(128 * 1024 * 1024).unwrap(); // 128 MB
- let commit_log_db_path = PathBuf::from("/tmp/commit_log/");
- let key_value_db_path = PathBuf::from("/tmp/key_value_store/");
+ let out_dir_env = env::var("OUT_DIR")
+ .unwrap_or_else(|_| "/tmp/feed_tezedge_context_with_actions".to_string());
let input_file = env::var("INPUT").expect("test input 'INPUT' not set");
let backend = env::var("BACKEND").expect("test backend 'BACKEND' not set");
+ let out_dir = PathBuf::from(out_dir_env.as_str());
+ let commit_log_db_path = out_dir.join("commit_log");
+ let key_value_db_path = out_dir.join("key_value_store");
+
let actions_storage_path = PathBuf::from(input_file.as_str());
- let _ = fs::remove_dir_all(&commit_log_db_path);
- let _ = fs::remove_dir_all(&key_value_db_path);
+ let _ = fs::remove_dir_all(&out_dir);
+
let logger = create_logger();
let commit_log = create_commit_log(&commit_log_db_path);
@@ -155,7 +159,9 @@ fn feed_tezedge_context_with_actions() -> Result<(), Error> {
commit_log,
match backend.as_str() {
"inmem" => storage::KeyValueStoreBackend::InMem,
- "sled" => storage::KeyValueStoreBackend::Sled,
+ "sled" => storage::KeyValueStoreBackend::Sled {
+ path: out_dir.join("sled"),
+ },
"btree" => storage::KeyValueStoreBackend::BTreeMap,
"rocksdb" => storage::KeyValueStoreBackend::RocksDB,
_ => panic!("unknown backend"),
@@ -229,30 +235,48 @@ fn feed_tezedge_context_with_actions() -> Result<(), Error> {
| ContextAction::Delete { .. }
| ContextAction::RemoveRecursively { .. }
| ContextAction::Commit { .. }
- | ContextAction::Checkout { .. } => {
+ | ContextAction::Checkout { .. }
+ | ContextAction::Get { .. }
+ | ContextAction::Mem { .. }
+ | ContextAction::DirMem { .. }
+ | ContextAction::Fold { .. } => {
if let Err(e) = perform_context_action(&action, &mut context) {
panic!("cannot perform action error: '{}'", e);
}
}
- ContextAction::Get { .. }
- | ContextAction::Mem { .. }
- | ContextAction::DirMem { .. }
- | ContextAction::Fold { .. }
- | ContextAction::Shutdown { .. } => {}
+ ContextAction::Shutdown { .. } => {}
};
- if let ContextAction::Commit {
+ // verify state of the storage after action has been applied
+ match action {
+ ContextAction::Commit {
new_context_hash, ..
- } = action
- {
+ } => {
+ assert_eq!(
+ new_context_hash.clone(),
+ context.get_last_commit_hash().unwrap()
+ );
+ }
+ ContextAction::Checkout { context_hash, .. } => {
+ assert!(!context_hash.is_empty());
assert_eq!(
- new_context_hash.as_slice(),
- context.get_last_commit_hash().unwrap().as_slice()
+ context_hash.clone(),
+ context.get_last_commit_hash().unwrap()
);
}
+ ContextAction::Get { key, value, .. } => {
+ assert_eq!(value.clone(), context.get_key(key).unwrap());
+ }
+ ContextAction::Mem { key, value, .. } => {
+ assert_eq!(*value, context.mem(key).unwrap());
+ }
+ ContextAction::DirMem { key, value, .. } => {
+ assert_eq!(*value, context.dirmem(key).unwrap());
+ }
+ _ => {}
+ };
// verify context hashes after each block
-
if let Some(expected_hash) = get_new_tree_hash(&action) {
assert_eq!(context.get_merkle_root(), expected_hash);
}

MODIFY
storage/src/lib.rs
storage/src/lib.rs
#![feature(allocator_api)]
use std::convert::{TryFrom, TryInto};
-use std::path::Path;
+use std::path::{Path, PathBuf};
use std::sync::Arc;
use failure::Fail;
@@ -476,7 +476,7 @@ pub fn check_database_compatibility(
pub enum KeyValueStoreBackend {
RocksDB,
InMem,
- Sled,
+ Sled { path: PathBuf },
BTreeMap,
}
@@ -493,7 +493,7 @@ impl KeyValueStoreBackend {
match self {
KeyValueStoreBackend::RocksDB => vec!["rocksdb"],
KeyValueStoreBackend::InMem => vec!["inmem"],
- KeyValueStoreBackend::Sled => vec!["sled"],
+ KeyValueStoreBackend::Sled { .. } => vec!["sled"],
KeyValueStoreBackend::BTreeMap => vec!["btree"],
}
}

MODIFY
storage/src/persistent/mod.rs
storage/src/persistent/mod.rs
@@ -159,8 +159,8 @@ impl PersistentStorage {
MerkleStorage::name(),
))),
KeyValueStoreBackend::InMem => MerkleStorage::new(Box::new(InMemoryBackend::new())),
- KeyValueStoreBackend::Sled => {
- let sled = sled::Config::new().temporary(true).open().unwrap();
+ KeyValueStoreBackend::Sled { path } => {
+ let sled = sled::Config::new().path(path).open().unwrap();
MerkleStorage::new(Box::new(SledBackend::new(sled.deref().clone())))
}
KeyValueStoreBackend::BTreeMap => MerkleStorage::new(Box::new(BTreeMapBackend::new())),

apply non mutating actions