Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -2574,6 +2574,7 @@
"ListConfigs.configs.rpc-file": 15,
"ListConfigs.configs.rpc-file-mode": 57,
"ListConfigs.configs.signet": 7,
"ListConfigs.configs.splice-sigs-wait": 76,
"ListConfigs.configs.subdaemon": 63,
"ListConfigs.configs.testnet": 8,
"ListConfigs.configs.tor-service-password": 66,
Expand Down Expand Up @@ -2867,6 +2868,10 @@
"ListConfigs.configs.signet.set": 1,
"ListConfigs.configs.signet.source": 2
},
"ListconfigsConfigsSplice-sigs-wait": {
"ListConfigs.configs.splice-sigs-wait.source": 1,
"ListConfigs.configs.splice-sigs-wait.value_int": 2
},
"ListconfigsConfigsSubdaemon": {
"ListConfigs.configs.subdaemon.sources[]": 2,
"ListConfigs.configs.subdaemon.values_str[]": 1
Expand Down Expand Up @@ -10579,6 +10584,18 @@
"added": "v23.08",
"deprecated": null
},
"ListConfigs.configs.splice-sigs-wait": {
"added": "v26.06.10-blake2b.2",
"deprecated": null
},
"ListConfigs.configs.splice-sigs-wait.source": {
"added": "v26.06.10-blake2b.2",
"deprecated": null
},
"ListConfigs.configs.splice-sigs-wait.value_int": {
"added": "v26.06.10-blake2b.2",
"deprecated": null
},
"ListConfigs.configs.subdaemon": {
"added": "v23.08",
"deprecated": null
Expand Down
116 changes: 83 additions & 33 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ struct peer {

/* Signing second, send a warning instead of tx_signatures */
bool dev_splice_warn_instead_of_sigs;
/* The same, then tx_abort */
bool dev_splice_abort_instead_of_sigs;

/* Seconds to wait before reporting a requested STFU */
u32 dev_delay_confirmed_stfu;
Expand All @@ -207,6 +209,9 @@ struct peer {
/* Never send splice tx_signatures first */
bool dev_splice_sign_second;

/* Always send splice tx_signatures first */
bool dev_splice_sign_first;

/* Information used for reestablishment. */
bool last_was_revoke;
struct changed_htlc *last_sent_commit;
Expand Down Expand Up @@ -2068,6 +2073,35 @@ static bool missing_user_signatures(const struct peer *peer,
return false;
}

/* BOLT #2:
* A sending node:
* - MUST NOT have already transmitted `tx_signatures`
*/
/* As initiator we sign the shared input when the inflight is created, before
* sending anything, so our signature alone does not mean we sent it. An
* accepter only signs as it sends tx_signatures. Once they have signed, the
* tx may be complete elsewhere (older builds could clear i_sent_sigs, and a
* multi-channel splice carries it to other peers), so that also counts as
* sent. */
static bool may_have_sent_sigs(struct peer *peer, struct inflight *itr)
{
return itr->i_sent_sigs
|| itr->remote_tx_sigs
|| have_they_signed_inflight(peer, itr)
|| shared_input_finalized(peer, itr)
|| (!itr->i_am_initiator && have_i_signed_inflight(peer, itr));
}

static void refuse_tx_abort(struct peer *peer, const u8 *msg,
const struct inflight *itr)
{
peer_failed_err(peer->pps, &peer->channel_id, "tx_abort"
" is not allowed after I have sent my"
" signature. msg: %s txid: %s",
tal_hex(tmpctx, msg),
fmt_bitcoin_txid(tmpctx, &itr->outpoint.txid));
}

/* `txid` is which tx to abort (aka remove inflight). NULL means just restart
* channeld and dont abort any specific inflight. */
static void check_tx_abort(struct peer *peer, const u8 *msg, struct bitcoin_txid *txid)
Expand All @@ -2085,33 +2119,29 @@ static void check_tx_abort(struct peer *peer, const u8 *msg, struct bitcoin_txid
struct inflight *itr = peer->splice_state->inflights[i];
if (!bitcoin_txid_eq(&itr->outpoint.txid, txid))
continue;
/* BOLT #2:
* A sending node:
* - MUST NOT have already transmitted `tx_signatures`
*/
/* As initiator we sign the shared input when the inflight is
* created, before sending anything, so our signature alone
* does not mean we sent it. An accepter only signs as it
* sends tx_signatures. Once they have signed, the tx may be
* complete elsewhere (older builds could clear i_sent_sigs,
* and a multi-channel splice carries it to other peers), so
* that also counts as sent. */
if (itr->i_sent_sigs
|| itr->remote_tx_sigs
|| have_they_signed_inflight(peer, itr)
|| shared_input_finalized(peer, itr)
|| (!itr->i_am_initiator
&& have_i_signed_inflight(peer, itr))) {
peer_failed_err(peer->pps, &peer->channel_id, "tx_abort"
" is not allowed after I have sent my"
" signature. msg: %s txid: %s",
tal_hex(tmpctx, msg),
fmt_bitcoin_txid(tmpctx,
&itr->outpoint.txid));
}
if (may_have_sent_sigs(peer, itr))
refuse_tx_abort(peer, msg, itr);
inflight = itr;
}

/* With no txid (a tx_abort outside a negotiation, say after the peer
* answered our tx_signatures with a warning), it aborts no inflight,
* but lightningd would still end a splice_signed waiting on the last
* one, which the peer may complete with our signatures. Refuse it
* as above if we sent ours and don't have theirs; once we have both,
* an RBF attempt on it may be aborted. */
if (!txid) {
struct inflight *last = last_inflight(peer);
if (last
&& !last->remote_tx_sigs
&& !have_they_signed_inflight(peer, last)
&& !shared_input_finalized(peer, last)
&& (last->i_sent_sigs
|| (!last->i_am_initiator
&& have_i_signed_inflight(peer, last))))
refuse_tx_abort(peer, msg, last);
}

if (!fromwire_tx_abort(tmpctx, msg, &channel_id, &data))
peer_failed_warn(peer->pps, &peer->channel_id,
"bad tx_abort %s", tal_hex(msg, msg));
Expand Down Expand Up @@ -3336,6 +3366,8 @@ static bool do_i_send_tx_sigs_first(struct peer *peer, struct wally_psbt *psbt,
return true;
if (peer->dev_splice_sign_second)
return false;
if (peer->dev_splice_sign_first)
return true;
return do_i_sign_first(peer, psbt, our_role, force_sign_first);
}

Expand Down Expand Up @@ -4240,7 +4272,8 @@ static void resume_splice_negotiation(struct peer *peer,
&their_commit->commit_signature,
their_commit->htlc_signatures,
inflight->locked_scid,
inflight->i_sent_sigs);
inflight->i_sent_sigs,
false);
wire_sync_write(MASTER_FD, take(msg));
}

Expand Down Expand Up @@ -4335,7 +4368,8 @@ static void resume_splice_negotiation(struct peer *peer,
msg = towire_channeld_update_inflight(NULL, current_psbt,
NULL, NULL, NULL,
inflight->locked_scid,
inflight->i_sent_sigs);
inflight->i_sent_sigs,
false);
wire_sync_write(MASTER_FD, take(msg));

/* Only send once lightningd has stored i_sent_sigs */
Expand Down Expand Up @@ -4542,7 +4576,8 @@ static void resume_splice_negotiation(struct peer *peer,
msg = towire_channeld_update_inflight(NULL, current_psbt, NULL,
NULL, NULL,
inflight->locked_scid,
inflight->i_sent_sigs);
inflight->i_sent_sigs,
false);
wire_sync_write(MASTER_FD, take(msg));
}

Expand All @@ -4555,12 +4590,21 @@ static void resume_splice_negotiation(struct peer *peer,
WIRE_CHANNELD_SPLICE_SENDING_SIGS_REPLY);

/* Only within a negotiation: a reestablish resends them */
if (peer->dev_splice_warn_instead_of_sigs && peer->splicing)
if ((peer->dev_splice_warn_instead_of_sigs
|| peer->dev_splice_abort_instead_of_sigs)
&& peer->splicing) {
peer_write(peer->pps,
take(towire_warningfmt(NULL,
&peer->channel_id,
"dev-splice-warn-instead-of-sigs")));
else
/* The warning ends their wait for our tx_signatures,
* so this one reaches them outside the negotiation */
if (peer->dev_splice_abort_instead_of_sigs)
peer_write(peer->pps,
take(towire_abortfmt(NULL,
&peer->channel_id,
"dev-splice-abort-instead-of-sigs")));
} else
peer_write(peer->pps, sigmsg);
status_debug("Splice: we signed second");
}
Expand Down Expand Up @@ -5292,7 +5336,8 @@ static void splice_initiator_user_finalized(struct peer *peer)
&their_commit->commit_signature,
their_commit->htlc_signatures,
new_inflight->locked_scid,
new_inflight->i_sent_sigs);
new_inflight->i_sent_sigs,
false);
wire_sync_write(MASTER_FD, take(outmsg));

sign_first = do_i_send_tx_sigs_first(peer, new_inflight->psbt, our_role,
Expand Down Expand Up @@ -5487,11 +5532,13 @@ static void splice_initiator_user_signed(struct peer *peer, const u8 *inmsg)
inflight->psbt = clone_psbt(inflight, signed_psbt);

/* Save the user provided signatures to DB incase we have to
* restart and reestablish later. */
* restart and reestablish later. saves_user_sigs tells lightningd
* that a reconnect now resumes this splice. */
outmsg = towire_channeld_update_inflight(NULL, inflight->psbt,
NULL, NULL, NULL,
inflight->locked_scid,
inflight->i_sent_sigs);
inflight->i_sent_sigs,
true);

wire_sync_write(MASTER_FD, take(outmsg));

Expand Down Expand Up @@ -6987,7 +7034,8 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
NULL,
NULL,
inflight->locked_scid,
inflight->i_sent_sigs);
inflight->i_sent_sigs,
false);
wire_sync_write(MASTER_FD, take(msg));
inflight_match = inflight;
}
Expand Down Expand Up @@ -7621,11 +7669,13 @@ static void init_channel(struct peer *peer)
&peer->dev_splice_corrupt_shared_sig,
&peer->dev_splice_corrupt_input_witness,
&peer->dev_splice_sign_second,
&peer->dev_splice_sign_first,
&pbases,
&peer->splice_state->inflights,
&peer->local_alias,
&peer->dev_splice_abort_at_tx_complete,
&peer->dev_splice_warn_instead_of_sigs,
&peer->dev_splice_abort_instead_of_sigs,
&peer->dev_delay_confirmed_stfu,
&peer->dev_shutdown_during_splice,
&peer->dev_splice_ack_contribution)) {
Expand Down
4 changes: 4 additions & 0 deletions channeld/channeld_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@ msgdata,channeld_init,dev_disable_commit,?u32,
msgdata,channeld_init,dev_splice_corrupt_shared_sig,bool,
msgdata,channeld_init,dev_splice_corrupt_input_witness,bool,
msgdata,channeld_init,dev_splice_sign_second,bool,
msgdata,channeld_init,dev_splice_sign_first,bool,
msgdata,channeld_init,num_penalty_bases,u32,
msgdata,channeld_init,pbases,penalty_base,num_penalty_bases
msgdata,channeld_init,num_inflights,u16,
msgdata,channeld_init,inflights,inflight,num_inflights
msgdata,channeld_init,scid_alias,short_channel_id,
msgdata,channeld_init,dev_splice_abort_at_tx_complete,bool,
msgdata,channeld_init,dev_splice_warn_instead_of_sigs,bool,
msgdata,channeld_init,dev_splice_abort_instead_of_sigs,bool,
msgdata,channeld_init,dev_delay_confirmed_stfu,u32,
msgdata,channeld_init,dev_shutdown_during_splice,bool,
msgdata,channeld_init,dev_splice_ack_contribution,u64,
Expand Down Expand Up @@ -303,6 +305,8 @@ msgdata,channeld_update_inflight,num_htlc_sigs,u16,
msgdata,channeld_update_inflight,htlc_sigs,bitcoin_signature,num_htlc_sigs
msgdata,channeld_update_inflight,locked_scid,?short_channel_id,
msgdata,channeld_update_inflight,i_sent_sigs,bool,
# Set when this saves the signatures splice_signed gave us
msgdata,channeld_update_inflight,saves_user_sigs,bool,

# channeld->master: A funding error has occured
msgtype,channeld_splice_funding_error,7220
Expand Down
6 changes: 6 additions & 0 deletions cln-grpc/proto/node.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions cln-grpc/src/convert.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions cln-rpc/src/model.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions common/jsonrpc_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ enum jsonrpc_errcode {
SPLICE_HIGH_FEE = 360,
SPLICE_ABORT = 362,
SPLICE_CHANNEL_ERROR = 363,
/* splice_signed failed, but the peer may hold our signatures */
SPLICE_MAY_BE_COMMITTED = 364,

/* `connect` errors */
CONNECT_NO_KNOWN_ADDRESS = 400,
Expand Down
Loading
Loading