Skip to content

Commit bff76fd

Browse files
committed
WIP Commit
Work is still in progress! WIP changes
1 parent 589e382 commit bff76fd

26 files changed

Lines changed: 1521 additions & 259 deletions

File tree

.msggen.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,7 @@
16891689
"Feerates.perkb.mutual_close": 4,
16901690
"Feerates.perkb.opening": 3,
16911691
"Feerates.perkb.penalty": 8,
1692+
"Feerates.perkb.splice": 12,
16921693
"Feerates.perkb.unilateral_anchor_close": 11,
16931694
"Feerates.perkb.unilateral_close": 5
16941695
},
@@ -1707,6 +1708,7 @@
17071708
"Feerates.perkw.mutual_close": 4,
17081709
"Feerates.perkw.opening": 3,
17091710
"Feerates.perkw.penalty": 8,
1711+
"Feerates.perkw.splice": 12,
17101712
"Feerates.perkw.unilateral_anchor_close": 11,
17111713
"Feerates.perkw.unilateral_close": 5
17121714
},
@@ -7288,6 +7290,10 @@
72887290
"added": "pre-v0.10.1",
72897291
"deprecated": null
72907292
},
7293+
"Feerates.perkb.splice": {
7294+
"added": "v26.04",
7295+
"deprecated": null
7296+
},
72917297
"Feerates.perkb.unilateral_anchor_close": {
72927298
"added": "v23.08",
72937299
"deprecated": null
@@ -7348,6 +7354,10 @@
73487354
"added": "pre-v0.10.1",
73497355
"deprecated": null
73507356
},
7357+
"Feerates.perkw.splice": {
7358+
"added": "v26.04",
7359+
"deprecated": null
7360+
},
73517361
"Feerates.perkw.unilateral_anchor_close": {
73527362
"added": "v23.08",
73537363
"deprecated": null

channeld/channeld.c

Lines changed: 68 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,16 @@ struct peer {
7676
/* What (additional) messages the HSM accepts */
7777
u32 *hsm_capabilities;
7878

79+
/* The feerate to initiate a splice */
80+
u32 feerate_splice;
81+
7982
/* Tolerable amounts for feerate (only relevant for fundee). */
8083
u32 feerate_min, feerate_max;
8184

8285
/* Feerate to be used when creating penalty transactions. */
8386
u32 feerate_penalty;
8487

85-
/* Feerate to be used when opening (or splicing) a channel. */
88+
/* Feerate to be used when opening a channel. */
8689
u32 feerate_opening;
8790

8891
/* Local next per-commit point. */
@@ -967,6 +970,10 @@ static struct bitcoin_signature *calc_commitsigs(const tal_t *ctx,
967970
const u8 *msg;
968971
struct bitcoin_signature *htlc_sigs;
969972

973+
status_debug("calc_commitsigs(%p, %p, %p, %p, %p, %d, %p, %p)",
974+
ctx, peer, txs, funding_wscript, htlc_map,
975+
(int)commit_index, remote_per_commit, commit_sig);
976+
970977
htlcs = collect_htlcs(tmpctx, htlc_map);
971978
msg = towire_hsmd_sign_remote_commitment_tx(NULL, txs[0],
972979
&remote_funding_pubkey,
@@ -1890,9 +1897,9 @@ static void check_tx_abort(struct peer *peer, const u8 *msg, struct bitcoin_txid
18901897
exit(0);
18911898
}
18921899

1893-
static void splice_abort(struct peer *peer, const char *fmt, ...)
1900+
static void splice_abort(struct peer *peer, struct inflight *inflight,
1901+
const char *fmt, ...)
18941902
{
1895-
struct inflight *inflight = last_inflight(peer);
18961903
struct bitcoin_outpoint *outpoint;
18971904
u8 *msg;
18981905
char *reason;
@@ -3333,7 +3340,8 @@ static struct amount_sat calc_balance(struct peer *peer)
33333340
}
33343341

33353342
/* Returns the total channel funding output amount if all checks pass.
3336-
* Otherwise, exits via peer_failed_warn. DTODO: Change to `tx_abort`. */
3343+
* Otherwise, exits via peer_failed_warn.
3344+
* Note: Should only be called before adding splice to inflights. */
33373345
static struct amount_sat check_balances(struct peer *peer,
33383346
enum tx_role our_role,
33393347
const struct wally_psbt *psbt,
@@ -3374,6 +3382,32 @@ static struct amount_sat check_balances(struct peer *peer,
33743382
"Unable to add HTLC balance");
33753383
}
33763384

3385+
status_debug("in[TX_INITIATOR] %s; in[TX_ACCEPTER] %s",
3386+
fmt_amount_m_as_sat(tmpctx, in[TX_INITIATOR]),
3387+
fmt_amount_m_as_sat(tmpctx, in[TX_ACCEPTER]));
3388+
3389+
/* Here in[*] only contains the amounts from this channel.
3390+
* This is a great opportunity to check their splice out amount does
3391+
* not exceed their channel funds as this is never allowed even if
3392+
* additional funds are otherwise contributed. */
3393+
if (!amount_msat_can_add_sat_s64(in[TX_INITIATOR],
3394+
peer->splicing->opener_relative)) {
3395+
splice_abort(peer, NULL, "Intiator is attempting to splice out"
3396+
" %"PRId64"sat funds out of channel while only "
3397+
"having %s funds attributable to them.",
3398+
peer->splicing->opener_relative,
3399+
fmt_amount_m_as_sat(tmpctx, in[TX_INITIATOR]));
3400+
}
3401+
if (!amount_msat_can_add_sat_s64(in[TX_ACCEPTER],
3402+
peer->splicing->accepter_relative)) {
3403+
splice_abort(peer, NULL, "Accepter is attempting to splice out"
3404+
" %"PRId64"sat funds out of channel while only "
3405+
"having %s funds attributable to them.",
3406+
peer->splicing->accepter_relative,
3407+
fmt_amount_m_as_sat(tmpctx, in[TX_ACCEPTER]));
3408+
}
3409+
3410+
/* Now add values from the other outputs */
33773411
for (size_t i = 0; i < psbt->num_inputs; i++)
33783412
if (i != chan_input_index)
33793413
add_amount_to_side(peer, in,
@@ -3422,32 +3456,41 @@ static struct amount_sat check_balances(struct peer *peer,
34223456
*/
34233457
if (!amount_msat_add_sat_s64(&funding_amount, funding_amount,
34243458
peer->splicing->opener_relative))
3425-
splice_abort(peer, "Splice initiator did not provide enough"
3459+
splice_abort(peer, NULL, "Splice initiator did not provide enough"
34263460
" funding, funding_amount: %s, opener_relative:"
34273461
" %"PRIu64,
34283462
fmt_amount_msat(tmpctx, funding_amount),
34293463
peer->splicing->opener_relative);
3464+
3465+
status_debug("out[TX_INITIATOR] %s + %"PRId64,
3466+
fmt_amount_m_as_sat(tmpctx, out[TX_INITIATOR]),
3467+
peer->splicing->opener_relative);
3468+
34303469
if (!amount_msat_add_sat_s64(&out[TX_INITIATOR], out[TX_INITIATOR],
34313470
peer->splicing->opener_relative))
34323471
peer_failed_warn(peer->pps, &peer->channel_id,
34333472
"Unable to add opener funding to out amnt.");
34343473

34353474
if (!amount_msat_add_sat_s64(&funding_amount, funding_amount,
34363475
peer->splicing->accepter_relative))
3437-
splice_abort(peer, "Splice accepter did not provide enough"
3476+
splice_abort(peer, NULL, "Splice accepter did not provide enough"
34383477
" funding");
34393478
if (!amount_msat_add_sat_s64(&out[TX_ACCEPTER], out[TX_ACCEPTER],
34403479
peer->splicing->accepter_relative))
34413480
peer_failed_warn(peer->pps, &peer->channel_id,
34423481
"Unable to add accepter funding to out amnt.");
34433482

3483+
status_debug("is in[TX_INITIATOR] %s less than out[TX_INITIATOR] %s?",
3484+
fmt_amount_m_as_sat(tmpctx, in[TX_INITIATOR]),
3485+
fmt_amount_m_as_sat(tmpctx, out[TX_INITIATOR]));
3486+
34443487
if (amount_msat_less(in[TX_INITIATOR], out[TX_INITIATOR])) {
34453488
msg = towire_channeld_splice_funding_error(NULL,
34463489
in[TX_INITIATOR],
34473490
out[TX_INITIATOR],
34483491
true);
34493492
wire_sync_write(MASTER_FD, take(msg));
3450-
splice_abort(peer,
3493+
splice_abort(peer, NULL,
34513494
"Initiator funding is less than commited"
34523495
" amount. Initiator contributing %s but they"
34533496
" committed to %s. Pending offered HTLC"
@@ -3474,7 +3517,7 @@ static struct amount_sat check_balances(struct peer *peer,
34743517
out[TX_INITIATOR],
34753518
true);
34763519
wire_sync_write(MASTER_FD, take(msg));
3477-
splice_abort(peer,
3520+
splice_abort(peer, NULL,
34783521
"Accepter funding is less than commited"
34793522
" amount. Accepter contributing %s but they"
34803523
" committed to %s. Pending offered HTLC"
@@ -3504,10 +3547,10 @@ static struct amount_sat check_balances(struct peer *peer,
35043547
calc_weight(TX_INITIATOR, psbt, opener));
35053548

35063549
if (opener) {
3507-
status_debug("User specified fee of %s. Opening feerate %"PRIu32
3550+
status_debug("User specified fee of %s. Splice feerate %"PRIu32
35083551
" * weight %lu / 1000 = %s",
35093552
fmt_amount_m_as_sat(tmpctx, initiator_fee),
3510-
peer->feerate_opening,
3553+
peer->feerate_splice,
35113554
calc_weight(TX_INITIATOR, psbt, false),
35123555
fmt_amount_sat(tmpctx, max_initiator_fee));
35133556
}
@@ -3517,7 +3560,7 @@ static struct amount_sat check_balances(struct peer *peer,
35173560
msg = towire_channeld_splice_feerate_error(NULL, initiator_fee,
35183561
false);
35193562
wire_sync_write(MASTER_FD, take(msg));
3520-
splice_abort(peer,
3563+
splice_abort(peer, NULL,
35213564
"%s fee (%s) was too low, must be at least %s",
35223565
opener ? "Our" : "Your",
35233566
fmt_amount_msat(tmpctx, initiator_fee),
@@ -3537,7 +3580,7 @@ static struct amount_sat check_balances(struct peer *peer,
35373580

35383581
wire_sync_write(MASTER_FD, take(msg));
35393582

3540-
splice_abort(peer,
3583+
splice_abort(peer, NULL,
35413584
"Our own fee (%s) is too high to use without"
35423585
" forcing. Opening feerate %"PRIu32
35433586
" x weight %lu / 1000 = %s (max)",
@@ -3551,7 +3594,7 @@ static struct amount_sat check_balances(struct peer *peer,
35513594
msg = towire_channeld_splice_feerate_error(NULL, accepter_fee,
35523595
false);
35533596
wire_sync_write(MASTER_FD, take(msg));
3554-
splice_abort(peer,
3597+
splice_abort(peer, NULL,
35553598
"%s fee (%s) was too low, must be at least %s"
35563599
" weight: %"PRIu64", feerate_max: %"PRIu32,
35573600
opener ? "Your" : "Our",
@@ -3565,7 +3608,7 @@ static struct amount_sat check_balances(struct peer *peer,
35653608
msg = towire_channeld_splice_feerate_error(NULL, accepter_fee,
35663609
true);
35673610
wire_sync_write(MASTER_FD, take(msg));
3568-
splice_abort(peer,
3611+
splice_abort(peer, NULL,
35693612
"Our own fee (%s) was too high, max without"
35703613
" forcing is %s.",
35713614
fmt_amount_msat(tmpctx, accepter_fee),
@@ -4988,7 +5031,7 @@ static void handle_abort_req(struct peer *peer, const u8 *inmsg)
49885031
if (!fromwire_channeld_abort(inmsg))
49895032
master_badmsg(WIRE_CHANNELD_ABORT, inmsg);
49905033

4991-
splice_abort(peer, "requested by user");
5034+
splice_abort(peer, last_inflight(peer), "requested by user");
49925035
}
49935036

49945037
static void peer_in(struct peer *peer, const u8 *msg)
@@ -5844,7 +5887,8 @@ static void peer_reconnect(struct peer *peer,
58445887
" channel, ignoring it: %s",
58455888
fmt_bitcoin_outpoint(tmpctx, &peer->channel->funding));
58465889
else
5847-
splice_abort(peer, "next_funding_txid not recognized.");
5890+
splice_abort(peer, NULL,
5891+
"next_funding_txid not recognized.");
58485892
}
58495893

58505894
/* BOLT #2:
@@ -6338,11 +6382,13 @@ static void handle_feerates(struct peer *peer, const u8 *inmsg)
63386382
{
63396383
u32 feerate;
63406384

6341-
if (!fromwire_channeld_feerates(inmsg, &feerate,
6342-
&peer->feerate_min,
6343-
&peer->feerate_max,
6344-
&peer->feerate_penalty,
6345-
&peer->feerate_opening))
6385+
if (!fromwire_channeld_feerates(inmsg,
6386+
&feerate,
6387+
&peer->feerate_min,
6388+
&peer->feerate_max,
6389+
&peer->feerate_penalty,
6390+
&peer->feerate_opening,
6391+
&peer->feerate_splice))
63466392
master_badmsg(WIRE_CHANNELD_FEERATES, inmsg);
63476393

63486394
/* BOLT #2:
@@ -6710,6 +6756,7 @@ static void init_channel(struct peer *peer)
67106756
&lease_expiry,
67116757
&conf[LOCAL], &conf[REMOTE],
67126758
&fee_states,
6759+
&peer->feerate_splice,
67136760
&peer->feerate_min,
67146761
&peer->feerate_max,
67156762
&peer->feerate_penalty,

channeld/channeld_wire.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ msgdata,channeld_init,lease_expiry,u32,
2828
msgdata,channeld_init,our_config,channel_config,
2929
msgdata,channeld_init,their_config,channel_config,
3030
msgdata,channeld_init,fee_states,fee_states,
31+
msgdata,channeld_init,feerate_splice,u32,
3132
msgdata,channeld_init,feerate_min,u32,
3233
msgdata,channeld_init,feerate_max,u32,
3334
msgdata,channeld_init,feerate_penalty,u32,
@@ -331,6 +332,7 @@ msgdata,channeld_feerates,min_feerate,u32,
331332
msgdata,channeld_feerates,max_feerate,u32,
332333
msgdata,channeld_feerates,penalty_feerate,u32,
333334
msgdata,channeld_feerates,opening_feerate,u32,
335+
msgdata,channeld_feerates,feerate_splice,u32,
334336

335337
# master -> channeld: do you have a memleak?
336338
msgtype,channeld_dev_memleak,1033

channeld/full_channel.c

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,10 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
317317
&channel->basepoints[side],
318318
&channel->basepoints[!side],
319319
channel_has(channel, OPT_STATIC_REMOTEKEY),
320-
&keyset))
320+
&keyset)) {
321+
status_broken("channel_txs fails to derive keyset");
321322
return NULL;
323+
}
322324

323325
/* Figure out what @side will already be committed to. */
324326
gather_htlcs(ctx, channel, side, &committed, NULL, NULL);
@@ -332,16 +334,54 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
332334
side_pay = channel->view[side].owed[side];
333335
other_side_pay = channel->view[side].owed[!side];
334336

337+
status_debug("channel->view[REMOTE].owed[REMOTE] %s;"
338+
" channel->view[REMOTE].owed[LOCAL] %s;"
339+
" channel->view[LOCAL].owed[REMOTE] %s;"
340+
" channel->view[LOCAL].owed[LOCAL] %s;",
341+
fmt_amount_m_as_sat(tmpctx,
342+
channel->view[REMOTE].owed[REMOTE]),
343+
fmt_amount_m_as_sat(tmpctx,
344+
channel->view[REMOTE].owed[LOCAL]),
345+
fmt_amount_m_as_sat(tmpctx,
346+
channel->view[LOCAL].owed[REMOTE]),
347+
fmt_amount_m_as_sat(tmpctx,
348+
channel->view[LOCAL].owed[LOCAL]));
349+
335350
if (side == LOCAL) {
336-
if (!amount_msat_add_sat_s64(&side_pay, side_pay, splice_amnt))
351+
if (!amount_msat_add_sat_s64(&side_pay, side_pay, splice_amnt)) {
352+
status_broken("channel_txs fails to"
353+
" amount_msat_add_sat_s64 %s + %"PRId64
354+
" LOCAL (side_pay + splice_amnt)",
355+
fmt_amount_m_as_sat(tmpctx, side_pay),
356+
splice_amnt);
337357
return NULL;
338-
if (!amount_msat_add_sat_s64(&other_side_pay, other_side_pay, remote_splice_amnt))
358+
}
359+
if (!amount_msat_add_sat_s64(&other_side_pay, other_side_pay, remote_splice_amnt)) {
360+
status_broken("channel_txs fails to"
361+
" amount_msat_add_sat_s64 %s + %"PRId64
362+
" LOCAL (other_side_pay + remote_splice_amnt)",
363+
fmt_amount_m_as_sat(tmpctx, other_side_pay),
364+
remote_splice_amnt);
339365
return NULL;
366+
}
340367
} else if (side == REMOTE) {
341-
if (!amount_msat_add_sat_s64(&side_pay, side_pay, remote_splice_amnt))
368+
// channel_txs fails to amount_msat_add_sat_s64 0sat + -100000 REMOTE (side_pay + remote_splice_amnt)
369+
if (!amount_msat_add_sat_s64(&side_pay, side_pay, remote_splice_amnt)) {
370+
status_broken("channel_txs fails to"
371+
" amount_msat_add_sat_s64 %s + %"PRId64
372+
" REMOTE (side_pay + remote_splice_amnt)",
373+
fmt_amount_m_as_sat(tmpctx, side_pay),
374+
remote_splice_amnt);
342375
return NULL;
343-
if (!amount_msat_add_sat_s64(&other_side_pay, other_side_pay, splice_amnt))
376+
}
377+
if (!amount_msat_add_sat_s64(&other_side_pay, other_side_pay, splice_amnt)){
378+
status_broken("channel_txs fails to"
379+
" amount_msat_add_sat_s64 %s + %"PRId64
380+
" REMOTE (other_side_pay + splice_amnt)",
381+
fmt_amount_m_as_sat(tmpctx, other_side_pay),
382+
splice_amnt);
344383
return NULL;
384+
}
345385
}
346386

347387
txs = tal_arr(ctx, struct bitcoin_tx *, 1);

cln-grpc/proto/node.proto

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cln-grpc/src/convert.rs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)