Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7167013
splice: Clean up error messages for RPC
ddustin Oct 4, 2024
8e8c811
channeld: Fix `tx_abort` encoding
ddustin Oct 4, 2024
9c0c5dc
splice: Add `remote_funding` to database
ddustin Oct 4, 2024
c899a67
interactivetx: Add support for shared prevtx
ddustin Oct 4, 2024
ad2d085
channeld: Store `remote_funding` for splice
ddustin Oct 4, 2024
91ad6fb
channeld: Add `remote_funding` to inflight
ddustin Oct 4, 2024
6b2f3c0
splice: Pass `remote_funding` between ld and channeld
ddustin Oct 4, 2024
3367bca
channeld: Add dynamic funding_pubkeys to channel_txs
ddustin Oct 4, 2024
459f7d8
channeld: Update commitsigs to support remote_funding
ddustin Oct 4, 2024
153b5d2
splice: Remove blockhash from peer msg
ddustin Oct 4, 2024
a75d354
splice: Update splice signature msg type
ddustin Oct 4, 2024
d232a00
splice: Add new funding output balance
ddustin Oct 4, 2024
130f7eb
splice: Update `commitment_signed_tlvs`
ddustin Oct 4, 2024
02d24b3
splice: Update commit sigs to use dynamic remote funding pubkey.
ddustin Oct 4, 2024
6f55c1f
splice: Update find_channel_output for rotating funding key
ddustin Nov 20, 2024
879ec7c
channeld: Move tx lookup function up
ddustin Oct 4, 2024
2b196f3
splice: Enable shared tx on `interactivetx`
ddustin Nov 15, 2024
5b880bc
channeld: `tx_abort` should skip reestablish
ddustin Oct 4, 2024
88173ae
splice: Update funding pubkey on splice lock
ddustin Oct 4, 2024
aaa2033
splice: Enable remote funding key rotation
ddustin Oct 4, 2024
4a06096
splice: Update messages to spec
ddustin Oct 4, 2024
f1ed25e
splice: tx_abort no longer reestablishes
ddustin Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
322 changes: 216 additions & 106 deletions channeld/channeld.c

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion channeld/channeld_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ msgdata,channeld_splice_feerate_error,too_high,bool,

# channeld->master: Add an inflight to the DB
msgtype,channeld_add_inflight,7216
msgdata,channeld_add_inflight,remote_funding,pubkey,
msgdata,channeld_add_inflight,tx_id,bitcoin_txid,
msgdata,channeld_add_inflight,tx_outnum,u32,
msgdata,channeld_add_inflight,feerate,u32,
Expand Down Expand Up @@ -287,7 +288,7 @@ msgdata,channeld_splice_state_error,state_error,wirestring,
msgtype,channeld_splice_abort,7223
msgdata,channeld_splice_abort,did_i_initiate,bool,
msgdata,channeld_splice_abort,inflight_outpoint,?bitcoin_outpoint,
msgdata,channeld_splice_abort,reason,?wirestring,
msgdata,channeld_splice_abort,reason,wirestring,

# master->channeld: Please enter stfu mode
msgtype,channeld_stfu,7224
Expand Down
18 changes: 11 additions & 7 deletions channeld/full_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,17 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
enum side side,
s64 splice_amnt,
s64 remote_splice_amnt,
int *other_anchor_outnum)
int *other_anchor_outnum,
const struct pubkey funding_pubkeys[NUM_SIDES])
{
struct bitcoin_tx **txs;
const struct htlc **committed;
struct keyset keyset;
struct amount_msat side_pay, other_side_pay;

if (!funding_pubkeys)
funding_pubkeys = channel->funding_pubkey;

if (!derive_keyset(per_commitment_point,
&channel->basepoints[side],
&channel->basepoints[!side],
Expand All @@ -329,8 +333,8 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
/* Generating and saving witness script required to spend
* the funding output */
*funding_wscript = bitcoin_redeem_2of2(ctx,
&channel->funding_pubkey[side],
&channel->funding_pubkey[!side]);
&funding_pubkeys[side],
&funding_pubkeys[!side]);

side_pay = channel->view[side].owed[side];
other_side_pay = channel->view[side].owed[!side];
Expand All @@ -351,8 +355,8 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
txs[0] = commit_tx(
txs, funding,
funding_sats,
&channel->funding_pubkey[side],
&channel->funding_pubkey[!side],
&funding_pubkeys[side],
&funding_pubkeys[!side],
channel->opener,
channel->config[!side].to_self_delay,
channel->lease_expiry,
Expand All @@ -367,9 +371,9 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,

/* Set the remote/local pubkeys on the commitment tx psbt */
psbt_input_add_pubkey(txs[0]->psbt, 0,
&channel->funding_pubkey[side], false /* is_taproot */);
&funding_pubkeys[side], false /* is_taproot */);
psbt_input_add_pubkey(txs[0]->psbt, 0,
&channel->funding_pubkey[!side], false /* is_taproot */);
&funding_pubkeys[!side], false /* is_taproot */);

add_htlcs(&txs, *htlcmap, channel, &keyset, side);

Expand Down
4 changes: 3 additions & 1 deletion channeld/full_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ struct channel *new_full_channel(const tal_t *ctx,
* @local_splice_amnt: how much is being spliced in (or out, if -ve) of local side.
* @remote_splice_amnt: how much is being spliced in (or out, if -ve) of remote side.
* @other_anchor_outnum: which output (-1 if none) is the !!side anchor
* @funding_pubkeys: The funding pubkeys (specify NULL to use channel's value).
*
* Returns the unsigned commitment transaction for the committed state
* for @side, followed by the htlc transactions in output order and
Expand All @@ -84,7 +85,8 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
enum side side,
s64 local_splice_amnt,
s64 remote_splice_amnt,
int *local_anchor_outnum);
int *local_anchor_outnum,
const struct pubkey funding_pubkeys[NUM_SIDES]);

/**
* actual_feerate: what is the actual feerate for the local side.
Expand Down
15 changes: 2 additions & 13 deletions channeld/inflight.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct inflight *fromwire_inflight(const tal_t *ctx, const u8 **cursor, size_t *
struct inflight *inflight = tal(ctx, struct inflight);

fromwire_bitcoin_outpoint(cursor, max, &inflight->outpoint);
fromwire_pubkey(cursor, max, &inflight->remote_funding);
inflight->amnt = fromwire_amount_sat(cursor, max);
inflight->remote_tx_sigs = fromwire_bool(cursor, max);
inflight->psbt = fromwire_wally_psbt(inflight, cursor, max);
Expand All @@ -31,6 +32,7 @@ struct inflight *fromwire_inflight(const tal_t *ctx, const u8 **cursor, size_t *
void towire_inflight(u8 **pptr, const struct inflight *inflight)
{
towire_bitcoin_outpoint(pptr, &inflight->outpoint);
towire_pubkey(pptr, &inflight->remote_funding);
towire_amount_sat(pptr, inflight->amnt);
towire_bool(pptr, inflight->remote_tx_sigs);
towire_wally_psbt(pptr, inflight->psbt);
Expand All @@ -43,16 +45,3 @@ void towire_inflight(u8 **pptr, const struct inflight *inflight)
towire_bool(pptr, inflight->i_am_initiator);
towire_bool(pptr, inflight->force_sign_first);
}

void copy_inflight(struct inflight *dest, struct inflight *src)
{
dest->outpoint = src->outpoint;
dest->amnt = src->amnt;
dest->remote_tx_sigs = src->remote_tx_sigs;
dest->psbt = src->psbt ? clone_psbt(dest, src->psbt): NULL;
dest->splice_amnt = src->splice_amnt;
dest->last_tx = src->last_tx ? clone_bitcoin_tx(dest, src->last_tx) : NULL;
dest->last_sig = src->last_sig;
dest->i_am_initiator = src->i_am_initiator;
dest->force_sign_first = src->force_sign_first;
}
4 changes: 2 additions & 2 deletions channeld/inflight.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
#define LIGHTNING_CHANNELD_INFLIGHT_H

#include "config.h"
#include <bitcoin/pubkey.h>
#include <bitcoin/tx.h>
#include <common/amount.h>

struct inflight {
struct bitcoin_outpoint outpoint;
struct pubkey remote_funding;
struct amount_sat amnt;
bool remote_tx_sigs;
struct wally_psbt *psbt;
Expand All @@ -22,6 +24,4 @@ struct inflight {
struct inflight *fromwire_inflight(const tal_t *ctx, const u8 **cursor, size_t *max);
void towire_inflight(u8 **pptr, const struct inflight *inflight);

void copy_inflight(struct inflight *dest, struct inflight *src);

#endif /* LIGHTNING_CHANNELD_INFLIGHT_H */
2 changes: 2 additions & 0 deletions channeld/splice.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ struct splice_state *splice_state_new(const tal_t *ctx);
/* An active splice negotiation. Born when splice beings and dies when a splice
* negotation has finished */
struct splicing {
/* The remote side's rotated funding pubkey */
struct pubkey remote_funding_pubkey;
/* The opener side's relative balance change */
s64 opener_relative;
/* The accepter side's relative balance change */
Expand Down
16 changes: 8 additions & 8 deletions channeld/test/run-full_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ int main(int argc, const char *argv[])
txs = channel_txs(tmpctx, &funding, funding_amount,
&htlc_map, NULL, &funding_wscript_alt,
lchannel, &local_per_commitment_point, 42, LOCAL, 0, 0,
&local_anchor);
&local_anchor, NULL);
assert(tal_count(txs) == 1);
assert(tal_count(htlc_map) == 2);
assert(scripteq(funding_wscript_alt, funding_wscript));
Expand All @@ -564,7 +564,7 @@ int main(int argc, const char *argv[])
txs2 = channel_txs(tmpctx, &funding, funding_amount,
&htlc_map, NULL, &funding_wscript,
rchannel, &local_per_commitment_point, 42, REMOTE, 0, 0,
&local_anchor);
&local_anchor, NULL);
txs_must_be_eq(txs, txs2);

/* BOLT #3:
Expand Down Expand Up @@ -593,12 +593,12 @@ int main(int argc, const char *argv[])
txs = channel_txs(tmpctx, &funding, funding_amount,
&htlc_map, NULL, &funding_wscript,
lchannel, &local_per_commitment_point, 42, LOCAL, 0, 0,
&local_anchor);
&local_anchor, NULL);
assert(tal_count(txs) == 1);
txs2 = channel_txs(tmpctx, &funding, funding_amount,
&htlc_map, NULL, &funding_wscript,
rchannel, &local_per_commitment_point, 42, REMOTE, 0, 0,
&local_anchor);
&local_anchor, NULL);
txs_must_be_eq(txs, txs2);

update_feerate(lchannel, feerate_per_kw[LOCAL]);
Expand All @@ -615,12 +615,12 @@ int main(int argc, const char *argv[])
txs = channel_txs(tmpctx, &funding, funding_amount,
&htlc_map, NULL, &funding_wscript,
lchannel, &local_per_commitment_point, 42, LOCAL, 0, 0,
&local_anchor);
&local_anchor, NULL);
assert(tal_count(txs) == 6);
txs2 = channel_txs(tmpctx, &funding, funding_amount,
&htlc_map, NULL, &funding_wscript,
rchannel, &local_per_commitment_point, 42, REMOTE, 0, 0,
&local_anchor);
&local_anchor, NULL);
txs_must_be_eq(txs, txs2);

/* FIXME: Compare signatures! */
Expand Down Expand Up @@ -695,14 +695,14 @@ int main(int argc, const char *argv[])
&htlc_map, NULL, &funding_wscript,
lchannel, &local_per_commitment_point, 42,
LOCAL, 0, 0,
&local_anchor);
&local_anchor, NULL);
tx_must_be_eq(txs[0], raw_tx);

txs2 = channel_txs(tmpctx, &funding, funding_amount,
&htlc_map, NULL, &funding_wscript,
rchannel, &local_per_commitment_point,
42, REMOTE, 0, 0,
&local_anchor);
&local_anchor, NULL);
txs_must_be_eq(txs, txs2);
}

Expand Down
59 changes: 48 additions & 11 deletions common/interactivetx.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ struct interactivetx_context *new_interactivetx_context(const tal_t *ctx,
ictx->our_role = our_role;
ictx->pps = pps;
ictx->channel_id = channel_id;
ictx->shared_outpoint = NULL;
ictx->funding_tx = NULL;
ictx->tx_add_input_count = 0;
ictx->tx_add_output_count = 0;
ictx->next_update_fn = default_next_update;
Expand Down Expand Up @@ -208,6 +210,7 @@ static char *send_next(const tal_t *ctx,

if (tal_count(set->added_ins) != 0) {
const struct input_set *in = &set->added_ins[0];
struct bitcoin_outpoint point;
u8 *prevtx;

if (!psbt_get_serial_id(&in->input.unknowns, &serial_id))
Expand All @@ -220,9 +223,24 @@ static char *send_next(const tal_t *ctx,
return "interactivetx ADD_INPUT PSBT needs the previous"
" transaction set.";

msg = towire_tx_add_input(NULL, cid, serial_id,
prevtx, in->input.index,
in->input.sequence);
wally_psbt_input_get_outpoint(&in->input, &point);

/* If this the shared channel input, we send funding txid in
* in tlvs and do not send prevtx */
if (ictx->shared_outpoint
&& bitcoin_outpoint_eq(&point, ictx->shared_outpoint)) {
struct tlv_tx_add_input_tlvs *tlvs = tal(tmpctx, struct tlv_tx_add_input_tlvs);
tlvs->shared_input_txid = tal_dup(tlvs,
struct bitcoin_txid,
&point.txid);
msg = towire_tx_add_input(NULL, cid, serial_id,
NULL, in->input.index,
in->input.sequence, tlvs);
} else {
msg = towire_tx_add_input(NULL, cid, serial_id,
prevtx, in->input.index,
in->input.sequence, NULL);
}

tal_arr_remove(&set->added_ins, 0);
}
Expand Down Expand Up @@ -417,12 +435,14 @@ char *process_interactivetx_updates(const tal_t *ctx,
size_t len;
struct bitcoin_tx *tx;
struct bitcoin_outpoint outpoint;
struct tlv_tx_add_input_tlvs *tlvs;

if (!fromwire_tx_add_input(ctx, msg, &cid,
&serial_id,
cast_const2(u8 **,
&tx_bytes),
&outpoint.n, &sequence))
&outpoint.n, &sequence,
&tlvs))
return tal_fmt(ctx,
"Parsing tx_add_input %s",
tal_hex(ctx, msg));
Expand Down Expand Up @@ -459,13 +479,30 @@ char *process_interactivetx_updates(const tal_t *ctx,
return tal_fmt(ctx, "Duplicate serial_id rcvd"
" %"PRIu64, serial_id);

/* Convert tx_bytes to a tx! */
len = tal_bytelen(tx_bytes);
tx = pull_bitcoin_tx_only(ctx, &tx_bytes, &len);

if (!tx || len != 0)
return tal_fmt(ctx, "Invalid tx sent. len: %d",
(int)len);
/* For our shared input only, we will fill in prevtx */
if (ictx->shared_outpoint && tlvs->shared_input_txid) {
if (!bitcoin_txid_eq(tlvs->shared_input_txid,
&ictx->shared_outpoint->txid))
return tal_fmt(ctx, "funding_txid value"
" %s unrecognized."
" Should be %s",
fmt_bitcoin_txid(ctx, tlvs->shared_input_txid),
fmt_bitcoin_txid(ctx, &ictx->shared_outpoint->txid));
if (!ictx->funding_tx)
return tal_fmt(ctx, "Internal error"
" did not set"
" interactivetx"
" funding_tx");
tx = ictx->funding_tx;
}
else {
/* Convert tx_bytes to a tx! */
len = tal_bytelen(tx_bytes);
tx = pull_bitcoin_tx_only(ctx, &tx_bytes, &len);
if (!tx || len != 0)
return tal_fmt(ctx, "Invalid tx sent. len: %d",
(int)len);
}

if (outpoint.n >= tx->wtx->num_outputs)
return tal_fmt(ctx,
Expand Down
8 changes: 8 additions & 0 deletions common/interactivetx.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ struct interactivetx_context {
struct per_peer_state *pps;
struct channel_id channel_id;

/* The existing funding outpoint of a channel being spliced.
* This input will send funding_txid instead of prevtx. */
struct bitcoin_outpoint *shared_outpoint;

/* When receiving `tx_add_input` we will fill in prevtx using this
* value when `shared_outpoint`'s txid matches */
struct bitcoin_tx *funding_tx;

/* Track how many of each tx collab msg we receive */
u16 tx_add_input_count, tx_add_output_count;

Expand Down
1 change: 1 addition & 0 deletions common/jsonrpc_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ enum jsonrpc_errcode {
SPLICE_LOW_FEE = 359,
SPLICE_HIGH_FEE = 360,
SPLICE_ABORT = 362,
SPLICE_CHANNEL_ERROR = 363,

/* `connect` errors */
CONNECT_NO_KNOWN_ADDRESS = 400,
Expand Down
37 changes: 37 additions & 0 deletions common/wire_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,43 @@ u8 *towire_warningfmt(const tal_t *ctx,
return msg;
}

u8 *towire_abortfmtv(const tal_t *ctx,
const struct channel_id *channel,
const char *fmt,
va_list ap)
{
/* BOLT #1:
*
* The channel is referred to by `channel_id`, unless `channel_id` is
* 0 (i.e. all bytes are 0), in which case it refers to all
* channels. */
static const struct channel_id all_channels;
char *estr;
u8 *msg;

estr = tal_vfmt(ctx, fmt, ap);
/* We need tal_len to work, so we use copy. */
msg = towire_tx_abort(ctx, channel ? channel : &all_channels,
(u8 *)tal_dup_arr(estr, char, estr, strlen(estr), 0));
tal_free(estr);

return msg;
}

u8 *towire_abortfmt(const tal_t *ctx,
const struct channel_id *channel,
const char *fmt, ...)
{
va_list ap;
u8 *msg;

va_start(ap, fmt);
msg = towire_abortfmtv(ctx, channel, fmt, ap);
va_end(ap);

return msg;
}

bool channel_id_is_all(const struct channel_id *channel_id)
{
return memeqzero(channel_id, sizeof(*channel_id));
Expand Down
Loading
Loading