Skip to content
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

bolt2: give the possibility to the sender to be outdated #1428

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ pub(super) struct ReestablishResponses {
pub holding_cell_failed_htlcs: Vec<(HTLCSource, PaymentHash)>,
pub announcement_sigs: Option<msgs::AnnouncementSignatures>,
pub shutdown_msg: Option<msgs::Shutdown>,
pub channel_reestablish_msg: Option<msgs::ChannelReestablish>,
}

/// If the majority of the channels funds are to the fundee and the initiator holds only just
Expand Down Expand Up @@ -3743,6 +3744,7 @@ impl<Signer: Sign> Channel<Signer> {
order: RAACommitmentOrder::CommitmentFirst,
holding_cell_failed_htlcs: Vec::new(),
shutdown_msg, announcement_sigs,
channel_reestablish_msg: None,
});
}

Expand All @@ -3758,6 +3760,7 @@ impl<Signer: Sign> Channel<Signer> {
order: RAACommitmentOrder::CommitmentFirst,
holding_cell_failed_htlcs: Vec::new(),
shutdown_msg, announcement_sigs,
channel_reestablish_msg: None,
});
}

Expand Down Expand Up @@ -3816,6 +3819,7 @@ impl<Signer: Sign> Channel<Signer> {
order: self.resend_order.clone(),
mon_update: Some(monitor_update),
holding_cell_failed_htlcs,
channel_reestablish_msg: None,
})
},
Ok((None, holding_cell_failed_htlcs)) => {
Expand All @@ -3826,6 +3830,7 @@ impl<Signer: Sign> Channel<Signer> {
order: self.resend_order.clone(),
mon_update: None,
holding_cell_failed_htlcs,
channel_reestablish_msg: None,
})
},
}
Expand All @@ -3837,6 +3842,7 @@ impl<Signer: Sign> Channel<Signer> {
order: self.resend_order.clone(),
mon_update: None,
holding_cell_failed_htlcs: Vec::new(),
channel_reestablish_msg: None,
})
}
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
Expand All @@ -3853,6 +3859,7 @@ impl<Signer: Sign> Channel<Signer> {
commitment_update: None, raa: None, mon_update: None,
order: self.resend_order.clone(),
holding_cell_failed_htlcs: Vec::new(),
channel_reestablish_msg: None,
})
} else {
Ok(ReestablishResponses {
Expand All @@ -3862,10 +3869,31 @@ impl<Signer: Sign> Channel<Signer> {
order: self.resend_order.clone(),
mon_update: None,
holding_cell_failed_htlcs: Vec::new(),
channel_reestablish_msg: None,
})
}
} else {
Err(ChannelError::Close("Peer attempted to reestablish channel with a very old remote commitment transaction".to_owned()))
// BOLT 2 allow the sender to be outdate, and to avoid
// to close channel due the very old remote commitment
// a channel_reestablish message form us is sent, to
// give the possibility to try to resolver from some problem.
let channel_state_updated = msgs::ChannelReestablish{
channel_id: self.channel_id,
next_local_commitment_number: self.cur_holder_commitment_transaction_number,
next_remote_commitment_number: self.cur_holder_commitment_transaction_number,
data_loss_protect: OptionalField::Absent,
};
Ok(ReestablishResponses{
funding_locked,
raa: None,
commitment_update: None,
order: self.resend_order.clone(),
mon_update: None,
holding_cell_failed_htlcs: Vec::new(),
announcement_sigs,
shutdown_msg,
channel_reestablish_msg: Some(channel_state_updated)
})
}
}

Expand Down
11 changes: 11 additions & 0 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4761,6 +4761,17 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
msg,
});
} else if chan.get().is_usable() {
// the channel should be in a usable condition, but the counterparty
// is stuck in the past, so we send the updated data with a
// `channel_reestablish` msg.
if let Some(reestablish_msg) = responses.channel_reestablish_msg {
channel_state.pending_msg_events.push(events::MessageSendEvent::SendChannelReestablish {
node_id: counterparty_node_id.clone(),
msg: reestablish_msg,
});
return Ok(());
}

// If the channel is in a usable state (ie the channel is not being shut
// down), send a unicast channel_update to our counterparty to make sure
// they have the latest channel parameters.
Expand Down