Skip to content

Commit fe02d2f

Browse files
adi2011endothermicdev
authored andcommitted
scb_wire: Define new subtype 'modern_scb_chan' with 'scb_tlvs'
We define a new subtype 'modern_scb_chan' and a new tlvtype 'scb_tlvs' which includes all the relevant information to create a penalty transaction when the peer tries to cheat. Key Changes: - Rename the old format to 'legacy_scb_chan' and define a new type 'modern_scb_chan' - Include TLVs to 'modern_scb_chan' - Create a new msgtype 'static_chan_backup_with_tlvs' - Modify 'struct channel' to include 'struct modern_scb_chan' - Add these two types to 'varsize_types' in generate.py
1 parent 6df6789 commit fe02d2f

File tree

8 files changed

+94
-34
lines changed

8 files changed

+94
-34
lines changed

common/scb_wire.csv

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,52 @@
1-
#include <common/node_id.h>
1+
#include <bitcoin/tx.h>
2+
#include <ccan/crypto/shachain/shachain.h>
3+
#include <common/amount.h>
24
#include <common/channel_id.h>
3-
#include <common/wireaddr.h>
45
#include <common/channel_type.h>
5-
#include <common/amount.h>
6-
#include <bitcoin/tx.h>
6+
#include <common/derive_basepoints.h>
7+
#include <common/htlc_wire.h>
8+
#include <common/node_id.h>
9+
#include <common/wireaddr.h>
10+
11+
tlvtype,scb_tlvs,shachain,1,
12+
tlvdata,scb_tlvs,shachain,their_shachain,shachain,
13+
tlvtype,scb_tlvs,basepoints,3,
14+
tlvdata,scb_tlvs,basepoints,their_basepoint,basepoints,
15+
tlvtype,scb_tlvs,opener,5,
16+
tlvdata,scb_tlvs,opener,opener,enum side,
17+
tlvtype,scb_tlvs,remote_to_self_delay,7,
18+
tlvdata,scb_tlvs,remote_to_self_delay,remote_to_self_delay,u16,
719

8-
# scb_chan stores min. info required to sweep the peer's force close.
9-
subtype,scb_chan
10-
subtypedata,scb_chan,id,u64,
11-
subtypedata,scb_chan,cid,channel_id,
12-
subtypedata,scb_chan,node_id,node_id,
13-
subtypedata,scb_chan,unused,u8,
14-
subtypedata,scb_chan,addr,wireaddr,
15-
subtypedata,scb_chan,funding,bitcoin_outpoint,
16-
subtypedata,scb_chan,funding_sats,amount_sat,
17-
subtypedata,scb_chan,type,channel_type,
20+
# legacy_scb_chan stores min. info required to sweep the peer's force close.
21+
subtype,legacy_scb_chan
22+
subtypedata,legacy_scb_chan,id,u64,
23+
subtypedata,legacy_scb_chan,cid,channel_id,
24+
subtypedata,legacy_scb_chan,node_id,node_id,
25+
subtypedata,legacy_scb_chan,unused,u8,
26+
subtypedata,legacy_scb_chan,addr,wireaddr,
27+
subtypedata,legacy_scb_chan,funding,bitcoin_outpoint,
28+
subtypedata,legacy_scb_chan,funding_sats,amount_sat,
29+
subtypedata,legacy_scb_chan,type,channel_type,
1830

1931
msgtype,static_chan_backup,6135,
2032
msgdata,static_chan_backup,version,u64,
2133
msgdata,static_chan_backup,timestamp,u32,
2234
msgdata,static_chan_backup,num,u16,
23-
msgdata,static_chan_backup,channels,scb_chan,num
35+
msgdata,static_chan_backup,channels,legacy_scb_chan,num
36+
37+
subtype,modern_scb_chan
38+
subtypedata,modern_scb_chan,id,u64,
39+
subtypedata,modern_scb_chan,cid,channel_id,
40+
subtypedata,modern_scb_chan,node_id,node_id,
41+
subtypedata,modern_scb_chan,addr,wireaddr,
42+
subtypedata,modern_scb_chan,funding,bitcoin_outpoint,
43+
subtypedata,modern_scb_chan,funding_sats,amount_sat,
44+
subtypedata,modern_scb_chan,type,channel_type,
45+
subtypedata,modern_scb_chan,len_tlv,u32,
46+
subtypedata,modern_scb_chan,tlvs,scb_tlvs,len_tlv
47+
48+
msgtype,static_chan_backup_with_tlvs,6137,
49+
msgdata,static_chan_backup_with_tlvs,version,u64,
50+
msgdata,static_chan_backup_with_tlvs,timestamp,u32,
51+
msgdata,static_chan_backup_with_tlvs,num,u16,
52+
msgdata,static_chan_backup_with_tlvs,channels,modern_scb_chan,num

lightningd/channel.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,12 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
482482
channel->owner = NULL;
483483
memset(&channel->billboard, 0, sizeof(channel->billboard));
484484
channel->billboard.transient = tal_strdup(channel, transient_billboard);
485+
channel->channel_info = *channel_info;
485486

486487
/* If it's a unix domain socket connection, we don't save it */
487488
if (peer->addr.itype == ADDR_INTERNAL_WIREADDR) {
488-
channel->scb = tal(channel, struct scb_chan);
489+
channel->scb = tal(channel, struct modern_scb_chan);
489490
channel->scb->id = dbid;
490-
channel->scb->unused = 0;
491491
/* More useful to have last_known_addr, if avail */
492492
if (peer->last_known_addr)
493493
channel->scb->addr = *peer->last_known_addr;
@@ -497,6 +497,14 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
497497
channel->scb->cid = *cid;
498498
channel->scb->funding_sats = funding_sats;
499499
channel->scb->type = channel_type_dup(channel->scb, type);
500+
501+
struct tlv_scb_tlvs *scb_tlvs = tlv_scb_tlvs_new(channel);
502+
scb_tlvs->shachain = &channel->their_shachain.chain;
503+
scb_tlvs->basepoints = &channel->channel_info.theirbase;
504+
scb_tlvs->opener = &channel->opener;
505+
scb_tlvs->remote_to_self_delay = &channel->channel_info.their_config.to_self_delay;
506+
507+
channel->scb->tlvs = scb_tlvs;
500508
} else
501509
channel->scb = NULL;
502510

@@ -542,7 +550,6 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
542550
if (last_sig)
543551
channel->last_sig = *last_sig;
544552
channel->last_htlc_sigs = tal_steal(channel, last_htlc_sigs);
545-
channel->channel_info = *channel_info;
546553
channel->fee_states = dup_fee_states(channel, fee_states);
547554
channel->shutdown_scriptpubkey[REMOTE]
548555
= tal_steal(channel, remote_shutdown_scriptpubkey);

lightningd/channel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ struct channel {
334334

335335
/* `Channel-shell` of this channel
336336
* (Minimum information required to backup this channel). */
337-
struct scb_chan *scb;
337+
struct modern_scb_chan *scb;
338338

339339
/* Do we allow the peer to set any fee it wants? */
340340
bool ignore_fee_limits;

lightningd/dual_open_control.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,14 +1462,21 @@ wallet_commit_channel(struct lightningd *ld,
14621462
channel->min_possible_feerate = commitment_feerate;
14631463
channel->max_possible_feerate = commitment_feerate;
14641464
if (channel->peer->addr.itype == ADDR_INTERNAL_WIREADDR) {
1465-
channel->scb = tal(channel, struct scb_chan);
1465+
channel->scb = tal(channel, struct modern_scb_chan);
14661466
channel->scb->id = channel->dbid;
1467-
channel->scb->unused = 0;
14681467
channel->scb->addr = channel->peer->addr.u.wireaddr.wireaddr;
14691468
channel->scb->node_id = channel->peer->id;
14701469
channel->scb->funding = *funding;
14711470
channel->scb->cid = channel->cid;
14721471
channel->scb->funding_sats = total_funding;
1472+
1473+
struct tlv_scb_tlvs *scb_tlvs = tlv_scb_tlvs_new(channel);
1474+
scb_tlvs->shachain = &channel->their_shachain.chain;
1475+
scb_tlvs->basepoints = &channel_info->theirbase;
1476+
scb_tlvs->opener = &channel->opener;
1477+
scb_tlvs->remote_to_self_delay = &channel_info->their_config.to_self_delay;
1478+
1479+
channel->scb->tlvs = scb_tlvs;
14731480
} else
14741481
channel->scb = NULL;
14751482

lightningd/test/run-invoice-select-inchan.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,9 @@ u8 *towire_hsmd_sign_commitment_tx(const tal_t *ctx UNNEEDED, const struct node_
10121012
/* Generated stub for towire_hsmd_sign_invoice */
10131013
u8 *towire_hsmd_sign_invoice(const tal_t *ctx UNNEEDED, const u8 *u5bytes UNNEEDED, const u8 *hrp UNNEEDED)
10141014
{ fprintf(stderr, "towire_hsmd_sign_invoice called!\n"); abort(); }
1015+
/* Generated stub for towire_modern_scb_chan */
1016+
void towire_modern_scb_chan(u8 **p UNNEEDED, const struct modern_scb_chan *modern_scb_chan UNNEEDED)
1017+
{ fprintf(stderr, "towire_modern_scb_chan called!\n"); abort(); }
10151018
/* Generated stub for towire_node_id */
10161019
void towire_node_id(u8 **pptr UNNEEDED, const struct node_id *id UNNEEDED)
10171020
{ fprintf(stderr, "towire_node_id called!\n"); abort(); }
@@ -1021,9 +1024,6 @@ u8 *towire_onchaind_dev_memleak(const tal_t *ctx UNNEEDED)
10211024
/* Generated stub for towire_openingd_dev_memleak */
10221025
u8 *towire_openingd_dev_memleak(const tal_t *ctx UNNEEDED)
10231026
{ fprintf(stderr, "towire_openingd_dev_memleak called!\n"); abort(); }
1024-
/* Generated stub for towire_scb_chan */
1025-
void towire_scb_chan(u8 **p UNNEEDED, const struct scb_chan *scb_chan UNNEEDED)
1026-
{ fprintf(stderr, "towire_scb_chan called!\n"); abort(); }
10271027
/* Generated stub for towire_warningfmt */
10281028
u8 *towire_warningfmt(const tal_t *ctx UNNEEDED,
10291029
const struct channel_id *channel UNNEEDED,

tools/generate-wire.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ class Type(FieldSet):
249249
'tx_parts',
250250
'wally_psbt',
251251
'wally_tx',
252-
'scb_chan',
252+
'legacy_scb_chan',
253+
'modern_scb_chan',
253254
'inflight',
254255
]
255256

wallet/test/run-db.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,6 @@ const u8 *psbt_fixup(const tal_t *ctx UNNEEDED, const u8 *psbtblob UNNEEDED)
293293
struct htlc_in *remove_htlc_in_by_dbid(struct htlc_in_map *remaining_htlcs_in UNNEEDED,
294294
u64 dbid UNNEEDED)
295295
{ fprintf(stderr, "remove_htlc_in_by_dbid called!\n"); abort(); }
296-
/* Generated stub for rune_is_ours */
297-
const char *rune_is_ours(struct lightningd *ld UNNEEDED, const struct rune *rune UNNEEDED)
298-
{ fprintf(stderr, "rune_is_ours called!\n"); abort(); }
299296
/* Generated stub for rune_unique_id */
300297
u64 rune_unique_id(const struct rune *rune UNNEEDED)
301298
{ fprintf(stderr, "rune_unique_id called!\n"); abort(); }

wallet/test/run-wallet.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static void test_error(struct lightningd *ld, bool fatal, const char *fmt, va_li
2020
wallet_err = tal_vfmt(NULL, fmt, ap);
2121
}
2222

23+
#include "common/scb_wiregen.c"
2324
#include "wallet/wallet.c"
2425
#include "lightningd/hsm_control.c"
2526
#include "lightningd/htlc_end.c"
@@ -277,6 +278,13 @@ u64 forward_index_update_status(struct lightningd *ld UNNEEDED,
277278
struct amount_msat in_amount UNNEEDED,
278279
const struct short_channel_id *out_channel UNNEEDED)
279280
{ fprintf(stderr, "forward_index_update_status called!\n"); abort(); }
281+
/* Generated stub for fromwire_channel_id */
282+
bool fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
283+
struct channel_id *channel_id UNNEEDED)
284+
{ fprintf(stderr, "fromwire_channel_id called!\n"); abort(); }
285+
/* Generated stub for fromwire_channel_type */
286+
struct channel_type *fromwire_channel_type(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *plen UNNEEDED)
287+
{ fprintf(stderr, "fromwire_channel_type called!\n"); abort(); }
280288
/* Generated stub for fromwire_channeld_dev_memleak_reply */
281289
bool fromwire_channeld_dev_memleak_reply(const void *p UNNEEDED, bool *leak UNNEEDED)
282290
{ fprintf(stderr, "fromwire_channeld_dev_memleak_reply called!\n"); abort(); }
@@ -349,6 +357,12 @@ bool fromwire_onchaind_dev_memleak_reply(const void *p UNNEEDED, bool *leak UNNE
349357
/* Generated stub for fromwire_openingd_dev_memleak_reply */
350358
bool fromwire_openingd_dev_memleak_reply(const void *p UNNEEDED, bool *leak UNNEEDED)
351359
{ fprintf(stderr, "fromwire_openingd_dev_memleak_reply called!\n"); abort(); }
360+
/* Generated stub for fromwire_tlv */
361+
bool fromwire_tlv(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
362+
const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED,
363+
void *record UNNEEDED, struct tlv_field **fields UNNEEDED,
364+
const u64 *extra_types UNNEEDED, size_t *err_off UNNEEDED, u64 *err_type UNNEEDED)
365+
{ fprintf(stderr, "fromwire_tlv called!\n"); abort(); }
352366
/* Generated stub for get_block_height */
353367
u32 get_block_height(const struct chain_topology *topo UNNEEDED)
354368
{ fprintf(stderr, "get_block_height called!\n"); abort(); }
@@ -950,9 +964,6 @@ void report_subd_memleak(struct leak_detect *leak_detect UNNEEDED, struct subd *
950964
void resolve_close_command(struct lightningd *ld UNNEEDED, struct channel *channel UNNEEDED,
951965
bool cooperative UNNEEDED, const struct bitcoin_tx **close_txs UNNEEDED)
952966
{ fprintf(stderr, "resolve_close_command called!\n"); abort(); }
953-
/* Generated stub for rune_is_ours */
954-
const char *rune_is_ours(struct lightningd *ld UNNEEDED, const struct rune *rune UNNEEDED)
955-
{ fprintf(stderr, "rune_is_ours called!\n"); abort(); }
956967
/* Generated stub for rune_unique_id */
957968
u64 rune_unique_id(const struct rune *rune UNNEEDED)
958969
{ fprintf(stderr, "rune_unique_id called!\n"); abort(); }
@@ -1033,9 +1044,15 @@ void topology_add_sync_waiter_(const tal_t *ctx UNNEEDED,
10331044
/* Generated stub for towire_announcement_signatures */
10341045
u8 *towire_announcement_signatures(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED, struct short_channel_id short_channel_id UNNEEDED, const secp256k1_ecdsa_signature *node_signature UNNEEDED, const secp256k1_ecdsa_signature *bitcoin_signature UNNEEDED)
10351046
{ fprintf(stderr, "towire_announcement_signatures called!\n"); abort(); }
1047+
/* Generated stub for towire_channel_id */
1048+
void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED)
1049+
{ fprintf(stderr, "towire_channel_id called!\n"); abort(); }
10361050
/* Generated stub for towire_channel_reestablish */
10371051
u8 *towire_channel_reestablish(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED, u64 next_commitment_number UNNEEDED, u64 next_revocation_number UNNEEDED, const struct secret *your_last_per_commitment_secret UNNEEDED, const struct pubkey *my_current_per_commitment_point UNNEEDED, const struct tlv_channel_reestablish_tlvs *channel_reestablish UNNEEDED)
10381052
{ fprintf(stderr, "towire_channel_reestablish called!\n"); abort(); }
1053+
/* Generated stub for towire_channel_type */
1054+
void towire_channel_type(u8 **p UNNEEDED, const struct channel_type *channel_type UNNEEDED)
1055+
{ fprintf(stderr, "towire_channel_type called!\n"); abort(); }
10391056
/* Generated stub for towire_channeld_dev_memleak */
10401057
u8 *towire_channeld_dev_memleak(const tal_t *ctx UNNEEDED)
10411058
{ fprintf(stderr, "towire_channeld_dev_memleak called!\n"); abort(); }
@@ -1155,15 +1172,17 @@ u8 *towire_openingd_dev_memleak(const tal_t *ctx UNNEEDED)
11551172
/* Generated stub for towire_permanent_channel_failure */
11561173
u8 *towire_permanent_channel_failure(const tal_t *ctx UNNEEDED)
11571174
{ fprintf(stderr, "towire_permanent_channel_failure called!\n"); abort(); }
1158-
/* Generated stub for towire_scb_chan */
1159-
void towire_scb_chan(u8 **p UNNEEDED, const struct scb_chan *scb_chan UNNEEDED)
1160-
{ fprintf(stderr, "towire_scb_chan called!\n"); abort(); }
11611175
/* Generated stub for towire_temporary_channel_failure */
11621176
u8 *towire_temporary_channel_failure(const tal_t *ctx UNNEEDED, const u8 *channel_update UNNEEDED)
11631177
{ fprintf(stderr, "towire_temporary_channel_failure called!\n"); abort(); }
11641178
/* Generated stub for towire_temporary_node_failure */
11651179
u8 *towire_temporary_node_failure(const tal_t *ctx UNNEEDED)
11661180
{ fprintf(stderr, "towire_temporary_node_failure called!\n"); abort(); }
1181+
/* Generated stub for towire_tlv */
1182+
void towire_tlv(u8 **pptr UNNEEDED,
1183+
const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED,
1184+
const void *record UNNEEDED)
1185+
{ fprintf(stderr, "towire_tlv called!\n"); abort(); }
11671186
/* Generated stub for towire_unknown_next_peer */
11681187
u8 *towire_unknown_next_peer(const tal_t *ctx UNNEEDED)
11691188
{ fprintf(stderr, "towire_unknown_next_peer called!\n"); abort(); }

0 commit comments

Comments
 (0)