-
Notifications
You must be signed in to change notification settings - Fork 407
persist: Persist ChannelMonitors in their own directory. #806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
persist: Persist ChannelMonitors in their own directory. #806
Conversation
Codecov Report
@@ Coverage Diff @@
## main #806 +/- ##
==========================================
- Coverage 91.04% 91.00% -0.05%
==========================================
Files 48 48
Lines 25480 25483 +3
==========================================
- Hits 23199 23190 -9
- Misses 2281 2293 +12
Continue to review full report at Codecov.
|
7be8bbf
to
bfaec71
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review ACK bfaec71
Could be cool to display somewhere in the doc what's the expected dir-tree should look like (e.g a tree
cmd-like output)
your_path
└── channel
├── manager
└── monitors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Post-merge ACK.
Code Review ACK bfaec71
Could be cool to display somewhere in the doc what's the expected dir-tree should look like (e.g a
tree
cmd-like output)your_path └── channel ├── manager └── monitors
I think it's actually suppose to be:
your_path
├── manager
└── monitors
└── channel
But currently this is not enforced because FilesystemPersister::persist_manager
can be given any directory by the user. We could enforce this by making it non-pub and have a pub
method return a closure calling it with the appropriate path.
Result<HashMap<OutPoint, ChannelMonitor<Keys::Signer>>, ChannelMonitorUpdateErr> { | ||
if let Err(_) = fs::create_dir_all(&self.path_to_channel_data) { | ||
return Err(ChannelMonitorUpdateErr::PermanentFailure); | ||
} | ||
let mut res = HashMap::new(); | ||
for file_option in fs::read_dir(&self.path_to_channel_data).unwrap() { | ||
let file = file_option.unwrap(); | ||
let owned_file_name = file.file_name(); | ||
let filename = owned_file_name.to_str(); | ||
if !filename.is_some() || !filename.unwrap().is_ascii() || filename.unwrap().len() < 65 { | ||
if let Err(_) = fs::create_dir_all(self.path_to_monitor_data()) { | ||
return Err(ChannelMonitorUpdateErr::PermanentFailure); | ||
} | ||
let mut res = HashMap::new(); | ||
for file_option in fs::read_dir(self.path_to_monitor_data()).unwrap() { | ||
let file = file_option.unwrap(); | ||
let owned_file_name = file.file_name(); | ||
let filename = owned_file_name.to_str(); | ||
if !filename.is_some() || !filename.unwrap().is_ascii() || filename.unwrap().len() < 65 { | ||
return Err(ChannelMonitorUpdateErr::PermanentFailure); | ||
} | ||
|
||
let txid = Txid::from_hex(filename.unwrap().split_at(64).0); | ||
if txid.is_err() { return Err(ChannelMonitorUpdateErr::PermanentFailure); } | ||
let txid = Txid::from_hex(filename.unwrap().split_at(64).0); | ||
if txid.is_err() { return Err(ChannelMonitorUpdateErr::PermanentFailure); } | ||
|
||
let index = filename.unwrap().split_at(65).1.split('.').next().unwrap().parse(); | ||
if index.is_err() { return Err(ChannelMonitorUpdateErr::PermanentFailure); } | ||
let index = filename.unwrap().split_at(65).1.split('.').next().unwrap().parse(); | ||
if index.is_err() { return Err(ChannelMonitorUpdateErr::PermanentFailure); } | ||
|
||
let contents = fs::read(&file.path()); | ||
if contents.is_err() { return Err(ChannelMonitorUpdateErr::PermanentFailure); } | ||
let contents = fs::read(&file.path()); | ||
if contents.is_err() { return Err(ChannelMonitorUpdateErr::PermanentFailure); } | ||
|
||
if let Ok((_, loaded_monitor)) = | ||
<(BlockHash, ChannelMonitor<Keys::Signer>)>::read(&mut Cursor::new(&contents.unwrap()), keys) { | ||
res.insert(OutPoint { txid: txid.unwrap(), index: index.unwrap() }, loaded_monitor); | ||
} else { | ||
return Err(ChannelMonitorUpdateErr::PermanentFailure); | ||
if let Ok((_, loaded_monitor)) = | ||
<(BlockHash, ChannelMonitor<Keys::Signer>)>::read(&mut Cursor::new(&contents.unwrap()), keys) { | ||
res.insert(OutPoint { txid: txid.unwrap(), index: index.unwrap() }, loaded_monitor); | ||
} else { | ||
return Err(ChannelMonitorUpdateErr::PermanentFailure); | ||
} | ||
} | ||
Ok(res) | ||
} | ||
Ok(res) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation looks off by one. I've started following these conventions when wrapping long method signatures:
https://github.com/rust-dev-tools/fmt-rfcs/blob/master/guide/items.md
With an extra line for the opening brace, you can reduce the indent to how it was before.
Slightly nicer to work with for loading monitors from disk.