Skip to content

Commit 805edc2

Browse files
authored
Merge pull request #4098 from jkczyz/2025-09-next-funding-spec
Update `next_funding` spec requirements
2 parents 9514637 + e083a2d commit 805edc2

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

lightning/src/ln/channel.rs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9366,6 +9366,10 @@ where
93669366
return Err(ChannelError::close("Peer sent a loose channel_reestablish not after reconnect".to_owned()));
93679367
}
93689368

9369+
// A node:
9370+
// - if `next_commitment_number` is zero:
9371+
// - MUST immediately fail the channel and broadcast any relevant latest commitment
9372+
// transaction.
93699373
if msg.next_local_commitment_number == 0
93709374
|| msg.next_local_commitment_number >= INITIAL_COMMITMENT_NUMBER
93719375
|| msg.next_remote_commitment_number >= INITIAL_COMMITMENT_NUMBER
@@ -9437,9 +9441,10 @@ where
94379441
let mut tx_signatures = None;
94389442
let mut tx_abort = None;
94399443

9440-
// if next_funding is set:
9444+
// A receiving node:
9445+
// - if the `next_funding` TLV is set:
94419446
if let Some(next_funding) = &msg.next_funding {
9442-
// - if `next_funding` matches the latest interactive funding transaction
9447+
// - if `next_funding_txid` matches the latest interactive funding transaction
94439448
// or the current channel funding transaction:
94449449
if let Some(session) = &self.context.interactive_tx_signing_session {
94459450
let our_next_funding_txid = session.unsigned_tx().compute_txid();
@@ -9454,8 +9459,12 @@ where
94549459
self.context.expecting_peer_commitment_signed = true;
94559460
}
94569461

9457-
// TODO(splicing): Add comment for spec requirements
9458-
if next_funding.should_retransmit(msgs::NextFundingFlag::CommitmentSigned) {
9462+
// - if it has not received `tx_signatures` for that funding transaction:
9463+
// - if the `commitment_signed` bit is set in `retransmit_flags`:
9464+
if !session.has_received_tx_signatures()
9465+
&& next_funding.should_retransmit(msgs::NextFundingFlag::CommitmentSigned)
9466+
{
9467+
// - MUST retransmit its `commitment_signed` for that funding transaction.
94599468
let funding = self
94609469
.pending_splice
94619470
.as_ref()
@@ -9591,6 +9600,13 @@ where
95919600
let is_awaiting_remote_revoke = self.context.channel_state.is_awaiting_remote_revoke();
95929601
let next_counterparty_commitment_number = INITIAL_COMMITMENT_NUMBER - self.context.counterparty_next_commitment_transaction_number + if is_awaiting_remote_revoke { 1 } else { 0 };
95939602

9603+
// A node:
9604+
// - if `next_commitment_number` is 1 in both the `channel_reestablish` it
9605+
// sent and received:
9606+
// - MUST retransmit `channel_ready`.
9607+
// - otherwise:
9608+
// - MUST NOT retransmit `channel_ready`, but MAY send `channel_ready` with
9609+
// a different `short_channel_id` `alias` field.
95949610
let channel_ready = if msg.next_local_commitment_number == 1 && INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.next_transaction_number() == 1 {
95959611
// We should never have to worry about MonitorUpdateInProgress resending ChannelReady
95969612
self.get_channel_ready(logger)
@@ -11293,26 +11309,31 @@ where
1129311309
}
1129411310

1129511311
fn maybe_get_next_funding(&self) -> Option<msgs::NextFunding> {
11296-
// If we've sent `commtiment_signed` for an interactively constructed transaction
11297-
// during a signing session, but have not received `tx_signatures` we MUST set `next_funding`
11298-
// to the txid of that interactive transaction, else we MUST NOT set it.
11312+
// The sending node:
11313+
// - if it has sent `commitment_signed` for an interactive transaction construction but
11314+
// it has not received `tx_signatures`:
1129911315
self.context
1130011316
.interactive_tx_signing_session
1130111317
.as_ref()
1130211318
.filter(|session| !session.has_received_tx_signatures())
1130311319
.map(|signing_session| {
11320+
// - MUST include the `next_funding` TLV.
11321+
// - MUST set `next_funding_txid` to the txid of that interactive transaction.
1130411322
let mut next_funding = msgs::NextFunding {
1130511323
txid: signing_session.unsigned_tx().compute_txid(),
1130611324
retransmit_flags: 0,
1130711325
};
1130811326

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

1131411333
next_funding
1131511334
})
11335+
// - otherwise:
11336+
// - MUST NOT include the `next_funding` TLV.
1131611337
}
1131711338

1131811339
fn maybe_get_my_current_funding_locked(&self) -> Option<msgs::FundingLocked> {

0 commit comments

Comments
 (0)