Skip to content

Commit 4fb0352

Browse files
committed
Update accept_channel flow.
1. If we had an acceptchannel earlier, we check if it matches the one received just now. If not we error, because the channel parameters have changed and that warrants renegotiating parameters again. 2. If they do match we simply skip the rest of the function because we had updated those values already.
1 parent 080c90b commit 4fb0352

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lightning/src/ln/channel.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7525,9 +7525,16 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
75257525
if !self.context.is_outbound() {
75267526
return Err(ChannelError::Close("Got an accept_channel message from an inbound peer".to_owned()));
75277527
}
7528-
if !matches!(self.context.channel_state, ChannelState::NegotiatingFunding(flags) if flags == NegotiatingFundingFlags::OUR_INIT_SENT) {
7528+
if !matches!(self.context.channel_state, ChannelState::NegotiatingFunding(flags) if flags == NegotiatingFundingFlags::OUR_INIT_SENT) && !self.deja_vu() {
75297529
return Err(ChannelError::Close("Got an accept_channel message at a strange time".to_owned()));
75307530
}
7531+
if self.outbound_context.received_accept_channel() {
7532+
if self.outbound_context.received_accept_channel_msg.as_ref().unwrap() == msg {
7533+
return Ok(());
7534+
} else {
7535+
return Err(ChannelError::Close("The new accep_channel_msg doesn't match the old one. Should renegotiating channel parameters".to_owned()));
7536+
}
7537+
}
75317538
if msg.common_fields.dust_limit_satoshis > 21000000 * 100000000 {
75327539
return Err(ChannelError::Close(format!("Peer never wants payout outputs? dust_limit_satoshis was {}", msg.common_fields.dust_limit_satoshis)));
75337540
}
@@ -7614,6 +7621,10 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
76147621
}
76157622
} else { None };
76167623

7624+
7625+
// Save the accept channel msg after all the sanity checks to the outbound_context parameters.
7626+
self.outbound_context.received_accept_channel_msg = Some(msg.clone());
7627+
76177628
self.context.counterparty_dust_limit_satoshis = msg.common_fields.dust_limit_satoshis;
76187629
self.context.counterparty_max_htlc_value_in_flight_msat = cmp::min(msg.common_fields.max_htlc_value_in_flight_msat, self.context.channel_value_satoshis * 1000);
76197630
self.context.counterparty_selected_channel_reserve_satoshis = Some(msg.channel_reserve_satoshis);

0 commit comments

Comments
 (0)