-
Notifications
You must be signed in to change notification settings - Fork 409
Makes ChannelManager::force_close_channel fail for unknown chan_ids #777
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -917,8 +917,8 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> | |
} | ||
|
||
/// Force closes a channel, immediately broadcasting the latest local commitment transaction to | ||
/// the chain and rejecting new HTLCs on the given channel. | ||
pub fn force_close_channel(&self, channel_id: &[u8; 32]) { | ||
/// the chain and rejecting new HTLCs on the given channel. Fails if channel_id is unknown to the manager. | ||
pub fn force_close_channel(&self, channel_id: &[u8; 32]) -> Result<(), APIError>{ | ||
let _consistency_lock = self.total_consistency_lock.read().unwrap(); | ||
|
||
let mut chan = { | ||
|
@@ -930,7 +930,7 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> | |
} | ||
chan | ||
} else { | ||
return; | ||
return Err(APIError::ChannelUnavailable{err: "No such channel".to_owned()}); | ||
} | ||
}; | ||
log_trace!(self.logger, "Force-closing channel {}", log_bytes!(channel_id[..])); | ||
|
@@ -941,13 +941,15 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> | |
msg: update | ||
}); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Force close all channels, immediately broadcasting the latest local commitment transaction | ||
/// for each to the chain and rejecting new HTLCs on each. | ||
pub fn force_close_all_channels(&self) { | ||
for chan in self.list_channels() { | ||
self.force_close_channel(&chan.channel_id); | ||
let _ = self.force_close_channel(&chan.channel_id); | ||
} | ||
} | ||
|
||
|
@@ -3471,11 +3473,13 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K: | |
if msg.channel_id == [0; 32] { | ||
for chan in self.list_channels() { | ||
if chan.remote_network_id == *counterparty_node_id { | ||
self.force_close_channel(&chan.channel_id); | ||
// Untrusted messages from peer, we throw away the error if id points to a non-existent channel | ||
let _ = self.force_close_channel(&msg.channel_id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a code comment here and below : "Untrusted messages from peer, we throw away the error if id points to a non-existent channel". A good warning to avoid vulns in in case of new work around this code path. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in 821f6cd |
||
} | ||
} | ||
} else { | ||
self.force_close_channel(&msg.channel_id); | ||
// Untrusted messages from peer, we throw away the error if id points to a non-existent channel | ||
let _ = self.force_close_channel(&msg.channel_id); | ||
} | ||
} | ||
} | ||
|
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.
It would be nice to update the docs here to state that we only fail in case the channel is not found.
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.
Rebased in 0e83723