splice: track funding_tx_index on inflights and channel funding
What changed, and why it matters
This commit adds a stable counter, called funding_tx_index, that tracks whether a Lightning channel is on its original funding transaction (index 0) or on a later splice (index 1, 2, etc.). It stores the index in memory, passes it between daemon processes, and saves it in the wallet database. The change is a correctness fix for how Core Lightning handles reconnections and retransmissions after a splice, but the commit itself is a feature/infrastructure patch rather than a direct fix for an active exploit.
Treat as a correctness improvement with latent security relevance for splice handling. Review whether any remaining code paths still identify a channel solely by funding txid instead of the (channel_id, funding_tx_index) pair, especially around reconnection, watchtower/penalty logic, and database lookups. No immediate emergency patch is indicated, but operators using splicing should upgrade to avoid reconnection edge cases.
Security signals we found
Adds persistent funding_tx_index to distinguish original funding from splice funding after channel funding txid changes
Removes xfail markers on splice reconnection tests, implying prior incorrect behavior on reestablish after splice lock
Updates database migrations to backfill index=1 for pending splice inflights across upgrade
Touches wire protocol messages (channeld_init, channeld_add_inflight) to propagate the new field
Evidence from the diff
The patch threads a new u32 funding_tx_index through channel lifecycle structures: struct channel, struct channel_inflight, channeld_init and channeld_add_inflight wire messages, and the channels / channel_funding_inflights database tables. Original funding and RBF attempts use index 0; each splice increments by 1. A migration sets existing splice inflights to index 1. Tests are updated to remove xfail markers for splice reconnect and funding_tx_index tests, indicating the change resolves previously known incorrect behavior around channel_ready retransmission after a splice.
Changed components
channeld/channeld.cchanneld/full_channel.c / .hchanneld/inflight.c / .hcommon/initial_channel.c / .hlightningd/channel.c / .hlightningd/channel_control.clightningd/dual_open_control.clightningd/opening_control.clightningd/peer_control.copeningd/dualopend.copeningd/openingd.cwallet/wallet.cwallet/migrations.cchanneld/channeld_wire.csvInspect captured patch +113 / −15
### channeld/channeld.c
@@ -514,6 +514,7 @@ static void check_mutual_splice_locked(struct peer *peer)
fmt_channel(tmpctx, peer->channel));
error = channel_update_funding(peer->channel, &inflight->outpoint,
+ inflight->funding_tx_index,
inflight->amnt,
inflight->splice_amnt);
if (error)
@@ -4533,6 +4534,7 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
&peer->splicing->remote_funding_pubkey,
&outpoint.txid,
outpoint.n,
+ peer->channel->funding_tx_index + 1,
funding_feerate_perkw,
both_amount,
peer->splicing->accepter_relative,
@@ -4550,6 +4552,8 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
&new_inflight->outpoint.txid, NULL);
new_inflight->remote_funding = peer->splicing->remote_funding_pubkey;
new_inflight->outpoint = outpoint;
+ /* A splice's funding tx is the parent funding's index + 1. */
+ new_inflight->funding_tx_index = peer->channel->funding_tx_index + 1;
new_inflight->amnt = both_amount;
new_inflight->psbt = clone_psbt(new_inflight, ictx->current_psbt);
new_inflight->splice_amnt = peer->splicing->accepter_relative;
@@ -4832,6 +4836,7 @@ static void splice_initiator_user_finalized(struct peer *peer)
&peer->splicing->remote_funding_pubkey,
¤t_psbt_txid,
chan_output_index,
+ peer->channel->funding_tx_index + 1,
peer->splicing->feerate_per_kw,
amount_sat(new_chan_output->amount),
peer->splicing->opener_relative,
@@ -4849,6 +4854,8 @@ static void splice_initiator_user_finalized(struct peer *peer)
NULL);
new_inflight->remote_funding = peer->splicing->remote_funding_pubkey;
new_inflight->outpoint.n = chan_output_index;
+ /* A splice's funding tx is the parent funding's index + 1. */
+ new_inflight->funding_tx_index = peer->channel->funding_tx_index + 1;
new_inflight->amnt = amount_sat(new_chan_output->amount);
new_inflight->splice_amnt = peer->splicing->opener_relative;
new_inflight->last_tx = NULL;
@@ -7073,6 +7080,7 @@ static void init_channel(struct peer *peer)
{
struct basepoints points[NUM_SIDES];
struct amount_sat funding_sats;
+ u32 funding_tx_index;
struct amount_msat local_msat;
struct pubkey funding_pubkey[NUM_SIDES];
struct channel_config conf[NUM_SIDES];
@@ -7102,6 +7110,7 @@ static void init_channel(struct peer *peer)
&peer->channel_id,
&funding,
&funding_sats,
+ &funding_tx_index,
&minimum_depth,
&peer->our_blockheight,
&blockheight_states,
@@ -7219,6 +7228,7 @@ static void init_channel(struct peer *peer)
peer->channel = new_full_channel(peer, &peer->channel_id,
&funding,
+ funding_tx_index,
minimum_depth,
take(blockheight_states),
lease_expiry,
### channeld/channeld_wire.csv
@@ -21,6 +21,7 @@ msgdata,channeld_init,hsm_capabilities,u32,num_hsm_capabilities
msgdata,channeld_init,channel_id,channel_id,
msgdata,channeld_init,funding,bitcoin_outpoint,
msgdata,channeld_init,funding_satoshi,amount_sat,
+msgdata,channeld_init,funding_tx_index,u32,
msgdata,channeld_init,minimum_depth,u32,
msgdata,channeld_init,our_blockheight,u32,
msgdata,channeld_init,blockheight_states,height_states,
@@ -270,6 +271,7 @@ 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,funding_tx_index,u32,
msgdata,channeld_add_inflight,feerate,u32,
msgdata,channeld_add_inflight,satoshis,amount_sat,
msgdata,channeld_add_inflight,splice_amount,s64,
### channeld/full_channel.c
@@ -74,6 +74,7 @@ static bool balance_ok(const struct balance *balance,
struct channel *new_full_channel(const tal_t *ctx,
const struct channel_id *cid,
const struct bitcoin_outpoint *funding,
+ u32 funding_tx_index,
u32 minimum_depth,
const struct height_states *blockheight_states,
u32 lease_expiry,
@@ -93,6 +94,7 @@ struct channel *new_full_channel(const tal_t *ctx,
struct channel *channel = new_initial_channel(ctx,
cid,
funding,
+ funding_tx_index,
minimum_depth,
blockheight_states,
lease_expiry,
### channeld/full_channel.h
@@ -36,6 +36,7 @@ struct existing_htlc;
struct channel *new_full_channel(const tal_t *ctx,
const struct channel_id *cid,
const struct bitcoin_outpoint *funding,
+ u32 funding_tx_index,
u32 minimum_depth,
const struct height_states *blockheight_states,
u32 lease_expiry,
### channeld/inflight.c
@@ -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);
+ inflight->funding_tx_index = fromwire_u32(cursor, max);
fromwire_pubkey(cursor, max, &inflight->remote_funding);
inflight->amnt = fromwire_amount_sat(cursor, max);
inflight->remote_tx_sigs = fromwire_bool(cursor, max);
@@ -41,6 +42,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_u32(pptr, inflight->funding_tx_index);
towire_pubkey(pptr, &inflight->remote_funding);
towire_amount_sat(pptr, inflight->amnt);
towire_bool(pptr, inflight->remote_tx_sigs);
### channeld/inflight.h
@@ -10,6 +10,9 @@
struct inflight {
/* The new channel outpoint */
struct bitcoin_outpoint outpoint;
+ /* Which funding tx this is: 0 for the original funding (incl. RBF
+ * attempts), incrementing by 1 for each splice. */
+ u32 funding_tx_index;
struct pubkey remote_funding;
struct amount_sat amnt;
bool remote_tx_sigs;
### channeld/test/run-full_channel.c
@@ -517,7 +517,7 @@ int main(int argc, const char *argv[])
feerate_per_kw[LOCAL] = feerate_per_kw[REMOTE] = 15000;
derive_channel_id(&cid, &funding);
lchannel = new_full_channel(tmpctx, &cid,
- &funding, 0,
+ &funding, 0, 0,
take(new_height_states(NULL, LOCAL, &blockheight)),
0, /* No channel lease */
funding_amount, to_local,
@@ -530,7 +530,7 @@ int main(int argc, const char *argv[])
&remote_funding_pubkey,
take(channel_type_static_remotekey(NULL)), false, LOCAL);
rchannel = new_full_channel(tmpctx, &cid,
- &funding, 0,
+ &funding, 0, 0,
take(new_height_states(NULL, REMOTE, &blockheight)),
0, /* No channel lease */
funding_amount, to_remote,
@@ -749,8 +749,8 @@ int main(int argc, const char *argv[])
= (struct amount_sat){lchannel->funding_sats.satoshis + splice_amnt};
const char *err;
- err = channel_update_funding(lchannel, &funding, new_funding_sats,
- splice_amnt);
+ err = channel_update_funding(lchannel, &funding, 1,
+ new_funding_sats, splice_amnt);
assert(err != NULL);
assert(amount_msat_eq(lchannel->view[LOCAL].owed[LOCAL], local_before));
}
### common/initial_channel.c
@@ -12,6 +12,7 @@
struct channel *new_initial_channel(const tal_t *ctx,
const struct channel_id *cid,
const struct bitcoin_outpoint *funding,
+ u32 funding_tx_index,
u32 minimum_depth,
const struct height_states *height_states TAKES,
u32 lease_expiry,
@@ -46,6 +47,7 @@ struct channel *new_initial_channel(const tal_t *ctx,
channel->cid = *cid;
channel->funding = *funding;
+ channel->funding_tx_index = funding_tx_index;
channel->funding_sats = funding_sats;
channel->minimum_depth = minimum_depth;
channel->lease_expiry = lease_expiry;
@@ -156,6 +158,7 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
const char *channel_update_funding(struct channel *channel,
const struct bitcoin_outpoint *funding,
+ u32 funding_tx_index,
struct amount_sat funding_sats,
s64 splice_amnt)
{
@@ -164,6 +167,7 @@ const char *channel_update_funding(struct channel *channel,
channel->funding = *funding;
channel->funding_sats = funding_sats;
+ channel->funding_tx_index = funding_tx_index;
if (splice_amnt * 1000 + (s64)channel->view[LOCAL].owed[LOCAL].millisatoshis < 0) /* Raw: splicing */
return tal_fmt(tmpctx, "Channel funding update would make local"
### common/initial_channel.h
@@ -39,6 +39,10 @@ struct channel {
/* Funding txid and output. */
struct bitcoin_outpoint funding;
+ /* Which funding tx this is: 0 for the original funding (incl. RBF
+ * attempts), incrementing by 1 for each splice. */
+ u32 funding_tx_index;
+
/* Keys used to spend funding tx. */
struct pubkey funding_pubkey[NUM_SIDES];
@@ -88,6 +92,7 @@ struct channel {
* @ctx: tal context to allocate return value from.
* @cid: The channel's id.
* @funding: The commitment transaction id/outnum
+ * @funding_tx_index: 0 for the original funding, +1 for each splice.
* @minimum_depth: The minimum confirmations needed for funding transaction.
* @height_states: The blockheight update states.
* @lease_expiry: Block the lease expires.
@@ -109,6 +114,7 @@ struct channel {
struct channel *new_initial_channel(const tal_t *ctx,
const struct channel_id *cid,
const struct bitcoin_outpoint *funding,
+ u32 funding_tx_index,
u32 minimum_depth,
const struct height_states *height_states TAKES,
u32 lease_expiry,
@@ -154,6 +160,7 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
*/
const char *channel_update_funding(struct channel *channel,
const struct bitcoin_outpoint *funding,
+ u32 funding_tx_index,
struct amount_sat funding_sats,
s64 splice_amnt);
### devtools/mkcommit.c
@@ -399,7 +399,7 @@ int main(int argc, char *argv[])
channel = new_full_channel(NULL,
&cid,
- &funding, 1,
+ &funding, 0, 1,
take(new_height_states(NULL, fee_payer,
&blockheight)),
0, /* Defaults to no lease */
### lightningd/channel.c
@@ -177,6 +177,7 @@ struct channel_inflight *
new_inflight(struct channel *channel,
struct pubkey *remote_funding,
const struct bitcoin_outpoint *funding_outpoint,
+ u32 funding_tx_index,
u32 funding_feerate,
struct amount_sat total_funds,
struct amount_sat our_funds,
@@ -205,6 +206,7 @@ new_inflight(struct channel *channel,
funding->splice_remote_funding = tal_steal(funding, remote_funding);
inflight->funding = funding;
+ inflight->funding_tx_index = funding_tx_index;
inflight->channel = channel;
inflight->remote_tx_sigs = false;
inflight->funding_psbt = tal_steal(inflight, psbt);
@@ -384,6 +386,10 @@ struct channel *new_unsaved_channel(struct peer *peer,
channel->next_their_htlc_id = 0;
channel->funding_spend_watch = NULL;
channel->inflight_spend_watches = NULL;
+ /* Original funding: splices increment this. channel->funding itself
+ * isn't known until commit, but we save the channel then, so this
+ * must be set now. */
+ channel->funding_tx_index = 0;
/* FIXME: remove push when v1 deprecated */
channel->push = AMOUNT_MSAT(0);
channel->closing_fee_negotiation_step = 50;
@@ -514,6 +520,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
u64 next_index_remote,
u64 next_htlc_id,
const struct bitcoin_outpoint *funding,
+ u32 funding_tx_index,
struct amount_sat funding_sats,
struct amount_msat push,
struct amount_sat our_funds,
@@ -622,6 +629,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
/* Set by wallet_htlcs_load_in_for_channel */
channel->next_their_htlc_id = 0;
channel->funding = *funding;
+ channel->funding_tx_index = funding_tx_index;
channel->funding_sats = funding_sats;
channel->funding_spend_watch = NULL;
channel->inflight_spend_watches = NULL;
@@ -1411,4 +1419,3 @@ const u8 *channel_update_for_error(const tal_t *ctx,
return channel_gossip_update_for_error(ctx, channel);
}
-
### lightningd/channel.h
@@ -58,6 +58,9 @@ struct channel_inflight {
/* Funding info */
const struct funding_info *funding;
+ /* Which funding tx this is: 0 for the original funding (incl. RBF
+ * attempts), incrementing by 1 for each splice. */
+ u32 funding_tx_index;
struct wally_psbt *funding_psbt;
bool remote_tx_sigs;
bool tx_broadcast;
@@ -205,6 +208,9 @@ struct channel {
/* Funding outpoint and amount */
struct bitcoin_outpoint funding;
+ /* Which funding tx this is: 0 for the original funding (incl. RBF
+ * attempts), incrementing by 1 for each splice. */
+ u32 funding_tx_index;
struct amount_sat funding_sats;
/* Watch we have on funding output. */
@@ -399,6 +405,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
u64 next_index_remote,
u64 next_htlc_id,
const struct bitcoin_outpoint *funding,
+ u32 funding_tx_index,
struct amount_sat funding_sats,
struct amount_msat push,
struct amount_sat our_funds,
@@ -463,6 +470,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
struct channel_inflight *new_inflight(struct channel *channel,
struct pubkey *remote_funding STEALS,
const struct bitcoin_outpoint *funding_outpoint,
+ u32 funding_tx_index,
u32 funding_feerate,
struct amount_sat funding_sat,
struct amount_sat our_funds,
### lightningd/channel_control.c
@@ -907,6 +907,7 @@ static void handle_add_inflight(struct lightningd *ld,
{
struct pubkey *remote_funding = tal(tmpctx, struct pubkey);
struct bitcoin_outpoint outpoint;
+ u32 funding_tx_index;
u32 feerate;
struct amount_sat satoshis;
s64 splice_amnt;
@@ -919,6 +920,7 @@ static void handle_add_inflight(struct lightningd *ld,
remote_funding,
&outpoint.txid,
&outpoint.n,
+ &funding_tx_index,
&feerate,
&satoshis,
&splice_amnt,
@@ -959,6 +961,7 @@ static void handle_add_inflight(struct lightningd *ld,
inflight = new_inflight(channel,
remote_funding,
&outpoint,
+ funding_tx_index,
feerate,
satoshis,
channel->our_funds,
@@ -1952,6 +1955,7 @@ bool peer_start_channeld(struct channel *channel,
infcopy->remote_funding = *inflight->funding->splice_remote_funding;
infcopy->outpoint = inflight->funding->outpoint;
+ infcopy->funding_tx_index = inflight->funding_tx_index;
infcopy->amnt = inflight->funding->total_funds;
infcopy->remote_tx_sigs = inflight->remote_tx_sigs;
infcopy->splice_amnt = inflight->funding->splice_amnt;
@@ -1979,6 +1983,7 @@ bool peer_start_channeld(struct channel *channel,
&channel->cid,
&channel->funding,
channel->funding_sats,
+ channel->funding_tx_index,
channel->minimum_depth,
curr_blockheight,
channel->blockheight_states,
### lightningd/dual_open_control.c
@@ -1390,6 +1390,7 @@ wallet_update_channel(struct lightningd *ld,
inflight = new_inflight(channel,
NULL,
&channel->funding,
+ 0,
funding_feerate,
channel->funding_sats,
channel->our_funds,
@@ -1456,6 +1457,7 @@ wallet_add_inflight_attempt(struct lightningd *ld,
inflight = new_inflight(channel,
NULL,
funding,
+ 0,
funding_feerate,
total_funding,
our_funding,
@@ -1697,6 +1699,7 @@ wallet_commit_channel(struct lightningd *ld,
inflight = new_inflight(channel,
NULL,
&channel->funding,
+ 0,
funding_feerate,
channel->funding_sats,
channel->our_funds,
### lightningd/opening_control.c
@@ -182,6 +182,7 @@ wallet_commit_channel(struct lightningd *ld,
uc->minimum_depth,
1, 1, 0,
funding,
+ 0,
funding_sats,
push,
local_funding,
@@ -1632,6 +1633,7 @@ static struct channel *stub_chan(struct command *cmd,
0,
1, 1, 1,
&funding,
+ 0,
funding_sats,
AMOUNT_MSAT(0),
AMOUNT_SAT(0),
### lightningd/peer_control.c
@@ -2503,6 +2503,7 @@ void update_channel_from_inflight(struct lightningd *ld,
bool is_splice)
{
channel->funding = inflight->funding->outpoint;
+ channel->funding_tx_index = inflight->funding_tx_index;
channel->funding_sats = inflight->funding->total_funds;
channel->our_funds = inflight->funding->our_funds;
### openingd/dualopend.c
@@ -2261,6 +2261,7 @@ static void revert_channel_state(struct state *state)
state->channel = new_initial_channel(state,
&state->channel_id,
&tx_state->funding,
+ 0,
state->minimum_depth,
take(new_height_states(NULL, opener,
&tx_state->blockheight)),
@@ -2335,6 +2336,7 @@ static u8 *accepter_commits(struct state *state,
state->channel = new_initial_channel(state,
&state->channel_id,
&tx_state->funding,
+ 0,
state->minimum_depth,
take(new_height_states(NULL, REMOTE,
&tx_state->blockheight)),
@@ -3003,6 +3005,7 @@ static u8 *opener_commits(struct state *state,
state->channel = new_initial_channel(state,
&state->channel_id,
&tx_state->funding,
+ 0,
state->minimum_depth,
take(new_height_states(NULL, LOCAL,
&state->tx_state->blockheight)),
@@ -4611,6 +4614,7 @@ int main(int argc, char *argv[])
state->channel = new_initial_channel(state,
&state->channel_id,
&state->tx_state->funding,
+ 0,
state->minimum_depth,
take(new_height_states(NULL, opener,
&state->tx_state->blockheight)),
### openingd/openingd.c
@@ -588,6 +588,7 @@ static bool funder_finalize_channel_setup(struct state *state,
state->channel = new_initial_channel(state,
&cid,
&state->funding,
+ 0,
state->minimum_depth,
NULL, 0, /* No channel lease */
state->funding_sats,
@@ -1153,6 +1154,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
state->channel = new_initial_channel(state,
&state->channel_id,
&state->funding,
+ 0,
state->minimum_depth,
NULL, 0, /* No channel lease */
state->funding_sats,
### tests/fuzz/fuzz-full_channel.c
@@ -208,15 +208,15 @@ static void init_channels(const tal_t *ctx, const u8 **cursor, size_t *max,
derive_channel_id(&cid, funding);
- *lchannel = new_full_channel(ctx, &cid, funding, 0,
+ *lchannel = new_full_channel(ctx, &cid, funding, 0, 0,
take(new_height_states(NULL, LOCAL, blockheight)),
0, *funding_amount, to_local,
take(new_fee_states(NULL, LOCAL, &feerate_per_kw[LOCAL])),
local_config, remote_config,
&localbase, &remotebase,
&local_funding_pubkey, &remote_funding_pubkey,
take(channel_type_static_remotekey(NULL)), false, LOCAL);
- *rchannel = new_full_channel(ctx, &cid, funding, 0,
+ *rchannel = new_full_channel(ctx, &cid, funding, 0, 0,
take(new_height_states(NULL, REMOTE, blockheight)),
0, *funding_amount, to_remote,
take(new_fee_states(NULL, REMOTE, &feerate_per_kw[REMOTE])),
### tests/fuzz/fuzz-initial_channel.c
@@ -46,7 +46,7 @@ static void test_channel_update_funding(struct channel *channel, const u8 **curs
funding_sats.satoshis %= MAX_SATS; /* Raw: fuzzing */
splice_amnt = fromwire_s64(cursor, max) % MAX_SATS;
- channel_update_funding(channel, &funding, funding_sats, splice_amnt);
+ channel_update_funding(channel, &funding, 0, funding_sats, splice_amnt);
}
void run(const uint8_t *data, size_t size)
@@ -98,6 +98,7 @@ void run(const uint8_t *data, size_t size)
for (enum side opener = 0; opener < NUM_SIDES; opener++) {
channel = new_initial_channel(tmpctx, &cid, &funding,
+ 0,
minimum_depth,
take(new_height_states(NULL, opener,
&blockheight)),
### tests/plugins/channeld_fakenet.c
@@ -1073,6 +1073,7 @@ static struct channel *handle_init(struct info *info, const u8 *init_msg)
struct ext_key final_ext_key;
u8 *fwd_msg;
u32 minimum_depth, lease_expiry;
+ u32 funding_tx_index;
struct secret last_remote_per_commit_secret;
struct penalty_base *pbases;
struct channel_type *channel_type;
@@ -1112,6 +1113,7 @@ static struct channel *handle_init(struct info *info, const u8 *init_msg)
&channel_id,
&funding,
&funding_sats,
+ &funding_tx_index,
&minimum_depth,
&info->current_block_height,
&info->blockheight_states,
@@ -1167,6 +1169,7 @@ static struct channel *handle_init(struct info *info, const u8 *init_msg)
status_debug("Parsed init...");
channel = new_full_channel(info, &channel_id,
&funding,
+ funding_tx_index,
minimum_depth,
info->blockheight_states,
lease_expiry,
### tests/test_splicing.py
@@ -105,6 +105,8 @@ def test_splice_stored_feerate_repaired_on_upgrade(node_factory, bitcoind,
# Every migration after the clamps runs again too, so undo the ones that
# cannot simply be repeated. Add to this as migrations are appended.
l1.db_manip("ALTER TABLE forwards DROP COLUMN reason")
+ l1.db_manip("ALTER TABLE channel_funding_inflights DROP COLUMN funding_tx_index")
+ l1.db_manip("ALTER TABLE channels DROP COLUMN funding_tx_index")
l1.daemon.opts['database-upgrade'] = 'true'
l1.start()
### tests/test_splicing_disconnect.py
@@ -80,7 +80,7 @@ def test_splice_disconnect_sig(node_factory, bitcoind):
@pytest.mark.openchannel('v1')
@pytest.mark.openchannel('v2')
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
-@pytest.mark.xfail(strict=True, reason="funding_tx_index tracking not yet implemented")
+@pytest.mark.xfail(strict=True, reason="channel_ready wrongly retransmitted after splice until funding_tx_index detection")
def test_splice_reconnect_after_lock_no_channel_ready(node_factory, bitcoind):
# Once a splice locks, channel funding txid is updated to the splice txid.
# On reconnect we must still recognise the peer's `my_current_funding_locked`
@@ -183,7 +183,6 @@ def test_splice_disconnect_commit(node_factory, bitcoind, executor):
@pytest.mark.openchannel('v1')
@pytest.mark.openchannel('v2')
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
-@pytest.mark.xfail(strict=True, reason="funding_tx_index tracking not yet implemented")
def test_splice_funding_tx_index_increments(node_factory, bitcoind):
# funding_tx_index is 0 for the original funding and increments by 1 per
# splice. Two sequential splices must reach index 2 on the persisted
@@ -218,7 +217,6 @@ def channel_funding_tx_index():
@pytest.mark.openchannel('v1')
@pytest.mark.openchannel('v2')
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
-@pytest.mark.xfail(strict=True, reason="funding_tx_index tracking not yet implemented")
def test_splice_inflight_funding_tx_index(node_factory, bitcoind):
# A pending (not-yet-locked) splice inflight carries funding_tx_index == 1
# (the open was index 0), and the value must survive a restart so the
### wallet/migrations.c
@@ -1224,6 +1224,22 @@ static const struct db_migration dbmigrations[] = {
{SQL("ALTER TABLE forwards ADD reason INTEGER DEFAULT NULL"), NULL,
SQL("ALTER TABLE forwards DROP COLUMN reason"), NULL},
+ /* Which funding tx this is: 0 for the original funding, incrementing
+ * by 1 for each splice. Lets us tell a splice from the original
+ * funding on reestablish, once the channel funding txid has moved. */
+ {SQL("ALTER TABLE channel_funding_inflights ADD funding_tx_index INTEGER DEFAULT 0"), NULL,
+ SQL("ALTER TABLE channel_funding_inflights DROP COLUMN funding_tx_index"), NULL},
+ {SQL("ALTER TABLE channels ADD funding_tx_index INTEGER DEFAULT 0"), NULL,
+ SQL("ALTER TABLE channels DROP COLUMN funding_tx_index"), NULL},
+ /* A splice pending across the upgrade must not look like the original
+ * funding. Only splice inflights record remote_funding, and they are
+ * one splice past the channel funding, which is 0 for everyone here.
+ * Channels which spliced before this have no record of it, so they
+ * stay 0. */
+ {SQL("UPDATE channel_funding_inflights SET funding_tx_index = 1"
+ " WHERE remote_funding IS NOT NULL;"), NULL,
+ /* The revert drops the column */
+ NULL, NULL},
};
const struct db_migration *get_db_migrations(size_t *num)
### wallet/test/run-chain_moves_duplicate-detect.c
@@ -189,6 +189,7 @@ struct channel *new_channel(struct peer *peer UNNEEDED, u64 dbid UNNEEDED,
u64 next_index_remote UNNEEDED,
u64 next_htlc_id UNNEEDED,
const struct bitcoin_outpoint *funding UNNEEDED,
+ u32 funding_tx_index UNNEEDED,
struct amount_sat funding_sats UNNEEDED,
struct amount_msat push UNNEEDED,
struct amount_sat our_funds UNNEEDED,
@@ -261,6 +262,7 @@ struct channel_state_change *new_channel_state_change(const tal_t *ctx UNNEEDED,
struct channel_inflight *new_inflight(struct channel *channel UNNEEDED,
struct pubkey *remote_funding STEALS UNNEEDED,
const struct bitcoin_outpoint *funding_outpoint UNNEEDED,
+ u32 funding_tx_index UNNEEDED,
u32 funding_feerate UNNEEDED,
struct amount_sat funding_sat UNNEEDED,
struct amount_sat our_funds UNNEEDED,
### wallet/test/run-db.c
@@ -197,6 +197,7 @@ struct channel *new_channel(struct peer *peer UNNEEDED, u64 dbid UNNEEDED,
u64 next_index_remote UNNEEDED,
u64 next_htlc_id UNNEEDED,
const struct bitcoin_outpoint *funding UNNEEDED,
+ u32 funding_tx_index UNNEEDED,
struct amount_sat funding_sats UNNEEDED,
struct amount_msat push UNNEEDED,
struct amount_sat our_funds UNNEEDED,
@@ -269,6 +270,7 @@ struct channel_state_change *new_channel_state_change(const tal_t *ctx UNNEEDED,
struct channel_inflight *new_inflight(struct channel *channel UNNEEDED,
struct pubkey *remote_funding STEALS UNNEEDED,
const struct bitcoin_outpoint *funding_outpoint UNNEEDED,
+ u32 funding_tx_index UNNEEDED,
u32 funding_feerate UNNEEDED,
struct amount_sat funding_sat UNNEEDED,
struct amount_sat our_funds UNNEEDED,
### wallet/test/run-migrate_remove_chain_moves_duplicates.c
@@ -230,6 +230,7 @@ struct channel *new_channel(struct peer *peer UNNEEDED, u64 dbid UNNEEDED,
u64 next_index_remote UNNEEDED,
u64 next_htlc_id UNNEEDED,
const struct bitcoin_outpoint *funding UNNEEDED,
+ u32 funding_tx_index UNNEEDED,
struct amount_sat funding_sats UNNEEDED,
struct amount_msat push UNNEEDED,
struct amount_sat our_funds UNNEEDED,
@@ -302,6 +303,7 @@ struct channel_state_change *new_channel_state_change(const tal_t *ctx UNNEEDED,
struct channel_inflight *new_inflight(struct channel *channel UNNEEDED,
struct pubkey *remote_funding STEALS UNNEEDED,
const struct bitcoin_outpoint *funding_outpoint UNNEEDED,
+ u32 funding_tx_index UNNEEDED,
u32 funding_feerate UNNEEDED,
struct amount_sat funding_sat UNNEEDED,
struct amount_sat our_funds UNNEEDED,
### wallet/test/run-wallet.c
@@ -1759,6 +1759,7 @@ static bool test_channel_inflight_crud(struct lightningd *ld, const tal_t *ctx,
8, false, false, &our_config,
101, 1, 1, 1,
&outpoint,
+ 0,
funding_sats, AMOUNT_MSAT(0),
our_sats,
0, NULL,
@@ -1810,7 +1811,7 @@ static bool test_channel_inflight_crud(struct lightningd *ld, const tal_t *ctx,
memset(&outpoint, 1, sizeof(outpoint));
mempat(&sig.s, sizeof(sig.s));
- inflight = new_inflight(chan, NULL, &outpoint, 253,
+ inflight = new_inflight(chan, NULL, &outpoint, 0, 253,
funding_sats,
our_sats,
funding_psbt,
@@ -1846,7 +1847,7 @@ static bool test_channel_inflight_crud(struct lightningd *ld, const tal_t *ctx,
our_sats = AMOUNT_SAT(555555);
memset(&outpoint, 2, sizeof(outpoint));
mempat(&sig.s, sizeof(sig.s));
- inflight = new_inflight(chan, NULL, &outpoint, 300,
+ inflight = new_inflight(chan, NULL, &outpoint, 0, 300,
funding_sats,
our_sats,
funding_psbt,
### wallet/wallet.c
@@ -1495,6 +1495,7 @@ void wallet_inflight_add(struct wallet *w, struct channel_inflight *inflight)
" channel_id"
", funding_tx_id"
", funding_tx_outnum"
+ ", funding_tx_index"
", funding_feerate"
", funding_satoshi"
", our_funding_satoshi"
@@ -1516,11 +1517,12 @@ void wallet_inflight_add(struct wallet *w, struct channel_inflight *inflight)
", locked_scid"
", i_sent_sigs"
") VALUES ("
- "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"));
+ "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"));
db_bind_u64(stmt, inflight->channel->dbid);
db_bind_txid(stmt, &inflight->funding->outpoint.txid);
db_bind_int(stmt, inflight->funding->outpoint.n);
+ db_bind_int(stmt, inflight->funding_tx_index);
db_bind_int(stmt, inflight->funding->feerate);
db_bind_amount_sat(stmt, inflight->funding->total_funds);
db_bind_amount_sat(stmt, inflight->funding->our_funds);
@@ -1716,6 +1718,7 @@ wallet_stmt2inflight(struct wallet *w, struct db_stmt *stmt,
i_sent_sigs = db_col_int(stmt, "i_sent_sigs");
inflight = new_inflight(chan, remote_funding, &funding,
+ db_col_int(stmt, "funding_tx_index"),
db_col_int(stmt, "funding_feerate"),
funding_sat,
our_funding_sat,
@@ -1767,6 +1770,7 @@ static bool wallet_channel_load_inflights(struct wallet *w,
stmt = db_prepare_v2(w->db, SQL("SELECT"
" funding_tx_id"
", funding_tx_outnum"
+ ", funding_tx_index"
", funding_feerate"
", funding_satoshi"
", our_funding_satoshi"
@@ -2134,6 +2138,7 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm
db_col_u64(stmt, "next_index_remote"),
db_col_u64(stmt, "next_htlc_id"),
&funding,
+ db_col_int(stmt, "funding_tx_index"),
funding_sat,
push_msat,
our_funding_sat,
@@ -2381,6 +2386,7 @@ static bool wallet_channels_load_active(struct wallet *w)
", next_htlc_id"
", funding_tx_id"
", funding_tx_outnum"
+ ", funding_tx_index"
", funding_satoshi"
", our_funding_satoshi"
", funding_locked_remote"
@@ -2687,6 +2693,7 @@ void wallet_channel_save(struct wallet *w, struct channel *chan)
" next_htlc_id=?,"
" funding_tx_id=?,"
" funding_tx_outnum=?,"
+ " funding_tx_index=?,"
" funding_satoshi=?,"
" our_funding_satoshi=?,"
" funding_locked_remote=?,"
@@ -2752,6 +2759,7 @@ void wallet_channel_save(struct wallet *w, struct channel *chan)
db_bind_sha256d(stmt, &chan->funding.txid.shad);
db_bind_int(stmt, chan->funding.n);
+ db_bind_int(stmt, chan->funding_tx_index);
db_bind_amount_sat(stmt, chan->funding_sats);
db_bind_amount_sat(stmt, chan->our_funds);
db_bind_int(stmt, chan->remote_channel_ready);Why this scored 33/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.