Repository navigation
Makes ChannelManager::force_close_channel fail for unknown chan_ids - #777
Conversation
75d9ee0 to
e6e0cf6
Compare
Codecov Report
@@ Coverage Diff @@
## main #777 +/- ##
==========================================
- Coverage 91.24% 91.24% -0.01%
==========================================
Files 37 37
Lines 22866 22847 -19
==========================================
- Hits 20865 20846 -19
Misses 2001 2001
Continue to review full report at Codecov.
|
| pub fn force_close_all_channels(&self) { | ||
| for chan in self.list_channels() { | ||
| self.force_close_channel(&chan.channel_id); | ||
| self.force_close_channel(&chan.channel_id).unwrap(); |
There was a problem hiding this comment.
This is race-y - if we close a channel in another thread while this is running we'll panic needlessly.
| /// 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]) { | ||
| pub fn force_close_channel(&self, channel_id: &[u8; 32]) -> Result<(), APIError>{ |
There was a problem hiding this comment.
It would be nice to update the docs here to state that we only fail in case the channel is not found.
e6e0cf6 to
0e83723
Compare
| } | ||
| } else { | ||
| self.force_close_channel(&msg.channel_id); | ||
| self.force_close_channel(&msg.channel_id).unwrap(); |
There was a problem hiding this comment.
This handles an untrusted message from a peer - if they send us a garbage channel_id we shouldn't crash.
There was a problem hiding this comment.
Ups, didn't realize that came from a peer.
Rebased in 03a72f1
| for chan in self.list_channels() { | ||
| if chan.remote_network_id == *counterparty_node_id { | ||
| self.force_close_channel(&chan.channel_id); | ||
| self.force_close_channel(&chan.channel_id).unwrap(); |
There was a problem hiding this comment.
This is also race-y, I believe.
0e83723 to
03a72f1
Compare
| for chan in self.list_channels() { | ||
| if chan.remote_network_id == *counterparty_node_id { | ||
| self.force_close_channel(&chan.channel_id); | ||
| let _ = self.force_close_channel(&msg.channel_id); |
There was a problem hiding this comment.
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.
ChannelManager::force_close_channel does not fail if a non-existing channel id is being passed, making it hard to catch from an API point of view. Makes force_close_channel return in the same way close_channel does so the user calling the method with an unknown id can be warned.
03a72f1 to
821f6cd
Compare
When we receive an error message from a peer, it can indicate a channel which we should close. However, we previously did not check that the counterparty who sends us such a message is the counterparty with whom we have the channel, allowing any connected peer to make us force-close any channel we have as long as they know the channel id. This commit simply changes the force-close logic to check that the sender matches the channel's counterparty node_id, though as noted in lightningdevkit#105, we eventually need to change the indexing anyway to allow absurdly terrible peers to open channels with us. Found during review of lightningdevkit#777.
When we receive an error message from a peer, it can indicate a channel which we should close. However, we previously did not check that the counterparty who sends us such a message is the counterparty with whom we have the channel, allowing any connected peer to make us force-close any channel we have as long as they know the channel id. This commit simply changes the force-close logic to check that the sender matches the channel's counterparty node_id, though as noted in lightningdevkit#105, we eventually need to change the indexing anyway to allow absurdly terrible peers to open channels with us. Found during review of lightningdevkit#777.
When we receive an error message from a peer, it can indicate a channel which we should close. However, we previously did not check that the counterparty who sends us such a message is the counterparty with whom we have the channel, allowing any connected peer to make us force-close any channel we have as long as they know the channel id. This commit simply changes the force-close logic to check that the sender matches the channel's counterparty node_id, though as noted in lightningdevkit#105, we eventually need to change the indexing anyway to allow absurdly terrible peers to open channels with us. Found during review of lightningdevkit#777.
When we receive an error message from a peer, it can indicate a channel which we should close. However, we previously did not check that the counterparty who sends us such a message is the counterparty with whom we have the channel, allowing any connected peer to make us force-close any channel we have as long as they know the channel id. This commit simply changes the force-close logic to check that the sender matches the channel's counterparty node_id, though as noted in lightningdevkit#105, we eventually need to change the indexing anyway to allow absurdly terrible peers to open channels with us. Found during review of lightningdevkit#777.
When we receive an error message from a peer, it can indicate a channel which we should close. However, we previously did not check that the counterparty who sends us such a message is the counterparty with whom we have the channel, allowing any connected peer to make us force-close any channel we have as long as they know the channel id. This commit simply changes the force-close logic to check that the sender matches the channel's counterparty node_id, though as noted in lightningdevkit#105, we eventually need to change the indexing anyway to allow absurdly terrible peers to open channels with us. Found during review of lightningdevkit#777.
ChannelManager::force_close_channel does not fail if a non-existing channel id is being passed, making it hard to catch from an API point of view.
Makes force_close_channel return in the same way close_channel does so the user calling the method with an unknown id can be warned.
There's a couple of things that may need fixing:
close #773