Skip to content

Commit 07a0b0d

Browse files
committed
splice: Update our_funds during splice_lock
The value of `our_funds` inlightningd is the funds added to the channel during creation. Splicing is a quasi-creation event. This change makes our pending funds be considered funding funds at the moment of splice confirmation. Changelog-None
1 parent 030fb3c commit 07a0b0d

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

lightningd/channel_control.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,11 @@ static void handle_peer_splice_locked(struct channel *channel, const u8 *msg)
11121112
" locked_txid %s",
11131113
fmt_bitcoin_txid(tmpctx, &locked_txid));
11141114

1115+
wallet_htlcsigs_confirm_inflight(channel->peer->ld->wallet, channel,
1116+
&inflight->funding->outpoint);
1117+
1118+
update_channel_from_inflight(channel->peer->ld, channel, inflight, true);
1119+
11151120
/* Stash prev funding data so we can log it after scid is updated
11161121
* (to get the blockheight) */
11171122
prev_our_msats = channel->our_msat;
@@ -1122,11 +1127,6 @@ static void handle_peer_splice_locked(struct channel *channel, const u8 *msg)
11221127
channel->msat_to_us_min.millisatoshis += splice_amnt * 1000; /* Raw: splicing */
11231128
channel->msat_to_us_max.millisatoshis += splice_amnt * 1000; /* Raw: splicing */
11241129

1125-
wallet_htlcsigs_confirm_inflight(channel->peer->ld->wallet, channel,
1126-
&inflight->funding->outpoint);
1127-
1128-
update_channel_from_inflight(channel->peer->ld, channel, inflight);
1129-
11301130
/* Remember that we got the lockin */
11311131
wallet_channel_save(channel->peer->ld->wallet, channel);
11321132

lightningd/dual_open_control.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,8 @@ static enum watch_result opening_depth_cb(struct lightningd *ld,
10561056
&inflight->channel->peer->id);
10571057

10581058
if (depth >= inflight->channel->minimum_depth)
1059-
update_channel_from_inflight(ld, inflight->channel, inflight);
1059+
update_channel_from_inflight(ld, inflight->channel, inflight,
1060+
false);
10601061

10611062
dualopend_tell_depth(inflight->channel, txid, depth);
10621063

lightningd/peer_control.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ static enum watch_result closed_inflight_depth_cb(struct lightningd *ld,
362362
return KEEP_WATCHING;
363363

364364
/* This is now the main tx. */
365-
update_channel_from_inflight(ld, inflight->channel, inflight);
365+
update_channel_from_inflight(ld, inflight->channel, inflight, false);
366366
channel_fail_saw_onchain(inflight->channel,
367367
REASON_UNKNOWN,
368368
tx,
@@ -2105,13 +2105,19 @@ void peer_disconnect_done(struct lightningd *ld, const u8 *msg)
21052105

21062106
void update_channel_from_inflight(struct lightningd *ld,
21072107
struct channel *channel,
2108-
const struct channel_inflight *inflight)
2108+
const struct channel_inflight *inflight,
2109+
bool is_splice)
21092110
{
21102111
channel->funding = inflight->funding->outpoint;
21112112
channel->funding_sats = inflight->funding->total_funds;
21122113

21132114
channel->our_funds = inflight->funding->our_funds;
21142115

2116+
/* At this point, our_msat *becomes* our_funds because the splice
2117+
* confirms. Any excess millisats stay in our_msats */
2118+
if (is_splice)
2119+
channel->our_funds = amount_msat_to_sat_round_down(channel->our_msat);
2120+
21152121
if (!amount_sat_add_sat_s64(&channel->our_funds, channel->our_funds,
21162122
inflight->funding->splice_amnt)) {
21172123

lightningd/peer_control.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ void drop_to_chain(struct lightningd *ld, struct channel *channel,
128128

129129
void update_channel_from_inflight(struct lightningd *ld,
130130
struct channel *channel,
131-
const struct channel_inflight *inflight);
131+
const struct channel_inflight *inflight,
132+
bool is_splice);
132133

133134
void channel_watch_funding(struct lightningd *ld, struct channel *channel);
134135

0 commit comments

Comments
 (0)