5151#include <wire/peer_wire.h>
5252#include <wire/wire_sync.h>
5353
54+ #define EXPERIMENTAL_UPGRADE_ENABLED 0
55+
5456/* stdin == requests, 3 == peer, 4 = HSM */
5557#define MASTER_FD STDIN_FILENO
5658#define HSM_FD 4
@@ -356,6 +358,7 @@ static bool handle_master_request_later(struct peer *peer, const u8 *msg)
356358 return false;
357359}
358360
361+ #if EXPERIMENTAL_UPGRADE_ENABLED
359362/* Compare, with false if either is NULL */
360363static bool match_type (const u8 * t1 , const u8 * t2 )
361364{
@@ -385,6 +388,7 @@ static void set_channel_type(struct channel *channel, const u8 *type)
385388 wire_sync_write (MASTER_FD ,
386389 take (towire_channeld_upgraded (NULL , channel -> type )));
387390}
391+ #endif
388392
389393static void lock_signer_outpoint (const struct bitcoin_outpoint * outpoint )
390394{
@@ -5165,6 +5169,7 @@ static bool capture_premature_msg(const u8 ***shit_lnd_says, const u8 *msg)
51655169 return true;
51665170}
51675171
5172+ #if EXPERIMENTAL_UPGRADE_ENABLED
51685173/* Unwrap a channel_type into a raw byte array for the wire: can be NULL */
51695174static u8 * to_bytearr (const tal_t * ctx ,
51705175 const struct channel_type * channel_type TAKES )
@@ -5183,6 +5188,7 @@ static u8 *to_bytearr(const tal_t *ctx,
51835188 ret = tal_dup_talarr (ctx , u8 , channel_type -> features );
51845189 return ret ;
51855190}
5191+ #endif
51865192
51875193static void peer_reconnect (struct peer * peer ,
51885194 const struct secret * last_remote_per_commit_secret )
@@ -5219,6 +5225,7 @@ static void peer_reconnect(struct peer *peer,
52195225
52205226 send_tlvs = NULL ;
52215227
5228+ #if EXPERIMENTAL_UPGRADE_ENABLED
52225229 if (peer -> experimental_upgrade ) {
52235230 /* Subtle: we free tmpctx below as we loop, so tal off peer */
52245231 send_tlvs = tlv_channel_reestablish_tlvs_new (peer );
@@ -5257,6 +5264,7 @@ static void peer_reconnect(struct peer *peer,
52575264 peer -> channel )));
52585265 }
52595266 }
5267+ #endif
52605268
52615269 inflight = last_inflight (peer );
52625270
@@ -5284,6 +5292,34 @@ static void peer_reconnect(struct peer *peer,
52845292 }
52855293 }
52865294
5295+ if (feature_negotiated (peer -> our_features , peer -> their_features ,
5296+ OPT_SPLICE )) {
5297+ if (!send_tlvs ) {
5298+ /* Subtle: we free tmpctx below as we loop, so
5299+ * tal off peer */
5300+ send_tlvs = tlv_channel_reestablish_tlvs_new (peer );
5301+ }
5302+
5303+ if (peer -> channel_ready [REMOTE ])
5304+ send_tlvs -> your_last_funding_locked_txid = & peer -> channel -> funding .txid ;
5305+
5306+ send_tlvs -> my_current_funding_locked_txid = & peer -> channel -> funding .txid ;
5307+
5308+ for (size_t i = 0 ; i < tal_count (peer -> splice_state -> inflights ); i ++ ) {
5309+ struct inflight * itr = peer -> splice_state -> inflights [i ];
5310+ if (itr -> locked_scid ) {
5311+ send_tlvs -> my_current_funding_locked_txid = & itr -> outpoint .txid ;
5312+ status_debug ("Overriding send_tlvs->my_current_"
5313+ "funding_locked_txid to %s because"
5314+ " inflight is locked to scid %s" ,
5315+ fmt_bitcoin_txid (tmpctx ,
5316+ & itr -> outpoint .txid ),
5317+ fmt_short_channel_id (tmpctx ,
5318+ * itr -> locked_scid ));
5319+ }
5320+ }
5321+ }
5322+
52875323 /* BOLT #2:
52885324 *
52895325 * - upon reconnection:
@@ -5396,26 +5432,6 @@ static void peer_reconnect(struct peer *peer,
53965432 true,
53975433 false,
53985434 true);
5399- } else if (inflight -> is_locked
5400- && bitcoin_txid_eq (remote_next_funding ,
5401- & inflight -> outpoint .txid )) {
5402- if (!bitcoin_txid_eq (& inflight -> outpoint .txid ,
5403- & peer -> splice_state -> locked_txid ))
5404- peer_failed_err (peer -> pps ,
5405- & peer -> channel_id ,
5406- "Invalid splice was resumed %s,"
5407- " should be %s" ,
5408- fmt_bitcoin_txid (tmpctx ,
5409- & inflight -> outpoint .txid ),
5410- fmt_bitcoin_txid (tmpctx ,
5411- & peer -> splice_state -> locked_txid ));
5412- status_info ("Splice is not confirmed but locked on"
5413- " chain -- resending splice_locked" );
5414- peer_write (peer -> pps ,
5415- take (towire_splice_locked (NULL ,
5416- & peer -> channel_id ,
5417- & inflight -> outpoint .txid )));
5418- peer -> splice_state -> locked_ready [LOCAL ] = true;
54195435 } else if (bitcoin_txid_eq (remote_next_funding ,
54205436 & inflight -> outpoint .txid )) {
54215437 /* Don't send sigs unless we have theirs */
@@ -5470,6 +5486,19 @@ static void peer_reconnect(struct peer *peer,
54705486 }
54715487 }
54725488
5489+ /* Re-send `splice_locked` if an inflight is locked */
5490+ for (size_t i = 0 ; i < tal_count (peer -> splice_state -> inflights ); i ++ ) {
5491+ struct inflight * itr = peer -> splice_state -> inflights [i ];
5492+ if (!itr -> locked_scid )
5493+ continue ;
5494+
5495+ peer_write (peer -> pps ,
5496+ take (towire_splice_locked (NULL ,
5497+ & peer -> channel_id ,
5498+ & itr -> outpoint .txid )));
5499+ peer -> splice_state -> locked_ready [LOCAL ] = true;
5500+ }
5501+
54735502 /* BOLT #2:
54745503 *
54755504 * - if `next_commitment_number` is 1 in both the
@@ -5634,6 +5663,7 @@ static void peer_reconnect(struct peer *peer,
56345663 /* (If we had sent `closing_signed`, we'd be in closingd). */
56355664 maybe_send_shutdown (peer );
56365665
5666+ #if EXPERIMENTAL_UPGRADE_ENABLED
56375667 if (recv_tlvs -> desired_channel_type )
56385668 status_debug ("They sent desired_channel_type [%s]" ,
56395669 fmt_featurebits (tmpctx ,
@@ -5711,6 +5741,7 @@ static void peer_reconnect(struct peer *peer,
57115741 if (type )
57125742 set_channel_type (peer -> channel , type );
57135743 }
5744+ #endif
57145745
57155746 tal_free (send_tlvs );
57165747
0 commit comments