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

@@ -0,0 +1,18 @@
--- wire/peer_exp_wire.csv 2022-06-22 19:07:24.000000000 -0500
+++ - 2022-06-30 16:00:51.000000000 -0500
@@ -65,12 +57,15 @@
msgdata,tx_signatures,txid,sha256,
msgdata,tx_signatures,num_witnesses,u16,
msgdata,tx_signatures,witness_stack,witness_stack,num_witnesses
+msgdata,tx_signatures,tlvs,txsigs_tlvs,
subtype,witness_stack
subtypedata,witness_stack,num_input_witness,u16,
subtypedata,witness_stack,witness_element,witness_element,num_input_witness
subtype,witness_element
subtypedata,witness_element,len,u16,
subtypedata,witness_element,witness,byte,len
+tlvtype,txsigs_tlvs,funding_outpoint_sig,0
+tlvdata,txsigs_tlvs,funding_outpoint_sig,sig,byte,...
msgtype,tx_init_rbf,72
msgdata,tx_init_rbf,channel_id,channel_id,
msgdata,tx_init_rbf,locktime,u32,

View File

@@ -1,10 +1,12 @@
--- wire/peer_wire.csv 2021-05-09 15:44:59.166135652 +0930
+++ wire/peer_wire.csv.raw 2021-05-11 09:59:31.695459756 +0930
@@ -244,6 +140,15 @@
@@ -244,6 +140,17 @@
msgdata,channel_reestablish,next_revocation_number,u64,
msgdata,channel_reestablish,your_last_per_commitment_secret,byte,32
msgdata,channel_reestablish,my_current_per_commitment_point,point,
+msgdata,channel_reestablish,tlvs,channel_reestablish_tlvs,
+tlvtype,channel_reestablish_tlvs,next_funding,0
+tlvdata,channel_reestablish_tlvs,next_funding,next_funding_txid,sha256,
+tlvtype,channel_reestablish_tlvs,next_to_send,1
+tlvdata,channel_reestablish_tlvs,next_to_send,commitment_number,tu64,
+tlvtype,channel_reestablish_tlvs,desired_channel_type,3

View File

@@ -280,3 +280,4 @@ void fromwire_siphash_seed(const u8 **cursor, size_t *max,
{
fromwire(cursor, max, seed, sizeof(*seed));
}

View File

@@ -50,6 +50,9 @@ static bool unknown_type(enum peer_wire t)
case WIRE_OPEN_CHANNEL2:
case WIRE_ACCEPT_CHANNEL2:
case WIRE_STFU:
case WIRE_SPLICE:
case WIRE_SPLICE_ACK:
case WIRE_SPLICE_LOCKED:
return false;
}
return true;
@@ -104,6 +107,9 @@ bool is_msg_for_gossipd(const u8 *cursor)
case WIRE_PEER_STORAGE:
case WIRE_YOUR_PEER_STORAGE:
case WIRE_STFU:
case WIRE_SPLICE:
case WIRE_SPLICE_ACK:
case WIRE_SPLICE_LOCKED:
break;
}
return false;
@@ -365,6 +371,30 @@ bool extract_channel_id(const u8 *in_pkt, struct channel_id *channel_id)
* 2. data:
* * [`channel_id`:`channel_id`]
*/
case WIRE_SPLICE:
/* BOLT-splice #2:
* 1. type: 74 (`splice`)
* 2. data:
* * [`chain_hash`:`chain_hash`]
* * [`channel_id`:`channel_id`]
* * [`u32`:`funding_feerate_perkw`]
* * [`point`:`funding_pubkey`]
*/
case WIRE_SPLICE_ACK:
/* BOLT-splice #2:
* 1. type: 76 (`splice_ack`)
* 2. data:
* * [`chain_hash`:`chain_hash`]
* * [`channel_id`:`channel_id`]
* * [`point`:`funding_pubkey`]
*/
case WIRE_SPLICE_LOCKED:
/* BOLT-splice #2:
* 1. type: 78 (`splice_locked`)
* 2. data:
* * [`chain_hash`:`chain_hash`]
* * [`channel_id`:`channel_id`]
*/
return fromwire_channel_id(&cursor, &max, channel_id);
}
return false;

View File

@@ -66,6 +66,9 @@ msgdata,tx_signatures,witnesses,witness,num_witnesses
subtype,witness
subtypedata,witness,len,u16,
subtypedata,witness,witness_data,byte,len
msgdata,tx_signatures,tlvs,txsigs_tlvs,
tlvtype,txsigs_tlvs,funding_outpoint_sig,0
tlvdata,txsigs_tlvs,funding_outpoint_sig,sig,byte,...
msgtype,tx_init_rbf,72
msgdata,tx_init_rbf,channel_id,channel_id,
msgdata,tx_init_rbf,locktime,u32,
@@ -203,6 +206,20 @@ subtypedata,lease_rates,channel_fee_max_base_msat,tu32,
msgtype,stfu,2
msgdata,stfu,channel_id,channel_id,
msgdata,stfu,initiator,u8,
msgtype,splice,75
msgdata,splice,channel_id,channel_id,
msgdata,splice,chain_hash,chain_hash,
msgdata,splice,relative_satoshis,s64,
msgdata,splice,funding_feerate_perkw,u32,
msgdata,splice,locktime,u32,
msgdata,splice,funding_pubkey,point,
msgtype,splice_ack,76
msgdata,splice_ack,channel_id,channel_id,
msgdata,splice_ack,chain_hash,chain_hash,
msgdata,splice_ack,relative_satoshis,s64,
msgdata,splice_ack,funding_pubkey,point,
msgtype,splice_locked,77,
msgdata,splice_locked,channel_id,channel_id,
msgtype,shutdown,38
msgdata,shutdown,channel_id,channel_id,
msgdata,shutdown,len,u16,
@@ -247,6 +264,9 @@ msgdata,commitment_signed,channel_id,channel_id,
msgdata,commitment_signed,signature,signature,
msgdata,commitment_signed,num_htlcs,u16,
msgdata,commitment_signed,htlc_signature,signature,num_htlcs
msgdata,commitment_signed,splice_channel_id,commitment_signed_tlvs,
tlvtype,commitment_signed_tlvs,splice_info,0
tlvdata,commitment_signed_tlvs,splice_info,splice_channel_id,channel_id,
msgtype,revoke_and_ack,133
msgdata,revoke_and_ack,channel_id,channel_id,
msgdata,revoke_and_ack,per_commitment_secret,byte,32
1 msgtype,init,16
66 subtype,witness
67 subtypedata,witness,len,u16,
68 subtypedata,witness,witness_data,byte,len
69 msgdata,tx_signatures,tlvs,txsigs_tlvs,
70 tlvtype,txsigs_tlvs,funding_outpoint_sig,0
71 tlvdata,txsigs_tlvs,funding_outpoint_sig,sig,byte,...
72 msgtype,tx_init_rbf,72
73 msgdata,tx_init_rbf,channel_id,channel_id,
74 msgdata,tx_init_rbf,locktime,u32,
206 msgtype,stfu,2
207 msgdata,stfu,channel_id,channel_id,
208 msgdata,stfu,initiator,u8,
209 msgtype,splice,75
210 msgdata,splice,channel_id,channel_id,
211 msgdata,splice,chain_hash,chain_hash,
212 msgdata,splice,relative_satoshis,s64,
213 msgdata,splice,funding_feerate_perkw,u32,
214 msgdata,splice,locktime,u32,
215 msgdata,splice,funding_pubkey,point,
216 msgtype,splice_ack,76
217 msgdata,splice_ack,channel_id,channel_id,
218 msgdata,splice_ack,chain_hash,chain_hash,
219 msgdata,splice_ack,relative_satoshis,s64,
220 msgdata,splice_ack,funding_pubkey,point,
221 msgtype,splice_locked,77,
222 msgdata,splice_locked,channel_id,channel_id,
223 msgtype,shutdown,38
224 msgdata,shutdown,channel_id,channel_id,
225 msgdata,shutdown,len,u16,
264 msgdata,commitment_signed,signature,signature,
265 msgdata,commitment_signed,num_htlcs,u16,
266 msgdata,commitment_signed,htlc_signature,signature,num_htlcs
267 msgdata,commitment_signed,splice_channel_id,commitment_signed_tlvs,
268 tlvtype,commitment_signed_tlvs,splice_info,0
269 tlvdata,commitment_signed_tlvs,splice_info,splice_channel_id,channel_id,
270 msgtype,revoke_and_ack,133
271 msgdata,revoke_and_ack,channel_id,channel_id,
272 msgdata,revoke_and_ack,per_commitment_secret,byte,32

View File

@@ -40,6 +40,11 @@ static void set_scid(struct short_channel_id *scid)
memset(scid, 2, sizeof(struct short_channel_id));
}
static void set_cid(struct channel_id *cid)
{
memset(cid, 2, sizeof(struct channel_id));
}
/* Size up to field. */
#define upto_field(p, field) \
((char *)&(p)->field - (char *)(p))
@@ -160,6 +165,7 @@ struct msg_commitment_signed {
struct channel_id channel_id;
secp256k1_ecdsa_signature signature;
secp256k1_ecdsa_signature *htlc_signature;
struct tlv_commitment_signed_tlvs *tlvs;
};
struct msg_node_announcement {
secp256k1_ecdsa_signature signature;
@@ -525,17 +531,20 @@ static void *towire_struct_commitment_signed(const tal_t *ctx,
return towire_commitment_signed(ctx,
&s->channel_id,
&s->signature,
s->htlc_signature);
s->htlc_signature,
s->tlvs);
}
static struct msg_commitment_signed *fromwire_struct_commitment_signed(const tal_t *ctx, const void *p)
{
struct msg_commitment_signed *s = tal(ctx, struct msg_commitment_signed);
s->tlvs = tlv_commitment_signed_tlvs_new(ctx);
if (!fromwire_commitment_signed(s, p,
&s->channel_id,
&s->signature,
&s->htlc_signature))
&s->htlc_signature,
&s->tlvs))
return tal_free(s);
return s;
}
@@ -781,7 +790,8 @@ static bool commitment_signed_eq(const struct msg_commitment_signed *a,
const struct msg_commitment_signed *b)
{
return eq_upto(a, b, htlc_signature)
&& eq_var(a, b, htlc_signature);
&& eq_var(a, b, htlc_signature)
&& eq_tlv(a, b, splice_info, channel_id_eq);
}
static bool funding_signed_eq(const struct msg_funding_signed *a,
@@ -1007,11 +1017,14 @@ int main(int argc, char *argv[])
memset(&cs, 2, sizeof(cs));
cs.htlc_signature = tal_arr(ctx, secp256k1_ecdsa_signature, 2);
memset(cs.htlc_signature, 2, sizeof(secp256k1_ecdsa_signature)*2);
cs.tlvs = tlv_commitment_signed_tlvs_new(tmpctx);
cs.tlvs->splice_info = tal(ctx, struct channel_id);
set_cid(cs.tlvs->splice_info);
msg = towire_struct_commitment_signed(ctx, &cs);
cs2 = fromwire_struct_commitment_signed(ctx, msg);
assert(commitment_signed_eq(&cs, cs2));
test_corruption(&cs, cs2, commitment_signed);
test_corruption_tlv(&cs, cs2, commitment_signed);
memset(&fs, 2, sizeof(fs));

View File

@@ -4,6 +4,7 @@
#include <ccan/crypto/siphash24/siphash24.h>
#include <ccan/endian/endian.h>
#include <ccan/mem/mem.h>
#include <channeld/inflight.h>
#include <common/utils.h>
void towire(u8 **pptr, const void *data, size_t len)