Skip to content

Commit 080c90b

Browse files
committed
Update get_open_channel flow.
- If our channel_state has moved forward, we check if it is at the negotiation stage, and that we have access to previously received accept_channel_msg. We panic only when both conditions fail.
1 parent dd83080 commit 080c90b

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

lightning/src/ln/channel.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,18 @@ impl OutboundContext {
12621262
created_funding_transaction: None,
12631263
}
12641264
}
1265+
1266+
/// Determines whether an `AcceptChannel` message has been received during a previous
1267+
/// channel handshake.
1268+
pub fn received_accept_channel(&self) -> bool {
1269+
self.received_accept_channel_msg.is_some()
1270+
}
1271+
1272+
/// Determines whether a Funding Transaction had been created during a previous
1273+
/// channel handshake.
1274+
pub fn created_funding_transaction(&self) -> bool {
1275+
self.created_funding_transaction.is_some()
1276+
}
12651277
}
12661278

12671279
struct FundingTransaction {
@@ -7465,8 +7477,8 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
74657477
if !self.context.is_outbound() {
74667478
panic!("Tried to open a channel for an inbound channel?");
74677479
}
7468-
if self.context.have_received_message() {
7469-
panic!("Cannot generate an open_channel after we've moved forward");
7480+
if self.context.have_received_message() && !self.deja_vu() {
7481+
panic!("Cannot generate an open_channel after we've moved forward earlier, but doesn't know the previous accept_channel_msg");
74707482
}
74717483

74727484
if self.context.cur_holder_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER {
@@ -7738,6 +7750,19 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
77387750
Ok((channel, channel_monitor))
77397751
}
77407752

7753+
/// Determines if the outbound channel handshake process is being retried.
7754+
fn deja_vu(&self) -> bool {
7755+
let negotiating = !matches!(self.context.channel_state, ChannelState::NegotiatingFunding(flags) if flags == NegotiatingFundingFlags::OUR_INIT_SENT);
7756+
let negotiated = self.context.channel_state == ChannelState::FundingNegotiated;
7757+
7758+
if (negotiated && self.outbound_context.created_funding_transaction()) ||
7759+
(negotiating && self.outbound_context.received_accept_channel()) {
7760+
true
7761+
} else {
7762+
false
7763+
}
7764+
}
7765+
77417766
/// Indicates that the signer may have some signatures for us, so we should retry if we're
77427767
/// blocked.
77437768
#[cfg(async_signing)]

0 commit comments

Comments
 (0)