Skip to content

Commit bde48b2

Browse files
authored
Merge pull request #165 from TheBlueMatt/2018-09-pre-disconnect-misc
Further minor misc changes from reconnect work
2 parents f71ff8f + a2d4889 commit bde48b2

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

fuzz/fuzz_targets/full_stack_target.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,13 @@ pub fn do_test(data: &[u8], logger: &Arc<Logger>) {
403403
13 => {
404404
loss_detector.disconnect_block();
405405
},
406+
14 => {
407+
let mut channels = channelmanager.list_channels();
408+
let channel_id = get_slice!(1)[0] as usize;
409+
if channel_id >= channels.len() { return; }
410+
channels.sort_by(|a, b| { a.channel_id.cmp(&b.channel_id) });
411+
channelmanager.force_close_channel(&channels[channel_id].channel_id);
412+
},
406413
_ => return,
407414
}
408415
loss_detector.handler.process_events();

src/ln/channel.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ impl Channel {
10941094

10951095
pub fn get_update_fail_htlc(&mut self, payment_hash_arg: &[u8; 32], err_packet: msgs::OnionErrorPacket) -> Result<Option<msgs::UpdateFailHTLC>, HandleError> {
10961096
if (self.channel_state & (ChannelState::ChannelFunded as u32)) != (ChannelState::ChannelFunded as u32) {
1097-
return Err(HandleError{err: "Was asked to fail an HTLC when channel was not in an operational state", action: None});
1097+
panic!("Was asked to fail an HTLC when channel was not in an operational state");
10981098
}
10991099
assert_eq!(self.channel_state & ChannelState::ShutdownComplete as u32, 0);
11001100

@@ -2390,12 +2390,13 @@ impl Channel {
23902390
/// Creates a signed commitment transaction to send to the remote peer.
23912391
/// Always returns a Channel-failing HandleError::action if an immediately-preceding (read: the
23922392
/// last call to this Channel) send_htlc returned Ok(Some(_)) and there is an Err.
2393+
/// May panic if called except immediately after a successful, Ok(Some(_))-returning send_htlc.
23932394
pub fn send_commitment(&mut self) -> Result<(msgs::CommitmentSigned, ChannelMonitor), HandleError> {
23942395
if (self.channel_state & (ChannelState::ChannelFunded as u32)) != (ChannelState::ChannelFunded as u32) {
2395-
return Err(HandleError{err: "Cannot create commitment tx until channel is fully established", action: None});
2396+
panic!("Cannot create commitment tx until channel is fully established");
23962397
}
23972398
if (self.channel_state & (ChannelState::AwaitingRemoteRevoke as u32)) == (ChannelState::AwaitingRemoteRevoke as u32) {
2398-
return Err(HandleError{err: "Cannot create commitment tx until remote revokes their previous commitment", action: None});
2399+
panic!("Cannot create commitment tx until remote revokes their previous commitment");
23992400
}
24002401
let mut have_updates = false; // TODO initialize with "have we sent a fee update?"
24012402
for htlc in self.pending_htlcs.iter() {
@@ -2405,7 +2406,7 @@ impl Channel {
24052406
if have_updates { break; }
24062407
}
24072408
if !have_updates {
2408-
return Err(HandleError{err: "Cannot create commitment tx until we have some updates to send", action: None});
2409+
panic!("Cannot create commitment tx until we have some updates to send");
24092410
}
24102411
self.send_commitment_no_status_check()
24112412
}

src/ln/channelmanager.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,9 @@ impl ChannelManager {
985985
if chan.get_their_node_id() != route.hops.first().unwrap().pubkey {
986986
return Err(HandleError{err: "Node ID mismatch on first hop!", action: None});
987987
}
988+
if !chan.is_live() {
989+
return Err(HandleError{err: "Peer for first hop currently disconnected!", action: None});
990+
}
988991
chan.send_htlc_and_commit(htlc_msat, payment_hash, htlc_cltv, onion_packet)?
989992
};
990993

0 commit comments

Comments
 (0)