Skip to content

Commit 730d563

Browse files
authored
Merge pull request #1080 from valentinewallace/2021-09-dup-chan-outpoint
Fix fuzzer-found panic from duplicate channel outpoint
2 parents 2352587 + 612d1fb commit 730d563

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lightning/src/chain/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ pub trait Watch<ChannelSigner: Sign> {
203203
/// with any spends of outputs returned by [`get_outputs_to_watch`]. In practice, this means
204204
/// calling [`block_connected`] and [`block_disconnected`] on the monitor.
205205
///
206+
/// Note: this interface MUST error with `ChannelMonitorUpdateErr::PermanentFailure` if
207+
/// the given `funding_txo` has previously been registered via `watch_channel`.
208+
///
206209
/// [`get_outputs_to_watch`]: channelmonitor::ChannelMonitor::get_outputs_to_watch
207210
/// [`block_connected`]: channelmonitor::ChannelMonitor::block_connected
208211
/// [`block_disconnected`]: channelmonitor::ChannelMonitor::block_disconnected

lightning/src/ln/channelmanager.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -3431,7 +3431,16 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
34313431
Err(e) => try_chan_entry!(self, Err(e), channel_state, chan),
34323432
};
34333433
if let Err(e) = self.chain_monitor.watch_channel(chan.get().get_funding_txo().unwrap(), monitor) {
3434-
return_monitor_err!(self, e, channel_state, chan, RAACommitmentOrder::RevokeAndACKFirst, false, false);
3434+
let mut res = handle_monitor_err!(self, e, channel_state, chan, RAACommitmentOrder::RevokeAndACKFirst, false, false);
3435+
if let Err(MsgHandleErrInternal { ref mut shutdown_finish, .. }) = res {
3436+
// We weren't able to watch the channel to begin with, so no updates should be made on
3437+
// it. Previously, full_stack_target found an (unreachable) panic when the
3438+
// monitor update contained within `shutdown_finish` was applied.
3439+
if let Some((ref mut shutdown_finish, _)) = shutdown_finish {
3440+
shutdown_finish.0.take();
3441+
}
3442+
}
3443+
return res
34353444
}
34363445
funding_tx
34373446
},

0 commit comments

Comments
 (0)