Skip to content
Merged
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
37 changes: 29 additions & 8 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9380,6 +9380,10 @@ where
return Err(ChannelError::close("Peer sent a loose channel_reestablish not after reconnect".to_owned()));
}

// A node:
// - if `next_commitment_number` is zero:
// - MUST immediately fail the channel and broadcast any relevant latest commitment
// transaction.
if msg.next_local_commitment_number == 0
|| msg.next_local_commitment_number >= INITIAL_COMMITMENT_NUMBER
|| msg.next_remote_commitment_number >= INITIAL_COMMITMENT_NUMBER
Expand Down Expand Up @@ -9451,9 +9455,10 @@ where
let mut tx_signatures = None;
let mut tx_abort = None;

// if next_funding is set:
// A receiving node:
// - if the `next_funding` TLV is set:
if let Some(next_funding) = &msg.next_funding {
// - if `next_funding` matches the latest interactive funding transaction
// - if `next_funding_txid` matches the latest interactive funding transaction
// or the current channel funding transaction:
if let Some(session) = &self.context.interactive_tx_signing_session {
let our_next_funding_txid = session.unsigned_tx().compute_txid();
Expand All @@ -9468,8 +9473,12 @@ where
self.context.expecting_peer_commitment_signed = true;
}

// TODO(splicing): Add comment for spec requirements
if next_funding.should_retransmit(msgs::NextFundingFlag::CommitmentSigned) {
// - if it has not received `tx_signatures` for that funding transaction:
// - if the `commitment_signed` bit is set in `retransmit_flags`:
if !session.has_received_tx_signatures()
&& next_funding.should_retransmit(msgs::NextFundingFlag::CommitmentSigned)
{
// - MUST retransmit its `commitment_signed` for that funding transaction.
let funding = self
.pending_splice
.as_ref()
Expand Down Expand Up @@ -9605,6 +9614,13 @@ where
let is_awaiting_remote_revoke = self.context.channel_state.is_awaiting_remote_revoke();
let next_counterparty_commitment_number = INITIAL_COMMITMENT_NUMBER - self.context.counterparty_next_commitment_transaction_number + if is_awaiting_remote_revoke { 1 } else { 0 };

// A node:
// - if `next_commitment_number` is 1 in both the `channel_reestablish` it
// sent and received:
// - MUST retransmit `channel_ready`.
Comment on lines +9618 to +9620
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While testing, I noticed there's an overlap between this requirement and my_current_funding_locked when splicing. If we open a fresh channel and immediately splice it, we'll retransmit channel_ready after a reconnect since the commitments have not advanced even though we already locked the splice (either explicitly via splice_locked or implicitly via my_current_funding_locked).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm, probably worth skipping the channel_ready if we have a splice indicator in the reestablish.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably leave this for a follow-up? Relevant discussion in the spec: lightning/bolts#1160 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will land this then, its otherwise trivial.

// - otherwise:
// - MUST NOT retransmit `channel_ready`, but MAY send `channel_ready` with
// a different `short_channel_id` `alias` field.
let channel_ready = if msg.next_local_commitment_number == 1 && INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.next_transaction_number() == 1 {
// We should never have to worry about MonitorUpdateInProgress resending ChannelReady
self.get_channel_ready(logger)
Expand Down Expand Up @@ -11307,26 +11323,31 @@ where
}

fn maybe_get_next_funding(&self) -> Option<msgs::NextFunding> {
// If we've sent `commtiment_signed` for an interactively constructed transaction
// during a signing session, but have not received `tx_signatures` we MUST set `next_funding`
// to the txid of that interactive transaction, else we MUST NOT set it.
// The sending node:
// - if it has sent `commitment_signed` for an interactive transaction construction but
// it has not received `tx_signatures`:
self.context
.interactive_tx_signing_session
.as_ref()
.filter(|session| !session.has_received_tx_signatures())
.map(|signing_session| {
// - MUST include the `next_funding` TLV.
// - MUST set `next_funding_txid` to the txid of that interactive transaction.
let mut next_funding = msgs::NextFunding {
txid: signing_session.unsigned_tx().compute_txid(),
retransmit_flags: 0,
};

// TODO(splicing): Add comment for spec requirements
// - if it has not received `commitment_signed` for this `next_funding_txid`:
// - MUST set the `commitment_signed` bit in `retransmit_flags`.
if !signing_session.has_received_commitment_signed() {
next_funding.retransmit(msgs::NextFundingFlag::CommitmentSigned);
}

next_funding
})
// - otherwise:
// - MUST NOT include the `next_funding` TLV.
}

fn maybe_get_my_current_funding_locked(&self) -> Option<msgs::FundingLocked> {
Expand Down
Loading