Skip to content

Commit 3fac565

Browse files
committed
splice: Update to Eclair style of reestablish
Update to use Eclair’s spec’d version of reestablish. Changelog-None
1 parent 2f196dc commit 3fac565

File tree

4 files changed

+68
-30
lines changed

4 files changed

+68
-30
lines changed

channeld/channeld.c

Lines changed: 51 additions & 20 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
@@ -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 */
360363
static 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

389393
static 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 */
51695174
static 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

51875193
static 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

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)

tests/test_connection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3745,6 +3745,7 @@ def test_openchannel_init_alternate(node_factory, executor):
37453745
print("nothing to do")
37463746

37473747

3748+
@unittest.skip("experimental-upgrade-protocol TLV fields conflict with splicing TLV fields")
37483749
def test_upgrade_statickey(node_factory, executor):
37493750
"""l1 doesn't have option_static_remotekey, l2 offers it."""
37503751
l1, l2 = node_factory.get_nodes(2, opts=[{'may_reconnect': True,
@@ -3783,6 +3784,7 @@ def test_upgrade_statickey(node_factory, executor):
37833784
l2.daemon.wait_for_log(r"They sent desired_channel_type \[12\]")
37843785

37853786

3787+
@unittest.skip("experimental-upgrade-protocol TLV fields conflict with splicing TLV fields")
37863788
def test_upgrade_statickey_onchaind(node_factory, executor, bitcoind):
37873789
"""We test penalty before/after, and unilateral before/after"""
37883790
l1, l2 = node_factory.get_nodes(2, opts=[{'may_reconnect': True,
@@ -3940,6 +3942,7 @@ def test_upgrade_statickey_onchaind(node_factory, executor, bitcoind):
39403942
wait_for(lambda: len(l2.rpc.listpeerchannels()['channels']) == 0)
39413943

39423944

3945+
@unittest.skip("experimental-upgrade-protocol TLV fields conflict with splicing TLV fields")
39433946
def test_upgrade_statickey_fail(node_factory, executor, bitcoind):
39443947
"""We reconnect at all points during retransmit, and we won't upgrade."""
39453948
l1_disconnects = ['-WIRE_COMMITMENT_SIGNED',

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)