}
}
- fn get_dest_dir_path(&self, namespace: &str, sub_namespace: &str) -> std::io::Result<PathBuf> {
+ fn get_dest_dir_path(&self, primary_namespace: &str, secondary_namespace: &str) -> std::io::Result<PathBuf> {
let mut dest_dir_path = {
#[cfg(target_os = "windows")]
{
}
};
- dest_dir_path.push(namespace);
- if !sub_namespace.is_empty() {
- dest_dir_path.push(sub_namespace);
+ dest_dir_path.push(primary_namespace);
+ if !secondary_namespace.is_empty() {
+ dest_dir_path.push(secondary_namespace);
}
Ok(dest_dir_path)
}
impl KVStore for FilesystemStore {
- fn read(&self, namespace: &str, sub_namespace: &str, key: &str) -> std::io::Result<Vec<u8>> {
- check_namespace_key_validity(namespace, sub_namespace, Some(key), "read")?;
+ fn read(&self, primary_namespace: &str, secondary_namespace: &str, key: &str) -> std::io::Result<Vec<u8>> {
+ check_namespace_key_validity(primary_namespace, secondary_namespace, Some(key), "read")?;
- let mut dest_file_path = self.get_dest_dir_path(namespace, sub_namespace)?;
+ let mut dest_file_path = self.get_dest_dir_path(primary_namespace, secondary_namespace)?;
dest_file_path.push(key);
let mut buf = Vec::new();
Ok(buf)
}
- fn write(&self, namespace: &str, sub_namespace: &str, key: &str, buf: &[u8]) -> std::io::Result<()> {
- check_namespace_key_validity(namespace, sub_namespace, Some(key), "write")?;
+ fn write(&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: &[u8]) -> std::io::Result<()> {
+ check_namespace_key_validity(primary_namespace, secondary_namespace, Some(key), "write")?;
- let mut dest_file_path = self.get_dest_dir_path(namespace, sub_namespace)?;
+ let mut dest_file_path = self.get_dest_dir_path(primary_namespace, secondary_namespace)?;
dest_file_path.push(key);
let parent_directory = dest_file_path
res
}
- fn remove(&self, namespace: &str, sub_namespace: &str, key: &str, lazy: bool) -> std::io::Result<()> {
- check_namespace_key_validity(namespace, sub_namespace, Some(key), "remove")?;
+ fn remove(&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool) -> std::io::Result<()> {
+ check_namespace_key_validity(primary_namespace, secondary_namespace, Some(key), "remove")?;
- let mut dest_file_path = self.get_dest_dir_path(namespace, sub_namespace)?;
+ let mut dest_file_path = self.get_dest_dir_path(primary_namespace, secondary_namespace)?;
dest_file_path.push(key);
if !dest_file_path.is_file() {
Ok(())
}
- fn list(&self, namespace: &str, sub_namespace: &str) -> std::io::Result<Vec<String>> {
- check_namespace_key_validity(namespace, sub_namespace, None, "list")?;
+ fn list(&self, primary_namespace: &str, secondary_namespace: &str) -> std::io::Result<Vec<String>> {
+ check_namespace_key_validity(primary_namespace, secondary_namespace, None, "list")?;
- let prefixed_dest = self.get_dest_dir_path(namespace, sub_namespace)?;
+ let prefixed_dest = self.get_dest_dir_path(primary_namespace, secondary_namespace)?;
let mut keys = Vec::new();
if !Path::new(&prefixed_dest).exists() {
let metadata = p.metadata()?;
- // We allow the presence of directories in the empty namespace and just skip them.
+ // We allow the presence of directories in the empty primary namespace and just skip them.
if metadata.is_dir() {
continue;
}
// If we otherwise don't find a file at the given path something went wrong.
if !metadata.is_file() {
debug_assert!(false, "Failed to list keys of {}/{}: file couldn't be accessed.",
- PrintableString(namespace), PrintableString(sub_namespace));
+ PrintableString(primary_namespace), PrintableString(secondary_namespace));
let msg = format!("Failed to list keys of {}/{}: file couldn't be accessed.",
- PrintableString(namespace), PrintableString(sub_namespace));
+ PrintableString(primary_namespace), PrintableString(secondary_namespace));
return Err(std::io::Error::new(std::io::ErrorKind::Other, msg));
}
}
} else {
debug_assert!(false, "Failed to list keys of {}/{}: file path is not valid UTF-8",
- PrintableString(namespace), PrintableString(sub_namespace));
+ PrintableString(primary_namespace), PrintableString(secondary_namespace));
let msg = format!("Failed to list keys of {}/{}: file path is not valid UTF-8",
- PrintableString(namespace), PrintableString(sub_namespace));
+ PrintableString(primary_namespace), PrintableString(secondary_namespace));
return Err(std::io::Error::new(std::io::ErrorKind::Other, msg));
}
}
Err(e) => {
debug_assert!(false, "Failed to list keys of {}/{}: {}",
- PrintableString(namespace), PrintableString(sub_namespace), e);
+ PrintableString(primary_namespace), PrintableString(secondary_namespace), e);
let msg = format!("Failed to list keys of {}/{}: {}",
- PrintableString(namespace), PrintableString(sub_namespace), e);
+ PrintableString(primary_namespace), PrintableString(secondary_namespace), e);
return Err(std::io::Error::new(std::io::ErrorKind::Other, msg));
}
}
use super::*;
use crate::test_utils::{do_read_write_remove_list_persist, do_test_store};
- use bitcoin::hashes::hex::FromHex;
use bitcoin::Txid;
use lightning::chain::ChannelMonitorUpdateStatus;
use lightning::ln::functional_test_utils::*;
use lightning::util::test_utils;
use lightning::util::persist::read_channel_monitors;
- use std::fs;
- #[cfg(target_os = "windows")]
- use {
- lightning::get_event_msg,
- lightning::ln::msgs::ChannelMessageHandler,
- };
+ use std::str::FromStr;
impl Drop for FilesystemStore {
fn drop(&mut self) {
}
// Test that if the store's path to channel data is read-only, writing a
- // monitor to it results in the store returning an InProgress.
+ // monitor to it results in the store returning an UnrecoverableError.
// Windows ignores the read-only flag for folders, so this test is Unix-only.
#[cfg(not(target_os = "windows"))]
#[test]
nodes[1].node.force_close_broadcasting_latest_txn(&chan.2, &nodes[0].node.get_our_node_id()).unwrap();
check_closed_event!(nodes[1], 1, ClosureReason::HolderForceClosed, [nodes[0].node.get_our_node_id()], 100000);
let mut added_monitors = nodes[1].chain_monitor.added_monitors.lock().unwrap();
- let update_map = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap();
- let update_id = update_map.get(&added_monitors[0].0.to_channel_id()).unwrap();
// Set the store's directory to read-only, which should result in
- // returning a permanent failure when we then attempt to persist a
+ // returning an unrecoverable failure when we then attempt to persist a
// channel update.
let path = &store.get_data_dir();
let mut perms = fs::metadata(path).unwrap().permissions();
fs::set_permissions(path, perms).unwrap();
let test_txo = OutPoint {
- txid: Txid::from_hex("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(),
+ txid: Txid::from_str("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(),
index: 0
};
- match store.persist_new_channel(test_txo, &added_monitors[0].1, update_id.2) {
- ChannelMonitorUpdateStatus::InProgress => {},
+ match store.persist_new_channel(test_txo, &added_monitors[0].1) {
+ ChannelMonitorUpdateStatus::UnrecoverableError => {},
_ => panic!("unexpected result from persisting new channel")
}
check_closed_event!(nodes[1], 1, ClosureReason::HolderForceClosed, [nodes[0].node.get_our_node_id()], 100000);
let mut added_monitors = nodes[1].chain_monitor.added_monitors.lock().unwrap();
let update_map = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap();
- let update_id = update_map.get(&added_monitors[0].0.to_channel_id()).unwrap();
+ let update_id = update_map.get(&added_monitors[0].1.channel_id()).unwrap();
// Create the store with an invalid directory name and test that the
// channel fails to open because the directories fail to be created. There
let store = FilesystemStore::new(":<>/".into());
let test_txo = OutPoint {
- txid: Txid::from_hex("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(),
+ txid: Txid::from_str("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(),
index: 0
};
- match store.persist_new_channel(test_txo, &added_monitors[0].1, update_id.2) {
- ChannelMonitorUpdateStatus::InProgress => {},
+ match store.persist_new_channel(test_txo, &added_monitors[0].1) {
+ ChannelMonitorUpdateStatus::UnrecoverableError => {},
_ => panic!("unexpected result from persisting new channel")
}