@@ -489,6 +489,32 @@ static void check_mutual_splice_locked(struct peer *peer)
489489 peer -> splice_state -> remote_locked_txid = tal_free (peer -> splice_state -> remote_locked_txid );
490490}
491491
492+ static void implied_peer_splice_locked (struct peer * peer ,
493+ struct bitcoin_txid splice_txid )
494+ {
495+ /* If we've `mutual_splice_locked` but our peer hasn't, we can ignore
496+ * this message harmlessly */
497+ if (!tal_count (peer -> splice_state -> inflights )) {
498+ status_info ("Peer implied redundant splice_locked, ignoring" );
499+ return ;
500+ }
501+
502+ /* If we've `mutual_splice_locked` but our peer hasn't, we can ignore
503+ * this message harmlessly */
504+ if (!tal_count (peer -> splice_state -> inflights )) {
505+ status_info ("Peer implied redundant splice_locked, ignoring" );
506+ return ;
507+ }
508+
509+ peer -> splice_state -> remote_locked_txid = tal (peer -> splice_state ,
510+ struct bitcoin_txid );
511+
512+ * peer -> splice_state -> remote_locked_txid = splice_txid ;
513+
514+ peer -> splice_state -> locked_ready [REMOTE ] = true;
515+ check_mutual_splice_locked (peer );
516+ }
517+
492518/* Our peer told us they saw our splice confirm on chain with `splice_locked`.
493519 * If we see it to we jump into transitioning to post-splice, otherwise we mark
494520 * a flag and wait until we see it on chain too. */
@@ -506,11 +532,6 @@ static void handle_peer_splice_locked(struct peer *peer, const u8 *msg)
506532 "Peer sent duplicate splice_locked message %s" ,
507533 tal_hex (tmpctx , msg ));
508534
509- peer -> splice_state -> remote_locked_txid = tal (peer -> splice_state ,
510- struct bitcoin_txid );
511-
512- * peer -> splice_state -> remote_locked_txid = splice_txid ;
513-
514535 if (!channel_id_eq (& chanid , & peer -> channel_id ))
515536 peer_failed_err (peer -> pps , & chanid ,
516537 "Wrong splice lock channel id in %s "
@@ -525,8 +546,7 @@ static void handle_peer_splice_locked(struct peer *peer, const u8 *msg)
525546 return ;
526547 }
527548
528- peer -> splice_state -> locked_ready [REMOTE ] = true;
529- check_mutual_splice_locked (peer );
549+ implied_peer_splice_locked (peer , splice_txid );
530550}
531551
532552static void handle_peer_channel_ready (struct peer * peer , const u8 * msg )
@@ -5485,8 +5505,8 @@ static void peer_reconnect(struct peer *peer,
54855505 bool dataloss_protect , check_extra_fields ;
54865506 const u8 * * premature_msgs = tal_arr (peer , const u8 * , 0 );
54875507 struct inflight * inflight ;
5488- struct bitcoin_txid * local_next_funding , * remote_next_funding ,
5489- * remote_your_last_funding ;
5508+ struct tlv_channel_reestablish_tlvs_next_funding * local_next_funding ,
5509+ * remote_next_funding ;
54905510 u64 send_next_commitment_number ;
54915511
54925512 struct tlv_channel_reestablish_tlvs * send_tlvs , * recv_tlvs ;
@@ -5529,17 +5549,27 @@ static void peer_reconnect(struct peer *peer,
55295549 * tal off peer */
55305550 send_tlvs = tlv_channel_reestablish_tlvs_new (peer );
55315551 }
5532- send_tlvs -> next_funding = & inflight -> outpoint .txid ;
5533-
5534- /* Eclair wants us to decrement commitment number to
5535- * indicate that we would like them to re-send
5536- * commitment signatures */
5537- /* DTODO: Add bolt reference */
5538- if (!inflight -> last_tx )
5552+ send_tlvs -> next_funding = talz (send_tlvs , struct tlv_channel_reestablish_tlvs_next_funding );
5553+ send_tlvs -> next_funding -> next_funding_txid = inflight -> outpoint .txid ;
5554+
5555+ /* BOLT-??? #2:
5556+ * The `next_funding.retransmit_flags` bitfield is used to let the
5557+ * receiving peer know which messages they must retransmit for the
5558+ * corresponding `next_funding_txid` after the reconnection:
5559+ * | Bit Position | Name |
5560+ * | ------------- | --------------------|
5561+ * | 0 | `commitment_signed` |
5562+ */
5563+ if (!inflight -> last_tx ) {
55395564 send_next_commitment_number -- ;
5565+ send_tlvs -> next_funding -> retransmit_flags |= 1 ; /* commitment_signed */
5566+ }
55405567 }
55415568 }
55425569
5570+ /* BOLT-??? #2:
5571+ * - if `option_splice` was negotiated:
5572+ */
55435573 if (feature_negotiated (peer -> our_features , peer -> their_features ,
55445574 OPT_SPLICE )) {
55455575 if (!send_tlvs ) {
@@ -5548,46 +5578,90 @@ static void peer_reconnect(struct peer *peer,
55485578 send_tlvs = tlv_channel_reestablish_tlvs_new (peer );
55495579 }
55505580
5551- if (peer -> channel_ready [REMOTE ])
5552- send_tlvs -> your_last_funding_locked_txid = & peer -> channel -> funding .txid ;
5553-
5554- send_tlvs -> my_current_funding_locked_txid = & peer -> channel -> funding .txid ;
5555- status_debug ("Setting send_tlvs->my_current_funding_locked_txid"
5556- " to %s" ,
5557- fmt_bitcoin_txid (tmpctx ,
5558- & peer -> channel -> funding .txid ));
5559-
55605581 for (size_t i = 0 ; i < tal_count (peer -> splice_state -> inflights ); i ++ ) {
55615582 struct inflight * itr = peer -> splice_state -> inflights [i ];
55625583 if (itr -> locked_scid ) {
5563- send_tlvs -> my_current_funding_locked_txid = & itr -> outpoint .txid ;
5564- status_debug ("Overriding send_tlvs->my_current_"
5565- "funding_locked_txid to %s because"
5566- " inflight is locked to scid %s" ,
5567- fmt_bitcoin_txid (tmpctx ,
5568- & itr -> outpoint .txid ),
5569- fmt_short_channel_id (tmpctx ,
5570- * itr -> locked_scid ));
5584+ peer -> splice_state -> short_channel_id = * itr -> locked_scid ;
5585+ peer -> splice_state -> locked_txid = itr -> outpoint .txid ;
5586+ peer -> splice_state -> locked_ready [LOCAL ] = true;
55715587 }
55725588 }
5589+
5590+ /* BOLT-??? #2:
5591+ * - if a splice transaction reached acceptable depth while disconnected:
5592+ * - MUST include `my_current_funding_locked` with the txid of the latest such transaction.
5593+ * - otherwise, if it has already sent `splice_locked` for any transaction:
5594+ * - MUST include `my_current_funding_locked` with the txid of the last `splice_locked` it sent.
5595+ */
5596+ if (peer -> splice_state -> locked_ready [LOCAL ]) {
5597+
5598+ send_tlvs -> my_current_funding_locked = talz (send_tlvs , struct tlv_channel_reestablish_tlvs_my_current_funding_locked );
5599+ send_tlvs -> my_current_funding_locked -> my_current_funding_locked_txid = peer -> splice_state -> locked_txid ;
5600+ status_debug ("Setting send_tlvs->my_current_funding"
5601+ "_locked_txid to splice txid %s" ,
5602+ fmt_bitcoin_txid (tmpctx ,
5603+ & peer -> splice_state -> locked_txid ));
5604+ }
5605+ /* BOLT-??? #2:
5606+ * - otherwise, if it has already sent `channel_ready`:
5607+ * - MUST include `my_current_funding_locked` with the txid of the channel funding transaction.
5608+ */
5609+ else if (peer -> channel_ready [LOCAL ]) {
5610+
5611+ send_tlvs -> my_current_funding_locked = talz (send_tlvs , struct tlv_channel_reestablish_tlvs_my_current_funding_locked );
5612+ send_tlvs -> my_current_funding_locked -> my_current_funding_locked_txid = peer -> channel -> funding .txid ;
5613+ status_debug ("Setting send_tlvs->my_current_funding"
5614+ "_locked_txid to channel txid %s" ,
5615+ fmt_bitcoin_txid (tmpctx ,
5616+ & peer -> channel -> funding .txid ));
5617+ }
5618+ /* BOLT-??? #2:
5619+ * - otherwise (it has never sent `channel_ready` or `splice_locked`):
5620+ * - MUST NOT include `my_current_funding_locked`.
5621+ */
5622+ else {
5623+ status_debug ("Not setting send_tlvs->my_current_funding"
5624+ "_locked_txid (funding txid %s)" ,
5625+ fmt_bitcoin_txid (tmpctx ,
5626+ & peer -> channel -> funding .txid ));
5627+ assert (!send_tlvs -> my_current_funding_locked );
5628+ }
5629+
5630+ /* BOLT-??? #2:
5631+ * - if `my_current_funding_locked` is included:
5632+ * - if `announce_channel` is set for this channel:
5633+ * - if it has not received `announcement_signatures` for that transaction:
5634+ * - MUST set the `announcement_signatures` bit to `1` in `retransmit_flags`.
5635+ * - otherwise:
5636+ * - MUST set the `announcement_signatures` bit to `0` in `retransmit_flags`.
5637+ */
5638+ // if (send_tlvs->my_current_funding_locked) {
5639+ /* BOLT-??? #2:
5640+ * The `retransmit_flags` bitfield is used to let our peer know which messages
5641+ * we expect them to retransmit after the reconnection:
5642+ *
5643+ * | Bit Position | Name |
5644+ * | ------------- | --------------------------|
5645+ * | 0 | `announcement_signatures` |
5646+ */
5647+ // if (annnounce_channel && not_received_announcement_sigs)
5648+ // send_tlvs->my_current_funding_locked->retransmit_flags |= 1; /* announcement_signatures */
5649+ /* Otherwise bit defaults to 0 because
5650+ * my_current_funding_locked was allocated with talz */
5651+ // }
55735652 }
55745653
55755654 status_debug ("Sending channel_reestablish with"
55765655 " next_funding_tx_id: %s,"
5577- " your_last_funding_locked: %s,"
55785656 " my_current_funding_locked: %s,"
55795657 " next_local_commit_number: %" PRIu64 "," ,
55805658 send_tlvs && send_tlvs -> next_funding
55815659 ? fmt_bitcoin_txid (tmpctx ,
5582- send_tlvs -> next_funding )
5660+ & send_tlvs -> next_funding -> next_funding_txid )
55835661 : "NULL" ,
5584- send_tlvs && send_tlvs -> your_last_funding_locked_txid
5662+ send_tlvs && send_tlvs -> my_current_funding_locked
55855663 ? fmt_bitcoin_txid (tmpctx ,
5586- send_tlvs -> your_last_funding_locked_txid )
5587- : "NULL" ,
5588- send_tlvs && send_tlvs -> my_current_funding_locked_txid
5589- ? fmt_bitcoin_txid (tmpctx ,
5590- send_tlvs -> my_current_funding_locked_txid )
5664+ & send_tlvs -> my_current_funding_locked -> my_current_funding_locked_txid )
55915665 : "NULL" ,
55925666 send_next_commitment_number );
55935667
@@ -5703,7 +5777,7 @@ static void peer_reconnect(struct peer *peer,
57035777 !inflight -> last_tx ,
57045778 false,
57055779 true);
5706- } else if (bitcoin_txid_eq (remote_next_funding ,
5780+ } else if (bitcoin_txid_eq (& remote_next_funding -> next_funding_txid ,
57075781 & inflight -> outpoint .txid )) {
57085782 /* Don't send sigs unless we have theirs */
57095783 assert (local_next_funding || inflight -> remote_tx_sigs );
@@ -5713,11 +5787,11 @@ static void peer_reconnect(struct peer *peer,
57135787 if (local_next_funding )
57145788 assume_stfu_mode (peer );
57155789 resume_splice_negotiation (peer ,
5716- next_commitment_number == peer -> next_index [ REMOTE ] - 1 ,
5790+ remote_next_funding ? remote_next_funding -> retransmit_flags & 1 : false ,
57175791 local_next_funding && !inflight -> last_tx ,
57185792 true,
57195793 local_next_funding );
5720- } else if (bitcoin_txid_eq (remote_next_funding ,
5794+ } else if (bitcoin_txid_eq (& remote_next_funding -> next_funding_txid ,
57215795 & peer -> channel -> funding .txid )) {
57225796 peer_failed_err (peer -> pps ,
57235797 & peer -> channel_id ,
@@ -5726,7 +5800,7 @@ static void peer_reconnect(struct peer *peer,
57265800 " active funding txid %s. Should be %s"
57275801 " or NULL" ,
57285802 fmt_bitcoin_txid (tmpctx ,
5729- remote_next_funding ),
5803+ & remote_next_funding -> next_funding_txid ),
57305804 fmt_bitcoin_txid (tmpctx ,
57315805 & peer -> channel -> funding .txid ),
57325806 fmt_bitcoin_txid (tmpctx ,
@@ -5737,71 +5811,21 @@ static void peer_reconnect(struct peer *peer,
57375811 "Invalid reestablish with unrecognized"
57385812 " next_funding txid %s, should be %s" ,
57395813 fmt_bitcoin_txid (tmpctx ,
5740- remote_next_funding ),
5814+ & remote_next_funding -> next_funding_txid ),
57415815 fmt_bitcoin_txid (tmpctx ,
57425816 & inflight -> outpoint .txid ));
57435817 }
57445818 } else if (remote_next_funding ) { /* No current inflight */
57455819 /* If our peer is trying to negotiate details about a splice
57465820 * that is already onchain, jump ahead to sending splice_lock */
5747- if (bitcoin_txid_eq (remote_next_funding ,
5748- & peer -> channel -> funding .txid )) {
5821+ if (bitcoin_txid_eq (& remote_next_funding -> next_funding_txid ,
5822+ & peer -> channel -> funding .txid ))
57495823 status_info ("We have no pending splice but peer"
5750- " is negotiating one; resending "
5751- " splice_lock %s" ,
5824+ " is negotiating one that matches current "
5825+ " channel, ignoring it: %s" ,
57525826 fmt_bitcoin_outpoint (tmpctx , & peer -> channel -> funding ));
5753- peer_write (peer -> pps ,
5754- take (towire_splice_locked (NULL ,
5755- & peer -> channel_id ,
5756- & peer -> channel -> funding .txid )));
5757- }
5758- else {
5759- splice_abort (peer , "next_funding_txid not recognized."
5760- " Sending tx_abort." );
5761- }
5762- }
5763-
5764- /* Re-send `splice_locked` if an inflight is locked */
5765- for (size_t i = 0 ; i < tal_count (peer -> splice_state -> inflights ); i ++ ) {
5766- struct inflight * itr = peer -> splice_state -> inflights [i ];
5767- if (!itr -> locked_scid )
5768- continue ;
5769-
5770- status_info ("Resending splice_locked because an inflight %s is"
5771- " locked" ,
5772- fmt_bitcoin_outpoint (tmpctx , & itr -> outpoint ));
5773- peer_write (peer -> pps ,
5774- take (towire_splice_locked (NULL ,
5775- & peer -> channel_id ,
5776- & itr -> outpoint .txid )));
5777- peer -> splice_state -> locked_ready [LOCAL ] = true;
5778- }
5779-
5780- /* If no inflight, no splice negotiation, but
5781- `your_last_funding_locked_txid is stale, re-send `splice_locked`. */
5782- if (!inflight && !remote_next_funding
5783- && feature_negotiated (peer -> our_features , peer -> their_features ,
5784- OPT_SPLICE )) {
5785- remote_your_last_funding = recv_tlvs
5786- ? recv_tlvs -> your_last_funding_locked_txid : NULL ;
5787- if (remote_your_last_funding
5788- && !bitcoin_txid_eq (& peer -> channel -> funding .txid ,
5789- remote_your_last_funding )) {
5790- status_info ("Resending splice_locked with no inflight,"
5791- " no splice negotation, but we did recv"
5792- " remote_your_last_funding value of %s"
5793- " instead of %s. Our sent splice_locked"
5794- " value is %s." ,
5795- remote_your_last_funding
5796- ? fmt_bitcoin_txid (tmpctx , remote_your_last_funding )
5797- : "NULL" ,
5798- fmt_bitcoin_outpoint (tmpctx , & peer -> channel -> funding ),
5799- fmt_bitcoin_txid (tmpctx , & peer -> channel -> funding .txid ));
5800- peer_write (peer -> pps ,
5801- take (towire_splice_locked (NULL ,
5802- & peer -> channel_id ,
5803- & peer -> channel -> funding .txid )));
5804- }
5827+ else
5828+ splice_abort (peer , "next_funding_txid not recognized." );
58055829 }
58065830
58075831 /* BOLT #2:
@@ -5829,6 +5853,25 @@ static void peer_reconnect(struct peer *peer,
58295853 peer_write (peer -> pps , take (msg ));
58305854 }
58315855
5856+ /* BOLT-??? #2
5857+ * A receiving node:
5858+ * - if splice transactions are pending and `my_current_funding_locked` matches one of
5859+ * those splice transactions, for which it hasn't received `splice_locked` yet:
5860+ */
5861+ if (inflight && recv_tlvs && recv_tlvs -> my_current_funding_locked ) {
5862+ for (size_t i = 0 ; i < tal_count (peer -> splice_state -> inflights ); i ++ ) {
5863+ struct inflight * itr = peer -> splice_state -> inflights [i ];
5864+ if (!bitcoin_txid_eq (& itr -> outpoint .txid ,
5865+ & recv_tlvs -> my_current_funding_locked -> my_current_funding_locked_txid ))
5866+ continue ;
5867+ /* BOLT-??? #2
5868+ * - MUST process `my_current_funding_locked` as if it was receiving `splice_locked`
5869+ * for this `txid`.
5870+ */
5871+ implied_peer_splice_locked (peer , itr -> outpoint .txid );
5872+ }
5873+ }
5874+
58325875 /* Note: next_index is the index of the current commit we're working
58335876 * on, but BOLT #2 refers to the *last* commit index, so we -1 where
58345877 * required. */
0 commit comments