Skip to content

Commit ee6ded1

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 1d722a9 commit ee6ded1

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

lightningd/channel_control.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ static void handle_peer_splice_locked(struct channel *channel, const u8 *msg)
11251125
wallet_htlcsigs_confirm_inflight(channel->peer->ld->wallet, channel,
11261126
&inflight->funding->outpoint);
11271127

1128-
update_channel_from_inflight(channel->peer->ld, channel, inflight);
1128+
update_channel_from_inflight(channel->peer->ld, channel, inflight, true);
11291129

11301130
/* Remember that we got the lockin */
11311131
wallet_channel_save(channel->peer->ld->wallet, channel);

lightningd/dual_open_control.c

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

10571057
if (depth >= inflight->channel->minimum_depth)
1058-
update_channel_from_inflight(ld, inflight->channel, inflight);
1058+
update_channel_from_inflight(ld, inflight->channel, inflight,
1059+
false);
10591060

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

lightningd/peer_control.c

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

363363
/* This is now the main tx. */
364-
update_channel_from_inflight(ld, inflight->channel, inflight);
364+
update_channel_from_inflight(ld, inflight->channel, inflight, false);
365365
channel_fail_saw_onchain(inflight->channel,
366366
REASON_UNKNOWN,
367367
tx,
@@ -2074,13 +2074,19 @@ void peer_disconnect_done(struct lightningd *ld, const u8 *msg)
20742074

20752075
void update_channel_from_inflight(struct lightningd *ld,
20762076
struct channel *channel,
2077-
const struct channel_inflight *inflight)
2077+
const struct channel_inflight *inflight,
2078+
bool is_splice)
20782079
{
20792080
channel->funding = inflight->funding->outpoint;
20802081
channel->funding_sats = inflight->funding->total_funds;
20812082

20822083
channel->our_funds = inflight->funding->our_funds;
20832084

2085+
/* At this point, our_msat *becomes* our_funds because the splice
2086+
* confirms. Any excess millisats stay in our_msats */
2087+
if (is_splice)
2088+
channel->our_funds = amount_msat_to_sat_round_down(channel->our_msat);
2089+
20842090
if (!amount_sat_add_sat_s64(&channel->our_funds, channel->our_funds,
20852091
inflight->funding->splice_amnt)) {
20862092

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)