-
Notifications
You must be signed in to change notification settings - Fork 412
Check the PK of the source of an error before closing chans from it #787
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 |
---|---|---|
|
@@ -916,19 +916,22 @@ 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. 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(); | ||
|
||
fn force_close_channel_with_peer(&self, channel_id: &[u8; 32], peer_node_id: Option<&PublicKey>) -> Result<(), APIError> { | ||
let mut chan = { | ||
let mut channel_state_lock = self.channel_state.lock().unwrap(); | ||
let channel_state = &mut *channel_state_lock; | ||
if let Some(chan) = channel_state.by_id.remove(channel_id) { | ||
if let Some(short_id) = chan.get_short_channel_id() { | ||
if let hash_map::Entry::Occupied(chan) = channel_state.by_id.entry(channel_id.clone()) { | ||
if let Some(node_id) = peer_node_id { | ||
if chan.get().get_counterparty_node_id() != *node_id { | ||
// Error or Ok here doesn't matter - the result is only exposed publicly | ||
// when peer_node_id is None anyway. | ||
return Ok(()); | ||
} | ||
} | ||
if let Some(short_id) = chan.get().get_short_channel_id() { | ||
channel_state.short_to_id.remove(&short_id); | ||
} | ||
chan | ||
chan.remove_entry().1 | ||
} else { | ||
return Err(APIError::ChannelUnavailable{err: "No such channel".to_owned()}); | ||
} | ||
|
@@ -945,6 +948,13 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> | |
Ok(()) | ||
} | ||
|
||
/// Force closes a channel, immediately broadcasting the latest local commitment transaction to | ||
/// 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(); | ||
self.force_close_channel_with_peer(channel_id, None) | ||
} | ||
|
||
/// 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) { | ||
|
@@ -3474,12 +3484,12 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K: | |
for chan in self.list_channels() { | ||
if chan.remote_network_id == *counterparty_node_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); | ||
let _ = self.force_close_channel_with_peer(&chan.channel_id, Some(counterparty_node_id)); | ||
} | ||
} | ||
} else { | ||
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. About the zero-value channel id branch, wouldn't be better to sanitize early that case at 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. Hmm? Not sure exactly what you mean - zero-value channel id means "close all channels with me", its not a specific reference to a channel. |
||
// 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); | ||
let _ = self.force_close_channel_with_peer(&msg.channel_id, Some(counterparty_node_id)); | ||
} | ||
} | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.