Skip to content

Commit 6275942

Browse files
committed
fixup! splice: Update to Eclair style of reestablish
1 parent 0a2f8f7 commit 6275942

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

channeld/channeld.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
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
@@ -358,6 +360,7 @@ static bool handle_master_request_later(struct peer *peer, const u8 *msg)
358360
return false;
359361
}
360362

363+
#if EXPERIMENTAL_UPGRADE_ENABLED
361364
/* Compare, with false if either is NULL */
362365
static bool match_type(const u8 *t1, const u8 *t2)
363366
{
@@ -387,6 +390,7 @@ static void set_channel_type(struct channel *channel, const u8 *type)
387390
wire_sync_write(MASTER_FD,
388391
take(towire_channeld_upgraded(NULL, channel->type)));
389392
}
393+
#endif
390394

391395
static void lock_signer_outpoint(const struct bitcoin_outpoint *outpoint)
392396
{
@@ -5254,6 +5258,7 @@ static bool capture_premature_msg(const u8 ***shit_lnd_says, const u8 *msg)
52545258
return true;
52555259
}
52565260

5261+
#if EXPERIMENTAL_UPGRADE_ENABLED
52575262
/* Unwrap a channel_type into a raw byte array for the wire: can be NULL */
52585263
static u8 *to_bytearr(const tal_t *ctx,
52595264
const struct channel_type *channel_type TAKES)
@@ -5272,6 +5277,7 @@ static u8 *to_bytearr(const tal_t *ctx,
52725277
ret = tal_dup_talarr(ctx, u8, channel_type->features);
52735278
return ret;
52745279
}
5280+
#endif
52755281

52765282
static void peer_reconnect(struct peer *peer,
52775283
const struct secret *last_remote_per_commit_secret)
@@ -5309,6 +5315,7 @@ static void peer_reconnect(struct peer *peer,
53095315

53105316
send_tlvs = NULL;
53115317

5318+
#if EXPERIMENTAL_UPGRADE_ENABLED
53125319
if (peer->experimental_upgrade) {
53135320
/* Subtle: we free tmpctx below as we loop, so tal off peer */
53145321
send_tlvs = tlv_channel_reestablish_tlvs_new(peer);
@@ -5347,6 +5354,7 @@ static void peer_reconnect(struct peer *peer,
53475354
peer->channel)));
53485355
}
53495356
}
5357+
#endif
53505358

53515359
inflight = last_inflight(peer);
53525360

@@ -5400,16 +5408,16 @@ static void peer_reconnect(struct peer *peer,
54005408
&peer->channel->funding.txid));
54015409

54025410
for (size_t i = 0; i < tal_count(peer->splice_state->inflights); i++) {
5403-
struct inflight *inflight = peer->splice_state->inflights[i];
5404-
if (inflight->locked_scid) {
5405-
send_tlvs->my_current_funding_locked_txid = &inflight->outpoint.txid;
5411+
struct inflight *itr = peer->splice_state->inflights[i];
5412+
if (itr->locked_scid) {
5413+
send_tlvs->my_current_funding_locked_txid = &itr->outpoint.txid;
54065414
status_debug("Overriding send_tlvs->my_current_"
54075415
"funding_locked_txid to %s because"
54085416
" inflight is locked to scid %s",
54095417
fmt_bitcoin_txid(tmpctx,
5410-
&inflight->outpoint.txid),
5418+
&itr->outpoint.txid),
54115419
fmt_short_channel_id(tmpctx,
5412-
*inflight->locked_scid));
5420+
*itr->locked_scid));
54135421
}
54145422
}
54155423
}
@@ -5601,14 +5609,14 @@ static void peer_reconnect(struct peer *peer,
56015609

56025610
/* Re-send `splice_locked` if an inflight is locked */
56035611
for (size_t i = 0; i < tal_count(peer->splice_state->inflights); i++) {
5604-
struct inflight *inflight = peer->splice_state->inflights[i];
5605-
if (!inflight->locked_scid)
5612+
struct inflight *itr = peer->splice_state->inflights[i];
5613+
if (!itr->locked_scid)
56065614
continue;
56075615

56085616
peer_write(peer->pps,
56095617
take(towire_splice_locked(NULL,
56105618
&peer->channel_id,
5611-
&inflight->outpoint.txid)));
5619+
&itr->outpoint.txid)));
56125620
peer->splice_state->locked_ready[LOCAL] = true;
56135621
}
56145622

@@ -5779,6 +5787,7 @@ static void peer_reconnect(struct peer *peer,
57795787
/* (If we had sent `closing_signed`, we'd be in closingd). */
57805788
maybe_send_shutdown(peer);
57815789

5790+
#if EXPERIMENTAL_UPGRADE_ENABLED
57825791
if (recv_tlvs->desired_channel_type)
57835792
status_debug("They sent desired_channel_type [%s]",
57845793
fmt_featurebits(tmpctx,
@@ -5856,6 +5865,7 @@ static void peer_reconnect(struct peer *peer,
58565865
if (type)
58575866
set_channel_type(peer->channel, type);
58585867
}
5868+
#endif
58595869

58605870
tal_free(send_tlvs);
58615871

tests/fuzz/fuzz-wire-channel_reestablish.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <tests/fuzz/wire.h>
77
#include <wire/peer_wire.h>
88

9+
#define EXPERIMENTAL_UPGRADE_ENABLED 0
10+
911
struct channel_reestablish {
1012
struct channel_id channel_id;
1113
u64 next_commitment_number;
@@ -46,6 +48,11 @@ static bool equal(const struct channel_reestablish *x,
4648

4749
if (!tal_arr_eq(x->tlvs->next_funding, y->tlvs->next_funding))
4850
return false;
51+
if (!tal_arr_eq(x->tlvs->your_last_funding_locked_txid, y->tlvs->your_last_funding_locked_txid))
52+
return false;
53+
if (!tal_arr_eq(x->tlvs->my_current_funding_locked_txid, y->tlvs->my_current_funding_locked_txid))
54+
return false;
55+
#if EXPERIMENTAL_UPGRADE_ENABLED
4956
if (!tal_arr_eq(x->tlvs->next_to_send, y->tlvs->next_to_send))
5057
return false;
5158
if (!tal_arr_eq(x->tlvs->desired_channel_type, y->tlvs->desired_channel_type))
@@ -54,6 +61,9 @@ static bool equal(const struct channel_reestablish *x,
5461
return false;
5562
return tal_arr_eq(x->tlvs->upgradable_channel_type,
5663
y->tlvs->upgradable_channel_type);
64+
#else
65+
return true;
66+
#endif
5767
}
5868

5969
void run(const u8 *data, size_t size)

wire/peer_wire.csv

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,16 +320,10 @@ msgdata,channel_reestablish,your_last_per_commitment_secret,byte,32
320320
msgdata,channel_reestablish,my_current_per_commitment_point,point,
321321
tlvtype,channel_reestablish_tlvs,next_funding,0
322322
tlvdata,channel_reestablish_tlvs,next_funding,next_funding_txid,sha256,
323-
tlvtype,channel_reestablish_tlvs,next_funding,0
324-
tlvdata,channel_reestablish_tlvs,next_funding,next_funding_txid,sha256,
325-
tlvtype,channel_reestablish_tlvs,next_to_send,1
326-
tlvdata,channel_reestablish_tlvs,next_to_send,commitment_number,tu64,
327-
tlvtype,channel_reestablish_tlvs,desired_channel_type,3
328-
tlvdata,channel_reestablish_tlvs,desired_channel_type,type,byte,...
329-
tlvtype,channel_reestablish_tlvs,current_channel_type,5
330-
tlvdata,channel_reestablish_tlvs,current_channel_type,type,byte,...
331-
tlvtype,channel_reestablish_tlvs,upgradable_channel_type,7
332-
tlvdata,channel_reestablish_tlvs,upgradable_channel_type,type,byte,...
323+
tlvtype,channel_reestablish_tlvs,your_last_funding_locked_txid,1
324+
tlvdata,channel_reestablish_tlvs,your_last_funding_locked_txid,your_last_funding_locked_txid,sha256,
325+
tlvtype,channel_reestablish_tlvs,my_current_funding_locked_txid,3
326+
tlvdata,channel_reestablish_tlvs,my_current_funding_locked_txid,my_current_funding_locked_txid,sha256,
333327
msgtype,announcement_signatures,259
334328
msgdata,announcement_signatures,channel_id,channel_id,
335329
msgdata,announcement_signatures,short_channel_id,short_channel_id,

0 commit comments

Comments
 (0)