channeld: Code to implement splicing

Update the lightningd <-> channeld interface with lots of new commands to needed to facilitate spicing.

Implement the channeld splicing protocol leveraging the interactivetx protocol.

Implement lightningd’s channel_control to support channeld in its splicing efforts.

Changelog-Added: Added the features to enable splicing & resizing of active channels.
This commit is contained in:
Dusty Daemon
2023-07-27 14:37:52 -07:00
committed by Rusty Russell
parent ebd0a3fd69
commit 4628e3ace8
88 changed files with 4560 additions and 644 deletions

View File

@@ -65,6 +65,11 @@ struct channel *new_initial_channel(const tal_t *ctx,
= channel->view[LOCAL].owed[REMOTE]
= remote_msatoshi;
channel->view[LOCAL].lowest_splice_amnt[LOCAL] = 0;
channel->view[LOCAL].lowest_splice_amnt[REMOTE] = 0;
channel->view[REMOTE].lowest_splice_amnt[LOCAL] = 0;
channel->view[REMOTE].lowest_splice_amnt[REMOTE] = 0;
channel->basepoints[LOCAL] = *local_basepoints;
channel->basepoints[REMOTE] = *remote_basepoints;
@@ -147,6 +152,34 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
return init_tx;
}
const char *channel_update_funding(struct channel *channel,
const struct bitcoin_outpoint *funding,
struct amount_sat funding_sats,
s64 splice_amnt)
{
s64 funding_diff = (s64)funding_sats.satoshis - (s64)channel->funding_sats.satoshis; /* Raw: splicing */
s64 remote_splice_amnt = funding_diff - splice_amnt;
channel->funding = *funding;
channel->funding_sats = funding_sats;
if (splice_amnt * 1000 + channel->view[LOCAL].owed[LOCAL].millisatoshis < 0) /* Raw: splicing */
return tal_fmt(tmpctx, "Channel funding update would make local"
" balance negative.");
channel->view[LOCAL].owed[LOCAL].millisatoshis += splice_amnt * 1000; /* Raw: splicing */
channel->view[REMOTE].owed[LOCAL].millisatoshis += splice_amnt * 1000; /* Raw: splicing */
if (remote_splice_amnt * 1000 + channel->view[LOCAL].owed[REMOTE].millisatoshis < 0) /* Raw: splicing */
return tal_fmt(tmpctx, "Channel funding update would make"
" remote balance negative.");
channel->view[LOCAL].owed[REMOTE].millisatoshis += remote_splice_amnt * 1000; /* Raw: splicing */
channel->view[REMOTE].owed[REMOTE].millisatoshis += remote_splice_amnt * 1000; /* Raw: splicing */
return NULL;
}
u32 channel_feerate(const struct channel *channel, enum side side)
{
return get_feerate(channel->fee_states, channel->opener, side);